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 4310BBBB7 for ; Tue, 25 Jul 2006 22:45:27 +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 k6PKjQil022996 for ; Tue, 25 Jul 2006 22:45:26 +0200 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 WAA22441 for ; Tue, 25 Jul 2006 22:45:26 +0200 (MET DST) Received: from coriana6.cis.mcmaster.ca (coriana6.CIS.McMaster.CA [130.113.128.17]) by nez-perce.inria.fr (8.13.6/8.13.6) with ESMTP id k6PKjOlB018266 for ; Tue, 25 Jul 2006 22:45:25 +0200 Received: from Dura7.UTS.McMaster.CA (dura7.UTS.McMaster.CA [130.113.196.62]) by coriana6.cis.mcmaster.ca (8.13.4/8.13.4) with ESMTP id k6PKjLoY016867; Tue, 25 Jul 2006 16:45:21 -0400 (EDT) Received: from cgpsrv2.cis.mcmaster.ca (univmail.CIS.McMaster.CA [130.113.64.46]) by Dura7.UTS.McMaster.CA (8.13.7/8.13.7) with ESMTP id k6PKjGP7018208; Tue, 25 Jul 2006 16:45:16 -0400 Received: from [69.193.76.85] (account carette@univmail.cis.mcmaster.ca HELO [192.168.1.101]) by cgpsrv2.cis.mcmaster.ca (CommuniGate Pro SMTP 4.1.8) with ESMTP-TLS id 133447633; Tue, 25 Jul 2006 16:45:16 -0400 Message-ID: <44C682E0.6040805@mcmaster.ca> Date: Tue, 25 Jul 2006 16:45:20 -0400 From: Jacques Carette Organization: McMaster University User-Agent: Thunderbird 1.5.0.4 (Windows/20060516) MIME-Version: 1.0 To: Andreas Rossberg Cc: caml-list@inria.fr Subject: How do I achiece this, was Re: [Caml-list] Variance problem in higher-order Functors? References: <44C3D4C8.8010502@mcmaster.ca> <00ea01c6ae9d$3c459750$15b2a8c0@wiko> In-Reply-To: <00ea01c6ae9d$3c459750$15b2a8c0@wiko> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-PMX-Version-Mac: 4.7.1.128075, Antispam-Engine: 2.1.0.0, Antispam-Data: 2006.7.25.123433 X-PerlMx-Spam: Gauge=IIIIIII, Probability=7%, Report='__CT 0, __CTE 0, __CT_TEXT_PLAIN 0, __HAS_MSGID 0, __MIME_TEXT_ONLY 0, __MIME_VERSION 0, __SANE_MSGID 0, __USER_AGENT 0' X-Miltered: at concorde with ID 44C682E6.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 44C682E4.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; variance:01 higher-order:01 functors:01 sig:01 struct:01 struct:01 first-order:01 functor:01 functor:01 sig:01 first-order:01 variants:01 run-time:01 functors:01 ocaml: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 My real question is (and should have been), how do I translate module type DOMAIN = sig type kind end type domain_is_field type domain_is_ring module Rational = struct type kind = domain_is_field end module Integer = struct type kind = domain_is_ring end module DivisionUpdate(D:DOMAIN with type kind = domain_is_field) = struct (* something only valid with D a field*) end module GeneralUpdate(D:DOMAIN) = struct (* something that always works, for rings and fields *) end The behaviour I want should be the same as the first-order applications module A = DivisionUpdate(Rational) (* OK *) module B = GeneralUpdate(Rational) (* OK *) module C = DivisionUpdate(Integer) (* ERROR *) module D = GeneralUpdate(Integer) (* OK *) BUT I want to pass all these modules as parameters to a functor. I don't see how to build the proper type that will work! [I have read the manuals in depth, Googled around the caml.inria.fr web site, played around with the implementation, etc to no avail] 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 works fine. I would be happy with a solution that uses polymorphic variants, or objects, or whatever work. The only thing I can't do is "run-time" tests, as I have a dozen domains, with more functors and more constraints floating around, so I really want this to be a type-level solution. If OCaml had conditional module application, I could use that, but "expanding" my definitions is not realistic. Jacques