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 HAA17274; Thu, 31 Jan 2002 07:38:56 +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 HAA17193 for ; Thu, 31 Jan 2002 07:38:55 +0100 (MET) Received: from nef.ens.fr (nef.ens.fr [129.199.96.32]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g0V6csD20677 for ; Thu, 31 Jan 2002 07:38:54 +0100 (MET) Received: from dmi.ens.fr (dmi.ens.fr [129.199.96.11]) by nef.ens.fr (8.10.1/1.01.28121999) with ESMTP id g0V6csl94094 for ; Thu, 31 Jan 2002 07:38:54 +0100 (CET) Received: from basilic.ens.fr (monniaux@basilic [129.199.99.48]) by dmi.ens.fr (8.10.1/jb-1.3-180200) id g0V6crp27089 for ; Thu, 31 Jan 2002 07:38:54 +0100 (MET) Received: from localhost (monniaux@localhost) by basilic.ens.fr (8.11.0/jb-1.1) id g0V6cqs16443 for ; Thu, 31 Jan 2002 07:38:52 +0100 (MET) X-Authentication-Warning: basilic.ens.fr: monniaux owned process doing -bs Date: Thu, 31 Jan 2002 07:38:51 +0100 (MET) From: David Monniaux X-Sender: monniaux@basilic.ens.fr To: Liste CAML Subject: [Caml-list] restricting polymorphic variants Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=ISO-8859-1 Content-Transfer-Encoding: 8BIT Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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;; ^^^ This expression has type M.op -> int but is here used with type op -> int Let us try eta-expansion: # module N = struct type op=[`A] let f: op->int=fun x->M.f x end;; ^ This expression has type op = [ `A] but is here used with type M.op = [ `A | `B] 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;; module N : sig type op = [ `A] val f : op -> int end Ok, it now works, but it is a bit clumsy: the typer knows all the constructors of type N.op, which all fit into type M.op, why should I have to enumerate them again? This would not be so bad if this code was optimized away (after all, this is a tail call with the same argument). Is it the case? David Monniaux http://www.di.ens.fr/~monniaux Laboratoire d'informatique de l'École Normale Supérieure, Paris, France ------------------- 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