[Haskell-beginners] question, chapter 10 Real World Haskell

Quentin Moser quentin.moser at unifr.ch
Sat Apr 11 13:04:22 EDT 2009


On Sat, 11 Apr 2009 09:37:53 -0700
Michael Mossey <mpm at alumni.caltech.edu> wrote:

> One other question. Later in the
> chapter they define peekByte as follows:
> 
> -- file: ch10/Parse.hs
> peekByte :: Parse (Maybe Word8)
> peekByte = (fmap fst . L.uncons . string) <$> getState
> 
> Here they are accessing the 'string' field of the state. So whomever
> writes this function needs to have the accessor functions. At this
> point I'm wondering how much state is really getting hidden. Or maybe
> peekByte would only be written inside the original library.

Even before worrying about the accessor functions, a parsing library
would in the first place not even export getState, putState, or the
ParseState type. It would instead provide functions like parseByte and
peekByte as primitives from which all complex parsers will be built.


More information about the Beginners mailing list