@@ -9,7 +9,7 @@ Elm.Native.List = function(elm) {
9 var Utils = Elm.Native.Utils(elm);
9 var Utils = Elm.Native.Utils(elm);
11 // TODO: Improve Nil handling
11 // TODO: Improve Nil handling
12− // We can change places like: if (xs.ctor === 'Nil') ... to if (xs === Nil) ...
12+ // We can change places like: if (xs.ctor === '[]') ... to if (xs === Nil) ...
13 // but only if we're confident Nil can only be defined once.
13 // but only if we're confident Nil can only be defined once.
14 // Currently (27Mar2013) each module can have different instantiations, so multiple Nil objects can exist
14 // Currently (27Mar2013) each module can have different instantiations, so multiple Nil objects can exist
15 // (and if they're used interchangeably then direct object comparison fails where ctor doesn't).
15 // (and if they're used interchangeably then direct object comparison fails where ctor doesn't).
@@ -17,11 +17,11 @@ Elm.Native.List = function(elm) {
17 // The performance overhead of the .ctor calls is 5-10% according to jsperf (depending on fn + list size)
17 // The performance overhead of the .ctor calls is 5-10% according to jsperf (depending on fn + list size)
18 // (on firefox 19)
18 // (on firefox 19)
20− var Nil = { ctor:'Nil' };
20+ var Nil = { ctor:'[]' };
22 // using freeze for every cons would be nice but is a huge (9x on firefox 19)
22 // using freeze for every cons would be nice but is a huge (9x on firefox 19)
23 // performance penalty
23 // performance penalty
24− function Cons(hd,tl) { return { ctor:"Cons", _0:hd, _1:tl }; }
24+ function Cons(hd,tl) { return { ctor:"::", _0:hd, _1:tl }; }
26 function throwError(f) {
26 function throwError(f) {
27 throw new Error("Function '" + f + "' expects a non-empty list!");
27 throw new Error("Function '" + f + "' expects a non-empty list!");
@@ -29,7 +29,7 @@ Elm.Native.List = function(elm) {
30 function toArray(xs) {
30 function toArray(xs) {
31 var out = [];
31 var out = [];
32− while (xs.ctor !== 'Nil') {
32+ while (xs.ctor !== '[]') {
33 out.push(xs._0);
33 out.push(xs._0);
34 xs = xs._1;
34 xs = xs._1;
@@ -54,11 +54,11 @@ Elm.Native.List = function(elm) {
55 function append(xs,ys) {
55 function append(xs,ys) {
56 if (typeof xs === "string") { return xs.concat(ys); }
56 if (typeof xs === "string") { return xs.concat(ys); }
57− if (xs.ctor === 'Nil') { return ys; }
57+ if (xs.ctor === '[]') { return ys; }
58 var root = Cons(xs._0, Nil);
58 var root = Cons(xs._0, Nil);
59 var curr = root;
59 var curr = root;
60 xs = xs._1;
60 xs = xs._1;
61− while (xs.ctor !== 'Nil') {
61+ while (xs.ctor !== '[]') {
62 curr._1 = Cons(xs._0, Nil);
62 curr._1 = Cons(xs._0, Nil);
63 xs = xs._1;
63 xs = xs._1;
64 curr = curr._1;
64 curr = curr._1;
@@ -67,13 +67,13 @@ Elm.Native.List = function(elm) {
67 return root;
67 return root;
70− function head(v) { return v.ctor === 'Nil' ? throwError('head') : v._0; }
70+ function head(v) { return v.ctor === '[]' ? throwError('head') : v._0; }
71− function tail(v) { return v.ctor === 'Nil' ? throwError('tail') : v._1; }
71+ function tail(v) { return v.ctor === '[]' ? throwError('tail') : v._1; }
73 function last(xs) {
73 function last(xs) {
74− if (xs.ctor === 'Nil') { throwError('last'); }
74+ if (xs.ctor === '[]') { throwError('last'); }
75 var out = xs._0;
75 var out = xs._0;
76− while (xs.ctor !== 'Nil') {
76+ while (xs.ctor !== '[]') {
77 out = xs._0;
77 out = xs._0;
78 xs = xs._1;
78 xs = xs._1;
@@ -82,7 +82,7 @@ Elm.Native.List = function(elm) {
83 function map(f, xs) {
83 function map(f, xs) {
84 var arr = [];
84 var arr = [];
85− while (xs.ctor !== 'Nil') {
85+ while (xs.ctor !== '[]') {
86 arr.push(f(xs._0));
86 arr.push(f(xs._0));
87 xs = xs._1;
87 xs = xs._1;
@@ -93,7 +93,7 @@ Elm.Native.List = function(elm) {
93 // ie, foldl :: (a -> b -> b) -> b -> [a] -> b
93 // ie, foldl :: (a -> b -> b) -> b -> [a] -> b
94 function foldl(f, b, xs) {
94 function foldl(f, b, xs) {
95 var acc = b;
95 var acc = b;
96− while (xs.ctor !== 'Nil') {
96+ while (xs.ctor !== '[]') {
97 acc = A2(f, xs._0, acc);
97 acc = A2(f, xs._0, acc);
98 xs = xs._1;
98 xs = xs._1;
@@ -110,11 +110,11 @@ Elm.Native.List = function(elm) {
112 function foldl1(f, xs) {
112 function foldl1(f, xs) {
113− return xs.ctor === 'Nil' ? throwError('foldl1') : foldl(f, xs._0, xs._1);
113+ return xs.ctor === '[]' ? throwError('foldl1') : foldl(f, xs._0, xs._1);
116 function foldr1(f, xs) {
116 function foldr1(f, xs) {
117− if (xs.ctor === 'Nil') { throwError('foldr1'); }
117+ if (xs.ctor === '[]') { throwError('foldr1'); }
118 var arr = toArray(xs);
118 var arr = toArray(xs);
119 var acc = arr.pop();
119 var acc = arr.pop();
120 for (var i = arr.length; i--; ) {
120 for (var i = arr.length; i--; ) {
@@ -134,12 +134,12 @@ Elm.Native.List = function(elm) {
136 function scanl1(f, xs) {
136 function scanl1(f, xs) {
137− return xs.ctor === 'Nil' ? throwError('scanl1') : scanl(f, xs._0, xs._1);
137+ return xs.ctor === '[]' ? throwError('scanl1') : scanl(f, xs._0, xs._1);
140 function filter(pred, xs) {
140 function filter(pred, xs) {
141 var arr = [];
141 var arr = [];
142− while (xs.ctor !== 'Nil') {
142+ while (xs.ctor !== '[]') {
143 if (pred(xs._0)) { arr.push(xs._0); }
143 if (pred(xs._0)) { arr.push(xs._0); }
144 xs = xs._1;
144 xs = xs._1;
@@ -148,7 +148,7 @@ Elm.Native.List = function(elm) {
149 function length(xs) {
149 function length(xs) {
150 var out = 0;
150 var out = 0;
151− while (xs.ctor !== 'Nil') {
151+ while (xs.ctor !== '[]') {
152 out += 1;
152 out += 1;
153 xs = xs._1;
153 xs = xs._1;
@@ -156,7 +156,7 @@ Elm.Native.List = function(elm) {
158 function member(x, xs) {
158 function member(x, xs) {
159− while (xs.ctor !== 'Nil') {
159+ while (xs.ctor !== '[]') {
160 if (Utils.eq(x,xs._0)) return true;
160 if (Utils.eq(x,xs._0)) return true;
161 xs = xs._1;
161 xs = xs._1;
@@ -166,7 +166,7 @@ Elm.Native.List = function(elm) {
166 function reverse(xs) { return fromArray(toArray(xs).reverse()); }
166 function reverse(xs) { return fromArray(toArray(xs).reverse()); }
168 function concat(xss) {
168 function concat(xss) {
169− if (xss.ctor === 'Nil') return xss;
169+ if (xss.ctor === '[]') return xss;
170 var arr = toArray(xss);
170 var arr = toArray(xss);
171 var xs = arr[arr.length-1];
171 var xs = arr[arr.length-1];
172 for (var i = arr.length-1; i--; ) {
172 for (var i = arr.length-1; i--; ) {
@@ -176,7 +176,7 @@ Elm.Native.List = function(elm) {
178 function all(pred, xs) {
178 function all(pred, xs) {
179− while (xs.ctor !== 'Nil') {
179+ while (xs.ctor !== '[]') {
180 if (!pred(xs._0)) return false;
180 if (!pred(xs._0)) return false;
181 xs = xs._1;
181 xs = xs._1;
@@ -184,7 +184,7 @@ Elm.Native.List = function(elm) {
186 function any(pred, xs) {
186 function any(pred, xs) {
187− while (xs.ctor !== 'Nil') {
187+ while (xs.ctor !== '[]') {
188 if (pred(xs._0)) return true;
188 if (pred(xs._0)) return true;
189 xs = xs._1;
189 xs = xs._1;
@@ -193,7 +193,7 @@ Elm.Native.List = function(elm) {
194 function zipWith(f, xs, ys) {
194 function zipWith(f, xs, ys) {
195 var arr = [];
195 var arr = [];
196− while (xs.ctor !== 'Nil' && ys.ctor !== 'Nil') {
196+ while (xs.ctor !== '[]' && ys.ctor !== '[]') {
197 arr.push(A2(f, xs._0, ys._0));
197 arr.push(A2(f, xs._0, ys._0));
198 xs = xs._1;
198 xs = xs._1;
199 ys = ys._1;
199 ys = ys._1;
@@ -203,7 +203,7 @@ Elm.Native.List = function(elm) {
204 function zip(xs, ys) {
204 function zip(xs, ys) {
205 var arr = [];
205 var arr = [];
206− while (xs.ctor !== 'Nil' && ys.ctor !== 'Nil') {
206+ while (xs.ctor !== '[]' && ys.ctor !== '[]') {
207 arr.push(Utils.Tuple2(xs._0, ys._0));
207 arr.push(Utils.Tuple2(xs._0, ys._0));
208 xs = xs._1;
208 xs = xs._1;
209 ys = ys._1;
209 ys = ys._1;
@@ -221,7 +221,7 @@ Elm.Native.List = function(elm) {
222 function take(n, xs) {
222 function take(n, xs) {
223 var arr = [];
223 var arr = [];
224− while (xs.ctor !== 'Nil' && n > 0) {
224+ while (xs.ctor !== '[]' && n > 0) {
225 arr.push(xs._0);
225 arr.push(xs._0);
226 xs = xs._1;
226 xs = xs._1;
@@ -230,7 +230,7 @@ Elm.Native.List = function(elm) {
232 function drop(n, xs) {
232 function drop(n, xs) {
233− while (xs.ctor !== 'Nil' && n > 0) {
233+ while (xs.ctor !== '[]' && n > 0) {
234 xs = xs._1;
234 xs = xs._1;
@@ -239,11 +239,11 @@ Elm.Native.List = function(elm) {
240 function join(sep, xss) {
240 function join(sep, xss) {
241 if (typeof sep === 'string') return toArray(xss).join(sep);
241 if (typeof sep === 'string') return toArray(xss).join(sep);
242− if (xss.ctor === 'Nil') return Nil;
242+ if (xss.ctor === '[]') return Nil;
243 var s = toArray(sep);
243 var s = toArray(sep);
244 var out = toArray(xss._0);
244 var out = toArray(xss._0);
245 xss = xss._1;
245 xss = xss._1;
246− while (xss.ctor !== 'Nil') {
246+ while (xss.ctor !== '[]') {
247 out = out.concat(s, toArray(xss._0));
247 out = out.concat(s, toArray(xss._0));
248 xss = xss._1;
248 xss = xss._1;