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 E013F81792 for ; Sun, 23 Jun 2013 17:15:11 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of Xavier.Leroy@inria.fr) identity=pra; client-ip=212.27.42.2; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="Xavier.Leroy@inria.fr"; x-sender="Xavier.Leroy@inria.fr"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of Xavier.Leroy@inria.fr) identity=mailfrom; client-ip=212.27.42.2; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="Xavier.Leroy@inria.fr"; x-sender="Xavier.Leroy@inria.fr"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@smtp2-g21.free.fr) identity=helo; client-ip=212.27.42.2; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="Xavier.Leroy@inria.fr"; x-sender="postmaster@smtp2-g21.free.fr"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ArYAALQQx1HUGyoClGdsb2JhbABbwE+Ca3wWDgEBAQEHDQkJFAMlgiMBAQQBJywlBgsLIRYPCQMCAQIBRRMIAQEXh20KuDePVhaDTQOXQ4YhjjU X-IPAS-Result: ArYAALQQx1HUGyoClGdsb2JhbABbwE+Ca3wWDgEBAQEHDQkJFAMlgiMBAQQBJywlBgsLIRYPCQMCAQIBRRMIAQEXh20KuDePVhaDTQOXQ4YhjjU X-IronPort-AV: E=Sophos;i="4.87,923,1363129200"; d="scan'208";a="22994176" Received: from smtp2-g21.free.fr ([212.27.42.2]) by mail2-smtp-roc.national.inria.fr with ESMTP; 23 Jun 2013 17:14:55 +0200 Received: from [192.168.1.2] (unknown [82.237.71.191]) by smtp2-g21.free.fr (Postfix) with ESMTP id 6D1CB4B01EC for ; Sun, 23 Jun 2013 17:14:51 +0200 (CEST) Message-ID: <51C710EA.5090100@inria.fr> Date: Sun, 23 Jun 2013 17:14:50 +0200 From: Xavier Leroy User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130510 Thunderbird/17.0.6 MIME-Version: 1.0 To: caml-list@inria.fr References: <001601ce6fe1$a2ea9390$e8bfbab0$@metastack.com> In-Reply-To: <001601ce6fe1$a2ea9390$e8bfbab0$@metastack.com> X-Enigmail-Version: 1.4.6 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [Caml-list] Anonymous sum types in functors On 23/06/13 09:16, David Allsopp wrote: > a) Is there a way to do it where you can end up with type elt = A | B (I > think the answer is no?) No, because that wouldn't quite respect the generativity of sum type definitions, but you can get close, see below. > b) Is there a syntactically lighter way to write the module definition? I would recommend naming your anonymous "struct": module Flag = struct type t = A | B let compare = compare (* Other useful operations over flags, e.g. *) let to_string = function A -> "A" | B -> "B" end module FlagSet = Set.Make(Flag) Then you get FlagSet: sig type elt = Flag.t type t ... end The good thing about this solution is that it gives you a natural place to put additional operations over flags, like "to_string" above, shall you ever need them. > the idea is that I'd > be able to write Flag1Set.add Flag1Set.CommonFlag Flag1Set.empty and > Flag2Set.add Flag2Set.CommonFlag Flag2Set.empty, etc. Why not "Flag1Set.add Flag1.CommonFlag Flag1Set.empty"? Flags morally come from Flag1, not from Flag1Set. 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. Hope this helps, - Xavier Leroy