on master help sign in
Whitespace, semicolons, lint etc. No functional changes.
commit2b90d0eb9e18387757073d739718b9b8801ff1bf authorColin Curtin <colin.t.curtin@gmail.com> dateSat 11 May 2013, 13:42 (13 years ago) parentd8067fd
14 files changed+244−240
libraries/Dict.elm+22−22 libraries/Native/Graphics/Input.js+2−2 libraries/Native/Matrix2D.js+8−8 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/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+15−15 runtime/Render/Collage.js+40−40 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/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+8−8
@@ -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
@@ -115,4 +115,4 @@ Elm.Native.Show = function(elm) {
115115 }
116116
117117 return elm.Native.Show = { show:show };
118−};
118+};
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/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
@@ -18,10 +18,10 @@ Elm.Native.Window = function(elm) {
1818
1919 // Do not move width and height into Elm. By setting the default number of kids,
2020 // the resize listener can be detached.
21− var width = A2(Signal.lift, function(p){return p._0}, dimensions);
21+ var width = A2(Signal.lift, function(p){return p._0;}, dimensions);
2222 width.defaultNumberOfKids = 0;
2323
24− var height = A2(Signal.lift, function(p){return p._1}, dimensions);
24+ var height = A2(Signal.lift, function(p){return p._1;}, dimensions);
2525 height.defaultNumberOfKids = 0;
2626
2727 function resize(e) {
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;
@@ -127,4 +129,4 @@ Elm.Native.Utils = function(elm) {
127129 htmlHeight: F2(htmlHeight),
128130 toFloat: function(x){return x}
129131 };
130−};
132+};
runtime/Init.js+15−15
@@ -6,7 +6,7 @@ Elm.init = function(module, baseNode) {
66 var signalGraph = null;
77 var inputs = [];
88 var visualModel = null;
9−
9+
1010 function notify(id, v) {
1111 var timestep = Date.now();
1212 var hasListener = false;
@@ -24,17 +24,17 @@ Elm.init = function(module, baseNode) {
2424 var style = document.createElement('style');
2525 style.type = 'text/css';
2626 style.innerHTML = "html,head,body { padding:0; margin:0; }" +
27− "body { font-family: calibri, helvetica, arial, sans-serif; }";
27+ "body { font-family: calibri, helvetica, arial, sans-serif; }";
2828 document.head.appendChild(style);
2929 }
3030
31− // create the actuall RTS. Any impure modules will attach themselves to this
31+ // create the actual RTS. Any impure modules will attach themselves to this
3232 // object. This permits many Elm programs to be embedded per document.
3333 var elm = {notify: notify, node: baseNode, id: ElmRuntime.guid(), inputs: inputs};
3434
3535 // Set up methods to communicate with Elm program from JS.
3636 function send(name, value) {
37− if (typeof value === 'undefined') return function(v) { return send(name,v) };
37+ if (typeof value === 'undefined') return function(v) { return send(name,v); };
3838 var e = document.createEvent('Event');
3939 e.initEvent(name + '_' + elm.id, true, true);
4040 e.value = value;
@@ -44,11 +44,11 @@ Elm.init = function(module, baseNode) {
4444 document.addEventListener(name + '_' + elm.id, handler);
4545 }
4646
47− recv('elm_log', function(e) {console.log(e.value)});
48− recv('elm_title', function(e) {document.title = e.value});
47+ recv('elm_log', function(e) {console.log(e.value);});
48+ recv('elm_title', function(e) {document.title = e.value;});
4949 recv('elm_redirect', function(e) {
50− if (e.value.length > 0) { window.location = e.value; }
51− });
50+ if (e.value.length > 0) { window.location = e.value; }
51+ });
5252
5353 // If graphics are not enabled, escape early, skip over setting up DOM stuff.
5454 if (baseNode === null) return { send : send, recv : recv };
@@ -58,14 +58,14 @@ Elm.init = function(module, baseNode) {
5858
5959 // evaluate the given module and extract its 'main' value.
6060 signalGraph = module(elm).main;
61−
61+
6262 // make sure the signal graph is actually a signal, extract the visual model,
6363 // and filter out any unused inputs.
6464 var Signal = Elm.Signal(elm);
6565 if (!('recv' in signalGraph)) signalGraph = Signal.constant(signalGraph);
6666 visualModel = signalGraph.value;
6767 inputs = ElmRuntime.filterDeadInputs(inputs);
68−
68+
6969 var tuple2 = Elm.Native.Utils(elm).Tuple2;
7070 function adjustWindow() {
7171 if ('Window' in elm) {
@@ -77,12 +77,12 @@ Elm.init = function(module, baseNode) {
7777 }
7878 }
7979 }
80−
80+
8181 // Add the visualModel to the DOM
82− var renderNode = Render.render(visualModel)
82+ var renderNode = Render.render(visualModel);
8383 baseNode.appendChild(renderNode);
8484 adjustWindow();
85−
85+
8686 // set up updates so that the DOM is adjusted as necessary.
8787 var update = Render.update;
8888 function domUpdate(value) {
@@ -93,8 +93,8 @@ Elm.init = function(module, baseNode) {
9393 });
9494 return value;
9595 }
96−
96+
9797 signalGraph = A2(Signal.lift, domUpdate, signalGraph);
98−
98+
9999 return { send : send, recv : recv };
100100};
runtime/Render/Collage.js+40−40
@@ -37,26 +37,26 @@ function customLineHelp(ctx, style, path) {
3737 var draw = true, segmentLength = pattern[0];
3838 ctx.moveTo(x0,y0);
3939 while (i--) {
40− x1 = points[i]._0; y1 = points[i]._1;
41− dx = x1 - x0; dy = y1 - y0;
42− remaining = Math.sqrt(dx * dx + dy * dy);
43− while (segmentLength <= remaining) {
44− x0 += dx * segmentLength / remaining;
45− y0 += dy * segmentLength / remaining;
46− ctx[draw ? 'lineTo' : 'moveTo'](x0, y0);
47− // update starting position
48− dx = x1 - x0; dy = y1 - y0;
49− remaining = Math.sqrt(dx * dx + dy * dy);
50− // update pattern
51− draw = !draw;
52− pindex = (pindex + 1) % plen;
53− segmentLength = pattern[pindex];
54− }
55− if (remaining > 0) {
56− ctx[draw ? 'lineTo' : 'moveTo'](x1, y1);
57− segmentLength -= remaining;
58− }
59− x0 = x1; y0 = y1;
40+ x1 = points[i]._0; y1 = points[i]._1;
41+ dx = x1 - x0; dy = y1 - y0;
42+ remaining = Math.sqrt(dx * dx + dy * dy);
43+ while (segmentLength <= remaining) {
44+ x0 += dx * segmentLength / remaining;
45+ y0 += dy * segmentLength / remaining;
46+ ctx[draw ? 'lineTo' : 'moveTo'](x0, y0);
47+ // update starting position
48+ dx = x1 - x0; dy = y1 - y0;
49+ remaining = Math.sqrt(dx * dx + dy * dy);
50+ // update pattern
51+ draw = !draw;
52+ pindex = (pindex + 1) % plen;
53+ segmentLength = pattern[pindex];
54+ }
55+ if (remaining > 0) {
56+ ctx[draw ? 'lineTo' : 'moveTo'](x1, y1);
57+ segmentLength -= remaining;
58+ }
59+ x0 = x1; y0 = y1;
6060 }
6161}
6262
@@ -79,18 +79,18 @@ function texture(redo, ctx, src) {
7979}
8080
8181function gradient(ctx, grad) {
82− var g;
82+ var g, p1, p2;
8383 if (grad.ctor === 'Linear') {
84− var p1 = grad._1, p2 = grad._2;
85− g = ctx.createLinearGradient(p1._0, p1._1, p2._0, p2._1);
84+ p1 = grad._1; p2 = grad._2;
85+ g = ctx.createLinearGradient(p1._0, p1._1, p2._0, p2._1);
8686 } else {
87− var p1 = grad._1, p2 = grad._3;
88− g = ctx.createRadialGradient(p1._0, p1._1, grad._2, p2._0, p2._1, grad._4);
87+ p1 = grad._1; p2 = grad._3;
88+ g = ctx.createRadialGradient(p1._0, p1._1, grad._2, p2._0, p2._1, grad._4);
8989 }
9090 var stops = fromList(grad._0);
9191 for (var i = stops.length; i--; ) {
92− var stop = stops[i];
93− g.addColorStop(stop._0, extract(stop._1));
92+ var stop = stops[i];
93+ g.addColorStop(stop._0, extract(stop._1));
9494 }
9595 return g;
9696}
@@ -123,23 +123,23 @@ function renderForm(stack, redo, ctx, form) {
123123 switch(f.ctor) {
124124 case 'FPath' : drawLine(ctx, f._0, f._1); break;
125125 case 'FShape':
126− if (f._0.ctor === 'Left') {
127− f._1.closed = true;
128− drawLine(ctx, f._0._0, f._1);
129− } else {
126+ if (f._0.ctor === 'Left') {
127+ f._1.closed = true;
128+ drawLine(ctx, f._0._0, f._1);
129+ } else {
130130 drawShape(redo, ctx, f._0._0, f._1);
131131 }
132− break;
132+ break;
133133 case 'FImage': drawImage(redo, ctx, f); break;
134134 case 'FGroup':
135− ctx.save();
136− var m = f._0;
135+ ctx.save();
136+ var m = f._0;
137137 // stack.push(makeTransform(x, y, theta, scale, m));
138− ctx.transform(m[0], m[3], m[1], m[4], m[2], m[5]);
139− renderForms(stack, redo, ctx, f._1);
138+ ctx.transform(m[0], m[3], m[1], m[4], m[2], m[5]);
139+ renderForms(stack, redo, ctx, f._1);
140140 // stack.pop();
141− ctx.restore();
142− break;
141+ ctx.restore();
142+ break;
143143 }
144144 ctx.restore();
145145}
@@ -207,10 +207,10 @@ function update(node, oldModel, newModel) {
207207 var ctx = node.getContext('2d');
208208 var w = newModel.w, h = newModel.h;
209209 ctx.clearRect(-w/2, -h/2, w, h);
210− function redo() { renderForms( [], this, ctx, newModel.forms ); }
210+ var redo = function(){ renderForms( [], this, ctx, newModel.forms ); };
211211 renderForms( [], redo, ctx, newModel.forms );
212212}
213213
214214return { render:render, update:update };
215215
216−};
216+};
runtime/Utils.js+5−5
@@ -13,11 +13,11 @@ ElmRuntime.use = function(M) {
1313function isAlive(input) {
1414 if (!('defaultNumberOfKids' in input)) return true;
1515 var len = input.kids.length;
16− if (len == 0) return false;
16+ if (len === 0) return false;
1717 if (len > input.defaultNumberOfKids) return true;
1818 var alive = false;
1919 for (var i = len; i--; ) {
20− alive = alive || isAlive(input.kids[i]);
20+ alive = alive || isAlive(input.kids[i]);
2121 }
2222 return alive;
2323}
@@ -25,7 +25,7 @@ function isAlive(input) {
2525ElmRuntime.filterDeadInputs = function(inputs) {
2626 var temp = [];
2727 for (var i = inputs.length; i--; ) {
28− if (isAlive(inputs[i])) temp.push(inputs[i]);
28+ if (isAlive(inputs[i])) temp.push(inputs[i]);
2929 }
3030 return temp;
3131};
@@ -34,8 +34,8 @@ ElmRuntime.filterDeadInputs = function(inputs) {
3434var vendors = ['ms', 'moz', 'webkit', 'o'];
3535for (var i = 0; i < vendors.length && !window.requestAnimationFrame; ++i) {
3636 window.requestAnimationFrame = window[vendors[i]+'RequestAnimationFrame'];
37− window.cancelAnimationFrame = window[vendors[i]+'CancelAnimationFrame']
38− || window[vendors[i]+'CancelRequestAnimationFrame'];
37+ window.cancelAnimationFrame = window[vendors[i]+'CancelAnimationFrame'] ||
38+ window[vendors[i]+'CancelRequestAnimationFrame'];
3939}
4040
4141if (window.requestAnimationFrame && window.cancelAnimationFrame) {