Version française
Home     About     Download     Resources     Contact us    
Browse thread
# and polymorphic variants
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Andrzej M. Ostruszka <ostruszk@o...>
Subject: Re: # and polymorphic variants
On Thu, Feb 01 (2001), Juergen Pfitzenmaier wrote:
> 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.

What about alias patterns? The following seems to work:

type t1 = [ `A of int ]
type t2 = [ `B of string ]
type t = [ `A of int | `B of string ]

let f1 (`A x) = print_int x
and f2 (`B x) = print_string x
and f (x : t) = match x with
        | #t1 as a -> f1 a
        | #t2 as b -> f2 b
						Best regards
-- 
    ____   _  ___
   /  | \_/ |/ _ \		Andrzej Marek Ostruszka
  / _ |     | (_) | Instytut Fizyki, Uniwersytet Jagiellonski (Cracow)
 /_/ L|_|V|_|\___/	(PGP <-- finger ostruszk@order.if.uj.edu.pl)