(cyclic list with constant space consumption)
Revision as of 08:21, 29 November 2007
Non-strict semantics allows to bypass undefined values (e.g. results of infinite loops) and this way it also allows to process formally infinite data.
When it comes to machine level and efficiency issues then it is important whether equal objects share the same memory.A Haskell program cannot observe whether
In many cases it is also not necessary to know it, but in some cases the difference between shared and separated objects yields different orders of space or time complexity.Consider the infinite list
But with lazy evaluation (i.e. sharing) this becomes a list with a loop, a pointer back to the beginning. It does only consume constant space. In an imperative language (here Modula-3) the same would be achieved with the following code:
TYPE List = REF RECORD next: List; value: INTEGER; END;
VAR x := NEW(List, value:=1); BEGIN x.next := x; END;