Haskell Parsers Part 3.

This is the third part of parsing in Haskell. The previous posts are available at Haskell Parsers Part 1 and Haskell Parsers Part 2. In part one we defined a parser as a type and derived a very simple parser, a parser of char. Part two extended the ideas and created monadic, functorial and applicative instances of the parser type. This allowed us to combine parsers monadically – using ‘do’ or in an applicative style – e.g. using ‘<*>’ etc. Which to use is often a stylistic choice. In this post we’ll look at creating a few extra functions to Read More


Haskell Parsers Part 2.

This post continues from Haskell Parsers Part 1 and here we look at elevating the parser first to a Functor then an Applicative and finally to a Monad. Creating Functor, Applicative and Monad instances for the parser will provide useful operations and allow parsers to be combined in interesting and useful ways. For a Functor we need to implement the fmap function and in the context of a Parser the signature of fmap is

in other words “A function a -> b applied to the result of a parser of ‘a’ gives a parser of ‘b’” and the implementation Read More


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


ˆ Back To Top