Skip to content

Instantly share code, notes, and snippets.

@yloiseau
Created October 9, 2014 12:55
Show Gist options
  • Save yloiseau/d669c0e30023bf5b5bbc to your computer and use it in GitHub Desktop.
Save yloiseau/d669c0e30023bf5b5bbc to your computer and use it in GitHub Desktop.
curryfy fails in decorator
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 ?
}
@yloiseau
Copy link
Author

yloiseau commented Oct 9, 2014

same with

function curry = |f| -> |a| -> f:bindTo(a)

@artpej
Copy link

artpej commented Oct 9, 2014

I'm not fluent with funtionnal programming but I think it's normal: f takes only one argument (|a| -> ...) and foo always take exactly 2 arguments.

if you want to simulate the decoraction with f, it's more like this :

let f = |a,b| -> curry(^bar)(a,b)
# will fail too

in short words : the decorators current implemention prohibits to change the original function arity.

@yloiseau
Copy link
Author

yloiseau commented Oct 9, 2014

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

@jponge
Copy link

jponge commented Oct 9, 2014

Pej is right wrt the implementation :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment