constrained-categories-0.3.1.0: Constrained clones of the category-theory type classes, using ConstraintKinds.

Copyright(c) 2013-2016 Justus Sagemüller
LicenseGPL v3 (see COPYING)
Maintainer(@) sagemueller $ geo.uni-koeln.de
Safe HaskellTrustworthy
LanguageHaskell2010

Control.Category.Constrained

Contents

Description

The most basic category theory tools are included partly in this module, partly in Control.Arrow.Constrained.

Synopsis

The category class

class Category k where Source #

In mathematics, a category is defined as a class of objects, plus a class of morphisms between those objects. In Haskell, one traditionally works in the category (->) (called Hask), in which any Haskell type is an object. But of course there are lots of useful categories where the objects are much more specific, e.g. vector spaces with linear maps as morphisms. The obvious way to express this in Haskell is as type class constraints, and the ConstraintKinds extension allows quantifying over such object classes.

Like in Control.Category, "the category k" means actually k is the morphism type constructor. From a mathematician's point of view this may seem a bit strange way to define the category, but it just turns out to be quite convenient for practical purposes.

Minimal complete definition

id, (.)

Associated Types

type Object k o :: Constraint Source #

Methods

id :: Object k a => k a a Source #

(.) :: (Object k a, Object k b, Object k c) => k b c -> k a b -> k a c infixr 9 Source #

Instances

Category (Coercion *) Source # 

Associated Types

type Object (Coercion * :: * -> * -> *) o :: Constraint Source #

Methods

id :: Object (Coercion *) a => Coercion * a a Source #

(.) :: (Object (Coercion *) a, Object (Coercion *) b, Object (Coercion *) c) => Coercion * b c -> Coercion * a b -> Coercion * a c Source #

Category (Discrete *) Source # 

Associated Types

type Object (Discrete * :: * -> * -> *) o :: Constraint Source #

Methods

id :: Object (Discrete *) a => Discrete * a a Source #

(.) :: (Object (Discrete *) a, Object (Discrete *) b, Object (Discrete *) c) => Discrete * b c -> Discrete * a b -> Discrete * a c Source #

WellPointed k => Category (ReWellPointed k) Source # 

Associated Types

type Object (ReWellPointed k :: * -> * -> *) o :: Constraint Source #

PreArrow k => Category (RePreArrow k) Source # 

Associated Types

type Object (RePreArrow k :: * -> * -> *) o :: Constraint Source #

Methods

id :: Object (RePreArrow k) a => RePreArrow k a a Source #

(.) :: (Object (RePreArrow k) a, Object (RePreArrow k) b, Object (RePreArrow k) c) => RePreArrow k b c -> RePreArrow k a b -> RePreArrow k a c Source #

Morphism k => Category (ReMorphism k) Source # 

Associated Types

type Object (ReMorphism k :: * -> * -> *) o :: Constraint Source #

Methods

id :: Object (ReMorphism k) a => ReMorphism k a a Source #

(.) :: (Object (ReMorphism k) a, Object (ReMorphism k) b, Object (ReMorphism k) c) => ReMorphism k b c -> ReMorphism k a b -> ReMorphism k a c Source #

Cartesian k => Category (ReCartesian k) Source # 

Associated Types

type Object (ReCartesian k :: * -> * -> *) o :: Constraint Source #

Methods

id :: Object (ReCartesian k) a => ReCartesian k a a Source #

(.) :: (Object (ReCartesian k) a, Object (ReCartesian k) b, Object (ReCartesian k) c) => ReCartesian k b c -> ReCartesian k a b -> ReCartesian k a c Source #

Category k => Category (ReCategory k) Source # 

Associated Types

type Object (ReCategory k :: * -> * -> *) o :: Constraint Source #

Methods

id :: Object (ReCategory k) a => ReCategory k a a Source #

(.) :: (Object (ReCategory k) a, Object (ReCategory k) b, Object (ReCategory k) c) => ReCategory k b c -> ReCategory k a b -> ReCategory k a c Source #

Category ((->) LiftedRep LiftedRep) Source # 

Associated Types

type Object (LiftedRep -> LiftedRep :: * -> * -> *) o :: Constraint Source #

Category k => Category (ConstrainedCategory k isObj) Source # 

Associated Types

type Object (ConstrainedCategory k isObj :: * -> * -> *) o :: Constraint Source #

Methods

id :: Object (ConstrainedCategory k isObj) a => ConstrainedCategory k isObj a a Source #

(.) :: (Object (ConstrainedCategory k isObj) a, Object (ConstrainedCategory k isObj) b, Object (ConstrainedCategory k isObj) c) => ConstrainedCategory k isObj b c -> ConstrainedCategory k isObj a b -> ConstrainedCategory k isObj a c Source #

Monad m k => Category (Kleisli m k) Source # 

Associated Types

type Object (Kleisli m k :: * -> * -> *) o :: Constraint Source #

Methods

id :: Object (Kleisli m k) a => Kleisli m k a a Source #

(.) :: (Object (Kleisli m k) a, Object (Kleisli m k) b, Object (Kleisli m k) c) => Kleisli m k b c -> Kleisli m k a b -> Kleisli m k a c Source #

Monoidal categories

class (Category k, Monoid (UnitObject k), Object k (UnitObject k)) => Cartesian k where Source #

Quite a few categories (monoidal categories) will permit "products" of objects as objects again – in the Haskell sense those are tuples – allowing for "dyadic morphisms" (x,y) ~> r.

Together with a unique UnitObject, this makes for a monoidal structure, with a few natural isomorphisms. Ordinary tuples may not always be powerful enough to express the product objects; we avoid making a dedicated associated type for the sake of simplicity, but allow for an extra constraint to be imposed on objects prior to consideration of pair-building.

The name Cartesian is disputable: in category theory that would rather Imply cartesian closed category (which we represent with Curry). Monoidal would make sense, but we reserve that to Functors.

Minimal complete definition

swap, attachUnit, detachUnit, regroup, regroup'

Associated Types

type PairObjects k a b :: Constraint Source #

Extra properties two types a, b need to fulfill so (a,b) can be an object of the category. This need not take care for a and b themselves being objects, we do that seperately: every function that actually deals with (a,b) objects should require the stronger ObjectPair k a b.

If any two object types of your category make up a pair object, then just leave PairObjects at the default (empty constraint).

type UnitObject k :: * Source #

Defaults to '()', and should normally be left at that.

Methods

swap :: (ObjectPair k a b, ObjectPair k b a) => k (a, b) (b, a) Source #

attachUnit :: (u ~ UnitObject k, ObjectPair k a u) => k a (a, u) Source #

detachUnit :: (u ~ UnitObject k, ObjectPair k a u) => k (a, u) a Source #

regroup :: (ObjectPair k a b, ObjectPair k b c, ObjectPair k a (b, c), ObjectPair k (a, b) c) => k (a, (b, c)) ((a, b), c) Source #

regroup' :: (ObjectPair k a b, ObjectPair k b c, ObjectPair k a (b, c), ObjectPair k (a, b) c) => k ((a, b), c) (a, (b, c)) Source #

Instances

WellPointed k => Cartesian (ReWellPointed k) Source # 

Associated Types

type PairObjects (ReWellPointed k :: * -> * -> *) a b :: Constraint Source #

type UnitObject (ReWellPointed k :: * -> * -> *) :: * Source #

Methods

swap :: (ObjectPair (ReWellPointed k) a b, ObjectPair (ReWellPointed k) b a) => ReWellPointed k (a, b) (b, a) Source #

attachUnit :: ((* ~ u) (UnitObject (ReWellPointed k)), ObjectPair (ReWellPointed k) a u) => ReWellPointed k a (a, u) Source #

detachUnit :: ((* ~ u) (UnitObject (ReWellPointed k)), ObjectPair (ReWellPointed k) a u) => ReWellPointed k (a, u) a Source #

regroup :: (ObjectPair (ReWellPointed k) a b, ObjectPair (ReWellPointed k) b c, ObjectPair (ReWellPointed k) a (b, c), ObjectPair (ReWellPointed k) (a, b) c) => ReWellPointed k (a, (b, c)) ((a, b), c) Source #

regroup' :: (ObjectPair (ReWellPointed k) a b, ObjectPair (ReWellPointed k) b c, ObjectPair (ReWellPointed k) a (b, c), ObjectPair (ReWellPointed k) (a, b) c) => ReWellPointed k ((a, b), c) (a, (b, c)) Source #

PreArrow k => Cartesian (RePreArrow k) Source # 

Associated Types

type PairObjects (RePreArrow k :: * -> * -> *) a b :: Constraint Source #

type UnitObject (RePreArrow k :: * -> * -> *) :: * Source #

Methods

swap :: (ObjectPair (RePreArrow k) a b, ObjectPair (RePreArrow k) b a) => RePreArrow k (a, b) (b, a) Source #

attachUnit :: ((* ~ u) (UnitObject (RePreArrow k)), ObjectPair (RePreArrow k) a u) => RePreArrow k a (a, u) Source #

detachUnit :: ((* ~ u) (UnitObject (RePreArrow k)), ObjectPair (RePreArrow k) a u) => RePreArrow k (a, u) a Source #

regroup :: (ObjectPair (RePreArrow k) a b, ObjectPair (RePreArrow k) b c, ObjectPair (RePreArrow k) a (b, c), ObjectPair (RePreArrow k) (a, b) c) => RePreArrow k (a, (b, c)) ((a, b), c) Source #

regroup' :: (ObjectPair (RePreArrow k) a b, ObjectPair (RePreArrow k) b c, ObjectPair (RePreArrow k) a (b, c), ObjectPair (RePreArrow k) (a, b) c) => RePreArrow k ((a, b), c) (a, (b, c)) Source #

Morphism k => Cartesian (ReMorphism k) Source # 

Associated Types

type PairObjects (ReMorphism k :: * -> * -> *) a b :: Constraint Source #

type UnitObject (ReMorphism k :: * -> * -> *) :: * Source #

Methods

swap :: (ObjectPair (ReMorphism k) a b, ObjectPair (ReMorphism k) b a) => ReMorphism k (a, b) (b, a) Source #

attachUnit :: ((* ~ u) (UnitObject (ReMorphism k)), ObjectPair (ReMorphism k) a u) => ReMorphism k a (a, u) Source #

detachUnit :: ((* ~ u) (UnitObject (ReMorphism k)), ObjectPair (ReMorphism k) a u) => ReMorphism k (a, u) a Source #

regroup :: (ObjectPair (ReMorphism k) a b, ObjectPair (ReMorphism k) b c, ObjectPair (ReMorphism k) a (b, c), ObjectPair (ReMorphism k) (a, b) c) => ReMorphism k (a, (b, c)) ((a, b), c) Source #

regroup' :: (ObjectPair (ReMorphism k) a b, ObjectPair (ReMorphism k) b c, ObjectPair (ReMorphism k) a (b, c), ObjectPair (ReMorphism k) (a, b) c) => ReMorphism k ((a, b), c) (a, (b, c)) Source #

Cartesian k => Cartesian (ReCartesian k) Source # 

Associated Types

type PairObjects (ReCartesian k :: * -> * -> *) a b :: Constraint Source #

type UnitObject (ReCartesian k :: * -> * -> *) :: * Source #

Methods

swap :: (ObjectPair (ReCartesian k) a b, ObjectPair (ReCartesian k) b a) => ReCartesian k (a, b) (b, a) Source #

attachUnit :: ((* ~ u) (UnitObject (ReCartesian k)), ObjectPair (ReCartesian k) a u) => ReCartesian k a (a, u) Source #

detachUnit :: ((* ~ u) (UnitObject (ReCartesian k)), ObjectPair (ReCartesian k) a u) => ReCartesian k (a, u) a Source #

regroup :: (ObjectPair (ReCartesian k) a b, ObjectPair (ReCartesian k) b c, ObjectPair (ReCartesian k) a (b, c), ObjectPair (ReCartesian k) (a, b) c) => ReCartesian k (a, (b, c)) ((a, b), c) Source #

regroup' :: (ObjectPair (ReCartesian k) a b, ObjectPair (ReCartesian k) b c, ObjectPair (ReCartesian k) a (b, c), ObjectPair (ReCartesian k) (a, b) c) => ReCartesian k ((a, b), c) (a, (b, c)) Source #

Cartesian ((->) LiftedRep LiftedRep) Source # 

Associated Types

type PairObjects (LiftedRep -> LiftedRep :: * -> * -> *) a b :: Constraint Source #

type UnitObject (LiftedRep -> LiftedRep :: * -> * -> *) :: * Source #

Methods

swap :: (ObjectPair (LiftedRep -> LiftedRep) a b, ObjectPair (LiftedRep -> LiftedRep) b a) => (LiftedRep -> LiftedRep) (a, b) (b, a) Source #

attachUnit :: ((* ~ u) (UnitObject (LiftedRep -> LiftedRep)), ObjectPair (LiftedRep -> LiftedRep) a u) => (LiftedRep -> LiftedRep) a (a, u) Source #

detachUnit :: ((* ~ u) (UnitObject (LiftedRep -> LiftedRep)), ObjectPair (LiftedRep -> LiftedRep) a u) => (LiftedRep -> LiftedRep) (a, u) a Source #

regroup :: (ObjectPair (LiftedRep -> LiftedRep) a b, ObjectPair (LiftedRep -> LiftedRep) b c, ObjectPair (LiftedRep -> LiftedRep) a (b, c), ObjectPair (LiftedRep -> LiftedRep) (a, b) c) => (LiftedRep -> LiftedRep) (a, (b, c)) ((a, b), c) Source #

regroup' :: (ObjectPair (LiftedRep -> LiftedRep) a b, ObjectPair (LiftedRep -> LiftedRep) b c, ObjectPair (LiftedRep -> LiftedRep) a (b, c), ObjectPair (LiftedRep -> LiftedRep) (a, b) c) => (LiftedRep -> LiftedRep) ((a, b), c) (a, (b, c)) Source #

(Cartesian f, o (UnitObject f)) => Cartesian (ConstrainedCategory f o) Source # 

Associated Types

type PairObjects (ConstrainedCategory f o :: * -> * -> *) a b :: Constraint Source #

type UnitObject (ConstrainedCategory f o :: * -> * -> *) :: * Source #

(Monad m a, Cartesian a) => Cartesian (Kleisli m a) Source # 

Associated Types

type PairObjects (Kleisli m a :: * -> * -> *) a b :: Constraint Source #

type UnitObject (Kleisli m a :: * -> * -> *) :: * Source #

Methods

swap :: (ObjectPair (Kleisli m a) a b, ObjectPair (Kleisli m a) b a) => Kleisli m a (a, b) (b, a) Source #

attachUnit :: ((* ~ u) (UnitObject (Kleisli m a)), ObjectPair (Kleisli m a) a u) => Kleisli m a a (a, u) Source #

detachUnit :: ((* ~ u) (UnitObject (Kleisli m a)), ObjectPair (Kleisli m a) a u) => Kleisli m a (a, u) a Source #

regroup :: (ObjectPair (Kleisli m a) a b, ObjectPair (Kleisli m a) b c, ObjectPair (Kleisli m a) a (b, c), ObjectPair (Kleisli m a) (a, b) c) => Kleisli m a (a, (b, c)) ((a, b), c) Source #

regroup' :: (ObjectPair (Kleisli m a) a b, ObjectPair (Kleisli m a) b c, ObjectPair (Kleisli m a) a (b, c), ObjectPair (Kleisli m a) (a, b) c) => Kleisli m a ((a, b), c) (a, (b, c)) Source #

type ObjectPair k a b = (Category k, Object k a, Object k b, PairObjects k a b, Object k (a, b)) Source #

Use this constraint to ensure that a, b and (a,b) are all "fully valid" objects of your category (meaning, you can use them with the Cartesian combinators).

class Cartesian k => Curry k where Source #

Minimal complete definition

uncurry, curry

Associated Types

type MorphObjects k b c :: Constraint Source #

Methods

uncurry :: (ObjectPair k a b, ObjectMorphism k b c) => k a (k b c) -> k (a, b) c Source #

curry :: (ObjectPair k a b, ObjectMorphism k b c) => k (a, b) c -> k a (k b c) Source #

apply :: (ObjectMorphism k a b, ObjectPair k (k a b) a) => k (k a b, a) b Source #

Instances

Curry ((->) LiftedRep LiftedRep) Source # 
(Curry f, o (UnitObject f)) => Curry (ConstrainedCategory f o) Source # 
(Monad m a, Arrow a ((->) LiftedRep LiftedRep), Function a) => Curry (Kleisli m a) Source # 

Associated Types

type MorphObjects (Kleisli m a :: * -> * -> *) b c :: Constraint Source #

Methods

uncurry :: (ObjectPair (Kleisli m a) a b, ObjectMorphism (Kleisli m a) b c) => Kleisli m a a (Kleisli m a b c) -> Kleisli m a (a, b) c Source #

curry :: (ObjectPair (Kleisli m a) a b, ObjectMorphism (Kleisli m a) b c) => Kleisli m a (a, b) c -> Kleisli m a a (Kleisli m a b c) Source #

apply :: (ObjectMorphism (Kleisli m a) a b, ObjectPair (Kleisli m a) (Kleisli m a a b) a) => Kleisli m a (Kleisli m a a b, a) b Source #

type ObjectMorphism k b c = (Object k b, Object k c, MorphObjects k b c, Object k (k b c)) Source #

Analogous to ObjectPair: express that k b c be an exponential object representing the morphism.

Monoidal with coproducts

class (Category k, Object k (ZeroObject k)) => CoCartesian k where Source #

Monoidal categories need not be based on a cartesian product. The relevant alternative is coproducts.

The dual notion to Cartesian replaces such products (pairs) with sums (Either), and unit '()' with void types.

Basically, the only thing that doesn't mirror Cartesian here is that we don't require CoMonoid (ZeroObject k). Comonoids do in principle make sense, but not from a Haskell viewpoint (every type is trivially a comonoid).

Haskell of course uses sum types, variants, most often without Either appearing. But variants are generally isomorphic to sums; the most important (sums of unit) are methods here.

Associated Types

type SumObjects k a b :: Constraint Source #

type ZeroObject k :: * Source #

Defaults to Void.

Methods

coSwap :: (ObjectSum k a b, ObjectSum k b a) => k (a + b) (b + a) Source #

attachZero :: (Object k a, z ~ ZeroObject k, ObjectSum k a z) => k a (a + z) Source #

detachZero :: (Object k a, z ~ ZeroObject k, ObjectSum k a z) => k (a + z) a Source #

coRegroup :: (Object k a, Object k c, ObjectSum k a b, ObjectSum k b c, ObjectSum k a (b + c), ObjectSum k (a + b) c) => k (a + (b + c)) ((a + b) + c) Source #

coRegroup' :: (Object k a, Object k c, ObjectSum k a b, ObjectSum k b c, ObjectSum k a (b + c), ObjectSum k (a + b) c) => k ((a + b) + c) (a + (b + c)) Source #

maybeAsSum :: (ObjectSum k u a, u ~ UnitObject k, Object k (Maybe a)) => k (Maybe a) (u + a) Source #

maybeFromSum :: (ObjectSum k u a, u ~ UnitObject k, Object k (Maybe a)) => k (u + a) (Maybe a) Source #

boolAsSum :: (ObjectSum k u u, u ~ UnitObject k, Object k Bool) => k Bool (u + u) Source #

boolFromSum :: (ObjectSum k u u, u ~ UnitObject k, Object k Bool) => k (u + u) Bool Source #

Instances

CoCartesian ((->) LiftedRep LiftedRep) Source # 

Associated Types

type SumObjects (LiftedRep -> LiftedRep :: * -> * -> *) a b :: Constraint Source #

type ZeroObject (LiftedRep -> LiftedRep :: * -> * -> *) :: * Source #

Methods

coSwap :: (ObjectSum (LiftedRep -> LiftedRep) a b, ObjectSum (LiftedRep -> LiftedRep) b a) => (LiftedRep -> LiftedRep) (a + b) (b + a) Source #

attachZero :: (Object (LiftedRep -> LiftedRep) a, (* ~ z) (ZeroObject (LiftedRep -> LiftedRep)), ObjectSum (LiftedRep -> LiftedRep) a z) => (LiftedRep -> LiftedRep) a (a + z) Source #

detachZero :: (Object (LiftedRep -> LiftedRep) a, (* ~ z) (ZeroObject (LiftedRep -> LiftedRep)), ObjectSum (LiftedRep -> LiftedRep) a z) => (LiftedRep -> LiftedRep) (a + z) a Source #

coRegroup :: (Object (LiftedRep -> LiftedRep) a, Object (LiftedRep -> LiftedRep) c, ObjectSum (LiftedRep -> LiftedRep) a b, ObjectSum (LiftedRep -> LiftedRep) b c, ObjectSum (LiftedRep -> LiftedRep) a (b + c), ObjectSum (LiftedRep -> LiftedRep) (a + b) c) => (LiftedRep -> LiftedRep) (a + (b + c)) ((a + b) + c) Source #

coRegroup' :: (Object (LiftedRep -> LiftedRep) a, Object (LiftedRep -> LiftedRep) c, ObjectSum (LiftedRep -> LiftedRep) a b, ObjectSum (LiftedRep -> LiftedRep) b c, ObjectSum (LiftedRep -> LiftedRep) a (b + c), ObjectSum (LiftedRep -> LiftedRep) (a + b) c) => (LiftedRep -> LiftedRep) ((a + b) + c) (a + (b + c)) Source #

maybeAsSum :: (ObjectSum (LiftedRep -> LiftedRep) u a, (* ~ u) (UnitObject (LiftedRep -> LiftedRep)), Object (LiftedRep -> LiftedRep) (Maybe a)) => (LiftedRep -> LiftedRep) (Maybe a) (u + a) Source #

maybeFromSum :: (ObjectSum (LiftedRep -> LiftedRep) u a, (* ~ u) (UnitObject (LiftedRep -> LiftedRep)), Object (LiftedRep -> LiftedRep) (Maybe a)) => (LiftedRep -> LiftedRep) (u + a) (Maybe a) Source #

boolAsSum :: (ObjectSum (LiftedRep -> LiftedRep) u u, (* ~ u) (UnitObject (LiftedRep -> LiftedRep)), Object (LiftedRep -> LiftedRep) Bool) => (LiftedRep -> LiftedRep) Bool (u + u) Source #

boolFromSum :: (ObjectSum (LiftedRep -> LiftedRep) u u, (* ~ u) (UnitObject (LiftedRep -> LiftedRep)), Object (LiftedRep -> LiftedRep) Bool) => (LiftedRep -> LiftedRep) (u + u) Bool Source #

(CoCartesian f, o (ZeroObject f)) => CoCartesian (ConstrainedCategory f o) Source # 

Associated Types

type SumObjects (ConstrainedCategory f o :: * -> * -> *) a b :: Constraint Source #

type ZeroObject (ConstrainedCategory f o :: * -> * -> *) :: * Source #

Methods

coSwap :: (ObjectSum (ConstrainedCategory f o) a b, ObjectSum (ConstrainedCategory f o) b a) => ConstrainedCategory f o (a + b) (b + a) Source #

attachZero :: (Object (ConstrainedCategory f o) a, (* ~ z) (ZeroObject (ConstrainedCategory f o)), ObjectSum (ConstrainedCategory f o) a z) => ConstrainedCategory f o a (a + z) Source #

detachZero :: (Object (ConstrainedCategory f o) a, (* ~ z) (ZeroObject (ConstrainedCategory f o)), ObjectSum (ConstrainedCategory f o) a z) => ConstrainedCategory f o (a + z) a Source #

coRegroup :: (Object (ConstrainedCategory f o) a, Object (ConstrainedCategory f o) c, ObjectSum (ConstrainedCategory f o) a b, ObjectSum (ConstrainedCategory f o) b c, ObjectSum (ConstrainedCategory f o) a (b + c), ObjectSum (ConstrainedCategory f o) (a + b) c) => ConstrainedCategory f o (a + (b + c)) ((a + b) + c) Source #

coRegroup' :: (Object (ConstrainedCategory f o) a, Object (ConstrainedCategory f o) c, ObjectSum (ConstrainedCategory f o) a b, ObjectSum (ConstrainedCategory f o) b c, ObjectSum (ConstrainedCategory f o) a (b + c), ObjectSum (ConstrainedCategory f o) (a + b) c) => ConstrainedCategory f o ((a + b) + c) (a + (b + c)) Source #

maybeAsSum :: (ObjectSum (ConstrainedCategory f o) u a, (* ~ u) (UnitObject (ConstrainedCategory f o)), Object (ConstrainedCategory f o) (Maybe a)) => ConstrainedCategory f o (Maybe a) (u + a) Source #

maybeFromSum :: (ObjectSum (ConstrainedCategory f o) u a, (* ~ u) (UnitObject (ConstrainedCategory f o)), Object (ConstrainedCategory f o) (Maybe a)) => ConstrainedCategory f o (u + a) (Maybe a) Source #

boolAsSum :: (ObjectSum (ConstrainedCategory f o) u u, (* ~ u) (UnitObject (ConstrainedCategory f o)), Object (ConstrainedCategory f o) Bool) => ConstrainedCategory f o Bool (u + u) Source #

boolFromSum :: (ObjectSum (ConstrainedCategory f o) u u, (* ~ u) (UnitObject (ConstrainedCategory f o)), Object (ConstrainedCategory f o) Bool) => ConstrainedCategory f o (u + u) Bool Source #

(Monad m k, CoCartesian k, Object k (m (ZeroObject k)), Object k (m (m (ZeroObject k)))) => CoCartesian (Kleisli m k) Source # 

Associated Types

type SumObjects (Kleisli m k :: * -> * -> *) a b :: Constraint Source #

type ZeroObject (Kleisli m k :: * -> * -> *) :: * Source #

Methods

coSwap :: (ObjectSum (Kleisli m k) a b, ObjectSum (Kleisli m k) b a) => Kleisli m k (a + b) (b + a) Source #

attachZero :: (Object (Kleisli m k) a, (* ~ z) (ZeroObject (Kleisli m k)), ObjectSum (Kleisli m k) a z) => Kleisli m k a (a + z) Source #

detachZero :: (Object (Kleisli m k) a, (* ~ z) (ZeroObject (Kleisli m k)), ObjectSum (Kleisli m k) a z) => Kleisli m k (a + z) a Source #

coRegroup :: (Object (Kleisli m k) a, Object (Kleisli m k) c, ObjectSum (Kleisli m k) a b, ObjectSum (Kleisli m k) b c, ObjectSum (Kleisli m k) a (b + c), ObjectSum (Kleisli m k) (a + b) c) => Kleisli m k (a + (b + c)) ((a + b) + c) Source #

coRegroup' :: (Object (Kleisli m k) a, Object (Kleisli m k) c, ObjectSum (Kleisli m k) a b, ObjectSum (Kleisli m k) b c, ObjectSum (Kleisli m k) a (b + c), ObjectSum (Kleisli m k) (a + b) c) => Kleisli m k ((a + b) + c) (a + (b + c)) Source #

maybeAsSum :: (ObjectSum (Kleisli m k) u a, (* ~ u) (UnitObject (Kleisli m k)), Object (Kleisli m k) (Maybe a)) => Kleisli m k (Maybe a) (u + a) Source #

maybeFromSum :: (ObjectSum (Kleisli m k) u a, (* ~ u) (UnitObject (Kleisli m k)), Object (Kleisli m k) (Maybe a)) => Kleisli m k (u + a) (Maybe a) Source #

boolAsSum :: (ObjectSum (Kleisli m k) u u, (* ~ u) (UnitObject (Kleisli m k)), Object (Kleisli m k) Bool) => Kleisli m k Bool (u + u) Source #

boolFromSum :: (ObjectSum (Kleisli m k) u u, (* ~ u) (UnitObject (Kleisli m k)), Object (Kleisli m k) Bool) => Kleisli m k (u + u) Bool Source #

type ObjectSum k a b = (Category k, Object k a, Object k b, SumObjects k a b, Object k (a + b)) Source #

Isomorphisms

class Category k => Isomorphic k a b where Source #

Apart from the identity morphism, id, there are other morphisms that can basically be considered identies. For instance, in any cartesian category (where it makes sense to have tuples and unit () at all), it should be possible to switch between a and the isomorphic (a, ()). iso is the method for such "pseudo-identities", the most basic of which are required as methods of the Cartesian class.

Why it is necessary to make these morphisms explicit: they are needed for a couple of general-purpose category-theory methods, but even though they're normally trivial to define there is no uniform way to do so. For instance, for vector spaces, the baseis of (a, (b,c)) and ((a,b), c) are sure enough structurally equivalent, but not in the same way the spaces themselves are (sum vs. product types).

Minimal complete definition

iso

Methods

iso :: k a b Source #

Deprecated: This generic method, while looking nicely uniform, relies on OverlappingInstances and is therefore probably a bad idea. Use the specialised methods in classes like SPDistribute instead.

Instances

(CoCartesian k, Object k a, (~) * u (ZeroObject k), ObjectSum k a u, ObjectSum k u a, Object k ((+) u a), Object k ((+) a u)) => Isomorphic k a ((+) u a) Source # 

Methods

iso :: k a (u + a) Source #

(CoCartesian k, Object k a, (~) * u (ZeroObject k), ObjectSum k a u) => Isomorphic k a ((+) a u) Source # 

Methods

iso :: k a (a + u) Source #

(Cartesian k, Object k a, (~) * u (UnitObject k), ObjectPair k a u, ObjectPair k u a, Object k (u, a), Object k (a, u)) => Isomorphic k a (u, a) Source # 

Methods

iso :: k a (u, a) Source #

(Cartesian k, Object k a, (~) * u (UnitObject k), ObjectPair k a u) => Isomorphic k a (a, u) Source # 

Methods

iso :: k a (a, u) Source #

(CoCartesian k, Object k a, (~) * u (ZeroObject k), ObjectSum k a u, ObjectSum k u a, Object k ((+) u a), Object k ((+) a u)) => Isomorphic k ((+) u a) a Source # 

Methods

iso :: k (u + a) a Source #

(CoCartesian k, Object k a, (~) * u (ZeroObject k), ObjectSum k a u) => Isomorphic k ((+) a u) a Source # 

Methods

iso :: k (a + u) a Source #

(Cartesian k, Object k a, (~) * u (UnitObject k), ObjectPair k a u, ObjectPair k u a, Object k (u, a), Object k (a, u)) => Isomorphic k (u, a) a Source # 

Methods

iso :: k (u, a) a Source #

(Cartesian k, Object k a, (~) * u (UnitObject k), ObjectPair k a u) => Isomorphic k (a, u) a Source # 

Methods

iso :: k (a, u) a Source #

(CoCartesian k, Object k a, ObjectSum k a b, ObjectSum k b c, ObjectSum k a ((+) b c), ObjectSum k ((+) a b) c, Object k c) => Isomorphic k ((+) ((+) a b) c) ((+) a ((+) b c)) Source # 

Methods

iso :: k ((a + b) + c) (a + (b + c)) Source #

(CoCartesian k, Object k a, ObjectSum k a b, ObjectSum k b c, ObjectSum k a ((+) b c), ObjectSum k ((+) a b) c, Object k c) => Isomorphic k ((+) a ((+) b c)) ((+) ((+) a b) c) Source # 

Methods

iso :: k (a + (b + c)) ((a + b) + c) Source #

(Cartesian k, Object k a, ObjectPair k a b, ObjectPair k b c, ObjectPair k a (b, c), ObjectPair k (a, b) c, Object k c) => Isomorphic k ((a, b), c) (a, (b, c)) Source # 

Methods

iso :: k ((a, b), c) (a, (b, c)) Source #

(Cartesian k, Object k a, ObjectPair k a b, ObjectPair k b c, ObjectPair k a (b, c), ObjectPair k (a, b) c, Object k c) => Isomorphic k (a, (b, c)) ((a, b), c) Source # 

Methods

iso :: k (a, (b, c)) ((a, b), c) Source #

Constraining a category

newtype ConstrainedCategory (k :: * -> * -> *) (o :: * -> Constraint) (a :: *) (b :: *) Source #

A given category can be specialised, by using the same morphisms but adding extra constraints to what is considered an object.

For instance, ConstrainedCategory (->) Ord is the category of all totally ordered data types (but with arbitrary functions; this does not require monotonicity or anything).

Constructors

ConstrainedMorphism (k a b) 

Instances

(o (), o [()], o Void, o [Void]) => SumToProduct [] (ConstrainedCategory ((->) LiftedRep LiftedRep) o) (ConstrainedCategory ((->) LiftedRep LiftedRep) o) Source # 
(Functor [] k k, o [UnitObject k]) => Functor [] (ConstrainedCategory k o) (ConstrainedCategory k o) Source # 
(Foldable f s t, WellPointed s, WellPointed t, Functor f (ConstrainedCategory s o) (ConstrainedCategory t o)) => Foldable f (ConstrainedCategory s o) (ConstrainedCategory t o) Source # 
EnhancedCat (Discrete *) f => EnhancedCat (Discrete *) (ConstrainedCategory f o) Source # 
(Curry f, o (UnitObject f)) => Curry (ConstrainedCategory f o) Source # 
(CoCartesian f, o (ZeroObject f)) => CoCartesian (ConstrainedCategory f o) Source # 

Associated Types

type SumObjects (ConstrainedCategory f o :: * -> * -> *) a b :: Constraint Source #

type ZeroObject (ConstrainedCategory f o :: * -> * -> *) :: * Source #

Methods

coSwap :: (ObjectSum (ConstrainedCategory f o) a b, ObjectSum (ConstrainedCategory f o) b a) => ConstrainedCategory f o (a + b) (b + a) Source #

attachZero :: (Object (ConstrainedCategory f o) a, (* ~ z) (ZeroObject (ConstrainedCategory f o)), ObjectSum (ConstrainedCategory f o) a z) => ConstrainedCategory f o a (a + z) Source #

detachZero :: (Object (ConstrainedCategory f o) a, (* ~ z) (ZeroObject (ConstrainedCategory f o)), ObjectSum (ConstrainedCategory f o) a z) => ConstrainedCategory f o (a + z) a Source #

coRegroup :: (Object (ConstrainedCategory f o) a, Object (ConstrainedCategory f o) c, ObjectSum (ConstrainedCategory f o) a b, ObjectSum (ConstrainedCategory f o) b c, ObjectSum (ConstrainedCategory f o) a (b + c), ObjectSum (ConstrainedCategory f o) (a + b) c) => ConstrainedCategory f o (a + (b + c)) ((a + b) + c) Source #

coRegroup' :: (Object (ConstrainedCategory f o) a, Object (ConstrainedCategory f o) c, ObjectSum (ConstrainedCategory f o) a b, ObjectSum (ConstrainedCategory f o) b c, ObjectSum (ConstrainedCategory f o) a (b + c), ObjectSum (ConstrainedCategory f o) (a + b) c) => ConstrainedCategory f o ((a + b) + c) (a + (b + c)) Source #

maybeAsSum :: (ObjectSum (ConstrainedCategory f o) u a, (* ~ u) (UnitObject (ConstrainedCategory f o)), Object (ConstrainedCategory f o) (Maybe a)) => ConstrainedCategory f o (Maybe a) (u + a) Source #

maybeFromSum :: (ObjectSum (ConstrainedCategory f o) u a, (* ~ u) (UnitObject (ConstrainedCategory f o)), Object (ConstrainedCategory f o) (Maybe a)) => ConstrainedCategory f o (u + a) (Maybe a) Source #

boolAsSum :: (ObjectSum (ConstrainedCategory f o) u u, (* ~ u) (UnitObject (ConstrainedCategory f o)), Object (ConstrainedCategory f o) Bool) => ConstrainedCategory f o Bool (u + u) Source #

boolFromSum :: (ObjectSum (ConstrainedCategory f o) u u, (* ~ u) (UnitObject (ConstrainedCategory f o)), Object (ConstrainedCategory f o) Bool) => ConstrainedCategory f o (u + u) Bool Source #

(Cartesian f, o (UnitObject f)) => Cartesian (ConstrainedCategory f o) Source # 

Associated Types

type PairObjects (ConstrainedCategory f o :: * -> * -> *) a b :: Constraint Source #

type UnitObject (ConstrainedCategory f o :: * -> * -> *) :: * Source #

Category k => Category (ConstrainedCategory k isObj) Source # 

Associated Types

type Object (ConstrainedCategory k isObj :: * -> * -> *) o :: Constraint Source #

Methods

id :: Object (ConstrainedCategory k isObj) a => ConstrainedCategory k isObj a a Source #

(.) :: (Object (ConstrainedCategory k isObj) a, Object (ConstrainedCategory k isObj) b, Object (ConstrainedCategory k isObj) c) => ConstrainedCategory k isObj b c -> ConstrainedCategory k isObj a b -> ConstrainedCategory k isObj a c Source #

(WellPointed a, o (UnitObject a)) => WellPointed (ConstrainedCategory a o) Source # 
(SPDistribute k, o (ZeroObject k), o (UnitObject k)) => SPDistribute (ConstrainedCategory k o) Source # 
(PreArrChoice k, o (ZeroObject k)) => PreArrChoice (ConstrainedCategory k o) Source # 
(PreArrow a, o (UnitObject a)) => PreArrow (ConstrainedCategory a o) Source # 
(MorphChoice k, o (ZeroObject k)) => MorphChoice (ConstrainedCategory k o) Source # 
(Morphism a, o (UnitObject a)) => Morphism (ConstrainedCategory a o) Source # 
(EnhancedCat a k, o (UnitObject a)) => EnhancedCat (ConstrainedCategory a o) k Source # 

Methods

arr :: (Object k b, Object k c, Object (ConstrainedCategory a o) b, Object (ConstrainedCategory a o) c) => k b c -> ConstrainedCategory a o b c Source #

Category f => EnhancedCat (ConstrainedCategory f o) (Discrete *) Source # 
Function f => EnhancedCat ((->) LiftedRep LiftedRep) (ConstrainedCategory f o) Source # 
type ZeroObject (ConstrainedCategory f o) Source # 
type UnitObject (ConstrainedCategory f o) Source # 
type Object (ConstrainedCategory k isObj) o Source # 
type Object (ConstrainedCategory k isObj) o = (Object k o, isObj o)
type PointObject (ConstrainedCategory a o) x Source # 
type MorphObjects (ConstrainedCategory f o) a c Source # 
type MorphObjects (ConstrainedCategory f o) a c = (MorphObjects f a c, (~) (* -> * -> *) f ((->) LiftedRep LiftedRep))
type SumObjects (ConstrainedCategory f o) a b Source # 
type PairObjects (ConstrainedCategory f o) a b Source # 

constrained :: (Category k, o a, o b) => k a b -> ConstrainedCategory k o a b Source #

Cast a morphism to its equivalent in a more constrained category, provided it connects objects that actually satisfy the extra constraint.

unconstrained :: Category k => ConstrainedCategory k o a b -> k a b Source #

"Unpack" a constrained morphism again (forgetful functor).

Note that you may often not need to do that; in particular morphisms that are actually Functions can just be applied to their objects with $ right away, no need to go back to Hask first.

Global-element proxies

class Category k => HasAgent k where Source #

An agent value is a "general representation" of a category's values, i.e. global elements. This is useful to define certain morphisms (including ones that can't just "inherit" from '->' with arr) in ways other than point-free composition pipelines. Instead, you can write algebraic expressions much as if dealing with actual values of your category's objects, but using the agent type which is restricted so any function defined as such a lambda-expression qualifies as a morphism of that category.

Minimal complete definition

alg, ($~)

Associated Types

type AgentVal k a v :: * Source #

Methods

alg :: (Object k a, Object k b) => (forall q. Object k q => AgentVal k q a -> AgentVal k q b) -> k a b Source #

($~) :: (Object k a, Object k b, Object k c) => k b c -> AgentVal k a b -> AgentVal k a c infixr 0 Source #

Instances

HasAgent (Discrete *) Source # 

Associated Types

type AgentVal (Discrete * :: * -> * -> *) a v :: * Source #

Methods

alg :: (Object (Discrete *) a, Object (Discrete *) b) => (forall q. Object (Discrete *) q => AgentVal (Discrete *) q a -> AgentVal (Discrete *) q b) -> Discrete * a b Source #

($~) :: (Object (Discrete *) a, Object (Discrete *) b, Object (Discrete *) c) => Discrete * b c -> AgentVal (Discrete *) a b -> AgentVal (Discrete *) a c Source #

(HasAgent k, WellPointed k) => HasAgent (ReWellPointed k) Source # 

Associated Types

type AgentVal (ReWellPointed k :: * -> * -> *) a v :: * Source #

(HasAgent k, PreArrow k) => HasAgent (RePreArrow k) Source # 

Associated Types

type AgentVal (RePreArrow k :: * -> * -> *) a v :: * Source #

Methods

alg :: (Object (RePreArrow k) a, Object (RePreArrow k) b) => (forall q. Object (RePreArrow k) q => AgentVal (RePreArrow k) q a -> AgentVal (RePreArrow k) q b) -> RePreArrow k a b Source #

($~) :: (Object (RePreArrow k) a, Object (RePreArrow k) b, Object (RePreArrow k) c) => RePreArrow k b c -> AgentVal (RePreArrow k) a b -> AgentVal (RePreArrow k) a c Source #

(HasAgent k, Morphism k) => HasAgent (ReMorphism k) Source # 

Associated Types

type AgentVal (ReMorphism k :: * -> * -> *) a v :: * Source #

Methods

alg :: (Object (ReMorphism k) a, Object (ReMorphism k) b) => (forall q. Object (ReMorphism k) q => AgentVal (ReMorphism k) q a -> AgentVal (ReMorphism k) q b) -> ReMorphism k a b Source #

($~) :: (Object (ReMorphism k) a, Object (ReMorphism k) b, Object (ReMorphism k) c) => ReMorphism k b c -> AgentVal (ReMorphism k) a b -> AgentVal (ReMorphism k) a c Source #

(HasAgent k, Cartesian k) => HasAgent (ReCartesian k) Source # 

Associated Types

type AgentVal (ReCartesian k :: * -> * -> *) a v :: * Source #

Methods

alg :: (Object (ReCartesian k) a, Object (ReCartesian k) b) => (forall q. Object (ReCartesian k) q => AgentVal (ReCartesian k) q a -> AgentVal (ReCartesian k) q b) -> ReCartesian k a b Source #

($~) :: (Object (ReCartesian k) a, Object (ReCartesian k) b, Object (ReCartesian k) c) => ReCartesian k b c -> AgentVal (ReCartesian k) a b -> AgentVal (ReCartesian k) a c Source #

HasAgent k => HasAgent (ReCategory k) Source # 

Associated Types

type AgentVal (ReCategory k :: * -> * -> *) a v :: * Source #

Methods

alg :: (Object (ReCategory k) a, Object (ReCategory k) b) => (forall q. Object (ReCategory k) q => AgentVal (ReCategory k) q a -> AgentVal (ReCategory k) q b) -> ReCategory k a b Source #

($~) :: (Object (ReCategory k) a, Object (ReCategory k) b, Object (ReCategory k) c) => ReCategory k b c -> AgentVal (ReCategory k) a b -> AgentVal (ReCategory k) a c Source #

HasAgent ((->) LiftedRep LiftedRep) Source # 

Associated Types

type AgentVal (LiftedRep -> LiftedRep :: * -> * -> *) a v :: * Source #

genericAlg :: (HasAgent k, Object k a, Object k b) => (forall q. Object k q => GenericAgent k q a -> GenericAgent k q b) -> k a b Source #

genericAgentMap :: (HasAgent k, Object k a, Object k b, Object k c) => k b c -> GenericAgent k a b -> GenericAgent k a c Source #

data GenericAgent k a v Source #

Constructors

GenericAgent 

Fields

Utility

inCategoryOf :: Category k => k a b -> k c d -> k a b Source #

Analogue to asTypeOf, this does not actually do anything but can give the compiler type unification hints in a convenient manner.

type CatTagged k x = Tagged (k (UnitObject k) (UnitObject k)) x Source #

Tagged type for values that depend on some choice of category, but not on some particular object / arrow therein.