Prelude> let a = 3
Prelude> :sprint a
a = _
Prelude> let c = \"ab\"
Prelude> :sprint c
c = _
Why does it always print a _
?
Haskell is lazy. It doesn't evaluate things until they are needed.
The GHCi sprint
command (not part of Haskell, just a debugging command of the interpreter) prints the value of an expression without forcing evaluation.
When you write
let a = 3
you bind a new name a
to the right-hand side expression, but Haskell won't evaluate that thing yet. Therefore, when you sprint
it, it prints _
as the value to indicate that the expression has not yet been evaluated.
Try this:
let a = 3
:sprint a -- a has not been evaluated yet
print a -- forces evaluation of a
:sprint a -- now a has been evaluated