0

Parsec で整数関数から Int 型を取得する必要があります。現時点での私のコードは

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

N の型はどこですか

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

私が得ているエラーは

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.

ここで Int 型を抽出することはできますか? 何らかの方法で fromInteger を使用していますか? Int から Integer への変更はオプションではありません。

4

1 に答える 1

3

これはうまくいくはずです。

aTerm =  parens aExpression
     <|> liftM GetV identifier
     <|> liftM (N . fromInteger) integer
于 2012-11-25T17:23:39.383 に答える