[clean-list] finding and curing a Space Leak

Erik Zuurbier F.S.A.Zuurbier@inter.nl.net
Mon, 27 Nov 2000 23:07:02 +0100 (MET)


Martin Wierich wrote

>Writing
>
>  :: *Counts      :== *{!(!Real,!Int)}
>
>is the same as writing
>
>  :: *Counts      :== *{!(Real,Int)}
>

Is that because it is a tuple? Is it because the elements are basic types?
Does the array matter?
How does the compiler interpret the types? As a tuple having strict
components, or as a tuple having lazy components? I guess it must be lazy,
given the space leak I had.
In that case, should not the compiler refuse the first type above?

A program is in a way a contract between the programmer and the computer.
They should have the same understanding of it. So I think a plain refusal
of one of the types above would be in order.

A quote from the reference manual (1.2):
"Strictness is a property of data structure which is specified in its type.
In general (with the exceptions of tuples) one cannot arbitrary mix strict
and non-strict data structures because they are considered to be of
different type. So, e.g. if one wants to use list with strict elements or a
spine strict list one has to define new algebraic data types (with
different data constructors). One cannot simply use the predefined notation
for lists because these lists are lazy lists."

And a little furtheron:
"One can define strict tuples, in the same way as defining strict arrays.
This can be done by putting strictness annotations in the type instance on
the tuple elements that one would like to make strict. When the
corresponding tuple is put into a strict context the tuple and the strict
annotated tuple elements will be evaluated."

This all leads me to believe that the strictness-annotations in the first
type above SHOULD make a difference.

>If you do not want your program to build closures for all the "(y-x)*0.9+x"
>expressions then you could also use an array whose elements contain two strict
>values (if you think that's nicer), e.g.:
>
>  :: MyRecord = { real :: !Real, int :: !Int }    // names don't matter here
>

So for a record it DOES matter whether I put strictness marks on the
components. What is the essential difference between a tuple and a two
field record?

Regards Erik Zuurbier