From: Sebastien Mondet <sebastien.mondet@gmail.com>
To: caml-list@inria.fr
Subject: [Caml-list] Potential Feature Request: "Remove poly-variants from match-with statements"
Date: Mon, 16 Apr 2012 11:24:09 -0400 [thread overview]
Message-ID: <CALScVYkjxA1th55ZewhAZe1-HgPXGX91fRJ_EsjLxRcqy0KQhw@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1033 bytes --]
Hi
I don't know if it is theoretically sound or possible, but
it would be helpful, if the typing of match-with statements with polymorphic
variants was able to remove one or more variants from the "catch-all" cases
In the following code, it would mean that three_is_a_lot would be typed like
three_is_a_lot_2 without having to write all the cases.
# let how_much = function
| 1 -> `One
| 2 -> `Two
| 3 -> `Three
| n -> `A_lot;;
val how_much : int -> [> `A_lot | `One | `Three | `Two ] = <fun>
# let three_is_a_lot x =
match how_much x with
| `Three -> `A_lot
| any -> any;;
val three_is_a_lot : int -> [> `A_lot | `One | `Three | `Two ] = <fun>
# let three_is_a_lot_2 x =
match how_much x with
| `Three -> `A_lot
| `One | `Two | `A_lot as any -> any;;
val three_is_a_lot_2 : int -> [> `A_lot | `One | `Two ] = <fun>
The practical use-case for us is that we use polymorphic variants to encode
"semantic" errors in an Error/Result monad.
What does the list think?
Cheers,
Sebastien
[-- Attachment #2: Type: text/html, Size: 1662 bytes --]
next reply other threads:[~2012-04-16 15:24 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-16 15:24 Sebastien Mondet [this message]
2012-04-17 1:52 ` Jacques Garrigue
2012-04-17 22:28 ` Sebastien Mondet
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=CALScVYkjxA1th55ZewhAZe1-HgPXGX91fRJ_EsjLxRcqy0KQhw@mail.gmail.com \
--to=sebastien.mondet@gmail.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