Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The definition for (<*) and (*>)

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  
like image 746
Tomer Avatar asked Mar 10 '20 02:03

Tomer


1 Answers

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
like image 171
Joseph Sible-Reinstate Monica Avatar answered Oct 03 '22 22:10

Joseph Sible-Reinstate Monica