on master help sign in
Finish tweaking the second half of .elm library files.
b343564evancz
libraries/Keyboard.elm+7−7
@@ -4,7 +4,7 @@
4
4
5module Keyboard where
5module Keyboard where
6
6
7−import Native.Keyboard
7+import Native.Keyboard as N
8
8
9type KeyCode = Int
9type KeyCode = Int
10
10
@@ -15,26 +15,26 @@ type KeyCode = Int
15-- `{ x = 1, y = 1 }` when pressing the up and right arrows.
15-- `{ x = 1, y = 1 }` when pressing the up and right arrows.
16-- `{ x = 0, y =-1 }` when pressing the down, left, and right arrows.
16-- `{ x = 0, y =-1 }` when pressing the down, left, and right arrows.
17arrows : Signal { x:Int, y:Int }
17arrows : Signal { x:Int, y:Int }
18−arrows = Native.Keyboard.dir 37 39 38 40
18+arrows = N.directions 37 39 38 40
19
19
20-- Just like the arrows signal, but this uses keys w, a, s, and d,
20-- Just like the arrows signal, but this uses keys w, a, s, and d,
21-- which are common controls for many computer games.
21-- which are common controls for many computer games.
22wasd : Signal { x:Int, y:Int }
22wasd : Signal { x:Int, y:Int }
23−wasd = Native.Keyboard.dir 65 68 87 83
23+wasd = N.directions 65 68 87 83
24
24
25+directions : KeyCode -> KeyCode -> KeyCode -> KeyCode -> Signal { x:Int, y:Int }
25
26
26
27
27isDown : KeyCode -> Signal Bool
28isDown : KeyCode -> Signal Bool
28−isDown = Native.Keyboard.isDown
29
29
30-- Whether the shift key is pressed.
30-- Whether the shift key is pressed.
31shift : Signal Bool
31shift : Signal Bool
32−shift = Native.Keyboard.isDown 16
32+shift = N.isDown 16
33
33
34-- Whether the control key is pressed.
34-- Whether the control key is pressed.
35ctrl : Signal Bool
35ctrl : Signal Bool
36−ctrl = Native.Keyboard.isDown 17
36+ctrl = N.isDown 17
37
37
38-- Whether the space key is pressed.
38-- Whether the space key is pressed.
39space : Signal Bool
39space : Signal Bool
40−space = Native.Keyboard.isDown 32
40+space = N.isDown 32
libraries/Maybe.elm+3−3
@@ -1,7 +1,7 @@
1
1
2module Maybe where
2module Maybe where
3
3
4−import List as List
4+import List (foldr)
5
5
6-- The Maybe datatype. Useful when a computation may or may not
6-- The Maybe datatype. Useful when a computation may or may not
7-- result in a value (e.g. logarithm is defined only for positive numbers).
7-- result in a value (e.g. logarithm is defined only for positive numbers).
@@ -26,8 +26,8 @@ isNothing = not . isJust
26-- If `Just`, adds the value to the front of the list.
26-- If `Just`, adds the value to the front of the list.
27-- If `Nothing`, list is unchanged.
27-- If `Nothing`, list is unchanged.
28cons : Maybe a -> [a] -> [a]
28cons : Maybe a -> [a] -> [a]
29−cons mx xs = maybe xs (\x -> x:xs) mx
29+cons mx xs = maybe xs (\x -> x :: xs) mx
30
30
31-- Filters out Nothings and extracts the remaining values.
31-- Filters out Nothings and extracts the remaining values.
32justs : [Maybe a] -> [a]
32justs : [Maybe a] -> [a]
33−justs = List.foldr cons []
33+justs = foldr cons []
libraries/Mouse.elm−15
@@ -1,39 +1,24 @@
1
1
2module Mouse where
2module Mouse where
3
3
4−import Native.Mouse
5−
6-- The current mouse position.
4-- The current mouse position.
7position : Signal (Int,Int)
5position : Signal (Int,Int)
8−position = Native.Mouse.position
9
6
10-- The current x-coordinate of the mouse.
7-- The current x-coordinate of the mouse.
11x : Signal Int
8x : Signal Int
12−x = Native.Mouse.x
13
9
14-- The current y-coordinate of the mouse.
10-- The current y-coordinate of the mouse.
15y : Signal Int
11y : Signal Int
16−y = Native.Mouse.y
17
12
18
13
19-- The current state of the left mouse-button.
14-- The current state of the left mouse-button.
20-- True when the button is down, and false otherwise.
15-- True when the button is down, and false otherwise.
21isDown : Signal Bool
16isDown : Signal Bool
22−isDown = Native.Mouse.isDown
23
17
24-- True immediately after the left mouse-button has been clicked,
18-- True immediately after the left mouse-button has been clicked,
25-- and false otherwise.
19-- and false otherwise.
26isClicked : Signal Bool
20isClicked : Signal Bool
27−isClicked = Native.Mouse.isClicked
28
21
29
22
30-- Always equal to unit. Event triggers on every mouse click.
23-- Always equal to unit. Event triggers on every mouse click.
31clicks : Signal ()
24clicks : Signal ()
32−clicks = Native.Mouse.clicks
33−
34−-- Determine whether an element has been clicked. The resulting pair
35−-- is a signal of booleans that is true when its paired element has
36−-- been clicked. The signal is True immediately after the left
37−-- mouse-button has been clicked, and false otherwise.
38−isClickedOn : Element -> (Element, Signal Bool)
39−isClickedOn = Native.Mouse.isClickedOn
libraries/Native/Signal/Keyboard.js+1−1
@@ -34,6 +34,6 @@ Elm.Native.Keyboard = function(elm) {
34
34
35 function is(key) { return keySignal(List.member(key)); }
35 function is(key) { return keySignal(List.member(key)); }
36
36
37− return elm.Native.Keyboard = { isDown:is, dir:F4(dir) };
37+ return elm.Native.Keyboard = { isDown:is, directions:F4(dir) };
38
38
39};
39};
libraries/Random.elm+5−10
@@ -1,16 +1,11 @@
1
1
2module Random where
2module Random where
3
3
4−import Native.Random
5−
6−-- Given a range from low to high, this produces a random number
7−-- between 'low' and 'high' inclusive. The value in the signal does
8−-- not change after the page has loaded.
9−inRange : Int -> Int -> Signal Int
10−inRange = Native.Random.inRange
11−
12-- Given a range from low to high and a signal of values, this produces
4-- Given a range from low to high and a signal of values, this produces
13-- a new signal that changes whenever the input signal changes. The new
5-- a new signal that changes whenever the input signal changes. The new
14-- values are random number between 'low' and 'high' inclusive.
6-- values are random number between 'low' and 'high' inclusive.
15−randomize : Int -> Int -> Signal a -> Signal Int
7+range : Int -> Int -> Signal a -> Signal Int
16−randomize = Native.Random.randomize
8+
9+-- Produces a new signal that changes whenever the input signal changes.
10+-- The new values are random number in [0..1).
11+float : Signal a -> Signal Float
libraries/Set.elm+6−5
@@ -6,7 +6,8 @@ module Set (empty,singleton,insert,remove
6 ,toList,fromList
6 ,toList,fromList
7 ) where
7 ) where
8
8
9−import Dict as Dict
9+import Dict
10+import List
10
11
11type Set t = Dict t ()
12type Set t = Dict t ()
12
13
@@ -38,13 +39,13 @@ toList : Set t -> [t]
38toList = Dict.keys
39toList = Dict.keys
39
40
40fromList : [t] -> Set t
41fromList : [t] -> Set t
41−fromList = List.foldl (\k t -> Dict.insert k () t) empty
42+fromList xs = List.foldl (\k t -> Dict.insert k () t) empty xs
42
43
43foldl : (a -> b -> b) -> b -> Set a -> b
44foldl : (a -> b -> b) -> b -> Set a -> b
44−foldl f = Dict.foldl (\k _ b -> f k b)
45+foldl f b s = Dict.foldl (\k _ b -> f k b) b s
45
46
46foldr : (a -> b -> b) -> b -> Set a -> b
47foldr : (a -> b -> b) -> b -> Set a -> b
47−foldr f = Dict.foldr (\k _ b -> f k b)
48+foldr f b s = Dict.foldr (\k _ b -> f k b) b s
48
49
49map : (a -> b) -> Set a -> Set b
50map : (a -> b) -> Set a -> Set b
50−map f = fromList . List.map f . toList
51+map f s = fromList (List.map f (toList s))
libraries/Touch.elm−2
@@ -13,9 +13,7 @@ type Touch = { x:Int, y:Int, id:Int, x0:Int, y0:Int, t0:Time }
13-- time of the initial contact (x0, y0, and t0) which helps compute more
13-- time of the initial contact (x0, y0, and t0) which helps compute more
14-- complicated gestures.
14-- complicated gestures.
15touches : Signal [Touch]
15touches : Signal [Touch]
16−touches = Native.Touch.touches
17
16
18-- The last position that was tapped. Default value is `{x=0,y=0}`.
17-- The last position that was tapped. Default value is `{x=0,y=0}`.
19-- Updates whenever the user taps the screen.
18-- Updates whenever the user taps the screen.
20taps : Signal { x:Int, y:Int }
19taps : Signal { x:Int, y:Int }
21−taps = Native.Touch.taps
libraries/WebSocket.elm−1
@@ -9,4 +9,3 @@ import Native.WebSocket
9-- web-socket server. The input signal holds the outgoing messages,
9-- web-socket server. The input signal holds the outgoing messages,
10-- and the resulting signal contains the incoming ones.
10-- and the resulting signal contains the incoming ones.
11open : String -> Signal String -> Signal String
11open : String -> Signal String -> Signal String
12−open = Native.WebSocket.open
libraries/Window.elm−3
@@ -6,12 +6,9 @@ import Native.Window
6-- The current dimensions of the window (i.e. the area viewable to the
6-- The current dimensions of the window (i.e. the area viewable to the
7-- user, not including scroll bars).
7-- user, not including scroll bars).
8dimensions : Signal (Int,Int)
8dimensions : Signal (Int,Int)
9−dimensions = Native.Window.dimensions
10
9
11-- The current width of the window.
10-- The current width of the window.
12width : Signal Int
11width : Signal Int
13−width = Native.Window.width
14
12
15-- The current height of the window.
13-- The current height of the window.
16height : Signal Int
14height : Signal Int
17−height = Native.Window.height