on master help sign in
Add some type annotations to Automaton.elm
e0b7d26evancz
core-elm/Automaton.elm+15−27
@@ -3,50 +3,30 @@ module Automaton where
3
3
4data Automaton a b = Automaton (a -> (b, Automaton a b))
4data Automaton a b = Automaton (a -> (b, Automaton a b))
5
5
6−
7{--- API possibilies: All names and types are up for debate!
6{--- API possibilies: All names and types are up for debate!
8−
9−run :: Automaton a b -> Signal a -> Signal b
10−run :: OrderedContainer c => Automaton a b -> c a -> c b
11−
12−step :: a -> Automaton a b -> (b, Automaton a b)
13−
14−
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
17−
18−combine :: [Automaton a b] -> Automaton a [b]
19−combine :: Container c => c (Automaton a b) -> Automaton a (c b)
20−
21−
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
25−
26−count :: Automaton a Int
27−
28−draggable :: Form -> Automaton (Bool,(Int,Int)) Form
29−
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
32−
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
35−
36--}
13--}
37
14
38
15
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
41
19
20+step : Automaton a b -> a -> (b, Automaton a b)
42step (Automaton m) a = m a
21step (Automaton m) a = m a
43
22
44
23
45a1 >>> a2 =
24a1 >>> a2 =
46− let { Automaton m1 = a1 ; Automaton m2 = a2 } in
25+ let Automaton m1 = a1
26+ Automaton m2 = a2
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'))
50
30
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
56
36
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'))
60
41
42+pure : (a -> b) -> Automaton a b
61pure f = Automaton (\x -> (f x, pure f))
43pure f = Automaton (\x -> (f x, pure f))
44+
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))
47+
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))
64
50
51+count : Automaton a Int
65count = init 0 (\_ c -> c + 1)
52count = init 0 (\_ c -> c + 1)
66
53
67
54
@@ -80,6 +67,7 @@ stepDrag (press,pos) (ds,form) =
80 (form', (Listen,form')))
67 (form', (Listen,form')))
81 }
68 }
82
69
70+draggable : Form -> Automaton (Bool,(Int,Int)) Form
83draggable form = init' (Listen,form) stepDrag
71draggable form = init' (Listen,form) stepDrag
84
72
85
73