caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: David Allsopp <dra-news@metastack.com>
To: OCaml List <caml-list@inria.fr>
Subject: Re: [Caml-list] Anonymous sum types in functors
Date: Sun, 23 Jun 2013 09:48:42 +0000	[thread overview]
Message-ID: <77CD1AA4-BDA5-4CE3-A563-E78BE8BABDF3@metastack.com> (raw)
In-Reply-To: <563607038852382852@orange.fr>

[-- Attachment #1: Type: text/plain, Size: 2042 bytes --]

On 23 Jun 2013, at 10:13, "Damien Guichard" <alphablock@orange.fr<mailto:alphablock@orange.fr>> 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?)

> b) Is there a syntactically lighter way to write the module definition?



My own quick & dirty hack :

module FlagSet = Set.Make(struct type t = [`A | `B] let compare = compare end)

Sadly not - the values are in use with C bindings and polymorphic variants would rather defeat the point of what I'm doing!

What would be nice would be an equivalent 'immediate' syntax for variant types - but its only use would be this context, I expect!


David


- damien


I couldn't think of a better way to describe what I'm trying to do, so forgive the possibly strange subject!



In:



module IntSet = Set.Make(struct type t = int let compare = compare end)



the resulting signature is:



sig

  type elt = int

  type t

  ...



but in:



module FlagSet = Set.Make(struct type t = A | B let compare = compare end)



the resulting signature is:



sig

  type elt

  type t

  ...



i.e. the constructors are hidden (I can see why, but presumably it is a special case in the type checker?) and the module is essentially useless. I don't want to define the type external to the module - the idea is that I'd be able to write Flag1Set.add Flag1Set.CommonFlag Flag1Set.empty and Flag2Set.add Flag2Set.CommonFlag Flag2Set.empty, etc.



I can work around this by writing:



module FlagSet =

  struct

    type flag = A | B

    include Set.Make(struct type t = flag let compare = compare end)

  end



where the resulting signature is:



sig

  type flag = A | B

  type elt = flag

  type t

  ...



but I'm wondering:



a) Is there a way to do it where you can end up with type elt = A | B (I think the answer is no?)

b) Is there a syntactically lighter way to write the module definition?





David


[-- Attachment #2: Type: text/html, Size: 6414 bytes --]

       reply	other threads:[~2013-06-23  9:48 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <563607038852382852@orange.fr>
2013-06-23  9:48 ` David Allsopp [this message]
2013-06-23  7:16 David Allsopp
2013-06-23 15:14 ` Xavier Leroy
2013-06-23 23:15 ` Jacques Garrigue
2013-06-24  9:39   ` David Allsopp
2013-06-24 14:37     ` Kristopher Micinski
2013-06-24 14:41       ` Raphaël Proust
2013-06-24 19:13         ` Kristopher Micinski
2013-06-25  8:39       ` David Allsopp

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=77CD1AA4-BDA5-4CE3-A563-E78BE8BABDF3@metastack.com \
    --to=dra-news@metastack.com \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).