I understand a `seq` b
as "be strict on a and compute b", so undefined `seq` True
throws and Exception.
I am playing around with :sprint
and tried following test in ghci:
Prelude> x = [True, undefined]
Prelude> :sprint x
x = _
Okay, because x
was not computed yet
Prelude> x `seq` True
True
Prelude> :sprint x
x = _
Why x = _
at this moment? I thought that seq
will evaluate x
at least to _:_
(or more possibly True:_
), but its value still remains completely latent. It needs somehow check whether x
is not undefined
, so it needs to perform kind of evaluation, but why doesn't it keep the result?
I am using GHC 8.6.3
x = True : _
for the last:sprint
:t x
to check thatx :: [Bool]
, as it should.() <$ evaluate x
instead, then it behaves as expected. I suggest you file a GHC tiicket.undefined
is irrelevant. The same happens if you usex = [True, False]
.