how to know if a value has already been evaluated?
In Haskell, the value of a variable is not always evaluated.
This is fundamental when working with infinite lists.
Is there a way of determining whether, at a certain point of the execution of a program, a value has been calculated or not?
In particular, I would like to write a function that works on an infinite list that:
- if the first value of a list, x, has already been evaluated, returns [x]
- Else waits until it is evaluated, but without forcing its evaluation. (eventually, its evaluation will be forced later by other functions). Until then, the result of this function must be considered as [ ]. As soon as x is computed, it can return [x].