Safe Haskell | None |
---|---|
Language | Haskell2010 |
Extensions |
|
Synopsis
- data Queue (f :: k -> k -> *) (a :: k) (b :: k) where
- consQ :: forall (f :: k -> k -> *) a b c. f b c -> Queue f a b -> Queue f a c
- snocQ :: forall (f :: k -> k -> *) a b c. Queue f b c -> f a b -> Queue f a c
- unconsQ :: Queue f a b -> ViewL f a b
- liftQ :: forall (f :: k -> k -> *) a b. f a b -> Queue f a b
- foldNatQ :: forall (f :: k -> k -> *) c a b. Category c => (forall x y. f x y -> c x y) -> Queue f a b -> c a b
- foldrQ :: forall (f :: k -> k -> *) c a b d. (forall x y z. f y z -> c x y -> c x z) -> c a b -> Queue f b d -> c a d
- foldlQ :: forall (f :: k -> k -> *) c a b d. (forall x y z. c y z -> f x y -> c x z) -> c b d -> Queue f a b -> c a d
- zipWithQ :: forall f g a b a' b'. Category f => (forall x y x' y'. f x y -> f x' y' -> f (g x x') (g y y')) -> Queue f a b -> Queue f a' b' -> Queue f (g a a') (g b b')
- data ListTr :: (k -> k -> *) -> k -> k -> * where
- liftL :: forall (f :: k -> k -> *) x y. f x y -> ListTr f x y
- foldNatL :: forall (f :: k -> k -> *) c a b. Category c => (forall x y. f x y -> c x y) -> ListTr f a b -> c a b
- foldlL :: forall (f :: k -> k -> *) c a b d. (forall x y z. c y z -> f x y -> c x z) -> c b d -> ListTr f a b -> c a d
- foldrL :: forall (f :: k -> k -> *) c a b d. (forall x y z. f y z -> c x y -> c x z) -> c a b -> ListTr f b d -> c a d
- zipWithL :: forall f g a b a' b'. Category f => (forall x y x' y'. f x y -> f x' y' -> f (g x x') (g y y')) -> ListTr f a b -> ListTr f a' b' -> ListTr f (g a a') (g b b')
- newtype C f a b = C {}
- liftC :: forall (f :: k -> k -> *) a b. f a b -> C f a b
- consC :: forall (f :: k -> k -> *) a b c. f b c -> C f a b -> C f a c
- foldNatC :: forall (f :: k -> k -> *) c a b. Category c => (forall x y. f x y -> c x y) -> C f a b -> c a b
- toC :: ListTr f a b -> C f a b
- fromC :: C f a b -> ListTr f a b
- newtype Op (f :: k -> k -> *) (a :: k) (b :: k) = Op {
- runOp :: f b a
- hoistOp :: forall (f :: k -> k -> *) (g :: k -> k -> *) a b. (forall x y. f x y -> g x y) -> Op f a b -> Op g a b
- class FreeAlgebra2 (m :: (k -> k -> Type) -> k -> k -> Type) where
- liftFree2 :: AlgebraType0 m f => f a b -> m f a b
- foldNatFree2 :: (AlgebraType m d, AlgebraType0 m f) => (forall (x :: k) (y :: k). f x y -> d x y) -> m f a b -> d a b
- codom2 :: AlgebraType0 m f => Proof (AlgebraType m (m f)) (m f)
- forget2 :: AlgebraType m f => Proof (AlgebraType0 m f) (m f)
- wrapFree2 :: (AlgebraType0 m f, FreeAlgebra2 m, Monad (m f a)) => f a (m f a b) -> m f a b
- foldFree2 :: (FreeAlgebra2 m, AlgebraType m f) => m f a b -> f a b
- hoistFree2 :: (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
- hoistFreeH2 :: (FreeAlgebra2 m, FreeAlgebra2 n, AlgebraType0 m f, AlgebraType0 n f, AlgebraType m (n f)) => m f a b -> n f a b
- joinFree2 :: (FreeAlgebra2 m, AlgebraType0 m f) => m (m f) a b -> m f a b
- bindFree2 :: (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
Real time Queue
data Queue (f :: k -> k -> *) (a :: k) (b :: k) where Source #
Type alligned real time queues; Based on `Purely Functinal Data Structures` C.Okasaki. This the most reliably behaved implementation of free categories in this package.
Upper bounds of consQ
, snocQ
, unconsQ
are O(1)
(worst case).
Internal invariant: sum of lengths of two last least is equal the length of the first one.
Instances
foldNatQ :: forall (f :: k -> k -> *) c a b. Category c => (forall x y. f x y -> c x y) -> Queue f a b -> c a b Source #
Efficient fold of a queue into a category, analogous to foldM
.
complexity O(n)
foldrQ :: forall (f :: k -> k -> *) c a b d. (forall x y z. f y z -> c x y -> c x z) -> c a b -> Queue f b d -> c a d Source #
foldlQ :: forall (f :: k -> k -> *) c a b d. (forall x y z. c y z -> f x y -> c x z) -> c b d -> Queue f a b -> c a d Source #
zipWithQ :: forall f g a b a' b'. Category f => (forall x y x' y'. f x y -> f x' y' -> f (g x x') (g y y')) -> Queue f a b -> Queue f a' b' -> Queue f (g a a') (g b b') Source #
Type alligned list
data ListTr :: (k -> k -> *) -> k -> k -> * where Source #
Simple representation of a free category by using type aligned lists. This is not a surprise as free monoids can be represented by lists (up to laziness)
ListTr
has
class instance:FreeAlgebra2
liftFree2 @ListTr :: f a b -> ListTr f ab foldNatFree2 @ListTr :: Category d => (forall x y. f x y -> d x y) -> ListTr f a b -> d a b
The same performance concerns that apply to
apply to this encoding of a free category.Free
Note that even though this is a naive version, it behaves quite well in simple benchmarks and quite stable regardless of the level of optimisations.
Instances
foldNatL :: forall (f :: k -> k -> *) c a b. Category c => (forall x y. f x y -> c x y) -> ListTr f a b -> c a b Source #
foldlL :: forall (f :: k -> k -> *) c a b d. (forall x y z. c y z -> f x y -> c x z) -> c b d -> ListTr f a b -> c a d Source #
foldrL :: forall (f :: k -> k -> *) c a b d. (forall x y z. f y z -> c x y -> c x z) -> c a b -> ListTr f b d -> c a d Source #
zipWithL :: forall f g a b a' b'. Category f => (forall x y x' y'. f x y -> f x' y' -> f (g x x') (g y y')) -> ListTr f a b -> ListTr f a' b' -> ListTr f (g a a') (g b b') Source #
Free category (CPS style)
CPS style encoded free category; one can use
class
instance:FreeAlgebra2
liftFree2 @C :: f a b -> C f a b foldNatFree2 @C :: Category d => (forall x y. f x y -> d x y) -> C f a b -> d a b
Instances
FreeAlgebra2 (C :: (k -> k -> Type) -> k -> k -> Type) Source # | |
Defined in Control.Category.Free liftFree2 :: AlgebraType0 C f => f a b -> C f a b # foldNatFree2 :: (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 :: AlgebraType0 C f => Proof (AlgebraType C (C f)) (C f) # forget2 :: AlgebraType C f => Proof (AlgebraType0 C f) (C f) # | |
Category (C f :: k -> k -> Type) Source # | |
Arrow f => Arrow (C f) Source # | |
ArrowZero f => ArrowZero (C f) Source # | |
Defined in Control.Category.Free | |
ArrowChoice f => ArrowChoice (C f) Source # | |
(forall (x :: k) (y :: k). Show (f x y)) => Show (C f a b) Source # | Show instance via |
Semigroup (C f o o) Source # | |
Monoid (C f o o) Source # | |
type AlgebraType0 (C :: (k -> k -> Type) -> k -> k -> Type) (f :: l) Source # | |
Defined in Control.Category.Free | |
type AlgebraType (C :: (k2 -> k2 -> Type) -> k2 -> k2 -> Type) (c :: k1 -> k1 -> Type) Source # | |
Defined in Control.Category.Free |
foldNatC :: forall (f :: k -> k -> *) c a b. Category c => (forall x y. f x y -> c x y) -> C f a b -> c a b Source #
toC :: ListTr f a b -> C f a b Source #
Isomorphism from
to ListTr
, which is a specialisation of
C
.hoistFreeH2
fromC :: C f a b -> ListTr f a b Source #
Inverse of
, which also is a specialisation of fromC
.hoistFreeH2
Opposite category
newtype Op (f :: k -> k -> *) (a :: k) (b :: k) Source #
Oposite categoy in which arrows from a
to b
are represented by arrows
from b
to a
in the original category.
hoistOp :: forall (f :: k -> k -> *) (g :: k -> k -> *) a b. (forall x y. f x y -> g x y) -> Op f a b -> Op g a b Source #
Op
is an endo-functor of the category of categories.
Free interface re-exports
class FreeAlgebra2 (m :: (k -> k -> Type) -> k -> k -> Type) where #
Free algebra class similar to
and FreeAlgebra1
, but for
types of kind FreeAlgebra
k -> k -> Type
.
liftFree2 :: AlgebraType0 m f => f a b -> m f a b #
Lift a graph f
satsifying the constraint
to
a free its object AlgebraType0
m f
.
foldNatFree2 :: (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 :: 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)
constrant. 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 satifsfy
the constraint AlgebraType m
.
forget2 :: 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
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 :: (FreeAlgebra2 m, AlgebraType m f) => m f a b -> f a b #
hoistFree2 :: (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
, which
defined functor instance for fmapFree
instances) and it satisfies the
functor laws:FreeAlgebra
hoistFree2 id = id
hoistFree2 f . hoistFree2 g = hoistFree2 (f . g)
hoistFreeH2 :: (FreeAlgebra2 m, FreeAlgebra2 n, AlgebraType0 m f, AlgebraType0 n f, AlgebraType m (n f)) => m f a b -> n f a b #
Hoist the top level free structure.
joinFree2 :: (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 :: (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