Last active
June 6, 2018 18:42
-
-
Save Leonidas-from-XIV/6d22e9cd6efb21e6995245447d60d80d to your computer and use it in GitHub Desktop.
Unifying polymorphic variants
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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