caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Exceptions polymorphes
@ 1997-11-18 13:57 Pascal Zimmer
  1997-11-18 15:12 ` David Monniaux
  1997-11-18 17:59 ` Christophe Raffalli
  0 siblings, 2 replies; 3+ messages in thread
From: Pascal Zimmer @ 1997-11-18 13:57 UTC (permalink / raw)
  To: caml-list; +Cc: Pascal.Zimmer

Pourquoi n'est-il pas possible de definir des exceptions renvoyant un
type quelconque:

#exception Found of 'a;;
Toplevel input:
>exception Found of 'a;;
>                   ^^
The type variable a is unbound.

Comme les exceptions exn sont un type comme un autre, je ne vois pas de
raison theorique empechant ce genre de declaration.



-------------------------------------------------------------------
  Pascal Zimmer  -  Ecole Normale Superieure de Lyon  -  France
-------------------------------------------------------------------





^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Exceptions polymorphes
  1997-11-18 13:57 Exceptions polymorphes Pascal Zimmer
@ 1997-11-18 15:12 ` David Monniaux
  1997-11-18 17:59 ` Christophe Raffalli
  1 sibling, 0 replies; 3+ messages in thread
From: David Monniaux @ 1997-11-18 15:12 UTC (permalink / raw)
  To: Pascal Zimmer; +Cc: caml-list

[ Why exceptions can't be polymorphic... ]

On Tue, 18 Nov 1997, Pascal Zimmer wrote:

> Comme les exceptions exn sont un type comme un autre, je ne vois pas de
> raison theorique empechant ce genre de declaration.

Quelle serait dans ce cas la semantique de:

exception Found of 'a;;

try
  raise (Found 1)
with
  Found x -> print_string;;

Pour que cela reste type-safe, il faudrait que l'on teste si les parties
polymorphes de l'exception renvoyee sont bien compatibles avec les
contraintes de types des variables du pattern-matching.

Cela revient a implementer un peu de la surcharge dynamique.

(Sauf erreur de ma part a faire reparer par les experts.)





^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Exceptions polymorphes
  1997-11-18 13:57 Exceptions polymorphes Pascal Zimmer
  1997-11-18 15:12 ` David Monniaux
@ 1997-11-18 17:59 ` Christophe Raffalli
  1 sibling, 0 replies; 3+ messages in thread
From: Christophe Raffalli @ 1997-11-18 17:59 UTC (permalink / raw)
  To: Pascal Zimmer; +Cc: caml-list

If you do what you suggest, the following program crashes (and is well
typed *)

exception Found of 'a;;

let rec assoc_exn n = function
  [] -> raise Not_found
| ((x,y)::l) -> 
  if x = n then raise Found y else assoc_exn n l

try
  assoc_exn 1 [1,2]
with 
  Found x -> print_string x (* x will be an integer, not a string *)




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1997-11-19  8:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-11-18 13:57 Exceptions polymorphes Pascal Zimmer
1997-11-18 15:12 ` David Monniaux
1997-11-18 17:59 ` Christophe Raffalli

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).