(<*>) = liftA2 id
liftA2 f x y = f <$> x <*> yFurther, any definition must satisfy the following:
pure id <*> v = v
pure (.) <*> u <*> v <*> w = u <*> (v <*> w)
pure f <*> pure x = pure (f x)
u <*> pure y = pure ($ y) <*> u
forall x y. p (q x y) = f x . g yit follows from the above that
liftA2 p (liftA2 q u v) = liftA2 f u . liftA2 g vIf f is also a Monad, it should satisfy (which implies that pure and <*> satisfy the applicative functor laws).
(<*>) = liftA2 id
liftA2 f x y = f <$> x <*> yFurther, any definition must satisfy the following:
pure id <*> v = v
pure (.) <*> u <*> v <*> w = u <*> (v <*> w)
pure f <*> pure x = pure (f x)
u <*> pure y = pure ($ y) <*> u
forall x y. p (q x y) = f x . g yit follows from the above that
liftA2 p (liftA2 q u v) = liftA2 f u . liftA2 g vIf f is also a Monad, it should satisfy (which implies that pure and <*> satisfy the applicative functor laws).
pure id <*> v = v
pure (.) <*> u <*> v <*> w = u <*> (v <*> w)
pure f <*> pure x = pure (f x)
u <*> pure y = pure ($ y) <*> u
bmap ((Pair a b) -> Pair (f a) (g b)) (u `bprod' v) = bmap f u `bprod' bmap g v
bmap ((Pair _ b) -> b) (bpure e `bprod' v) = v bmap ((Pair a _) -> a) (u `bprod' bpure e) = u
bmap ((Pair a (Pair b c)) -> Pair (Pair a b) c) (u `bprod' (v `bprod' w)) = (u `bprod' v) `bprod' wIt is to FunctorB in the same way as Applicative relates to Functor. For a presentation of Applicative as a monoidal functor, see Section 7 of Applicative Programming with Effects. There is a default implementation of bprod and bpure based on Generic. Intuitively, it works on types where the value of bpure is uniquely defined. This corresponds rougly to record types (in the presence of sums, there would be several candidates for bpure), where every field is either a Monoid or covered by the argument f.
tmap ((Pair a b) -> Pair (f a) (g b)) (u `tprod' v) = tmap f u `tprod' tmap g v
tmap ((Pair _ b) -> b) (tpure e `tprod' v) = v tmap ((Pair a _) -> a) (u `tprod' tpure e) = u
tmap ((Pair a (Pair b c)) -> Pair (Pair a b) c) (u `tprod' (v `tprod' w)) = (u `tprod' v) `tprod' wIt is to FunctorT in the same way is Applicative relates to Functor. For a presentation of Applicative as a monoidal functor, see Section 7 of Applicative Programming with Effects. There is a default implementation of tprod and tpure based on Generic. Intuitively, it works on types where the value of tpure is uniquely defined. This corresponds rougly to record types (in the presence of sums, there would be several candidates for tpure), where every field is either a Monoid or covered by the argument f.
applicativeSpecOnArbitrary @[]
applicativeSpecOnArbitrary @[]
applicativeSpecOnGens @Maybe @String (pure "ABC") "ABC" (Just <$> pure "ABC") "Just an ABC" (pure Nothing) "purely Nothing" ((++) <$> genValid) "prepends" (pure <$> ((++) <$> genValid)) "prepends in a Just" (pure <$> (flip (++) <$> genValid)) "appends in a Just"