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) <*> vu <* 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 <$> xliftA2 f x y = f <$> x <*> yflip const = const idx <$ m = const x <$> mIf 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