Cheddar icon indicating copy to clipboard operation
Cheddar copied to clipboard

Feature request: Functional operators

Open ConorOBrien-Foxx opened this issue 9 years ago • 8 comments

There should be an operator that curries a function. Perhaps ~:?

let add = ~: (x, y, z) -> x + y * z;
print(add(3)(4)(5));    // 23

A memoizing function/operator. E.g.:

let fib = memo(n -> n < 2 ? n : fib(n - 1) + fib(n - 2))
fib(1000); // takes however long
fib(1000); // takes virtually no time

Dynamic programing FTW!


I wonder if any more should be considered.

ConorOBrien-Foxx avatar Oct 05 '16 02:10 ConorOBrien-Foxx

Another idea: (N ~ f)(*a) is the same as calling f(*a,...*a) where *a is repeated N times.

ConorOBrien-Foxx avatar Oct 05 '16 03:10 ConorOBrien-Foxx

Currying: a => b => a+b => f(a, b) IIRC

Memoise: should be easy to do.

schas002 avatar Oct 05 '16 03:10 schas002

Memoize is easy but it's another thing if you don't want to use a hell ton of memory. Cyrrying is the otherway btw

vihanb avatar Oct 05 '16 04:10 vihanb

Some more revisions/additions:

F * n is function repetition. E.g., (F*3)(4) = F(F(F(4)))

F ** n is function argument repetition. E.g., (F**2)(2,3) = F(2,3,2,3)

ConorOBrien-Foxx avatar Oct 05 '16 04:10 ConorOBrien-Foxx

@ConorOBrien-Foxx can I plz make another porpoisal with that? ;3 (I will credit you)

schas002 avatar Oct 05 '16 04:10 schas002

porpisal

you spelt porpoisal wrong :P

vihanb avatar Oct 05 '16 04:10 vihanb

@vihanb fixed

schas002 avatar Oct 05 '16 04:10 schas002

@schas002 uh, okay?

ConorOBrien-Foxx avatar Oct 05 '16 11:10 ConorOBrien-Foxx