Last active
October 1, 2019 03:50
-
-
Save joshburgess/29f9c3df8176abef1753b7c1d61693e4 to your computer and use it in GitHub Desktop.
Weird edge case allowing polymorphic exceptions in ReasonML/OCaml
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
/* Uncomment below line to see error */ | |
/* exception Absurd('a); */ | |
/* ^^ Error: Unbound type parameter 'a */ | |
/* | |
Normally, exceptions are monomorphic. They usually cannot take in type params... | |
*/ | |
/* | |
...But what if we skip the `exception` syntax sugar and just use the `+=` open | |
variant extension syntax in tandem with GADT syntax? Aha! We've done the impossible! | |
*/ | |
type exn += | |
| Absurd('a) : exn; | |
let absurdString = Absurd("lol"); | |
let absurdInt = Absurd(0); | |
let absurdPolyVar = Absurd([ `LolWut ]); | |
raise(absurdString); | |
/* raise(absurdInt); */ | |
/* raise(absurdPolyVar); */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment