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 mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id C2CCA7EE99 for ; Tue, 21 Jan 2014 12:10:00 +0100 (CET) Received-SPF: None (mail3-smtp-sop.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=mail3-smtp-sop.national.inria.fr; envelope-from="Jocelyn.SEROT@univ-bpclermont.fr"; x-sender="Jocelyn.SEROT@univ-bpclermont.fr"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.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=mail3-smtp-sop.national.inria.fr; envelope-from="Jocelyn.SEROT@univ-bpclermont.fr"; x-sender="Jocelyn.SEROT@univ-bpclermont.fr"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.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=mail3-smtp-sop.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: AgECAB1V3lLD3XqWnGdsb2JhbABZDoQLgn24aYESFg4BAQEBAQgUCTyCJQEBAQMBIwQLAQVBBQsLDgwCJgICHzgGE4d9DKdvnBUXgSmNIzMHgm+BSQSOYIlBAZBDhENA X-IPAS-Result: AgECAB1V3lLD3XqWnGdsb2JhbABZDoQLgn24aYESFg4BAQEBAQgUCTyCJQEBAQMBIwQLAQVBBQsLDgwCJgICHzgGE4d9DKdvnBUXgSmNIzMHgm+BSQSOYIlBAZBDhENA X-IronPort-AV: E=Sophos;i="4.95,695,1384297200"; d="scan'208";a="45554630" Received: from ubpmes.univ-bpclermont.fr ([195.221.122.150]) by mail3-smtp-sop.national.inria.fr with ESMTP; 21 Jan 2014 12:10:00 +0100 Received: from localhost (localhost.localdomain [127.0.0.1]) by ubpmes.univ-bpclermont.fr (Postfix) with ESMTP id CD19A7500C90; Tue, 21 Jan 2014 12:09:59 +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 A4n0qXvSgmTV; Tue, 21 Jan 2014 12:09:54 +0100 (CET) Received: from univ-bpclermont.fr (ubpwme.univ-bpclermont.fr [195.221.122.180]) by ubpmes.univ-bpclermont.fr (Postfix) with ESMTP id D252F7500CCC; Tue, 21 Jan 2014 12:09:54 +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; Tue, 21 Jan 2014 12:09:54 +0100 Date: Tue, 21 Jan 2014 12:09:54 +0100 Message-ID: <20140121120954.Horde.QQKslk0F5ldpqozcxKyq3g1@wmail.univ-bpclermont.fr> From: SEROT Jocelyn To: Leo White Cc: OCaML Mailing List References: <87ppnm5q2x.fsf@study.localdomain> In-Reply-To: <87ppnm5q2x.fsf@study.localdomain> 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 Content-Transfer-Encoding: 8bit Subject: Re: [Caml-list] Question on functors (again...) Thanks for your answer, Leo. Leo White a écrit : > > You should add the constraints to the `SET` module type itself: > > module type SET = sig > type t > type elt > module Elt : sig type t = elt end > val choose : t -> elt > val singleton : elt -> t > end Unfortunately, this is not possible since the ELT signature is actually more complex than just 'sig type t end'. To illustrate this, without showing the original code (which, as you guessed it, has some extra and maybe unrelated complexity), i've tried to reuse your example, by simply changing module type ELT = sig type t end by module type ELT = sig type t val string_of: t -> string end Here's my attempt : module type ELT = sig type t val string_of: t -> string end module type SET = sig type t type elt module Elt : ELT val choose: t -> elt val singleton: elt -> t val string_of: t -> string end module Make (E : ELT) : SET with module Elt = E and type elt = E.t = struct type elt = E.t type t = elt list module Elt = E let choose s = List.hd s let singleton e = [e] let string_of s = "{" ^ E.string_of (choose s) ^ "}" end module MakePair (E1: ELT) (E2: ELT) : sig include ELT with type t = E1.t * E2.t val product : E1.t -> E2.t -> t end = struct type t = E1.t * E2.t let product x y = x,y let string_of (x,y) = "(" ^ E1.string_of x ^ "," ^ E2.string_of y ^ ")" end module MakeProduct (S1: SET) (S2: SET) : sig include SET with type elt = S1.elt * S2.elt val product : S1.t -> S2.t -> t end = struct module P = MakePair(S1.Elt)(S2.Elt) module S = Make(P) include S let product s1 s2 = S.singleton (P.product (S1.choose s1) (S2.choose s2)) end Again, the compiler chokes on the definition of MakeProduct.product, saying, for "S1.choose s1", that : "This expression has type S1.elt but an expression was expected of type S1.Elt.t" I understand your comment : > The compiler doesn't know that your `S1` and `S2` arguments have been > made with the `Make` functor so it cannot assume those constraints. so, let's add these constraints directly to the functor arguments : module MakeProduct (S1: SET with type elt = Elt.t) (S2: SET with type elt = Elt.t) : sig but then, we get : " module MakeProduct (S1: SET with type elt = Elt.t) (S2: SET) : sig ^^^^^ Error: Unbound module Elt" ??? The Elt module is part of the SET signature, isn't it ? Jocelyn