By: admin on: Nov 28,2007
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 [...]
By: admin on: Nov 27,2007
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 [ > [...]
By: admin on: Nov 27,2007
In: haskell
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”. [...]
By: admin on: Nov 26,2007
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 [...]
By: admin on: Nov 23,2007
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 [...]
By: admin on: Nov 20,2007
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 ".") [...]
By: admin on: Nov 12,2007
In: haskell, perl
Haskell's prelude has a function words that splits a string by spaces.
Prelude> words "nice cup of tea" ["nice","cup","of","tea"]
Apparently the question comes up quite regularly on irc or
haskell-cafe as to why this function is specialised to split only on
whitespace. Perl's split, for example, can split on any character, or indeed string or regular expression.
As quicksilver [...]
By: admin on: Oct 30,2007
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 [...]
By: admin on: Aug 28,2007
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 [...]
By: admin on: Jul 2,2007
In: haskell
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 [...]