@@ -1,7 +1,12 @@
2module Automaton where
2module Automaton where
4−data Automaton inp out = Automaton (inp -> (out, Automaton inp out))
4+data Automaton a b = Automaton (a -> (b, Automaton a b))
6+-- Maybe once there are infix type constructors this could be
8+-- or something like that.
6{--- API possibilies
11{--- API possibilies
@@ -12,13 +17,34 @@ How to run an automaton (some require typeclasses):
13run :: Automaton a b -> Signal a -> Signal b
18run :: Automaton a b -> Signal a -> Signal b
14run :: OrderedContainer c => Automaton a b -> c a -> c b
19run :: OrderedContainer c => Automaton a b -> c a -> c b
15−run :: Functor f => Automaton a b -> f a -> f b
18compose :: Automaton a b -> Automaton b c -> Automaton a c
21compose :: Automaton a b -> Automaton b c -> Automaton a c
19combine :: [Automaton a b] -> Automaton a [b]
23combine :: [Automaton a b] -> Automaton a [b]
24+combine :: Container c => c (Automaton a b) -> Automaton a (c b)
21init :: b -> (a -> b -> b) -> Automaton a b
26init :: b -> (a -> b -> b) -> Automaton a b
22init' :: s -> (a -> s -> (b,s)) -> Automaton a b
27init' :: s -> (a -> s -> (b,s)) -> Automaton a b
29+draggable :: Form -> Automaton (Bool,(Int,Int)) Form
34+run (Automaton m0) input =
35+ lift fst $ foldp1 (\a (b, Automaton m) -> m a) m0 input
37+compose (Automaton m1) (Automaton m2) =
39+ (\a -> let (b,m1') = m1 a in
40+ let (c,m2') = m2 b in (c, compose (Automaton m1') (Automaton m2')))
43+ Automaton (\a -> let (bs,autos') = unzip $ map (\m -> m a) autos in
44+ (bs, combine autos'))
47+ Automaton (\a -> let s' = step a s in (s', init s' step))
50+ Automaton (\a -> let (b,s') = step a s in (b, init s' step))