Created
March 20, 2013 12:03
-
-
Save frabbit/5204144 to your computer and use it in GitHub Desktop.
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
abstract Choice<A,B>(Dynamic) { | |
inline function new (x:Dynamic) this = x; | |
@:from static inline function fromA <A,B>(x:A):Choice<A,B> return new Choice(x); | |
@:from static inline function fromB <A,B>(x:B):Choice<A,B> return new Choice(x); | |
} | |
class Test { | |
public static function expectStringOrInt (x:Choice<String, Int>) { | |
} | |
public static function main () { | |
expectStringOrInt(1); //works | |
expectStringOrInt("hi"); //works | |
expectStringOrInt({ a : "hi"}); //error | |
expectStringOrInt(1.1); // error | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment