I was reading this interesting post for the hundredth time and I am still trying to understand what's behind the different instances of Pattern
and especially when it is useful to handle Monad Pattern
, Functor Pattern
and Applicative Pattern
.
Here is what I got so far:
-
Functor Pattern
comes handy when we want to use function from e.g. the standardPrelude
module but we don't know how to cope with thePattern
context. We use<$>
and we get a result wrapped in aPattern
context that we can use inside Tidal.
E.g.chop (round <$> (slow 8 $ range 1 128 $ sine))
- thanks @nuelmyr for the pattern -
Monad Pattern
comes handy when we have a function that returns aPattern
context, but it does not accept a value in a context. We use>>=
and theMonad Pattern
will apply the function to thePattern
and we get a result wrapped in aPattern
context.
I think the example from the post is quite explicative:
fastFromList[False,False,True] >>= \ f -> if not f then run 2 else run 3
But what about Applicative Pattern
: what is a pattern of functions (Pattern (a -> b)
)?
I am very interested in seeing some examples on how you use the different instances of Pattern
to create your own functions.