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
Re: [Caml-list] Another q about 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-18 (14:16)
From: Martin Jambon <m.jambon@i...>
Subject: Re: [Caml-list] Another q about many types
On Fri, 15 Feb 2002, Ryan Tarpine wrote:

> Unfortunately, this means that in order to raise an exception with an object
> of type my_object, not only its own object_data but the data of all the
> variables stored in object_ivs must be of the same type.  I've tried making
> the exception type like this:
>   type allowed_exc = [ `PNone | `PInteger of int | `PFloat of float |
> `PString of string ];;
>   exception EError of allowed_exc my_object;;
> to make the type of allowed exceptions somewhat lax.  But, given a single
> ('a my_object), how can I coerce it to an (allowed_exc my_object) if
> possible?  It has to recursively coerce all the variables in object_ivs.
> I've never done coercion at all before.

Try the following

  raise (EError (obj :> allowed_exc my_object))

instead of

  raise (EError obj)


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