on master help sign in
Get Matrix2D and Signal compiling
ff67c66Evan Czaplicki
compiler/Type/Environment.hs+2−1
@@ -45,7 +45,8 @@ makeTypes datatypes =
45 builtins :: [(String,Int)]
45 builtins :: [(String,Int)]
46 builtins = concat [ map tuple [0..9]
46 builtins = concat [ map tuple [0..9]
47 , kind 1 ["_List","Maybe","Signal"]
47 , kind 1 ["_List","Maybe","Signal"]
48− , kind 0 ["Int","Float","Char","Bool","Element","Text","Color","Order"]
48+ , kind 0 ["Int","Float","Char","Bool","Element","Text"
49+ ,"Color","Order","Matrix2D"]
49 ]
50 ]
50
51
51
52
libraries/Matrix2D.elm+9−5
@@ -1,13 +1,14 @@
1
1
2module Matrix2D where
2module Matrix2D where
3
3
4−import Native.Matrix2D as M
4+import Native.Matrix2D as Native
5
5
6-- Create an identity matrix.
6-- Create an identity matrix.
7--
7--
8-- / 1 0 \\
8-- / 1 0 \\
9-- \\ 0 1 /
9-- \\ 0 1 /
10−identity : Matrix2D
10+identity : Matrix2D
11+identity = Native.identity
11
12
12-- Creates an arbitrary matrix. This lets you create scales, shears, reflections,
13-- Creates an arbitrary matrix. This lets you create scales, shears, reflections,
13-- translations, or any other 2D transform.
14-- translations, or any other 2D transform.
@@ -18,14 +19,16 @@ identity : Matrix2D
18-- \\ c d /
19-- \\ c d /
19--
20--
20-- And `dx` and `dy` are the translation values.
21-- And `dx` and `dy` are the translation values.
21−matrix : Float -> Float -> Float -> Float -> Float -> Float -> Matrix2D
22+matrix : Float -> Float -> Float -> Float -> Float -> Float -> Matrix2D
23+matrix = Native.matrix
22
24
23-- Creates a [rotation matrix](http://en.wikipedia.org/wiki/Rotation_matrix).
25-- Creates a [rotation matrix](http://en.wikipedia.org/wiki/Rotation_matrix).
24-- Given an angle t, it creates a counterclockwise rotation matrix:
26-- Given an angle t, it creates a counterclockwise rotation matrix:
25--
27--
26-- / cos t -sin t \\
28-- / cos t -sin t \\
27-- \\ sin t cos t /
29-- \\ sin t cos t /
28−rotation : Float -> Matrix2D
30+rotation : Float -> Matrix2D
31+rotation = Native.rotation
29
32
30-- Multiplies two matrices together:
33-- Multiplies two matrices together:
31--
34--
@@ -33,4 +36,5 @@ rotation : Float -> Matrix2D
33--
36--
34-- / a11 a12 \\ . / b11 b12 \\
37-- / a11 a12 \\ . / b11 b12 \\
35-- \\ a21 a22 / \\ b21 b22 /
38-- \\ a21 a22 / \\ b21 b22 /
36−multiply : Matrix2D -> Matrix2D -> Matrix2D
39+multiply : Matrix2D -> Matrix2D -> Matrix2D
40+multiply = Native.multiply
libraries/Signal.elm+31−3
@@ -7,46 +7,64 @@
7-- Note: There are lift functions up to `lift8`.
7-- Note: There are lift functions up to `lift8`.
8module Signal where
8module Signal where
9
9
10−import Native.Signal as S
10+import Native.Signal as Native
11−import List as L
11+import List (foldr)
12
12
13-- Create a constant signal that never changes.
13-- Create a constant signal that never changes.
14constant : a -> Signal a
14constant : a -> Signal a
15+constant = Native.constant
15
16
16-- Transform a signal with a given function.
17-- Transform a signal with a given function.
17lift : (a -> b) -> Signal a -> Signal b
18lift : (a -> b) -> Signal a -> Signal b
19+lift = Native.lift
18
20
19-- Combine two signals with a given function.
21-- Combine two signals with a given function.
20lift2 : (a -> b -> c) -> Signal a -> Signal b -> Signal c
22lift2 : (a -> b -> c) -> Signal a -> Signal b -> Signal c
23+lift2 = Native.lift2
21
24
22-- Combine three signals with a given function.
25-- Combine three signals with a given function.
23lift3 : (a -> b -> c -> d) -> Signal a -> Signal b -> Signal c -> Signal d
26lift3 : (a -> b -> c -> d) -> Signal a -> Signal b -> Signal c -> Signal d
27+lift3 = Native.lift3
28+
24lift4 : (a -> b -> c -> d -> e) -> Signal a -> Signal b -> Signal c -> Signal d -> Signal e
29lift4 : (a -> b -> c -> d -> e) -> Signal a -> Signal b -> Signal c -> Signal d -> Signal e
30+lift4 = Native.lift4
31+
25lift5 : (a -> b -> c -> d -> e -> f) -> Signal a -> Signal b -> Signal c -> Signal d -> Signal e -> Signal f
32lift5 : (a -> b -> c -> d -> e -> f) -> Signal a -> Signal b -> Signal c -> Signal d -> Signal e -> Signal f
33+lift5 = Native.lift5
34+
26lift6 : (a -> b -> c -> d -> e -> f -> g)
35lift6 : (a -> b -> c -> d -> e -> f -> g)
27 -> Signal a -> Signal b -> Signal c -> Signal d -> Signal e -> Signal f -> Signal g
36 -> Signal a -> Signal b -> Signal c -> Signal d -> Signal e -> Signal f -> Signal g
37+lift6 = Native.lift6
38+
28lift7 : (a -> b -> c -> d -> e -> f -> g -> h)
39lift7 : (a -> b -> c -> d -> e -> f -> g -> h)
29 -> Signal a -> Signal b -> Signal c -> Signal d -> Signal e -> Signal f -> Signal g -> Signal h
40 -> Signal a -> Signal b -> Signal c -> Signal d -> Signal e -> Signal f -> Signal g -> Signal h
41+lift7 = Native.lift7
42+
30lift8 : (a -> b -> c -> d -> e -> f -> g -> h -> i)
43lift8 : (a -> b -> c -> d -> e -> f -> g -> h -> i)
31 -> Signal a -> Signal b -> Signal c -> Signal d -> Signal e -> Signal f -> Signal g -> Signal h -> Signal i
44 -> Signal a -> Signal b -> Signal c -> Signal d -> Signal e -> Signal f -> Signal g -> Signal h -> Signal i
45+lift8 = Native.lift8
46+
32
47
33-- Create a past-dependent signal. Each value given on the input signal will
48-- Create a past-dependent signal. Each value given on the input signal will
34-- be accumulated, producing a new output value.
49-- be accumulated, producing a new output value.
35--
50--
36-- For instance, `(foldp (\\t acc -> acc + 1) 0 (Time.every second))` increments every second.
51-- For instance, `(foldp (\\t acc -> acc + 1) 0 (Time.every second))` increments every second.
37foldp : (a -> b -> b) -> b -> Signal a -> Signal b
52foldp : (a -> b -> b) -> b -> Signal a -> Signal b
53+foldp = Native.foldp
38
54
39-- Merge two signals into one, biased towards the first signal if both signals
55-- Merge two signals into one, biased towards the first signal if both signals
40-- update at the same time.
56-- update at the same time.
41merge : Signal a -> Signal a -> Signal a
57merge : Signal a -> Signal a -> Signal a
58+merge = Native.merge
42
59
43-- Merge many signals into one, biased towards the left-most signal if multiple
60-- Merge many signals into one, biased towards the left-most signal if multiple
44-- signals update simultaneously.
61-- signals update simultaneously.
45merges : [Signal a] -> Signal a
62merges : [Signal a] -> Signal a
63+merges = Native.merges
46
64
47-- Combine a list of signals into a signal of lists.
65-- Combine a list of signals into a signal of lists.
48combine : [Signal a] -> Signal [a]
66combine : [Signal a] -> Signal [a]
49−combine = L.foldr (S.lift2 (::)) (S.constant [])
67+combine = foldr (Native.lift2 (::)) (Native.constant [])
50
68
51 -- Merge two signals into one, but distinguishing the values by marking the first
69 -- Merge two signals into one, but distinguishing the values by marking the first
52 -- signal as `Left` and the second signal as `Right`. This allows you to easily
70 -- signal as `Left` and the second signal as `Right`. This allows you to easily
@@ -55,19 +73,23 @@ combine = L.foldr (S.lift2 (::)) (S.constant [])
55
73
56-- Count the number of events that have occured.
74-- Count the number of events that have occured.
57count : Signal a -> Signal Int
75count : Signal a -> Signal Int
76+count = Native.count
58
77
59-- Count the number of events that have occured that satisfy a given predicate.
78-- Count the number of events that have occured that satisfy a given predicate.
60countIf : (a -> Bool) -> Signal a -> Signal Int
79countIf : (a -> Bool) -> Signal a -> Signal Int
80+countIf = Native.countIf
61
81
62-- Keep only events that satisfy the given predicate. Elm does not allow
82-- Keep only events that satisfy the given predicate. Elm does not allow
63-- undefined signals, so a base case must be provided in case the predicate is
83-- undefined signals, so a base case must be provided in case the predicate is
64-- never satisfied.
84-- never satisfied.
65keepIf : (a -> Bool) -> a -> Signal a -> Signal a
85keepIf : (a -> Bool) -> a -> Signal a -> Signal a
86+keepIf = Native.keepIf
66
87
67-- Drop events that satisfy the given predicate. Elm does not allow undefined
88-- Drop events that satisfy the given predicate. Elm does not allow undefined
68-- signals, so a base case must be provided in case the predicate is never
89-- signals, so a base case must be provided in case the predicate is never
69-- satisfied.
90-- satisfied.
70dropIf : (a -> Bool) -> a -> Signal a -> Signal a
91dropIf : (a -> Bool) -> a -> Signal a -> Signal a
92+dropIf = Native.dropIf
71
93
72-- Keep events only when the first signal is true. When the first signal becomes
94-- Keep events only when the first signal is true. When the first signal becomes
73-- true, the most recent value of the second signal will be propagated. Until
95-- true, the most recent value of the second signal will be propagated. Until
@@ -75,6 +97,7 @@ dropIf : (a -> Bool) -> a -> Signal a -> Signal a
75-- not allow undefined signals, so a base case must be provided in case the first
97-- not allow undefined signals, so a base case must be provided in case the first
76-- signal is never true.
98-- signal is never true.
77keepWhen : Signal Bool -> a -> Signal a -> Signal a
99keepWhen : Signal Bool -> a -> Signal a -> Signal a
100+keepWhen = Native.keepWhen
78
101
79-- Drop events when the first signal is true. When the first signal becomes false,
102-- Drop events when the first signal is true. When the first signal becomes false,
80-- the most recent value of the second signal will be propagated. Until the first
103-- the most recent value of the second signal will be propagated. Until the first
@@ -82,22 +105,26 @@ keepWhen : Signal Bool -> a -> Signal a -> Signal a
82-- undefined signals, so a base case must be provided in case the first signal is
105-- undefined signals, so a base case must be provided in case the first signal is
83-- always true.
106-- always true.
84dropWhen : Signal Bool -> a -> Signal a -> Signal a
107dropWhen : Signal Bool -> a -> Signal a -> Signal a
108+dropWhen = Native.dropWhen
85
109
86-- Drop sequential repeated values. For example, if a signal produces the
110-- Drop sequential repeated values. For example, if a signal produces the
87-- sequence `[1,1,2,2,1]`, it becomes `[1,2,1]` by dropping the values that
111-- sequence `[1,1,2,2,1]`, it becomes `[1,2,1]` by dropping the values that
88-- are the same as the previous value.
112-- are the same as the previous value.
89dropRepeats : Signal a -> Signal a
113dropRepeats : Signal a -> Signal a
114+dropRepeats = Native.dropRepeats
90
115
91-- Sample from the second input every time an event occurs on the first input.
116-- Sample from the second input every time an event occurs on the first input.
92-- For example, `(sampleOn clicks (every second))` will give the approximate
117-- For example, `(sampleOn clicks (every second))` will give the approximate
93-- time of the latest click.
118-- time of the latest click.
94sampleOn : Signal a -> Signal b -> Signal b
119sampleOn : Signal a -> Signal b -> Signal b
120+sampleOn = Native.sampleOn
95
121
96-- An alias for `lift`. A prettier way to apply a
122-- An alias for `lift`. A prettier way to apply a
97-- function to the current value of a signal.
123-- function to the current value of a signal.
98--
124--
99-- lift f signal == f <~ signal
125-- lift f signal == f <~ signal
100(<~) : (a -> b) -> Signal a -> Signal b
126(<~) : (a -> b) -> Signal a -> Signal b
127+(<~) = Native.lift
101
128
102-- Signal application. This takes two signals, holding a function and
129-- Signal application. This takes two signals, holding a function and
103-- a value. It applies the current function to the current value.
130-- a value. It applies the current function to the current value.
@@ -107,3 +134,4 @@ sampleOn : Signal a -> Signal b -> Signal b
107-- scene <~ Window.dimensions ~ Mouse.position
134-- scene <~ Window.dimensions ~ Mouse.position
108-- lift2 scene Window.dimensions Mouse.position
135-- lift2 scene Window.dimensions Mouse.position
109(~) : Signal (a -> b) -> Signal a -> Signal b
136(~) : Signal (a -> b) -> Signal a -> Signal b
137+(~) = Native.lift2 (\f x -> f x)
libraries/Time.elm+9−3
@@ -1,7 +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 Native.Time as T
4+import Native.Time as Native
5
5
6-- Type alias to make it clearer when you are working with time values.
6-- Type alias to make it clearer when you are working with time values.
7-- Using the `Time` constants instead of raw numbers is very highly recommended.
7-- Using the `Time` constants instead of raw numbers is very highly recommended.
@@ -38,18 +38,21 @@ inHours t = t / hour
38-- gives a sequence of time deltas as quickly as possible until it reaches
38-- gives a sequence of time deltas as quickly as possible until it reaches
39-- the desired FPS. A time delta is the time between the last frame and the
39-- the desired FPS. A time delta is the time between the last frame and the
40-- current frame.
40-- current frame.
41−fps : Number a -> Signal Time
41+fps : number -> Signal Time
42+fps = Native.fps
42
43
43-- Same as the fps function, but you can turn it on and off. Allows you
44-- Same as the fps function, but you can turn it on and off. Allows you
44-- to do brief animations based on user input without major inefficiencies.
45-- to do brief animations based on user input without major inefficiencies.
45-- The first time delta after a pause is always zero, no matter how long
46-- The first time delta after a pause is always zero, no matter how long
46-- the pause was. This way summing the deltas will actually give the amount
47-- the pause was. This way summing the deltas will actually give the amount
47-- of time that the output signal has been running.
48-- of time that the output signal has been running.
48−fpsWhen : Number a -> Signal Bool -> Signal Time
49+fpsWhen : number -> Signal Bool -> Signal Time
50+fpsWhen = Native.fpsWhen
49
51
50-- Takes a time interval t. The resulting signal is the current time,
52-- Takes a time interval t. The resulting signal is the current time,
51-- updated every t.
53-- updated every t.
52every : Time -> Signal Time
54every : Time -> Signal Time
55+every = Native.every
53
56
54-- Takes a time `t` and any signal. The resulting boolean signal
57-- Takes a time `t` and any signal. The resulting boolean signal
55-- is true for time `t` after every event on the input signal.
58-- is true for time `t` after every event on the input signal.
@@ -57,13 +60,16 @@ every : Time -> Signal Time
57-- that is true for one second after each mouse click and false
60-- that is true for one second after each mouse click and false
58-- otherwise.
61-- otherwise.
59since : Time -> Signal a -> Signal Bool
62since : Time -> Signal a -> Signal Bool
63+since = Native.since
60
64
61-- Add a timestamp to any signal. Timestamps increase monotonically. Each
65-- Add a timestamp to any signal. Timestamps increase monotonically. Each
62-- timestamp is related to a specfic event, so `Mouse.x` and `Mouse.y` will
66-- timestamp is related to a specfic event, so `Mouse.x` and `Mouse.y` will
63-- always have the same timestamp because they both rely on the same
67-- always have the same timestamp because they both rely on the same
64-- underlying event.
68-- underlying event.
65timestamp : Signal a -> Signal (Time, a)
69timestamp : Signal a -> Signal (Time, a)
70+timestamp = Native.timestamp
66
71
67-- Delay a signal by a certain amount of time. So `(delay second Mouse.clicks)`
72-- Delay a signal by a certain amount of time. So `(delay second Mouse.clicks)`
68-- will update one second later than any mouse click.
73-- will update one second later than any mouse click.
69delay : Time -> Signal a -> Signal a
74delay : Time -> Signal a -> Signal a
75+delay = Native.delay