Given the following list from 1 to 100:
> let x = [1..100]
I run sprint x
to observe its unevaluated value.
> :sprint x
x = _
Then, I ran seq
to evaluate it to Weak Head Normal Form:
> seq x ()
()
But re-running sprint x
shows (what I think) is the same value.
> :sprint x
x = _
Why is that?
I think this bheklilr's comment should be marked as the answer:
What is the type of x? If it's
(Num a, Enum a) => [a]
then this won't work as expected. Trylet x = [1..100] :: [Int
]. In reality, when you print x with the more general type GHCi specializes it to Integer to do the printing. This means that the values you see printed are not actually stored back in x's thunk. Using a concrete type avoids this problem.
With the additional note from David Young that this problem won't occur on GHCi versions earlier than 7.8, when the monomorphism restriction was enabled.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With