Consider this program:
module Main where main ∷ IO ( ) main = do x ← readLn let xs = [1..x] -- Location 1. `xs` is not yet evaluated. print xs -- Location 2. `xs` is evaluated. return ( )
Statements in a
do block are executed in the sequence that they are written. So, locations between statements correspond to moments of «logical time». Further, to every moment, and thus to every location, corresponds a state of memory containing all the values that are in scope at that location.
In the code above, the value
xs is visible both from location 1 and location 2. But, due to laziness, the state of memory is not the same at the corresponding moments.
- At the moment 1,
xsis a thunk
enumFromTo 1 x.
- At the moment 2,
xsis something like
Cons 1 (Cons 2 …), made of data constructors, and free from thunks.
How do I refer to the abstract representation of a value in memory in terms of data constructors and thunks? What is the terminology? What are these things that both represent the same value