HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Moduleinvariant-0.6.4Haskell2010

Data.Functor.Invariant

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/

  • 6 types
  • 2 classes
  • 7 values
  • Packageinvariant-0.6.4
  • Exports15
  • LanguageHaskell2010
  • LicenceBSD-2-Clause
  • SourceInvariant.hs

Invariant

2 declarations
classclass Invariant (f :: Type -> Type) where
#

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
Instances129Invariant, …

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.

newtypenewtype WrappedFunctor (f :: k -> Type) (a :: k)
#

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

Constructors

Instances12Monad, Functor, Applicative, Foldable, Traversable, Alternative, …
valueinvmapArrow :: Arrow arr => (a -> b) -> (b -> a) -> arr a a -> arr b b
#

An Arrow with the same input and output types can be seen as an Invariant functor.

newtypenewtype WrappedContravariant (f :: k -> Type) (a :: k)
#

Wrap a Contravariant functor to be used as a member of Invariant.

Instances8Contravariant, Decidable, Divisible, Invariant, Eq, Ord, …

Invariant2

5 declarations
classclass Invariant2 (f :: Type -> Type -> Type) where
#

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
Instances49Invariant2, …
newtypenewtype WrappedBifunctor (p :: k -> k1 -> Type) (a :: k) (b :: k1)
#

Make a Functor over the second argument of a Bifunctor.

Constructors

Instances26Generic1, Bifoldable, Bifoldable1, Bifunctor, Bitraversable, Eq2, …
newtypenewtype WrappedProfunctor (p :: k -> k1 -> Type) (a :: k) (b :: k1)
#

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

Constructors

Instances23ProfunctorFunctor, Category, ProfunctorComonad, ProfunctorMonad, Arrow, ArrowChoice, …