Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: [Caml-list] Type variables won't generalize
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Remi VANICAT <vanicat@l...>
Subject: Re: [Caml-list] Type variables won't generalize
"Ryan Tarpine" <rtarpine@hotmail.com> writes:

> Thank you; that was the explanation I was waiting for!  My next
> question is whether or not there is some non-typesafe route around
> this.  Could I use Obj.magic to store different data types in one
> field, as long as I keep track of what type is really there (e.g.,
> have a second field that would store a number representing the type)
> so I can cast back later?  Sorry if I keep finding myself longing for
> the "void*" C-ism!

well, I don't really see the interest of such things.

If you already know the types you can put in this field, you can use a
new variant type :

type multi =
| Float of float
| Int of int
| Int2float of int -> float
....

otherwise, it seem (to me) that you may find better way of doing it
that using a "void*" C-ism.
-- 
Rémi Vanicat
vanicat@labri.u-bordeaux.fr
http://dept-info.labri.u-bordeaux.fr/~vanicat
-------------------
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