Safe Haskell | None |
---|---|
Language | Haskell98 |
Synopsis
- newtype LeftBias tag f g a = LeftBias (Sum f g a)
- newtype RightBias tag f g a = RightBias (Sum f g a)
- type Idiomatically f sums = Generically1 (NewSums (Served sums) f)
- newtype Generically1 f a = Generically1 (f a)
- newtype NewSums sums f a = NewSums {
- reduce :: f a
- module Generic.Applicative.Idiom
Documentation
newtype LeftBias tag f g a Source #
Instances
(Functor f, Functor g) => Functor (LeftBias tag f g) Source # | |
Idiom tag f g => Applicative (LeftBias tag f g) Source # | An applicative instance of It injects pure = LeftBias . InL . pure |
Defined in Generic.Applicative pure :: a -> LeftBias tag f g a # (<*>) :: LeftBias tag f g (a -> b) -> LeftBias tag f g a -> LeftBias tag f g b # liftA2 :: (a -> b -> c) -> LeftBias tag f g a -> LeftBias tag f g b -> LeftBias tag f g c # (*>) :: LeftBias tag f g a -> LeftBias tag f g b -> LeftBias tag f g b # (<*) :: LeftBias tag f g a -> LeftBias tag f g b -> LeftBias tag f g a # |
newtype RightBias tag f g a Source #
An applicative instance of Sum
biased to the
right.
It injects pure
into the InR
constructor:
pure = LeftBias . InR . pure
Instances
(Functor f, Functor g) => Functor (RightBias tag f g) Source # | |
Idiom tag g f => Applicative (RightBias tag f g) Source # | |
Defined in Generic.Applicative pure :: a -> RightBias tag f g a # (<*>) :: RightBias tag f g (a -> b) -> RightBias tag f g a -> RightBias tag f g b # liftA2 :: (a -> b -> c) -> RightBias tag f g a -> RightBias tag f g b -> RightBias tag f g c # (*>) :: RightBias tag f g a -> RightBias tag f g b -> RightBias tag f g b # (<*) :: RightBias tag f g a -> RightBias tag f g b -> RightBias tag f g a # |
type Idiomatically f sums = Generically1 (NewSums (Served sums) f) Source #
A modifier that is used to generically derive Applicative
for
sum types.
Types with a single constructor can derive Applicative
using
Generically1
from GHC.Generics
:
Generically1 f = Idiomatically f '[]
A datatype with multiple constructors requires more input from the
user: what constructor should be pure
and how to map between two
different constructors in a law-abiding way.
This is done by specifying the appliative morphisms (Idiom
)
between each constructor.
Applicative
for Maybe
can be derived via the Terminal
applicative morphism, biased to the right. RightBias Terminal
means that when we lift over Nothing
and Just
it will result in
Nothing
.
data Maybe a = Nothing | Just a deriving stock Generic1 deriving (Functor, Applicative) via Idiomatically Maybe '[RightBias Terminal]
The same description derives Applicative
for ZipList
:
type ZipList :: Type -> Type data ZipList a = ZNil | a ::: ZipList deriving stock Generic1 deriving (Functor, Applicative) via Idiomatically ZipList '[RightBias Terminal]
newtype Generically1 f a Source #
Generically1 (f a) |
Instances
module Generic.Applicative.Idiom