Copyright | (c) Justin Le 2019 |
---|---|
License | BSD3 |
Maintainer | justin@jle.im |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
This module provides an abstraction for "two-argument functor
combinators", HBifunctor
, as well as some useful combinators.
Synopsis
- class HBifunctor t where
- newtype WrappedHBifunctor t (f :: k -> Type) (g :: k -> Type) a = WrapHBifunctor {
- unwrapHBifunctor :: t f g a
- overHBifunctor :: HBifunctor t => (f <~> f') -> (g <~> g') -> t f g <~> t f' g'
- newtype LeftF f g a = LeftF {
- runLeftF :: f a
- newtype RightF f g a = RightF {
- runRightF :: g a
Documentation
class HBifunctor t where Source #
A HBifunctor
is like an HFunctor
, but it enhances two different
functors instead of just one.
Usually, it enhaces them "together" in some sort of combining way.
This typeclass provides a uniform instance for "swapping out" or
"hoisting" the enhanced functors. We can hoist the first one with
hleft
, the second one with hright
, or both at the same time with
hbimap
.
For example, the f :*: g
type gives us "both f
and g
":
data (f :*:
g) a = f a :*: g a
It combines both f
and g
into a unified structure --- here, it does
it by providing both f
and g
.
The single law is:
hbimap
id
id == id
This ensures that hleft
, hright
, and hbimap
do not affect the
structure that t
adds on top of the underlying functors.
hleft :: (f ~> j) -> t f g ~> t j g Source #
Swap out the first transformed functor.
hright :: (g ~> k) -> t f g ~> t f k Source #
Swap out the second transformed functor.
hbimap :: (f ~> j) -> (g ~> k) -> t f g ~> t j k Source #
Swap out both transformed functors at the same time.
Instances
HBifunctor (Sum :: (k -> Type) -> (k -> Type) -> k -> Type) Source # | |
HBifunctor ((:+:) :: (k -> Type) -> (k -> Type) -> k -> Type) Source # | |
HBifunctor (Product :: (k -> Type) -> (k -> Type) -> k -> Type) Source # | |
HBifunctor ((:*:) :: (k -> Type) -> (k -> Type) -> k -> Type) Source # | |
HBifunctor (Joker :: (k2 -> Type) -> (k1 -> Type) -> k2 -> Type) Source # | |
HBifunctor (LeftF :: (k2 -> Type) -> (k1 -> Type) -> k2 -> Type) Source # | |
HBifunctor (RightF :: (k1 -> Type) -> (k2 -> Type) -> k2 -> Type) Source # | |
HBifunctor (Void3 :: (k1 -> Type) -> (k2 -> Type) -> k3 -> Type) Source # | |
HBifunctor Day Source # | |
HBifunctor These1 Source # | |
HBifunctor Comp Source # | |
newtype WrappedHBifunctor t (f :: k -> Type) (g :: k -> Type) a Source #
Useful newtype to allow us to derive an HFunctor
instance from any
instance of HBifunctor
, using -XDerivingVia.
For example, because we have instance
, we can
write:HBifunctor
Day
deriving via (WrappedHBifunctor
Day
f) instanceHFunctor
(Day
f)
to give us an automatic HFunctor
instance and save us some work.
WrapHBifunctor | |
|
Instances
HBifunctor t => HFunctor (WrappedHBifunctor t f :: (k1 -> Type) -> k2 -> Type) Source # | |
Defined in Data.HFunctor.Internal hmap :: (f0 ~> g) -> WrappedHBifunctor t f f0 ~> WrappedHBifunctor t f g Source # | |
Functor (t f g) => Functor (WrappedHBifunctor t f g) Source # | |
Defined in Data.HFunctor.Internal fmap :: (a -> b) -> WrappedHBifunctor t f g a -> WrappedHBifunctor t f g b # (<$) :: a -> WrappedHBifunctor t f g b -> WrappedHBifunctor t f g a # |
overHBifunctor :: HBifunctor t => (f <~> f') -> (g <~> g') -> t f g <~> t f' g' Source #
Lift two isomorphisms on each side of a bifunctor to become an isomorphism between the two bifunctor applications.
Basically, if f
and f'
are isomorphic, and g
and g'
are
isomorphic, then t f g
is isomorphic to t f' g'
.
Simple Instances
An HBifunctor
that ignores its second input. Like
a :+:
with no R1
/right branch.
This is Joker
from Data.Bifunctors.Joker, but
given a more sensible name for its purpose.
Instances
HBifunctor (LeftF :: (k2 -> Type) -> (k1 -> Type) -> k2 -> Type) Source # | |
HFunctor (LeftF f :: (k -> Type) -> k -> Type) Source # | |
Semigroupoidal (LeftF :: (Type -> Type) -> (Type -> Type) -> Type -> Type) Source # | |
Defined in Data.HBifunctor.Associative appendSF :: LeftF (SF LeftF f) (SF LeftF f) ~> SF LeftF f Source # matchSF :: Functor f => SF LeftF f ~> (f :+: LeftF f (SF LeftF f)) Source # consSF :: LeftF f (SF LeftF f) ~> SF LeftF f Source # toSF :: LeftF f f ~> SF LeftF f Source # biretract :: CS LeftF f => LeftF f f ~> f Source # binterpret :: CS LeftF h => (f ~> h) -> (g ~> h) -> LeftF f g ~> h Source # | |
Associative (LeftF :: (Type -> Type) -> (Type -> Type) -> Type -> Type) Source # | |
Functor f => Bifunctor (LeftF f :: Type -> Type -> Type) Source # | |
Traversable f => Bitraversable (LeftF f :: Type -> Type -> Type) Source # | |
Defined in Data.HBifunctor bitraverse :: Applicative f0 => (a -> f0 c) -> (b -> f0 d) -> LeftF f a b -> f0 (LeftF f c d) # | |
Foldable f => Bifoldable (LeftF f :: Type -> Type -> Type) Source # | |
Applicative f => Biapplicative (LeftF f :: Type -> Type -> Type) Source # | |
Defined in Data.HBifunctor | |
Functor f => Functor (LeftF f g) Source # | |
Foldable f => Foldable (LeftF f g) Source # | |
Defined in Data.HBifunctor fold :: Monoid m => LeftF f g m -> m # foldMap :: Monoid m => (a -> m) -> LeftF f g a -> m # foldr :: (a -> b -> b) -> b -> LeftF f g a -> b # foldr' :: (a -> b -> b) -> b -> LeftF f g a -> b # foldl :: (b -> a -> b) -> b -> LeftF f g a -> b # foldl' :: (b -> a -> b) -> b -> LeftF f g a -> b # foldr1 :: (a -> a -> a) -> LeftF f g a -> a # foldl1 :: (a -> a -> a) -> LeftF f g a -> a # toList :: LeftF f g a -> [a] # length :: LeftF f g a -> Int # elem :: Eq a => a -> LeftF f g a -> Bool # maximum :: Ord a => LeftF f g a -> a # minimum :: Ord a => LeftF f g a -> a # | |
Traversable f => Traversable (LeftF f g) Source # | |
Eq1 f => Eq1 (LeftF f g) Source # | |
Ord1 f => Ord1 (LeftF f g) Source # | |
Defined in Data.HBifunctor | |
Read1 f => Read1 (LeftF f g) Source # | |
Defined in Data.HBifunctor | |
Show1 f => Show1 (LeftF f g) Source # | |
Eq (f a) => Eq (LeftF f g a) Source # | |
(Typeable g, Typeable a, Typeable f, Typeable k2, Typeable k1, Data (f a)) => Data (LeftF f g a) Source # | |
Defined in Data.HBifunctor gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g0. g0 -> c g0) -> LeftF f g a -> c (LeftF f g a) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (LeftF f g a) # toConstr :: LeftF f g a -> Constr # dataTypeOf :: LeftF f g a -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (LeftF f g a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (LeftF f g a)) # gmapT :: (forall b. Data b => b -> b) -> LeftF f g a -> LeftF f g a # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> LeftF f g a -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> LeftF f g a -> r # gmapQ :: (forall d. Data d => d -> u) -> LeftF f g a -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> LeftF f g a -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> LeftF f g a -> m (LeftF f g a) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> LeftF f g a -> m (LeftF f g a) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> LeftF f g a -> m (LeftF f g a) # | |
Ord (f a) => Ord (LeftF f g a) Source # | |
Defined in Data.HBifunctor | |
Read (f a) => Read (LeftF f g a) Source # | |
Show (f a) => Show (LeftF f g a) Source # | |
Generic (LeftF f g a) Source # | |
type SF (LeftF :: (Type -> Type) -> (Type -> Type) -> Type -> Type) Source # | |
type Rep (LeftF f g a) Source # | |
Defined in Data.HBifunctor |
An HBifunctor
that ignores its first input. Like
a :+:
with no L1
/left branch.
In its polykinded form (on f
), it is essentially a higher-order
version of Tagged
.
Instances
HBifunctor (RightF :: (k1 -> Type) -> (k2 -> Type) -> k2 -> Type) Source # | |
HFunctor (RightF f :: (k1 -> Type) -> k1 -> Type) Source # | |
HFunctor (RightF f :: (k -> Type) -> k -> Type) Source # | |
HBind (RightF f :: (k1 -> Type) -> k1 -> Type) Source # | |
Inject (RightF f :: (k1 -> Type) -> k1 -> Type) Source # | |
Semigroupoidal (RightF :: (Type -> Type) -> (Type -> Type) -> Type -> Type) Source # | |
Defined in Data.HBifunctor.Associative appendSF :: RightF (SF RightF f) (SF RightF f) ~> SF RightF f Source # matchSF :: Functor f => SF RightF f ~> (f :+: RightF f (SF RightF f)) Source # consSF :: RightF f (SF RightF f) ~> SF RightF f Source # toSF :: RightF f f ~> SF RightF f Source # biretract :: CS RightF f => RightF f f ~> f Source # binterpret :: CS RightF h => (f ~> h) -> (g ~> h) -> RightF f g ~> h Source # | |
Associative (RightF :: (Type -> Type) -> (Type -> Type) -> Type -> Type) Source # | |
Interpret (RightF f :: (Type -> Type) -> Type -> Type) Source # | |
Functor g => Functor (RightF f g) Source # | |
Foldable g => Foldable (RightF f g) Source # | |
Defined in Data.HBifunctor fold :: Monoid m => RightF f g m -> m # foldMap :: Monoid m => (a -> m) -> RightF f g a -> m # foldr :: (a -> b -> b) -> b -> RightF f g a -> b # foldr' :: (a -> b -> b) -> b -> RightF f g a -> b # foldl :: (b -> a -> b) -> b -> RightF f g a -> b # foldl' :: (b -> a -> b) -> b -> RightF f g a -> b # foldr1 :: (a -> a -> a) -> RightF f g a -> a # foldl1 :: (a -> a -> a) -> RightF f g a -> a # toList :: RightF f g a -> [a] # null :: RightF f g a -> Bool # length :: RightF f g a -> Int # elem :: Eq a => a -> RightF f g a -> Bool # maximum :: Ord a => RightF f g a -> a # minimum :: Ord a => RightF f g a -> a # | |
Traversable g => Traversable (RightF f g) Source # | |
Defined in Data.HBifunctor | |
Eq1 g => Eq1 (RightF f g) Source # | |
Ord1 g => Ord1 (RightF f g) Source # | |
Defined in Data.HBifunctor | |
Read1 g => Read1 (RightF f g) Source # | |
Defined in Data.HBifunctor | |
Show1 g => Show1 (RightF f g) Source # | |
Eq (g a) => Eq (RightF f g a) Source # | |
(Typeable f, Typeable a, Typeable g, Typeable k1, Typeable k2, Data (g a)) => Data (RightF f g a) Source # | |
Defined in Data.HBifunctor gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g0. g0 -> c g0) -> RightF f g a -> c (RightF f g a) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (RightF f g a) # toConstr :: RightF f g a -> Constr # dataTypeOf :: RightF f g a -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (RightF f g a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (RightF f g a)) # gmapT :: (forall b. Data b => b -> b) -> RightF f g a -> RightF f g a # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> RightF f g a -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> RightF f g a -> r # gmapQ :: (forall d. Data d => d -> u) -> RightF f g a -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> RightF f g a -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> RightF f g a -> m (RightF f g a) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> RightF f g a -> m (RightF f g a) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> RightF f g a -> m (RightF f g a) # | |
Ord (g a) => Ord (RightF f g a) Source # | |
Defined in Data.HBifunctor | |
Read (g a) => Read (RightF f g a) Source # | |
Show (g a) => Show (RightF f g a) Source # | |
Generic (RightF f g a) Source # | |
type SF (RightF :: (Type -> Type) -> (Type -> Type) -> Type -> Type) Source # | |
type C (RightF f :: (Type -> Type) -> Type -> Type) Source # | |
Defined in Data.HBifunctor type C (RightF f :: (Type -> Type) -> Type -> Type) = (Unconstrained :: (Type -> Type) -> Constraint) | |
type Rep (RightF f g a) Source # | |
Defined in Data.HBifunctor |