free-category-0.0.4.5: efficient data types for free categories and arrows
Safe HaskellSafe-Inferred
LanguageHaskell2010
Extensions
  • Cpp
  • MonoLocalBinds
  • ScopedTypeVariables
  • TypeFamilies
  • GADTs
  • GADTSyntax
  • PolyKinds
  • InstanceSigs
  • TypeSynonymInstances
  • FlexibleInstances
  • KindSignatures
  • RankNTypes
  • ExplicitNamespaces
  • ExplicitForAll

Control.Arrow.Free

Synopsis

Free arrow

data Arr f a b where Source #

Constructors

Id :: Arr f a a 
Cons :: f b c -> Queue (Arr f) a b -> Arr f a c 
Arr :: (b -> c) -> Arr f a b -> Arr f a c 
Prod :: Arr f a b -> Arr f a c -> Arr f a (b, c) 

Instances

Instances details
Arrow (Arr f) Source # 
Instance details

Defined in Control.Arrow.Free

Methods

arr :: (b -> c) -> Arr f b c #

first :: Arr f b c -> Arr f (b, d) (c, d) #

second :: Arr f b c -> Arr f (d, b) (d, c) #

(***) :: Arr f b c -> Arr f b' c' -> Arr f (b, b') (c, c') #

(&&&) :: Arr f b c -> Arr f b c' -> Arr f b (c, c') #

ArrowChoice (Arr (Choice f)) Source # 
Instance details

Defined in Control.Arrow.Free

Methods

left :: Arr (Choice f) b c -> Arr (Choice f) (Either b d) (Either c d) #

right :: Arr (Choice f) b c -> Arr (Choice f) (Either d b) (Either d c) #

(+++) :: Arr (Choice f) b c -> Arr (Choice f) b' c' -> Arr (Choice f) (Either b b') (Either c c') #

(|||) :: Arr (Choice f) b d -> Arr (Choice f) c d -> Arr (Choice f) (Either b c) d #

FreeAlgebra2 Arr Source # 
Instance details

Defined in Control.Arrow.Free

Methods

liftFree2 :: forall f (a :: k) (b :: k). AlgebraType0 Arr f => f a b -> Arr f a b #

foldNatFree2 :: forall d f (a :: k) (b :: k). (AlgebraType Arr d, AlgebraType0 Arr f) => (forall (x :: k) (y :: k). f x y -> d x y) -> Arr f a b -> d a b #

codom2 :: forall (f :: k -> k -> Type). AlgebraType0 Arr f => Proof (AlgebraType Arr (Arr f)) (Arr f) #

forget2 :: forall (f :: k -> k -> Type). AlgebraType Arr f => Proof (AlgebraType0 Arr f) (Arr f) #

Category (Arr f :: TYPE LiftedRep -> TYPE LiftedRep -> Type) Source # 
Instance details

Defined in Control.Arrow.Free

Methods

id :: forall (a :: k). Arr f a a #

(.) :: forall (b :: k) (c :: k) (a :: k). Arr f b c -> Arr f a b -> Arr f a c #

Monoid (Arr f o o) Source # 
Instance details

Defined in Control.Arrow.Free

Methods

mempty :: Arr f o o #

mappend :: Arr f o o -> Arr f o o -> Arr f o o #

mconcat :: [Arr f o o] -> Arr f o o #

Semigroup (Arr f o o) Source # 
Instance details

Defined in Control.Arrow.Free

Methods

(<>) :: Arr f o o -> Arr f o o -> Arr f o o #

sconcat :: NonEmpty (Arr f o o) -> Arr f o o #

stimes :: Integral b => b -> Arr f o o -> Arr f o o #

type AlgebraType0 Arr (f :: l) Source # 
Instance details

Defined in Control.Arrow.Free

type AlgebraType0 Arr (f :: l) = ()
type AlgebraType Arr (c :: TYPE LiftedRep -> TYPE LiftedRep -> Type) Source # 
Instance details

Defined in Control.Arrow.Free

arrArr :: (b -> c) -> Arr f b c Source #

liftArr :: f a b -> Arr f a b Source #

mapArr :: f b c -> Arr f a b -> Arr f a c Source #

foldArr :: forall f arr a b. Arrow arr => (forall x y. f x y -> arr x y) -> Arr f a b -> arr a b Source #

Free arrow (CPS style)

newtype A f a b Source #

Free arrow using CPS style.

Constructors

A 

Fields

  • runA :: forall r. Arrow r => (forall x y. f x y -> r x y) -> r a b
     

Instances

Instances details
Arrow (A f) Source # 
Instance details

Defined in Control.Arrow.Free

Methods

arr :: (b -> c) -> A f b c #

first :: A f b c -> A f (b, d) (c, d) #

second :: A f b c -> A f (d, b) (d, c) #

(***) :: A f b c -> A f b' c' -> A f (b, b') (c, c') #

(&&&) :: A f b c -> A f b c' -> A f b (c, c') #

FreeAlgebra2 A Source # 
Instance details

Defined in Control.Arrow.Free

Methods

liftFree2 :: forall f (a :: k) (b :: k). AlgebraType0 A f => f a b -> A f a b #

foldNatFree2 :: forall d f (a :: k) (b :: k). (AlgebraType A d, AlgebraType0 A f) => (forall (x :: k) (y :: k). f x y -> d x y) -> A f a b -> d a b #

codom2 :: forall (f :: k -> k -> Type). AlgebraType0 A f => Proof (AlgebraType A (A f)) (A f) #

forget2 :: forall (f :: k -> k -> Type). AlgebraType A f => Proof (AlgebraType0 A f) (A f) #

Category (A f :: TYPE LiftedRep -> TYPE LiftedRep -> TYPE LiftedRep) Source # 
Instance details

Defined in Control.Arrow.Free

Methods

id :: forall (a :: k). A f a a #

(.) :: forall (b :: k) (c :: k) (a :: k). A f b c -> A f a b -> A f a c #

Monoid (A f o o) Source # 
Instance details

Defined in Control.Arrow.Free

Methods

mempty :: A f o o #

mappend :: A f o o -> A f o o -> A f o o #

mconcat :: [A f o o] -> A f o o #

Semigroup (A f o o) Source # 
Instance details

Defined in Control.Arrow.Free

Methods

(<>) :: A f o o -> A f o o -> A f o o #

sconcat :: NonEmpty (A f o o) -> A f o o #

stimes :: Integral b => b -> A f o o -> A f o o #

type AlgebraType0 A (f :: l) Source # 
Instance details

Defined in Control.Arrow.Free

type AlgebraType0 A (f :: l) = ()
type AlgebraType A (c :: TYPE LiftedRep -> TYPE LiftedRep -> Type) Source # 
Instance details

Defined in Control.Arrow.Free

fromA :: A f a b -> Arr f a b Source #

Inverse of fromA, which also is a specialisation of hoistFreeH2.

toA :: Arr f a b -> A f a b Source #

Isomorphism from Arr to A, which is a specialisation of hoistFreeH2.

Free interface re-exports

class FreeAlgebra2 (m :: (k -> k -> Type) -> k -> k -> Type) where #

Free algebra class similar to FreeAlgebra1 and FreeAlgebra, but for types of kind k -> k -> Type.

Minimal complete definition

liftFree2, foldNatFree2

Methods

liftFree2 :: forall f (a :: k) (b :: k). AlgebraType0 m f => f a b -> m f a b #

Lift a graph f satisfying the constraint AlgebraType0 to a free its object m f.

foldNatFree2 :: forall d f (a :: k) (b :: k). (AlgebraType m d, AlgebraType0 m f) => (forall (x :: k) (y :: k). f x y -> d x y) -> m f a b -> d a b #

This represents the theorem that m f is indeed free object (as in propositions as types). The types of kind k -> k -> Type form a category, where an arrow from f :: k -> k -> Type to d :: k -> k -> Type is represented by type forall x y. f x y -> d x y. foldNatFree2 states that whenever we have such a morphism and d satisfies the constraint AlgebraType m d then we can construct a morphism from m f to d.

foldNatFree2 nat (liftFree2 tr) = nat tr
foldNatFree2 nat . foldNatFree2 nat' = foldNatFree2 (foldNatFree2 nat . nat')

codom2 :: forall (f :: k -> k -> Type). AlgebraType0 m f => Proof (AlgebraType m (m f)) (m f) #

A proof that for each f satisfying AlgebraType0 m f, m f satisfies AlgebraType m (m f) constraint. This means that m is a well defined functor from the full sub-category of types of kind k -> k -> Type which satisfy the AlgebraType0 m constraint to the full subcategory of types of the same kind which satisfy the constraint AlgebraType m.

forget2 :: forall (f :: k -> k -> Type). AlgebraType m f => Proof (AlgebraType0 m f) (m f) #

A proof that each type f :: k -> k -> Type satisfying the Algebra m f constraint also satisfies AlgebraType0 m f. This states that there is a well defined forgetful functor from the category of types of kind k -> k -> Type which satisfy the AlgebraType m to the category of types of the same kind which satisfy the AlgebraType0 m constraint.

Instances

Instances details
FreeAlgebra2 (C :: (k -> k -> Type) -> k -> k -> TYPE LiftedRep) Source # 
Instance details

Defined in Control.Category.Free

Methods

liftFree2 :: forall f (a :: k0) (b :: k0). AlgebraType0 C f => f a b -> C f a b #

foldNatFree2 :: forall d f (a :: k0) (b :: k0). (AlgebraType C d, AlgebraType0 C f) => (forall (x :: k0) (y :: k0). f x y -> d x y) -> C f a b -> d a b #

codom2 :: forall (f :: k0 -> k0 -> Type). AlgebraType0 C f => Proof (AlgebraType C (C f)) (C f) #

forget2 :: forall (f :: k0 -> k0 -> Type). AlgebraType C f => Proof (AlgebraType0 C f) (C f) #

FreeAlgebra2 (ListTr :: (k -> k -> Type) -> k -> k -> Type) Source # 
Instance details

Defined in Control.Category.Free.Internal

Methods

liftFree2 :: forall f (a :: k0) (b :: k0). AlgebraType0 ListTr f => f a b -> ListTr f a b #

foldNatFree2 :: forall d f (a :: k0) (b :: k0). (AlgebraType ListTr d, AlgebraType0 ListTr f) => (forall (x :: k0) (y :: k0). f x y -> d x y) -> ListTr f a b -> d a b #

codom2 :: forall (f :: k0 -> k0 -> Type). AlgebraType0 ListTr f => Proof (AlgebraType ListTr (ListTr f)) (ListTr f) #

forget2 :: forall (f :: k0 -> k0 -> Type). AlgebraType ListTr f => Proof (AlgebraType0 ListTr f) (ListTr f) #

FreeAlgebra2 (Queue :: (k -> k -> Type) -> k -> k -> Type) Source # 
Instance details

Defined in Control.Category.Free.Internal

Methods

liftFree2 :: forall f (a :: k0) (b :: k0). AlgebraType0 Queue f => f a b -> Queue f a b #

foldNatFree2 :: forall d f (a :: k0) (b :: k0). (AlgebraType Queue d, AlgebraType0 Queue f) => (forall (x :: k0) (y :: k0). f x y -> d x y) -> Queue f a b -> d a b #

codom2 :: forall (f :: k0 -> k0 -> Type). AlgebraType0 Queue f => Proof (AlgebraType Queue (Queue f)) (Queue f) #

forget2 :: forall (f :: k0 -> k0 -> Type). AlgebraType Queue f => Proof (AlgebraType0 Queue f) (Queue f) #

Monad m => FreeAlgebra2 (EffCat m :: (k -> k -> Type) -> k -> k -> Type) Source # 
Instance details

Defined in Control.Category.FreeEffect

Methods

liftFree2 :: forall f (a :: k0) (b :: k0). AlgebraType0 (EffCat m) f => f a b -> EffCat m f a b #

foldNatFree2 :: forall d f (a :: k0) (b :: k0). (AlgebraType (EffCat m) d, AlgebraType0 (EffCat m) f) => (forall (x :: k0) (y :: k0). f x y -> d x y) -> EffCat m f a b -> d a b #

codom2 :: forall (f :: k0 -> k0 -> Type). AlgebraType0 (EffCat m) f => Proof (AlgebraType (EffCat m) (EffCat m f)) (EffCat m f) #

forget2 :: forall (f :: k0 -> k0 -> Type). AlgebraType (EffCat m) f => Proof (AlgebraType0 (EffCat m) f) (EffCat m f) #

FreeAlgebra2 A Source # 
Instance details

Defined in Control.Arrow.Free

Methods

liftFree2 :: forall f (a :: k) (b :: k). AlgebraType0 A f => f a b -> A f a b #

foldNatFree2 :: forall d f (a :: k) (b :: k). (AlgebraType A d, AlgebraType0 A f) => (forall (x :: k) (y :: k). f x y -> d x y) -> A f a b -> d a b #

codom2 :: forall (f :: k -> k -> Type). AlgebraType0 A f => Proof (AlgebraType A (A f)) (A f) #

forget2 :: forall (f :: k -> k -> Type). AlgebraType A f => Proof (AlgebraType0 A f) (A f) #

FreeAlgebra2 Arr Source # 
Instance details

Defined in Control.Arrow.Free

Methods

liftFree2 :: forall f (a :: k) (b :: k). AlgebraType0 Arr f => f a b -> Arr f a b #

foldNatFree2 :: forall d f (a :: k) (b :: k). (AlgebraType Arr d, AlgebraType0 Arr f) => (forall (x :: k) (y :: k). f x y -> d x y) -> Arr f a b -> d a b #

codom2 :: forall (f :: k -> k -> Type). AlgebraType0 Arr f => Proof (AlgebraType Arr (Arr f)) (Arr f) #

forget2 :: forall (f :: k -> k -> Type). AlgebraType Arr f => Proof (AlgebraType0 Arr f) (Arr f) #

wrapFree2 :: (AlgebraType0 m f, FreeAlgebra2 m, Monad (m f a)) => f a (m f a b) -> m f a b #

Version of wrap from free package but for graphs.

foldFree2 :: forall k m f (a :: k) (b :: k). (FreeAlgebra2 m, AlgebraType m f) => m f a b -> f a b #

Like foldFree or foldFree1 but for graphs.

A lawful instance will satisfy:

 foldFree2 . liftFree2 == id :: f a b -> f a b

It is the unit of adjunction defined by FreeAlgebra1 class.

hoistFree2 :: forall k m f g (a :: k) (b :: k). (FreeAlgebra2 m, AlgebraType0 m g, AlgebraType0 m f) => (forall (x :: k) (y :: k). f x y -> g x y) -> m f a b -> m g a b #

Hoist the underlying graph in the free structure. This is a higher version of a functor (analogous to fmapFree, which defined functor instance for FreeAlgebra instances) and it satisfies the functor laws:

hoistFree2 id = id
hoistFree2 f . hoistFree2 g = hoistFree2 (f . g)

joinFree2 :: forall k m (f :: k -> k -> Type) (a :: k) (b :: k). (FreeAlgebra2 m, AlgebraType0 m f) => m (m f) a b -> m f a b #

FreeAlgebra2 m is a monad on some subcategory of graphs (types of kind k -> k -> Type@), joinFree it is the join of this monad.

foldNatFree2 nat . joinFree2 = foldNatFree2 (foldNatFree2 nat)

This property is analogous to foldMap f . concat = foldMap (foldMap f),

bindFree2 :: forall {k} m f (g :: k -> k -> Type) (a :: k) (b :: k). (FreeAlgebra2 m, AlgebraType0 m g, AlgebraType0 m f) => m f a b -> (forall (x :: k) (y :: k). f x y -> m g x y) -> m g a b #

bind of the monad defined by m on the subcategory of graphs (types of kind k -> k -> Type).

foldNatFree2 nat (bindFree mf nat') = foldNatFree2 (foldNatFree2 nat . nat') mf

Free ArrowChoice

data Choice f a b where Source #

Constructors

NoChoice :: f a b -> Choice f a b 
Choose :: ArrChoice f a c -> ArrChoice f b c -> Choice f (Either a b) c 

Instances

Instances details
ArrowChoice (Arr (Choice f)) Source # 
Instance details

Defined in Control.Arrow.Free

Methods

left :: Arr (Choice f) b c -> Arr (Choice f) (Either b d) (Either c d) #

right :: Arr (Choice f) b c -> Arr (Choice f) (Either d b) (Either d c) #

(+++) :: Arr (Choice f) b c -> Arr (Choice f) b' c' -> Arr (Choice f) (Either b b') (Either c c') #

(|||) :: Arr (Choice f) b d -> Arr (Choice f) c d -> Arr (Choice f) (Either b c) d #

liftArrChoice :: f a b -> ArrChoice f a b Source #

foldArrChoice :: forall f arr a b. ArrowChoice arr => (forall x y. f x y -> arr x y) -> ArrChoice f a b -> arr a b Source #