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

make curried function composable #36

Closed
felixroos opened this issue Apr 10, 2022 · 5 comments
Closed

make curried function composable #36

felixroos opened this issue Apr 10, 2022 · 5 comments
Labels
enhancement improves an existing feature

Comments

@felixroos
Copy link
Collaborator

Curried functions are currently not composable:

this works:

"c3".superimpose(
  add(3),
  add(7),
)

this doesn't work:

"c3".superimpose(
  add(3).velocity(.5),
  add(7),
)

error: add(...).velocity is not a function

this works:

"c3".superimpose(
  x => x.add(3).velocity(.5),
  add(7),
)

ideally, all curried functions need to have all pattern methods.
This is what makeComposable is supposed to do, but it does not seem to work

@omicron321
Copy link

omicron321 commented Apr 11, 2022

I suggest priority on rewrite of compose #35, as it would help confine current issue

@felixroos
Copy link
Collaborator Author

#35 is done now. still not sure how to approach this. I thought it would be possible with a custom curry function (with additional overload function), but it's tricky. Some people use Proxy for this https://medium.com/dailyjs/haskell-like-composition-in-javascript-6142a2a82821 . Of course this could be fixed more easily on the eval side, but it then wouldn't work without it.

@felixroos felixroos added the enhancement improves an existing feature label Apr 24, 2022
@felixroos
Copy link
Collaborator Author

Maybe this problem can be solved much easier by flipping it around: https://strudel.tidalcycles.org?fpNMjYivvAhZ

@yaxu
Copy link
Member

yaxu commented Nov 17, 2022

Bringing discussion from #264.. Maybe we should move all the currying inside the patterns.

So add(3) returns a pattern of functions. Then add(3).mul(.5) composes together two patterns of functions, and add(3).mul(.5).fast(2) speeds up that pattern of functions.

This approach would be a challenge for stuff like this though:
s(3).n(2).every(2, add(n(3)).chop(3) )

as chopping implies changing the structure of the outer s(3).n(2) pattern, which I think the chop is too far away from..

But I think s(3).n(2).every(2, add(chop(3).n(3))) would be ok.

@yaxu
Copy link
Member

yaxu commented Feb 17, 2023

This is working now via #390 , as

note("c3").superimpose(
  add.note(3).velocity(.5),
  add.note(7),
)

or

note("c3").superimpose(
  add(note(3)).velocity(.5),
  add(note(7)),
)

@yaxu yaxu closed this as completed Feb 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement improves an existing feature
Projects
None yet
Development

No branches or pull requests

3 participants