on master help sign in
Finish tweaking the second half of .elm library files.
commitb3435647955e0f089a06cf89674f79200aa8e86b authorevancz <info@elm-lang.org> dateSun 10 Mar 2013, 01:07 (14 years ago) parent8a700e8
9 files changed+22−47
libraries/Keyboard.elm+7−7 libraries/Maybe.elm+3−3 libraries/Mouse.elm−15 libraries/Native/Signal/Keyboard.js+1−1 libraries/Random.elm+5−10 libraries/Set.elm+6−5 libraries/Touch.elm−2 libraries/WebSocket.elm−1 libraries/Window.elm−3
libraries/Keyboard.elm+7−7
@@ -4,7 +4,7 @@
44
55module Keyboard where
66
7−import Native.Keyboard
7+import Native.Keyboard as N
88
99type KeyCode = Int
1010
@@ -15,26 +15,26 @@ type KeyCode = Int
1515-- `{ x = 1, y = 1 }` when pressing the up and right arrows.
1616-- `{ x = 0, y =-1 }` when pressing the down, left, and right arrows.
1717arrows : Signal { x:Int, y:Int }
18−arrows = Native.Keyboard.dir 37 39 38 40
18+arrows = N.directions 37 39 38 40
1919
2020-- Just like the arrows signal, but this uses keys w, a, s, and d,
2121-- which are common controls for many computer games.
2222wasd : Signal { x:Int, y:Int }
23−wasd = Native.Keyboard.dir 65 68 87 83
23+wasd = N.directions 65 68 87 83
2424
25+directions : KeyCode -> KeyCode -> KeyCode -> KeyCode -> Signal { x:Int, y:Int }
2526
2627
2728isDown : KeyCode -> Signal Bool
28−isDown = Native.Keyboard.isDown
2929
3030-- Whether the shift key is pressed.
3131shift : Signal Bool
32−shift = Native.Keyboard.isDown 16
32+shift = N.isDown 16
3333
3434-- Whether the control key is pressed.
3535ctrl : Signal Bool
36−ctrl = Native.Keyboard.isDown 17
36+ctrl = N.isDown 17
3737
3838-- Whether the space key is pressed.
3939space : Signal Bool
40−space = Native.Keyboard.isDown 32
40+space = N.isDown 32
libraries/Maybe.elm+3−3
@@ -1,7 +1,7 @@
11
22module Maybe where
33
4−import List as List
4+import List (foldr)
55
66-- The Maybe datatype. Useful when a computation may or may not
77-- result in a value (e.g. logarithm is defined only for positive numbers).
@@ -26,8 +26,8 @@ isNothing = not . isJust
2626-- If `Just`, adds the value to the front of the list.
2727-- If `Nothing`, list is unchanged.
2828cons : Maybe a -> [a] -> [a]
29−cons mx xs = maybe xs (\x -> x:xs) mx
29+cons mx xs = maybe xs (\x -> x :: xs) mx
3030
3131-- Filters out Nothings and extracts the remaining values.
3232justs : [Maybe a] -> [a]
33−justs = List.foldr cons []
33+justs = foldr cons []
libraries/Mouse.elm−15
@@ -1,39 +1,24 @@
11
22module Mouse where
33
4−import Native.Mouse
5−
64-- The current mouse position.
75position : Signal (Int,Int)
8−position = Native.Mouse.position
96
107-- The current x-coordinate of the mouse.
118x : Signal Int
12−x = Native.Mouse.x
139
1410-- The current y-coordinate of the mouse.
1511y : Signal Int
16−y = Native.Mouse.y
1712
1813
1914-- The current state of the left mouse-button.
2015-- True when the button is down, and false otherwise.
2116isDown : Signal Bool
22−isDown = Native.Mouse.isDown
2317
2418-- True immediately after the left mouse-button has been clicked,
2519-- and false otherwise.
2620isClicked : Signal Bool
27−isClicked = Native.Mouse.isClicked
2821
2922
3023-- Always equal to unit. Event triggers on every mouse click.
3124clicks : 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) {
3434
3535 function is(key) { return keySignal(List.member(key)); }
3636
37− return elm.Native.Keyboard = { isDown:is, dir:F4(dir) };
37+ return elm.Native.Keyboard = { isDown:is, directions:F4(dir) };
3838
3939};
libraries/Random.elm+5−10
@@ -1,16 +1,11 @@
11
22module Random where
33
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−
124-- Given a range from low to high and a signal of values, this produces
135-- a new signal that changes whenever the input signal changes. The new
146-- values are random number between 'low' and 'high' inclusive.
15−randomize : Int -> Int -> Signal a -> Signal Int
16−randomize = Native.Random.randomize
7+range : Int -> Int -> Signal a -> Signal Int
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
66 ,toList,fromList
77 ) where
88
9−import Dict as Dict
9+import Dict
10+import List
1011
1112type Set t = Dict t ()
1213
@@ -38,13 +39,13 @@ toList : Set t -> [t]
3839toList = Dict.keys
3940
4041fromList : [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
4243
4344foldl : (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
4546
4647foldr : (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
4849
4950map : (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 }
1313-- time of the initial contact (x0, y0, and t0) which helps compute more
1414-- complicated gestures.
1515touches : Signal [Touch]
16−touches = Native.Touch.touches
1716
1817-- The last position that was tapped. Default value is `{x=0,y=0}`.
1918-- Updates whenever the user taps the screen.
2019taps : Signal { x:Int, y:Int }
21−taps = Native.Touch.taps
libraries/WebSocket.elm−1
@@ -9,4 +9,3 @@ import Native.WebSocket
99-- web-socket server. The input signal holds the outgoing messages,
1010-- and the resulting signal contains the incoming ones.
1111open : String -> Signal String -> Signal String
12−open = Native.WebSocket.open
libraries/Window.elm−3
@@ -6,12 +6,9 @@ import Native.Window
66-- The current dimensions of the window (i.e. the area viewable to the
77-- user, not including scroll bars).
88dimensions : Signal (Int,Int)
9−dimensions = Native.Window.dimensions
109
1110-- The current width of the window.
1211width : Signal Int
13−width = Native.Window.width
1412
1513-- The current height of the window.
1614height : Signal Int
17−height = Native.Window.height