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 79C5481792 for ; Mon, 24 Jun 2013 11:39:43 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of dra-news@metastack.com) identity=pra; client-ip=81.103.221.48; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="dra-news@metastack.com"; x-sender="dra-news@metastack.com"; x-conformance=sidf_compatible Received-SPF: Neutral (mail2-smtp-roc.national.inria.fr: domain of dra-news@metastack.com does not assert whether or not 81.103.221.48 is permitted sender) identity=mailfrom; client-ip=81.103.221.48; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="dra-news@metastack.com"; x-sender="dra-news@metastack.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mtaout02-winn.ispmail.ntl.com) identity=helo; client-ip=81.103.221.48; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="dra-news@metastack.com"; x-sender="postmaster@mtaout02-winn.ispmail.ntl.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AhsBAIkTyFFRZ90we2dsb2JhbABVBoJogRu8S4JrfBYOAQEJDQoIFAMlgiMBAQEDAScTRAsCAQgYChQQMiUBAQQbE4dtBwO5I44pdTiDAmEDl0OUVIIo X-IPAS-Result: AhsBAIkTyFFRZ90we2dsb2JhbABVBoJogRu8S4JrfBYOAQEJDQoIFAMlgiMBAQEDAScTRAsCAQgYChQQMiUBAQQbE4dtBwO5I44pdTiDAmEDl0OUVIIo X-IronPort-AV: E=Sophos;i="4.87,927,1363129200"; d="scan'208";a="23072931" Received: from mtaout02-winn.ispmail.ntl.com ([81.103.221.48]) by mail2-smtp-roc.national.inria.fr with ESMTP; 24 Jun 2013 11:39:29 +0200 Received: from aamtaout04-winn.ispmail.ntl.com ([81.103.221.35]) by mtaout02-winn.ispmail.ntl.com (InterMail vM.7.08.04.00 201-2186-134-20080326) with ESMTP id <20130624093927.WQEO23282.mtaout02-winn.ispmail.ntl.com@aamtaout04-winn.ispmail.ntl.com> for ; Mon, 24 Jun 2013 10:39:27 +0100 Received: from romulus.metastack.com ([81.102.132.77]) by aamtaout04-winn.ispmail.ntl.com (InterMail vG.3.00.04.00 201-2196-133-20080908) with ESMTP id <20130624093927.MQXP21648.aamtaout04-winn.ispmail.ntl.com@romulus.metastack.com> for ; Mon, 24 Jun 2013 10:39:27 +0100 Received: from remus.metastack.local (remus.metastack.com [172.16.0.1]) by romulus.metastack.com (8.14.2/8.14.2) with ESMTP id r5O9dPf3022760 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=FAIL) for ; Mon, 24 Jun 2013 10:39:25 +0100 Received: from Remus.metastack.local ([fe80::547c:3c42:e1da:eda2]) by Remus.metastack.local ([fe80::547c:3c42:e1da:eda2%10]) with mapi id 14.03.0123.003; Mon, 24 Jun 2013 10:39:24 +0100 From: David Allsopp To: OCaml List Thread-Topic: [Caml-list] Anonymous sum types in functors Thread-Index: Ac5v3yzwFRXNb/EAR2+F06vEU1G49QAgAOoAABeQzmA= Date: Mon, 24 Jun 2013 09:39:23 +0000 Message-ID: References: <001601ce6fe1$a2ea9390$e8bfbab0$@metastack.com> In-Reply-To: Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [213.205.235.48] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Organization: MetaStack Solutions Ltd. X-Scanned-By: MIMEDefang 2.65 on 172.16.0.20 X-Cloudmark-Analysis: v=1.1 cv=GaEGOwq9FwezmTggA+b6yC6zDZF2HYaK6RN/tSqdnVA= c=1 sm=0 a=Hn1YJl5WbBgA:10 a=SCxkbrXfzrIA:10 a=cTs9vV391PwA:10 a=kj9zAlcOel0A:10 a=xqWC_Br6kY4A:10 a=nzw1tOUVB3zuxYkfuPUA:9 a=CjuIK1q_8ugA:10 a=HpAAvcLHHh0Zw7uRqdWCyQ==:117 Subject: RE: [Caml-list] Anonymous sum types in functors Xavier Leroy wrote: > On 23/06/13 09:16, David Allsopp wrote: > > b) Is there a syntactically lighter way to write the module definition? >=20 > I would recommend naming your anonymous "struct": >=20 > module Flag =3D struct > type t =3D A | B > let compare =3D compare > (* Other useful operations over flags, e.g. *) > let to_string =3D function A -> "A" | B -> "B" > end The "reason" for wanting to avoid that in this instance is the specific app= lication - the sets are actually bit masks and there are about 50 of them (= using a code generator, unsurprisingly). Given that the ocamldoc output is = already going to be interesting, I was trying to avoid having 100 modules i= f possible :o) > Why not "Flag1Set.add Flag1.CommonFlag Flag1Set.empty"? Flags morally > come from Flag1, not from Flag1Set. Totally agree - this is just a slightly unusual case, I think. In my actual= implementation, the module is really called Flag1 and it happens to includ= e the set operations, so the operations that morally belong to Flag1Set are= in fact in Flag1 - but it doesn't look that weird in context. > As an aside, some ML-like module systems require functor arguments to be > module names or paths, e.g. Coq's. OCaml accepts anonymous structs as > arguments, and does the best it can with them, but if the struct contains > generative type definitions, some information is necessarily lost. >=20 > Hope this helps, It did, thank you! As did: Jacques Garrigue wrote: > > module FlagSet =3D Set.Make(struct type t =3D A | B let compare =3D com= pare > > end) > [doesn't work] > > but I'm wondering: > > > > a) Is there a way to do it where you can end up with type elt =3D A | B > > (I think the answer is no?) >=20 > Xavier described the official solution. > However, since 3.12 you can also do some trickery. > This is going to be heavier, so this is probably a bad idea, but if you > really need it, here it is: >=20 > module FlagSet =3D struct > type elt =3D A | B > include (Set.Make (struct type t =3D elt let compare =3D compare end) : > Set.S with type elt :=3D elt) end Fab, thanks - I had attempted something along these lines but couldn't quit= e get the syntax right. As I say, a slightly unusual use case as one wouldn= 't normally care about creating the extra module to house the type (and any= thing related to it). Whether there was a lighter syntax was just a curiosi= ty, rather than a need (having written full signatures for Sets and Maps ye= ars ago before discovering include Set.S with ...!).=20 David=20