Skip to content

Instantly share code, notes, and snippets.

@ncannasse
Created July 6, 2015 06:45
Show Gist options
  • Select an option

  • Save ncannasse/e235f64d2fbcac399abb to your computer and use it in GitHub Desktop.

Select an option

Save ncannasse/e235f64d2fbcac399abb to your computer and use it in GitHub Desktop.
enum Error<T> {
Code( i : Int ) : Error<Int>;
Message( s : String ) : Error<String>;
}
function getError<T>( e : Error<T> ) : T {
switch( e ) {
case Code(c): return c;
case Message(s): return s;
}
}
$type(getError(Code(55))); // Int
$type(getError(Message("something bad happenned"))); // String
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment