为什么这个 GHCi 表达式没有任何输出?
Why doesn't this GHCi expression have any output?
编辑:好的,我知道这没有问题,但我不知道为什么它没有给出输出
let y = 2 * x where x = sum[1..3]
我只是想知道,因为这个其他表达式确实给出了输出
let x = sum[1..3] in 2 * x
Ah. So let ... in ... is an expression. However, let ... can also occur in a do block. I encourage you to think of GHCi's behaviour as follows: if you enter something that just looks like a raw expression, it evaluates it and prints the result. On the other hand, if what you entered looks like it might belong in an IO do block, it will simply execute that action.
- @Alec
编辑:好的,我知道这没有问题,但我不知道为什么它没有给出输出
let y = 2 * x where x = sum[1..3]
我只是想知道,因为这个其他表达式确实给出了输出
let x = sum[1..3] in 2 * x
Ah. So let ... in ... is an expression. However, let ... can also occur in a do block. I encourage you to think of GHCi's behaviour as follows: if you enter something that just looks like a raw expression, it evaluates it and prints the result. On the other hand, if what you entered looks like it might belong in an IO do block, it will simply execute that action. - @Alec