[Haskell-cafe] Re: Large data structures

Benjamin Franksen benjamin.franksen at bessy.de
Mon Dec 11 21:07:57 EST 2006

Alex Queiroz wrote:
> On 12/11/06, Stefan O'Rear <stefanor at cox.net> wrote:
>> No.  Haskell's lists are linked lists, enlarge creates a single new link
>> without modifying (and copying) the original.
>      Thanks. Is there a way to mimic this behaviour with my own code?

It is the default for any data structure you define. Data is by default
represented internally as a pointer to the actual value. Otherwise
recursive structures (see below for an example) would not be easily
possible. And since no part of the data structure is 'mutable', different
instances can share (memory-wise) as much of their structure as the
implementation is able to find.

BTW apart from the special syntax (like [a,b,c]) there is nothing special
about lists. E.g. with this data type definition

data List a = Nil | Cons a (List a)

(List a) is completely equivalent to [a].


PS: Please try to include exactly the relevant context in replies, no more,
no less. Your original question (stripped down to the body of the text)
would have been relevant, here, but neither 'Hello', nor 'Cheers' are worth

More information about the Haskell-Cafe mailing list