caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: till.varoquaux@gmail.com
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Simple(?) subtyping problem...
Date: Wed, 25 Oct 2006 16:16:05 +0900 (JST)	[thread overview]
Message-ID: <20061025.161605.189731925.garrigue@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <9d3ec8300610242303q44cf7ec1pec711f530616f16a@mail.gmail.com>

From: "Till Varoquaux" <till.varoquaux@gmail.com>

> This would work but it isn't an option since I cannot get it to work
> with functors etc...
> AFAIK there's no way to specify a type must be a polymorphic variant
> without specfying any of it's members:
> 
> if we are building a functor against:
> 
> module type Evaluator=
> sig
>  ...
>  type 'a exp (*Is an exact polymorphic variant type *)
>  ...
> end
> 
> we won't be able to write something like:
> 
> type 'a t=[ `Some_label of 'a | 'a exp ]
> 
> since the compiler won't be able to detect 'a exp was a polymorphic
> variant (note: it looks like there could also be an issue on the
> freshness of the new label)

There is indeed an issue of freshness :-)
There is code doing exactly what you ask for inside a branch in the
CVS for ocaml. The branch is still experimental, and is called
varunion.
You would have to write
  type 'a exp = private [> ] ~ [`Some_label of 'a]
    (* `Some_label may only have type 'a (if present) *)
or
  type 'a exp = private [> ] ~ [`Some_label of 'a]
    (* `Some_label is absent *)
in order to be able to use it later in combination with `Some_label.

You can look at the code in testlabl/varunion.ml, which includes
examples corresponding exactly to the code you are trying to write.

Jacques Garrigue


      reply	other threads:[~2006-10-25  7:18 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-10-24 20:45 Till Varoquaux
2006-10-24 21:53 ` [Caml-list] " Jon Harrop
2006-10-24 22:46 ` Jacques Garrigue
2006-10-25  6:03   ` Till Varoquaux
2006-10-25  7:16     ` Jacques Garrigue [this message]

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=20061025.161605.189731925.garrigue@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=caml-list@yquem.inria.fr \
    --cc=till.varoquaux@gmail.com \
    /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).