【发布时间】:2017-04-24 17:17:25
【问题描述】:
我正在尝试用 Haskell 编写解析器。在这我需要一个解析长度至少为 1 的字符串的函数。我有下面声明的类型:
type Pname = String
但是我的功能不起作用。我的代码如下,sc 是我的空白和 cmets 的空间使用者(我一直在关注https://mrkkrp.github.io/megaparsec/tutorials/parsing-simple-imperative-language.html 的教程以获取有关此解析器的帮助):
pname :: Parser Pname
pname = (some ['a' .. 'z']) <* sc
但它给了我错误:
Couldn't match type ‘[]’
with ‘ParsecT Dec String Data.Functor.Identity.Identity’
Expected type: ParsecT
Dec String Data.Functor.Identity.Identity Char
Actual type: [Char]
In the first argument of ‘some’, namely ‘['a' .. 'z']’
In the first argument of ‘(<*)’, namely ‘(some ['a' .. 'z'])’
In the expression: (some ['a' .. 'z']) <* sc
关于为什么这不起作用的任何想法?
【问题讨论】:
标签: haskell