Can I assume that the below is true for all applicatives ?
f1 <* f2 = fmap const f1 <*> f2
and
f1 *> f2 = fmap (flip const ) f1 <*> f2
Yes. From the documentation for Applicative
:
The other methods have the following default definitions, which may be overridden with equivalent specialized implementations:
u *> v = (id <$ u) <*> v
u <* v = liftA2 const u v
The key word there is "equivalent". Since your definitions are equivalent to those ones*, they must also be equivalent to those of all lawful Applicatives.
*If you're not convinced that your definitions are equivalent to those ones, here's some hints:
fmap f x = f <$> x
liftA2 f x y = f <$> x <*> y
flip const = const id
x <$ m = const x <$> m
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With