Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Implements higher-ranked equivalents of Functor
, Monad
, Foldable
and
Traversable
.
Synopsis
- class HFunctor (h :: (u -> *) -> u -> *) where
- hmap :: (forall b. t b -> t' b) -> h t a -> h t' a
- class HPointed h where
- hpure :: t a -> h t a
- class HBind h where
- (^>>=) :: h t a -> (forall b. t b -> h t' b) -> h t' a
- class (HFunctor h, HPointed h, HBind h) => HMonad h
- hliftM :: (HPointed h, HBind h) => (forall b. t b -> t' b) -> h t a -> h t' a
- hjoin :: HBind h => h (h t) a -> h t a
- class HFunctor h => HTraversable h where
- htraverse :: Applicative f => (forall b. t b -> f (t' b)) -> h t a -> f (h t' a)
- hsequence :: Applicative f => h (Compose f t) a -> f (h t a)
- hfoldMapMonoid :: (HTraversable h, Monoid m) => (forall b. t b -> m) -> h t a -> m
- hbindTraverse :: (HTraversable h, HMonad h, Applicative f) => (forall b. t b -> f (h t' b)) -> h t a -> f (h t' a)
- class HBifunctor (h :: (k -> *) -> (k -> *) -> k -> *) where
- class HBifunctor h => HBitraversable h where
- hbitraverse :: Applicative f => (forall b. s b -> f (s' b)) -> (forall b. t b -> f (t' b)) -> h s t a -> f (h s' t' a)
- hbifoldMapMonoid :: (Monoid m, HBitraversable h) => (forall b. s b -> m) -> (forall b. t b -> m) -> h s t a -> m
- class HDuofunctor (h :: ((u -> *) -> u -> *) -> (u -> *) -> u -> *) where
- hduomap :: (forall g g' b. (forall c. g c -> g' c) -> s g b -> s' g' b) -> (forall b. t b -> t' b) -> h s t a -> h s' t' a
- hduomapFirst :: HDuofunctor h => (forall g g' b. (forall c. g c -> g' c) -> s g b -> s' g' b) -> h s t a -> h s' t a
- hduomapFirst' :: (HDuofunctor h, HFunctor s) => (forall g b. s g b -> s' g b) -> h s t a -> h s' t a
- hduomapSecond :: (HDuofunctor h, HFunctor s) => (forall b. t b -> t' b) -> h s t a -> h s t' a
- class HDuofunctor h => HDuotraversable h where
- hduotraverse :: Applicative f => (forall g g' b. (forall c. g c -> f (g' c)) -> s g b -> f (s' g' b)) -> (forall b. t b -> f (t' b)) -> h s t a -> f (h s' t' a)
- hduotraverseFirst :: (HDuotraversable h, Applicative f) => (forall g g' b. (forall c. g c -> f (g' c)) -> s g b -> f (s' g' b)) -> h s t a -> f (h s' t a)
- hduotraverseFirst' :: (HDuotraversable h, HTraversable s, Monad f) => (forall g b. s g b -> f (s' g b)) -> h s t a -> f (h s' t a)
- hduotraverseSecond :: (HDuotraversable h, HTraversable s, Applicative f) => (forall b. t b -> f (t' b)) -> h s t a -> f (h s t' a)
- class HFoldableAt k h where
- hfoldMap :: (forall b. t b -> k b) -> h t a -> k a
- implHfoldMap :: HFunctor h => (h k a -> k a) -> (forall b. t b -> k b) -> h t a -> k a
- implHfoldMapCompose :: (HTraversable h, Monad m) => (h k a -> m (k a)) -> (forall b. t b -> Compose m k b) -> h t a -> Compose m k a
- hfold :: HFoldableAt t h => h t a -> t a
- hfoldA :: (HFoldableAt (Compose f t) h, Applicative f) => h t a -> f (t a)
- hfoldMapA :: (HFoldableAt (Compose f k) h, Applicative f) => (forall b. t b -> f (k b)) -> h t a -> f (k a)
- hfoldTraverse :: (HFoldableAt k h, HTraversable h, Applicative f) => (forall b. t b -> f (k b)) -> h t a -> f (k a)
- class HBifoldableAt k h where
- hbifoldMap :: (forall b. f b -> k b) -> (forall b. g b -> k b) -> h f g a -> k a
- hbifold :: HBifoldableAt k h => h k k a -> k a
- class HDuofoldableAt k h where
- hduofoldMap :: HTraversable s => (forall g b. (forall c. g c -> k c) -> s g b -> k b) -> (forall b. t b -> k b) -> h s t a -> k a
- implHduofoldMap :: (HDuofunctor h, HFunctor s) => ((forall g b. (forall c. g c -> k c) -> s g b -> k b) -> h s k a -> k a) -> (forall g b. (forall c. g c -> k c) -> s g b -> k b) -> (forall b. t b -> k b) -> h s t a -> k a
- implHduofoldMapCompose :: (HDuotraversable h, HTraversable s, Monad m) => ((forall g b. (forall c. g c -> m (k c)) -> s g b -> m (k b)) -> h s k a -> m (k a)) -> (forall g b. (forall c. g c -> Compose m k c) -> s g b -> Compose m k b) -> (forall b. t b -> Compose m k b) -> h s t a -> Compose m k a
- data HFree h t a
Documentation
class HFunctor (h :: (u -> *) -> u -> *) where Source #
Higher-ranked analogue of Functor
.
Nothing
hmap :: (forall b. t b -> t' b) -> h t a -> h t' a Source #
Higher-ranked analogue of fmap
. Has a default implementation in terms of
htraverse
for
.HTraversable
h
hmap :: HTraversable h => (forall b. t b -> t' b) -> h t a -> h t' a Source #
Higher-ranked analogue of fmap
. Has a default implementation in terms of
htraverse
for
.HTraversable
h
Instances
class HPointed h where Source #
Half of the higher-ranked analogue of Monad
.
Instances
HPointed (Reverse :: (k -> Type) -> k -> Type) Source # | |
Defined in Language.Expression | |
HPointed (ReaderT r :: (k -> Type) -> k -> Type) Source # | |
Defined in Language.Expression | |
HPointed (Sum f :: (k -> Type) -> k -> Type) Source # | |
Defined in Language.Expression | |
HPointed (HFree h :: (k -> Type) -> k -> Type) Source # | |
Defined in Language.Expression | |
HPointed (BV g :: (k -> Type) -> k -> Type) Source # | |
Defined in Language.Expression.Scope | |
HPointed (SFree h :: (k -> Type) -> k -> Type) Source # | |
Defined in Language.Expression.Scope | |
Applicative f => HPointed (Compose f :: (k -> Type) -> k -> Type) Source # | |
Defined in Language.Expression | |
HPointed h => HPointed (Scope g h :: (k -> Type) -> k -> Type) Source # | |
Defined in Language.Expression.Scope | |
HPointed (HFree' ops :: (Type -> Type) -> Type -> Type) Source # | |
Defined in Language.Expression.Choice |
Half of the higher-ranked analogue of Monad
.
(^>>=) :: h t a -> (forall b. t b -> h t' b) -> h t' a infixr 1 Source #
Higher-ranked analogue of >>=
.
Instances
HBind (Reverse :: (k -> Type) -> k -> Type) Source # | |
HBind (ReaderT r :: (k -> Type) -> k -> Type) Source # | |
HBind (Sum f :: (k -> Type) -> k -> Type) Source # | |
HFunctor h => HBind (HFree h :: (k -> Type) -> k -> Type) Source # | |
HBind (BV g :: (k -> Type) -> k -> Type) Source # | |
HDuofunctor h => HBind (SFree h :: (k -> Type) -> k -> Type) Source # | |
Monad f => HBind (Compose f :: (k -> Type) -> k -> Type) Source # | |
HFunctor (OpChoice ops) => HBind (HFree' ops :: (Type -> Type) -> Type -> Type) Source # | |
class (HFunctor h, HPointed h, HBind h) => HMonad h Source #
Higher-ranked analogue of Monad
.
NB there's no such thing as HApplicative
for a reason. Consider f :: h t a ->
h t' a -> h (
, i.e. the higher-ranked analogue of Product
t t') aliftA2 (,)
:: f a -> f b -> f (a, b)
. Unfortunately f
can't exist, because
pairs up values of the same type, and in our constructions, Product
h
potentially
contains values of many types; a
just happens to be the one at the top level.
There's no guarantee that the two structures will have the same types inside to
pair together.
Instances
HMonad (Reverse :: (k -> Type) -> k -> Type) Source # | |
Defined in Language.Expression | |
HMonad (ReaderT r :: (k -> Type) -> k -> Type) Source # | |
Defined in Language.Expression | |
HMonad (Sum f :: (k -> Type) -> k -> Type) Source # | |
Defined in Language.Expression | |
HFunctor h => HMonad (HFree h :: (k -> Type) -> k -> Type) Source # | |
Defined in Language.Expression | |
HMonad (BV g :: (k -> Type) -> k -> Type) Source # | |
Defined in Language.Expression.Scope | |
HDuofunctor h => HMonad (SFree h :: (k -> Type) -> k -> Type) Source # | |
Defined in Language.Expression.Scope | |
HFunctor (OpChoice ops) => HMonad (HFree' ops :: (Type -> Type) -> Type -> Type) Source # | |
Defined in Language.Expression.Choice |
class HFunctor h => HTraversable h where Source #
Higher-ranked analogue of Traversable
.
htraverse :: Applicative f => (forall b. t b -> f (t' b)) -> h t a -> f (h t' a) Source #
Higher-ranked analogue of traverse
.
hsequence :: Applicative f => h (Compose f t) a -> f (h t a) Source #
Higher-ranked analogue of sequenceA
.
Instances
hfoldMapMonoid :: (HTraversable h, Monoid m) => (forall b. t b -> m) -> h t a -> m Source #
An HTraversable
instance lets you do something similar to foldMap
. For
a more flexible operation, see hfoldMap
.
hbindTraverse :: (HTraversable h, HMonad h, Applicative f) => (forall b. t b -> f (h t' b)) -> h t a -> f (h t' a) Source #
class HBifunctor (h :: (k -> *) -> (k -> *) -> k -> *) where Source #
Higher-ranked analogue of Bifunctor
.
Nothing
hbimap :: (forall b. s b -> s' b) -> (forall b. t b -> t' b) -> h s t a -> h s' t' a Source #
Higher-ranked analogue of bimap
.
hfirst :: (forall b. s b -> s' b) -> h s t a -> h s' t a Source #
hsecond :: (forall b. t b -> t' b) -> h s t a -> h s t' a Source #
hbimap :: HBitraversable h => (forall b. s b -> s' b) -> (forall b. t b -> t' b) -> h s t a -> h s' t' a Source #
Higher-ranked analogue of bimap
.
Instances
HBifunctor (Sum :: (k -> Type) -> (k -> Type) -> k -> Type) Source # | |
HBifunctor (Product :: (k -> Type) -> (k -> Type) -> k -> Type) Source # | |
Defined in Language.Expression | |
HBifunctor (BV :: (k -> Type) -> (k -> Type) -> k -> Type) Source # | |
HFunctor h => HBifunctor (Scoped h :: (k -> Type) -> (k -> Type) -> k -> Type) Source # | |
Defined in Language.Expression.Scope |
class HBifunctor h => HBitraversable h where Source #
hbitraverse :: Applicative f => (forall b. s b -> f (s' b)) -> (forall b. t b -> f (t' b)) -> h s t a -> f (h s' t' a) Source #
Instances
HBitraversable (Sum :: (k -> Type) -> (k -> Type) -> k -> Type) Source # | |
Defined in Language.Expression hbitraverse :: Applicative f => (forall (b :: k0). s b -> f (s' b)) -> (forall (b :: k0). t b -> f (t' b)) -> Sum s t a -> f (Sum s' t' a) Source # | |
HBitraversable (Product :: (k -> Type) -> (k -> Type) -> k -> Type) Source # | |
Defined in Language.Expression hbitraverse :: Applicative f => (forall (b :: k0). s b -> f (s' b)) -> (forall (b :: k0). t b -> f (t' b)) -> Product s t a -> f (Product s' t' a) Source # | |
HBitraversable (BV :: (k -> Type) -> (k -> Type) -> k -> Type) Source # | |
Defined in Language.Expression.Scope hbitraverse :: Applicative f => (forall (b :: k0). s b -> f (s' b)) -> (forall (b :: k0). t b -> f (t' b)) -> BV s t a -> f (BV s' t' a) Source # | |
HTraversable h => HBitraversable (Scoped h :: (k -> Type) -> (k -> Type) -> k -> Type) Source # | |
Defined in Language.Expression.Scope hbitraverse :: Applicative f => (forall (b :: k0). s b -> f (s' b)) -> (forall (b :: k0). t b -> f (t' b)) -> Scoped h s t a -> f (Scoped h s' t' a) Source # |
hbifoldMapMonoid :: (Monoid m, HBitraversable h) => (forall b. s b -> m) -> (forall b. t b -> m) -> h s t a -> m Source #
class HDuofunctor (h :: ((u -> *) -> u -> *) -> (u -> *) -> u -> *) where Source #
Nothing
hduomap :: (forall g g' b. (forall c. g c -> g' c) -> s g b -> s' g' b) -> (forall b. t b -> t' b) -> h s t a -> h s' t' a Source #
hduomap :: HDuotraversable h => (forall g g' b. (forall c. g c -> g' c) -> s g b -> s' g' b) -> (forall b. t b -> t' b) -> h s t a -> h s' t' a Source #
hduomapFirst :: HDuofunctor h => (forall g g' b. (forall c. g c -> g' c) -> s g b -> s' g' b) -> h s t a -> h s' t a Source #
hduomapFirst' :: (HDuofunctor h, HFunctor s) => (forall g b. s g b -> s' g b) -> h s t a -> h s' t a Source #
hduomapSecond :: (HDuofunctor h, HFunctor s) => (forall b. t b -> t' b) -> h s t a -> h s t' a Source #
class HDuofunctor h => HDuotraversable h where Source #
hduotraverse :: Applicative f => (forall g g' b. (forall c. g c -> f (g' c)) -> s g b -> f (s' g' b)) -> (forall b. t b -> f (t' b)) -> h s t a -> f (h s' t' a) Source #
Instances
HDuotraversable (HFree :: ((u -> Type) -> u -> Type) -> (u -> Type) -> u -> Type) Source # | |
Defined in Language.Expression hduotraverse :: Applicative f => (forall (g :: u0 -> Type) (g' :: u0 -> Type) (b :: u0). (forall (c :: u0). g c -> f (g' c)) -> s g b -> f (s' g' b)) -> (forall (b :: u0). t b -> f (t' b)) -> HFree s t a -> f (HFree s' t' a) Source # | |
HDuotraversable (Scope g :: ((u -> Type) -> u -> Type) -> (u -> Type) -> u -> Type) Source # | |
Defined in Language.Expression.Scope hduotraverse :: Applicative f => (forall (g0 :: u0 -> Type) (g' :: u0 -> Type) (b :: u0). (forall (c :: u0). g0 c -> f (g' c)) -> s g0 b -> f (s' g' b)) -> (forall (b :: u0). t b -> f (t' b)) -> Scope g s t a -> f (Scope g s' t' a) Source # |
hduotraverseFirst :: (HDuotraversable h, Applicative f) => (forall g g' b. (forall c. g c -> f (g' c)) -> s g b -> f (s' g' b)) -> h s t a -> f (h s' t a) Source #
hduotraverseFirst' :: (HDuotraversable h, HTraversable s, Monad f) => (forall g b. s g b -> f (s' g b)) -> h s t a -> f (h s' t a) Source #
hduotraverseSecond :: (HDuotraversable h, HTraversable s, Applicative f) => (forall b. t b -> f (t' b)) -> h s t a -> f (h s t' a) Source #
class HFoldableAt k h where Source #
This is a more flexible, higher-ranked version of Foldable
. While Foldable
only allows you to fold into a Monoid
, HFoldable
allows you to fold into
some arbitrary type constructor k
. This means that the instance can take
advantage of additional structure inside k
and h
, to combine internal
results in different ways, rather than just the mappend
available to
foldMap
.
Notice that if you have
instance (Monoid
m) =>HFoldableAt
(Const
m) h
Instances
implHfoldMap :: HFunctor h => (h k a -> k a) -> (forall b. t b -> k b) -> h t a -> k a Source #
implHfoldMapCompose :: (HTraversable h, Monad m) => (h k a -> m (k a)) -> (forall b. t b -> Compose m k b) -> h t a -> Compose m k a Source #
A helper function for implementing instances with the general form
. I.e. folding that requires a monadic
context of some kind.Monad
m => HFoldableAt
(Compose
m t) h
hfold :: HFoldableAt t h => h t a -> t a Source #
Higher-ranked equivalent of fold
.
hfoldA :: (HFoldableAt (Compose f t) h, Applicative f) => h t a -> f (t a) Source #
Fold in an applicative context.
hfoldMapA :: (HFoldableAt (Compose f k) h, Applicative f) => (forall b. t b -> f (k b)) -> h t a -> f (k a) Source #
Fold in an applicative context.
hfoldTraverse :: (HFoldableAt k h, HTraversable h, Applicative f) => (forall b. t b -> f (k b)) -> h t a -> f (k a) Source #
hfoldTraverse
is to hfoldMap
as htraverse
is to hmap
.
class HBifoldableAt k h where Source #
hbifoldMap :: (forall b. f b -> k b) -> (forall b. g b -> k b) -> h f g a -> k a Source #
Instances
HBifoldableAt (k2 :: k1 -> Type) (Sum :: (k1 -> Type) -> (k1 -> Type) -> k1 -> Type) Source # | |
Defined in Language.Expression hbifoldMap :: (forall (b :: k). f b -> k2 b) -> (forall (b :: k). g b -> k2 b) -> Sum f g a -> k2 a Source # | |
HBifoldableAt (k2 :: k1 -> Type) (BV :: (k1 -> Type) -> (k1 -> Type) -> k1 -> Type) Source # | |
Defined in Language.Expression.Scope hbifoldMap :: (forall (b :: k). f b -> k2 b) -> (forall (b :: k). g b -> k2 b) -> BV f g a -> k2 a Source # | |
(HFunctor h, HFoldableAt k2 h) => HBifoldableAt (k2 :: k1 -> Type) (Scoped h :: (k1 -> Type) -> (k1 -> Type) -> k1 -> Type) Source # | |
Defined in Language.Expression.Scope hbifoldMap :: (forall (b :: k). f b -> k2 b) -> (forall (b :: k). g b -> k2 b) -> Scoped h f g a -> k2 a Source # | |
Alternative k => HBifoldableAt (k :: Type -> Type) (Product :: (Type -> Type) -> (Type -> Type) -> Type -> Type) Source # | |
Defined in Language.Expression hbifoldMap :: (forall (b :: k0). f b -> k b) -> (forall (b :: k0). g b -> k b) -> Product f g a -> k a Source # |
hbifold :: HBifoldableAt k h => h k k a -> k a Source #
class HDuofoldableAt k h where Source #
hduofoldMap :: HTraversable s => (forall g b. (forall c. g c -> k c) -> s g b -> k b) -> (forall b. t b -> k b) -> h s t a -> k a Source #
Instances
HDuofoldableAt (k2 :: k1 -> Type) (HFree :: ((k1 -> Type) -> k1 -> Type) -> (k1 -> Type) -> k1 -> Type) Source # | |
Defined in Language.Expression hduofoldMap :: HTraversable s => (forall (g :: k -> Type) (b :: k). (forall (c :: k). g c -> k2 c) -> s g b -> k2 b) -> (forall (b :: k). t b -> k2 b) -> HFree s t a -> k2 a Source # | |
HDuofoldableAt (k2 :: k1 -> Type) (Scope k2 :: ((k1 -> Type) -> k1 -> Type) -> (k1 -> Type) -> k1 -> Type) Source # | |
Defined in Language.Expression.Scope hduofoldMap :: HTraversable s => (forall (g :: k -> Type) (b :: k). (forall (c :: k). g c -> k2 c) -> s g b -> k2 b) -> (forall (b :: k). t b -> k2 b) -> Scope k2 s t a -> k2 a Source # |
implHduofoldMap :: (HDuofunctor h, HFunctor s) => ((forall g b. (forall c. g c -> k c) -> s g b -> k b) -> h s k a -> k a) -> (forall g b. (forall c. g c -> k c) -> s g b -> k b) -> (forall b. t b -> k b) -> h s t a -> k a Source #
implHduofoldMapCompose :: (HDuotraversable h, HTraversable s, Monad m) => ((forall g b. (forall c. g c -> m (k c)) -> s g b -> m (k b)) -> h s k a -> m (k a)) -> (forall g b. (forall c. g c -> Compose m k c) -> s g b -> Compose m k b) -> (forall b. t b -> Compose m k b) -> h s t a -> Compose m k a Source #
is a higher-ranked free monad over the higher-ranked functor HFree
hh
.
That means that given
, we get HFunctor
h
for free.HMonad
(HFree
h)