Skip to content

Instantly share code, notes, and snippets.

@rleonid
Last active August 29, 2015 14:11
Show Gist options
  • Save rleonid/ebcbf8ea546699833945 to your computer and use it in GitHub Desktop.
Save rleonid/ebcbf8ea546699833945 to your computer and use it in GitHub Desktop.
Playing around with typing parametric polymorphic vairants
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