来自Text.Parsec.Token
:
lexeme p = do { x <- p; whiteSpace; return x }
似乎 lexeme 采用解析器 p 并提供与 p 具有相同行为的解析器,除了它还跳过所有尾随空格。正确的?
那么为什么以下不起作用:
constant :: Parser Int
constant = do
digits <- many1 digit
return (read digits)
lexConst :: Parser Int
lexConst = lexeme constant
最后一行导致以下错误消息:
Couldn't match expected type `ParsecT
String () Data.Functor.Identity.Identity Int'
with actual type `ParsecT s0 u0 m0 a0 -> ParsecT s0 u0 m0 a0'
Expected type: Parser Int
Actual type: ParsecT s0 u0 m0 a0 -> ParsecT s0 u0 m0 a0
In the return type of a call of `lexeme'
In the expression: lexeme constant
我究竟做错了什么?