functor-combinators-0.4.1.2: Tools for functor combinator-based program design
Copyright(c) Justin Le 2019
LicenseBSD3
Maintainerjustin@jle.im
Stabilityexperimental
Portabilitynon-portable
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.Functor.Invariant.Night

Description

Provides an Invariant version of a Day convolution over Either.

Since: 0.3.0.0

Synopsis

Documentation

data Night :: (Type -> Type) -> (Type -> Type) -> Type -> Type where Source #

A pairing of invariant functors to create a new invariant functor that represents the "choice" between the two.

A Night f g a is a invariant "consumer" and "producer" of a, and it does this by either feeding the a to f, or feeding the a to g, and then collecting the result from whichever one it was fed to. Which decision of which path to takes happens at runtime depending what a is actually given.

For example, if we have x :: f a and y :: g b, then night x y :: Night f g (Either a b). This is a consumer/producer of Either a bs, and it consumes Left branches by feeding it to x, and Right branches by feeding it to y. It then passes back the single result from the one of the two that was chosen.

Mathematically, this is a invariant day convolution, except with a different choice of bifunctor (Either) than the typical one we talk about in Haskell (which uses (,)). Therefore, it is an alternative to the typical Day convolution --- hence, the name Night.

Constructors

Night :: f b -> g c -> (b -> a) -> (c -> a) -> (a -> Either b c) -> Night f g a 

Instances

Instances details
Associative Night Source # 
Instance details

Defined in Data.HBifunctor.Associative

Associated Types

type NonEmptyBy Night :: (Type -> Type) -> Type -> Type Source #

type FunctorBy Night :: (Type -> Type) -> Constraint Source #

Methods

associating :: forall (f :: Type -> Type) (g :: Type -> Type) (h :: Type -> Type). (FunctorBy Night f, FunctorBy Night g, FunctorBy Night h) => Night f (Night g h) <~> Night (Night f g) h Source #

appendNE :: forall (f :: Type -> Type). Night (NonEmptyBy Night f) (NonEmptyBy Night f) ~> NonEmptyBy Night f Source #

matchNE :: forall (f :: Type -> Type). FunctorBy Night f => NonEmptyBy Night f ~> (f :+: Night f (NonEmptyBy Night f)) Source #

consNE :: forall (f :: Type -> Type). Night f (NonEmptyBy Night f) ~> NonEmptyBy Night f Source #

toNonEmptyBy :: forall (f :: Type -> Type). Night f f ~> NonEmptyBy Night f Source #

Inalt f => SemigroupIn Night f Source #

Since: 0.4.0.0

Instance details

Defined in Data.HBifunctor.Associative

Methods

biretract :: Night f f ~> f Source #

binterpret :: forall (g :: Type -> Type) (h :: Type -> Type). (g ~> f) -> (h ~> f) -> Night g h ~> f Source #

Matchable Night Not Source # 
Instance details

Defined in Data.HBifunctor.Tensor

Methods

unsplitNE :: forall (f :: Type -> Type). FunctorBy Night f => Night f (ListBy Night f) ~> NonEmptyBy Night f Source #

matchLB :: forall (f :: Type -> Type). FunctorBy Night f => ListBy Night f ~> (Not :+: NonEmptyBy Night f) Source #

Tensor Night Not Source # 
Instance details

Defined in Data.HBifunctor.Tensor

Associated Types

type ListBy Night :: (Type -> Type) -> Type -> Type Source #

Methods

intro1 :: forall (f :: Type -> Type). f ~> Night f Not Source #

intro2 :: forall (g :: Type -> Type). g ~> Night Not g Source #

elim1 :: forall (f :: Type -> Type). FunctorBy Night f => Night f Not ~> f Source #

elim2 :: forall (g :: Type -> Type). FunctorBy Night g => Night Not g ~> g Source #

appendLB :: forall (f :: Type -> Type). Night (ListBy Night f) (ListBy Night f) ~> ListBy Night f Source #

splitNE :: forall (f :: Type -> Type). NonEmptyBy Night f ~> Night f (ListBy Night f) Source #

splittingLB :: forall (f :: Type -> Type). ListBy Night f <~> (Not :+: Night f (ListBy Night f)) Source #

toListBy :: forall (f :: Type -> Type). Night f f ~> ListBy Night f Source #

fromNE :: forall (f :: Type -> Type). NonEmptyBy Night f ~> ListBy Night f Source #

HBifunctor Night Source # 
Instance details

Defined in Data.HFunctor.Internal

Methods

hleft :: forall (f :: k -> Type) (j :: k -> Type) (g :: k -> Type). (f ~> j) -> Night f g ~> Night j g Source #

hright :: forall (g :: k -> Type) (l :: k -> Type) (f :: k -> Type). (g ~> l) -> Night f g ~> Night f l Source #

hbimap :: forall (f :: k -> Type) (j :: k -> Type) (g :: k -> Type) (l :: k -> Type). (f ~> j) -> (g ~> l) -> Night f g ~> Night j l Source #

Inplus f => MonoidIn Night Not f Source #

Since: 0.4.0.0

Instance details

Defined in Data.HBifunctor.Tensor

Methods

pureT :: Not ~> f Source #

HTraversable (Night f :: (Type -> Type) -> Type -> Type) Source # 
Instance details

Defined in Data.HFunctor.HTraversable

Methods

htraverse :: forall h f0 g (a :: k1). Applicative h => (forall (x :: k). f0 x -> h (g x)) -> Night f f0 a -> h (Night f g a) Source #

HTraversable1 (Night f :: (Type -> Type) -> Type -> Type) Source # 
Instance details

Defined in Data.HFunctor.HTraversable

Methods

htraverse1 :: forall h f0 g (a :: k1). Apply h => (forall (x :: k). f0 x -> h (g x)) -> Night f f0 a -> h (Night f g a) Source #

HFunctor (Night f :: (Type -> Type) -> Type -> Type) Source # 
Instance details

Defined in Data.HFunctor.Internal

Methods

hmap :: forall (f0 :: k -> Type) (g :: k -> Type). (f0 ~> g) -> Night f f0 ~> Night f g Source #

Invariant (Night f g) Source # 
Instance details

Defined in Data.Functor.Invariant.Night

Methods

invmap :: (a -> b) -> (b -> a) -> Night f g a -> Night f g b #

Invariant f => Inalt (Chain1 Night f) Source #

Since: 0.4.0.0

Instance details

Defined in Data.HFunctor.Chain

Methods

swerve :: (b -> a) -> (c -> a) -> (a -> Either b c) -> Chain1 Night f b -> Chain1 Night f c -> Chain1 Night f a Source #

swerved :: Chain1 Night f a -> Chain1 Night f b -> Chain1 Night f (Either a b) Source #

Inalt (Chain Night Not f) Source #

Since: 0.4.0.0

Instance details

Defined in Data.HFunctor.Chain

Methods

swerve :: (b -> a) -> (c -> a) -> (a -> Either b c) -> Chain Night Not f b -> Chain Night Not f c -> Chain Night Not f a Source #

swerved :: Chain Night Not f a -> Chain Night Not f b -> Chain Night Not f (Either a b) Source #

Inplus (Chain Night Not f) Source #

Since: 0.4.0.0

Instance details

Defined in Data.HFunctor.Chain

Methods

reject :: (a -> Void) -> Chain Night Not f a Source #

type FunctorBy Night Source # 
Instance details

Defined in Data.HBifunctor.Associative

type NonEmptyBy Night Source # 
Instance details

Defined in Data.HBifunctor.Associative

type ListBy Night Source # 
Instance details

Defined in Data.HBifunctor.Tensor

newtype Not a Source #

A value of type Not a is "proof" that a is uninhabited.

Constructors

Not 

Fields

Instances

Instances details
Contravariant Not Source # 
Instance details

Defined in Data.Functor.Contravariant.Night

Methods

contramap :: (a' -> a) -> Not a -> Not a' #

(>$) :: b -> Not b -> Not a #

Invariant Not Source #

Since: 0.3.1.0

Instance details

Defined in Data.Functor.Contravariant.Night

Methods

invmap :: (a -> b) -> (b -> a) -> Not a -> Not b #

Matchable Night Not Source #

Since: 0.3.0.0

Instance details

Defined in Data.HBifunctor.Tensor

Methods

unsplitNE :: forall (f :: Type -> Type). FunctorBy Night f => Night f (ListBy Night f) ~> NonEmptyBy Night f Source #

matchLB :: forall (f :: Type -> Type). FunctorBy Night f => ListBy Night f ~> (Not :+: NonEmptyBy Night f) Source #

Matchable Night Not Source # 
Instance details

Defined in Data.HBifunctor.Tensor

Methods

unsplitNE :: forall (f :: Type -> Type). FunctorBy Night f => Night f (ListBy Night f) ~> NonEmptyBy Night f Source #

matchLB :: forall (f :: Type -> Type). FunctorBy Night f => ListBy Night f ~> (Not :+: NonEmptyBy Night f) Source #

Tensor Night Not Source #

Since: 0.3.0.0

Instance details

Defined in Data.HBifunctor.Tensor

Associated Types

type ListBy Night :: (Type -> Type) -> Type -> Type Source #

Methods

intro1 :: forall (f :: Type -> Type). f ~> Night f Not Source #

intro2 :: forall (g :: Type -> Type). g ~> Night Not g Source #

elim1 :: forall (f :: Type -> Type). FunctorBy Night f => Night f Not ~> f Source #

elim2 :: forall (g :: Type -> Type). FunctorBy Night g => Night Not g ~> g Source #

appendLB :: forall (f :: Type -> Type). Night (ListBy Night f) (ListBy Night f) ~> ListBy Night f Source #

splitNE :: forall (f :: Type -> Type). NonEmptyBy Night f ~> Night f (ListBy Night f) Source #

splittingLB :: forall (f :: Type -> Type). ListBy Night f <~> (Not :+: Night f (ListBy Night f)) Source #

toListBy :: forall (f :: Type -> Type). Night f f ~> ListBy Night f Source #

fromNE :: forall (f :: Type -> Type). NonEmptyBy Night f ~> ListBy Night f Source #

Tensor Night Not Source # 
Instance details

Defined in Data.HBifunctor.Tensor

Associated Types

type ListBy Night :: (Type -> Type) -> Type -> Type Source #

Methods

intro1 :: forall (f :: Type -> Type). f ~> Night f Not Source #

intro2 :: forall (g :: Type -> Type). g ~> Night Not g Source #

elim1 :: forall (f :: Type -> Type). FunctorBy Night f => Night f Not ~> f Source #

elim2 :: forall (g :: Type -> Type). FunctorBy Night g => Night Not g ~> g Source #

appendLB :: forall (f :: Type -> Type). Night (ListBy Night f) (ListBy Night f) ~> ListBy Night f Source #

splitNE :: forall (f :: Type -> Type). NonEmptyBy Night f ~> Night f (ListBy Night f) Source #

splittingLB :: forall (f :: Type -> Type). ListBy Night f <~> (Not :+: Night f (ListBy Night f)) Source #

toListBy :: forall (f :: Type -> Type). Night f f ~> ListBy Night f Source #

fromNE :: forall (f :: Type -> Type). NonEmptyBy Night f ~> ListBy Night f Source #

Conclude f => MonoidIn Night Not f Source #

Instances of Conclude are monoids in the monoidal category on Night.

Instance details

Defined in Data.HBifunctor.Tensor

Methods

pureT :: Not ~> f Source #

Inplus f => MonoidIn Night Not f Source #

Since: 0.4.0.0

Instance details

Defined in Data.HBifunctor.Tensor

Methods

pureT :: Not ~> f Source #

Semigroup (Not a) Source # 
Instance details

Defined in Data.Functor.Contravariant.Night

Methods

(<>) :: Not a -> Not a -> Not a #

sconcat :: NonEmpty (Not a) -> Not a #

stimes :: Integral b => b -> Not a -> Not a #

Conclude (Chain Night Not f) Source #

Chain Night Refutec is the free "monoid in the monoidal category of endofunctors enriched by Night" --- aka, the free Conclude.

Since: 0.3.0.0

Instance details

Defined in Data.HFunctor.Chain

Methods

conclude :: (a -> Void) -> Chain Night Not f a Source #

Decide (Chain Night Not f) Source #

Since: 0.3.0.0

Instance details

Defined in Data.HFunctor.Chain

Methods

decide :: (a -> Either b c) -> Chain Night Not f b -> Chain Night Not f c -> Chain Night Not f a Source #

Inalt (Chain Night Not f) Source #

Since: 0.4.0.0

Instance details

Defined in Data.HFunctor.Chain

Methods

swerve :: (b -> a) -> (c -> a) -> (a -> Either b c) -> Chain Night Not f b -> Chain Night Not f c -> Chain Night Not f a Source #

swerved :: Chain Night Not f a -> Chain Night Not f b -> Chain Night Not f (Either a b) Source #

Inplus (Chain Night Not f) Source #

Since: 0.4.0.0

Instance details

Defined in Data.HFunctor.Chain

Methods

reject :: (a -> Void) -> Chain Night Not f a Source #

refuted :: Not Void Source #

A useful shortcut for a common usage: Void is always not so.

Since: 0.3.1.0

night :: f a -> g b -> Night f g (Either a b) Source #

Pair two invariant actions together into a Night; assigns the first one to Left inputs and outputs and the second one to Right inputs and outputs.

runNight :: Inalt h => (f ~> h) -> (g ~> h) -> Night f g ~> h Source #

Interpret out of a Night into any instance of Inalt by providing two interpreting functions.

Since: 0.4.0.0

nerve :: Inalt f => Night f f ~> f Source #

Squash the two items in a Night using their natural Inalt instances.

Since: 0.4.0.0

runNightAlt :: forall f g h. Alt h => (f ~> h) -> (g ~> h) -> Night f g ~> h Source #

Interpret the covariant part of a Night into a target context h, as long as the context is an instance of Alt. The Alt is used to combine results back together, chosen by <!>.

runNightDecide :: forall f g h. Decide h => (f ~> h) -> (g ~> h) -> Night f g ~> h Source #

Interpret the contravariant part of a Night into a target context h, as long as the context is an instance of Decide. The Decide is used to pick which part to feed the input to.

toCoNight :: (Functor f, Functor g) => Night f g ~> (f :*: g) Source #

Convert an invariant Night into the covariant version, dropping the contravariant part.

Note that there is no covariant version of Night defined in any common library, so we use an equivalent type (if f and g are Functors) f :*: g.

toCoNight_ :: Night f g ~> (Coyoneda f :*: Coyoneda g) Source #

Convert an invariant Night into the covariant version, dropping the contravariant part.

This version does not require a Functor constraint because it converts to the coyoneda-wrapped product, which is more accurately the covariant Night convolution.

Since: 0.3.2.0

toContraNight :: Night f g ~> Night f g Source #

Convert an invariant Night into the contravariant version, dropping the covariant part.

assoc :: Night f (Night g h) ~> Night (Night f g) h Source #

Night is associative.

unassoc :: Night (Night f g) h ~> Night f (Night g h) Source #

Night is associative.

intro1 :: g ~> Night Not g Source #

The left identity of Night is Not; this is one side of that isomorphism.

intro2 :: f ~> Night f Not Source #

The right identity of Night is Not; this is one side of that isomorphism.

elim1 :: Invariant g => Night Not g ~> g Source #

The left identity of Night is Not; this is one side of that isomorphism.

elim2 :: Invariant f => Night f Not ~> f Source #

The right identity of Night is Not; this is one side of that isomorphism.

swapped :: Night f g ~> Night g f Source #

The two sides of a Night can be swapped.

trans1 :: (f ~> h) -> Night f g ~> Night h g Source #

Hoist a function over the left side of a Night.

trans2 :: (g ~> h) -> Night f g ~> Night f h Source #

Hoist a function over the right side of a Night.