on master help sign in
Get Matrix2D and Signal compiling
commitff67c667a0f3004f2be4b3af59c9eb0e30b985dc authorEvan Czaplicki <info@elm-lang.org> dateFri 26 Jul 2013, 00:33 (13 years ago) parentc19ccfe
4 files changed+51−12
compiler/Type/Environment.hs+2−1 libraries/Matrix2D.elm+9−5 libraries/Signal.elm+31−3 libraries/Time.elm+9−3
compiler/Type/Environment.hs+2−1
@@ -45,7 +45,8 @@ makeTypes datatypes =
4545 builtins :: [(String,Int)]
4646 builtins = concat [ map tuple [0..9]
4747 , 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"]
4950 ]
5051
5152
libraries/Matrix2D.elm+9−5
@@ -1,13 +1,14 @@
11
22module Matrix2D where
33
4−import Native.Matrix2D as M
4+import Native.Matrix2D as Native
55
66-- Create an identity matrix.
77--
88-- / 1 0 \\
99-- \\ 0 1 /
10−identity : Matrix2D
10+identity : Matrix2D
11+identity = Native.identity
1112
1213-- Creates an arbitrary matrix. This lets you create scales, shears, reflections,
1314-- translations, or any other 2D transform.
@@ -18,14 +19,16 @@ identity : Matrix2D
1819-- \\ c d /
1920--
2021-- 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
2224
2325-- Creates a [rotation matrix](http://en.wikipedia.org/wiki/Rotation_matrix).
2426-- Given an angle t, it creates a counterclockwise rotation matrix:
2527--
2628-- / cos t -sin t \\
2729-- \\ sin t cos t /
28−rotation : Float -> Matrix2D
30+rotation : Float -> Matrix2D
31+rotation = Native.rotation
2932
3033-- Multiplies two matrices together:
3134--
@@ -33,4 +36,5 @@ rotation : Float -> Matrix2D
3336--
3437-- / a11 a12 \\ . / b11 b12 \\
3538-- \\ 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 @@
77-- Note: There are lift functions up to `lift8`.
88module Signal where
99
10−import Native.Signal as S
11−import List as L
10+import Native.Signal as Native
11+import List (foldr)
1212
1313-- Create a constant signal that never changes.
1414constant : a -> Signal a
15+constant = Native.constant
1516
1617-- Transform a signal with a given function.
1718lift : (a -> b) -> Signal a -> Signal b
19+lift = Native.lift
1820
1921-- Combine two signals with a given function.
2022lift2 : (a -> b -> c) -> Signal a -> Signal b -> Signal c
23+lift2 = Native.lift2
2124
2225-- Combine three signals with a given function.
2326lift3 : (a -> b -> c -> d) -> Signal a -> Signal b -> Signal c -> Signal d
27+lift3 = Native.lift3
28+
2429lift4 : (a -> b -> c -> d -> e) -> Signal a -> Signal b -> Signal c -> Signal d -> Signal e
30+lift4 = Native.lift4
31+
2532lift5 : (a -> b -> c -> d -> e -> f) -> Signal a -> Signal b -> Signal c -> Signal d -> Signal e -> Signal f
33+lift5 = Native.lift5
34+
2635lift6 : (a -> b -> c -> d -> e -> f -> g)
2736 -> Signal a -> Signal b -> Signal c -> Signal d -> Signal e -> Signal f -> Signal g
37+lift6 = Native.lift6
38+
2839lift7 : (a -> b -> c -> d -> e -> f -> g -> h)
2940 -> Signal a -> Signal b -> Signal c -> Signal d -> Signal e -> Signal f -> Signal g -> Signal h
41+lift7 = Native.lift7
42+
3043lift8 : (a -> b -> c -> d -> e -> f -> g -> h -> i)
3144 -> Signal a -> Signal b -> Signal c -> Signal d -> Signal e -> Signal f -> Signal g -> Signal h -> Signal i
45+lift8 = Native.lift8
46+
3247
3348-- Create a past-dependent signal. Each value given on the input signal will
3449-- be accumulated, producing a new output value.
3550--
3651-- For instance, `(foldp (\\t acc -> acc + 1) 0 (Time.every second))` increments every second.
3752foldp : (a -> b -> b) -> b -> Signal a -> Signal b
53+foldp = Native.foldp
3854
3955-- Merge two signals into one, biased towards the first signal if both signals
4056-- update at the same time.
4157merge : Signal a -> Signal a -> Signal a
58+merge = Native.merge
4259
4360-- Merge many signals into one, biased towards the left-most signal if multiple
4461-- signals update simultaneously.
4562merges : [Signal a] -> Signal a
63+merges = Native.merges
4664
4765-- Combine a list of signals into a signal of lists.
4866combine : [Signal a] -> Signal [a]
49−combine = L.foldr (S.lift2 (::)) (S.constant [])
67+combine = foldr (Native.lift2 (::)) (Native.constant [])
5068
5169 -- Merge two signals into one, but distinguishing the values by marking the first
5270 -- 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 [])
5573
5674-- Count the number of events that have occured.
5775count : Signal a -> Signal Int
76+count = Native.count
5877
5978-- Count the number of events that have occured that satisfy a given predicate.
6079countIf : (a -> Bool) -> Signal a -> Signal Int
80+countIf = Native.countIf
6181
6282-- Keep only events that satisfy the given predicate. Elm does not allow
6383-- undefined signals, so a base case must be provided in case the predicate is
6484-- never satisfied.
6585keepIf : (a -> Bool) -> a -> Signal a -> Signal a
86+keepIf = Native.keepIf
6687
6788-- Drop events that satisfy the given predicate. Elm does not allow undefined
6889-- signals, so a base case must be provided in case the predicate is never
6990-- satisfied.
7091dropIf : (a -> Bool) -> a -> Signal a -> Signal a
92+dropIf = Native.dropIf
7193
7294-- Keep events only when the first signal is true. When the first signal becomes
7395-- 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
7597-- not allow undefined signals, so a base case must be provided in case the first
7698-- signal is never true.
7799keepWhen : Signal Bool -> a -> Signal a -> Signal a
100+keepWhen = Native.keepWhen
78101
79102-- Drop events when the first signal is true. When the first signal becomes false,
80103-- 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
82105-- undefined signals, so a base case must be provided in case the first signal is
83106-- always true.
84107dropWhen : Signal Bool -> a -> Signal a -> Signal a
108+dropWhen = Native.dropWhen
85109
86110-- Drop sequential repeated values. For example, if a signal produces the
87111-- sequence `[1,1,2,2,1]`, it becomes `[1,2,1]` by dropping the values that
88112-- are the same as the previous value.
89113dropRepeats : Signal a -> Signal a
114+dropRepeats = Native.dropRepeats
90115
91116-- Sample from the second input every time an event occurs on the first input.
92117-- For example, `(sampleOn clicks (every second))` will give the approximate
93118-- time of the latest click.
94119sampleOn : Signal a -> Signal b -> Signal b
120+sampleOn = Native.sampleOn
95121
96122-- An alias for `lift`. A prettier way to apply a
97123-- function to the current value of a signal.
98124--
99125-- lift f signal == f <~ signal
100126(<~) : (a -> b) -> Signal a -> Signal b
127+(<~) = Native.lift
101128
102129-- Signal application. This takes two signals, holding a function and
103130-- a value. It applies the current function to the current value.
@@ -107,3 +134,4 @@ sampleOn : Signal a -> Signal b -> Signal b
107134-- scene <~ Window.dimensions ~ Mouse.position
108135-- lift2 scene Window.dimensions Mouse.position
109136(~) : Signal (a -> b) -> Signal a -> Signal b
137+(~) = Native.lift2 (\f x -> f x)
libraries/Time.elm+9−3
@@ -1,7 +1,7 @@
11-- Library for working with time. Type `Time` represents some number of milliseconds.
22module Time where
33
4−import Native.Time as T
4+import Native.Time as Native
55
66-- Type alias to make it clearer when you are working with time values.
77-- Using the `Time` constants instead of raw numbers is very highly recommended.
@@ -38,18 +38,21 @@ inHours t = t / hour
3838-- gives a sequence of time deltas as quickly as possible until it reaches
3939-- the desired FPS. A time delta is the time between the last frame and the
4040-- current frame.
41−fps : Number a -> Signal Time
41+fps : number -> Signal Time
42+fps = Native.fps
4243
4344-- Same as the fps function, but you can turn it on and off. Allows you
4445-- to do brief animations based on user input without major inefficiencies.
4546-- The first time delta after a pause is always zero, no matter how long
4647-- the pause was. This way summing the deltas will actually give the amount
4748-- 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
4951
5052-- Takes a time interval t. The resulting signal is the current time,
5153-- updated every t.
5254every : Time -> Signal Time
55+every = Native.every
5356
5457-- Takes a time `t` and any signal. The resulting boolean signal
5558-- is true for time `t` after every event on the input signal.
@@ -57,13 +60,16 @@ every : Time -> Signal Time
5760-- that is true for one second after each mouse click and false
5861-- otherwise.
5962since : Time -> Signal a -> Signal Bool
63+since = Native.since
6064
6165-- Add a timestamp to any signal. Timestamps increase monotonically. Each
6266-- timestamp is related to a specfic event, so `Mouse.x` and `Mouse.y` will
6367-- always have the same timestamp because they both rely on the same
6468-- underlying event.
6569timestamp : Signal a -> Signal (Time, a)
70+timestamp = Native.timestamp
6671
6772-- Delay a signal by a certain amount of time. So `(delay second Mouse.clicks)`
6873-- will update one second later than any mouse click.
6974delay : Time -> Signal a -> Signal a
75+delay = Native.delay