Skip to content

Instantly share code, notes, and snippets.

@Gbury
Last active December 5, 2016 21:17
Show Gist options
  • Save Gbury/fbeee432179113b05b078d01bd47d511 to your computer and use it in GitHub Desktop.
Save Gbury/fbeee432179113b05b078d01bd47d511 to your computer and use it in GitHub Desktop.
GADTs and polymorphic variants
(* Overly simplified example *)
type _ foo =
| Foo : int -> [< `A | `B ] foo
| Bar : int -> [< `B | `C ] foo
(* The most general type for foo is:
int -> [< `A | `B ] foo
But, because of the call in bar, the type actually inferred is:
int -> _[< `B ] foo
*)
let rec foo i = Foo i
and bar = [ foo 1; Bar 42 ]
(* This call then fails *)
let x : [ `A ] foo = foo 5
(* Remark: If the "rec" is dropped, the correct type for foo is inferred *)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment