GHCi“让"- 它有什么作用? [英] GHCi "let" -- what does it do?
问题描述
如果有人能指出有关让"什么的文档,我将不胜感激.在 GHCi 中做到了,或者没有做到这一点,请令人信服地解释它.
I'd appreciate if someone could point to docs on what "let" does in GHCi, or failing that, explain it convincingly.
据我所知,让"(没有in")本身不是 Haskell 语言的一部分,另一方面,它似乎也不是 GHCi 命令,因为它没有以冒号为前缀.
So far as I can tell, "let" (without "in") is not part of the Haskell language per se, and on the other hand, it doesn't appear to be a GHCi command either, as it's not prefixed by colon.
推荐答案
在 GHCi 中编程时,您就像使用 do
语法在 IO monad 中编程,因此例如您可以直接执行一个IO
动作,或者使用像 r <- someIOFun
这样的 monadic 绑定语法.
While programming in GHCi, you're like programming in the IO monad with do
syntax, so for example you can directly execute an IO
action, or use monadic bind syntax like r <- someIOFun
.
let
也是 do
的一部分,所以你也可以使用它.我认为它被去除为 let .. in <rest of the computing>
,所以例如当你这样做时:
let
is also a part of do
so you can also use this. I think it's being desugared into let .. in <rest of the computation>
, so for example when you do this:
ghci> let a = 1
ghci> someFun
ghci> someFun2
就像:
let a = 1 in
do someFun
someFun2
这篇关于GHCi“让"- 它有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!