module curry
----
Function to curryfy a diadic function
----
function curry = |f| -> |a| -> |b| -> f(a, b)
@curry
function foo = |a, b| -> a + b
function bar = |a, b| -> a + b
function main = |args| {
# let's curryfy bar
let f = curry(^bar)
# and call it
println(f(1)(4)) # all is well
# trying with the decorated one
println(foo(1)(4))
# Blam... java.lang.NoSuchMethodError: foo
# WTF ?
}
Created
October 9, 2014 12:55
-
-
Save yloiseau/d669c0e30023bf5b5bbc to your computer and use it in GitHub Desktop.
curryfy fails in decorator
well, normal w.r.t. the decorator implementation :)
curry = lambda f: lambda a: lambda b: f(a, b)
@curry
def foo(a, b):
return a + b
foo(21)(21) # -> 42
Pej is right wrt the implementation :-)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm not fluent with funtionnal programming but I think it's normal:
f
takes only one argument (|a| -> ...
) andfoo
always take exactly 2 arguments.if you want to simulate the decoraction with
f
, it's more like this :in short words : the decorators current implemention prohibits to change the original function arity.