Shane
Shane

Reputation: 2375

Using ParSec integer function to give a Int?

I need to get an Int type from the integer function with Parsec. My code at the moment is

aTerm =  parens aExpression
     <|> liftM GetV identifier
     <|> liftM N integer

Where the type of N is

N    :: Num a => a -> Expr a

The error I am getting is

Shane.hs:227:18:
    Couldn't match expected type `Int' with actual type `Integer'
    Expected type: Text.Parsec.Prim.ParsecT String u0 Identity Int
      Actual type: Text.Parsec.Prim.ParsecT String u0 Identity Integer
    In the second argument of `liftM', namely `integer'
    In the second argument of `(<|>)', namely `liftM N integer'
Failed, modules loaded: none.

Is it possible to extract an Int type here? Using fromInteger some way? Changing from Int to Integer isn't an option.

Upvotes: 0

Views: 249

Answers (1)

dave4420
dave4420

Reputation: 47052

This should work.

aTerm =  parens aExpression
     <|> liftM GetV identifier
     <|> liftM (N . fromInteger) integer

Upvotes: 3

Related Questions