Skip to content

Instantly share code, notes, and snippets.

@Leonidas-from-XIV
Last active June 6, 2018 18:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Leonidas-from-XIV/6d22e9cd6efb21e6995245447d60d80d to your computer and use it in GitHub Desktop.
Save Leonidas-from-XIV/6d22e9cd6efb21e6995245447d60d80d to your computer and use it in GitHub Desktop.
Unifying polymorphic variants
type foo = [`Hello | `World | `Other]
type bar = [`Yet | `Another | `Other]
type baz = [foo | bar]
type qux = Foo of foo | Bar of bar | Quux
let transform = function
| Foo x -> x
| Bar x -> x
| Quux -> `Other
type foo = [`Hello | `World | `Other]
type bar = [`Yet | `Another | `Other]
type baz = [foo | bar]
type qux = Foo of foo | Bar of bar | Quux
let transform = function
| Foo `Hello -> `Hello
| Foo `World -> `World
| Foo `Other -> `Other
| Bar `Yet -> `Yet
| Bar `Another -> `Another
| Bar `Other -> `Other
| Quux -> `Other
type foo = [`Hello | `World | `Other]
type bar = [`Yet | `Another | `Other]
type baz = [foo | bar]
type qux = Foo of foo | Bar of bar | Quux
let transform = function
| Foo x -> (x :> baz)
| Bar x -> (x :> baz)
| Quux -> `Other
(* thanks octachron *)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment