
I'm having the following issue but I have no idea what to do about it, clearly I'm missing something. integer = P.integer lexer identifier = P.identifier lexer data Expression = ID String | Num Integer deriving (Show) name :: Expression name = ID "string" number :: Expression number = Num 123 whileParser :: Parser Expression whileParser = whiteSpace >> expr8 expr8 :: Parser Expression expr8 = name <|> number The error I'm getting is the following: Couldn't match expected type `Text.Parsec.Prim.ParsecT String () Data.Functor.Identity.Identity Expression' with actual type `Expression' In the first argument of `(<|>)', namely `name' In the expression: name <|> number In an equation for `expr8': expr8 = name <|> number Failed, modules loaded: none. Also there is an issue where i have the following code changed: name = ID "string" to name = ID identifier number = Num 123 to number = Num integer which gives me two further errors regarding: Couldn't match expected type `String' with actual type `Text.Parsec.Prim.ParsecT String () Data.Functor.Identity.Identity String' and Couldn't match expected type `Integer' with actual type `Text.Parsec.Prim.ParsecT String () Data.Functor.Identity.Identity Integer' Now I am sure this is something silly but thanks for any help!

On Tue, Feb 12, 2013 at 4:38 PM, Sean Cormican
name :: Expression name = ID "string"
number :: Expression number = Num 123
whileParser :: Parser Expression whileParser = whiteSpace >> expr8
expr8 :: Parser Expression expr8 = name <|> number
You have defined name to be an Expression. But <|> composes *parsers*, not expressions. To create a Parser Expression, you would be composing (Parser Expression)s, not simply (Expression)s; so you don't want "name" to be simply an Expression, but a Parser that parses an input String and produces an Expression, something like name :: Parser Expression name = ID <*> identifier -- parse an identifier, wrap it in an ID number :: Parser Expression number = Num <*> integer -- parse an integer, wrap it in a Num -- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
participants (2)
-
Brandon Allbery
-
Sean Cormican