on master help sign in
Removed after and renamed before to andThen.
commit8544bb80f474f0acc9624417d398da19d463314f authorJeff Smits <jeff.smits@gmail.com> dateFri 6 Sep 2013, 10:02 (13 years ago) parent9823941
1 file changed+9−14
libraries/Automaton.elm+9−14
libraries/Automaton.elm+9−14
@@ -9,10 +9,8 @@ import Signal (lift,foldp,Signal)
99import open List
1010import Maybe (Just, Nothing)
1111
12−data Automaton input output =
13− Pure (input -> output)
14− | Stateful state (input -> state -> (output,state))
15−
12+data Automaton input output = Pure (input -> output)
13+ | Stateful state (input -> state -> (output,state))
1614
1715-- The basics
1816
@@ -21,8 +19,8 @@ pure: (i -> o) -> Automaton i o
2119pure = Pure
2220
2321-- AFRP name: >>>
24−before: Automaton i inter -> Automaton inter o -> Automaton i o
25−before first second =
22+andThen: Automaton i inter -> Automaton inter o -> Automaton i o
23+andThen first second =
2624 case first of
2725 Pure f -> case second of -- f is the function from first
2826 Pure s -> Pure (s . f) -- s is the function from second
@@ -84,26 +82,23 @@ hiddenState base fun = loop base (pure (\(i,s) ->
8482 let (o,s') = fun i s
8583 in (s',o)))
8684
87−after : Automaton inter o -> Automaton i inter -> Automaton i o
88−after g f = f `before` g
89−
9085-- AFRP name: second
9186extendUp: Automaton i o -> Automaton (extra,i) (extra,o)
9287extendUp auto =
9388 let swap (a, b) = (b, a)
94− in pure swap `before` extendDown auto `before` pure swap
89+ in pure swap `andThen` extendDown auto `andThen` pure swap
9590
9691-- (parallel composition)
9792pair: Automaton i1 o1 -> Automaton i2 o2 -> Automaton (i1,i2) (o1,o2)
98−pair f g = extendDown f `before` extendUp g
93+pair f g = extendDown f `andThen` extendUp g
9994
10095branch : Automaton i o1 -> Automaton i o2 -> Automaton i (o1,o2)
10196branch f g =
10297 let double = pure (\i -> (i,i))
103− in double `before` pair f g
98+ in double `andThen` pair f g
10499
105100combi: Automaton i o -> Automaton i [o] -> Automaton i [o]
106−combi a1 a2 = (a1 `branch` a2) `before` pure (uncurry (::))
101+combi a1 a2 = (a1 `branch` a2) `andThen` pure (uncurry (::))
107102
108103-- Combine a list of automatons into a single automaton that produces a list.
109104combine : [Automaton i o] -> Automaton i [o]
@@ -111,7 +106,7 @@ combine autos =
111106 let l = length autos
112107 in if l == 0
113108 then pure (\_ -> [])
114− else foldr combi (last autos `before` pure (\a -> [a])) (take (l-1) autos)
109+ else foldr combi (last autos `andThen` pure (\a -> [a])) (take (l-1) autos)
115110
116111
117112-- Examples of automata