GHCi 提示符下的声明
我刚刚安装了 Haskell Platform for Windows(版本 2011.2.0.1),并开始处理 HaskellQuestions.pdf
第二个问题需要“x = 3”作为答案。但是当我将其输入 GHCi 时,我得到了
GHCi, version 7.0.3: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package ffi-1.0 ... linking ... done.
Prelude> x = 3
<interactive>:1:3: parse error on input `='
Prelude>
为什么?我检查了答案,我是对的。等号有什么问题吗?
I have just installed Haskell Platform for Windows (version 2011.2.0.1), and started to work through the HaskellQuestions.pdf
The second question requires "x = 3" as the answer. But when I enter this into GHCi I get
GHCi, version 7.0.3: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package ffi-1.0 ... linking ... done.
Prelude> x = 3
<interactive>:1:3: parse error on input `='
Prelude>
Why? I checked the answer, and I am right. Whats the matter with the equals sign?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 GHCi 中,要分配一个值,您必须
在常规 Haskell 代码中,
x = 3
是有效的(请参见下面的注意事项)。真实世界 Haskell 的 入门 页面包含许多有关使用 GHCI 的有用信息。
您还可以查看GHCi 文档 (但就我个人而言,我发现 Real World Haskell 更容易理解)。
注意:正如 EdvardM 在注释中指出的那样,在此上下文中使用
let
的语法来自 < a href="http://www.haskell.org/ghc/docs/7.0.3/html/users_guide/interactive-evaluation.html#ghci-stmts" rel="nofollow noreferrer">Haskell 的 do 表示法(如果你刚刚开始,如果你有点迷失,不要给自己太大压力。慢慢来,享受乐趣,它应该很快就会有意义)。In GHCi, to assign a value, you have to go
In regular Haskell code,
x = 3
would be valid (see NB below).Real World Haskell's Getting Started page has lots of useful info about using GHCI.
You can also look at the documentation for GHCi (but personally, I find Real World Haskell a little more digestable).
N.B. As EdvardM notes in the comments, the syntax for using
let
in this context is from Haskell's do notation (if you're just beginning, don't stress yourself out if you're a little lost. Take your time, have fun, and it ought to make sense in no time).