home/ atoms/ tidal-haskell-dollar-operator

The $ operator in Tidal applies a function to everything to its right, replacing wrapping parentheses

Tidal is built on Haskell, where functions are called by juxtaposition rather than parentheses: f arg not f(arg). The $ operator (‘apply’) means ‘apply the function on the left to everything to the right’ — it replaces an opening parenthesis with an invisible closing parenthesis at the end of the line. So d1 $ sound "bd" and d1 (sound "bd") are identical. When chaining multiple functions, $ avoids deeply nested parentheses: d1 $ every 4 (fast 4) $ sound "bd*2" applies every to the result of sound, from right to left. Understanding $ is prerequisite to reading any Tidal code.

Examples

-- these are identical:
d1 $ sound "bd"
d1 (sound "bd")
-- chained:
d1 $ every 4 (fast 4) $ sound "bd*2 [bd [sn sn*2 sn] sn]"

Assessment

Rewrite d1 $ every 4 (rev) $ sound "bd*2 sn" using only parentheses and no $. Then explain why $ is preferred in live-coding contexts.

“the $ operator that you've seen before is actually just another way of applying functions. It's the "apply" operator and you can think of it as being equivalent to a starting paren”
corpus · tidalcycles-userbase-tutorial-community-function-by-function · chunk 2