invariant-0.3: Haskell 98 invariant functors

Copyright(C) 2012-2015 Nicolas Frisby, (C) 2015 Ryan Scott
LicenseBSD-style (see the file LICENSE)
MaintainerRyan Scott
PortabilityPortable
Safe HaskellNone
LanguageHaskell98

Data.Functor.Invariant

Contents

Description

Haskell98 invariant functors (also known as exponential functors).

For more information, see Edward Kmett's article "Rotten Bananas":

http://comonad.com/reader/2008/rotten-bananas/

Synopsis

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')

Minimal complete definition

Nothing

Methods

invmap :: (a -> b) -> (b -> a) -> f a -> f b Source

Instances

Invariant [] Source 
Invariant IO Source 
Invariant V1 Source

from GHC.Generics

Invariant U1 Source

from GHC.Generics

Invariant Par1 Source

from GHC.Generics

Invariant StateVar Source

from the StateVar package

Invariant SettableStateVar Source

from the StateVar package

Invariant ArgOrder Source

from System.Console.GetOpt

Invariant OptDescr Source

from System.Console.GetOpt

Invariant ArgDescr Source

from System.Console.GetOpt

Invariant Identity Source

from Data.Functor.Identity

Invariant ZipList Source

from Control.Applicative

Invariant Handler Source

from Control.Exception

Invariant STM Source

from the stm package

Invariant Dual Source

from Data.Monoid

Invariant Endo Source

from Data.Monoid

Invariant First Source

from Data.Monoid

Invariant Last Source

from Data.Monoid

Invariant ReadPrec Source 
Invariant ReadP Source 
Invariant Maybe Source 
Invariant IntMap Source

from the containers package

Invariant Tree Source

from the containers package

Invariant Seq Source

from the containers package

Invariant ViewL Source

from the containers package

Invariant ViewR Source

from the containers package

Invariant Predicate Source

from the contravariant package

Invariant Comparison Source

from the contravariant package

Invariant Equivalence Source

from the contravariant package

Invariant Min Source

from the semigroups package

Invariant Max Source

from the semigroups package

Invariant First Source

from the semigroups package

Invariant Last Source

from the semigroups package

Invariant Option Source

from the semigroups package

Invariant NonEmpty Source

from the semigroups package

Invariant ((->) a) Source 
Invariant (Either a) Source 
Invariant f => Invariant (Rec1 f) Source

from GHC.Generics

Invariant ((,) a) Source 
Invariant (ST s) Source 
Ix i => Invariant (Array i) Source

from the array package

Invariant (ST s) Source 
Invariant (Const a) Source

from Control.Applicative

Monad m => Invariant (WrappedMonad m) Source

from Control.Applicative

Arrow a => Invariant (ArrowMonad a) Source

from Control.Arrow

Invariant (Proxy *) Source

from Data.Proxy

Invariant m => Invariant (IdentityT m) Source

from the transformers package

Invariant (Map k) Source

from the containers package

Invariant (Op a) Source

from the contravariant package

Invariant2 p => Invariant (Prep p) Source

from the profunctors package

Invariant2 p => Invariant (Coprep p) Source

from the profunctors package

Invariant (Arg a) Source

from the semigroups package

Invariant f => Invariant (Reverse f) Source

from the transformers package

Invariant f => Invariant (Backwards f) Source

from the transformers package

Invariant m => Invariant (MaybeT m) Source

from the transformers package

Invariant m => Invariant (ListT m) Source

from the transformers package

Invariant f => Invariant (Lift f) Source

from the transformers package

Invariant (Constant a) Source

from the transformers package

Invariant (HashMap k) Source

from the unordered-containers package

Invariant (K1 i c) Source

from GHC.Generics

(Invariant l, Invariant r) => Invariant ((:+:) l r) Source

from GHC.Generics

(Invariant l, Invariant r) => Invariant ((:*:) l r) Source

from GHC.Generics

(Invariant f, Invariant g) => Invariant ((:.:) f g) Source

from GHC.Generics; genuinely relying on this instance likely requires writing your Generic1 instance by hand

Invariant ((,,) a b) Source 
Arrow arr => Invariant (WrappedArrow arr a) Source

from Control.Applicative

Invariant f => Invariant (Alt * f) Source

from Data.Monoid

Invariant2 p => Invariant (Join * p) Source

from the bifunctors package

Invariant2 p => Invariant (Fix * p) Source

from the bifunctors package

(Invariant f, Invariant g) => Invariant (Compose f g) Source

from the contravariant package

(Invariant f, Invariant g) => Invariant (ComposeFC f g) Source

from the contravariant package

(Invariant f, Invariant g) => Invariant (ComposeCF f g) Source

from the contravariant package

(Invariant f, Invariant g) => Invariant (Compose f g) Source

from the transformers package

Invariant2 p => Invariant (Codensity p a) Source

from the profunctors package

Invariant2 p => Invariant (TambaraSum p a) Source

from the profunctors package

Invariant (CotambaraSum p a) Source

from the profunctors package

Invariant2 p => Invariant (Closure p a) Source

from the profunctors package

Invariant2 p => Invariant (Tambara p a) Source

from the profunctors package

Invariant (Cotambara p a) Source

from the profunctors package

Invariant f => Invariant (Star f a) Source

from the profunctors package

Invariant (Costar f a) Source

from the profunctors package

Arrow arr => Invariant (WrappedArrow arr a) Source

from the profunctors package

Invariant (Forget r a) Source

from the profunctors package

Invariant (Tagged k s) Source

from the tagged package

(Invariant f, Invariant g) => Invariant (Sum f g) Source

from the transformers package

(Invariant f, Invariant g) => Invariant (Product f g) Source

from the transformers package

Invariant m => Invariant (WriterT w m) Source

from the transformers package

Invariant m => Invariant (WriterT w m) Source

from the transformers package

Invariant m => Invariant (ErrorT e m) Source 
Invariant m => Invariant (ExceptT e m) Source

from the transformers package

Invariant m => Invariant (StateT s m) Source

from the transformers package

Invariant m => Invariant (StateT s m) Source

from the transformers package

Invariant m => Invariant (ReaderT r m) Source

from the transformers package

Invariant (ContT r m) Source

from the transformers package

Contravariant f => Invariant (WrappedContravariant * f) Source 
Functor f => Invariant (WrappedFunctor * f) Source 
Invariant f => Invariant (M1 i t f) Source

from GHC.Generics

Invariant ((,,,) a b c) Source 
Invariant2 q => Invariant (Ran p q a) Source

from the profunctors package

Invariant2 p => Invariant (Procompose p q a) Source

from the profunctors package

Invariant2 p => Invariant (Rift p q a) Source

from the profunctors package

Invariant ((,,,,) a b c d) Source 
Bifunctor p => Invariant (WrappedBifunctor * * p a) Source

from the bifunctors package

Invariant g => Invariant (Joker k * g a) Source

from the bifunctors package

Invariant2 p => Invariant (Flip * * p a) Source

from the bifunctors package

Invariant (Clown * k f a) Source

from the bifunctors package

Invariant m => Invariant (RWST r w s m) Source

from the transformers package

Invariant m => Invariant (RWST r w s m) Source

from the transformers package

Profunctor p => Invariant (WrappedProfunctor * * p a) Source 
(Invariant f, Invariant2 p) => Invariant (Tannen * * * f p a) Source

from the bifunctors package

(Invariant2 p, Invariant g) => Invariant (Biff * * k * p f g a) Source

from the bifunctors package

invmapFunctor :: Functor f => (a -> b) -> (b -> a) -> f a -> f b Source

Every Functor is also an Invariant functor.

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.

invmapContravariant :: Contravariant f => (a -> b) -> (b -> a) -> f a -> f b Source

Every Contravariant functor is also an Invariant functor.

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')

Methods

invmap2 :: (a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> f a b -> f c d Source

Instances

Invariant2 (->) Source 
Invariant2 Either Source 
Invariant2 (,) Source 
Invariant2 Const Source

from Control.Applicative

Invariant2 Op Source

from the contravariant package

Invariant2 Arg Source

from the semigroups package

Invariant2 Constant Source

from the transformers package

Invariant2 (K1 i) Source

from GHC.Generics

Invariant2 ((,,) a) Source 
Arrow arr => Invariant2 (WrappedArrow arr) Source

from Control.Applicative

Invariant2 p => Invariant2 (Codensity p) Source

from the profunctors package

Invariant2 p => Invariant2 (CofreeMapping p) Source

from the profunctors package

Invariant2 (FreeMapping p) Source

from the profunctors package

Invariant2 p => Invariant2 (CofreeTraversing p) Source

from the profunctors package

Invariant2 (FreeTraversing p) Source

from the profunctors package

Invariant2 p => Invariant2 (TambaraSum p) Source

from the profunctors package

Invariant2 (PastroSum p) Source

from the profunctors package

Invariant2 (CotambaraSum p) Source

from the profunctors package

Invariant2 (CopastroSum p) Source

from the profunctors package

Invariant2 p => Invariant2 (Closure p) Source

from the profunctors package

Invariant2 (Environment p) Source

from the profunctors package

Invariant2 p => Invariant2 (Tambara p) Source

from the profunctors package

Invariant2 (Pastro p) Source

from the profunctors package

Invariant2 (Cotambara p) Source

from the profunctors package

Invariant f => Invariant2 (Star f) Source

from the profunctors package

Invariant f => Invariant2 (Costar f) Source

from the profunctors package

Arrow arr => Invariant2 (WrappedArrow arr) Source

from the profunctors package

Invariant2 (Forget r) Source

from the profunctors package

Invariant2 (Tagged *) Source

from the tagged package

Invariant2 ((,,,) a b) Source 
(Invariant2 p, Invariant2 q) => Invariant2 (Ran p q) Source

from the profunctors package

(Invariant2 p, Invariant2 q) => Invariant2 (Procompose p q) Source

from the profunctors package

(Invariant2 p, Invariant2 q) => Invariant2 (Rift p q) Source

from the profunctors package

(Invariant f, Invariant2 p) => Invariant2 (Cayley f p) Source

from the profunctors package

Invariant2 ((,,,,) a b c) Source 
Bifunctor p => Invariant2 (WrappedBifunctor * * p) Source

from the bifunctors package

Invariant g => Invariant2 (Joker * * g) Source

from the bifunctors package

Invariant2 p => Invariant2 (Flip * * p) Source

from the bifunctors package

Invariant f => Invariant2 (Clown * * f) Source

from the bifunctors package

Profunctor p => Invariant2 (WrappedProfunctor * * p) Source 
(Invariant2 f, Invariant2 g) => Invariant2 (Product * * f g) Source

from the bifunctors package

(Invariant2 p, Invariant2 q) => Invariant2 (Sum * * p q) Source

from the bifunctors package

(Invariant f, Invariant2 p) => Invariant2 (Tannen * * * f p) Source

from the bifunctors package

(Invariant2 p, Invariant f, Invariant g) => Invariant2 (Biff * * * * p f g) Source

from the bifunctors package

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 a b :: (k -> k1 -> *) -> k -> k1 -> *

Make a Functor over the second argument of a Bifunctor.

Constructors

WrapBifunctor 

Fields

unwrapBifunctor :: p a b
 

Instances

Bifunctor p => Bifunctor (WrappedBifunctor * * p) 
Biapplicative p => Biapplicative (WrappedBifunctor * * p) 
Bitraversable p => Bitraversable (WrappedBifunctor * * p) 
Bifoldable p => Bifoldable (WrappedBifunctor * * p) 
Bifunctor p => Invariant2 (WrappedBifunctor * * p) Source

from the bifunctors package

Bifunctor p => Functor (WrappedBifunctor * * p a) 
Bifoldable p => Foldable (WrappedBifunctor * * p a) 
Bitraversable p => Traversable (WrappedBifunctor * * p a) 
Generic1 (WrappedBifunctor k * p a) 
Bifunctor p => Invariant (WrappedBifunctor * * p a) Source

from the bifunctors package

Eq (p a b) => Eq (WrappedBifunctor k k1 p a b) 
Ord (p a b) => Ord (WrappedBifunctor k k1 p a b) 
Read (p a b) => Read (WrappedBifunctor k k1 p a b) 
Show (p a b) => Show (WrappedBifunctor k k1 p a b) 
Generic (WrappedBifunctor k k1 p a b) 
type Rep1 (WrappedBifunctor k k1 p a) = D1 D1WrappedBifunctor (C1 C1_0WrappedBifunctor (S1 S1_0_0WrappedBifunctor (Rec1 (p a)))) 
type Rep (WrappedBifunctor k k1 p a b) = D1 D1WrappedBifunctor (C1 C1_0WrappedBifunctor (S1 S1_0_0WrappedBifunctor (Rec0 (p a b)))) 

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.