# What's the difference between |+| and (+) <$> a <*> b asked 2017-01-07 09:36:53 -0500 This post is a wiki. Anyone with karma >1 is welcome to improve it. Why is it sometimes necessary to use completely different syntax to combine patterns? edit retag close merge delete ## 1 answer Sort by ยป oldest newest most voted answered 2017-01-07 10:19:06 -0500 This post is a wiki. Anyone with karma >1 is welcome to improve it. The core issue is the difference between basic Patterns and what Tidal calls "ParamPatterns". ### "Basic" Patterns "Pattern" is a generic class of types - you can have Pattern Int: "0 1 2", a Pattern Double: "0.1 0.8", a Pattern String: "rave arpy" or any other type. However, note that these Patterns don't have a name in front like n or sound or speed - they're "basic" types, and don't yet mean anything to a synthesizer (like SuperDirt). Since these are patterns of types such as "Int" or "Double", you can combine them with ordinary math, as long as you tell Haskell to "lift" or "map" the operators so they work on Patterns of numbers instead of just normal numbers. So that's where you see expressions like (+) <$> "0 1 2" <*> "4"


or

liftA2 (+) "0 1 2" "4"


### Which should I use?

Often you can do things either way, so whichever is most convenient. Some Tidal functions (like striate) only work on ParamPatterns, so they can force you to use ParamPattern operators. But these two are completely equivalent:

n ((+) <\$> (run 8) <*> "2")

n (run 8) |+| n "2"


If you want to more complex math than just arithmetic, it'll be much easier to work with the number pattern before turning it into a ParamPattern

speed (fmap ((**2) . cos . (/8)) run 32)


which makes the number pattern run 32, divides by 8, takes the cosine, and squares it.

more

Is there a reference for all the tidal operators somewhere? I couldn't find it in the documentation.

( 2017-01-09 17:38:33 -0500 )edit

I don't think so, but that sounds like a good suggestion!

( 2017-01-09 20:49:42 -0500 )edit

Definitely on the list of things to do. Thanks for the suggestion.

( 2017-01-10 09:37:44 -0500 )edit