1

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)?

Micha Wiedenmann
  • 19,979
  • 21
  • 92
  • 137
Pawan Kumar
  • 1,443
  • 2
  • 16
  • 30

1 Answers1

4

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.

chi
  • 111,837
  • 3
  • 133
  • 218
  • Thanks got it. (<*) fa fb = liftA2 (\a _ -> a) fa fb && (*>) fa fb = liftA2 (\_ b -> b) fa fb. Can also please comment on my assumptions to the bottom of the question. – Pawan Kumar Nov 11 '19 at 09:30
  • @PKChem I don't understand the last part of your question. Are you referring to two other type classes `Sequential` and `Parallel`? I don't know about those, sorry. – chi Nov 11 '19 at 10:09