gpt4 book ai didi

haskell - ''hello' '++ '' 世界 '' doesn' t 在 Haskell 中工作

转载 作者:行者123 更新时间:2023-12-05 08:53:52 25 4
gpt4 key购买 nike

只是想澄清一下,这是我第一天编程,我意识到这个问题是多么愚蠢:D

1) 为什么它不起作用?

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 '''

我应该在文本编辑器中添加一些东西来让它工作吗?还是我只是犯了一些菜鸟错误?

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

当我使用数字执行这些命令时,它可以工作,但不能使用字符。我一定是做错了什么,但我不确定是什么:/

提前致谢!

最佳答案

字符串被双引号包围(如".."),而不是两个单引号(如'' ..'').因此,您应该使用 " 而不是 '

例如:

$ ghci
GHCi, version 8.0.2: http://www.haskell.org/ghc/ :? for help
Prelude> "hello" ++ "world"
"helloworld"
Prelude> "hello" ++ " " ++ "world"
"hello world"

这在 Haskell report 2010 section on 'Character and String Literals' 中指定:

Character literals are written between single quotes, as in 'a', and strings between double quotes, as in "Hello".

基于 this article , 可以在 Mac 键盘上使用 Shift + ' 编写直双引号,这是它在“标准”查询上的组织方式键盘:

On any typical keyboard, simply press ' for a straight single mark (') and Shift + ' for a straight double mark (").

基于 @M.Aroosi's comment , 对于 UK querty 键盘,"Shift+2

关于haskell - ''hello' '++ '' 世界 '' doesn' t 在 Haskell 中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52246049/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com