@@ -9,41 +9,63 @@ data Automaton a b = Automaton (a -> (b, Automaton a b))
99run :: Automaton a b -> Signal a -> Signal b
1010run :: OrderedContainer c => Automaton a b -> c a -> c b
1111
12−compose :: Automaton a b -> Automaton b c -> Automaton a c
12+(>>>) :: Automaton a b -> Automaton b c -> Automaton a c
13+(<<<) :: Automaton b c -> Automaton a b -> Automaton a c
1314
1415combine :: [Automaton a b] -> Automaton a [b]
1516combine :: Container c => c (Automaton a b) -> Automaton a (c b)
1617
1718
18−pure :: (a -> b) -> Automaton a b
19+pure :: (a -> b) -> Automaton a b
1920init :: b -> (a -> b -> b) -> Automaton a b
2021init' :: s -> (a -> s -> (b,s)) -> Automaton a b
2122
2223count :: Automaton a Int
2324
2425draggable :: Form -> Automaton (Bool,(Int,Int)) Form
25−foo :: (a -> b) -> Automaton b c -> Automaton a c
26−bar :: Automaton a b -> (b -> c) -> Automaton a c
26+
27+(^>>) :: (a -> b) -> Automaton b c -> Automaton a c
28+(>>^) :: Automaton a b -> (b -> c) -> Automaton a c
29+
30+(^<<) :: (b -> c) -> Automaton a b -> Automaton a c
31+(<<^) :: Automaton b c -> (a -> b) -> Automaton a c
2732
2833--}
2934
3035
3136run (Automaton m0) input =
32− lift fst $ foldp1 (\a (b, Automaton m) -> m a) m0 input
37+ lift fst $ foldp' (\a (b, Automaton m) -> m a) m0 input
3338
34−compose (Automaton m1) (Automaton m2) =
35− Automaton
39+a1 >>> a2 =
40+ let { Automaton m1 = a1 ; Automaton m2 = a2 } in
41+ Automaton
3642 (\a -> let (b,m1') = m1 a in
37− let (c,m2') = m2 b in (c, compose (Automaton m1') (Automaton m2')))
43+ let (c,m2') = m2 b in (c, Automaton m1' >>> Automaton m2'))
44+
45+a2 <<< a1 = a1 >>> a2
46+f ^>> a = pure f >>> a
47+a >>^ f = a >>> pure f
48+f ^<< a = a >>> pure f
49+a <<^ f = pure f >>> a
3850
3951combine autos =
40− Automaton (\a -> let (bs,autos') = unzip $ map (\m -> m a) autos in
41− (bs, combine autos'))
52+ Automaton (\a -> let (bs,autos') = unzip $ map (\m -> m a) autos in
53+ (bs, combine autos'))
54+
55+pure f = Automaton (\x -> (f x, pure f))
56+init s step = Automaton (\a -> let s' = step a s in (s', init s' step))
57+init' s step = Automaton (\a -> let (b,s') = step a s in (b , init s' step))
58+
59+count = init 0 (\_ c -> c + 1)
60+
61+
62+
63+{--- See the following papers for ideas on how to make this faster:
4264
43−init s step =
44− Automaton (\a -> let s' = step a s in (s', init s' step))
65+- Functional Reactive Programming, Continued
66+- Causal commutative arrows and their optimization
4567
46−init' s step =
47− Automaton (\a -> let (b,s') = step a s in (b, init s' step))
68+Speeding things up is a really low priority. Language features and
69+libraries with nice APIs and are way more important!
4870
49−count = init 0 (\_ c -> c + 1)
71+--}