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
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" <> 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
To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: