Haskell中的单引号和双引号 [英] Single vs. double quotes in Haskell
问题描述
考虑:
ghci> :t'a'
'a':: Char
ghci> :ta
a:: [Char]
为什么要治疗单引号和双引号的区别是不同的,并且是那么重要?解析方案
这与C / C ++ / C#/ Java和其他编程语言。单引号表示单字符,双引号表示字符数组(字符串)。
在Haskell中, 这很重要,因为必须有一个区别单个元素和元素列表之间。您可以对简单元素执行不同的操作,并对列表执行不同的操作。 Consider: Why is it treating single and double quotes differently, and is that important? This is just like C/C++/C#/Java and other programming languages. Single quotes means single character, double quotes means character array (string). In Haskell, You can compare this to integers and lists of integers: It is important because there has to be a distinction between single elements and a list of elements. You can perform different operations on simple elements, and different operations on lists. 这篇关于Haskell中的单引号和双引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!'c'
是一个字符( Char
)和c
是一个字符列表( [您可以将此与整数和整数列表进行比较:
pre> ghci的>让a = 1
ghci>让b = [1,2,3]
ghci> :t a
a :: Integer
ghci> :tb
b :: [Integer]
ghci> :t 'a'
'a' :: Char
ghci> :t "a"
"a" :: [Char]
'c'
is a single character (Char
), and "c"
is a list of characters ([Char]
).ghci> let a = 1
ghci> let b = [1,2,3]
ghci> :t a
a :: Integer
ghci> :t b
b :: [Integer]