Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* [Caml-list] intersections of polymorphic variants
@ 2017-02-09  9:52 Martin DeMello
  2017-02-09  9:57 ` Jeremy Yallop
  0 siblings, 1 reply; 4+ messages in thread
From: Martin DeMello @ 2017-02-09  9:52 UTC (permalink / raw)
  To: caml-list

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

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

martin

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

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

end of thread, other threads:[~2017-02-09 15:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-09  9:52 [Caml-list] intersections of polymorphic variants Martin DeMello
2017-02-09  9:57 ` Jeremy Yallop
2017-02-09 10:03   ` Martin DeMello
2017-02-09 15:15     ` Ashish Agarwal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox