[Haskell-beginners] Parser as an instance of the monad class

Iustin Pop iusty at k1024.org
Wed Jan 12 09:01:30 CET 2011


On Tue, Jan 11, 2011 at 11:39:48PM -0800, Paul Higham wrote:
> There are a number of ugly things that you can do at this point that
> are just plain wrong, so I thought that the right thing to do would
> be to get the Parser type to be manifested as an instance of the
> Monad class.  Ok, now what?  Since Parser is only a type synonym it
> cannot be used directly in the following way:
> 
>    instance Monad Parser where
>       return v = . . .
>       p >>= f  = . . .
> 
> but since Parser is not an algebraic type as it is defined that
> won't work either.  So how do you do it?  help .

Have you looked at the book's website? He provides the entire
Parsing.lhs library, and you can see there an example of how to do it.

regards,
iustin



More information about the Beginners mailing list