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 C5DC07EE99 for ; Tue, 21 Jan 2014 12:31:05 +0100 (CET) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of josh@berdine.net) identity=pra; client-ip=66.111.4.25; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="josh@berdine.net"; x-sender="josh@berdine.net"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of josh@berdine.net) identity=mailfrom; client-ip=66.111.4.25; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="josh@berdine.net"; x-sender="josh@berdine.net"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@out1-smtp.messagingengine.com) identity=helo; client-ip=66.111.4.25; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="josh@berdine.net"; x-sender="postmaster@out1-smtp.messagingengine.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Av8BADJa3lJCbwQZnGdsb2JhbABZDocIuGmBEhYOAQEBAQEGDQkJFCiCJQEBAQMBIwQZFCUBBAsLGAICBSECAg8BLBsGARKHfQgEpnl2g2KYNhEGFoETjSMzB4JvgUmtLD8 X-IPAS-Result: Av8BADJa3lJCbwQZnGdsb2JhbABZDocIuGmBEhYOAQEBAQEGDQkJFCiCJQEBAQMBIwQZFCUBBAsLGAICBSECAg8BLBsGARKHfQgEpnl2g2KYNhEGFoETjSMzB4JvgUmtLD8 X-IronPort-AV: E=Sophos;i="4.95,696,1384297200"; d="scan'208";a="54171073" Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/ADH-AES256-SHA; 21 Jan 2014 12:31:04 +0100 Received: from compute5.internal (compute5.nyi.mail.srv.osa [10.202.2.45]) by gateway1.nyi.mail.srv.osa (Postfix) with ESMTP id 1B05620D6F; Tue, 21 Jan 2014 06:31:04 -0500 (EST) Received: from frontend2 ([10.202.2.161]) by compute5.internal (MEProxy); Tue, 21 Jan 2014 06:31:04 -0500 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=berdine.net; h= from:to:cc:subject:in-reply-to:references:date:message-id :mime-version:content-type:content-transfer-encoding; s=mesmtp; bh=3cftuFLDNm61zRVTgYxmuFga314=; b=hkyRPCMyWlKD4amXNSRK5fNEq6yH S3JvluHK1PRnNHvnoQayFxqPIvxT8PPLt7+is4JKDw0qN2tEIYgslVJOX945V32B sxBZ3KM8QzVizl2/zRofqodg8aNgjuZrpFG5r3U7CDrm2kPd7ITbCU0FEx/D/6kC cKZTGEPv8JQGFKU= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=from:to:cc:subject:in-reply-to:references :date:message-id:mime-version:content-type :content-transfer-encoding; s=smtpout; bh=3cftuFLDNm61zRVTgYxmuF ga314=; b=oyFUMSRpv8qOTpql4iQpt3kB/KcORJCoV4w5aVJh4emLHHd+kjThpc wY6HWw2NRIwDHMjM8Muq97K3ySStQ9X5ve7LYn7b4RdZZ52qyo/mfaQvFXMHP7Gq xr6nxy2c+QApsN0BqtI5sGSP6zWjdM0OWCLvvsgCYz/r77rSbuPgM= X-Sasl-enc: QApC2StB0rhjVWuuY/nP1OzBIlFb1DX4DRAEe85hMp8x 1390303863 Received: from locust (unknown [94.245.87.87]) by mail.messagingengine.com (Postfix) with ESMTPA id C4E0868027A; Tue, 21 Jan 2014 06:31:03 -0500 (EST) Received: from jjb by locust with local (Exim 4.80) (envelope-from ) id 1W5ZXn-0000Rl-Hv; Tue, 21 Jan 2014 11:30:59 +0000 From: Josh Berdine To: SEROT Jocelyn , Leo White Cc: "caml-list" In-Reply-To: <20140121120954.Horde.QQKslk0F5ldpqozcxKyq3g1@wmail.univ-bpclermont.fr> References: <87ppnm5q2x.fsf@study.localdomain> <20140121120954.Horde.QQKslk0F5ldpqozcxKyq3g1@wmail.univ-bpclermont.fr> Date: Tue, 21 Jan 2014 11:30:59 +0000 Message-ID: <87txcxlggc.fsf@berdine.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Caml-list] Question on functors (again...) On Tue, Jan 21 2014, SEROT Jocelyn wrote: > Leo White a =C3=A9crit=C2=A0: >> >> 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 > > Unfortunately, this is not possible since the ELT signature is=20=20 > actually more complex than just 'sig type t end'. > To illustrate this, without showing the original code (which, as you=20=20 > guessed it, has some extra and maybe unrelated complexity), i've tried=20= =20 > to reuse your example, by simply changing > > module type ELT =3D sig type t end > > by > > module type ELT =3D sig type t val string_of: t -> string end Shouldn't Elt.t and elt in SET be equal? The following typechecks, though maybe not what you want: > module type ELT =3D > sig > type t > val string_of: t -> string > end > > module type SET =3D sig > type t > type elt > module Elt : ELT > val choose: t -> elt > val singleton: elt -> t > val string_of: t -> string > end module type SET =3D sig type t module Elt : ELT type elt =3D Elt.t val choose: t -> elt val singleton: elt -> t val string_of: t -> string end > module Make (E : ELT) : SET with module Elt =3D E and 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] > let string_of s =3D "{" ^ E.string_of (choose s) ^ "}" > end > > 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 > let string_of (x,y) =3D "(" ^ E1.string_of x ^ "," ^ E2.string_of y ^ = ")" > end > > module MakeProduct (S1: SET) (S2: SET) : sig > include SET with type elt =3D S1.elt * S2.elt > val product : S1.t -> S2.t -> t > end =3D struct > module P =3D MakePair(S1.Elt)(S2.Elt) > module S =3D Make(P) > include S > let product s1 s2 =3D S.singleton (P.product (S1.choose s1) (S2.choose= s2)) > end module MakeProduct (S1: SET) (S2: SET) : sig include SET with type Elt.t =3D S1.elt * S2.elt val product : S1.t -> S2.t -> t end =3D struct module P =3D MakePair(S1.Elt)(S2.Elt) module S =3D Make(P) include S let product s1 s2 =3D S.singleton (P.product (S1.choose s1) (S2.choose s= 2)) end Cheers, Josh