Last active
August 29, 2015 14:11
-
-
Save rleonid/ebcbf8ea546699833945 to your computer and use it in GitHub Desktop.
Playing around with typing parametric polymorphic vairants
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 ('b , 'a) foo = [ `Foo of 'a | |
| `Bar of 'b | |
] | |
type ('a, 'c) ani = [ (('a, 'c) foo) | |
| `Cat of 'a | |
| `Dog of 'a | |
] | |
let foo_to_str = function | |
| `Foo f -> "Foo " ^ f | |
| `Bar b -> "Bar " ^ b | |
let ani_to_str = function | |
| #foo as f -> foo_to_str f | |
| `Cat c -> "Cat " ^ c | |
| `Dog d -> "Dog " ^ d | |
let swap_foo = function | |
| `Foo f -> `Bar f | |
| `Bar b -> `Foo b | |
let swap_ani = function | |
| #foo as f -> swap_foo f | |
| `Cat c -> `Dog c | |
| `Dog d -> `Cat d | |
let swap_ani2 = function | |
| `Foo f -> `Bar f | |
| `Bar b -> `Foo b | |
| `Cat c -> `Dog c | |
| `Dog d -> `Cat d |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment