haskell Category

Will on #geekup has been working on a Countdown letters and numbers game solver written in Python. I thought it'd be fun to try to do it in Haskell, and started with the letters game (anagram) solver. Starting with a string of jumbled letters, the goal is to make the longest possible anagram. I remember the first time [...]

Monad Wars - code online

In: haskell
Chessguy pointed out that it's currently hard to play along with the monad wars code. It would be nice for the posts to be “literate haskell”, where sections preceded by “>“ characters are valid Haskell. The idea is great - that you can mix sections of introduction and description with sections of actual code, ending up with an article [...]

Monad Wars - 3: Command line actions

In: haskell
After the last post, we have parser actions that can recognise an integer or an item of merchandise. Now we need to be able to process a command, like “jet bronx” or “buy 4 lambdas”. Let's start off with this basis: > parseCommand = parseMap commandMap > commandMap = getPrefixMap [ > [...]
One of the advantages of demonstrating your ignorance in public is that you may receive useful corrections... thanks to everyone who replied on these recent posts, I found the comments very instructive, and thought it was worth writing up as a new post. Strict records ddarius got in touch to mention that I might want to use “strict fields”. [...]

Monad Wars - 2: the command line

In: haskell
This time around, we're going to look at how we'll turn user input into commands in Monad Wars. I think that the easiest option to implement will also be very convenient to play with: a command line where we issue commands like: $ buy 4 foo $ sell 20 bar [...]

Monad Wars - 1: the Prompt

In: haskell
A lot of learning projects involve writing games: people have written clones of Tetris, Asteroids, Space Invaders, and even first person shooters (Frag) in Haskell. As I'm far less clever than these people, I thought I'd start with something a bit simpler: Dope Wars. Dope Wars is basically a trading game. In 30 turns, you move from one location to [...]

Haskell snippet - getPrefixMap

In: haskell
Here's a little snippet I worked on yesterday, while preparing my talk for the London Perl Workshop.It takes a list of tuples ("string", whatever) and maps all the prefixes of the string ("string", "strin", "stri", etc.) to the whatever.I was quite impressed at how easily this came together.  The functional composition (pipelines connected with ".") [...]

For loops in Haskell

In: haskell
Functional programmers often seem to complain that for loops are better off done with maps, and that, in any case, they're just degenerate cases of the same thing, as all imperative constructs can be created in a fully functional way... That being the claim, I thought it might be a fun exercise to try to implement for loops in [...]

More on Maybes and Haskell Ternary

In: haskell
I was playing with the Maybe type and realised that there are useful functions provided to play with these types. Then I realised that in my definition of ternary operator in haskell the definition of (!) > Nothing ! a = a > Just b ! _ = b was very similar to the predefined function [...]
I looked at chapter 8 in terror and ran to the (comparative) familiarity of this chapter. Currying I remember a couple of years ago, when I was looking up Functional Programming early on, I came across the idea that functional programming languages didn't take multiple arguments, but returned a function at each step. I think I scoffed slightly at this [...]