我期待找到一个功能
integer :: Stream s m Char => ParsecT s u m Integer
Run Code Online (Sandbox Code Playgroud)
或者甚至是
natural :: Stream s m Char => ParsecT s u m Integer
Run Code Online (Sandbox Code Playgroud)
在标准库中,但我没有找到一个.
将纯自然数直接解析为Integer?的标准方法是什么?
我有以下类型检查:
p_int = liftA read (many (char ' ') *> many1 digit <* many (char ' '))
Run Code Online (Sandbox Code Playgroud)
现在,正如函数名称所暗示的那样,我希望它能给我一个Int.但如果我这样做:
p_int = liftA read (many (char ' ') *> many1 digit <* many (char ' ')) :: Int
Run Code Online (Sandbox Code Playgroud)
我收到这种类型的错误:
Couldn't match expected type `Int' with actual type `f0 b0'
In the return type of a call of `liftA'
In the expression:
liftA read (many (char ' ') *> many1 digit <* many (char ' ')) ::
Int
In an equation for `p_int': …Run Code Online (Sandbox Code Playgroud)