haskell 中的字符串与字符串?

string vs String in haskell?

对于类型声明为 here,使用 String

p_pair :: CharParser () (String, Maybe String)

并且在其他一些地方如herestring被使用:

req = ctor <$ string name <* char ' '

注意 Stringstring

之间的大小写差异

Haskell中的Stringstring有什么区别?

一个是a type, the other is a function.

看起来 stringText.Parsec.Char 的函数,而 String 是通常的类型。

事实上,在RealWorldHaskell的同一章中,这个函数在'Choices and Errors;:

下明确提到

This must be done carefully. Recall that our earlier definition of eol was simply char '\n'. There is a parser called string that we can use to match the multi-character patterns. Let's start by thinking of how we would add support for \n\r

在Haskell中值和类型变量名称以小写字母开头,而值和类型构造函数名称、类型同义词和类 以大写字母开头。例如:

data Tree a = Empty
            | Node a (Tree a) (Tree a)

height Empty = 0
height (Node _ l r) = max (height l) (height r) + 1

请注意,Tree 是类型构造函数名称,EmptyNode 是值构造函数名称,height 是函数名称。在你的例子中 String 是类型 "string" 的名称,它只是 [Char] 的同义词,而 string 是一个函数。