invariant-0.2.1: 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')

Methods

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

Instances

Invariant [] 
Invariant IO 
Invariant V1

from GHC.Generics

Invariant U1

from GHC.Generics

Invariant Par1

from GHC.Generics

Invariant ArgOrder

from System.Console.GetOpt

Invariant OptDescr

from System.Console.GetOpt

Invariant ArgDescr

from System.Console.GetOpt

Invariant ZipList

from Control.Applicative

Invariant Handler

from Control.Exception

Invariant STM

from the stm package

Invariant Dual

from Data.Monoid

Invariant Endo

from Data.Monoid

Invariant First

from Data.Monoid

Invariant Last

from Data.Monoid

Invariant ReadPrec 
Invariant ReadP 
Invariant Maybe 
Invariant Identity

from Data.Functor.Identity

Invariant IntMap

from the containers package

Invariant Tree

from the containers package

Invariant Seq

from the containers package

Invariant ViewL

from the containers package

Invariant ViewR

from the containers package

Invariant Predicate

from the contravariant package

Invariant Comparison

from the contravariant package

Invariant Equivalence

from the contravariant package

Invariant Min

from the semigroups package

Invariant Max

from the semigroups package

Invariant First

from the semigroups package

Invariant Last

from the semigroups package

Invariant Option

from the semigroups package

Invariant NonEmpty

from the semigroups package

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

from GHC.Generics

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

from the array package

Invariant (Const a)

from Control.Applicative

Monad m => Invariant (WrappedMonad m)

from Control.Applicative

Invariant (ST s) 
Arrow a => Invariant (ArrowMonad a)

from Control.Arrow

Invariant (Proxy *)

from Data.Proxy

Invariant2 p => Invariant (Join p)

from the bifunctors package

Invariant m => Invariant (IdentityT m)

from the transformers package

Invariant (Map k)

from the containers package

Invariant (Op a)

from the contravariant package

Invariant (Arg a)

from the semigroups package

Invariant f => Invariant (Reverse f)

from the transformers package

Invariant f => Invariant (Backwards f)

from the transformers package

Invariant m => Invariant (MaybeT m)

from the transformers package

Invariant m => Invariant (ListT m)

from the transformers package

Invariant f => Invariant (Lift f)

from the transformers package

Invariant (Constant a)

from the transformers package

Invariant (HashMap k)

from the unordered-containers package

Contravariant f => Invariant (WrappedContravariant f) 
Functor f => Invariant (WrappedFunctor f) 
Invariant (K1 i c)

from GHC.Generics

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

from GHC.Generics

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

from GHC.Generics

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

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

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

from Control.Applicative

Bifunctor p => Invariant (WrappedBifunctor p a)

from the bifunctors package

Invariant g => Invariant (Joker g a)

from the bifunctors package

Invariant2 p => Invariant (Flip p a)

from the bifunctors package

Invariant (Clown f a)

from the bifunctors package

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

from the contravariant package

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

from the contravariant package

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

from the contravariant package

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

from the transformers package

Invariant2 p => Invariant (Tambara p a)

from the profunctors package

Invariant2 p => Invariant (Cotambara p a)

from the profunctors package

Invariant2 p => Invariant (Codensity p a)

from the profunctors package

Invariant2 p => Invariant (Closure p a)

from the profunctors package

Invariant f => Invariant (Star f a)

from the profunctors package

Invariant (Costar f a)

from the profunctors package

Arrow arr => Invariant (WrappedArrow arr a)

from the profunctors package

Invariant (Forget r a)

from the profunctors package

Invariant (Tagged * s)

from the tagged package

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

from the transformers package

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

from the transformers package

Invariant m => Invariant (WriterT w m)

from the transformers package

Invariant m => Invariant (WriterT w m)

from the transformers package

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

from the transformers package

Invariant m => Invariant (StateT s m)

from the transformers package

Invariant m => Invariant (StateT s m)

from the transformers package

Invariant m => Invariant (ReaderT r m)

from the transformers package

Invariant (ContT r m)

from the transformers package

Profunctor p => Invariant (WrappedProfunctor p a) 
Invariant f => Invariant (M1 i t f)

from GHC.Generics

Invariant ((,,,) a b c) 
(Invariant f, Invariant2 p) => Invariant (Tannen f p a)

from the bifunctors package

Invariant2 q => Invariant (Ran p q a)

from the profunctors package

Invariant2 p => Invariant (Procompose p q a)

from the profunctors package

Invariant2 p => Invariant (Rift p q a)

from the profunctors package

Invariant ((,,,,) a b c d) 
(Invariant2 p, Invariant g) => Invariant (Biff p f g a)

from the bifunctors package

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

from the transformers package

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

from the transformers package

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

Every Functor is also an Invariant functor.

newtype WrappedFunctor f a Source

Wrap a Functor to be used as a member of Invariant.

Constructors

WrapFunctor 

Fields

unwrapFunctor :: f a
 

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

Every Contravariant functor is also an Invariant functor.

GHC.Generics

Note: The restriction to Haskell98 prevents the full adoption of GHC.Generics, but we are permitted to at least provide Invariant instances for the representation data types. Thus, while the "ideal"

  instance Invariant f => Invariant (T f)

doesn't work --- because Haskell98 precludes our use of -XDefaultSignatures in the class definition ---, the user only needs to do slightly more work:

  import GHC.Generics (from1,to1)

  instance Invariant f => Invariant (T f) where
    invmap f g = to1 . invmap f g . from1

Note also that that instance is in fact Haskell98. Unfortunately, one would require -XFlexibleContexts in order to factor that right-hand side out as reusable declaration polymorphic in the data type.

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 (->) 
Invariant2 Either 
Invariant2 (,) 
Invariant2 Const

from Control.Applicative

Invariant2 Op

from the contravariant package

Invariant2 Arg

from the semigroups package

Invariant2 Constant

from the transformers package

Invariant2 (K1 i)

from GHC.Generics

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

from Control.Applicative

Bifunctor p => Invariant2 (WrappedBifunctor p)

from the bifunctors package

Invariant g => Invariant2 (Joker g)

from the bifunctors package

Invariant2 p => Invariant2 (Flip p)

from the bifunctors package

Invariant f => Invariant2 (Clown f)

from the bifunctors package

Invariant2 p => Invariant2 (Tambara p)

from the profunctors package

Invariant2 (Pastro p)

from the profunctors package

Invariant2 p => Invariant2 (Cotambara p)

from the profunctors package

Invariant2 (Copastro p)

from the profunctors package

Invariant2 p => Invariant2 (Codensity p)

from the profunctors package

Invariant2 p => Invariant2 (Closure p)

from the profunctors package

Invariant2 (Environment p)

from the profunctors package

Invariant f => Invariant2 (Star f)

from the profunctors package

Invariant f => Invariant2 (Costar f)

from the profunctors package

Arrow arr => Invariant2 (WrappedArrow arr)

from the profunctors package

Invariant2 (Forget r)

from the profunctors package

Invariant2 (Tagged *)

from the tagged package

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

from the bifunctors package

(Invariant2 f, Invariant2 g) => Invariant2 (Product f g)

from the bifunctors package

(Invariant2 p, Invariant2 q) => Invariant2 (Ran p q)

from the profunctors package

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

from the profunctors package

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

from the profunctors package

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

from the profunctors package

Invariant2 ((,,,,) a b c) 
(Invariant2 p, Invariant f, Invariant g) => Invariant2 (Biff p f g)

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 :: (* -> * -> *) -> * -> * -> *

Make a Functor over the second argument of a Bifunctor.

Constructors

WrapBifunctor 

Fields

unwrapBifunctor :: 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.

newtype WrappedProfunctor p a b Source

Wrap a Profunctor to be used as a member of Invariant2.

Constructors

WrapProfunctor 

Fields

unwrapProfunctor :: p a b