Copyright | (C) 2012-2017 Nicolas Frisby (C) 2015-2017 Ryan Scott |
---|---|
License | BSD-style (see the file LICENSE) |
Maintainer | Ryan Scott |
Portability | Portable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Haskell98 invariant functors (also known as exponential functors).
For more information, see Edward Kmett's article "Rotten Bananas":
Synopsis
- class Invariant f where
- invmap :: (a -> b) -> (b -> a) -> f a -> f b
- invmapFunctor :: Functor f => (a -> b) -> (b -> a) -> f a -> f b
- genericInvmap :: (Generic1 f, Invariant (Rep1 f)) => (a -> b) -> (b -> a) -> f a -> f b
- newtype WrappedFunctor f a = WrapFunctor {
- unwrapFunctor :: f a
- invmapContravariant :: Contravariant f => (a -> b) -> (b -> a) -> f a -> f b
- invmapProfunctor :: Profunctor p => (a -> b) -> (b -> a) -> p a a -> p b b
- invmapArrow :: Arrow arr => (a -> b) -> (b -> a) -> arr a a -> arr b b
- newtype WrappedContravariant f a = WrapContravariant {
- unwrapContravariant :: f a
- newtype InvariantProfunctor p a = InvariantProfunctor (p a a)
- newtype InvariantArrow c a = InvariantArrow (c a a)
- class Invariant2 f where
- invmap2 :: (a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
- invmap2Bifunctor :: Bifunctor f => (a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
- newtype WrappedBifunctor (p :: k -> k1 -> Type) (a :: k) (b :: k1) = WrapBifunctor {
- unwrapBifunctor :: p a b
- invmap2Profunctor :: Profunctor f => (a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d
- newtype WrappedProfunctor p a b = WrapProfunctor {
- unwrapProfunctor :: p a b
Invariant
class Invariant f where Source #
Any * -> *
type parametric in the argument permits an instance of
Invariant
.
Instances should satisfy the following laws:
invmap id id = id invmap f2 f2' . invmap f1 f1' = invmap (f2 . f1) (f1' . f2')
Nothing
Instances
invmapFunctor :: Functor f => (a -> b) -> (b -> a) -> f a -> f b Source #
GHC.Generics
With GHC 7.2 or later, Invariant
instances can be defined easily using GHC
generics like so:
{-# LANGUAGE DeriveGeneric, FlexibleContexts #-}
import Data.Functor.Invariant
import GHC.Generics
data T f a = T (f a) deriving Generic1
instance Invariant f => Invariant
(T f)
Be aware that generic Invariant
instances cannot be derived for data types
that have function arguments in which the last type parameter appears in a
position other than the result type (e.g., data Fun a = Fun (a -> a)
). For
these, you can derive them using the Data.Functor.Invariant.TH module.
genericInvmap :: (Generic1 f, Invariant (Rep1 f)) => (a -> b) -> (b -> a) -> f a -> f b Source #
A generic implementation of invmap
.
newtype WrappedFunctor f a Source #
WrapFunctor | |
|
Instances
invmapContravariant :: Contravariant f => (a -> b) -> (b -> a) -> f a -> f b Source #
Every Contravariant
functor is also an Invariant
functor.
invmapProfunctor :: Profunctor p => (a -> b) -> (b -> a) -> p a a -> p b b Source #
A Profunctor
with the same input and output types can be seen as an Invariant
functor.
invmapArrow :: Arrow arr => (a -> b) -> (b -> a) -> arr a a -> arr b b Source #
newtype WrappedContravariant f a Source #
Wrap a Contravariant
functor to be used as a member of Invariant
.
Instances
newtype InvariantProfunctor p a Source #
A Profunctor
with the same input and output types can be seen as an Invariant
functor.
InvariantProfunctor (p a a) |
Instances
Profunctor p => Invariant (InvariantProfunctor p) Source # | |
Defined in Data.Functor.Invariant invmap :: (a -> b) -> (b -> a) -> InvariantProfunctor p a -> InvariantProfunctor p b Source # |
newtype InvariantArrow c a Source #
InvariantArrow (c a a) |
Instances
Arrow c => Invariant (InvariantArrow c) Source # | |
Defined in Data.Functor.Invariant invmap :: (a -> b) -> (b -> a) -> InvariantArrow c a -> InvariantArrow c b Source # |
Invariant2
class Invariant2 f where Source #
Any * -> * -> *
type parametric in both arguments permits an instance of
Invariant2
.
Instances should satisfy the following laws:
invmap2 id id id id = id invmap2 f2 f2' g2 g2' . invmap2 f1 f1' g1 g1' = invmap2 (f2 . f1) (f1' . f2') (g2 . g1) (g1' . g2')
Instances
Invariant2 Either Source # | |
Invariant2 Op Source # | from the |
Invariant2 Arg Source # | from Data.Semigroup |
Invariant2 (,) Source # | |
Defined in Data.Functor.Invariant | |
Arrow arr => Invariant2 (WrappedArrow arr) Source # | from Control.Applicative |
Defined in Data.Functor.Invariant invmap2 :: (a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> WrappedArrow arr a b -> WrappedArrow arr c d Source # | |
Invariant m => Invariant2 (Kleisli m) Source # | from Control.Arrow |
Invariant2 (Const :: Type -> Type -> Type) Source # | from Control.Applicative |
Invariant2 (CopastroSum p) Source # | from the |
Defined in Data.Functor.Invariant invmap2 :: (a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> CopastroSum p a b -> CopastroSum p c d Source # | |
Invariant2 (CotambaraSum p) Source # | from the |
Defined in Data.Functor.Invariant invmap2 :: (a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> CotambaraSum p a b -> CotambaraSum p c d Source # | |
Invariant2 (PastroSum p) Source # | from the |
Invariant2 p => Invariant2 (TambaraSum p) Source # | from the |
Defined in Data.Functor.Invariant invmap2 :: (a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> TambaraSum p a b -> TambaraSum p c d Source # | |
Invariant2 p => Invariant2 (Closure p) Source # | from the |
Invariant2 (Environment p) Source # | from the |
Defined in Data.Functor.Invariant invmap2 :: (a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> Environment p a b -> Environment p c d Source # | |
Invariant2 p => Invariant2 (CofreeMapping p) Source # | from the |
Defined in Data.Functor.Invariant invmap2 :: (a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> CofreeMapping p a b -> CofreeMapping p c d Source # | |
Invariant2 (FreeMapping p) Source # | from the |
Defined in Data.Functor.Invariant invmap2 :: (a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> FreeMapping p a b -> FreeMapping p c d Source # | |
Invariant2 (Copastro p) Source # | from the |
Invariant2 (Cotambara p) Source # | from the |
Invariant2 (Pastro p) Source # | from the |
Invariant2 p => Invariant2 (Tambara p) Source # | from the |
Invariant2 p => Invariant2 (CofreeTraversing p) Source # | from the |
Defined in Data.Functor.Invariant invmap2 :: (a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> CofreeTraversing p a b -> CofreeTraversing p c d Source # | |
Invariant2 (FreeTraversing p) Source # | from the |
Defined in Data.Functor.Invariant invmap2 :: (a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> FreeTraversing p a b -> FreeTraversing p c d Source # | |
Invariant2 (Coyoneda p) Source # | from the |
Invariant2 (Yoneda p) Source # | from the |
Invariant2 (Tagged :: Type -> Type -> Type) Source # | from the |
Invariant2 (Constant :: Type -> Type -> Type) Source # | from the |
Invariant2 ((,,) a) Source # | |
Defined in Data.Functor.Invariant | |
Invariant2 (K1 i :: Type -> Type -> Type) Source # | from GHC.Generics |
Invariant w => Invariant2 (Cokleisli w) Source # | from the |
Invariant f => Invariant2 (Costar f) Source # | from the |
Invariant2 (Forget r :: Type -> Type -> Type) Source # | from the |
Invariant f => Invariant2 (Star f) Source # | from the |
Invariant2 ((,,,) a b) Source # | |
Defined in Data.Functor.Invariant | |
Invariant2 (->) Source # | |
Defined in Data.Functor.Invariant | |
Invariant f => Invariant2 (Clown f :: Type -> Type -> Type) Source # | from the |
Invariant2 p => Invariant2 (Flip p) Source # | from the |
Invariant g => Invariant2 (Joker g :: Type -> Type -> Type) Source # | from the |
Bifunctor p => Invariant2 (WrappedBifunctor p) Source # | from the |
Defined in Data.Functor.Invariant invmap2 :: (a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> WrappedBifunctor p a b -> WrappedBifunctor p c d Source # | |
Profunctor p => Invariant2 (WrappedProfunctor p) Source # | |
Defined in Data.Functor.Invariant invmap2 :: (a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> WrappedProfunctor p a b -> WrappedProfunctor p c d Source # | |
Invariant2 p => Invariant2 (Codensity p) Source # | from the |
Arrow arr => Invariant2 (WrappedArrow arr) Source # | from the |
Defined in Data.Functor.Invariant invmap2 :: (a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> WrappedArrow arr a b -> WrappedArrow arr c d Source # | |
Invariant2 ((,,,,) a b c) Source # | |
Defined in Data.Functor.Invariant | |
(Invariant2 f, Invariant2 g) => Invariant2 (Product f g) Source # | from the |
(Invariant2 p, Invariant2 q) => Invariant2 (Sum p q) Source # | from the |
(Invariant f, Invariant2 p) => Invariant2 (Tannen f p) Source # | from the |
(Invariant f, Invariant2 p) => Invariant2 (Cayley f p) Source # | from the |
(Invariant2 p, Invariant2 q) => Invariant2 (Procompose p q) Source # | from the |
Defined in Data.Functor.Invariant invmap2 :: (a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> Procompose p q a b -> Procompose p q c d Source # | |
(Invariant2 p, Invariant2 q) => Invariant2 (Rift p q) Source # | from the |
(Invariant2 p, Invariant2 q) => Invariant2 (Ran p q) Source # | from the |
(Invariant2 p, Invariant f, Invariant g) => Invariant2 (Biff p f g) Source # | from the |
invmap2Bifunctor :: Bifunctor f => (a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d Source #
Every Bifunctor
is also an Invariant2
functor.
newtype WrappedBifunctor (p :: k -> k1 -> Type) (a :: k) (b :: k1) Source #
WrapBifunctor | |
|
Instances
invmap2Profunctor :: Profunctor f => (a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d Source #
Every Profunctor
is also an Invariant2
functor.
newtype WrappedProfunctor p a b Source #
Wrap a Profunctor
to be used as a member of Invariant2
.
WrapProfunctor | |
|