GHCi“让” - 它有什么作用? [英] GHCi "let" -- what does it do?

查看:159
本文介绍了GHCi“让” - 它有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望有人能够指出关于GHCi中让做什么的文档,或者说失败了,可以令人信服地解释:-)。



据我所知,let(不含in)本身不是Haskell语言的一部分,另一方面,因为它没有用冒号作为前缀。

解决方案

在GHCi编程时,你就像使用 do 语法编程IO monad,例如,您可以直接执行 IO 操作,或者使用monadic bind语法如 r < - someIOFun

let 也是 do 的一部分,所以你也可以使用这个。我认为它被解析成 let .. in<其余计算> ,例如当你这样做时:

  ghci>让a = 1 
ghci> someFun
ghci> someFun2

这就像:

  let a = 1 in 
do someFun
someFun2


I'd appreciate is someone could point to docs on what "let" does in GHCi, or failing that, explain it convincingly :-).

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.

解决方案

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

It's like:

let a = 1 in
do someFun
   someFun2

这篇关于GHCi“让” - 它有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆