2012-11-25 3 views
0

Parsec을 사용하여 정수 함수에서 Int 유형을 가져와야합니다. N의 유형ParSec 정수 함수를 사용하여 Int?

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 타입을 추출하는 것입니다 무엇입니까 오류 인 경우 순간에 내 코드

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

입니까? fromInteger를 어떤 방법으로 사용합니까? Int에서 Integer로 변경하는 것은 옵션이 아닙니다.

+1

사용 사례에 따라, 확인해야 할 수도 있습니다 여부를 분석'Integer'는'Int' 범위에 있으며, 구문 분석에 실패하지합니다. –

답변

3

이렇게하면됩니다.

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