@@ -3,50 +3,30 @@ module Automaton where
4data Automaton a b = Automaton (a -> (b, Automaton a b))
4data Automaton a b = Automaton (a -> (b, Automaton a b))
7{--- API possibilies: All names and types are up for debate!
6{--- API possibilies: All names and types are up for debate!
9−run :: Automaton a b -> Signal a -> Signal b
10−run :: OrderedContainer c => Automaton a b -> c a -> c b
12−step :: a -> Automaton a b -> (b, Automaton a b)
15(>>>) :: Automaton a b -> Automaton b c -> Automaton a c
7(>>>) :: Automaton a b -> Automaton b c -> Automaton a c
16(<<<) :: Automaton b c -> Automaton a b -> Automaton a c
8(<<<) :: Automaton b c -> Automaton a b -> Automaton a c
18−combine :: [Automaton a b] -> Automaton a [b]
19−combine :: Container c => c (Automaton a b) -> Automaton a (c b)
22−pure :: (a -> b) -> Automaton a b
23−init :: b -> (a -> b -> b) -> Automaton a b
24−init' :: s -> (a -> s -> (b,s)) -> Automaton a b
26−count :: Automaton a Int
28−draggable :: Form -> Automaton (Bool,(Int,Int)) Form
30(^>>) :: (a -> b) -> Automaton b c -> Automaton a c
9(^>>) :: (a -> b) -> Automaton b c -> Automaton a c
31(>>^) :: Automaton a b -> (b -> c) -> Automaton a c
10(>>^) :: Automaton a b -> (b -> c) -> Automaton a c
33(^<<) :: (b -> c) -> Automaton a b -> Automaton a c
11(^<<) :: (b -> c) -> Automaton a b -> Automaton a c
34(<<^) :: Automaton b c -> (a -> b) -> Automaton a c
12(<<^) :: Automaton b c -> (a -> b) -> Automaton a c
16+run : Automaton a b -> Signal a -> Signal b
39run (Automaton m0) input =
17run (Automaton m0) input =
40 lift fst $ foldp' (\a (b, Automaton m) -> m a) m0 input
18 lift fst $ foldp' (\a (b, Automaton m) -> m a) m0 input
20+step : Automaton a b -> a -> (b, Automaton a b)
42step (Automaton m) a = m a
21step (Automaton m) a = m a
45a1 >>> a2 =
24a1 >>> a2 =
46− let { Automaton m1 = a1 ; Automaton m2 = a2 } in
25+ let Automaton m1 = a1
47− Automaton
27+ in Automaton (\a -> let (b,m1') = m1 a
48− (\a -> let (b,m1') = m1 a in
28+ (c,m2') = m2 b
49− let (c,m2') = m2 b in (c, m1' >>> m2'))
29+ in (c, m1' >>> m2'))
51a2 <<< a1 = a1 >>> a2
31a2 <<< a1 = a1 >>> a2
52f ^>> a = pure f >>> a
32f ^>> a = pure f >>> a
@@ -54,14 +34,21 @@ a >>^ f = a >>> pure f
54f ^<< a = a >>> pure f
34f ^<< a = a >>> pure f
55a <<^ f = pure f >>> a
35a <<^ f = pure f >>> a
37+combine : [Automaton a b] -> Automaton a [b]
57combine autos =
38combine autos =
58 Automaton (\a -> let (bs,autos') = unzip $ map (\(Automaton m) -> m a) autos in
39 Automaton (\a -> let (bs,autos') = unzip $ map (\(Automaton m) -> m a) autos in
59 (bs, combine autos'))
40 (bs, combine autos'))
42+pure : (a -> b) -> Automaton a b
61pure f = Automaton (\x -> (f x, pure f))
43pure f = Automaton (\x -> (f x, pure f))
45+init : b -> (a -> b -> b) -> Automaton a b
62init s step = Automaton (\a -> let s' = step a s in (s', init s' step))
46init s step = Automaton (\a -> let s' = step a s in (s', init s' step))
48+init' : s -> (a -> s -> (b,s)) -> Automaton a b
63init' s step = Automaton (\a -> let (b,s') = step a s in (b , init' s' step))
49init' s step = Automaton (\a -> let (b,s') = step a s in (b , init' s' step))
51+count : Automaton a Int
65count = init 0 (\_ c -> c + 1)
52count = init 0 (\_ c -> c + 1)
@@ -80,6 +67,7 @@ stepDrag (press,pos) (ds,form) =
80 (form', (Listen,form')))
67 (form', (Listen,form')))
70+draggable : Form -> Automaton (Bool,(Int,Int)) Form
83draggable form = init' (Listen,form) stepDrag
71draggable form = init' (Listen,form) stepDrag