From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id JAA01266 for caml-red; Thu, 1 Feb 2001 09:28:11 +0100 (MET) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id BAA23871 for ; Thu, 1 Feb 2001 01:38:03 +0100 (MET) Received: from mx1.informatik.uni-tuebingen.de (mx1.Informatik.Uni-Tuebingen.De [134.2.12.5]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f110c2X13599 for ; Thu, 1 Feb 2001 01:38:02 +0100 (MET) Received: from sunstroke.informatik.uni-tuebingen.de (sunstroke [134.2.11.25]) by mx1.informatik.uni-tuebingen.de (Postfix) with ESMTP id CB8C14AC for ; Thu, 1 Feb 2001 01:38:01 +0100 (MET) Received: (from pfitzen@localhost) by sunstroke.informatik.uni-tuebingen.de (8.9.3+Sun/8.9.1) id BAA12641 for caml-list@inria.fr; Thu, 1 Feb 2001 01:37:59 +0100 (MET) Date: Thu, 1 Feb 2001 01:37:59 +0100 (MET) From: Juergen Pfitzenmaier Message-Id: <200102010037.BAA12641@sunstroke.informatik.uni-tuebingen.de> Subject: # and polymorphic variants Content-Type: text/plain To: undisclosed-recipients:; Sender: weis@pauillac.inria.fr Dear ocaml users, consider the following example: type t1 = [ `A of int ];; type t2 = [ `B of string ];; type t = [ `A of int | `B of string ];; let f1 (`A (x : int)) = print_int x and f2 (`B (x : string)) = print_string x and f (x : t) = match x with | #t1 -> f1 x (* this is not allowed !! *) | #t2 -> f2 x;; The compiler can't constrain the type t of x to t1/t2 in the call to f1/f2. And an coercion like in ... match x with | #t1 -> f1 (x :> t1) ... is not allowed. So I see only one solution: ... match x with | #t1 -> f1 (Obj.magic(x) :> t1) (* I don't like magic *) ... But I would like to see something clean like giving a name to the # pattern ... match x with | #t1 y -> f1 y (* (y : t1) would have the same value as x *) ... or like ... match x with | #t1 -> f1 x (* x is constrained to type t1 *) ... Any comments ? -- pfitzen