on master help sign in
Migrate type annotations to more JS files.
commitb4dba5ff918a82d8b93adff636ec1b554f329903 authorevancz <info@elm-lang.org> dateSun 3 Feb 2013, 20:13 (14 years ago) parentedb65fc
11 files changed+222−15
core-js/Char.js+40 core-js/Either.js+44 core-js/Maybe.js+32 core-js/Signal/HTTP.js+5−5 core-js/Signal/Keyboard.js+35 core-js/Signal/Mouse.js+36 core-js/Signal/Random.js+15 core-js/Signal/Time.js+4−4 core-js/Signal/Touch.js+2−2 core-js/Signal/WebSocket.js+6−1 core-js/Signal/Window.js+3−3
core-js/Char.js+40
@@ -1,3 +1,43 @@
1+/*! Char !*/
2+
3+/*[Classification]*/
4+
5+/** isUpper : Char -> Bool
6+ Selects upper case letters.
7+**/
8+/** isLower : Char -> Bool
9+ Selects lower case letters.
10+**/
11+/** isDigit : Char -> Bool
12+ Selects ASCII digits (0..9).
13+**/
14+/** isOctDigit : Char -> Bool
15+ Selects ASCII octal digits (0..7).
16+**/
17+/** isHexDigit : Char -> Bool
18+ Selects ASCII hexadecimal digits (0..9a..fA..F).
19+**/
20+
21+/*[Conversion]*/
22+
23+/** toUpper : Char -> Char
24+ Convert to upper case.
25+**/
26+/** toLower : Char -> Char
27+ Convert to lower case.
28+**/
29+/** toLocaleUpper : Char -> Char
30+ Convert to upper case, according to any locale-specific case mappings.
31+**/
32+/** toLocaleLower : Char -> Char
33+ Convert to lower case, according to any locale-specific case mappings.
34+**/
35+/** toCode : Char -> Int
36+ Convert to unicode.
37+**/
38+/** fromCode : Int -> Char
39+ Convert from unicode.
40+**/
141
242Elm.Char = function() {
343 function isBetween(lo,hi) { return function(chr) {
core-js/Either.js+44
@@ -1,19 +1,63 @@
1+/*! Either
2+!*/
3+
14
25Elm.Either = function() {
6+ /*[Definition]*/
7+
8+ /** data Either a b = Left a | Right b
9+ Represents any data that can take two different types.
10+
11+ This can also be used for error handling (`Either String a`) where
12+ error messages are stored on the left, and the correct values
13+ ("right" values) are stored on the right.
14+ **/
315 function Left(a1) { return ['Left',a1]; }
416 function Right(a1){ return ['Right',a1]; }
17+
18+ /*[Basics]*/
19+
20+ /** either : (a -> c) -> (b -> c) -> Either a b -> c
21+ Apply the first function to a `Left` and the second function to a `Right`.
22+ This allows the extraction of a value from an `Either`.
23+ **/
524 function either(f){ return function(g){ return function(e){
625 switch(e[0]){
726 case 'Left': return f(e[1]);
827 case 'Right': return g(e[1]);
928 }
1029 };};}
30+
31+ /** isLeft : Either a b -> Bool
32+ True if the value is a `Left`.
33+ **/
1134 function isLeft(e) { return e[0] == 'Left'; }
35+
36+ /** isRight : Either a b -> Bool
37+ True if the value is a `Right`.
38+ **/
1239 function isRight(e) { return e[0] == 'Right'; }
1340
41+ /*[With Lists]*/
42+
1443 function get(es) { return Elm.List.map(function(x){return x[1];})(es); }
44+
45+ /** lefts : [Either a b] -> [a]
46+ Keep only the values held in `Left` values.
47+ **/
1548 function lefts(es) { return get(Elm.List.filter(isLeft)(es)); }
49+
50+ /** rights : [Either a b] -> [a]
51+ Keep only the values held in `Right` values.
52+ **/
1653 function rights(es) { return get(Elm.List.filter(isRight)(es)); }
54+
55+ /** partition : [Either a b] -> ([a],[b])
56+ Split into two lists, lefts on the left and rights on the right.
57+ So we have the equivalence:
58+
59+ partition es == (lefts es, rights es)
60+ **/
1761 function partition(es) {
1862 var lrs = Elm.List.partition(isLeft)(es);
1963 lrs[1] = get(lrs[1]);
core-js/Maybe.js+32
@@ -1,3 +1,35 @@
1+/*! Maybe
2+!*/
3+
4+/*[Definition]*/
5+
6+/** data Maybe a = Just a | Nothing
7+ The Maybe datatype. Useful when a computation may or may not
8+ result in a value (e.g. logarithm is defined only for positive numbers).
9+**/
10+
11+/*[Basic Utilities]*/
12+
13+/** maybe : b -> (a -> b) -> Maybe a -> b
14+ Apply a function to the contents of a `Maybe`.
15+ Return default when given `Nothing`.
16+**/
17+/** isJust : Maybe a -> Bool
18+ Check if constructed with `Just`.
19+**/
20+/** isNothing : Maybe a -> Bool
21+ Check if constructed with `Nothing`.
22+**/
23+
24+/*[Maybe with Lists]*/
25+
26+/** cons : Maybe a -> [a] -> [a]
27+ If `Just`, adds the value to the front of the list.
28+ If `Nothing`, list is unchanged.
29+**/
30+/** justs : [Maybe a] -> [a]
31+ Filters out Nothings and extracts the remaining values.
32+**/
133
234Elm.Maybe = function() {
335 function consMaybe(x) { return function(xs) {
core-js/Signal/HTTP.js+5−5
@@ -11,18 +11,18 @@ Elm.HTTP = function() {
1111
1212 /*[Creating Requests]*/
1313
14− /** get :: String -> Request String
14+ /** get : String -> Request String
1515 Create a GET request to the given url.
1616 **/
1717 function get(url) { return request("GET")(url)(null)(["Nil"]); }
1818
19− /** post :: String -> String -> Request String
19+ /** post : String -> String -> Request String
2020 Create a POST request to the given url, carrying the given data.
2121 **/
2222 function post(url) { return function(data) {
2323 return request("POST")(url)(data)(["Nil"]); }; }
2424
25− /** request :: String -> String -> String -> [(String,String)] -> Request String
25+ /** request : String -> String -> String -> [(String,String)] -> Request String
2626 Create a customized request. Arguments are request type (get, post, put,
2727 delete, etc.), target url, data, and a list of additional headers.
2828 **/
@@ -86,7 +86,7 @@ Elm.HTTP = function() {
8686
8787 /*[Sending Requests]*/
8888
89− /** send :: Signal (Request a) -> Signal (Response String)
89+ /** send : Signal (Request a) -> Signal (Response String)
9090 Performs an HTTP request with the given requests. Produces a signal
9191 that carries the responses.
9292 **/
@@ -97,7 +97,7 @@ Elm.HTTP = function() {
9797 return Elm.Signal.lift2(f)(responses)(sender);
9898 }
9999
100− /** sendGet :: Signal String -> Signal (Response String)
100+ /** sendGet : Signal String -> Signal (Response String)
101101 Performs an HTTP GET request with the given urls. Produces a signal
102102 that carries the responses.
103103 **/
core-js/Signal/Keyboard.js+35
@@ -43,6 +43,12 @@ Elm.Keyboard = { Raw : function() {
4343 }()
4444};
4545
46+/*! Keyboard
47+These are nicely curated inputs from the keyboard. See the
48+[Keyboard.Raw library](/docs/Signal/KeyboardRaw.elm) for a
49+lower-level interface that will let you define more complicated behavior.
50+!*/
51+
4652(function() {
4753 function keySignal(f) {
4854 var signal = Elm.Signal.lift(f)(Elm.Keyboard.Raw.keysDown);
@@ -79,10 +85,39 @@ Elm.Keyboard = { Raw : function() {
7985 return keySignal(f);
8086 }
8187
88+ /*[Directions]*/
89+
90+ /** arrows : Signal { x:Int, y:Int }
91+ A signal of records indicating which arrow keys are pressed.
92+
93+ `{ x = 0, y = 0 }` when pressing no arrows.
94+ `{ x =-1, y = 0 }` when pressing the left arrow.
95+ `{ x = 1, y = 1 }` when pressing the up and right arrows.
96+ `{ x = 0, y =-1 }` when pressing the down, left, and right arrows.
97+ **/
8298 Elm.Keyboard.arrows = dir(37,39,38,40);
99+
100+ /** wasd : Signal { x:Int, y:Int }
101+ Just like the arrows signal, but this uses keys w, a, s, and d,
102+ which are common controls for many computer games.
103+ **/
83104 Elm.Keyboard.wasd = dir(65,68,87,83);
105+
106+ /*[Modifiers]*/
107+
108+ /** shift : Signal Bool
109+ Whether the shift key is pressed.
110+ **/
84111 Elm.Keyboard.shift = is(16);
112+
113+ /** ctrl : Signal Bool
114+ Whether the control key is pressed.
115+ **/
85116 Elm.Keyboard.ctrl = is(17);
117+
118+ /** space : Signal Bool
119+ Whether the space key is pressed.
120+ **/
86121 Elm.Keyboard.space = is(32);
87122
88123}());
core-js/Signal/Mouse.js+36
@@ -1,15 +1,44 @@
1+/*! Mouse
2+ !*/
13
24Elm.Mouse = function() {
5+ /*[Position]*/
6+
7+ /** position : Signal (Int,Int)
8+ The current mouse position.
9+ **/
310 var position = Elm.Signal.constant(Value.Tuple(0,0));
411 position.defaultNumberOfKids = 2;
512
13+ /** x : Signal Int
14+ The current x-coordinate of the mouse.
15+ **/
616 var x = Elm.Signal.lift(function(p){return p[1];})(position);
717 x.defaultNumberOfKids = 0;
18+
19+ /** y : Signal Int
20+ The current y-coordinate of the mouse.
21+ **/
822 var y = Elm.Signal.lift(function(p){return p[2];})(position);
923 y.defaultNumberOfKids = 0;
1024
25+ /*[Button Status]*/
26+
27+ /** isDown : Signal Bool
28+ The current state of the left mouse-button.
29+ True when the button is down, and false otherwise.
30+ **/
1131 var isDown = Elm.Signal.constant(false);
32+
33+ /** isClicked : Signal Bool
34+ True immediately after the left mouse-button has been clicked,
35+ and false otherwise.
36+ **/
1237 var isClicked = Elm.Signal.constant(false);
38+
39+ /** clicks : Signal ()
40+ Always equal to unit. Event triggers on every mouse click.
41+ **/
1342 var clicks = Elm.Signal.constant(Value.Tuple());
1443
1544 function getXY(e) {
@@ -50,6 +79,13 @@ Elm.Mouse = function() {
5079 if (!hasListener)
5180 this.removeEventListener('mousemove',arguments.callee,false);
5281 });
82+
83+ /** isClickedOn : Element -> (Element, Signal Bool)
84+ Determine whether an element has been clicked. The resulting pair
85+ is a signal of booleans that is true when its paired element has
86+ been clicked. The signal is True immediately after the left
87+ mouse-button has been clicked, and false otherwise.
88+ **/
5389 var clickedOn = function(elem) {
5490 var node = Render.render(elem);
5591 var click = Elm.Signal.constant(false);
core-js/Signal/Random.js+15
@@ -1,9 +1,24 @@
1+/*! Random
2+ !*/
13
24Elm.Random = function() {
5+ /*[In a Range]*/
6+
7+ /** inRange : Int -> Int -> Signal Int
8+ Given a range from low to high, this produces a random number
9+ between 'low' and 'high' inclusive. The value in the signal does
10+ not change after the page has loaded.
11+ **/
312 var inRange = function(min) { return function(max) {
413 return Elm.Signal.constant(Math.floor(Math.random() * (max-min+1)) + min);
514 };
615 };
16+
17+ /** randomize : Int -> Int -> Signal a -> Signal Int
18+ Given a range from low to high and a signal of values, this produces
19+ a new signal that changes whenever the input signal changes. The new
20+ values are random number between 'low' and 'high' inclusive.
21+ **/
722 var randomize = function(min) { return function(max) { return function(signal) {
823 function f(x) { return Math.floor(Math.random() * (max-min+1)) + min; }
924 return Elm.Signal.lift(f)(signal);
core-js/Signal/Time.js+4−4
@@ -7,7 +7,7 @@ Elm.Time = function() {
77
88 /*[Times]*/
99
10− /** hour, minute, second, ms :: Time
10+ /** hour, minute, second, ms : Time
1111 Units of time, making it easier to specify things like a
1212 half-second `(second / 2)`.
1313 **/
@@ -16,14 +16,14 @@ Elm.Time = function() {
1616
1717 /*[Tickers]*/
1818
19− /** fps :: Number -> Signal Time
19+ /** fps : Number -> Signal Time
2020 Takes desired number of frames per second (fps). The resulting signal
2121 gives a sequence of time deltas as quickly as possible until it reaches
2222 the desired FPS. A time delta is the time between the last frame and the
2323 current frame.
2424 **/
2525
26− /** fpsWhen :: Number -> Signal Bool -> Signal Time
26+ /** fpsWhen : Number -> Signal Bool -> Signal Time
2727 Same as the fps function, but you can turn it on and off. Allows you
2828 to do brief animations based on user input without major ineffeciencies.
2929 The first time delta after a pause is always zero, no matter how long
@@ -56,7 +56,7 @@ Elm.Time = function() {
5656 };
5757 }
5858
59− /** every :: Time -> Signal Time
59+ /** every : Time -> Signal Time
6060 Takes a time interval t. The resulting signal is the current time,
6161 updated every t.
6262 **/
core-js/Signal/Touch.js+2−2
@@ -79,7 +79,7 @@ Elm.Touch = function() {
7979
8080 /*[Touches]*/
8181
82− /** touches :: Signal [{ x :: Int, y :: Int, id :: Int, x0 :: Int, y0 :: Int, t0 :: Time }]
82+ /** touches : Signal [{ x:Int, y:Int, id:Int, x0:Int, y0:Int, t0:Time }]
8383 A list of touches. Each ongoing touch is represented by a set of
8484 coordinates and an identifier id that allows you to distinguish
8585 between different touches. Each touch also contains the coordinates and
@@ -92,7 +92,7 @@ Elm.Touch = function() {
9292
9393 /*[Gestures]*/
9494
95− /** taps :: Signal { x :: Int, y :: Int }
95+ /** taps : Signal { x:Int, y:Int }
9696 The last position that was tapped. Default value is `{x=0,y=0}`.
9797 Updates whenever the user taps the screen.
9898 **/
core-js/Signal/WebSocket.js+6−1
@@ -1,7 +1,12 @@
1+/*! WebSocket
2+A library for low latency HTTP communication. See the HTTP library for standard
3+requests like GET, POST, etc.
4+!*/
5+
16Elm.WebSocket = function() {
27 var JS = Elm.JavaScript;
38
4− /** open :: String -> Signal String -> Signal String
9+ /** open : String -> Signal String -> Signal String
510 Create a web-socket. The first argument is the URL of the desired
611 web-socket server. The input signal holds the outgoing messages,
712 and the resulting signal contains the incoming ones.
core-js/Signal/Window.js+3−3
@@ -4,7 +4,7 @@ Elm.Window = function() {
44
55 /*[Dimensions]*/
66
7− /** dimensions :: Signal (Int,Int)
7+ /** dimensions : Signal (Int,Int)
88 The current dimensions of the window (i.e. the area viewable to the
99 user, not including scroll bars).
1010 **/
@@ -12,13 +12,13 @@ Elm.Window = function() {
1212 window.innerHeight));
1313 dimensions.defaultNumberOfKids = 2;
1414
15− /** width :: Signal Int
15+ /** width : Signal Int
1616 The current width of the window.
1717 **/
1818 var width = Elm.Signal.lift(function(p){return p[1];})(dimensions);
1919 width.defaultNumberOfKids = 0;
2020
21− /** height :: Signal Int
21+ /** height : Signal Int
2222 The current height of the window.
2323 **/
2424 var height = Elm.Signal.lift(function(p){return p[2];})(dimensions);