-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Description
In the bottom example for squaz curry doesn't match without the special-cased curry()
proc curry[A, Ret] (
funk: proc(someA: A): Ret,
valueA: A): proc: Ret =
return proc: Ret = funk(valueA)
proc curry[A,B, Ret] (
funk: proc(someA: A, someB: B): Ret,
valueA: A): proc(someB: B): Ret =
return proc(someB: B): Ret = funk(valueA, someB)
proc curry[A,B,C, Ret] (
funk: proc(someA: A, someB: B, someC: C): Ret,
valueA: A): proc(someB: B, someC: C): Ret =
return proc(someB: B, someC: C): Ret = funk(valueA, someB, someC)
proc curry[A,B,C,D, Ret] (
funk: proc(someA:A, someB:B, someC:C, someD:D): Ret,
valueA: A): proc(someB:B,someC:C,someD:D): Ret =
return proc(someB:B,someC:C,someD:D): Ret = funk(valueA, someB,someC,someD)
when isMainModule:
proc foo(a, b: int): int =
return a * b
proc foo2(a, b, c: int): int =
return a * b * c
let f = foo.curry(50)
assert f(2) == 100
let f2 = foo2.curry(2)
assert f2(3, 2) == 12
assert f2.curry(3)(2) == 12
proc squaz(some: int) = echo(some)
curry[int,void](squaz, 9001)()
proc curry[A] (funk: proc(someA: A), valueA: A): proc() =
return proc = funk(valueA)
## this doesnt work without the above function
curry(squaz, 9001)()