On 6/4/07, Juozas Gaigalas <[EMAIL PROTECTED]> wrote:
Hello,

I am a somewhat experienced programmer and a complete Haskell newbie, so I
hope this is the correct ML for my question.

I have decided to learn Haskell and started with  Graham Hutton's book.
Everything was going nicely until section 8.4, on sequencing functional
parsers. I am trying to write an elementary parser that produces the 1st and
3d elements from a string. I am using the code from the book.

---------------------

 type Parser a = String -> [(a, String)]

 return :: a -> Parser a
 return v = \inp -> [(v, inp)]

 failure :: Parser a
 failure = \inp -> []


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


 parse :: Parser a -> String -> [(a, String)]
 parse p inp = p inp


 (>>=) :: Parser a -> (a -> Parser b) -> Parser b
 p >>= f = \inp -> case parse p inp of
                   [] -> []
                   [(v, out)] -> parse (f v) out


 p :: Parser (Char, Char)
 p = do x <- item
        item
        y <- item
        return (x, y)  -- LINE 34
 --------------------

BUT, when I try to :load parse.hs from hugs I get the following error:

ERROR "parse.hs":34 - Last generator in do {...} must be an expression

Although the error is not really friendly (your "supposedly" last
generator in do is an expression) the problem probably is indentation:

Try like this

 p = do x <- item
            item
            y <- item
            return (x, y)  -- LINE 34

Hugs is probably complaining because it identifies "x <- item" (which
is not a simple expression) as the last element of do.
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to