caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Sebastien Mondet <sebastien.mondet@gmail.com>
To: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Potential Feature Request: "Remove poly-variants from match-with statements"
Date: Tue, 17 Apr 2012 18:28:44 -0400	[thread overview]
Message-ID: <CALScVYmHWZTPKXm5VLXpnhjmq+vkhDtuRKufDUMtcf1DjQw6XA@mail.gmail.com> (raw)
In-Reply-To: <08857D21-9495-4332-8BB9-315368430349@math.nagoya-u.ac.jp>

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

>
>
> This has been asked for repeatedly.
>

Sorry, I swear I have searched through Mantis for this :-/


> I admit this could be useful in some cases but there are difficulties.
>
> One first question is, what are you really asking for?
>
> If you just want to be able to omit the pattern before "as",
> then it is probably doable (not easy, as in your example one has
> to detect that while the return type of how_much is open, other cases
> cannot happen), but would not add any expressivity.
>
>
As there is already a nice form of  "at least" exhaustiveness check, I had
the
impression that enough information is available at some point (?)


let three_is_a_lot_3 x =
  match how_much x with
  | `Three -> `A_lot
  | `Two | `A_lot as any -> any;;
      ^^^^^^
Error: This pattern matches values of type [< `A_lot | `Three | `Two ]
       but a pattern was expected which matches values of type
         [> `A_lot | `One | `Three | `Two ]
       The first variant type does not allow tag(s) `One



If you want the real thing, i.e. the ability to have functions that "skim"
> a variant
> type, then this gets much more difficult.
>
>
After a few years trying to follow this list, I start to have an idea of
what it
means when J. Garrigue says that something is difficult  :)

So, no, the "real thing" is really not worth the complexity.



>  let remove_Three = function
>      `Three -> failwith "Three"
>   | any -> any
>
> What kind of type should we give to this function?
> Probably something like:
>
>  [`Three | 'a]  -> [ 'a ]
>
> Note here that 'a is a new kind of type variable, that can only
> be used as a polymorphic variant row variable.
> Such type systems have been studied in the literature, and I think
> there is even an Haskell extension doing that, but this can easily
> get complicated.
>
> OCaml avoids introducing such new type variables by requiring
> that if two types share the same row variable they must be identical.
> In particular this rules out the above type. Removing this restriction
> would be a major design change.
>
>        Jacques Garrigue

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

      reply	other threads:[~2012-04-17 22:29 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-16 15:24 Sebastien Mondet
2012-04-17  1:52 ` Jacques Garrigue
2012-04-17 22:28   ` Sebastien Mondet [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=CALScVYmHWZTPKXm5VLXpnhjmq+vkhDtuRKufDUMtcf1DjQw6XA@mail.gmail.com \
    --to=sebastien.mondet@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=garrigue@math.nagoya-u.ac.jp \
    /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).