Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Functional operators #84

Open
ConorOBrien-Foxx opened this issue Oct 5, 2016 · 8 comments
Open

Feature request: Functional operators #84

ConorOBrien-Foxx opened this issue Oct 5, 2016 · 8 comments

Comments

@ConorOBrien-Foxx
Copy link
Member

ConorOBrien-Foxx commented Oct 5, 2016

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
Copy link
Member Author

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

@ConorOBrien-Foxx ConorOBrien-Foxx changed the title Proposal: Functional operators Feature request: Functional operators Oct 5, 2016
@schas002
Copy link

schas002 commented Oct 5, 2016

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

Memoise: should be easy to do.

@vihanb
Copy link
Member

vihanb commented Oct 5, 2016

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
Copy link
Member Author

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
Copy link

schas002 commented Oct 5, 2016

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

@vihanb
Copy link
Member

vihanb commented Oct 5, 2016

porpisal

you spelt porpoisal wrong :P

@schas002
Copy link

schas002 commented Oct 5, 2016

@vihanb fixed

@ConorOBrien-Foxx
Copy link
Member Author

@schas002 uh, okay?

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

No branches or pull requests

3 participants