Wed Oct 19 11:34:07 EDT 2011
Implemented the signal fold in an abstract way. See for list instance
below. The idea is to also implement this on 1. Concrete syntax
elements and 2. maybe on a higher level like TML directly? Currently
it's a bit too abstract so I probably need some playing first..
-- a: arrow (stream abstraction as an arrow between i and o)
-- s: recursion state
-- i: input stream element
-- o: output stream element
class Arrow a => SigFold a s i o where
sigFold :: s -> ((s,i) -> (s,o)) -> a i o
-- Represent as functions on infinite lists.
data ListOp i o = ListOp ([i] -> [o])
instance Category ListOp where
id = ListOp $ id
(ListOp a) . (ListOp b) = ListOp $ a . b
instance Arrow ListOp where
arr = ListOp . map
first = undefined -- ??
instance SigFold ListOp s i o where
sigFold s0 f = ListOp $ fa s0 where
fa s (i:is) = (o:os) where
(s',o) = f (s, i)
os = fa s' is
intgr (s, i) = (s', s') where s' = s + i
intgr' = sigFold 0 intgr
Maybe the arrow instance isn't necessary.. Category might be enough.
Actually, I don't even use Category. This is really just a