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

> Many thanks for the advice on polymorphic variants; they seemed to be just
> what I needed.  But I've run into one small problem:  I can't define
> exceptions with arguments of polymorphic types.
> In the language I'm trying to implement, to raise an exception, the user
> needs to create an instance of an exception class.  So, in my
> implementation, I wanted to define an exception whose sole argument would be
> an instance of a class.  But, I designed instances to be records containing
> a polymorphic variant, which makes the record type itself polymorphic.  Is
> there some way to raise exceptions with polymorphic arguments, or some other
> possible way of implementing this?

Maybe something like this:

exception E of exn
exception E_1 of t1
exception E_2 of t2

try ... with
  E e ->
    match e with
       E_1 x1 -> x1
     | E_2 x2 -> some_conversion_to_t1 x2


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