[Haskell-beginners] how to know if a value has already been evaluated?

Ut Primum utprimum at gmail.com
Sun Mar 18 13:37:31 UTC 2018


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].

Is something like this possible in Haskell?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20180318/df35151a/attachment.html>


More information about the Beginners mailing list