@@ -444,9 +444,9 @@ var Value = function(){
444444 }
445445 return "(" + name + ".fromList " + toString(list) + ")";
446446 } else {
447− var output = [];
448− for (var i = v.length; --i; ) { output.push(toString(v[i])); }
449− output = v[0] + ' ' + output.join(' ');
447+ var output = "";
448+ for (var i = v.length; --i; ) { output = ' ' + toString(v[i]) + output; }
449+ output = v[0] + output;
450450 return (v.length > 1) ? "(" + output + ")" : output;
451451 }
452452 }
@@ -1000,11 +1000,6 @@ Elm.Maybe = function() {
10001000 return xs;
10011001 };
10021002 }
1003− function fromMaybe(b) { return function(m) {
1004− if (m[0] === "Just") return m[1];
1005− return b;
1006− };
1007− }
10081003 function mapCons(f) { return function(y) { return function(xs) {
10091004 var x = f(y);
10101005 if (x[0] === "Just") return ["Cons", x[1], xs];
@@ -1021,16 +1016,45 @@ Elm.Maybe = function() {
10211016
10221017 return {Just : function(x) { return ["Just",x]; },
10231018 Nothing : ["Nothing"],
1024− catMaybes : Elm.List.foldr(consMaybe)(["Nil"]),
1019+ justs : Elm.List.foldr(consMaybe)(["Nil"]),
10251020 isJust : function(m) { return m[0] === "Just"; },
10261021 isNothing : function(m) { return m[0] === "Nothing"; },
1027− fromMaybe : fromMaybe,
1028− consMaybe : consMaybe,
1029− mapMaybe : function(f) { return Elm.List.foldr(mapCons(f))(["Nil"]); },
1022+ cons : consMaybe,
10301023 maybe : maybe
10311024 };
10321025}();
10331026
1027+Elm.Either = function() {
1028+ function Left(a1) { return ['Left',a1]; }
1029+ function Right(a1){ return ['Right',a1]; }
1030+ function either(f){ return function(g){ return function(e){
1031+ switch(e[0]){
1032+ case 'Left': return f(e[1]);
1033+ case 'Right': return g(e[1]);
1034+ }
1035+ };};}
1036+ function isLeft(e) { return e[0] == 'Left'; }
1037+ function isRight(e) { return e[0] == 'Right'; }
1038+
1039+ function get(es) { return Elm.List.map(function(x){return x[1];})(es); }
1040+ function lefts(es) { return get(Elm.List.filter(isLeft)(es)); }
1041+ function rights(es) { return get(Elm.List.filter(isRight)(es)); }
1042+ function partition(es) {
1043+ var lrs = Elm.List.partition(isLeft)(es);
1044+ lrs[1] = get(lrs[1]);
1045+ lrs[2] = get(lrs[2]);
1046+ return lrs;
1047+ }
1048+ return {Left:Left,
1049+ Right:Right,
1050+ either:either,
1051+ isLeft:isLeft,
1052+ isRight:isRight,
1053+ lefts:lefts,
1054+ rights:rights,
1055+ partition:partition};
1056+}();
1057+
10341058Elm.Char = function() {
10351059 function isBetween(lo,hi) { return function(chr) {
10361060 var c = chr.charCodeAt(0);
@@ -2943,32 +2967,6 @@ Elm.Mouse = function() {
29432967 isClickedOn: clickedOn
29442968 };
29452969 }();
2946−Elm.Touch = function() {
2947− var touches = Elm.Signal.constant(["Nil"]);
2948−
2949− function touch(t) {
2950− return {_ : [true], x: [t.pageX], y: [t.pageY], id: [t.identifier] };
2951− }
2952−
2953− function listen(name) {
2954− function update(e) {
2955− var ts = Elm.JavaScript.castJSArrayToList(e.touches);
2956− var hasListener = Dispatcher.notify(touches.id, Elm.List.map(touch)(ts));
2957− if (!hasListener)
2958− return this.removeEventListener(name,arguments.callee,false);
2959− e.preventDefault();
2960− }
2961− Value.addListener(document, name, update);
2962− }
2963−
2964− listen("touchstart");
2965− listen("touchmove");
2966− listen("touchend");
2967− listen("touchcancel");
2968− listen("touchleave");
2969−
2970− return { touches: touches };
2971−}();
29722970Elm.Random = function() {
29732971 var inRange = function(min) { return function(max) {
29742972 return Elm.Signal.constant(Math.floor(Math.random() * (max-min+1)) + min);
@@ -3303,6 +3301,102 @@ Elm.Prelude = function() {
33033301
33043302}());
33053303
3304+Elm.Touch = function() {
3305+
3306+ function log(id,msg) {
3307+ var e = document.getElementById('logger' + id);
3308+ if (!e) {
3309+ e = document.createElement('div');
3310+ e.id = 'logger' + id;
3311+ document.body.appendChild(e);
3312+ }
3313+ e.innerHTML = msg;
3314+ }
3315+
3316+ function Dict() {
3317+ this.keys = [];
3318+ this.values = [];
3319+
3320+ this.insert = function(key,value) {
3321+ this.keys.push(key);
3322+ this.values.push(value);
3323+ }
3324+ this.lookup = function(key) {
3325+ var i = this.keys.indexOf(key)
3326+ return i >= 0 ? this.values[i] : {x:0,y:0,t:0};
3327+ }
3328+ this.remove = function(key) {
3329+ var i = this.keys.indexOf(key);
3330+ if (i < 0) return;
3331+ var t = this.values[i];
3332+ this.keys.splice(i,1);
3333+ this.values.splice(i,1);
3334+ return t;
3335+ }
3336+ }
3337+
3338+ var root = Elm.Signal.constant([]),
3339+ tapTime = 500,
3340+ hasTap = false,
3341+ tap = {_:[true],x:[0],y:[0]},
3342+ dict = new Dict();
3343+
3344+ function touch(t) {
3345+ var r = dict.lookup(t.identifier);
3346+ return {_ : [true], id: [t.identifier],
3347+ x: [t.pageX], y: [t.pageY],
3348+ x0: [r.x], y0: [r.y],
3349+ t0: [r.t] };
3350+ }
3351+
3352+ function start(e) {
3353+ dict.insert(e.identifier,{x:e.pageX,y:e.pageY,t:Date.now()});
3354+ }
3355+ function end(e) {
3356+ var t = dict.remove(e.identifier);
3357+ if (Date.now() - t.t < tapTime) {
3358+ hasTap = true;
3359+ tap = {_:[true], x:[t.x], y:[t.y]};
3360+ }
3361+ }
3362+
3363+ function listen(name, f) {
3364+ function update(e) {
3365+ for (var i = e.changedTouches.length; i--; ) { f(e.changedTouches[i]); }
3366+ var ts = new Array(e.touches.length);
3367+ for (var i = e.touches.length; i--; ) { ts[i] = touch(e.touches[i]); }
3368+ var hasListener = Dispatcher.notify(root.id, ts);
3369+ if (!hasListener)
3370+ return this.removeEventListener(name,arguments.callee,false);
3371+ e.preventDefault();
3372+ }
3373+ Value.addListener(document, name, update);
3374+ }
3375+
3376+ listen("touchstart", start);
3377+ listen("touchmove", function(_){});
3378+ listen("touchend", end);
3379+ listen("touchcancel", end);
3380+ listen("touchleave", end);
3381+
3382+ function dependency(f) {
3383+ var signal = Elm.Signal.lift(f)(root);
3384+ root.defaultNumberOfKids += 1;
3385+ signal.defaultNumberOfKids = 0;
3386+ return signal;
3387+ }
3388+
3389+ var touches = dependency(function(ts) {
3390+ return Elm.JavaScript.castJSArrayToList(ts);
3391+ });
3392+ var taps = function() {
3393+ function pred(_) { var b = hasTap; hasTap = false; return b; }
3394+ var sig = dependency(function(_) { return tap; });
3395+ return Elm.Signal.keepIf(pred)({_:[true],x:[0],y:[0]})(sig);
3396+ }();
3397+
3398+ return { touches: touches, taps: taps };
3399+}();
33063400Elm.Dict=function(){
33073401 var compare = Elm.Prelude.compare;
33083402 var uncurry = Elm.Prelude.uncurry;