Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Polymorphism and the "for" loop
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-10-22 (09:39)
From: Andreas Rossberg <rossberg@p...>
Subject: Re: [Caml-list] Polymorphism and the "for" loop
On Fri, Oct 22, 2004 at 08:38:49AM +0100, Jon Harrop wrote:
>I've been wondering about this recently: how do the compilers store types 
>which contain "unit". For example, if we have a tree:
>type 'a 'b tree = Leaf of 'a | Node of 'b * 'a 'b tree * 'a 'b tree
>Does a "unit unit tree" take up less space than a "int int tree"?

No, because the representation must be the same. Otherwise polymorphic 
functions could not operate on both. (Besides, you got the syntax wrong. 
It's ('a,'b) tree.).

If you rephrase the question as


   type unit_tree = Leaf of unit | Node of unit * unit_tree * unit_tree

have a more efficient representation than

   type int_tree = Leaf of int | Node of int * int_tree * int_tree


you _might_ find a different answer. But in fact you don't, the 
representation still is the same. And I believe it is right for the 
compiler not to bother optimising types like unit_tree, because they are 
not very useful.

>The reason I'm asking is that it might be nice to generalise data structures 
>as much as possible and then specialise them using "unit" arguments.

This definitely won't work.


	- Andreas

Andreas Rossberg,

Let's get rid of those possible thingies!  -- TB

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: