Version française
Home     About     Download     Resources     Contact us    
Browse thread
Exceptions polymorphes
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Christophe Raffalli <raffalli@u...>
Subject: Re: Exceptions polymorphes
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 *)