Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
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

"Does

   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.

Cheers,

	- Andreas

-- 
Andreas Rossberg, rossberg@ps.uni-sb.de

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

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners