constrained-categories-0.4.1.0: Constrained clones of the category-theory type classes, using ConstraintKinds.
Copyright(c) 2013 Justus Sagemüller
LicenseGPL v3 (see COPYING)
Maintainer(@) jsag $ hvl.no
Safe HaskellTrustworthy
LanguageHaskell2010

Control.Arrow.Constrained

Description

Haskell's Arrows, going back to [Hughes 2000], combine multiple ideas from category theory:

  • They expand upon cartesian categories, by offering ways to combine arrows between simple objects to composite ones working on tuples (i.e. products) thereof.
  • They constitute a "profunctor" interface, allowing to "fmap" both covariantly over the second parameter, as well as contravariantly over the first. As in case of Control.Functor.Constrained, we wish the underlying category to fmap from not to be limited to Hask, so Arrow also has an extra parameter.

To facilitate these somewhat divergent needs, Arrow is split up in three classes. These do not even form an ordinary hierarchy, to allow categories to implement only one or the other aspect.

That's not the only significant difference of this module, compared to Control.Arrow:

  • Kleisli arrows are not defined here, but in Control.Monad.Constrained. Monads are really a much more specific concept than category arrows.
  • Some extra utilities are included that don't apparently have much to do with Arrow at all, but require the expanded cartesian-category tools and are therefore not in Control.Category.Constrained.
Synopsis

The Arrow type classes

type Arrow a k = (WellPointed a, EnhancedCat a k) Source #

class Cartesian a => Morphism a where Source #

Minimal complete definition

(***)

Methods

first :: (ObjectPair a b d, ObjectPair a c d) => a b c -> a (b, d) (c, d) Source #

second :: (ObjectPair a d b, ObjectPair a d c) => a b c -> a (d, b) (d, c) Source #

(***) :: (ObjectPair a b b', ObjectPair a c c') => a b c -> a b' c' -> a (b, b') (c, c') infixr 3 Source #

Instances

Instances details
Morphism Op Source # 
Instance details

Defined in Control.Arrow.Constrained

Methods

first :: (ObjectPair Op b d, ObjectPair Op c d) => Op b c -> Op (b, d) (c, d) Source #

second :: (ObjectPair Op d b, ObjectPair Op d c) => Op b c -> Op (d, b) (d, c) Source #

(***) :: (ObjectPair Op b b', ObjectPair Op c c') => Op b c -> Op b' c' -> Op (b, b') (c, c') Source #

WellPointed k => Morphism (ReWellPointed k) Source # 
Instance details

Defined in Control.Category.Constrained.Reified

Methods

first :: (ObjectPair (ReWellPointed k) b d, ObjectPair (ReWellPointed k) c d) => ReWellPointed k b c -> ReWellPointed k (b, d) (c, d) Source #

second :: (ObjectPair (ReWellPointed k) d b, ObjectPair (ReWellPointed k) d c) => ReWellPointed k b c -> ReWellPointed k (d, b) (d, c) Source #

(***) :: (ObjectPair (ReWellPointed k) b b', ObjectPair (ReWellPointed k) c c') => ReWellPointed k b c -> ReWellPointed k b' c' -> ReWellPointed k (b, b') (c, c') Source #

PreArrow k => Morphism (RePreArrow k) Source # 
Instance details

Defined in Control.Category.Constrained.Reified

Methods

first :: (ObjectPair (RePreArrow k) b d, ObjectPair (RePreArrow k) c d) => RePreArrow k b c -> RePreArrow k (b, d) (c, d) Source #

second :: (ObjectPair (RePreArrow k) d b, ObjectPair (RePreArrow k) d c) => RePreArrow k b c -> RePreArrow k (d, b) (d, c) Source #

(***) :: (ObjectPair (RePreArrow k) b b', ObjectPair (RePreArrow k) c c') => RePreArrow k b c -> RePreArrow k b' c' -> RePreArrow k (b, b') (c, c') Source #

Morphism k => Morphism (ReMorphism k) Source # 
Instance details

Defined in Control.Category.Constrained.Reified

Methods

first :: (ObjectPair (ReMorphism k) b d, ObjectPair (ReMorphism k) c d) => ReMorphism k b c -> ReMorphism k (b, d) (c, d) Source #

second :: (ObjectPair (ReMorphism k) d b, ObjectPair (ReMorphism k) d c) => ReMorphism k b c -> ReMorphism k (d, b) (d, c) Source #

(***) :: (ObjectPair (ReMorphism k) b b', ObjectPair (ReMorphism k) c c') => ReMorphism k b c -> ReMorphism k b' c' -> ReMorphism k (b, b') (c, c') Source #

Morphism ((->) :: Type -> Type -> Type) Source # 
Instance details

Defined in Control.Arrow.Constrained

Methods

first :: (ObjectPair (->) b d, ObjectPair (->) c d) => (b -> c) -> (b, d) -> (c, d) Source #

second :: (ObjectPair (->) d b, ObjectPair (->) d c) => (b -> c) -> (d, b) -> (d, c) Source #

(***) :: (ObjectPair (->) b b', ObjectPair (->) c c') => (b -> c) -> (b' -> c') -> (b, b') -> (c, c') Source #

(Morphism a, o (UnitObject a)) => Morphism (o a) Source # 
Instance details

Defined in Control.Arrow.Constrained

Methods

first :: (ObjectPair (o a) b d, ObjectPair (o a) c d) => (o a) b c -> (o a) (b, d) (c, d) Source #

second :: (ObjectPair (o a) d b, ObjectPair (o a) d c) => (o a) b c -> (o a) (d, b) (d, c) Source #

(***) :: (ObjectPair (o a) b b', ObjectPair (o a) c c') => (o a) b c -> (o a) b' c' -> (o a) (b, b') (c, c') Source #

(Monad m a, Morphism a, Curry a) => Morphism (Kleisli m a) Source # 
Instance details

Defined in Control.Monad.Constrained

Methods

first :: (ObjectPair (Kleisli m a) b d, ObjectPair (Kleisli m a) c d) => Kleisli m a b c -> Kleisli m a (b, d) (c, d) Source #

second :: (ObjectPair (Kleisli m a) d b, ObjectPair (Kleisli m a) d c) => Kleisli m a b c -> Kleisli m a (d, b) (d, c) Source #

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

class Morphism a => PreArrow a where Source #

Unlike first, second, *** and arr, the fanout operation &&& has an intrinsic notion of "direction": it is basically equivalent to precomposing the result of *** with a b -> (b,b), but that is only available for arrows that generalise ordinary functions, in their native direction. ((b,b) ->b is specific to semigroups.) It is for this reason the only constituent class of Arrow that actually has "arrow" in its name.

In terms of category theory, this "direction" reflects the distinction between initial- and terminal objects. The latter are more interesting, basically what UnitObject is useful for. It gives rise to the tuple selector morphisms as well.

Methods

(&&&) :: (Object a b, ObjectPair a c c') => a b c -> a b c' -> a b (c, c') infixr 3 Source #

terminal :: Object a b => a b (UnitObject a) Source #

fst :: ObjectPair a x y => a (x, y) x Source #

snd :: ObjectPair a x y => a (x, y) y Source #

Instances

Instances details
WellPointed k => PreArrow (ReWellPointed k) Source # 
Instance details

Defined in Control.Category.Constrained.Reified

PreArrow k => PreArrow (RePreArrow k) Source # 
Instance details

Defined in Control.Category.Constrained.Reified

Methods

(&&&) :: (Object (RePreArrow k) b, ObjectPair (RePreArrow k) c c') => RePreArrow k b c -> RePreArrow k b c' -> RePreArrow k b (c, c') Source #

terminal :: Object (RePreArrow k) b => RePreArrow k b (UnitObject (RePreArrow k)) Source #

fst :: ObjectPair (RePreArrow k) x y => RePreArrow k (x, y) x Source #

snd :: ObjectPair (RePreArrow k) x y => RePreArrow k (x, y) y Source #

PreArrow ((->) :: Type -> Type -> Type) Source # 
Instance details

Defined in Control.Arrow.Constrained

Methods

(&&&) :: (Object (->) b, ObjectPair (->) c c') => (b -> c) -> (b -> c') -> b -> (c, c') Source #

terminal :: Object (->) b => b -> UnitObject (->) Source #

fst :: ObjectPair (->) x y => (x, y) -> x Source #

snd :: ObjectPair (->) x y => (x, y) -> y Source #

(PreArrow a, o (UnitObject a)) => PreArrow (o a) Source # 
Instance details

Defined in Control.Arrow.Constrained

Methods

(&&&) :: (Object (o a) b, ObjectPair (o a) c c') => (o a) b c -> (o a) b c' -> (o a) b (c, c') Source #

terminal :: Object (o a) b => (o a) b (UnitObject (o a)) Source #

fst :: ObjectPair (o a) x y => (o a) (x, y) x Source #

snd :: ObjectPair (o a) x y => (o a) (x, y) y Source #

(Monad m a, PreArrow a, Curry a) => PreArrow (Kleisli m a) Source # 
Instance details

Defined in Control.Monad.Constrained

Methods

(&&&) :: (Object (Kleisli m a) b, ObjectPair (Kleisli m a) c c') => Kleisli m a b c -> Kleisli m a b c' -> Kleisli m a b (c, c') Source #

terminal :: Object (Kleisli m a) b => Kleisli m a b (UnitObject (Kleisli m a)) Source #

fst :: ObjectPair (Kleisli m a) x y => Kleisli m a (x, y) x Source #

snd :: ObjectPair (Kleisli m a) x y => Kleisli m a (x, y) y Source #

class (PreArrow a, ObjectPoint a (UnitObject a)) => WellPointed a where Source #

WellPointed expresses the relation between your category's objects and the values of the Haskell data types (which is, after all, what objects are in this library). Specifically, this class allows you to "point" on specific objects, thus making out a value of that type as a point of the object.

Perhaps easier than thinking about what that's supposed to mean is noting this class contains const. Thus WellPointed is almost the traditional Arrow: it lets you express all the natural transformations and inject constant values, only you can't just promote arbitrary functions to arrows of the category.

Unlike with Morphism and PreArrow, a literal dual of WellPointed does not seem useful.

Minimal complete definition

unit, (globalElement | const)

Associated Types

type PointObject a x :: Constraint Source #

type PointObject a x = ()

Methods

globalElement :: ObjectPoint a x => x -> a (UnitObject a) x Source #

unit :: CatTagged a (UnitObject a) Source #

const :: (Object a b, ObjectPoint a x) => x -> a b x Source #

Instances

Instances details
WellPointed k => WellPointed (ReWellPointed k) Source # 
Instance details

Defined in Control.Category.Constrained.Reified

Associated Types

type PointObject (ReWellPointed k) x Source #

WellPointed ((->) :: Type -> Type -> Type) Source # 
Instance details

Defined in Control.Arrow.Constrained

Associated Types

type PointObject (->) x Source #

Methods

globalElement :: ObjectPoint (->) x => x -> UnitObject (->) -> x Source #

unit :: CatTagged (->) (UnitObject (->)) Source #

const :: (Object (->) b, ObjectPoint (->) x) => x -> b -> x Source #

(WellPointed a, o (UnitObject a)) => WellPointed (o a) Source # 
Instance details

Defined in Control.Arrow.Constrained

Associated Types

type PointObject (o a) x Source #

Methods

globalElement :: ObjectPoint (o a) x => x -> (o a) (UnitObject (o a)) x Source #

unit :: CatTagged (o a) (UnitObject (o a)) Source #

const :: (Object (o a) b, ObjectPoint (o a) x) => x -> (o a) b x Source #

(Monad m a, WellPointed a, ObjectPoint a (m (UnitObject a))) => WellPointed (Kleisli m a) Source # 
Instance details

Defined in Control.Monad.Constrained

Associated Types

type PointObject (Kleisli m a) x Source #

Methods

globalElement :: ObjectPoint (Kleisli m a) x => x -> Kleisli m a (UnitObject (Kleisli m a)) x Source #

unit :: CatTagged (Kleisli m a) (UnitObject (Kleisli m a)) Source #

const :: (Object (Kleisli m a) b, ObjectPoint (Kleisli m a) x) => x -> Kleisli m a b x Source #

type ObjectPoint k a = (Object k a, PointObject k a) Source #

class (Category a, Category k) => EnhancedCat a k where Source #

EnhancedCat a k means that the subcategory of k whose objects are also objects of a is a subcategory of a. This works like EnhancedCat', but does not require Object k ⊆ Object a.

Methods

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

Instances

Instances details
Category k => EnhancedCat k k Source # 
Instance details

Defined in Control.Arrow.Constrained

Methods

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

WellPointed k => EnhancedCat (ReWellPointed k) k Source # 
Instance details

Defined in Control.Category.Constrained.Reified

Methods

arr :: (Object k b, Object k c, Object (ReWellPointed k) b, Object (ReWellPointed k) c) => k b c -> ReWellPointed k b c Source #

PreArrow k => EnhancedCat (RePreArrow k) k Source # 
Instance details

Defined in Control.Category.Constrained.Reified

Methods

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

Morphism k => EnhancedCat (ReMorphism k) k Source # 
Instance details

Defined in Control.Category.Constrained.Reified

Methods

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

Cartesian k => EnhancedCat (ReCartesian k) k Source # 
Instance details

Defined in Control.Category.Constrained.Reified

Methods

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

Category k => EnhancedCat (ReCategory k) k Source # 
Instance details

Defined in Control.Category.Constrained.Reified

Methods

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

EnhancedCat (Coercion :: Type -> Type -> Type) (Discrete :: Type -> Type -> Type) Source # 
Instance details

Defined in Control.Arrow.Constrained

EnhancedCat (Discrete :: Type -> Type -> Type) f => EnhancedCat (Discrete :: Type -> Type -> Type) (o f) Source # 
Instance details

Defined in Control.Arrow.Constrained

Methods

arr :: (Object (o f) b, Object (o f) c, Object Discrete b, Object Discrete c) => (o f) b c -> Discrete b c Source #

(EnhancedCat a k, o (UnitObject a)) => EnhancedCat (o a) k Source # 
Instance details

Defined in Control.Arrow.Constrained

Methods

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

(Monad m a, Arrow a q, Cartesian a) => EnhancedCat (Kleisli m a) q Source # 
Instance details

Defined in Control.Monad.Constrained

Methods

arr :: (Object q b, Object q c, Object (Kleisli m a) b, Object (Kleisli m a) c) => q b c -> Kleisli m a b c Source #

EnhancedCat ((->) :: Type -> Type -> Type) (Coercion :: Type -> Type -> Type) Source # 
Instance details

Defined in Control.Arrow.Constrained

Methods

arr :: (Object Coercion b, Object Coercion c, Object (->) b, Object (->) c) => Coercion b c -> b -> c Source #

EnhancedCat ((->) :: Type -> Type -> Type) (Discrete :: Type -> Type -> Type) Source # 
Instance details

Defined in Control.Arrow.Constrained

Methods

arr :: (Object Discrete b, Object Discrete c, Object (->) b, Object (->) c) => Discrete b c -> b -> c Source #

Category f => EnhancedCat (o f) (Discrete :: Type -> Type -> Type) Source # 
Instance details

Defined in Control.Arrow.Constrained

Methods

arr :: (Object Discrete b, Object Discrete c, Object (o f) b, Object (o f) c) => Discrete b c -> (o f) b c Source #

Function f => EnhancedCat ((->) :: Type -> Type -> Type) (o f) Source # 
Instance details

Defined in Control.Arrow.Constrained

Methods

arr :: (Object (o f) b, Object (o f) c, Object (->) b, Object (->) c) => (o f) b c -> b -> c Source #

Dual / "choice" arrows

class CoCartesian a => MorphChoice a where Source #

Dual to Morphism, dealing with sums instead of products.

Minimal complete definition

(+++)

Methods

left :: (ObjectSum a b d, ObjectSum a c d) => a b c -> a (b + d) (c + d) Source #

right :: (ObjectSum a d b, ObjectSum a d c) => a b c -> a (d + b) (d + c) Source #

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

Instances

Instances details
MorphChoice Op Source # 
Instance details

Defined in Control.Arrow.Constrained

Methods

left :: (ObjectSum Op b d, ObjectSum Op c d) => Op b c -> Op (b + d) (c + d) Source #

right :: (ObjectSum Op d b, ObjectSum Op d c) => Op b c -> Op (d + b) (d + c) Source #

(+++) :: (ObjectSum Op b b', ObjectSum Op c c') => Op b c -> Op b' c' -> Op (b + b') (c + c') Source #

MorphChoice ((->) :: Type -> Type -> Type) Source # 
Instance details

Defined in Control.Arrow.Constrained

Methods

left :: (ObjectSum (->) b d, ObjectSum (->) c d) => (b -> c) -> (b + d) -> (c + d) Source #

right :: (ObjectSum (->) d b, ObjectSum (->) d c) => (b -> c) -> (d + b) -> (d + c) Source #

(+++) :: (ObjectSum (->) b b', ObjectSum (->) c c') => (b -> c) -> (b' -> c') -> (b + b') -> (c + c') Source #

(MorphChoice k, o (ZeroObject k)) => MorphChoice (o k) Source # 
Instance details

Defined in Control.Arrow.Constrained

Methods

left :: (ObjectSum (o k) b d, ObjectSum (o k) c d) => (o k) b c -> (o k) (b + d) (c + d) Source #

right :: (ObjectSum (o k) d b, ObjectSum (o k) d c) => (o k) b c -> (o k) (d + b) (d + c) Source #

(+++) :: (ObjectSum (o k) b b', ObjectSum (o k) c c') => (o k) b c -> (o k) b' c' -> (o k) (b + b') (c + c') Source #

(Monad m k, Arrow k ((->) :: Type -> Type -> Type), Function k, PreArrChoice k, Object k (m (ZeroObject k)), Object k (m (m (ZeroObject k)))) => MorphChoice (Kleisli m k) Source #

Hask-Kleislis inherit more or less trivially ArrowChoice; however this does not generalise greatly well to non-function categories.

Instance details

Defined in Control.Monad.Constrained

Methods

left :: (ObjectSum (Kleisli m k) b d, ObjectSum (Kleisli m k) c d) => Kleisli m k b c -> Kleisli m k (b + d) (c + d) Source #

right :: (ObjectSum (Kleisli m k) d b, ObjectSum (Kleisli m k) d c) => Kleisli m k b c -> Kleisli m k (d + b) (d + c) Source #

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

class MorphChoice k => PreArrChoice k where Source #

Dual to PreArrow, this class deals with the vacuous initial (zero) objects, but also more usefully with choices / sums. This represents the most part of ArrowChoice.

Methods

(|||) :: (ObjectSum k b b', Object k c) => k b c -> k b' c -> k (b + b') c infixr 2 Source #

initial :: Object k b => k (ZeroObject k) b Source #

This is basically absurd.

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

Perhaps lft and rgt would be more consequent names, but likely more confusing as well.

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

Instances

Instances details
PreArrChoice ((->) :: Type -> Type -> Type) Source # 
Instance details

Defined in Control.Arrow.Constrained

Methods

(|||) :: (ObjectSum (->) b b', Object (->) c) => (b -> c) -> (b' -> c) -> (b + b') -> c Source #

initial :: Object (->) b => ZeroObject (->) -> b Source #

coFst :: ObjectSum (->) a b => a -> (a + b) Source #

coSnd :: ObjectSum (->) a b => b -> (a + b) Source #

(PreArrChoice k, o (ZeroObject k)) => PreArrChoice (o k) Source # 
Instance details

Defined in Control.Arrow.Constrained

Methods

(|||) :: (ObjectSum (o k) b b', Object (o k) c) => (o k) b c -> (o k) b' c -> (o k) (b + b') c Source #

initial :: Object (o k) b => (o k) (ZeroObject (o k)) b Source #

coFst :: ObjectSum (o k) a b => (o k) a (a + b) Source #

coSnd :: ObjectSum (o k) a b => (o k) b (a + b) Source #

(Monad m k, Arrow k ((->) :: Type -> Type -> Type), Function k, PreArrChoice k, Object k (m (ZeroObject k)), Object k (m (m (ZeroObject k)))) => PreArrChoice (Kleisli m k) Source # 
Instance details

Defined in Control.Monad.Constrained

Methods

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

initial :: Object (Kleisli m k) b => Kleisli m k (ZeroObject (Kleisli m k)) b Source #

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

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

Distributive law between sum- and product objects

class (PreArrow k, PreArrChoice k) => SPDistribute k where Source #

Like in arithmetics, the distributive law a ⋅ (b + c) ≈ (a ⋅ b) + (a ⋅ c) holds for Haskell types – in the usual isomorphism sense. But like many such isomorphisms that are trivial to inline in Hask, this is not necessarily the case for general categories.

Methods

distribute :: (ObjectSum k (a, b) (a, c), ObjectPair k a (b + c), ObjectSum k b c, PairObjects k a b, PairObjects k a c) => k (a, b + c) ((a, b) + (a, c)) Source #

unDistribute :: (ObjectSum k (a, b) (a, c), ObjectPair k a (b + c), ObjectSum k b c, PairObjects k a b, PairObjects k a c) => k ((a, b) + (a, c)) (a, b + c) Source #

boolAsSwitch :: (ObjectSum k a a, ObjectPair k Bool a) => k (Bool, a) (a + a) Source #

boolFromSwitch :: (ObjectSum k a a, ObjectPair k Bool a) => k (a + a) (Bool, a) Source #

Instances

Instances details
SPDistribute ((->) :: Type -> Type -> Type) Source # 
Instance details

Defined in Control.Arrow.Constrained

Methods

distribute :: (ObjectSum (->) (a, b) (a, c), ObjectPair (->) a (b + c), ObjectSum (->) b c, PairObjects (->) a b, PairObjects (->) a c) => (a, b + c) -> ((a, b) + (a, c)) Source #

unDistribute :: (ObjectSum (->) (a, b) (a, c), ObjectPair (->) a (b + c), ObjectSum (->) b c, PairObjects (->) a b, PairObjects (->) a c) => ((a, b) + (a, c)) -> (a, b + c) Source #

boolAsSwitch :: (ObjectSum (->) a a, ObjectPair (->) Bool a) => (Bool, a) -> (a + a) Source #

boolFromSwitch :: (ObjectSum (->) a a, ObjectPair (->) Bool a) => (a + a) -> (Bool, a) Source #

(SPDistribute k, o (ZeroObject k), o (UnitObject k)) => SPDistribute (o k) Source # 
Instance details

Defined in Control.Arrow.Constrained

Methods

distribute :: (ObjectSum (o k) (a, b) (a, c), ObjectPair (o k) a (b + c), ObjectSum (o k) b c, PairObjects (o k) a b, PairObjects (o k) a c) => (o k) (a, b + c) ((a, b) + (a, c)) Source #

unDistribute :: (ObjectSum (o k) (a, b) (a, c), ObjectPair (o k) a (b + c), ObjectSum (o k) b c, PairObjects (o k) a b, PairObjects (o k) a c) => (o k) ((a, b) + (a, c)) (a, b + c) Source #

boolAsSwitch :: (ObjectSum (o k) a a, ObjectPair (o k) Bool a) => (o k) (Bool, a) (a + a) Source #

boolFromSwitch :: (ObjectSum (o k) a a, ObjectPair (o k) Bool a) => (o k) (a + a) (Bool, a) Source #

(SPDistribute k, Monad m k, PreArrow (Kleisli m k), PreArrChoice (Kleisli m k)) => SPDistribute (Kleisli m k) Source # 
Instance details

Defined in Control.Monad.Constrained

Methods

distribute :: (ObjectSum (Kleisli m k) (a, b) (a, c), ObjectPair (Kleisli m k) a (b + c), ObjectSum (Kleisli m k) b c, PairObjects (Kleisli m k) a b, PairObjects (Kleisli m k) a c) => Kleisli m k (a, b + c) ((a, b) + (a, c)) Source #

unDistribute :: (ObjectSum (Kleisli m k) (a, b) (a, c), ObjectPair (Kleisli m k) a (b + c), ObjectSum (Kleisli m k) b c, PairObjects (Kleisli m k) a b, PairObjects (Kleisli m k) a c) => Kleisli m k ((a, b) + (a, c)) (a, b + c) Source #

boolAsSwitch :: (ObjectSum (Kleisli m k) a a, ObjectPair (Kleisli m k) Bool a) => Kleisli m k (Bool, a) (a + a) Source #

boolFromSwitch :: (ObjectSum (Kleisli m k) a a, ObjectPair (Kleisli m k) Bool a) => Kleisli m k (a + a) (Bool, a) Source #

Function-like categories

type Function f = EnhancedCat (->) f Source #

Many categories have as morphisms essentially functions with extra properties: group homomorphisms, linear maps, continuous functions...

It makes sense to generalise the notion of function application to these morphisms; we can't do that for the simple juxtaposition writing f x, but it is possible for the function-application operator $.

This is particularly useful for ConstrainedCategory versions of Hask, where after all the morphisms are nothing but functions.

($) :: (Function f, Object f a, Object f b) => f a b -> a -> b infixr 0 Source #

Alternative composition notation

(>>>) :: (Category k, Object k a, Object k b, Object k c) => k a b -> k b c -> k a c infixr 1 Source #

(<<<) :: (Category k, Object k a, Object k b, Object k c) => k b c -> k a b -> k a c infixr 1 Source #

Proxies for cartesian categories

class (Morphism k, HasAgent k) => CartesianAgent k where Source #

Methods

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

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

alg2to2 :: (ObjectPair k a b, ObjectPair k c d) => (forall q. Object k q => AgentVal k q a -> AgentVal k q b -> (AgentVal k q c, AgentVal k q d)) -> k (a, b) (c, d) Source #

genericAgentCombine :: (HasAgent k, PreArrow k, Object k a, ObjectPair k b c, Object k d) => k (b, c) d -> GenericAgent k a b -> GenericAgent k a c -> GenericAgent k a d Source #

genericAlg1to2 :: (PreArrow k, u ~ UnitObject k, Object k a, ObjectPair k b c) => (forall q. Object k q => GenericAgent k q a -> (GenericAgent k q b, GenericAgent k q c)) -> k a (b, c) Source #

genericAlg2to1 :: (PreArrow k, u ~ UnitObject k, ObjectPair k a u, ObjectPair k a b, ObjectPair k b u, ObjectPair k b a) => (forall q. Object k q => GenericAgent k q a -> GenericAgent k q b -> GenericAgent k q c) -> k (a, b) c Source #

genericAlg2to2 :: (PreArrow k, u ~ UnitObject k, ObjectPair k a u, ObjectPair k a b, ObjectPair k c d, ObjectPair k b u, ObjectPair k b a) => (forall q. Object k q => GenericAgent k q a -> GenericAgent k q b -> (GenericAgent k q c, GenericAgent k q d)) -> k (a, b) (c, d) Source #

class (HasAgent k, AgentVal k a x ~ p a x) => PointAgent p k a x | p -> k where Source #

Methods

point :: (Object k a, Object k x) => x -> p a x Source #

Misc utility

Conditionals

choose Source #

Arguments

:: (Arrow f (->), Function f, Object f Bool, Object f a) 
=> f (UnitObject f) a

"False" value

-> f (UnitObject f) a

"True" value

-> f Bool a 

Basically ifThenElse with inverted argument order, and "morphismised" arguments.

ifThenElse :: (EnhancedCat f (->), Function f, Object f Bool, Object f a, Object f (f a a), Object f (f a (f a a))) => Bool `f` (a `f` (a `f` a)) Source #

Coercions

follow :: (EnhancedCat k Coercion, Coercible a b, Object k a, Object k b) => p a b -> k a b Source #

Imitate a type change in a different category. This is usually possible for type changes that are no-ops at runtime, in particular for newtype wrappers.

flout :: (EnhancedCat k Coercion, Coercible b a, Object k a, Object k b) => p a b -> k b a Source #

The opposite of follow.

pretend :: (EnhancedCat k Coercion, Object k a, Object k b) => Coercion a b -> k a a -> k b b Source #

Wrap an endomorphism in inverse coercions, to have it work on any type that's representationally equivalent to the one in the morphism's signature. This is a specialised version of pretendLike.

swallow :: (EnhancedCat k Coercion, Object k a, Object k b) => Coercion b a -> k a a -> k b b Source #

Equivalent to pretend . sym.

pretendLike :: (EnhancedCat k Coercion, Coercible b a, Coercible c d, Object k a, Object k b, Object k c, Object k d) => p c d -> k a c -> k b d Source #

This works much like over: wrap a morphism in any coercions required so the result types match. This will often be too polymorphic for the type checker; consider using the more explicit follow and flout.

swallowLike :: (EnhancedCat k Coercion, Coercible b a, Coercible c d, Object k a, Object k b, Object k c, Object k d) => p b a -> k a c -> k b d Source #

Generalised coercion analogue of under.

Orphan instances

(SPDistribute k, ObjectSum k a a, ObjectPair k Bool a) => Isomorphic (k :: Type -> Type -> Type) (a + a :: Type) ((Bool, a) :: Type) Source # 
Instance details

Methods

iso :: k (a + a) (Bool, a) Source #

(SPDistribute k, ObjectSum k a a, ObjectPair k Bool a) => Isomorphic (k :: Type -> Type -> Type) ((Bool, a) :: Type) (a + a :: Type) Source # 
Instance details

Methods

iso :: k (Bool, a) (a + a) Source #

(SPDistribute k, ObjectSum k (a, b) (a, c), ObjectPair k a (b + c), ObjectSum k b c, PairObjects k a b, PairObjects k a c) => Isomorphic (k :: Type -> Type -> Type) ((a, b) + (a, c) :: Type) ((a, b + c) :: Type) Source # 
Instance details

Methods

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

(SPDistribute k, ObjectSum k (a, b) (a, c), ObjectPair k a (b + c), ObjectSum k b c, PairObjects k a b, PairObjects k a c) => Isomorphic (k :: Type -> Type -> Type) ((a, b + c) :: Type) ((a, b) + (a, c) :: Type) Source # 
Instance details

Methods

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