caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Jonathan Roewen" <jonathan.roewen@gmail.com>
To: "Seth J. Fogarty" <sfogarty@gmail.com>
Cc: caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] Question on Variant Types
Date: Thu, 29 Jun 2006 11:51:00 +1200	[thread overview]
Message-ID: <ad8cfe7e0606281651o3b9f82dfhe0067bcd581ab938@mail.gmail.com> (raw)
In-Reply-To: <c7ee61120606281644y1ed7b5cev174c4fe3f664cb63@mail.gmail.com>

> Followup question:
> Given I have:
> type foo = [`A | `B of int | `C of char]
> type bar = [`B of int | `C  of char| `D]
>
> and a function
> let f (x : foo) : bar =
> match x with
>     `A -> `D
>    |`B _
>    |`C _ -> (x : bar)
>
> Is there any way to properly coerce this using the restricted variant
> information of x? Or do I have to duplicate code and reconstruct x?

let f (x : foo) : bar = match x with
| `A -> `D
| `B _ | `C _ as x -> (x : bar)

Jonathan


  reply	other threads:[~2006-06-28 23:51 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-06-28 16:27 Seth J. Fogarty
2006-06-28 16:47 ` [Caml-list] " Jonathan Roewen
2006-06-28 16:48   ` Jonathan Roewen
2006-06-28 23:44     ` Seth J. Fogarty
2006-06-28 23:51       ` Jonathan Roewen [this message]
     [not found]         ` <c7ee61120606281739g27fc344bt855cde4bd6a89797@mail.gmail.com>
2006-06-29  3:09           ` Jonathan Roewen
2006-06-29  3:37           ` Jacques Garrigue
2006-06-29 21:27 ` Another question on variant types and matching (was: Re: [Caml-list] Question on Variant Types) Richard Jones
2006-06-29 21:51   ` Jonathan Roewen

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=ad8cfe7e0606281651o3b9f82dfhe0067bcd581ab938@mail.gmail.com \
    --to=jonathan.roewen@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=sfogarty@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).