From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 5AD2DBBB7 for ; Wed, 26 Jul 2006 07:17:19 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id k6Q5HIWN009938 for ; Wed, 26 Jul 2006 07:17:18 +0200 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 HAA28242 for ; Wed, 26 Jul 2006 07:17:17 +0200 (MET DST) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id k6Q5H68W009899 for ; Wed, 26 Jul 2006 07:17:16 +0200 Received: from localhost (suiren [130.54.16.25]) by kurims.kurims.kyoto-u.ac.jp (8.13.7/8.13.7) with ESMTP id k6Q5H2N0001752; Wed, 26 Jul 2006 14:17:02 +0900 (JST) Date: Wed, 26 Jul 2006 14:16:53 +0900 (JST) Message-Id: <20060726.141653.100091046.garrigue@math.nagoya-u.ac.jp> To: carette@mcmaster.ca Cc: AndreasRossberg@web.de, caml-list@inria.fr Subject: Re: How do I achiece this, was Re: [Caml-list] Variance problem in higher-order Functors? From: Jacques Garrigue In-Reply-To: <44C682E0.6040805@mcmaster.ca> References: <44C3D4C8.8010502@mcmaster.ca> <00ea01c6ae9d$3c459750$15b2a8c0@wiko> <44C682E0.6040805@mcmaster.ca> X-Mailer: Mew version 4.2 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 44C6FADE.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 44C6FAD2.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; variance:01 higher-order:01 functors:01 functor:01 functor:01 sig:01 first-order:01 applicative:01 struct:01 sig:01 foo:01 val:01 struct:01 functors:01 caml-list:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 From: Jacques Carette > In other words, I want to be able to define > module type Trans = functor(U:UPDATE) -> functor(D:DOMAIN) -> sig ... end > but none of my attempts have worked, even though the first-order code I think I have a solution, at least to your first post. If I am right, what you need is to express that Bar's 2nd parameter is a functor with input of type "DOMAIN with type kind = D.kind". But you cannot use "with", because the functor type is defined as an abrreviation. The trick is to wrap the module type definition in a functor, and to use applicative types. (* If we go higher order: *) module UPDATE2(D0:DOMAIN) = struct module type S = functor(D:DOMAIN with type kind = D0.kind) -> sig type obj = D.foo val update : obj -> obj end end (* this is the same as the "updates" above, just wrapped in a module *) module Bar(D:DOMAIN)(U:UPDATE2(D).S) = struct module U = U(D) let update x = U.update x end (* works as there are no restrictions *) module T3 = Bar(Integer)(BadUpdate) ;; (* and now this works! *) module T2 = Bar(Rational)(DivisionUpdate) ;; This trick of wrapping module types inside functors proves useful in many situations, when you want to express sharing that cannot be expressed by with alone. Jacques Garrigue