4

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  
Tomer
  • 1,159
  • 7
  • 15

1 Answers1

7

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
Community
  • 1
  • 1