``hello''++``world''在Haskell中不起作用 [英] ''hello'' ++ ''world'' doesn't work in Haskell
问题描述
只想澄清一下这是我的第一天编程,所以我意识到这个问题是多么愚蠢:D
Just want to clarify that it's my first day programming, and I realise how dumb this question is :D
1)为什么不起作用?
1) Why doesn't it work?
ghci>''hello'' ++ ''world''
<interactive>:40:1: error
* Syntax error on ''hello''
Perhaps you intended to use TemplateHaskell or TemplateHaskellQuotes
* In the Template Haskell quotation ''hello''
ghci>''hello'' ++ '' '' ++ ''world''
<interactive>:41:17: error: parse error on input '''
我应该在文本编辑器中添加一些东西使其工作吗?还是我只是犯了一些菜鸟错误?
Should I add something in the texteditor to make it work? Or did I just do some rookie mistake?
2)
ghci> ''Steve'' !! 2
<interactive>:42:2: error
* Syntax error on ''Steve''
Perhaps you intended to use TemplateHaskell or TemplateHaskellQuotes
* In the Template Haskell quotation ''Steve''
ghci>[1,2,3,5,8] !! 2
3
当我用数字执行这些命令时,它可以工作,但不能用字符.我一定做错了,但是我不确定:/
When I do these commands with numbers it works, but not with characters. I must be doing something wrong, but I'm not sure what :/
提前谢谢!
推荐答案
字符串用双引号包围(例如".."
),而不是两个单引号(如''..''
).因此,您应该使用"
而不是'
.
Strings are surrounded by double quotes (like ".."
), not two single quotes (as in ''..''
). You thus should use "
instead of '
.
例如:
$ ghci
GHCi, version 8.0.2: http://www.haskell.org/ghc/ :? for help
Prelude> "hello" ++ "world"
"helloworld"
Prelude> "hello" ++ " " ++ "world"
"hello world"
这在 Haskell报告2010部分中针对字符和字符串文字' :
字符文字写在单引号之间,如
'a'
,而字符串则写在双引号之间,如"Hello"
.
Character literals are written between single quotes, as in
'a'
, and strings between double quotes, as in"Hello"
.
基于这篇文章,人们可以在双引号上写上具有 Shift + '的Mac键盘,这是在标准"质询键盘上进行组织的方式:
Based on this article, one can write straight double quotes on a Mac keyboard with Shift + ', which is the way it is organized on a "standard" querty keyboard:
在任何典型的键盘上,只需按'即可获得一个连续的单个标记(
'
)和 Shift + '表示直双标记("
).
On any typical keyboard, simply press ' for a straight single mark (
'
) and Shift + ' for a straight double mark ("
).
基于 @ M.Aroosi的评论,对于英国的通用键盘,"
是 Shift + 2
Based on @M.Aroosi's comment, for a UK querty keyboard, the "
is Shift+2
这篇关于``hello''++``world''在Haskell中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!