# More on the dollar sign

**URL:** <https://uzu.lurk.org/t/more-on-the-dollar-sign/3952>\
**Category:** TidalCycles\
**Tags:** questions\
**Created:** [24 March 2022 23:41 UTC](https://uzu.lurk.org/t/more-on-the-dollar-sign/3952 "2022-03-24T23:41:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![staxl](https://uzu.lurk.org/user_avatar/uzu.lurk.org/staxl/32/1717_2.png) [@staxl](https://uzu.lurk.org/u/staxl)\
**Post date:** [24 March 2022 23:41 UTC](https://uzu.lurk.org/t/more-on-the-dollar-sign/3952/1 "2022-03-24T23:41:21Z")

</div>

Hey all!  
In the docs or elsewehere I sometimes find the dollar sign used inside brackets like so:

```haskell
d1 $ segment 16 $ n (scale "minor" $ floor <$> (range 0 14 sine))
  # sound "supersaw"

```

There the `<$>` works kind of like the usual `$`: taking the right-hand side stuff and passing it to the left-hand side function (`floor`). But I found some uses of `<$>` that I can't really wrap my head around here: [tidal-workshop/workshop.tidal at master · tidalcycles/tidal-workshop · GitHub](https://github.com/tidalcycles/tidal-workshop/blob/master/workshop.tidal)

So I wonder in general, how do these angle brackets change what `$` usually does?

Other than that, I sometimes saw the dollar sign used in paratheses `($)`, e.g.:

```haskell
d1 $ spread ($) [gap 4, striate 4] $ sound "ho ho:2 ho:3 hc"

```

This seems to allow `spread` to take an array of functions as an input and spread it across a pattern. But I wonder how to actually read that `($)`. Does anyone know?

---

<div class="post-metadata">

**Author:** ![polymorphic.engine](https://uzu.lurk.org/user_avatar/uzu.lurk.org/polymorphic.engine/32/30_2.png) [@polymorphic.engine](https://uzu.lurk.org/u/polymorphic.engine)\
**Post date:** [25 March 2022 10:25 UTC](https://uzu.lurk.org/t/more-on-the-dollar-sign/3952/2 "2022-03-25T10:25:23Z")

</div>

The `$` is an operator in haskell with the following definition

```haskell
($) :: (a -> b) -> a -> b
($) f x = f x

```

so seemingly it doesn't actually do anything, but the thing is that it has a very low precedence, so whatever is on it's right side will be evaluated first and than passed to whatever function is on it's left side. This is very useful for not having to type too many brackets.

if it is used without brackets, then it is in infix notation, which means you can write it between two expressions (like `f $ x`). If you write it in brackets, it is in prefix notation, so you can write `($) f x` which doesn't make much sense unless you want to pass the operator itself as a function like in the example with spread.

Now the `<$>` operator has the following definition:

```haskell
(<$>) :: Functor f => (a -> b) -> f a -> f b
(<$>) = fmap

```

this function basically defines the typeclass `Functor`. For us it is only important that the type constructor Pattern is part of that typeclass. More specifically we get the concrete function:

`(<$>) :: (a -> b) -> Pattern a -> Pattern b`

It is quite similar to `($)` in that it applies a function to an input, but it also "lifts" that function to work on patterns, and not only on primitive values.

In your example `(range 0 14 sine)` is of type `Pattern Double` and you would like to apply floor to the Doubles inside the Pattern (think of patterns as containers). You can not just apply floor directly (with $), but you can use \<$\> instead.

I hope this makes it somewhat clear, but please feel free to ask questions! 🙂
