Haskell Parsers Part 1.

I really enjoy using Haskell. It’s probably the most intellectually satisfying programming language ever! Parsing is one of its many strengths and these next few posts will be about creating simple parsers from first principles and expressing them in two different ways. For parsing, start with a newtype definition for a Parser and a data constructor P that has a function String -> [(a, String)] which will parse the string for an ‘a’. The result of the parse is a list of tuples. The first element of a tuple being an ‘a’ and the other is whatever is left of Read More

The expressiveness of Haskell – Sorting.

What first excited me about Haskell was the expressiveness of the language. It somehow encapsulates thought and the problem being solved can often be seen clearly in the solution. Take, for example, sorting a list containing elements of a general type ‘a’. For these to be placed in order it must be possible to compare them. So in Haskell the sort function can be defined as:

i.e. the sort function takes a list of ‘a’ and returns a list of ‘a’ and the restriction on the type of ‘a’ is that it must be an instance of the Ord Read More

ˆ Back To Top