From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 972F1BCAB for ; Thu, 2 Jun 2005 09:53:51 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j527rp8U003203 for ; Thu, 2 Jun 2005 09:53:51 +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 JAA13465 for ; Thu, 2 Jun 2005 09:53:50 +0200 (MET DST) Received: from ext.lri.fr (ext.lri.fr [129.175.15.4]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j527roYL003200 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO) for ; Thu, 2 Jun 2005 09:53:50 +0200 Received: from localhost (localhost [127.0.0.1]) by ext.lri.fr (Postfix) with ESMTP id 4548C19E715; Thu, 2 Jun 2005 09:53:50 +0200 (CEST) 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 00977-03; Thu, 2 Jun 2005 09:53:50 +0200 (CEST) Received: from smtp.lri.fr (serveur3-5 [129.175.3.5]) by ext.lri.fr (Postfix) with ESMTP id 3258B19E706; Thu, 2 Jun 2005 09:53:50 +0200 (CEST) Received: from pc8-102 (pc8-102 [129.175.8.102]) by smtp.lri.fr (Postfix) with ESMTP id C1CEFCED9C; Thu, 2 Jun 2005 09:53:49 +0200 (CEST) Received: from pc8-102 ([127.0.0.1] helo=localhost) by pc8-102 with esmtp (Exim 3.36 #1 (Debian)) id 1DdkWS-0005IP-00; Thu, 02 Jun 2005 09:53:48 +0200 Date: Thu, 2 Jun 2005 09:53:48 +0200 (CEST) From: Julien Signoles X-X-Sender: signoles@pc8-102 To: Keiko Nakata Cc: caml-list@inria.fr Subject: Re: [Caml-list] a module with multiple signatures In-Reply-To: <20050602.161836.68553253.keiko@kurims.kyoto-u.ac.jp> Message-ID: References: <20050602.161836.68553253.keiko@kurims.kyoto-u.ac.jp> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new at lri.fr X-Miltered: at nez-perce with ID 429EBB0F.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 429EBB0E.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; signoles:01 signoles:01 lri:01 caml-list:01 struct:01 functor:01 sig:01 struct:01 functor:01 sig:01 val:01 ocaml:01 syntax:01 val:01 avoiding:01 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.2 X-Spam-Level: > module M = struct type s = S type t = T1 | T2 of s end > > module F1 = functor (X : sig type t end) -> struct type t = X.t end > > module F2 = functor (X : sig type s type t end) -> > struct type s = X.s type t = X.t end > > module M1 = F1(M) > > module M2 = F2(M) > > let f x = match x with M1.T1 -> 1 | M1.T2 x -> 2;; > (* This is not type checked *) > (* I got the error "Unbound constructor M1.T1" *) > > (* This is type checked *) > let g (x : M1.t) = match x with M.T1 -> 1 | M.T2 x -> 2;; > > Why M1.T1 should not be bound? Because only M.T1 exists, not M1.T1. You can see this on a simpler example: module X = struct type t = T end module Y = struct type t = X.t end let f x = match x with Y.T -> () (* type error : "Unbound constructor Y.T" *) let f (x:Y.t) = match x with X.t -> () (* val f : Y.t -> unit *) But, in ocaml, it possible to export the constructor T in Y by using the following syntax: module X = struct type t = T end module Y = struct type t = X.t = T (* T is egal to X.t *) end let f x = match x with Y.T -> () (* val f : Y.t -> unit *) > Anyway, > there may be a nicer way to give a module multiple signatures > while avoiding duplicate type declarations as possible? You can use signature constraints: module M = struct type s = S type t = T1 | T2 end module M1 : sig type t = M.t end = M module M2 : sig type s = M.s type t = M.t end = M Hope this helps, Julien -- mailto:Julien.Signoles@lri.fr ; http://www.lri.fr/~signoles "In theory, practice and theory are the same, but in practice they are different" (Larry McVoy)