caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Potential Feature Request: "Remove poly-variants from match-with statements"
@ 2012-04-16 15:24 Sebastien Mondet
  2012-04-17  1:52 ` Jacques Garrigue
  0 siblings, 1 reply; 3+ messages in thread
From: Sebastien Mondet @ 2012-04-16 15:24 UTC (permalink / raw)
  To: caml-list

[-- 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 --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-04-17 22:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-16 15:24 [Caml-list] Potential Feature Request: "Remove poly-variants from match-with statements" Sebastien Mondet
2012-04-17  1:52 ` Jacques Garrigue
2012-04-17 22:28   ` Sebastien Mondet

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).