diff --git a/src/Control/Category/Free.hs b/src/Control/Category/Free.hs index 4c50071..08706d3 100644 --- a/src/Control/Category/Free.hs +++ b/src/Control/Category/Free.hs @@ -103,11 +103,11 @@ foldCat :: forall f c a b. -> Cat f a b -> c a b foldCat _nat Id = id -foldCat nat (Cat tr queue) = - case queue of - NilQ -> nat tr - ConsQ Id queue' -> nat tr . foldQ (foldCat nat) queue' - ConsQ c queue' -> nat tr . foldCat nat c . foldQ (foldCat nat) queue' +foldCat nat (Cat tr q) = + case q of + NilQ -> nat tr + ConsQ Id q' -> nat tr . foldQ (foldCat nat) q' + ConsQ c q' -> nat tr . foldCat nat c . foldQ (foldCat nat) q' -- TODO: implement foldl; it might require different representation. Function -- composition is applied from right to left, so it should be more efficient. @@ -138,10 +138,10 @@ instance FreeAlgebra2 Cat where instance Arrow f => Arrow (Cat f) where arr = arrCat . arr - Cat tr queue *** Cat tr' queue' = Cat (tr *** tr') (zipWithQ (***) queue queue') - Cat tr queue *** Id = Cat (tr *** arr id) (zipWithQ (***) queue NilQ) - Id *** Cat tr' queue' = Cat (arr id *** tr') (zipWithQ (***) NilQ queue') - Id *** Id = Cat (arr id *** arr id) NilQ + Cat tr q *** Cat tr' q' = Cat (tr *** tr') (zipWithQ (***) q q') + Cat tr q *** Id = Cat (tr *** arr id) (zipWithQ (***) q NilQ) + Id *** Cat tr' q' = Cat (arr id *** tr') (zipWithQ (***) NilQ q') + Id *** Id = Cat (arr id *** arr id) NilQ instance ArrowZero f => ArrowZero (Cat f) where zeroArrow = arrCat zeroArrow diff --git a/src/Control/Category/Free/Internal.hs b/src/Control/Category/Free/Internal.hs index 23aaf6a..88cd7f1 100644 --- a/src/Control/Category/Free/Internal.hs +++ b/src/Control/Category/Free/Internal.hs @@ -202,9 +202,9 @@ foldQ :: forall (f :: k -> k -> *) c a b. => (forall x y. f x y -> c x y) -> Queue f a b -> c a b -foldQ nat queue = case queue of - NilQ -> id - ConsQ tr queue' -> nat tr . foldQ nat queue' +foldQ nat q = case q of + NilQ -> id + ConsQ tr q' -> nat tr . foldQ nat q' zipWithQ :: forall f g a b a' b'. Arrow f @@ -220,6 +220,9 @@ zipWithQ fn queueA queueB = case (queueA, queueB) of -> ConsQ (trA' `fn` trB') (zipWithQ fn queueA' queueB') +-- +-- Internal API +-- exec :: ListTr f b c -> ListTr (Op f) b a -> ListTr f b x -> Queue f a c exec xs ys (ConsTr _ t) = Queue xs ys t