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 DAA22446; Mon, 16 Jun 2003 03:11:23 +0200 (MET DST) 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 DAA22782 for ; Mon, 16 Jun 2003 03:11:21 +0200 (MET DST) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h5G1BJT23122 for ; Mon, 16 Jun 2003 03:11:20 +0200 (MET DST) Received: from localhost (suiren.kurims.kyoto-u.ac.jp [130.54.16.25]) by kurims.kurims.kyoto-u.ac.jp (8.9.3p2/3.7W) with ESMTP id KAA26524; Mon, 16 Jun 2003 10:11:12 +0900 (JST) To: brogoff@speakeasy.net Cc: caml-list@inria.fr Subject: Re: [Caml-list] Polymorphic variants and signatures In-Reply-To: References: X-Mailer: Mew version 1.94.2 on Emacs 21.2 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <20030616101112O.garrigue@kurims.kyoto-u.ac.jp> Date: Mon, 16 Jun 2003 10:11:12 +0900 From: Jacques Garrigue X-Dispatcher: imput version 20000228(IM140) X-Spam: no; 0.00; jacques:01 caml-list:01 brogoff:01 val:01 inst:99 functor:01 struct:01 unsound:01 functors:01 abstraction:01 explicitely:01 speakeasy:01 variants:01 sig:01 garrigue:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk From: brogoff@speakeasy.net > I've run into some issues with polymorphic variants that I can't find > addressed in the manual. I'd like to define a module type which looks > (simplified) like this > > module type CELL_TYPE = > sig > type ('a, 'b) t > > val show_rec : > ('a -> ('b -> string) -> string) -> ([< ('b, 'a) t ] * 'c) inst -> > ('b -> string) -> string > ... > > end > > and obviously I can't because ('a, 'b) t is not a polymorphic variant type. > > Is there some way I can write such a module type, and, after having > written it, use it in a functor as follows, > > module Make (Cell : CELL_TYPE) = > struct > type ('a, 'b) t = [`Newtag of 'b list | ('a, 'b) Cell.t] > > (* and some dispatch on `Newtag and #Cell.t *) > end This is just plain impossible. In order to dispatch on a variant type, you must explicitely know all its cases. If Cell.t is abstract,then the pattern #Cell.t is not defined. Even allowing just your type definition would make then implementation unsound (all complete variant types must known). This is just the same thing as with objects: you cannot build a functor to create a class inheriting from a class given in parameter, as long as you don't give an explicit class type for the parameter, indicating at least all the public methods. Polymorphic variant don't mix well with functors: they allow incremental progamming, but not type abstraction. Do you really need a functor here? Actually, both variants and objects alleviate a great part of the need for functors. Of course, if you make t concrete in CELL_TYPE, there is no problem. Not very helpful, Jacques ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners