Skip to content

Instantly share code, notes, and snippets.

@frabbit
Forked from anonymous/gist:4317927
Created December 17, 2012 12:26
Show Gist options
  • Save frabbit/4317936 to your computer and use it in GitHub Desktop.
Save frabbit/4317936 to your computer and use it in GitHub Desktop.
Haxe Partial Application Proposal
// - Implicit and explicit PA (via partial function)
// - Short alternative for partial => part, foo.part(_)
// - Implicit as default usage (short and concise), explicit for corner cases, where implicit usage is not possible/ambigous
// - Explicit PA can handle all cases that implicit PA can handle + corner cases
// - Implicit PA is only applied if one of the arguments is an underscore
function foo(x:Array<Int>, ?a:Int, ?b:Int):Void;
// Implicit Explicit Type
foo(_) <=> foo.partial(_) // Array<Int>->Void
foo(_,_) <=> foo.partial(_,_) // Array<Int>->?a:Int->Void
foo(_,_,_) <=> foo.partial(_,_,_) // Array<Int>->?a:Int->?b:Int->Void
foo.partial([]) // Void->Void, implicit PA not available because foo([]) is ambigious
foo.partial([],1) // Void->Void, implicit PA not available because foo([],1) is ambigious
foo([],_,1) <=> foo.partial([],_,1) // ?a:Int->Void
foo([],1,_) <=> foo.partial([],1,_) // ?b:Int->Void
foo([], _,_) <=> foo.partial([],_,_) // ?a:Int->?b:Int->Void
function bar(?a:Int, ?b:Int):Void;
// Implicit Explicit Type
bar.partial() // Void->Void, implicit PA not available because bar() is ambigious
bar(_) <=> bar.partial(_) // ?a:Int->Void
bar.partial(1) // Void->Void, implicit PA not available because bar(1) is ambigious
bar(1,_) <=> bar.partial(1,_) // ?b:Int->Void
bar(_,1) <=> bar.partial(_,1) // ?a:Int->Void
bar(_,_) <=> bar.partial(_,_) // ?a:Int->?b:Int->Void
function fooBar(?a:Int):Void;
// Implicit Explicit Type
fooBar.partial() // Void->Void, implicit PA not available because fooBar() is ambigious
fooBar.partial(1) // Void->Void, implicit PA not available because fooBar(1) is ambigious
fooBar(_) <=> fooBar.partial(_) // ?a:Int->Void
function foox(a:Int,b:Int):Void;
// Implicit Explicit Type
foox(1,_) <=> foox.partial(1,_) // b:Int->Void
foox(_,1) <=> foox.partial(_,1) // a:Int->Void
<=> foox.partial(1,1) // Void->Void, implicit PA not available because foox(1,1) is ambigious
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment