In the tutorial What I Wish I Knew When Learning Haskell there is this interaction inside GHCi regarding the use of the :sprint
command to inspect the state of evaluation of some variable:
λ: let a = [1..] :: [Integer]
λ: :sprint a
a = _
λ: a !! 4
5
λ: :sprint a
a = 1 : 2 : 3 : 4 : 5 : _
However, if we ommit the part :: [Integer]
from the definition of a
, the last call to :sprint a
will return a = _
and not a = 1 : 2 : 3 : 4 : 5 : _
.
Why?
ANSWER: the monomorphism restriction must be turned on/off inside GHCi via :set -XMonomorphismRestriction
and :set -XNoMonomorphismRestriction
(see Reid Barton's comment below). And the best explanation I found for :sprint
behavior is here.