@@ -4,8 +4,6 @@ module Automaton where
4data Automaton a b = Automaton (a -> (b, Automaton a b))
4data Automaton a b = Automaton (a -> (b, Automaton a b))
6{--- API possibilies: All names and types are up for debate!
6{--- API possibilies: All names and types are up for debate!
7−(>>>) :: Automaton a b -> Automaton b c -> Automaton a c
8−(<<<) :: Automaton b c -> Automaton a b -> Automaton a c
9(^>>) :: (a -> b) -> Automaton b c -> Automaton a c
7(^>>) :: (a -> b) -> Automaton b c -> Automaton a c
10(>>^) :: Automaton a b -> (b -> c) -> Automaton a c
8(>>^) :: Automaton a b -> (b -> c) -> Automaton a c
11(^<<) :: (b -> c) -> Automaton a b -> Automaton a c
9(^<<) :: (b -> c) -> Automaton a b -> Automaton a c
@@ -21,6 +19,7 @@ step : Automaton a b -> a -> (b, Automaton a b)
21step (Automaton m) a = m a
19step (Automaton m) a = m a
22+(>>>) : Automaton a b -> Automaton b c -> Automaton a c
24a1 >>> a2 =
23a1 >>> a2 =
25 let Automaton m1 = a1
24 let Automaton m1 = a1
26 Automaton m2 = a2
25 Automaton m2 = a2
@@ -28,11 +27,8 @@ a1 >>> a2 =
28 (c,m2') = m2 b
27 (c,m2') = m2 b
29 in (c, m1' >>> m2'))
28 in (c, m1' >>> m2'))
30+(<<<) : Automaton b c -> Automaton a b -> Automaton a c
31a2 <<< a1 = a1 >>> a2
31a2 <<< a1 = a1 >>> a2
32−f ^>> a = pure f >>> a
33−a >>^ f = a >>> pure f
34−f ^<< a = a >>> pure f
35−a <<^ f = pure f >>> a
37combine : [Automaton a b] -> Automaton a [b]
33combine : [Automaton a b] -> Automaton a [b]
38combine autos =
34combine autos =
@@ -59,13 +55,14 @@ vecSub (x1,y1) (x2,y2) = (x1-x2,y1-y2)
59stepDrag (press,pos) (ds,form) =
55stepDrag (press,pos) (ds,form) =
60 let wrap ds' = (form, (ds',form)) in
56 let wrap ds' = (form, (ds',form)) in
61 case ds of
57 case ds of
62− { Listen -> wrap (if not press then Listen else
58+ Listen -> wrap (if | not press -> Listen
63− if pos `isWithin` form then DragFrom pos else Ignore)
59+ | pos `isWithin` form -> DragFrom pos
60+ | otherwise -> Ignore)
64− ; Ignore -> wrap (if press then Ignore else Listen)
61+ Ignore -> wrap (if press then Ignore else Listen)
65− ; DragFrom p0 -> if press then (uncurry move (vecSub pos p0) form, (DragFrom p0, form))
63+ if press then (uncurry move (vecSub pos p0) form, (DragFrom p0, form))
66− else (let form' = uncurry move (vecSub pos p0) form in
64+ else (let form' = uncurry move (vecSub pos p0) form in
67− (form', (Listen,form')))
65+ (form', (Listen,form')))
70draggable : Form -> Automaton (Bool,(Int,Int)) Form
67draggable : Form -> Automaton (Bool,(Int,Int)) Form
71draggable form = init' (Listen,form) stepDrag
68draggable form = init' (Listen,form) stepDrag