[Haskell-beginners] question, chapter 10 Real World Haskell
Michael Mossey
mpm at alumni.caltech.edu
Sat Apr 11 05:02:04 EDT 2009
I'll looking at the parser example, page 242 in Chapter 10 of Real World Haskell, and
they are defining a type of monadic parser with the help of an operator they call ==>
You can find chapter 10 online. This ebook doesn't have page numbers, but you can
find the example I'm looking at in the second called "A more interesting parser",
about 40% of the way down:
<http://book.realworldhaskell.org/read/code-case-study-parsing-a-binary-data-format.html>
The authors have defined their parser by chaining together functions with ==>. The
first function is "getState". What confuses me is: they use getState to "get the
state out of the Parser," but a Parser is by definition a function that takes the
parse state as its lone argument. I don't understand why they can't drop getState
entirely. Maybe it's a simply a way to avoid wrapping the entire function in Parser
(...)?
Some of this stuff looks "inefficient" to me, but I realize that in a lazy language
with an optimizing compiler you can often write long chains of functions (many of
which discard their results) and not impede efficiency.
Thanks,
Mike
More information about the Beginners
mailing list