on master help sign in
Get Automaton compiling
d7cdaceEvan Czaplicki
libraries/Automaton.elm+4−3
@@ -4,8 +4,9 @@
4-- it can be used.
4-- it can be used.
5module Automaton where
5module Automaton where
6
6
7+import open Basics
7import Signal (lift,foldp)
8import Signal (lift,foldp)
8−import List (reverse)
9+import open List
9import Maybe (Just, Nothing)
10import Maybe (Just, Nothing)
10
11
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)
19
20
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))
40
41
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
libraries/Time.elm+1
@@ -1,6 +1,7 @@
1-- Library for working with time. Type `Time` represents some number of milliseconds.
1-- Library for working with time. Type `Time` represents some number of milliseconds.
2module Time where
2module Time where
3
3
4+import open Basics
4import Native.Time as Native
5import Native.Time as Native
5
6
6-- Type alias to make it clearer when you are working with time values.
7-- Type alias to make it clearer when you are working with time values.