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.4 required=5.0 tests=AWL,DNS_FROM_RFC_ABUSE autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id DD5D9BC69 for ; Fri, 24 Aug 2007 04:56:17 +0200 (CEST) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l7O2uF1B021071 for ; Fri, 24 Aug 2007 04:56:17 +0200 Received: from localhost (orion [130.54.16.5]) by kurims.kurims.kyoto-u.ac.jp (8.13.8/8.13.8) with ESMTP id l7O2uD5H016907; Fri, 24 Aug 2007 11:56:14 +0900 (JST) Date: Fri, 24 Aug 2007 11:56:08 +0900 (JST) Message-Id: <20070824.115608.24601967.garrigue@math.nagoya-u.ac.jp> To: bhurt@spnz.org Cc: caml-list@inria.fr Subject: Re: [Caml-list] Stupid question re:modules From: Jacques Garrigue In-Reply-To: References: X-Mailer: Mew version 4.2 on Emacs 22.1 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Miltered: at discorde with ID 46CE48CF.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; foo:01 sig:01 val:01 foo:01 sig:01 val:01 baz:01 baz:01 overwrite:01 struct:01 struct:01 signatures:01 signatures:01 caml-list:01 define:02 From: Brian Hurt > I should just know this. So let's say I have two module types defined: > > module type Foo = sig > type 'a t > val foo : 'a -> 'a t > end;; > > module type Bar = sig > type 'a t > val bar : 'a -> 'a t > end;; > > Now, I want to define a module that is both a Foo and a Bar without > cutting and pasting the module definitions around. I've been trying to > do: > > module Baz : sig > type 'a baz > include Foo with type 'a t = 'a baz > include Bar with type 'a t = 'a baz > end;; > > but this blows up on the Bar line (multiple definitions of 'a t). > > There is a solution to this, I'm just being stupid and forgetting what it > is. Hints would be appreciated. Unfortunately, there is no solution to this, as you cannot remove a declaration from a signature, and include cannot overwrite existing type definitions. There was a paper in ICFP'2005 on how to solve this, but I'm not aware of any plan to follow it. If you're ready to write longer signatures, there is a workaround. module type T = sig type 'a t end module FooS(X:T) = struct module type S = sig val foo : 'a -> 'a X.t end end module BarS(X:T) = struct module type S = sig val bar : 'a -> 'a X.t end end module Baz : sig module T : sig type 'a t end include FooS(T) include BarS(T) end The basic idea if you want to be able to construct signatures modularly is to always keep types and function declarations separated. Jacques Garrigue