haskell-cafe@haskell.org
[Top] [All Lists]

Re: [Haskell-cafe] stuck with a sample of "programming in haskell"

Subject: Re: [Haskell-cafe] stuck with a sample of "programming in haskell"
From: Stephen Tetley
Date: Fri, 19 Mar 2010 10:01:29 +0000
2010/3/19 国平张 <zhangguoping@xxxxxxxxx>:
> Sorry. The same error, This is new stuff.

Ah indeed - I didn't spot that one as I only read the code rather than ran it.

With the change the parser type to use /newtype/ all the primitive
parsers have to be encoded inside the newtype's constructor
(primitive parsers being ones that have to look directly at the input
stream).

item :: Parser Char
item = Parser $ \inp -> case inp of
                     [] -> []
                     (x:xs) -> [(x,xs)]

Or in a more prosaic style

item :: Parser Char
item = Parser (\inp -> case inp of
                    [] -> []
                    (x:xs) -> [(x,xs)])



This is slightly tiresome. Fortunately once you have defined a small
set of primitive parsers, many more parsers can be "derived" by
combining the primitives rather than looking at the input stream -
this is the power of the monadic style. The p parser you defined with
the do ... notation is one such derived parser.

Best wishes

Stephen
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@xxxxxxxxxxx
http://www.haskell.org/mailman/listinfo/haskell-cafe

<Prev in Thread] Current Thread [Next in Thread>