From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 52D767F706 for ; Fri, 17 Jan 2014 15:10:32 +0100 (CET) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of Jocelyn.SEROT@univ-bpclermont.fr) identity=pra; client-ip=195.221.122.150; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="Jocelyn.SEROT@univ-bpclermont.fr"; x-sender="Jocelyn.SEROT@univ-bpclermont.fr"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of Jocelyn.SEROT@univ-bpclermont.fr) identity=mailfrom; client-ip=195.221.122.150; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="Jocelyn.SEROT@univ-bpclermont.fr"; x-sender="Jocelyn.SEROT@univ-bpclermont.fr"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@ubpmes.univ-bpclermont.fr) identity=helo; client-ip=195.221.122.150; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="Jocelyn.SEROT@univ-bpclermont.fr"; x-sender="postmaster@ubpmes.univ-bpclermont.fr"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ak0DAJFf2FLD3XqWnGdsb2JhbABZg0NWgn64DgOBERYOAQEBAQEIFAk8gk8EEXYCJgIhiFmaD48RnDSBKZBMgUkEjl+FXINlAYExiSyFZYUD X-IPAS-Result: Ak0DAJFf2FLD3XqWnGdsb2JhbABZg0NWgn64DgOBERYOAQEBAQEIFAk8gk8EEXYCJgIhiFmaD48RnDSBKZBMgUkEjl+FXINlAYExiSyFZYUD X-IronPort-AV: E=Sophos;i="4.95,670,1384297200"; d="scan'208";a="53720505" Received: from ubpmes.univ-bpclermont.fr ([195.221.122.150]) by mail2-smtp-roc.national.inria.fr with ESMTP; 17 Jan 2014 15:10:32 +0100 Received: from localhost (localhost.localdomain [127.0.0.1]) by ubpmes.univ-bpclermont.fr (Postfix) with ESMTP id 03F2A7500D00 for ; Fri, 17 Jan 2014 15:10:32 +0100 (CET) X-Virus-Scanned: amavisd-new at univ-bpclermont.fr Received: from ubpmes.univ-bpclermont.fr ([127.0.0.1]) by localhost (ubpmes.univ-bpclermont.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id oq7zdR6rXvH4 for ; Fri, 17 Jan 2014 15:10:30 +0100 (CET) Received: from univ-bpclermont.fr (ubpwme.univ-bpclermont.fr [195.221.122.180]) by ubpmes.univ-bpclermont.fr (Postfix) with ESMTP id AA9B57500C0C for ; Fri, 17 Jan 2014 15:10:30 +0100 (CET) Received: from lav63-2-88-164-92-250.fbx.proxad.net (lav63-2-88-164-92-250.fbx.proxad.net [88.164.92.250]) by wmail.univ-bpclermont.fr (Horde Framework) with HTTP; Fri, 17 Jan 2014 15:10:30 +0100 Date: Fri, 17 Jan 2014 15:10:30 +0100 Message-ID: <20140117151030.Horde.4IXAJuUEQPnzcftAlxa4vw4@wmail.univ-bpclermont.fr> From: SEROT Jocelyn To: caml-list@inria.fr User-Agent: Internet Messaging Program (IMP) H5 (6.0.4) Content-Type: text/plain; charset=UTF-8; format=flowed; DelSp=Yes MIME-Version: 1.0 Content-Disposition: inline Subject: [Caml-list] Need help with higher order functors Hi, I'm trying to implement an extension of the Set module including the notion of cartesian product. The interface of the module is : (** File pset.mli *) module type ELT_PROD = sig include Set.OrderedType type t1 type t2 val product: t1 -> t2 -> t end module type SET_PROD = sig include Set.S type t1 type t2 val product: t1 -> t2 -> t end module MakeProduct (E1: Set.OrderedType) (E2: Set.OrderedType) (C: functor (E1: Set.OrderedType) -> functor (E2: Set.OrderedType) -> ELT_PROD with type t1 = E1.t and type t2 = E2.t) : SET_PROD with type t1 = Set.Make(E1).t and type t2 = Set.Make(E2).t and type t = Set.Make(C(E1)(E2)).t and type elt = C(E1)(E2).t The [MakeProduct] functor takes the signature of element types and a functor describing how to combine these elements for building the set product. An "obvious" definition of such a functor could be module MakePair (E1: Set.OrderedType) (E2: Set.OrderedType) = struct type t = E1.t * E2.t let compare = Pervasives.compare type t1 = E1.t type t2 = E2.t let product x y = x,y end so that the definition of the "natural" cartesian product of two sets with with elements having sig Int and Bool resp., should be module IntBoolSet = MakeProduct (Int) (Bool) (MakePair) but taking an extra functor argument for [MakeProduct] allows specialized definitions of the product. For example, here's an alternative definition of the MakePair functor which could be passed to MakeProduct : module MakePair' (E1: Set.OrderedType) (E2: Set.OrderedType) = struct type t = Pair of E1.t * E2.t let compare = Pervasives.compare type t1 = E1.t type t2 = E2.t let product x y = Pair (x,y) end The problem i have is in the implementation of the Mset module : (** File mset.ml *) module type SET_PROD = sig include Set.S type t1 type t2 val product: t1 -> t2 -> t end module type ELT_PROD = sig include Set.OrderedType type t1 type t2 val product: t1 -> t2 -> t end module MakeProduct (E1: Set.OrderedType) (E2: Set.OrderedType) (C: functor (E1: Set.OrderedType) -> functor (E2: Set.OrderedType) -> ELT_PROD with type t1 = E1.t and type t2 = E2.t) = struct module S1 = Set.Make (E1) module S2 = Set.Make (E2) module P = C (E1) (E2) module R = Set.Make(P) include R type t1 = S1.t type t2 = S2.t let product s1 s2 = let f x y t = R.add (P.product x y) t in let g x t = S2.fold (f x) s2 t in S1.fold g s1 R.empty end Unfortunately, this does not compile. I get a long error message, ending with : (* excerpt of the compiler log : *) module R : sig type elt = P.t type t = Set.Make(P).t val empty : t ... end type elt = P.t type t = Set.Make(P).t val empty : t .... type t1 = S1.t type t2 = S2.t val product : S1.t -> S2.t -> R.t end is not included in sig type elt = C(E1)(E2).t type t = Set.Make(C(E1)(E2)).t val empty : t ... type t1 = Set.Make(E1).t type t2 = Set.Make(E2).t val product : t1 -> t2 -> t end Type declarations do not match: type t = Set.Make(P).t is not included in type t = Set.Make(C(E1)(E2)).t I suspect that some sharing constraint is missing here, but cannot spot where. I was expecting that declaration module P = C (E1) (E2) in the functor definition should automatically enforce the equality of types P.t and C(E1)(E2).t, and, hence, of types Set.Make(P).t and Set.Make(C(E1)(E2)).t. Obviously not. Any help would be greatly appreciated ;) Thanks in advance, Jocelyn