[Haskell-beginners] Parsec simple question

Sean Cormican seancormican1 at gmail.com
Tue Feb 12 22:38:52 CET 2013


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!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20130212/9ac63501/attachment.htm>


More information about the Beginners mailing list