Last active
December 5, 2016 21:17
-
-
Save Gbury/fbeee432179113b05b078d01bd47d511 to your computer and use it in GitHub Desktop.
GADTs and polymorphic variants
This file contains 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
(* 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