Skip to content

Instantly share code, notes, and snippets.

@joshburgess
Last active October 1, 2019 03:50
Show Gist options
  • Save joshburgess/29f9c3df8176abef1753b7c1d61693e4 to your computer and use it in GitHub Desktop.
Save joshburgess/29f9c3df8176abef1753b7c1d61693e4 to your computer and use it in GitHub Desktop.
Weird edge case allowing polymorphic exceptions in ReasonML/OCaml
/* 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