on master help sign in
Merge pull request #155 from perplexes/lint

Whitespace, semicolons, lint etc. No functional changes.

commit4f9ddacdd86a1663bb7ad34f015c765a0374a572 authorEvan Czaplicki <info@elm-lang.org> dateTue 14 May 2013, 10:23 (13 years ago) parent4bb23bcacd2b61
16 files changed+238−223
libraries/Dict.elm+22−22 libraries/Maybe.elm+1−1 libraries/Native/Graphics/Input.js+2−2 libraries/Native/Matrix2D.js+9−9 libraries/Native/Prelude.js+36−35 libraries/Native/Show.js+1−1 libraries/Native/Signal/Http.js+4−4 libraries/Native/Signal/Keyboard.js+7−7 libraries/Native/Signal/Random.js+4−4 libraries/Native/Signal/Signal.js+73−72 libraries/Native/Signal/Time.js+7−7 libraries/Native/Signal/Window.js+2−2 libraries/Native/Utils.js+22−20 runtime/Init.js+7−7 runtime/Render/Collage.js+36−25 runtime/Utils.js+5−5
libraries/Dict.elm+22−22
@@ -24,7 +24,7 @@ empty = RBEmpty
2424{-- Helpers for checking invariants
2525
2626-- Check that the tree has an equal number of black nodes on each path
27−equal_pathLen t =
27+equal_pathLen t =
2828 let path_numBlacks t =
2929 case t of
3030 RBEmpty -> 1
@@ -35,14 +35,14 @@ equal_pathLen t =
3535 else bl + (if col == Red then 0 else 1)
3636 in 0-1 /= path_numBlacks t
3737
38−rootBlack t =
38+rootBlack t =
3939 case t of
4040 RBEmpty -> True
4141 RBNode Black _ _ _ _ -> True
4242 _ -> False
4343
44−redBlack_children t =
45− case t of
44+redBlack_children t =
45+ case t of
4646 { RBNode Red _ _ (RBNode Red _ _ _ _) _ -> False
4747 ; RBNode Red _ _ _ (RBNode Red _ _ _ _) -> False
4848 ; RBEmpty -> True
@@ -57,7 +57,7 @@ findExtreme f t =
5757 { Nothing -> Just k
5858 ; Just k' -> Just k' }
5959 }
60−
60+
6161findminRbt t = findExtreme fst t
6262findmaxRbt t = findExtreme snd t
6363
@@ -83,7 +83,7 @@ ordered t =
8383 }
8484
8585-- Check that there aren't any right red nodes in the tree *)
86−leftLeaning t =
86+leftLeaning t =
8787 case t of
8888 { RBEmpty -> True
8989 ; RBNode _ _ _ (RBNode Black _ _ _ _) (RBNode Red _ _ _ _) -> False
@@ -92,7 +92,7 @@ leftLeaning t =
9292 }
9393
9494invariants_hold t =
95− ordered t && rootBlack t && redBlack_children t &&
95+ ordered t && rootBlack t && redBlack_children t &&
9696 equal_pathLen t && leftLeaning t
9797
9898--** End invariant helpers *****
@@ -101,14 +101,14 @@ invariants_hold t =
101101
102102min : Dict k v -> (k,v)
103103min t =
104− case t of
104+ case t of
105105 RBNode _ k v RBEmpty _ -> (k,v)
106106 RBNode _ _ _ l _ -> min l
107107 RBEmpty -> Error.raise "(min Empty) is not defined"
108108
109109{--
110110max t =
111− case t of
111+ case t of
112112 { RBNode _ k v _ RBEmpty -> (k,v)
113113 ; RBNode _ _ _ _ r -> max r
114114 ; RBEmpty -> Error.raise "(max Empty) is not defined"
@@ -162,7 +162,7 @@ rotateLeft t =
162162 RBNode cy ky vy a (RBNode cz kz vz b c) -> RBNode cy kz vz (RBNode Red ky vy a b) c
163163 _ -> Error.raise "rotateLeft of a node without enough children"
164164
165−-- rotateRight -- the reverse, and
165+-- rotateRight -- the reverse, and
166166-- makes Y have Z's color, and makes Z Red.
167167rotateRight : Dict k v -> Dict k v
168168rotateRight t =
@@ -172,13 +172,13 @@ rotateRight t =
172172
173173rotateLeftIfNeeded : Dict k v -> Dict k v
174174rotateLeftIfNeeded t =
175− case t of
175+ case t of
176176 RBNode _ _ _ _ (RBNode Red _ _ _ _) -> rotateLeft t
177177 _ -> t
178178
179179rotateRightIfNeeded : Dict k v -> Dict k v
180180rotateRightIfNeeded t =
181− case t of
181+ case t of
182182 RBNode _ _ _ (RBNode Red _ _ (RBNode Red _ _ _ _) _) _ -> rotateRight t
183183 _ -> t
184184
@@ -187,14 +187,14 @@ otherColor c = case c of { Red -> Black ; Black -> Red }
187187color_flip : Dict k v -> Dict k v
188188color_flip t =
189189 case t of
190− RBNode c1 bk bv (RBNode c2 ak av la ra) (RBNode c3 ck cv lc rc) ->
190+ RBNode c1 bk bv (RBNode c2 ak av la ra) (RBNode c3 ck cv lc rc) ->
191191 RBNode (otherColor c1) bk bv
192192 (RBNode (otherColor c2) ak av la ra)
193193 (RBNode (otherColor c3) ck cv lc rc)
194194 _ -> Error.raise "color_flip called on a Empty or Node with a Empty child"
195195
196196color_flipIfNeeded : Dict k v -> Dict k v
197−color_flipIfNeeded t =
197+color_flipIfNeeded t =
198198 case t of
199199 RBNode _ _ _ (RBNode Red _ _ _ _) (RBNode Red _ _ _ _) -> color_flip t
200200 _ -> t
@@ -202,11 +202,11 @@ color_flipIfNeeded t =
202202fixUp t = color_flipIfNeeded (rotateRightIfNeeded (rotateLeftIfNeeded t))
203203
204204ensureBlackRoot : Dict k v -> Dict k v
205−ensureBlackRoot t =
205+ensureBlackRoot t =
206206 case t of
207207 RBNode Red k v l r -> RBNode Black k v l r
208208 _ -> t
209−
209+
210210-- Insert a key-value pair into a dictionary. Replaces value when there is
211211-- a collision.
212212insert : Comparable k -> v -> Dict (Comparable k) v -> Dict (Comparable k) v
@@ -265,7 +265,7 @@ isRedRightLeft t =
265265 _ -> False
266266
267267moveRedLeft : Dict k v -> Dict k v
268−moveRedLeft t =
268+moveRedLeft t =
269269 let t' = color_flip t in
270270 case t' of
271271 RBNode c k v l r ->
@@ -289,9 +289,9 @@ moveRedRightIfNeeded t =
289289 if isRedRight t || isRedRightLeft t then t else moveRedRight t
290290
291291deleteMin : Dict k v -> Dict k v
292−deleteMin t =
292+deleteMin t =
293293 let del t =
294− case t of
294+ case t of
295295 RBNode _ _ _ RBEmpty _ -> RBEmpty
296296 _ -> case moveRedLeftIfNeeded t of
297297 RBNode c k v l r -> fixUp (RBNode c k v (del l) r)
@@ -314,11 +314,11 @@ deleteMax t =
314314-- Remove a key-value pair from a dictionary. If the key is not found,
315315-- no changes are made.
316316remove : Comparable k -> Dict (Comparable k) v -> Dict (Comparable k) v
317−remove k t =
317+remove k t =
318318 let eq_and_noRightNode t =
319319 case t of { RBNode _ k' _ _ RBEmpty -> k == k' ; _ -> False }
320320 eq t = case t of { RBNode _ k' _ _ _ -> k == k' ; _ -> False }
321− delLT t = case moveRedLeftIfNeeded t of
321+ delLT t = case moveRedLeftIfNeeded t of
322322 RBNode c k' v l r -> fixUp (RBNode c k' v (del l) r)
323323 RBEmpty -> Error.raise "delLT on Empty"
324324 delEQ t = case t of -- Replace with successor
@@ -328,7 +328,7 @@ remove k t =
328328 delGT t = case t of
329329 RBNode c k' v l r -> fixUp (RBNode c k' v l (del r))
330330 RBEmpty -> Error.raise "delGT called on a Empty"
331− del t = case t of
331+ del t = case t of
332332 RBEmpty -> RBEmpty
333333 RBNode _ k' _ _ _ ->
334334 if k < k' then delLT t else
libraries/Maybe.elm+1−1
@@ -30,4 +30,4 @@ 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 = List.foldr cons []
libraries/Native/Graphics/Input.js+2−2
@@ -57,7 +57,7 @@ Elm.Native.Graphics.Input = function(elm) {
5757 btn.elmUp = Render.render(model.up);
5858 btn.elmHover = Render.render(model.hover);
5959 btn.elmDown = Render.render(model.down);
60−
60+
6161 function replace(node) {
6262 if (node !== btn.firstChild) btn.replaceChild(node, btn.firstChild);
6363 }
@@ -218,4 +218,4 @@ Elm.Native.Graphics.Input = function(elm) {
218218 passwords:mkTextPool('password')
219219 };
220220
221−};
221+};
libraries/Native/Matrix2D.js+9−9
@@ -5,7 +5,7 @@ Elm.Native.Matrix2D = function(elm) {
55 elm.Native = elm.Native || {};
66 if (elm.Native.Matrix2D) return elm.Native.Matrix2D;
77
8− try { Float32Array; } catch(e) { Float32Array = Array; }
8+ if (typeof Float32Array === 'undefined'){ Float32Array = Array; }
99 var A = Float32Array;
1010
1111 // layout of matrix in an array is
@@ -26,12 +26,12 @@ Elm.Native.Matrix2D = function(elm) {
2626 var s = Math.sin(t);
2727 var m11 = m[0], m12 = m[1], m21 = m[3], m22 = m[4];
2828 return new A([m11*c + m12*s, -m11*s + m12*c, m[2],
29− m21*c + m22*s, -m21*s + m22*c, m[5]]);
29+ m21*c + m22*s, -m21*s + m22*c, m[5]]);
3030 }
3131 function move(x,y,m) {
3232 var m11 = m[0], m12 = m[1], m21 = m[3], m22 = m[4];
3333 return new A([m11, m12, m11*x + m12*y + m[2],
34− m21, m22, m21*x + m22*y + m[5]]);
34+ m21, m22, m21*x + m22*y + m[5]]);
3535 }
3636 function scale(s,m) { return new A([m[0]*s, m[1]*s, m[2], m[3]*s, m[4]*s, m[5]]); }
3737 function scaleX(x,m) { return new A([m[0]*x, m[1], m[2], m[3]*x, m[4], m[5]]); }
@@ -42,11 +42,11 @@ Elm.Native.Matrix2D = function(elm) {
4242 function transform(m11, m21, m12, m22, mdx, mdy, n) {
4343 var n11 = n[0], n12 = n[1], n21 = n[3], n22 = n[4], ndx = n[2], ndy = n[5];
4444 return new A([m11*n11 + m12*n21,
45− m11*n12 + m12*n22,
46− m11*ndx + m12*ndy + mdx,
47− m21*n11 + m22*n21,
48− m21*n12 + m22*n22,
49− m21*ndx + m22*ndy + mdy]);
45+ m11*n12 + m12*n22,
46+ m11*ndx + m12*ndy + mdx,
47+ m21*n11 + m22*n21,
48+ m21*n12 + m22*n22,
49+ m21*ndx + m22*ndy + mdy]);
5050 }
5151
5252 function multiply(m, n) {
@@ -68,4 +68,4 @@ Elm.Native.Matrix2D = function(elm) {
6868 reflectY:reflectY
6969 };
7070
71−};
71+};
libraries/Native/Prelude.js+36−35
@@ -8,62 +8,63 @@ Elm.Native.Prelude = function(elm) {
88 var Utils = Elm.Native.Utils(elm);
99 var Char = Elm.Char(elm);
1010
11− function div(a,b) { return (a/b)|0 }
12− function rem(a,b) { return a % b }
11+ function div(a,b) { return (a/b)|0; }
12+ function rem(a,b) { return a % b; }
1313 function mod(a,b) {
1414 var r = a % b;
1515 var m = a === 0 ? 0 : (b > 0 ? (a >= 0 ? r : r+b) : -mod(-a,-b));
16+
1617 return m === b ? 0 : m;
1718 }
18− function abs(x) { return x < 0 ? -x : x }
19− function logBase(base,n) { return Math.log(n) / Math.log(base) }
20− function min(a,b) { return a < b ? a : b }
21− function max(a,b) { return a > b ? a : b }
22− function clamp(lo,hi,n) { return n < lo ? lo : n > hi ? hi : n }
23− function xor(a,b) { return a !== b }
24− function not(b) { return !b }
25−
26− function truncate(n) { return n|0 }
27−
28− function id(n) { return n }
29− function flip(f,a,b) { return A2(f,b,a) }
30− function curry(f,a,b) { return f(Utils.Tuple2(a,b)) }
31− function uncurry(f,v) { return A2(f,v._0,v._1) }
32− function fst(t) { return t._0 }
33− function snd(t) { return t._1 }
19+ function abs(x) { return x < 0 ? -x : x; }
20+ function logBase(base,n) { return Math.log(n) / Math.log(base); }
21+ function min(a,b) { return a < b ? a : b; }
22+ function max(a,b) { return a > b ? a : b; }
23+ function clamp(lo,hi,n) { return n < lo ? lo : n > hi ? hi : n; }
24+ function xor(a,b) { return a !== b; }
25+ function not(b) { return !b; }
26+
27+ function truncate(n) { return n|0; }
28+
29+ function id(n) { return n; }
30+ function flip(f,a,b) { return A2(f,b,a); }
31+ function curry(f,a,b) { return f(Utils.Tuple2(a,b)); }
32+ function uncurry(f,v) { return A2(f,v._0,v._1); }
33+ function fst(t) { return t._0; }
34+ function snd(t) { return t._1; }
3435
3536 function readInt(str) {
3637 var s = JS.fromString(str);
3738 var len = s.length;
38− if (len === 0) { return Maybe.Nothing }
39+ if (len === 0) { return Maybe.Nothing; }
3940 var start = 0;
4041 if (s[0] == '-') {
41− if (len === 1) { return Maybe.Nothing }
42− start = 1;
42+ if (len === 1) { return Maybe.Nothing; }
43+ start = 1;
4344 }
4445 for (var i = start; i < len; ++i) {
45− if (!Char.isDigit(s[i])) { return Maybe.Nothing }
46+ if (!Char.isDigit(s[i])) { return Maybe.Nothing; }
4647 }
47− return Maybe.Just(parseInt(s));
48+ return Maybe.Just(parseInt(s, 10));
4849 }
49−
50+
5051 function readFloat(str) {
5152 var s = JS.fromString(str);
5253 var len = s.length;
5354 if (len === 0) { return Maybe.Nothing; }
5455 var start = 0;
5556 if (s[0] == '-') {
56− if (len === 1) { return Maybe.Nothing; }
57− start = 1;
57+ if (len === 1) { return Maybe.Nothing; }
58+ start = 1;
5859 }
5960 var dotCount = 0;
6061 for (var i = start; i < len; ++i) {
61− if (Char.isDigit(s[i])) { continue; }
62− if (s[i] === '.') {
63− dotCount += 1;
64− if (dotCount <= 1) { continue; }
65− }
66− return Maybe.Nothing;
62+ if (Char.isDigit(s[i])) { continue; }
63+ if (s[i] === '.') {
64+ dotCount += 1;
65+ if (dotCount <= 1) { continue; }
66+ }
67+ return Maybe.Nothing;
6768 }
6869 return Maybe.Just(parseFloat(s));
6970 }
@@ -113,8 +114,8 @@ Elm.Native.Prelude = function(elm) {
113114 };
114115
115116 function add(Module) {
116− var M = Module(elm);
117− for (var k in M) { prelude[k] = M[k] }
117+ var M = Module(elm);
118+ for (var k in M) { prelude[k] = M[k]; }
118119 }
119120 add(Elm.Native.Show);
120121 add(Elm.Signal);
@@ -124,4 +125,4 @@ Elm.Native.Prelude = function(elm) {
124125 add(Elm.Graphics.Element);
125126
126127 return elm.Native.Prelude = prelude;
127−};
128+};
libraries/Native/Show.js+1−1
@@ -96,4 +96,4 @@ Elm.Native.Show = function(elm) {
9696 }
9797
9898 return elm.Native.Show = { show:show };
99−};
99+};
libraries/Native/Signal/Http.js+4−4
@@ -39,16 +39,16 @@ Elm.Native.Http = function(elm) {
3939 request.onreadystatechange = function(e) {
4040 if (request.readyState === 4) {
4141 response.value = (request.status === 200 ?
42− { ctor:'Success', _0:JS.toString(request.responseText) } :
43− { ctor:'Failure', _0:request.status, _1:JS.toString(request.statusText) });
44− setTimeout(function() { updateQueue(queue,responses); }, 0);
42+ { ctor:'Success', _0:JS.toString(request.responseText) } :
43+ { ctor:'Failure', _0:request.status, _1:JS.toString(request.statusText) });
44+ setTimeout(function() { updateQueue(queue,responses); }, 0);
4545 }
4646 };
4747 request.open(JS.fromString(req.verb), JS.fromString(req.url), true);
4848 List.map(setHeader)(req.headers);
4949 request.send(JS.fromString(req.body));
5050 }
51−
51+
5252 function send(requests) {
5353 var responses = Signal.constant(elm.Http.Waiting);
5454 var sender = A2( Signal.lift, registerReq([],responses), requests );
libraries/Native/Signal/Keyboard.js+7−7
@@ -47,13 +47,13 @@ Elm.Native.Keyboard = function(elm) {
4747 function f(ks) {
4848 var x = 0, y = 0;
4949 while (ks.ctor == "Cons") {
50− switch (ks._0) {
51− case left : --x; break;
52− case right: ++x; break;
53− case up : ++y; break;
54− case down : --y; break;
55− }
56− ks = ks._1;
50+ switch (ks._0) {
51+ case left : --x; break;
52+ case right: ++x; break;
53+ case up : ++y; break;
54+ case down : --y; break;
55+ }
56+ ks = ks._1;
5757 }
5858 return { _:{}, x:x, y:y };
5959 }
libraries/Native/Signal/Random.js+4−4
@@ -11,11 +11,11 @@ Elm.Native.Random = function(elm) {
1111 return A2( Signal.lift, f, signal );
1212 }
1313
14− function float(signal) {
15− function f(x) { return Math.random() }
14+ function flt(signal) {
15+ function f(x) { return Math.random(); }
1616 return A2( Signal.lift, f, signal );
1717 }
1818
19− return elm.Native.Random = { range: F3(range), float: float };
19+ return elm.Native.Random = { range: F3(range), float: flt };
2020
21−};
21+};
libraries/Native/Signal/Signal.js+73−72
@@ -4,7 +4,7 @@ Elm.Native.Signal = function(elm) {
44
55 elm.Native = elm.Native || {};
66 if (elm.Native.Signal) return elm.Native.Signal;
7−
7+
88 var Utils = Elm.Native.Utils(elm);
99 var Either = Elm.Either(elm);
1010 var foldl1 = Elm.List(elm).foldl1;
@@ -44,45 +44,45 @@ Elm.Native.Signal = function(elm) {
4444 ++count;
4545 if (changed) { isChanged = true; }
4646 if (count == n) {
47− if (isChanged) { this.value = update() }
48− send(this, timestep, isChanged);
49− isChanged = false;
50− count = 0;
47+ if (isChanged) { this.value = update(); }
48+ send(this, timestep, isChanged);
49+ isChanged = false;
50+ count = 0;
5151 }
5252 };
5353 for (var i = n; i--; ) { args[i].kids.push(this); }
5454 }
5555
5656 function lift(func, a) {
57− function update() { return func(a.value) }
57+ function update() { return func(a.value); }
5858 return new LiftN(update, [a]);
5959 }
6060 function lift2(func, a, b) {
61− function update() { return A2( func, a.value, b.value ) }
61+ function update() { return A2( func, a.value, b.value ); }
6262 return new LiftN(update, [a,b]);
6363 }
6464 function lift3(func, a, b, c) {
65− function update() { return A3( func, a.value, b.value, c.value ) }
65+ function update() { return A3( func, a.value, b.value, c.value ); }
6666 return new LiftN(update, [a,b,c]);
6767 }
6868 function lift4(func, a, b, c, d) {
69− function update() { return A4( func, a.value, b.value, c.value, d.value ) }
69+ function update() { return A4( func, a.value, b.value, c.value, d.value ); }
7070 return new LiftN(update, [a,b,c,d]);
7171 }
7272 function lift5(func, a, b, c, d, e) {
73− function update() { return A5( func, a.value, b.value, c.value, d.value, e.value ) }
73+ function update() { return A5( func, a.value, b.value, c.value, d.value, e.value ); }
7474 return new LiftN(update, [a,b,c,d,e]);
7575 }
7676 function lift6(func, a, b, c, d, e, f) {
77− function update() { return A6( func, a.value, b.value, c.value, d.value, e.value, f.value ) }
77+ function update() { return A6( func, a.value, b.value, c.value, d.value, e.value, f.value ); }
7878 return new LiftN(update, [a,b,c,d,e,f]);
7979 }
8080 function lift7(func, a, b, c, d, e, f, g) {
81− function update() { return A7( func, a.value, b.value, c.value, d.value, e.value, f.value, g.value ) }
81+ function update() { return A7( func, a.value, b.value, c.value, d.value, e.value, f.value, g.value ); }
8282 return new LiftN(update, [a,b,c,d,e,f,g]);
8383 }
8484 function lift8(func, a, b, c, d, e, f, g, h) {
85− function update() { return A8( func, a.value, b.value, c.value, d.value, e.value, f.value, g.value, h.value ) }
85+ function update() { return A8( func, a.value, b.value, c.value, d.value, e.value, f.value, g.value, h.value ); }
8686 return new LiftN(update, [a,b,c,d,e,f,g,h]);
8787 }
8888
@@ -95,38 +95,38 @@ Elm.Native.Signal = function(elm) {
9595 return new LiftN(update, [input]);
9696 }
9797
98− function dropIf(pred,base,input) {
98+ function DropIf(pred,base,input) {
9999 this.id = Utils.guid();
100100 this.value = pred(input.value) ? base : input.value;
101101 this.kids = [];
102102 this.recv = function(timestep, changed, parentID) {
103− var chng = changed && !pred(input.value);
104− if (chng) { this.value = input.value; }
105− send(this, timestep, chng);
103+ var chng = changed && !pred(input.value);
104+ if (chng) { this.value = input.value; }
105+ send(this, timestep, chng);
106106 };
107107 input.kids.push(this);
108108 }
109109
110− function dropRepeats(input) {
110+ function DropRepeats(input) {
111111 this.id = Utils.guid();
112112 this.value = input.value;
113113 this.kids = [];
114114 this.recv = function(timestep, changed, parentID) {
115− var chng = changed && !Utils.eq(this.value,input.value);
116− if (chng) { this.value = input.value; }
117− send(this, timestep, chng);
115+ var chng = changed && !Utils.eq(this.value,input.value);
116+ if (chng) { this.value = input.value; }
117+ send(this, timestep, chng);
118118 };
119119 input.kids.push(this);
120120 }
121−
121+
122122 function dropWhen(s1,b,s2) {
123− var pairs = lift2( F2(function(x,y){return {x:x,y:y}}), s1, s2 );
124− var dropped = new dropIf(function(p){return p.x},{x:true,y:b},pairs);
125− return lift(function(p){return p.y}, dropped)
123+ var pairs = lift2( F2(function(x,y){return {x:x,y:y};}), s1, s2 );
124+ var dropped = new DropIf(function(p){return p.x;},{x:true,y:b},pairs);
125+ return lift(function(p){return p.y;}, dropped);
126126 }
127127
128128 function timestamp(a) {
129− function update() { return Utils.Tuple2(Date.now(), a.value) }
129+ function update() { return Utils.Tuple2(Date.now(), a.value); }
130130 return new LiftN(update, [a]);
131131 }
132132
@@ -134,69 +134,69 @@ Elm.Native.Signal = function(elm) {
134134 this.id = Utils.guid();
135135 this.value = s2.value;
136136 this.kids = [];
137−
137+
138138 var count = 0;
139139 var isChanged = false;
140−
140+
141141 this.recv = function(timestep, changed, parentID) {
142− if (parentID === s1.id) isChanged = changed;
143− ++count;
144− if (count == 2) {
145− if (isChanged) { this.value = s2.value; }
146− send(this, timestep, isChanged);
147− count = 0;
148− isChanged = false;
149− }
142+ if (parentID === s1.id) isChanged = changed;
143+ ++count;
144+ if (count == 2) {
145+ if (isChanged) { this.value = s2.value; }
146+ send(this, timestep, isChanged);
147+ count = 0;
148+ isChanged = false;
149+ }
150150 };
151151 s1.kids.push(this);
152152 s2.kids.push(this);
153153 }
154154
155− function sampleOn(s1,s2) { return new SampleOn(s1,s2) }
155+ function sampleOn(s1,s2) { return new SampleOn(s1,s2); }
156156
157157 function delay(t,s) {
158158 var delayed = new Input(s.value);
159159 var firstEvent = true;
160160 function update(v) {
161− if (firstEvent) { firstEvent = false; return; }
162− setTimeout(function() { elm.notify(delayed.id, v) }, t);
161+ if (firstEvent) { firstEvent = false; return; }
162+ setTimeout(function() { elm.notify(delayed.id, v); }, t);
163163 }
164− function first(a,b) { return a }
164+ function first(a,b) { return a; }
165165 return new SampleOn(delayed, lift2(F2(first), delayed, lift(update,s)));
166166 }
167−
167+
168168 function Merge(s1,s2) {
169169 this.id = Utils.guid();
170170 this.value = s1.value;
171171 this.kids = [];
172−
172+
173173 var next = null;
174174 var count = 0;
175175 var isChanged = false;
176−
176+
177177 this.recv = function(timestep, changed, parentID) {
178− ++count;
179− if (changed) {
180− isChanged = true;
181− if (parentID == s2.id && next === null) { next = s2.value; }
182− if (parentID == s1.id) { next = s1.value; }
183− }
184−
185− if (count == 2) {
186− if (isChanged) { this.value = next; next = null; }
187− send(this, timestep, isChanged);
188− isChanged = false;
189− count = 0;
190− }
178+ ++count;
179+ if (changed) {
180+ isChanged = true;
181+ if (parentID == s2.id && next === null) { next = s2.value; }
182+ if (parentID == s1.id) { next = s1.value; }
183+ }
184+
185+ if (count == 2) {
186+ if (isChanged) { this.value = next; next = null; }
187+ send(this, timestep, isChanged);
188+ isChanged = false;
189+ count = 0;
190+ }
191191 };
192192 s1.kids.push(this);
193193 s2.kids.push(this);
194194 }
195195
196− function merge(s1,s2) { return new Merge(s1,s2) }
197− function merges(ss) { return A2(foldl1, F2(merge), ss) }
196+ function merge(s1,s2) { return new Merge(s1,s2); }
197+ function merges(ss) { return A2(foldl1, F2(merge), ss); }
198198 function mergeEither(s1,s2) { return new Merge(lift(Either.Left, s1),
199− lift(Either.Right,s2)) }
199+ lift(Either.Right,s2)); }
200200
201201 function average(sampleSize, s) {
202202 var sample = new Array(sampleSize);
@@ -206,13 +206,13 @@ Elm.Native.Signal = function(elm) {
206206 var full = false;
207207 var total = 0;
208208 function f(n) {
209− total += n - sample[i];
210− sample[i] = n;
211− var avg = total / Math.max(1, full ? sampleSize : i);
212− if (++i == sampleSize) { full = true; i = 0; }
213− return avg;
209+ total += n - sample[i];
210+ sample[i] = n;
211+ var avg = total / Math.max(1, full ? sampleSize : i);
212+ if (++i == sampleSize) { full = true; i = 0; }
213+ return avg;
214214 }
215− return lift(f,s);pp
215+ return lift(f,s);
216216 }
217217
218218 return elm.Native.Signal = {
@@ -231,17 +231,18 @@ Elm.Native.Signal = function(elm) {
231231 merges : merges,
232232 mergeEither : F2(mergeEither),
233233 average : F2(average),
234− count : function(s) { return foldp(F2(function(_,c) { return c+1 }), 0, s) },
234+ count : function(s) { return foldp(F2(function(_,c) { return c+1; }), 0, s); },
235235 countIf : F2(function(pred,s) {
236− return foldp(F2(function(x,c){return pred(x) ? c+1 : c}), 0, s)}),
236+ return foldp(F2(function(x,c){
237+ return pred(x) ? c+1 : c; }), 0, s)}),
237238 keepIf : F3(function(pred,base,sig) {
238− return new dropIf(function(x) {return !pred(x)},base,sig) }),
239− dropIf : F3(function(pred,base,sig) { return new dropIf(pred,base,sig) }),
239+ return new DropIf(function(x) {return !pred(x);},base,sig); }),
240+ dropIf : F3(function(pred,base,sig) { return new DropIf(pred,base,sig); }),
240241 keepWhen : F3(function(s1,b,s2) {
241− return dropWhen(lift(function(b){return !b;},s1), b, s2) }),
242+ return dropWhen(lift(function(b){return !b;},s1), b, s2); }),
242243 dropWhen : F3(dropWhen),
243− dropRepeats : function(s) { return new dropRepeats(s);},
244+ dropRepeats : function(s) { return new DropRepeats(s);},
244245 sampleOn : F2(sampleOn),
245246 timestamp : timestamp
246247 };
247−};
248+};
libraries/Native/Signal/Time.js+7−7
@@ -12,9 +12,9 @@ Elm.Native.Time = function(elm) {
1212 var ticker = Signal.constant(diff);
1313 function tick(zero) { return function() {
1414 curr = Date.now();
15− diff = zero ? 0 : curr - prev;
16− prev = curr;
17− elm.notify(ticker.id, diff);
15+ diff = zero ? 0 : curr - prev;
16+ prev = curr;
17+ elm.notify(ticker.id, diff);
1818 };
1919 }
2020 var timeoutID = 0;
@@ -22,14 +22,14 @@ Elm.Native.Time = function(elm) {
2222 if (isOn) {
2323 timeoutID = setTimeout(tick(!wasOn && isOn), msPerFrame);
2424 } else if (wasOn) {
25− clearTimeout(timeoutID);
25+ clearTimeout(timeoutID);
2626 }
2727 wasOn = isOn;
2828 return t;
2929 }
3030 return A3( Signal.lift2, F2(f), isOn, ticker );
3131 }
32−
32+
3333 function everyWhen(t, isOn) {
3434 var clock = Signal.constant(Date.now());
3535 function tellTime() { elm.notify(clock.id, Date.now()); }
@@ -38,7 +38,7 @@ Elm.Native.Time = function(elm) {
3838 }
3939
4040 function since(t, s) {
41− function cmp(a,b) { return !Utils.eq(a,b) }
41+ function cmp(a,b) { return !Utils.eq(a,b); }
4242 var dcount = Signal.count(A2(Signal.delay, t, s));
4343 return A3( Signal.lift2, F2(cmp), Signal.count(s), dcount );
4444 }
@@ -70,4 +70,4 @@ Elm.Native.Time = function(elm) {
7070 read : read
7171 };
7272
73−};
73+};
libraries/Native/Signal/Window.js+2−2
@@ -21,10 +21,10 @@ Elm.Native.Window = function(elm) {
2121
2222 // Do not move width and height into Elm. By setting the default number of kids,
2323 // the resize listener can be detached.
24− var width = A2(Signal.lift, function(p){return p._0}, dimensions);
24+ var width = A2(Signal.lift, function(p){return p._0;}, dimensions);
2525 width.defaultNumberOfKids = 0;
2626
27− var height = A2(Signal.lift, function(p){return p._1}, dimensions);
27+ var height = A2(Signal.lift, function(p){return p._1;}, dimensions);
2828 height.defaultNumberOfKids = 0;
2929
3030 function resizeIfNeeded() {
libraries/Native/Utils.js+22−20
@@ -13,8 +13,8 @@ Elm.Native.Utils = function(elm) {
1313 return c === Object.keys(y).length;
1414 }
1515 if (typeof x === 'function') {
16− throw new Error('Equality error: general function equality is ' +
17− 'undecidable, and therefore, unsupported');
16+ throw new Error('Equality error: general function equality is ' +
17+ 'undecidable, and therefore, unsupported');
1818 }
1919 return x === y;
2020 }
@@ -22,18 +22,20 @@ Elm.Native.Utils = function(elm) {
2222 var EQ = 0, LT = 1, GT = 2, ord = ['EQ','LT','GT'];
2323 function compare(x,y) { return { ctor: ord[cmp(x,y)] } }
2424 function cmp(x,y) {
25+ var ord;
2526 if (typeof x !== 'object') return x === y ? EQ : x < y ? LT : GT;
2627
2728 if (x.ctor === "Cons" || x.ctor === "Nil") {
28− while (true) {
29− if (x.ctor === "Nil" && y.ctor === "Nil") return EQ;
30− if (x.ctor !== y.ctor) return {ctor: x.ctor==='Nil'?LT:GT};
31− var ord = cmp(x._0, y._0);
32− if (ord !== EQ) return ord;
33− x = x._1;
34− y = y._1;
35− }
29+ while (true) {
30+ if (x.ctor === "Nil" && y.ctor === "Nil") return EQ;
31+ if (x.ctor !== y.ctor) return x.ctor === 'Nil' ? LT : GT;
32+ ord = cmp(x._0, y._0);
33+ if (ord !== EQ) return ord;
34+ x = x._1;
35+ y = y._1;
36+ }
3637 }
38+
3739 if (x.ctor.slice(0,5) === 'Tuple') {
3840 var n = x.ctor.slice(5) - 0;
3941 var err = 'cannot compare tuples with more than 6 elements.';
@@ -48,8 +50,8 @@ Elm.Native.Utils = function(elm) {
4850 return EQ;
4951 }
5052 throw new Error('Comparison error: comparison is only defined on ints, ' +
51− 'floats, times, chars, strings, lists of comparable values, ' +
52− 'and tuples of comparable values.')
53+ 'floats, times, chars, strings, lists of comparable values, ' +
54+ 'and tuples of comparable values.')
5355 }
5456
5557
@@ -68,11 +70,11 @@ Elm.Native.Utils = function(elm) {
6870 function remove(x,r) {
6971 var o = copy(r);
7072 if (x in o._) {
71− o[x] = o._[x][0];
72− o._[x] = o._[x].slice(1);
73− if (o._[x].length === 0) { delete o._[x]; }
73+ o[x] = o._[x][0];
74+ o._[x] = o._[x].slice(1);
75+ if (o._[x].length === 0) { delete o._[x]; }
7476 } else {
75− delete o[x];
77+ delete o[x];
7678 }
7779 return o;
7880 }
@@ -80,8 +82,8 @@ Elm.Native.Utils = function(elm) {
8082 function replace(kvs,r) {
8183 var o = copy(r);
8284 for (var i = kvs.length; i--; ) {
83− var kvsi = kvs[i];
84− o[kvsi[0]] = kvsi[1];
85+ var kvsi = kvs[i];
86+ o[kvsi[0]] = kvsi[1];
8587 }
8688 return o;
8789 }
@@ -103,7 +105,7 @@ Elm.Native.Utils = function(elm) {
103105 t.style.visibility = "hidden";
104106 t.style.styleFloat = "left";
105107 t.style.cssFloat = "left";
106−
108+
107109 elm.node.appendChild(t);
108110 var w = t.clientWidth;
109111 var h = t.clientHeight;
@@ -144,4 +146,4 @@ Elm.Native.Utils = function(elm) {
144146 htmlHeight: F2(htmlHeight),
145147 toFloat: function(x){return x}
146148 };
147−};
149+};
runtime/Init.js+7−7
@@ -27,7 +27,7 @@ function init(display, container, module) {
2727 var signalGraph = null;
2828 var inputs = [];
2929 var visualModel = null;
30−
30+
3131 function notify(id, v) {
3232 var timestep = Date.now();
3333 var hasListener = false;
@@ -42,7 +42,7 @@ function init(display, container, module) {
4242 container.offsetX = 0;
4343 container.offsetY = 0;
4444
45− // create the actuall RTS. Any impure modules will attach themselves to this
45+ // create the actual RTS. Any impure modules will attach themselves to this
4646 // object. This permits many Elm programs to be embedded per document.
4747 var elm = { notify:notify,
4848 node:container,
@@ -53,7 +53,7 @@ function init(display, container, module) {
5353
5454 // Set up methods to communicate with Elm program from JS.
5555 function send(name, value) {
56− if (typeof value === 'undefined') return function(v) { return send(name,v) };
56+ if (typeof value === 'undefined') return function(v) { return send(name,v); };
5757 var e = document.createEvent('Event');
5858 e.initEvent(name + '_' + elm.id, true, true);
5959 e.value = value;
@@ -66,8 +66,8 @@ function init(display, container, module) {
6666 recv('log', function(e) {console.log(e.value)});
6767 recv('title', function(e) {document.title = e.value});
6868 recv('redirect', function(e) {
69− if (e.value.length > 0) { window.location = e.value; }
70− });
69+ if (e.value.length > 0) { window.location = e.value; }
70+ });
7171
7272 // If graphics are not enabled, escape early, skip over setting up DOM stuff.
7373 if (display === ElmRuntime.Display.NONE) {
@@ -78,7 +78,7 @@ function init(display, container, module) {
7878
7979 // evaluate the given module and extract its 'main' value.
8080 signalGraph = module(elm).main;
81−
81+
8282 // make sure the signal graph is actually a signal, extract the visual model,
8383 // and filter out any unused inputs.
8484 var Signal = Elm.Signal(elm);
@@ -101,7 +101,7 @@ function init(display, container, module) {
101101 });
102102 return value;
103103 }
104−
104+
105105 signalGraph = A2(Signal.lift, domUpdate, signalGraph);
106106
107107 return { send : send, recv : recv, node : container };
runtime/Render/Collage.js+36−25
@@ -16,8 +16,8 @@ function trace(ctx, path) {
1616 ctx.moveTo(points[i]._0, points[i]._1);
1717 while (i--) { ctx.lineTo(points[i]._0, points[i]._1); }
1818 if (path.closed) {
19− i = points.length - 1;
20− ctx.lineTo(points[i]._0, points[i]._1);
19+ i = points.length - 1;
20+ ctx.lineTo(points[i]._0, points[i]._1);
2121 }
2222}
2323
@@ -38,26 +38,26 @@ function customLineHelp(ctx, style, path) {
3838 var draw = true, segmentLength = pattern[0];
3939 ctx.moveTo(x0,y0);
4040 while (i--) {
41− x1 = points[i]._0; y1 = points[i]._1;
42− dx = x1 - x0; dy = y1 - y0;
43− remaining = Math.sqrt(dx * dx + dy * dy);
44− while (segmentLength <= remaining) {
45− x0 += dx * segmentLength / remaining;
46− y0 += dy * segmentLength / remaining;
47− ctx[draw ? 'lineTo' : 'moveTo'](x0, y0);
48− // update starting position
49− dx = x1 - x0; dy = y1 - y0;
50− remaining = Math.sqrt(dx * dx + dy * dy);
51− // update pattern
52− draw = !draw;
53− pindex = (pindex + 1) % plen;
54− segmentLength = pattern[pindex];
55− }
56− if (remaining > 0) {
57− ctx[draw ? 'lineTo' : 'moveTo'](x1, y1);
58− segmentLength -= remaining;
59− }
60− x0 = x1; y0 = y1;
41+ x1 = points[i]._0; y1 = points[i]._1;
42+ dx = x1 - x0; dy = y1 - y0;
43+ remaining = Math.sqrt(dx * dx + dy * dy);
44+ while (segmentLength <= remaining) {
45+ x0 += dx * segmentLength / remaining;
46+ y0 += dy * segmentLength / remaining;
47+ ctx[draw ? 'lineTo' : 'moveTo'](x0, y0);
48+ // update starting position
49+ dx = x1 - x0; dy = y1 - y0;
50+ remaining = Math.sqrt(dx * dx + dy * dy);
51+ // update pattern
52+ draw = !draw;
53+ pindex = (pindex + 1) % plen;
54+ segmentLength = pattern[pindex];
55+ }
56+ if (remaining > 0) {
57+ ctx[draw ? 'lineTo' : 'moveTo'](x1, y1);
58+ segmentLength -= remaining;
59+ }
60+ x0 = x1; y0 = y1;
6161 }
6262}
6363
@@ -112,8 +112,19 @@ function drawImage(redo, ctx, form) {
112112 var img = new Image();
113113 img.onload = redo;
114114 img.src = fromString(form._3);
115− var w = form._0, h = form._1, pos = form._2;
116− ctx.drawImage(img, pos._0, pos._1, w, h, -w/2, -h/2, w, h);
115+ var w = form._0,
116+ h = form._1,
117+ pos = form._2,
118+ srcX = pos._0,
119+ srcY = pos._1,
120+ srcW = w,
121+ srcH = h,
122+ destX = -w/2,
123+ destY = -h/2,
124+ destW = w,
125+ destH = h;
126+
127+ ctx.drawImage(img, srcX, srcY, srcW, srcH, destX, destY, destW, destH);
117128}
118129
119130function renderForm(redo, ctx, form) {
@@ -317,4 +328,4 @@ function update(div, _, model) {
317328
318329return { render:render, update:update };
319330
320−};
331+};
runtime/Utils.js+5−5
@@ -15,11 +15,11 @@ ElmRuntime.use = function(M) {
1515function isAlive(input) {
1616 if (!('defaultNumberOfKids' in input)) return true;
1717 var len = input.kids.length;
18− if (len == 0) return false;
18+ if (len === 0) return false;
1919 if (len > input.defaultNumberOfKids) return true;
2020 var alive = false;
2121 for (var i = len; i--; ) {
22− alive = alive || isAlive(input.kids[i]);
22+ alive = alive || isAlive(input.kids[i]);
2323 }
2424 return alive;
2525}
@@ -27,7 +27,7 @@ function isAlive(input) {
2727ElmRuntime.filterDeadInputs = function(inputs) {
2828 var temp = [];
2929 for (var i = inputs.length; i--; ) {
30− if (isAlive(inputs[i])) temp.push(inputs[i]);
30+ if (isAlive(inputs[i])) temp.push(inputs[i]);
3131 }
3232 return temp;
3333};
@@ -36,8 +36,8 @@ ElmRuntime.filterDeadInputs = function(inputs) {
3636var vendors = ['ms', 'moz', 'webkit', 'o'];
3737for (var i = 0; i < vendors.length && !window.requestAnimationFrame; ++i) {
3838 window.requestAnimationFrame = window[vendors[i]+'RequestAnimationFrame'];
39− window.cancelAnimationFrame = window[vendors[i]+'CancelAnimationFrame']
40− || window[vendors[i]+'CancelRequestAnimationFrame'];
39+ window.cancelAnimationFrame = window[vendors[i]+'CancelAnimationFrame'] ||
40+ window[vendors[i]+'CancelRequestAnimationFrame'];
4141}
4242
4343if (window.requestAnimationFrame && window.cancelAnimationFrame) {