on master help sign in
Add some type annotations to Automaton.elm
commite0b7d2668edf7e3782857de4d1b2f0aaa8f35611 authorevancz <info@elm-lang.org> dateTue 5 Feb 2013, 22:26 (14 years ago) parent55b3d39
1 file changed+15−27
core-elm/Automaton.elm+15−27
core-elm/Automaton.elm+15−27
@@ -3,50 +3,30 @@ module Automaton where
33
44data Automaton a b = Automaton (a -> (b, Automaton a b))
55
6−
76{--- 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−
157(>>>) :: Automaton a b -> Automaton b c -> Automaton a c
168(<<<) :: 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−
309(^>>) :: (a -> b) -> Automaton b c -> Automaton a c
3110(>>^) :: Automaton a b -> (b -> c) -> Automaton a c
32−
3311(^<<) :: (b -> c) -> Automaton a b -> Automaton a c
3412(<<^) :: Automaton b c -> (a -> b) -> Automaton a c
35−
3613--}
3714
3815
16+run : Automaton a b -> Signal a -> Signal b
3917run (Automaton m0) input =
4018 lift fst $ foldp' (\a (b, Automaton m) -> m a) m0 input
4119
20+step : Automaton a b -> a -> (b, Automaton a b)
4221step (Automaton m) a = m a
4322
4423
4524a1 >>> a2 =
46− let { Automaton m1 = a1 ; Automaton m2 = a2 } in
47− Automaton
48− (\a -> let (b,m1') = m1 a in
49− let (c,m2') = m2 b in (c, m1' >>> m2'))
25+ let Automaton m1 = a1
26+ Automaton m2 = a2
27+ in Automaton (\a -> let (b,m1') = m1 a
28+ (c,m2') = m2 b
29+ in (c, m1' >>> m2'))
5030
5131a2 <<< a1 = a1 >>> a2
5232f ^>> a = pure f >>> a
@@ -54,14 +34,21 @@ a >>^ f = a >>> pure f
5434f ^<< a = a >>> pure f
5535a <<^ f = pure f >>> a
5636
37+combine : [Automaton a b] -> Automaton a [b]
5738combine autos =
5839 Automaton (\a -> let (bs,autos') = unzip $ map (\(Automaton m) -> m a) autos in
5940 (bs, combine autos'))
6041
42+pure : (a -> b) -> Automaton a b
6143pure f = Automaton (\x -> (f x, pure f))
44+
45+init : b -> (a -> b -> b) -> Automaton a b
6246init 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
6349init' s step = Automaton (\a -> let (b,s') = step a s in (b , init' s' step))
6450
51+count : Automaton a Int
6552count = init 0 (\_ c -> c + 1)
6653
6754
@@ -80,6 +67,7 @@ stepDrag (press,pos) (ds,form) =
8067 (form', (Listen,form')))
8168 }
8269
70+draggable : Form -> Automaton (Bool,(Int,Int)) Form
8371draggable form = init' (Listen,form) stepDrag
8472
8573