idiomatic-0.1.1.0: Deriving Applicative for sum types.. Idiomatically.
Safe HaskellNone
LanguageHaskell98

Generic.Applicative

Synopsis

Documentation

newtype LeftBias tag f g a Source #

Constructors

LeftBias (Sum f g a) 

Instances

Instances details
(Functor f, Functor g) => Functor (LeftBias tag f g) Source # 
Instance details

Defined in Generic.Applicative

Methods

fmap :: (a -> b) -> LeftBias tag f g a -> LeftBias tag f g b #

(<$) :: a -> LeftBias tag f g b -> LeftBias tag f g a #

Idiom tag f g => Applicative (LeftBias tag f g) Source #

An applicative instance of Sum biased to the left.

It injects pure into the InL constructor:

  pure = LeftBias . InL . pure
Instance details

Defined in Generic.Applicative

Methods

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

Constructors

RightBias (Sum f g a) 

Instances

Instances details
(Functor f, Functor g) => Functor (RightBias tag f g) Source # 
Instance details

Defined in Generic.Applicative

Methods

fmap :: (a -> b) -> RightBias tag f g a -> RightBias tag f g b #

(<$) :: a -> RightBias tag f g b -> RightBias tag f g a #

Idiom tag g f => Applicative (RightBias tag f g) Source # 
Instance details

Defined in Generic.Applicative

Methods

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 #

This exists in versions that don't have Generically1, i.e. before base 4.17.0.0.

Constructors

Generically1 (f a) 

Instances

Instances details
Generic1 f => Generic1 (Generically1 f :: k -> Type) Source # 
Instance details

Defined in Generic.Applicative.Internal

Associated Types

type Rep1 (Generically1 f) :: k -> Type #

Methods

from1 :: forall (a :: k0). Generically1 f a -> Rep1 (Generically1 f) a #

to1 :: forall (a :: k0). Rep1 (Generically1 f) a -> Generically1 f a #

(Generic1 f, Functor (Rep1 f)) => Functor (Generically1 f) Source # 
Instance details

Defined in Generic.Applicative.Internal

Methods

fmap :: (a -> b) -> Generically1 f a -> Generically1 f b #

(<$) :: a -> Generically1 f b -> Generically1 f a #

(Generic1 f, Applicative (Rep1 f)) => Applicative (Generically1 f) Source # 
Instance details

Defined in Generic.Applicative.Internal

Methods

pure :: a -> Generically1 f a #

(<*>) :: Generically1 f (a -> b) -> Generically1 f a -> Generically1 f b #

liftA2 :: (a -> b -> c) -> Generically1 f a -> Generically1 f b -> Generically1 f c #

(*>) :: Generically1 f a -> Generically1 f b -> Generically1 f b #

(<*) :: Generically1 f a -> Generically1 f b -> Generically1 f a #

type Rep1 (Generically1 f :: k -> Type) Source # 
Instance details

Defined in Generic.Applicative.Internal

type Rep1 (Generically1 f :: k -> Type) = Rep1 f

newtype NewSums sums f a Source #

Constructors

NewSums 

Fields

Instances

Instances details
(Generic1 f, ConvBæSum_ (CheckSum (ToSum (Rep1 f) (Const Void :: k -> Type))) (ToSum (Rep1 f) (Const Void :: k -> Type)), ConvSum (Rep1 f)) => Generic1 (NewSums sums f :: k -> Type) Source # 
Instance details

Defined in Generic.Applicative.Internal

Associated Types

type Rep1 (NewSums sums f) :: k -> Type #

Methods

from1 :: forall (a :: k0). NewSums sums f a -> Rep1 (NewSums sums f) a #

to1 :: forall (a :: k0). Rep1 (NewSums sums f) a -> NewSums sums f a #

type Rep1 (NewSums sums f :: k -> Type) Source # 
Instance details

Defined in Generic.Applicative.Internal

type Rep1 (NewSums sums f :: k -> Type) = ReplaceSums sums (BæSum_ (CheckSum (ToSum (Rep1 f) (Const Void :: k -> Type))) (ToSum (Rep1 f) (Const Void :: k -> Type)))