From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 37C21BB84 for ; Fri, 1 Aug 2008 13:58:53 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgsFAJ+XkkiBrw8EWGdsb2JhbACLIIZ8ARshnlU X-IronPort-AV: E=Sophos;i="4.31,293,1215381600"; d="scan'208";a="27879028" Received: from ext.lri.fr ([129.175.15.4]) by mail4-smtp-sop.national.inria.fr with ESMTP; 01 Aug 2008 13:58:53 +0200 Received: from localhost (localhost [127.0.0.1]) by ext.lri.fr (Postfix) with ESMTP id C6038A4A02; Fri, 1 Aug 2008 13:58:52 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at lri.fr Received: from ext.lri.fr ([127.0.0.1]) by localhost (ext.lri.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id WEAjCjRSEd6s; Fri, 1 Aug 2008 13:58:52 +0200 (CEST) Received: from smtp.lri.fr (vhost3-23 [129.175.3.23]) by ext.lri.fr (Postfix) with ESMTP id AEA37A49EB; Fri, 1 Aug 2008 13:58:52 +0200 (CEST) Received: from serveur9-10.lri.fr (serveur9-10 [129.175.9.10]) by smtp.lri.fr (Postfix) with ESMTP id BA201E050D; Fri, 1 Aug 2008 13:58:52 +0200 (CEST) Received: from localhost ([127.0.0.1] ident=signoles) by serveur9-10.lri.fr with esmtp (Exim 3.36 #1 (Debian)) id 1KOtHY-0007V9-00; Fri, 01 Aug 2008 13:58:52 +0200 Date: Fri, 1 Aug 2008 13:58:52 +0200 (CEST) From: Julien Signoles To: Christian Sternagel Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Problem with Functors and Module Types In-Reply-To: <4892EF0C.5090505@uibk.ac.at> Message-ID: References: <4892EF0C.5090505@uibk.ac.at> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Spam: no; 0.00; signoles:01 signoles:01 lri:01 functors:01 functors:01 sig:01 val:01 sig:01 val:01 struct:01 struct:01 maken:98 maken:98 caml-list:01 int:01 Hello, > once again I have some problems using functors with module types. I produced > following (almost?) minimal example: > > module type MT_M = sig > type s > type t = A of s | B of t list > val f : t -> t > end > > module type MT_N = sig > module M : MT_M > val f : 'a -> M.t > end > > module type MT_A = sig > type t > end > > module MakeM (A : MT_A) : MT_M with type s = A.t = struct > type s = A.t > type t = A of s | B of t list > let f x = x > end > > module MakeN (A : MT_A) (* : MT_N *) = struct > module M = MakeM (A) > let f _ = M.B [] > end > > module A = struct > type t = int > end > > module M = MakeM (A) > module N = MakeN (A) > > let _ = (M.f (N.f 1)) > > This expression has type N.M.t = MakeN(A).M.t but is here used with type > M.t = MakeM(A).t There are two different solutions (at least). === 1) Externalize the sum type and use the "with type" construct: type 'a m = A of 'a | B of 'a m list module type MT_M = sig type s type t = s m val f : t -> t end ... module MakeM(A:MT_A):MT_M with type s = A.t = struct type s = A.t type t = s m let f x = x end module MakeN(A:MT_A):MT_N with type M.s = A.t and type M.t = A.t m = struct ... end ... === 2) Use the "with module construct" module MakeN(A:MT_A):MT_N with module M = MakeM(A) = struct ... end === The second solution is more elegant. Hope this helps, Julien Signoles