[英]string vs String in haskell?
For type declarations as here , String
is used: 对于此处的类型声明,使用
String
:
p_pair :: CharParser () (String, Maybe String)
And in some other places as here , string
is used: 在这里的其他一些地方,使用
string
:
req = ctor <$ string name <* char ' '
Note the capitalization difference between String
and string
请注意
String
和string
之间的大小写差异
What is the difference between String
and string
in Haskell? Haskell中
String
和string
什么区别?
In Haskell value and type variable names start with a lower-case letter while value and type constructor names, type synonyms, and classes start with a capital letter. 在Haskell中, 值和类型变量名称以小写字母开头,而值和类型构造函数名称,类型同义词和类以大写字母开头。 For example:
例如:
data Tree a = Empty
| Node a (Tree a) (Tree a)
height Empty = 0
height (Node _ l r) = max (height l) (height r) + 1
Note that Tree
is a type constructor name, Empty
and Node
are value constructor names and height
is a function name. 请注意,
Tree
是类型构造函数名称, Empty
和Node
是值构造函数名称, height
是函数名称。 In your case String
is the name of the type "string" which is simply a synonym for [Char]
, while string
is a function. 在你的情况下,
String
是“string”类型的名称,它只是[Char]
的同义词,而string
是一个函数。
Looks like string
is the function from Text.Parsec.Char
while String
is the usual Type. 看起来
string
是Text.Parsec.Char
的函数,而String
是常用的Type。
In fact, in the same chapter of RealWorldHaskell , this function is explicitly mentioned under 'Choices and Errors;: 实际上,在RealWorldHaskell的同一章中,在“选择和错误”中明确提到了这个函数:
This must be done carefully.
这必须小心。 Recall that our earlier definition of eol was simply char '\\n'.
回想一下,我们之前对eol的定义只是char'\\ n'。 There is a parser called string that we can use to match the multi-character patterns.
我们可以使用一个名为string的解析器来匹配多字符模式。 Let's start by thinking of how we would add support for \\n\\r
让我们首先考虑如何添加对\\ n \\ r \\ n的支持
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.