Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Jeremy Yallop <yallop@gmail.com>
To: Martin DeMello <martindemello@gmail.com>
Cc: "caml-list@inria.fr" <caml-list@inria.fr>
Subject: Re: [Caml-list] intersections of polymorphic variants
Date: Thu, 9 Feb 2017 09:57:33 +0000	[thread overview]
Message-ID: <CAAxsn=F4EoBvyJnZG_3xoSgOEzwgRKGy3AAWszF-DzxozBS3yA@mail.gmail.com> (raw)
In-Reply-To: <CAFrFfuFna+7-sSH2nqy5n+bDYPeCgSeK-RrzaTQYm7CrmEE1zw@mail.gmail.com>

On 9 February 2017 at 09:52, Martin DeMello <martindemello@gmail.com> wrote:
> In the following code:
>
> type color = [`Red | `Blue | `Green | `Black | `White]
>
> let color_index c = match c with
>   | `Red -> 1
>   | `Blue -> 2
>   | `Green -> 3
>   | `Black -> 4
>   | `White -> 5
>
> type value = [`Red | `Blue | `Green | `Missing]
>
> type state = Color of int | Missing
>
> let state_of_value v = match v with
>   | `Red -> Color (color_index `Red)
>   | `Blue -> Color (color_index `Blue)
>   | `Green -> Color (color_index `Green)
>   | `Missing -> Missing
>
> is there any way to write the last function as
>
> let state_of_value v = match v with
>   | `Red  | `Blue  | `Green -> ?????
>   | `Missing -> Missing

  let state_of_value v = match v with
    | (`Red  | `Blue  | `Green) as c -> Color (color_index c)
    | `Missing -> Missing

  reply	other threads:[~2017-02-09  9:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-09  9:52 Martin DeMello
2017-02-09  9:57 ` Jeremy Yallop [this message]
2017-02-09 10:03   ` Martin DeMello
2017-02-09 15:15     ` Ashish Agarwal

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='CAAxsn=F4EoBvyJnZG_3xoSgOEzwgRKGy3AAWszF-DzxozBS3yA@mail.gmail.com' \
    --to=yallop@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=martindemello@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