0

Edit: Okay, I know nothing is wrong with this, but I don't know why it isn't giving output

let y = 2 * x where x = sum[1..3]

I only wonder, because this other expression DOES give output

let x = sum[1..3] in 2 * x
TurboCrackers
  • 43
  • 1
  • 10
  • Nope. I edited my question to reflect what I was trying to ask in more detail. I have one let that is giving output 12, but the other let is not giving any output – TurboCrackers Sep 15 '16 at 03:44
  • 3
    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 Sep 15 '16 at 03:50
  • Ohhh thank you!! That makes a ton of sense! – TurboCrackers Sep 15 '16 at 03:52

1 Answers1

2

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

TurboCrackers
  • 43
  • 1
  • 10