English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[Caml-list] Allowing many types
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-02-08 (16:37)
From: Ceri Storey <cez@p...>
Subject: Re: [Caml-list] Allowing many types
On Thu, Feb 07, 2002 at 09:29:44PM -0500, Ryan Tarpine wrote:
> type Primitive =
> | PInt of int
> | PString of string
> | PFloat of float
>  ...

>  The problem is, I know that I will need new types in the future besides 
> these.  It's an object-oriented language, and I would like to add classes 
> that manage things like Tk.  Every object has a variable of type Primitive 
> that it stores its value in.  Is it possible to somehow allow other types, 
> like Tk's widgets, without changing the definition of Primitive to include 
> them and recompiling everything?

I've been trying to do something similar with something i'm writing, and
the only thing i could come up with is to store data in an object, and
then subclass it. The problem here is that once the object has been
coerced to the general type, it cannot be coerced back again. ie: if you
subclass the object to say, impliment integers, then it's not possible
for it to be coerced back to the integer type so you can retreive / act
on the value. (withoug using Obj.magic, that is)

If anyone has any good ideas, I'd be happy to hear about them too.
Ceri Storey <cez@pkl.net> http://pkl.net/~cez/
vi(1)! postfix(7)! pie(5)!
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr