從Text.Parsec.Token
:我不明白如何使用語義功能
lexeme p = do { x <- p; whiteSpace; return x }
看來,語義需要一個解析器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
我在做什麼錯?