考虑:
ghci> :t'a''a':: Char ghci> :taa:: [Char]为什么要治疗单引号和双引号的区别是不同的,并且是那么重要?解析方案
这与C / C ++ / C#/ Java和其他编程语言。单引号表示单字符,双引号表示字符数组(字符串)。
在Haskell中,'c'是一个字符( Char )和c是一个字符列表( [您可以将此与整数和整数列表进行比较: pre> ghci的>让a = 1 ghci>让b = [1,2,3] ghci> :t a a :: Integer ghci> :tb b :: [Integer]
这很重要,因为必须有一个区别单个元素和元素列表之间。您可以对简单元素执行不同的操作,并对列表执行不同的操作。
Consider:
ghci> :t 'a' 'a' :: Char ghci> :t "a" "a" :: [Char]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, 'c' is a single character (Char), and "c" is a list of characters ([Char]).
You can compare this to integers and lists of integers:
ghci> let a = 1 ghci> let b = [1,2,3] ghci> :t a a :: Integer ghci> :t b b :: [Integer]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中的单引号和双引号
发布评论