@@ -4,8 +4,9 @@
4-- it can be used.
4-- it can be used.
5module Automaton where
5module Automaton where
7import Signal (lift,foldp)
8import Signal (lift,foldp)
8−import List (reverse)
9+import open List
9import Maybe (Just, Nothing)
10import Maybe (Just, Nothing)
11data Automaton a b = Step (a -> (Automaton a b, b))
12data Automaton a b = Step (a -> (Automaton a b, b))
@@ -15,7 +16,7 @@ data Automaton a b = Step (a -> (Automaton a b, b))
15run : Automaton a b -> b -> Signal a -> Signal b
16run : Automaton a b -> b -> Signal a -> Signal b
16run auto base inputs =
17run auto base inputs =
17 let step a (Step f, _) = f a
18 let step a (Step f, _) = f a
18− in lift (\(x,y) -> y) <| foldp step (auto,base) inputs
19+ in lift (\(x,y) -> y) (foldp step (auto,base) inputs)
20-- Step an automaton forward once with a given input.
21-- Step an automaton forward once with a given input.
21step : a -> Automaton a b -> (Automaton a b, b)
22step : a -> Automaton a b -> (Automaton a b, b)
@@ -35,7 +36,7 @@ g <<< f = f >>> g
35-- Combine a list of automatons into a single automaton that produces a list.
36-- Combine a list of automatons into a single automaton that produces a list.
36combine : [Automaton a b] -> Automaton a [b]
37combine : [Automaton a b] -> Automaton a [b]
37combine autos =
38combine autos =
38− Step (\a -> let (autos', bs) = unzip $ map (step a) autos
39+ Step (\a -> let (autos', bs) = unzip (map (step a) autos)
39 in (combine autos', bs))
40 in (combine autos', bs))
41-- Create an automaton with no memory. It just applies the given function to
42-- Create an automaton with no memory. It just applies the given function to