作者:徐韵茜YUNXI | 来源:互联网 | 2022-12-05 13:01
只想澄清这是我编程的第一天,我意识到这个问题是多么愚蠢:D
1)为什么不起作用?
ghci>''hello'' ++ ''world''
:40:1: error
* Syntax error on ''hello''
Perhaps you intended to use TemplateHaskell or TemplateHaskellQuotes
* In the Template Haskell quotation ''hello''
ghci>''hello'' ++ '' '' ++ ''world''
:41:17: error: parse error on input '''
我应该在texteditor中添加一些内容以使其正常工作吗?或者我只是做了一些菜鸟错误?
2)
ghci> ''Steve'' !! 2
: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
当我使用数字执行这些命令时,它可以工作,但不能使用字符.我一定做错了什么,但我不确定是什么:/
提前致谢!
1> Willem Van O..:
字符串被双引号(如".."
)括起来,而不是两个单引号(如''..''
).因此你应该使用"
而不是'
.
例如:
$ 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"
.
根据这篇文章,可以在Mac键盘上用+ 编写直接双引号,这是在"标准"querty键盘上组织的方式:Shift'
在任何典型的键盘上,只需按下'一个直的单个标记('
)和Shift+ '一个直的双重标记("
).
根据@ M.Aroosi的评论,对于英国的querty键盘,"
是Shift+2
@TobiasBernhardt Stack Overflow不是一个论坛 - 它没有"线程",[每个问题应该是它自己的问题](https://meta.stackexchange.com/questions/222735/can-i-ask-only-one -question每后).事实上,这个问题实际上应该是两个问题.
@TobiasBernhardt很难想象你不能在键盘上输入双引号.你来自哪个国家?这可能像威廉所说的那样转移+单引号.(只是确保你听到了他)