I have a hard time grasping this. When writing in do notation, how are the following two lines different?
1. let x = expression
2. x <- expression
I can’t see it. Sometimes one works, some times the other. But rarely both. “Learn you a haskell” says that <- binds the right side to the symbol on the left. But how is that different from simply defining x with let?
The
<-statement will extract the value from a monad, and theletstatement will not.When run, the program will ask for the value of x, because the monadic action
readInt "x"is executed by the<-statement. It will not ask for the value of y, becausereadInt "y"is evaluated but the resulting monadic action is not executed.Since
x :: Int, you can do normalIntthings with it.Since
y :: IO Int, you can’t pretend that it’s a regularInt.