I can define them using monads.
(<*) :: Monad m => m a -> m b -> m a
(<*) fa fb = fa >>= \a -> (fb >>= \_ -> return a)
(<*) fa fb = ??? -- In terms of pure & (<*>)
(*>) :: Monad m => m a -> m b -> m b
(*>) fa fb = fa >>= \_ -> (fb >>= \b -> return b)
(*>) fa fb = ??? -- In terms of pure & (<*>)
(\*>)
and (<\*)
are considered as sequencing operators. Can I safely assume that Applicatives can do work in both Sequential and Parallel? Monads are just a sub category of applicatives only capable of doing things sequentiallay. And even though it doesn't matter the order of operations for few monads like the reader monad (example reading configurations from a HashMap
of environment settings)?
The standard definition is
(<*) :: Applicative m => m a -> m b -> m a
(<*) fa fb = (\a _ -> a) <$> fa <*> fb
We can then apply the law f <$> x = pure f <*> x
to only use <*>
and pure
.
The other one is analogous.