cheddar-lang / Cheddar

🧀 Cheddar, the language that works for you
cheddar.vihan.org
Apache License 2.0
28 stars 9 forks source link

Feature request: Functional operators #84

Open ConorOBrien-Foxx opened 7 years ago

ConorOBrien-Foxx commented 7 years ago

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 commented 7 years ago

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

schas002 commented 7 years ago

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

Memoise: should be easy to do.

vihanb commented 7 years ago

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

ConorOBrien-Foxx commented 7 years ago

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)

schas002 commented 7 years ago

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

vihanb commented 7 years ago

porpisal

you spelt porpoisal wrong :P

schas002 commented 7 years ago

@vihanb fixed

ConorOBrien-Foxx commented 7 years ago

@schas002 uh, okay?