Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Extensions |
|
Internal module, contains implementation of type aligned real time queues (C.Okasaki 'Purely Functional Data Structures').
Synopsis
- newtype Op (f :: k -> k -> Type) (a :: k) (b :: k) = Op {
- runOp :: f b a
- hoistOp :: forall k (f :: k -> k -> Type) (g :: k -> k -> Type) a b. (forall x y. f x y -> g x y) -> Op f a b -> Op g a b
- data ListTr :: (k -> k -> Type) -> k -> k -> Type where
- liftL :: forall k (f :: k -> k -> Type) x y. f x y -> ListTr f x y
- foldNatL :: forall k (f :: k -> k -> Type) c a b. Category c => (forall x y. f x y -> c x y) -> ListTr f a b -> c a b
- lengthListTr :: ListTr f a b -> Int
- foldrL :: forall k (f :: k -> k -> Type) 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
- foldlL :: forall k (f :: k -> k -> Type) 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
- 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')
- data Queue (f :: k -> k -> Type) (a :: k) (b :: k) where
- liftQ :: forall k (f :: k -> k -> Type) a b. f a b -> Queue f a b
- nilQ :: Queue (f :: k -> k -> Type) a a
- consQ :: forall k (f :: k -> k -> Type) a b c. f b c -> Queue f a b -> Queue f a c
- data ViewL f a b where
- unconsQ :: Queue f a b -> ViewL f a b
- snocQ :: forall k (f :: k -> k -> Type) a b c. Queue f b c -> f a b -> Queue f a c
- foldNatQ :: forall k (f :: k -> k -> Type) c a b. Category c => (forall x y. f x y -> c x y) -> Queue f a b -> c a b
- foldrQ :: forall k (f :: k -> k -> Type) 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 k (f :: k -> k -> Type) 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
- hoistQ :: forall k (f :: k -> k -> Type) (g :: k -> k -> Type) a b. (forall x y. f x y -> g x y) -> Queue f a b -> Queue g a b
- 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')
Documentation
newtype Op (f :: k -> k -> Type) (a :: k) (b :: k) Source #
Opposite category in which arrows from a
to b
are represented by arrows
from b
to a
in the original category.
hoistOp :: forall k (f :: k -> k -> Type) (g :: k -> k -> Type) 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.
data ListTr :: (k -> k -> Type) -> k -> k -> Type 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 k (f :: k -> k -> Type) c a b. Category c => (forall x y. f x y -> c x y) -> ListTr f a b -> c a b Source #
lengthListTr :: ListTr f a b -> Int Source #
foldrL :: forall k (f :: k -> k -> Type) 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 #
foldlL :: forall k (f :: k -> k -> Type) 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 #
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 #
data Queue (f :: k -> k -> Type) (a :: k) (b :: k) where Source #
Type aligned real time queues; Based on `Purely Functional 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
FreeAlgebra2 (Queue :: (k -> k -> Type) -> k -> k -> Type) Source # | |
Defined in Control.Category.Free.Internal 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) # | |
Category (Queue f :: k -> k -> Type) Source # | |
Arrow f => Arrow (Queue f) Source # | |
ArrowChoice f => ArrowChoice (Queue f) Source # | |
Defined in Control.Category.Free.Internal | |
ArrowZero f => ArrowZero (Queue f) Source # | |
Defined in Control.Category.Free.Internal | |
Monoid (Queue f o o) Source # | |
Semigroup (Queue f o o) Source # | |
(forall (x :: k) (y :: k). Show (f x y)) => Show (Queue f a b) Source # | |
type AlgebraType0 (Queue :: (k -> k -> Type) -> k -> k -> Type) (f :: l) Source # | |
Defined in Control.Category.Free.Internal | |
type AlgebraType (Queue :: (k1 -> k1 -> Type) -> k1 -> k1 -> Type) (c :: k2 -> k2 -> Type) Source # | |
Defined in Control.Category.Free.Internal |
foldNatQ :: forall k (f :: k -> k -> Type) 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 k (f :: k -> k -> Type) 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 k (f :: k -> k -> Type) 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 #