strudel icon indicating copy to clipboard operation
strudel copied to clipboard

make curried function composable

Open felixroos opened this issue 3 years ago • 7 comments

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

felixroos avatar Apr 10 '22 12:04 felixroos

I suggest priority on rewrite of compose https://github.com/tidalcycles/strudel/issues/35, as it would help confine current issue

omicron321 avatar Apr 11 '22 20:04 omicron321

#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 avatar Apr 12 '22 20:04 felixroos

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

felixroos avatar Nov 11 '22 16:11 felixroos

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 avatar Nov 17 '22 16:11 yaxu

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 avatar Feb 17 '23 12:02 yaxu