相关疑难解决方法(0)

如何使用parsec解析Integer

我期待找到一个功能

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?的标准方法是什么?

haskell parsec

5
推荐指数
1
解决办法
3595
查看次数

如何让Parsec让我调用`read` :: Int?

我有以下类型检查:

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)

haskell parsec

2
推荐指数
2
解决办法
1424
查看次数

标签 统计

haskell ×2

parsec ×2