From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id KAA20008; Thu, 31 Jan 2002 10:19:57 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id KAA19923 for ; Thu, 31 Jan 2002 10:19:56 +0100 (MET) Received: from feu.irisa.fr (feu.irisa.fr [131.254.60.80]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g0V9JuD02447 for ; Thu, 31 Jan 2002 10:19:56 +0100 (MET) Received: from lawson.irisa.fr (lawson.irisa.fr [131.254.12.46]) by feu.irisa.fr (8.11.4/8.11.4) with ESMTP id g0V9Jtt10381 for ; Thu, 31 Jan 2002 10:19:55 +0100 (MET) Date: Thu, 31 Jan 2002 10:19:55 +0100 (MET) From: Laurent Vibert To: caml-list@inria.fr Subject: Re: [Caml-list] restricting polymorphic variants In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Thu, 31 Jan 2002, David Monniaux wrote: > Let us say I have a module M as follows: > module M = struct type op=[`A|`B] let f: op->int=function `A->0|`B->1 end; > > I cannot just sat that f has type [< `A|`B]->int because M has to fit > within a signature: > module type MT=sig type op val f: op->int end;; > > I would like to obtain another module where f only accepts `A: > # module N = struct type op=[`A] let f: op->int=M.f end;; > ^^^ > Let us try eta-expansion: > # module N = struct type op=[`A] let f: op->int=fun x->M.f x end;; > this one work with an explicit coercion : module N = struct type op=[`A] let f: op->int=fun x->M.f (x:>M.op) end;; > Well, let us try enumerating all the constructors in the closed type op! > # module N = struct type op=[`A] let f: op->int=function (`A as x)->M.f x > end;; or faster : module N = struct type op=[`A] let f (#op as x) = M.f x end;; ------------------- 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