Switch how ADT's are displayed. Should have no visible effect.
This commit is contained in:
parent
c5da28341c
commit
d2bc280d31
2 changed files with 135 additions and 41 deletions
|
@ -216,9 +216,9 @@ var Value = function(){
|
|||
}
|
||||
return "(" + name + ".fromList " + toString(list) + ")";
|
||||
} else {
|
||||
var output = [];
|
||||
for (var i = v.length; --i; ) { output.push(toString(v[i])); }
|
||||
output = v[0] + ' ' + output.join(' ');
|
||||
var output = "";
|
||||
for (var i = v.length; --i; ) { output = ' ' + toString(v[i]) + output; }
|
||||
output = v[0] + output;
|
||||
return (v.length > 1) ? "(" + output + ")" : output;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -444,9 +444,9 @@ var Value = function(){
|
|||
}
|
||||
return "(" + name + ".fromList " + toString(list) + ")";
|
||||
} else {
|
||||
var output = [];
|
||||
for (var i = v.length; --i; ) { output.push(toString(v[i])); }
|
||||
output = v[0] + ' ' + output.join(' ');
|
||||
var output = "";
|
||||
for (var i = v.length; --i; ) { output = ' ' + toString(v[i]) + output; }
|
||||
output = v[0] + output;
|
||||
return (v.length > 1) ? "(" + output + ")" : output;
|
||||
}
|
||||
}
|
||||
|
@ -1000,11 +1000,6 @@ Elm.Maybe = function() {
|
|||
return xs;
|
||||
};
|
||||
}
|
||||
function fromMaybe(b) { return function(m) {
|
||||
if (m[0] === "Just") return m[1];
|
||||
return b;
|
||||
};
|
||||
}
|
||||
function mapCons(f) { return function(y) { return function(xs) {
|
||||
var x = f(y);
|
||||
if (x[0] === "Just") return ["Cons", x[1], xs];
|
||||
|
@ -1021,16 +1016,45 @@ Elm.Maybe = function() {
|
|||
|
||||
return {Just : function(x) { return ["Just",x]; },
|
||||
Nothing : ["Nothing"],
|
||||
catMaybes : Elm.List.foldr(consMaybe)(["Nil"]),
|
||||
justs : Elm.List.foldr(consMaybe)(["Nil"]),
|
||||
isJust : function(m) { return m[0] === "Just"; },
|
||||
isNothing : function(m) { return m[0] === "Nothing"; },
|
||||
fromMaybe : fromMaybe,
|
||||
consMaybe : consMaybe,
|
||||
mapMaybe : function(f) { return Elm.List.foldr(mapCons(f))(["Nil"]); },
|
||||
cons : consMaybe,
|
||||
maybe : maybe
|
||||
};
|
||||
}();
|
||||
|
||||
Elm.Either = function() {
|
||||
function Left(a1) { return ['Left',a1]; }
|
||||
function Right(a1){ return ['Right',a1]; }
|
||||
function either(f){ return function(g){ return function(e){
|
||||
switch(e[0]){
|
||||
case 'Left': return f(e[1]);
|
||||
case 'Right': return g(e[1]);
|
||||
}
|
||||
};};}
|
||||
function isLeft(e) { return e[0] == 'Left'; }
|
||||
function isRight(e) { return e[0] == 'Right'; }
|
||||
|
||||
function get(es) { return Elm.List.map(function(x){return x[1];})(es); }
|
||||
function lefts(es) { return get(Elm.List.filter(isLeft)(es)); }
|
||||
function rights(es) { return get(Elm.List.filter(isRight)(es)); }
|
||||
function partition(es) {
|
||||
var lrs = Elm.List.partition(isLeft)(es);
|
||||
lrs[1] = get(lrs[1]);
|
||||
lrs[2] = get(lrs[2]);
|
||||
return lrs;
|
||||
}
|
||||
return {Left:Left,
|
||||
Right:Right,
|
||||
either:either,
|
||||
isLeft:isLeft,
|
||||
isRight:isRight,
|
||||
lefts:lefts,
|
||||
rights:rights,
|
||||
partition:partition};
|
||||
}();
|
||||
|
||||
Elm.Char = function() {
|
||||
function isBetween(lo,hi) { return function(chr) {
|
||||
var c = chr.charCodeAt(0);
|
||||
|
@ -2943,32 +2967,6 @@ Elm.Mouse = function() {
|
|||
isClickedOn: clickedOn
|
||||
};
|
||||
}();
|
||||
Elm.Touch = function() {
|
||||
var touches = Elm.Signal.constant(["Nil"]);
|
||||
|
||||
function touch(t) {
|
||||
return {_ : [true], x: [t.pageX], y: [t.pageY], id: [t.identifier] };
|
||||
}
|
||||
|
||||
function listen(name) {
|
||||
function update(e) {
|
||||
var ts = Elm.JavaScript.castJSArrayToList(e.touches);
|
||||
var hasListener = Dispatcher.notify(touches.id, Elm.List.map(touch)(ts));
|
||||
if (!hasListener)
|
||||
return this.removeEventListener(name,arguments.callee,false);
|
||||
e.preventDefault();
|
||||
}
|
||||
Value.addListener(document, name, update);
|
||||
}
|
||||
|
||||
listen("touchstart");
|
||||
listen("touchmove");
|
||||
listen("touchend");
|
||||
listen("touchcancel");
|
||||
listen("touchleave");
|
||||
|
||||
return { touches: touches };
|
||||
}();
|
||||
Elm.Random = function() {
|
||||
var inRange = function(min) { return function(max) {
|
||||
return Elm.Signal.constant(Math.floor(Math.random() * (max-min+1)) + min);
|
||||
|
@ -3303,6 +3301,102 @@ Elm.Prelude = function() {
|
|||
|
||||
}());
|
||||
|
||||
Elm.Touch = function() {
|
||||
|
||||
function log(id,msg) {
|
||||
var e = document.getElementById('logger' + id);
|
||||
if (!e) {
|
||||
e = document.createElement('div');
|
||||
e.id = 'logger' + id;
|
||||
document.body.appendChild(e);
|
||||
}
|
||||
e.innerHTML = msg;
|
||||
}
|
||||
|
||||
function Dict() {
|
||||
this.keys = [];
|
||||
this.values = [];
|
||||
|
||||
this.insert = function(key,value) {
|
||||
this.keys.push(key);
|
||||
this.values.push(value);
|
||||
}
|
||||
this.lookup = function(key) {
|
||||
var i = this.keys.indexOf(key)
|
||||
return i >= 0 ? this.values[i] : {x:0,y:0,t:0};
|
||||
}
|
||||
this.remove = function(key) {
|
||||
var i = this.keys.indexOf(key);
|
||||
if (i < 0) return;
|
||||
var t = this.values[i];
|
||||
this.keys.splice(i,1);
|
||||
this.values.splice(i,1);
|
||||
return t;
|
||||
}
|
||||
}
|
||||
|
||||
var root = Elm.Signal.constant([]),
|
||||
tapTime = 500,
|
||||
hasTap = false,
|
||||
tap = {_:[true],x:[0],y:[0]},
|
||||
dict = new Dict();
|
||||
|
||||
function touch(t) {
|
||||
var r = dict.lookup(t.identifier);
|
||||
return {_ : [true], id: [t.identifier],
|
||||
x: [t.pageX], y: [t.pageY],
|
||||
x0: [r.x], y0: [r.y],
|
||||
t0: [r.t] };
|
||||
}
|
||||
|
||||
function start(e) {
|
||||
dict.insert(e.identifier,{x:e.pageX,y:e.pageY,t:Date.now()});
|
||||
}
|
||||
function end(e) {
|
||||
var t = dict.remove(e.identifier);
|
||||
if (Date.now() - t.t < tapTime) {
|
||||
hasTap = true;
|
||||
tap = {_:[true], x:[t.x], y:[t.y]};
|
||||
}
|
||||
}
|
||||
|
||||
function listen(name, f) {
|
||||
function update(e) {
|
||||
for (var i = e.changedTouches.length; i--; ) { f(e.changedTouches[i]); }
|
||||
var ts = new Array(e.touches.length);
|
||||
for (var i = e.touches.length; i--; ) { ts[i] = touch(e.touches[i]); }
|
||||
var hasListener = Dispatcher.notify(root.id, ts);
|
||||
if (!hasListener)
|
||||
return this.removeEventListener(name,arguments.callee,false);
|
||||
e.preventDefault();
|
||||
}
|
||||
Value.addListener(document, name, update);
|
||||
}
|
||||
|
||||
listen("touchstart", start);
|
||||
listen("touchmove", function(_){});
|
||||
listen("touchend", end);
|
||||
listen("touchcancel", end);
|
||||
listen("touchleave", end);
|
||||
|
||||
function dependency(f) {
|
||||
var signal = Elm.Signal.lift(f)(root);
|
||||
root.defaultNumberOfKids += 1;
|
||||
signal.defaultNumberOfKids = 0;
|
||||
return signal;
|
||||
}
|
||||
|
||||
var touches = dependency(function(ts) {
|
||||
return Elm.JavaScript.castJSArrayToList(ts);
|
||||
});
|
||||
var taps = function() {
|
||||
function pred(_) { var b = hasTap; hasTap = false; return b; }
|
||||
var sig = dependency(function(_) { return tap; });
|
||||
return Elm.Signal.keepIf(pred)({_:[true],x:[0],y:[0]})(sig);
|
||||
}();
|
||||
|
||||
return { touches: touches, taps: taps };
|
||||
}();
|
||||
Elm.Dict=function(){
|
||||
var compare = Elm.Prelude.compare;
|
||||
var uncurry = Elm.Prelude.uncurry;
|
||||
|
|
Loading…
Reference in a new issue