Copyright | (c) Justin Le 2025 |
---|---|
License | BSD3 |
Maintainer | [email protected] |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
Data.Functor.Invariant.Night
Synopsis
- data Night (a :: Type -> Type) (b :: Type -> Type) c where
- newtype Not a = Not {}
- refuted :: Not Void
- night :: f a -> g b -> Night f g (Either a b)
- runNight :: forall (h :: Type -> Type) (f :: Type -> Type) (g :: Type -> Type). Inalt h => (f ~> h) -> (g ~> h) -> Night f g ~> h
- nerve :: forall (f :: Type -> Type). Inalt f => Night f f ~> f
- runNightAlt :: forall (f :: Type -> Type) (g :: Type -> Type) (h :: Type -> Type). Alt h => (f ~> h) -> (g ~> h) -> Night f g ~> h
- runNightDecide :: forall (f :: Type -> Type) (g :: Type -> Type) (h :: Type -> Type). Decide h => (f ~> h) -> (g ~> h) -> Night f g ~> h
- toCoNight :: forall (f :: Type -> Type) (g :: Type -> Type). (Functor f, Functor g) => Night f g ~> (f :*: g)
- toCoNight_ :: forall (f :: Type -> Type) (g :: Type -> Type) x. Night f g x -> (Coyoneda f :*: Coyoneda g) x
- toContraNight :: forall (f :: Type -> Type) (g :: Type -> Type) x. Night f g x -> Night f g x
- assoc :: forall (f :: Type -> Type) (g :: Type -> Type) (h :: Type -> Type) x. Night f (Night g h) x -> Night (Night f g) h x
- unassoc :: forall (f :: Type -> Type) (g :: Type -> Type) (h :: Type -> Type) x. Night (Night f g) h x -> Night f (Night g h) x
- intro1 :: g x -> Night Not g x
- intro2 :: f x -> Night f Not x
- elim1 :: forall (g :: Type -> Type). Invariant g => Night Not g ~> g
- elim2 :: forall (f :: Type -> Type). Invariant f => Night f Not ~> f
- swapped :: forall (f :: Type -> Type) (g :: Type -> Type) x. Night f g x -> Night g f x
- trans1 :: forall (f :: Type -> Type) (h :: Type -> Type) (g :: Type -> Type). (f ~> h) -> Night f g ~> Night h g
- trans2 :: forall (g :: Type -> Type) (h :: Type -> Type) (f :: Type -> Type). (g ~> h) -> Night f g ~> Night f h
Documentation
data Night (a :: Type -> Type) (b :: Type -> Type) c where Source #
A pairing of invariant functors to create a new invariant functor that represents the "choice" between the two.
A
is a invariant "consumer" and "producer" of Night
f g aa
, 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
. This is a consumer/producer of night
x y ::
Night
f g (Either
a b)
s, and
it consumes Either
a bLeft
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 :: forall (a :: Type -> Type) b1 (b :: Type -> Type) c1 c. a b1 -> b c1 -> (b1 -> c) -> (c1 -> c) -> (c -> Either b1 c1) -> Night a b c |
Instances
A value of type
is "proof" that Not
aa
is uninhabited.
Instances
Contravariant Not Source # | |
Invariant Not Source # | Since: 0.3.1.0 |
Defined in Data.Functor.Contravariant.Night | |
Matchable Night Not Source # | Since: 0.3.0.0 |
Matchable Night Not Source # | |
Tensor Night Not Source # | Since: 0.3.0.0 |
Defined in Data.HBifunctor.Tensor 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 # | |
Defined in Data.HBifunctor.Tensor 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 |
Inplus f => MonoidIn Night Not f Source # | Since: 0.4.0.0 |
Semigroup (Not a) Source # | |
Conclude (Chain Night Not f) Source # |
Since: 0.3.0.0 |
Decide (Chain Night Not f) Source # | Since: 0.3.0.0 |
Inalt (Chain Night Not f) Source # | Since: 0.4.0.0 |
Inplus (Chain Night Not f) Source # | Since: 0.4.0.0 |
A useful shortcut for a common usage: Void
is always not so.
Since: 0.3.1.0
runNight :: forall (h :: Type -> Type) (f :: Type -> Type) (g :: Type -> Type). Inalt h => (f ~> h) -> (g ~> h) -> Night f g ~> h Source #
runNightAlt :: forall (f :: Type -> Type) (g :: Type -> Type) (h :: Type -> Type). Alt h => (f ~> h) -> (g ~> h) -> Night f g ~> h Source #
runNightDecide :: forall (f :: Type -> Type) (g :: Type -> Type) (h :: Type -> Type). Decide h => (f ~> h) -> (g ~> h) -> Night f g ~> h Source #
toCoNight :: forall (f :: Type -> Type) (g :: Type -> Type). (Functor f, Functor g) => Night f g ~> (f :*: g) Source #
toCoNight_ :: forall (f :: Type -> Type) (g :: Type -> Type) x. Night f g x -> (Coyoneda f :*: Coyoneda g) x Source #
toContraNight :: forall (f :: Type -> Type) (g :: Type -> Type) x. Night f g x -> Night f g x Source #
Convert an invariant Night
into the contravariant version, dropping
the covariant part.
assoc :: forall (f :: Type -> Type) (g :: Type -> Type) (h :: Type -> Type) x. Night f (Night g h) x -> Night (Night f g) h x Source #
Night
is associative.
unassoc :: forall (f :: Type -> Type) (g :: Type -> Type) (h :: Type -> Type) x. Night (Night f g) h x -> Night f (Night g h) x Source #
Night
is associative.
swapped :: forall (f :: Type -> Type) (g :: Type -> Type) x. Night f g x -> Night g f x Source #
The two sides of a Night
can be swapped.