on master help sign in
Fix #557
9fb9f91Evan Czaplicki
libraries/Native/Utils.js+13−8
@@ -30,11 +30,15 @@ Elm.Native.Utils.make = function(elm) {
30 function compare(x,y) { return { ctor: ord[cmp(x,y)+1] } }
30 function compare(x,y) { return { ctor: ord[cmp(x,y)+1] } }
31 function cmp(x,y) {
31 function cmp(x,y) {
32 var ord;
32 var ord;
33− if (typeof x !== 'object' || x instanceof String){
33+ if (typeof x !== 'object'){
34 return x === y ? EQ : x < y ? LT : GT;
34 return x === y ? EQ : x < y ? LT : GT;
35 }
35 }
36−
36+ else if (x.isChar){
37+ var a = x.toString();
38+ var b = y.toString();
39+ return a === b ? EQ : a < b ? LT : GT;
40+ }
37− if (x.ctor === "::" || x.ctor === "[]") {
41+ else if (x.ctor === "::" || x.ctor === "[]") {
38 while (true) {
42 while (true) {
39 if (x.ctor === "[]" && y.ctor === "[]") return EQ;
43 if (x.ctor === "[]" && y.ctor === "[]") return EQ;
40 if (x.ctor !== y.ctor) return x.ctor === '[]' ? LT : GT;
44 if (x.ctor !== y.ctor) return x.ctor === '[]' ? LT : GT;
@@ -44,8 +48,7 @@ Elm.Native.Utils.make = function(elm) {
44 y = y._1;
48 y = y._1;
45 }
49 }
46 }
50 }
47−
48− if (x.ctor.slice(0,6) === '_Tuple') {
51+ else if (x.ctor.slice(0,6) === '_Tuple') {
49 var n = x.ctor.slice(6) - 0;
52 var n = x.ctor.slice(6) - 0;
50 var err = 'cannot compare tuples with more than 6 elements.';
53 var err = 'cannot compare tuples with more than 6 elements.';
51 if (n === 0) return EQ;
54 if (n === 0) return EQ;
@@ -58,9 +61,11 @@ Elm.Native.Utils.make = function(elm) {
58 if (n >= 7) throw new Error('Comparison error: ' + err); } } } } } }
61 if (n >= 7) throw new Error('Comparison error: ' + err); } } } } } }
59 return EQ;
62 return EQ;
60 }
63 }
64+ else {
61− throw new Error('Comparison error: comparison is only defined on ints, ' +
65+ throw new Error('Comparison error: comparison is only defined on ints, ' +
62− 'floats, times, chars, strings, lists of comparable values, ' +
66+ 'floats, times, chars, strings, lists of comparable values, ' +
63− 'and tuples of comparable values.')
67+ 'and tuples of comparable values.');
68+ }
64 }
69 }
65
70
66
71