Add named instances for functor & applicative composition

This commit is contained in:
russoul 2021-02-10 20:05:32 +03:00 committed by André Videla
parent a060dcc18e
commit 1d23c7a6bd

View File

@ -105,6 +105,12 @@ public export
ignore : Functor f => f a -> f ()
ignore = map (const ())
namespace Functor
||| Composition of functors is a functor.
export
[Compose] (Functor f, Functor g) => Functor (f . g) where
map fun = map (map fun)
||| Bifunctors
||| @f The action of the Bifunctor on pairs of objects
public export
@ -157,6 +163,15 @@ a *> b = map (const id) a <*> b
%allow_overloads (<*)
%allow_overloads (*>)
namespace Applicative
||| Composition of applicative functors is an applicative functor.
export
[Compose] (Applicative f, Applicative g) => Applicative (f . g)
using Functor.Compose where
pure = pure . pure
fun <*> x = ((<*>) <$> fun <*> x)
public export
interface Applicative f => Alternative f where
empty : f a