[Haskell-cafe] newbie question on Parsers from "Programming In
Haskell"
Juozas Gaigalas
juozas at tuesdaystudios.com
Mon Jun 4 10:42:35 EDT 2007
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
I have no idea what I am doing wrong and why Hugs is complaining. I hope
this question is not too simply for this mailing list, but I have honestly
googled for an answer and had found nothing.
Juozas Gaigalas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20070604/bb77d15e/attachment.htm
More information about the Haskell-Cafe
mailing list