The GHC manual states this about monadic binding in GHCI:
Another important difference between the two types of binding is that the monadic bind (p <- e) is strict (it evaluates e), whereas with the let form, the expression isn’t evaluated immediately:
(from here)
But I can do this in GHCI:
λ: x <- return $ error ":("
λ: :sprint x
x = _
This seems to show that the monadic bind is not strict. What am I missing?
x <- error ":("
andx <- return $ error ":("
are different expressions – user2407038let e = return $ error ":("; p <- e; :sprint e
, but it turns out that even evaluatedIO
actions getsprint
ed as_
. Bummer! But tryp <- Debug.Trace.trace "yep, got evaluated" $ return $ error ":("
for evidence that the action (if not its return value) is indeed getting evaluated as promised. – Daniel Wagner