Evaluating List to Weak Head Normal Form

前端 未结 1 1489
面向向阳花
面向向阳花 2021-01-01 20:07

Given the following list from 1 to 100:

> let x = [1..100]

I run sprint x to observe its unevaluated value.



        
相关标签:
1条回答
  • 2021-01-01 21:00

    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. Try let 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.

    0 讨论(0)
提交回复
热议问题