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 D41D97EE99 for ; Mon, 20 Jan 2014 21:48:04 +0100 (CET) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of lpw25@cam.ac.uk) identity=pra; client-ip=131.111.8.132; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="lpw25@cam.ac.uk"; x-sender="lpw25@cam.ac.uk"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of lpw25@cam.ac.uk) identity=mailfrom; client-ip=131.111.8.132; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="lpw25@cam.ac.uk"; x-sender="lpw25@cam.ac.uk"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@ppsw-32.csi.cam.ac.uk) identity=helo; client-ip=131.111.8.132; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="lpw25@cam.ac.uk"; x-sender="postmaster@ppsw-32.csi.cam.ac.uk"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApUBAPqK3VKDbwiEnGdsb2JhbABZhxa4VoEUFg4BAQEBAQgLCQkUKIIlAQEBAwEjBC0lBQsLGgIFIQICDwEESROHfQgEp2+XDYR/F4EpjSMzB4JvgUkEmCKVRQ X-IPAS-Result: ApUBAPqK3VKDbwiEnGdsb2JhbABZhxa4VoEUFg4BAQEBAQgLCQkUKIIlAQEBAwEjBC0lBQsLGgIFIQICDwEESROHfQgEp2+XDYR/F4EpjSMzB4JvgUkEmCKVRQ X-IronPort-AV: E=Sophos;i="4.95,691,1384297200"; d="scan'208";a="54079075" Received: from ppsw-32.csi.cam.ac.uk ([131.111.8.132]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 20 Jan 2014 21:48:04 +0100 X-Cam-AntiVirus: no malware found X-Cam-ScannerInfo: http://www.cam.ac.uk/cs/email/scanner/ Received: from host81-154-221-63.range81-154.btcentralplus.com ([81.154.221.63]:37972 helo=study.localdomain) by ppsw-32.csi.cam.ac.uk (smtp.hermes.cam.ac.uk [131.111.8.156]:587) with esmtpsa (PLAIN:lpw25) (TLSv1.2:DHE-RSA-AES128-SHA:128) id 1W5LlL-0000V6-1t (Exim 4.82_3-c0e5623) (return-path ); Mon, 20 Jan 2014 20:48:03 +0000 From: Leo White To: Jocelyn =?utf-8?Q?S=C3=A9rot?= Cc: OCaML Mailing List References: X-Face: "XWxb[u_Z\PA_Y?9@|IA!!+jTb(/290-*ea/Un$I0B98.$n%eL.;2w*,z]WR#T:,p[ NBd++M7l]#7zj7!{~iw $W-"/=|dVjhT[D{4~gE}gK<2`.6fs!;uqqud]vs2N/3^m7{aS1V, Date: Mon, 20 Jan 2014 20:57:26 +0000 In-Reply-To: ("Jocelyn \=\?utf-8\?Q\?S\=C3\=A9rot\=22's\?\= message of "Mon, 20 Jan 2014 17:34:21 +0100") Message-ID: <87ppnm5q2x.fsf@study.localdomain> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Caml-list] Question on functors (again...) Jocelyn S=C3=A9rot writes: > I was expecting that the constraints in the definition of the Make functo= r (".. with type elt=3DE.t and module Elt =3DE") > would automatically enforce the type equality "elt =3D Elt.t" for all mo= dules defined by applying Make (such as S1 and > S2). This is obviously not the case. I just can't see how to enforce thi= s.. The compiler doesn't know that your `S1` and `S2` arguments have been made with the `Make` functor so it cannot assume those constraints. You should add the constraints to the `SET` module type itself: module type SET =3D sig type t type elt module Elt : sig type t =3D elt end val choose : t -> elt val singleton : elt -> t end You've simplified your example, so there may be important complexity that you've left out, but your code seems to be unnecessarily complicated. You can probably simplify it to something that looks more like the code below. Regards, Leo module type ELT =3D sig type t end =20=20=20 module type SET =3D sig type t type elt val choose: t -> elt val singleton: elt -> t end =20=20=20 module Make (E : ELT) : SET with type elt =3D E.t =3D struct type elt =3D E.t type t =3D elt list module Elt =3D E let choose s =3D List.hd s let singleton e =3D [e] end =20=20=20 module MakePair (E1: ELT) (E2: ELT) : sig include ELT with type t =3D E1.t * E2.t val product : E1.t -> E2.t -> t end =3D struct type t =3D E1.t * E2.t let product x y =3D x,y end =20=20=20 module MakeProduct (S1: SET) (S2: SET) : sig=20 include SET with type elt =3D S1.elt * S2.elt val product : S1.t -> S2.t -> t end =3D struct module P =3D MakePair(struct type t =3D S1.elt end)(struct type t =3D= S2.elt end) module S =3D Make(P) include S let product s1 s2 =3D S.singleton (P.product (S1.choose s1) (S2.choos= e s2)) end