Skip to content

Instantly share code, notes, and snippets.

@commandodev
Created October 2, 2012 15:05
Show Gist options
  • Save commandodev/3819898 to your computer and use it in GitHub Desktop.
Save commandodev/3819898 to your computer and use it in GitHub Desktop.
Fay Arrows problem
/** @constructor
*/
var Tests = function() {
var True = true;
var False = false;
/*******************************************************************************
* Thunks.
*/
// Force a thunk (if it is a thunk) until WHNF.
function _(thunkish, nocache) {
while (thunkish instanceof $) {
thunkish = thunkish.force(nocache);
}
return thunkish;
}
// Apply a function to arguments (see method2 in Fay.hs).
function __() {
var f = arguments[0];
for (var i = 1, len = arguments.length; i < len; i++) {
f = (f instanceof $ ? _(f) : f)(arguments[i]);
}
return f;
}
// Thunk object.
function $(value) {
this.forced = false;
this.value = value;
}
// Force the thunk.
$.prototype.force = function(nocache) {
return nocache ? this.value() : (this.forced ? this.value : (this.value = this.value(), this.forced = true, this.value));
};
/*******************************************************************************
* Monad.
*/
function Fay$$Monad(value) {
this.value = value;
}
// >>
// encode_fay_to_js(">>=") → $62$$62$
// This is used directly from Fay, but can be rebound or shadowed.
function $62$$62$(a) {
return function(b) {
return new $(function() {
_(a, true);
return b;
});
};
}
// >>=
// encode_fay_to_js(">>=") → $62$$62$$61$
// This is used directly from Fay, but can be rebound or shadowed.
function $62$$62$$61$(m) {
return function(f) {
return new $(function() {
var monad = _(m, true);
return f(monad.value);
});
};
}
// This is used directly from Fay, but can be rebound or shadowed.
function $_return(a) {
return new Fay$$Monad(a);
}
var Fay$$unit = null;
/*******************************************************************************
* Serialization.
* Fay <-> JS. Should be bijective.
*/
// Serialize a Fay object to JS.
function Fay$$fayToJs(type, fayObj) {
var base = type[0];
var args = type[1];
var jsObj;
switch (base) {
case "action":
{
// A nullary monadic action. Should become a nullary JS function.
// Fay () -> function(){ return ... }
jsObj = function() {
return Fay$$fayToJs(args[0], _(fayObj, true).value);
};
break;
}
case "function":
{
// A proper function.
jsObj = function() {
var fayFunc = fayObj;
var return_type = args[args.length - 1];
var len = args.length;
// If some arguments.
if (len > 1) {
// Apply to all the arguments.
fayFunc = _(fayFunc, true);
// TODO: Perhaps we should throw an error when JS
// passes more arguments than Haskell accepts.
for (var i = 0, len = len; i < len - 1 && fayFunc instanceof Function; i++) {
// Unserialize the JS values to Fay for the Fay callback.
fayFunc = _(fayFunc(Fay$$jsToFay(args[i], arguments[i])), true);
}
// Finally, serialize the Fay return value back to JS.
var return_base = return_type[0];
var return_args = return_type[1];
// If it's a monadic return value, get the value instead.
if (return_base == "action") {
return Fay$$fayToJs(return_args[0], fayFunc.value);
}
// Otherwise just serialize the value direct.
else {
return Fay$$fayToJs(return_type, fayFunc);
}
} else {
throw new Error("Nullary function?");
}
};
break;
}
case "string":
{
// Serialize Fay string to JavaScript string.
var str = "";
fayObj = _(fayObj);
while (fayObj instanceof Fay$$Cons) {
str += fayObj.car;
fayObj = _(fayObj.cdr);
}
jsObj = str;
break;
}
case "list":
{
// Serialize Fay list to JavaScript array.
var arr = [];
fayObj = _(fayObj);
while (fayObj instanceof Fay$$Cons) {
arr.push(Fay$$fayToJs(args[0], fayObj.car));
fayObj = _(fayObj.cdr);
}
jsObj = arr;
break;
}
case "double":
{
// Serialize double, just force the argument. Doubles are unboxed.
jsObj = _(fayObj);
break;
}
case "int":
{
// Serialize int, just force the argument. Ints are unboxed.
jsObj = _(fayObj);
break;
}
case "bool":
{
// Bools are unboxed.
jsObj = _(fayObj);
break;
}
case "unknown":
case "user":
{
if (fayObj instanceof $) fayObj = _(fayObj);
jsObj = Fay$$fayToJsUserDefined(type, fayObj);
break;
}
default:
throw new Error("Unhandled Fay->JS translation type: " + base);
}
return jsObj;
}
// Unserialize an object from JS to Fay.
function Fay$$jsToFay(type, jsObj) {
var base = type[0];
var args = type[1];
var fayObj;
switch (base) {
case "action":
{
// Unserialize a "monadic" JavaScript return value into a monadic value.
fayObj = new Fay$$Monad(Fay$$jsToFay(args[0], jsObj));
break;
}
case "string":
{
// Unserialize a JS string into Fay list (String).
fayObj = Fay$$list(jsObj);
break;
}
case "list":
{
// Unserialize a JS array into a Fay list ([a]).
var serializedList = [];
for (var i = 0, len = jsObj.length; i < len; i++) {
// Unserialize each JS value into a Fay value, too.
serializedList.push(Fay$$jsToFay(args[0], jsObj[i]));
}
// Pop it all in a Fay list.
fayObj = Fay$$list(serializedList);
break;
}
case "double":
{
// Doubles are unboxed, so there's nothing to do.
fayObj = jsObj;
break;
}
case "int":
{
// Int are unboxed, so there's no forcing to do.
// But we can do validation that the int has no decimal places.
// E.g. Math.round(x)!=x? throw "NOT AN INTEGER, GET OUT!"
fayObj = Math.round(jsObj);
if (fayObj !== jsObj) throw "Argument " + jsObj + " is not an integer!"
break;
}
case "bool":
{
// Bools are unboxed.
fayObj = jsObj;
break;
}
case "unknown":
case "user":
{
if (jsObj && jsObj['instance']) {
fayObj = Fay$$jsToFayUserDefined(type, jsObj);
} else fayObj = jsObj;
break;
}
default:
throw new Error("Unhandled JS->Fay translation type: " + base);
}
return fayObj;
}
/*******************************************************************************
* Lists.
*/
// Cons object.
function Fay$$Cons(car, cdr) {
this.car = car;
this.cdr = cdr;
}
// Make a list.
function Fay$$list(xs) {
var out = null;
for (var i = xs.length - 1; i >= 0; i--)
out = new Fay$$Cons(xs[i], out);
return out;
}
// Built-in list cons.
function Fay$$cons(x) {
return function(y) {
return new Fay$$Cons(x, y);
};
}
// List index.
function Fay$$index(index) {
return function(list) {
for (var i = 0; i < index; i++) {
list = _(list).cdr;
}
return list.car;
};
}
/*******************************************************************************
* Numbers.
*/
// Built-in *.
function Fay$$mult(x) {
return function(y) {
return _(x) * _(y);
};
}
var $42$ = Fay$$mult;
// Built-in +.
function Fay$$add(x) {
return function(y) {
return _(x) + _(y);
};
}
var $43$ = Fay$$add;
// Built-in -.
function Fay$$sub(x) {
return function(y) {
return _(x) - _(y);
};
}
var $45$ = Fay$$sub;
// Built-in /.
function Fay$$div(x) {
return function(y) {
return _(x) / _(y);
};
}
var $47$ = Fay$$div;
/*******************************************************************************
* Booleans.
*/
// Are two values equal?
function Fay$$equal(lit1, lit2) {
// Simple case
lit1 = _(lit1);
lit2 = _(lit2);
if (lit1 === lit2) {
return true;
}
// General case
if (lit1 instanceof Array) {
if (lit1.length != lit2.length) return false;
for (var len = lit1.length, i = 0; i < len; i++) {
if (!Fay$$equal(lit1[i], lit2[i])) return false;
}
return true;
} else if (lit1 instanceof Fay$$Cons && lit2 instanceof Fay$$Cons) {
do {
if (!Fay$$equal(lit1.car, lit2.car)) return false;
lit1 = _(lit1.cdr), lit2 = _(lit2.cdr);
if (lit1 === null || lit2 === null) return lit1 === lit2;
} while (true);
} else if (typeof lit1 == 'object' && typeof lit2 == 'object' && lit1 && lit2 && lit1.constructor === lit2.constructor) {
for (var x in lit1) {
if (!(lit1.hasOwnProperty(x) && lit2.hasOwnProperty(x) && Fay$$equal(lit1[x], lit2[x]))) return false;
}
return true;
} else {
return false;
}
}
// Built-in ==.
function Fay$$eq(x) {
return function(y) {
return Fay$$equal(x, y);
};
}
var $61$$61$ = Fay$$eq;
// Built-in /=.
function Fay$$neq(x) {
return function(y) {
return !(Fay$$equal(x, y));
};
}
var $47$$61$ = Fay$$neq;
// Built-in >.
function Fay$$gt(x) {
return function(y) {
return _(x) > _(y);
};
}
var $62$ = Fay$$gt;
// Built-in <.
function Fay$$lt(x) {
return function(y) {
return _(x) < _(y);
};
}
var $60$ = Fay$$lt;
// Built-in >=.
function Fay$$gte(x) {
return function(y) {
return _(x) >= _(y);
};
}
var $62$$61$ = Fay$$gte;
// Built-in <=.
function Fay$$lte(x) {
return function(y) {
return _(x) <= _(y);
};
}
var $60$$61$ = Fay$$lte;
// Built-in &&.
function Fay$$and(x) {
return function(y) {
return _(x) && _(y);
};
}
var $38$$38$ = Fay$$and;
// Built-in ||.
function Fay$$or(x) {
return function(y) {
return _(x) || _(y);
};
}
var $124$$124$ = Fay$$or;
/*******************************************************************************
* Mutable references.
*/
// Make a new mutable reference.
function Fay$$Ref(x) {
this.value = x;
}
// Write to the ref.
function Fay$$writeRef(ref, x) {
ref.value = x;
}
// Get the value from the ref.
function Fay$$readRef(ref, x) {
return ref.value;
}
/*******************************************************************************
* Dates.
*/
function Fay$$date(str) {
return window.Date.parse(str);
}
/*******************************************************************************
* Application code.
*/
var $36$_Stream = function(slot1) {
this.slot1 = slot1;
};
var Stream = function(slot1) {
return new $(function() {
return new $36$_Stream(slot1);
});
};
var $36$_Coroutine = function(runC) {
this.runC = runC;
};
var Coroutine = function(runC) {
return new $(function() {
return new $36$_Coroutine(runC);
});
};
var runC = function(x) {
return new $(function() {
return _(x).runC;
});
};
var fmap = new $(function() {
return fmapC;
});
var $60$$36$$62$ = new $(function() {
return fmapC;
});
var fmapC = function($36$_a) {
return function($36$_b) {
return new $(function() {
var co = $36$_b;
var f = $36$_a;
return __($36$, Coroutine, function($36$_a) {
var i = $36$_a;
return (function() {
var o_coNext = new $(function() {
return __(runC, co, i);
});
var o = new $(function() {
return Fay$$index(0)(_(o_coNext));
});
var coNext = new $(function() {
return Fay$$index(1)(_(o_coNext));
});
return Fay$$list([__(f, o), __(fmapC, f, coNext)]);
})();
});
});
};
};
var pure = new $(function() {
return pureC;
});
var $60$$42$$62$ = new $(function() {
return appC;
});
var pureC = function($36$_a) {
return new $(function() {
var x = $36$_a;
return __($36$, Coroutine, __($_const, Fay$$list([x, __(pure, x)])));
});
};
var appC = function($36$_a) {
return function($36$_b) {
return new $(function() {
var cox = $36$_b;
var cof = $36$_a;
return __($36$, Coroutine, function($36$_a) {
var i = $36$_a;
return (function() {
var f_cof$39$ = new $(function() {
return __(runC, cof, i);
});
var f = new $(function() {
return Fay$$index(0)(_(f_cof$39$));
});
var cof$39$ = new $(function() {
return Fay$$index(1)(_(f_cof$39$));
});
var x_cox$39$ = new $(function() {
return __(runC, cox, i);
});
var x = new $(function() {
return Fay$$index(0)(_(x_cox$39$));
});
var cox$39$ = new $(function() {
return Fay$$index(1)(_(x_cox$39$));
});
return Fay$$list([__(f, x), __(appC, cof$39$, cox$39$)]);
})();
});
});
};
};
var $60$$42$$42$$62$ = new $(function() {
return __(liftC2, __(flip, $36$));
});
var liftC = function($36$_a) {
return function($36$_b) {
return new $(function() {
var a = $36$_b;
var f = $36$_a;
return __($60$$42$$62$, __(pure, f), a);
});
};
};
var liftC2 = function($36$_a) {
return function($36$_b) {
return function($36$_c) {
return new $(function() {
var b = $36$_c;
var a = $36$_b;
var f = $36$_a;
return __($60$$42$$62$, __($60$$36$$62$, f, a), b);
});
};
};
};
var liftC3 = function($36$_a) {
return function($36$_b) {
return function($36$_c) {
return function($36$_x) {
return new $(function() {
var c = $36$_x;
var b = $36$_c;
var a = $36$_b;
var f = $36$_a;
return __($60$$42$$62$, __($60$$42$$62$, __($60$$36$$62$, f, a), b), c);
});
};
};
};
};
var idC = new $(function() {
return __($36$, Coroutine, function($36$_a) {
var i = $36$_a;
return Fay$$list([i, idC]);
});
});
var $60$$60$$60$ = function($36$_a) {
return function($36$_b) {
return new $(function() {
var cog = $36$_b;
var cof = $36$_a;
return __($36$, Coroutine, function($36$_a) {
var i = $36$_a;
return (function() {
var x_cog$39$ = new $(function() {
return __(runC, cog, i);
});
var x = new $(function() {
return Fay$$index(0)(_(x_cog$39$));
});
var cog$39$ = new $(function() {
return Fay$$index(1)(_(x_cog$39$));
});
var y_cof$39$ = new $(function() {
return __(runC, cof, x);
});
var y = new $(function() {
return Fay$$index(0)(_(y_cof$39$));
});
var cof$39$ = new $(function() {
return Fay$$index(1)(_(y_cof$39$));
});
return Fay$$list([y, __($60$$60$$60$, cof$39$, cog$39$)]);
})();
});
});
};
};
var $62$$62$$62$ = new $(function() {
return __(flip, $60$$60$$60$);
});
var arr = new $(function() {
return arrC;
});
var first = new $(function() {
return firstC;
});
var second = new $(function() {
return secondC;
});
var $42$$42$$42$ = function($36$_a) {
return function($36$_b) {
return new $(function() {
var g = $36$_b;
var f = $36$_a;
return __($62$$62$$62$, __(first, f), __(second, g));
});
};
};
var $38$$38$$38$ = function($36$_a) {
return function($36$_b) {
return new $(function() {
var g = $36$_b;
var f = $36$_a;
return __($62$$62$$62$, __(arr, function($36$_a) {
var a = $36$_a;
return Fay$$list([a, a]);
}), __($42$$42$$42$, f, g));
});
};
};
var arrC = function($36$_a) {
return new $(function() {
var f = $36$_a;
return __($36$, Coroutine, function($36$_a) {
var i = $36$_a;
return Fay$$list([__(f, i), __(arr, f)]);
});
});
};
var firstC = function($36$_a) {
return new $(function() {
var co = $36$_a;
return __($36$, Coroutine, function($36$_a) {
var a = Fay$$index(0)(_($36$_a));
var b = Fay$$index(1)(_($36$_a));
return (function() {
var c_co$39$ = new $(function() {
return __(runC, co, a);
});
var c = new $(function() {
return Fay$$index(0)(_(c_co$39$));
});
var co$39$ = new $(function() {
return Fay$$index(1)(_(c_co$39$));
});
return Fay$$list([Fay$$list([c, b]), __(firstC, co$39$)]);
})();
throw ["unhandled case", $36$_a];
});
});
};
var secondC = function($36$_a) {
return new $(function() {
var f = $36$_a;
return (function() {
var swap = function($36$_a) {
return new $(function() {
var tup = $36$_a;
return (function() {
var x_y = new $(function() {
return tup;
});
var x = new $(function() {
return Fay$$index(0)(_(x_y));
});
var y = new $(function() {
return Fay$$index(1)(_(x_y));
});
return Fay$$list([y, x]);
})();
});
};
return __($62$$62$$62$, __(arr, swap), __($62$$62$$62$, __(first, f), __(arr, swap)));
})();
});
};
var $94$$62$$62$ = function($36$_a) {
return function($36$_b) {
return new $(function() {
var a = $36$_b;
var f = $36$_a;
return __($62$$62$$62$, __(arr, f), a);
});
};
};
var $62$$62$$94$ = function($36$_a) {
return function($36$_b) {
return new $(function() {
var f = $36$_b;
var a = $36$_a;
return __($62$$62$$62$, a, __(arr, f));
});
};
};
var $60$$60$$94$ = function($36$_a) {
return function($36$_b) {
return new $(function() {
var f = $36$_b;
var a = $36$_a;
return __($60$$60$$60$, a, __(arr, f));
});
};
};
var $94$$60$$60$ = function($36$_a) {
return function($36$_b) {
return new $(function() {
var a = $36$_b;
var f = $36$_a;
return __($60$$60$$60$, __(arr, f), a);
});
};
};
var loop = new $(function() {
return loopC;
});
var loopC = function($36$_a) {
return new $(function() {
var co = $36$_a;
return __($36$, Coroutine, function($36$_a) {
var b = $36$_a;
return (function() {
var c_d_co$39$ = new $(function() {
return __(runC, co, Fay$$list([b, d]));
});
var c = new $(function() {
return Fay$$index(0)(_(Fay$$index(0)(_(c_d_co$39$))));
});
var d = new $(function() {
return Fay$$index(1)(_(Fay$$index(0)(_(c_d_co$39$))));
});
var co$39$ = new $(function() {
return Fay$$index(1)(_(c_d_co$39$));
});
return Fay$$list([c, __(loopC, co$39$)]);
})();
});
});
};
var evalList = function($36$_a) {
return function($36$_b) {
return new $(function() {
if (_($36$_b) === null) {
return null;
}
var $36$_$36$_b = _($36$_b);
if ($36$_$36$_b instanceof Fay$$Cons) {
var x = $36$_$36$_b.car;
var xs = $36$_$36$_b.cdr;
var co = $36$_a;
return (function() {
var o_co$39$ = new $(function() {
return __(runC, co, x);
});
var o = new $(function() {
return Fay$$index(0)(_(o_co$39$));
});
var co$39$ = new $(function() {
return Fay$$index(1)(_(o_co$39$));
});
return __(Fay$$cons, o, __(evalList, co$39$, xs));
})();
}
throw ["unhandled case in Ident \"evalList\"", [$36$_a, $36$_b]];
});
};
};
var takeN = function($36$_a) {
return function($36$_b) {
return function($36$_c) {
return new $(function() {
if (_($36$_a) === 0) {
return null;
}
if (_($36$_b) === null) {
return null;
}
var co = $36$_c;
var $36$_$36$_b = _($36$_b);
if ($36$_$36$_b instanceof Fay$$Cons) {
var i = $36$_$36$_b.car;
var is = $36$_$36$_b.cdr;
var n = $36$_a;
return (function() {
var o_co$39$ = new $(function() {
return __(runC, co, i);
});
var o = new $(function() {
return Fay$$index(0)(_(o_co$39$));
});
var co$39$ = new $(function() {
return Fay$$index(1)(_(o_co$39$));
});
return __(Fay$$cons, o, __(takeN, _(n) - 1, is, co$39$));
})();
}
throw ["unhandled case in Ident \"takeN\"", [$36$_a, $36$_b, $36$_c]];
});
};
};
};
var take = function($36$_a) {
return function($36$_b) {
return new $(function() {
if (_($36$_b) === null) {
return null;
}
var $36$_$36$_b = _($36$_b);
if ($36$_$36$_b instanceof Fay$$Cons) {
var x = $36$_$36$_b.car;
var xs = $36$_$36$_b.cdr;
var n = $36$_a;
return _(_(n) > 0) ? __(Fay$$cons, x, __(take, _(n) - 1, xs)) : _(__(Fay$$lte, n, 0)) ? null : (function() {
throw ("Non-exhaustive guards");
})();
}
throw ["unhandled case in Ident \"take\"", [$36$_a, $36$_b]];
});
};
};
var intsFrom = function($36$_a) {
return new $(function() {
var n = $36$_a;
return __($36$, Coroutine, function($36$_a) {
return Fay$$list([n, __(intsFrom, _(n) + 1)]);
});
});
};
var scan = function($36$_a) {
return function($36$_b) {
return new $(function() {
var i = $36$_b;
var f = $36$_a;
return (function() {
var step = function($36$_a) {
return function($36$_b) {
return new $(function() {
var b = $36$_b;
var a = $36$_a;
return (function() {
var a$39$ = new $(function() {
return __(f, a, b);
});
return Fay$$list([a$39$, __(scan, f, a$39$)]);
})();
});
};
};
return __($36$, Coroutine, __(step, i));
})();
});
};
};
var accumSum = new $(function() {
return __(scan, $43$, 0);
});
var mapE = new $(function() {
return __($46$, arr, map);
});
var filterE = new $(function() {
return __($46$, arr, filter);
});
var constE = new $(function() {
return __($46$, mapE, $_const);
});
var zipWithC = new $(function() {
return __($46$, arr, uncurry);
});
var zipE = new $(function() {
return __(zipWithC, $43$$43$);
});
var scanE = function($36$_a) {
return function($36$_b) {
return new $(function() {
var i = $36$_b;
var f = $36$_a;
return (function() {
var step = function($36$_a) {
return function($36$_b) {
return new $(function() {
var e = $36$_b;
var a = $36$_a;
return (function() {
var a$39$ = new $(function() {
return __(foldl, f, a, e);
});
return Fay$$list([a$39$, __(scanE, f, a$39$)]);
})();
});
};
};
return __($36$, Coroutine, __(step, i));
})();
});
};
};
var mergeE = new $(function() {
return __(liftC2, $43$$43$);
});
var withPrevious = function($36$_a) {
return new $(function() {
var prev = $36$_a;
return (function() {
var step = function($36$_a) {
return new $(function() {
var old = $36$_a;
return __($36$, Coroutine, function($36$_a) {
var i = $36$_a;
return Fay$$list([Fay$$list([i, old]), __(step, i)]);
});
});
};
return __($36$, Coroutine, function($36$_a) {
var i = $36$_a;
return Fay$$list([Fay$$list([i, prev]), __(step, i)]);
});
})();
});
};
var delay = function($36$_a) {
return new $(function() {
var a = $36$_a;
return __($62$$62$$62$, __(withPrevious, a), __(arr, snd));
});
};
var integrate = new $(function() {
return __(scan, $43$);
});
var derivate = new $(function() {
return __($62$$62$$62$, __(withPrevious, 0), __(zipWithC, $45$));
});
var watch = function($36$_a) {
return new $(function() {
var f = $36$_a;
return __($36$, Coroutine, function($36$_a) {
var i = $36$_a;
return _(__(f, i)) ? Fay$$list([Fay$$list([i]), __(watch, f)]) : Fay$$list([null, __(watch, f)]);
});
});
};
var curry = function($36$_a) {
return function($36$_b) {
return function($36$_c) {
return new $(function() {
var y = $36$_c;
var x = $36$_b;
var f = $36$_a;
return __(f, Fay$$list([x, y]));
});
};
};
};
var uncurry = function($36$_a) {
return function($36$_b) {
return new $(function() {
var p = $36$_b;
var f = $36$_a;
return __(f, __(fst, p), __(snd, p));
});
};
};
var ready = function($36$_a) {
return new $(function() {
return Fay$$jsToFay(["action", [
["unknown"]
]], window['jQuery'](Fay$$fayToJs(["action", [
["unknown"]
]], $36$_a)));
});
};
var $_void = function($36$_a) {
return new $(function() {
var m = $36$_a;
return __($62$$62$, m, __($_return, Fay$$unit));
});
};
var main = new $(function() {
var fac = new $(function() {
return __(loopC, __($38$$38$$38$, __($62$$62$$62$, __(arr, __(uncurry, $42$)), idC), __(delay, 1)));
});
return __($36$, ready, __($62$$62$, __(logS, Fay$$list("test")), (function() {
var fst4 = new $(function() {
return __(takeN, 4, Fay$$list([Up, Up, Same, Down]), game);
});
return (function() {
var repeat = function($36$_a) {
return new $(function() {
var x = $36$_a;
return __(Fay$$cons, x, __(repeat, x));
});
};
return (function() {
var strPos = new $(function() {
return __($62$$62$$62$, ballPos, __(arr, __($46$, log, show)));
});
return (function() {
var tups = new $(function() {
return __(takeN, 5, enumFrom(1), __($62$$62$$62$, __(withPrevious, 0), __(arr, __(uncurry, showTup))));
});
return (function() {
var facs = new $(function() {
return __(takeN, 5, enumFromTo(1)(5), __($62$$62$$62$, fac, __(arr, logD)));
});
return __($62$$62$, __(forM_, tups, $_void), __($62$$62$, __(forM_, facs, $_void), __(logS, Fay$$list("Done"))));
})();
})();
})();
})();
})()));
});
var showTup = function($36$_a) {
return function($36$_b) {
return new $(function() {
return Fay$$jsToFay(["action", [
["unknown"]
]], console.log(Fay$$fayToJs(["double"], $36$_a), Fay$$fayToJs(["double"], $36$_b)));
});
};
};
var logD = function($36$_a) {
return new $(function() {
return Fay$$jsToFay(["action", [
["unknown"]
]], console.log(Fay$$fayToJs(["double"], $36$_a)));
});
};
var $36$_Rect = function(slot1) {
this.slot1 = slot1;
};
var Rect = function(slot1) {
return new $(function() {
return new $36$_Rect(slot1);
});
};
var $36$_HBounce = function() {};
var HBounce = new $(function() {
return new $36$_HBounce();
});
var $36$_VBounce = function() {};
var VBounce = new $(function() {
return new $36$_VBounce();
});
var $36$_NoBounce = function() {};
var NoBounce = new $(function() {
return new $36$_NoBounce();
});
var $36$_Up = function() {};
var Up = new $(function() {
return new $36$_Up();
});
var $36$_Down = function() {};
var Down = new $(function() {
return new $36$_Down();
});
var $36$_Same = function() {};
var Same = new $(function() {
return new $36$_Same();
});
var batSpeed = 5;
var batSize = new $(function() {
return Fay$$list([10, 40]);
});
var startPos = 200;
var ballInitPos = new $(function() {
return Fay$$list([400, 200]);
});
var ballSize = new $(function() {
return Fay$$list([8, 8]);
});
var ballInitVel = new $(function() {
return Fay$$list([0 - 6, 0 - 6]);
});
var topWall = 10;
var bottomWall = 590;
var vecMul = function($36$_a) {
return function($36$_b) {
return new $(function() {
var x = Fay$$index(0)(_($36$_b));
var y = Fay$$index(1)(_($36$_b));
var c = $36$_a;
return Fay$$list([_(x) * _(c), _(y) * _(c)]);
throw ["unhandled case in Ident \"vecMul\"", [$36$_a, $36$_b]];
});
};
};
var vecAdd = function($36$_a) {
return function($36$_b) {
return new $(function() {
var c = Fay$$index(0)(_($36$_b));
var d = Fay$$index(1)(_($36$_b));
var a = Fay$$index(0)(_($36$_a));
var b = Fay$$index(1)(_($36$_a));
return Fay$$list([_(a) + _(c), _(b) + _(d)]);
throw ["unhandled case in Ident \"vecAdd\"", [$36$_a, $36$_b]];
});
};
};
var bounce = function($36$_a) {
return function($36$_b) {
return new $(function() {
var b = $36$_b;
var dx = Fay$$index(0)(_($36$_a));
var dy = Fay$$index(1)(_($36$_a));
return (function($36$_b) {
if (_($36$_b) instanceof $36$_HBounce) {
return Fay$$list([0 - _(dx), dy]);
}
if (_($36$_b) instanceof $36$_VBounce) {
return Fay$$list([dx, 0 - _(dy)]);
}
if (_($36$_b) instanceof $36$_NoBounce) {
return Fay$$list([dx, dy]);
}
return (function() {
throw (["unhandled case", $36$_b]);
})();
})(b);
throw ["unhandled case in Ident \"bounce\"", [$36$_a, $36$_b]];
});
};
};
var mkRect = function($36$_a) {
return function($36$_b) {
return new $(function() {
var w = Fay$$index(0)(_($36$_b));
var h = Fay$$index(1)(_($36$_b));
var x = Fay$$index(0)(_($36$_a));
var y = Fay$$index(1)(_($36$_a));
return (function() {
var w$39$ = new $(function() {
return __(div, w, 2);
});
var h$39$ = new $(function() {
return __(div, h, 2);
});
return __(Rect, Fay$$list([Fay$$list([_(x) - _(w$39$), _(y) - _(h$39$)]), Fay$$list([w, h])]));
})();
throw ["unhandled case in Ident \"mkRect\"", [$36$_a, $36$_b]];
});
};
};
var batCollision = function($36$_a) {
return new $(function() {
var px = Fay$$index(0)(_(Fay$$index(0)(_($36$_a))));
var py = Fay$$index(1)(_(Fay$$index(0)(_($36$_a))));
var bx = Fay$$index(0)(_(Fay$$index(1)(_($36$_a))));
var by = Fay$$index(1)(_(Fay$$index(1)(_($36$_a))));
return (function() {
var w$39$ = new $(function() {
return __(div, _(bw) + _(pw), 2);
});
var h$39$ = new $(function() {
return __(div, _(bh) + _(ph), 2);
});
var bw_bh = new $(function() {
return ballSize;
});
var bw = new $(function() {
return Fay$$index(0)(_(bw_bh));
});
var bh = new $(function() {
return Fay$$index(1)(_(bw_bh));
});
var pw_ph = new $(function() {
return batSize;
});
var pw = new $(function() {
return Fay$$index(0)(_(pw_ph));
});
var ph = new $(function() {
return Fay$$index(1)(_(pw_ph));
});
return _(_(__(abs, _(px) - _(bx))) < _(w$39$)) && _(_(__(abs, _(py) - _(by))) < _(h$39$));
})();
throw ["unhandled case in Ident \"batCollision\"", [$36$_a]];
});
};
var wallCollision = function($36$_a) {
return new $(function() {
var y = Fay$$index(1)(_($36$_a));
return _(_(y) < _(topWall)) || _(_(y) > _(bottomWall));
throw ["unhandled case in Ident \"wallCollision\"", [$36$_a]];
});
};
var wallBounce = new $(function() {
return __($62$$62$$62$, __(watch, wallCollision), __(constE, VBounce));
});
var batBounce = new $(function() {
return __($62$$62$$62$, __(watch, batCollision), __(constE, HBounce));
});
var playerPos = new $(function() {
return __($62$$62$$62$, __($62$$62$$62$, playerSpeed, __(integrate, startPos)), __(arr, function($36$_a) {
var y = $36$_a;
return Fay$$list([10, y]);
}));
});
var playerSpeed = new $(function() {
var keyboardDir = function($36$_a) {
return new $(function() {
if (_($36$_a) instanceof $36$_Up) {
return 0 - _(batSpeed);
}
if (_($36$_a) instanceof $36$_Down) {
return batSpeed;
}
if (_($36$_a) instanceof $36$_Same) {
return 0;
}
throw ["unhandled case in Ident \"keyboardDir\"", [$36$_a]];
});
};
return __(arr, keyboardDir);
});
var restartWhen = function($36$_a) {
return new $(function() {
var co = $36$_a;
return (function() {
var step = function($36$_a) {
return function($36$_b) {
return new $(function() {
var i = Fay$$index(0)(_($36$_b));
var ev = Fay$$index(1)(_($36$_b));
var c = $36$_a;
return (function() {
var o_c$39$ = new $(function() {
return __(runC, c, i);
});
var o = new $(function() {
return Fay$$index(0)(_(o_c$39$));
});
var c$39$ = new $(function() {
return Fay$$index(1)(_(o_c$39$));
});
var cont = new $(function() {
return _(__($_null, ev)) ? __(step, c$39$) : __(step, co);
});
return Fay$$list([o, __(Coroutine, cont)]);
})();
throw ["unhandled case in Ident \"step\"", [$36$_a, $36$_b]];
});
};
};
return __($36$, Coroutine, __(step, co));
})();
});
};
var ballPos = new $(function() {
return __($36$, loopC, __($62$$62$$62$, __($62$$62$$62$, __($62$$62$$62$, __($62$$62$$62$, __($42$$42$$42$, __($62$$62$$62$, __(arr, function($36$_a) {
var ppos = Fay$$index(0)(_($36$_a));
var bpos = Fay$$index(1)(_($36$_a));
return Fay$$list([Fay$$list([ppos, bpos]), bpos]);
throw ["unhandled case", $36$_a];
}), batBounce), wallBounce), zipE), __(scanE, bounce, ballInitVel)), __(scan, vecAdd, ballInitPos)), __(withPrevious, ballInitPos)));
});
var resettingBallPos = new $(function() {
var outOfBounds = function($36$_a) {
return new $(function() {
var x = Fay$$index(0)(_($36$_a));
return _(_(x) < 0) || _(_(x) > 800);
throw ["unhandled case in Ident \"outOfBounds\"", [$36$_a]];
});
};
return __($36$, loopC, __($38$$38$$38$, __($62$$62$$62$, __(restartWhen, ballPos), idC), __(watch, outOfBounds)));
});
var game = new $(function() {
return __($62$$62$$62$, __($38$$38$$38$, __($62$$62$$62$, playerPos, idC), resettingBallPos), __($36$, arrC, function($36$_a) {
var plPos = Fay$$index(0)(_($36$_a));
var blPos = Fay$$index(1)(_($36$_a));
return Fay$$list([__(mkRect, plPos, batSize), __(mkRect, blPos, ballSize)]);
throw ["unhandled case", $36$_a];
}));
});
var abs = function($36$_a) {
return new $(function() {
return Fay$$jsToFay(["double"], Math.abs(Fay$$fayToJs(["double"], $36$_a)));
});
};
var div = function($36$_a) {
return function($36$_b) {
return new $(function() {
return Fay$$jsToFay(["double"], Math.floor(Fay$$fayToJs(["double"], $36$_a) / Fay$$fayToJs(["double"], $36$_b)));
});
};
};
var log = function($36$_a) {
return new $(function() {
return Fay$$jsToFay(["action", [
["unknown"]
]], console.log(Fay$$fayToJs(["unknown"], $36$_a)));
});
};
var log2 = function($36$_a) {
return function($36$_b) {
return new $(function() {
return Fay$$jsToFay(["action", [
["unknown"]
]], console.log(Fay$$fayToJs(["string"], $36$_a), Fay$$fayToJs(["string"], $36$_b)));
});
};
};
var showRect = function($36$_a) {
return new $(function() {
if (_($36$_a) instanceof $36$_Rect) {
var p1 = Fay$$index(0)(_(_($36$_a).slot1));
var p2 = Fay$$index(1)(_(_($36$_a).slot1));
return __($43$$43$, Fay$$list("("), __($43$$43$, __(show, p1), __($43$$43$, Fay$$list(", "), __($43$$43$, __(show, p2), Fay$$list(")")))));
}
throw ["unhandled case in Ident \"showRect\"", [$36$_a]];
});
};
var logS = function($36$_a) {
return new $(function() {
return Fay$$jsToFay(["action", [
["unknown"]
]], console.log(Fay$$fayToJs(["string"], $36$_a)));
});
};
var logF = function($36$_a) {
return new $(function() {
return Fay$$jsToFay(["action", [
["unknown"]
]], console.log(_(Fay$$fayToJs(["unknown"], $36$_a))));
});
};
var $36$_Just = function(slot1) {
this.slot1 = slot1;
};
var Just = function(slot1) {
return new $(function() {
return new $36$_Just(slot1);
});
};
var $36$_Nothing = function() {};
var Nothing = new $(function() {
return new $36$_Nothing();
});
var show = function($36$_a) {
return new $(function() {
return Fay$$jsToFay(["string"], JSON.stringify(Fay$$fayToJs(["unknown"], $36$_a)));
});
};
var fromInteger = function($36$_a) {
return new $(function() {
var x = $36$_a;
return x;
});
};
var fromRational = function($36$_a) {
return new $(function() {
var x = $36$_a;
return x;
});
};
var snd = function($36$_a) {
return new $(function() {
var x = Fay$$index(1)(_($36$_a));
return x;
throw ["unhandled case in Ident \"snd\"", [$36$_a]];
});
};
var fst = function($36$_a) {
return new $(function() {
var x = Fay$$index(0)(_($36$_a));
return x;
throw ["unhandled case in Ident \"fst\"", [$36$_a]];
});
};
var find = function($36$_a) {
return function($36$_b) {
return new $(function() {
var $36$_$36$_b = _($36$_b);
if ($36$_$36$_b instanceof Fay$$Cons) {
var x = $36$_$36$_b.car;
var xs = $36$_$36$_b.cdr;
var p = $36$_a;
return _(__(p, x)) ? __(Just, x) : __(find, p, xs);
}
if (_($36$_b) === null) {
return Nothing;
}
throw ["unhandled case in Ident \"find\"", [$36$_a, $36$_b]];
});
};
};
var any = function($36$_a) {
return function($36$_b) {
return new $(function() {
var $36$_$36$_b = _($36$_b);
if ($36$_$36$_b instanceof Fay$$Cons) {
var x = $36$_$36$_b.car;
var xs = $36$_$36$_b.cdr;
var p = $36$_a;
return _(__(p, x)) ? true : __(any, p, xs);
}
if (_($36$_b) === null) {
return false;
}
throw ["unhandled case in Ident \"any\"", [$36$_a, $36$_b]];
});
};
};
var filter = function($36$_a) {
return function($36$_b) {
return new $(function() {
var $36$_$36$_b = _($36$_b);
if ($36$_$36$_b instanceof Fay$$Cons) {
var x = $36$_$36$_b.car;
var xs = $36$_$36$_b.cdr;
var p = $36$_a;
return _(__(p, x)) ? __(Fay$$cons, x, __(filter, p, xs)) : __(filter, p, xs);
}
if (_($36$_b) === null) {
return null;
}
throw ["unhandled case in Ident \"filter\"", [$36$_a, $36$_b]];
});
};
};
var not = function($36$_a) {
return new $(function() {
var p = $36$_a;
return _(p) ? false : true;
});
};
var $_null = function($36$_a) {
return new $(function() {
if (_($36$_a) === null) {
return true;
}
return false;
});
};
var map = function($36$_a) {
return function($36$_b) {
return new $(function() {
if (_($36$_b) === null) {
return null;
}
var $36$_$36$_b = _($36$_b);
if ($36$_$36$_b instanceof Fay$$Cons) {
var x = $36$_$36$_b.car;
var xs = $36$_$36$_b.cdr;
var f = $36$_a;
return __(Fay$$cons, __(f, x), __(map, f, xs));
}
throw ["unhandled case in Ident \"map\"", [$36$_a, $36$_b]];
});
};
};
var nub = function($36$_a) {
return new $(function() {
var ls = $36$_a;
return __(nub$39$, ls, null);
});
};
var nub$39$ = function($36$_a) {
return function($36$_b) {
return new $(function() {
if (_($36$_a) === null) {
return null;
}
var ls = $36$_b;
var $36$_$36$_a = _($36$_a);
if ($36$_$36$_a instanceof Fay$$Cons) {
var x = $36$_$36$_a.car;
var xs = $36$_$36$_a.cdr;
return _(__(elem, x, ls)) ? __(nub$39$, xs, ls) : __(Fay$$cons, x, __(nub$39$, xs, __(Fay$$cons, x, ls)));
}
throw ["unhandled case in Ident \"nub'\"", [$36$_a, $36$_b]];
});
};
};
var elem = function($36$_a) {
return function($36$_b) {
return new $(function() {
var $36$_$36$_b = _($36$_b);
if ($36$_$36$_b instanceof Fay$$Cons) {
var y = $36$_$36$_b.car;
var ys = $36$_$36$_b.cdr;
var x = $36$_a;
return _(__(Fay$$eq, x, y)) || _(__(elem, x, ys));
}
if (_($36$_b) === null) {
return false;
}
throw ["unhandled case in Ident \"elem\"", [$36$_a, $36$_b]];
});
};
};
var $36$_GT = function() {};
var GT = new $(function() {
return new $36$_GT();
});
var $36$_LT = function() {};
var LT = new $(function() {
return new $36$_LT();
});
var $36$_EQ = function() {};
var EQ = new $(function() {
return new $36$_EQ();
});
var sort = new $(function() {
return __(sortBy, compare);
});
var compare = function($36$_a) {
return function($36$_b) {
return new $(function() {
var y = $36$_b;
var x = $36$_a;
return _(_(x) > _(y)) ? GT : _(_(x) < _(y)) ? LT : EQ;
});
};
};
var sortBy = function($36$_a) {
return new $(function() {
var cmp = $36$_a;
return __(foldr, __(insertBy, cmp), null);
});
};
var insertBy = function($36$_a) {
return function($36$_b) {
return function($36$_c) {
return new $(function() {
if (_($36$_c) === null) {
var x = $36$_b;
return Fay$$list([x]);
}
var ys = $36$_c;
var x = $36$_b;
var cmp = $36$_a;
return (function($36$_ys) {
if (_($36$_ys) === null) {
return Fay$$list([x]);
}
var $36$_$36$_ys = _($36$_ys);
if ($36$_$36$_ys instanceof Fay$$Cons) {
var y = $36$_$36$_ys.car;
var ys$39$ = $36$_$36$_ys.cdr;
return (function($tmp) {
if (_($tmp) instanceof $36$_GT) {
return __(Fay$$cons, y, __(insertBy, cmp, x, ys$39$));
}
return __(Fay$$cons, x, ys);
})(__(cmp, x, y));
}
return (function() {
throw (["unhandled case", $36$_ys]);
})();
})(ys);
});
};
};
};
var when = function($36$_a) {
return function($36$_b) {
return new $(function() {
var m = $36$_b;
var p = $36$_a;
return _(p) ? __($62$$62$, m, __($_return, Fay$$unit)) : __($_return, Fay$$unit);
});
};
};
var enumFrom = function($36$_a) {
return new $(function() {
var i = $36$_a;
return __(Fay$$cons, i, __(enumFrom, _(i) + 1));
});
};
var enumFromTo = function($36$_a) {
return function($36$_b) {
return new $(function() {
var n = $36$_b;
var i = $36$_a;
return _(__(Fay$$eq, i, n)) ? Fay$$list([i]) : __(Fay$$cons, i, __(enumFromTo, _(i) + 1, n));
});
};
};
var zipWith = function($36$_a) {
return function($36$_b) {
return function($36$_c) {
return new $(function() {
var $36$_$36$_c = _($36$_c);
if ($36$_$36$_c instanceof Fay$$Cons) {
var b = $36$_$36$_c.car;
var bs = $36$_$36$_c.cdr;
var $36$_$36$_b = _($36$_b);
if ($36$_$36$_b instanceof Fay$$Cons) {
var a = $36$_$36$_b.car;
var as = $36$_$36$_b.cdr;
var f = $36$_a;
return __(Fay$$cons, __(f, a, b), __(zipWith, f, as, bs));
}
}
return null;
});
};
};
};
var zip = function($36$_a) {
return function($36$_b) {
return new $(function() {
var $36$_$36$_b = _($36$_b);
if ($36$_$36$_b instanceof Fay$$Cons) {
var b = $36$_$36$_b.car;
var bs = $36$_$36$_b.cdr;
var $36$_$36$_a = _($36$_a);
if ($36$_$36$_a instanceof Fay$$Cons) {
var a = $36$_$36$_a.car;
var as = $36$_$36$_a.cdr;
return __(Fay$$cons, Fay$$list([a, b]), __(zip, as, bs));
}
}
return null;
});
};
};
var flip = function($36$_a) {
return function($36$_b) {
return function($36$_c) {
return new $(function() {
var y = $36$_c;
var x = $36$_b;
var f = $36$_a;
return __(f, y, x);
});
};
};
};
var maybe = function($36$_a) {
return function($36$_b) {
return function($36$_c) {
return new $(function() {
if (_($36$_c) instanceof $36$_Nothing) {
var m = $36$_a;
return m;
}
if (_($36$_c) instanceof $36$_Just) {
var x = _($36$_c).slot1;
var f = $36$_b;
return __(f, x);
}
throw ["unhandled case in Ident \"maybe\"", [$36$_a, $36$_b, $36$_c]];
});
};
};
};
var $46$ = function($36$_a) {
return function($36$_b) {
return function($36$_c) {
return new $(function() {
var x = $36$_c;
var g = $36$_b;
var f = $36$_a;
return __(f, __(g, x));
});
};
};
};
var $43$$43$ = function($36$_a) {
return function($36$_b) {
return new $(function() {
var y = $36$_b;
var x = $36$_a;
return __(conc, x, y);
});
};
};
var $36$ = function($36$_a) {
return function($36$_b) {
return new $(function() {
var x = $36$_b;
var f = $36$_a;
return __(f, x);
});
};
};
var conc = function($36$_a) {
return function($36$_b) {
return new $(function() {
var ys = $36$_b;
var $36$_$36$_a = _($36$_a);
if ($36$_$36$_a instanceof Fay$$Cons) {
var x = $36$_$36$_a.car;
var xs = $36$_$36$_a.cdr;
return __(Fay$$cons, x, __(conc, xs, ys));
}
var ys = $36$_b;
if (_($36$_a) === null) {
return ys;
}
throw ["unhandled case in Ident \"conc\"", [$36$_a, $36$_b]];
});
};
};
var concat = new $(function() {
return __(foldr, conc, null);
});
var foldr = function($36$_a) {
return function($36$_b) {
return function($36$_c) {
return new $(function() {
if (_($36$_c) === null) {
var z = $36$_b;
return z;
}
var $36$_$36$_c = _($36$_c);
if ($36$_$36$_c instanceof Fay$$Cons) {
var x = $36$_$36$_c.car;
var xs = $36$_$36$_c.cdr;
var z = $36$_b;
var f = $36$_a;
return __(f, x, __(foldr, f, z, xs));
}
throw ["unhandled case in Ident \"foldr\"", [$36$_a, $36$_b, $36$_c]];
});
};
};
};
var foldl = function($36$_a) {
return function($36$_b) {
return function($36$_c) {
return new $(function() {
if (_($36$_c) === null) {
var z = $36$_b;
return z;
}
var $36$_$36$_c = _($36$_c);
if ($36$_$36$_c instanceof Fay$$Cons) {
var x = $36$_$36$_c.car;
var xs = $36$_$36$_c.cdr;
var z = $36$_b;
var f = $36$_a;
return __(foldl, f, __(f, z, x), xs);
}
throw ["unhandled case in Ident \"foldl\"", [$36$_a, $36$_b, $36$_c]];
});
};
};
};
var lookup = function($36$_a) {
return function($36$_b) {
return new $(function() {
if (_($36$_b) === null) {
var _key = $36$_a;
return Nothing;
}
var $36$_$36$_b = _($36$_b);
if ($36$_$36$_b instanceof Fay$$Cons) {
var x = Fay$$index(0)(_($36$_$36$_b.car));
var y = Fay$$index(1)(_($36$_$36$_b.car));
var xys = $36$_$36$_b.cdr;
var key = $36$_a;
return _(__(Fay$$eq, key, x)) ? __(Just, y) : __(lookup, key, xys);
}
throw ["unhandled case in Ident \"lookup\"", [$36$_a, $36$_b]];
});
};
};
var intersperse = function($36$_a) {
return function($36$_b) {
return new $(function() {
if (_($36$_b) === null) {
return null;
}
var $36$_$36$_b = _($36$_b);
if ($36$_$36$_b instanceof Fay$$Cons) {
var x = $36$_$36$_b.car;
var xs = $36$_$36$_b.cdr;
var sep = $36$_a;
return __(Fay$$cons, x, __(prependToAll, sep, xs));
}
throw ["unhandled case in Ident \"intersperse\"", [$36$_a, $36$_b]];
});
};
};
var prependToAll = function($36$_a) {
return function($36$_b) {
return new $(function() {
if (_($36$_b) === null) {
return null;
}
var $36$_$36$_b = _($36$_b);
if ($36$_$36$_b instanceof Fay$$Cons) {
var x = $36$_$36$_b.car;
var xs = $36$_$36$_b.cdr;
var sep = $36$_a;
return __(Fay$$cons, sep, __(Fay$$cons, x, __(prependToAll, sep, xs)));
}
throw ["unhandled case in Ident \"prependToAll\"", [$36$_a, $36$_b]];
});
};
};
var intercalate = function($36$_a) {
return function($36$_b) {
return new $(function() {
var xss = $36$_b;
var xs = $36$_a;
return __(concat, __(intersperse, xs, xss));
});
};
};
var forM_ = function($36$_a) {
return function($36$_b) {
return new $(function() {
var m = $36$_b;
var $36$_$36$_a = _($36$_a);
if ($36$_$36$_a instanceof Fay$$Cons) {
var x = $36$_$36$_a.car;
var xs = $36$_$36$_a.cdr;
return __($62$$62$, __(m, x), __(forM_, xs, m));
}
if (_($36$_a) === null) {
return __($_return, Fay$$unit);
}
throw ["unhandled case in Ident \"forM_\"", [$36$_a, $36$_b]];
});
};
};
var mapM_ = function($36$_a) {
return function($36$_b) {
return new $(function() {
var $36$_$36$_b = _($36$_b);
if ($36$_$36$_b instanceof Fay$$Cons) {
var x = $36$_$36$_b.car;
var xs = $36$_$36$_b.cdr;
var m = $36$_a;
return __($62$$62$, __(m, x), __(mapM_, m, xs));
}
if (_($36$_b) === null) {
return __($_return, Fay$$unit);
}
throw ["unhandled case in Ident \"mapM_\"", [$36$_a, $36$_b]];
});
};
};
var $_const = function($36$_a) {
return function($36$_b) {
return new $(function() {
var a = $36$_a;
return a;
});
};
};
var length = function($36$_a) {
return new $(function() {
var $36$_$36$_a = _($36$_a);
if ($36$_$36$_a instanceof Fay$$Cons) {
var xs = $36$_$36$_a.cdr;
return 1 + _(__(length, xs));
}
if (_($36$_a) === null) {
return 0;
}
throw ["unhandled case in Ident \"length\"", [$36$_a]];
});
};
var mod = function($36$_a) {
return function($36$_b) {
return new $(function() {
return Fay$$jsToFay(["double"], Fay$$fayToJs(["double"], $36$_a) % Fay$$fayToJs(["double"], $36$_b));
});
};
};
var min = function($36$_a) {
return function($36$_b) {
return new $(function() {
return Fay$$jsToFay(["double"], Math.min(Fay$$fayToJs(["double"], $36$_a), Fay$$fayToJs(["double"], $36$_b)));
});
};
};
var max = function($36$_a) {
return function($36$_b) {
return new $(function() {
return Fay$$jsToFay(["double"], Math.max(Fay$$fayToJs(["double"], $36$_a), Fay$$fayToJs(["double"], $36$_b)));
});
};
};
var fromIntegral = function($36$_a) {
return new $(function() {
return Fay$$jsToFay(["double"], Fay$$fayToJs(["int"], $36$_a));
});
};
var otherwise = true;
var reverse = function($36$_a) {
return new $(function() {
var $36$_$36$_a = _($36$_a);
if ($36$_$36$_a instanceof Fay$$Cons) {
var x = $36$_$36$_a.car;
var xs = $36$_$36$_a.cdr;
return __($43$$43$, __(reverse, xs), Fay$$list([x]));
}
if (_($36$_a) === null) {
return null;
}
throw ["unhandled case in Ident \"reverse\"", [$36$_a]];
});
};
var Fay$$fayToJsUserDefined = function(type, obj) {
var _obj = _(obj);
var argTypes = type[2];
if (_obj instanceof $36$_EQ) {
return {
"instance": "EQ"
};
}
if (_obj instanceof $36$_LT) {
return {
"instance": "LT"
};
}
if (_obj instanceof $36$_GT) {
return {
"instance": "GT"
};
}
if (_obj instanceof $36$_Nothing) {
return {
"instance": "Nothing"
};
}
if (_obj instanceof $36$_Just) {
return {
"instance": "Just",
"slot1": Fay$$fayToJs(["unknown"], _(_obj.slot1))
};
}
if (_obj instanceof $36$_Same) {
return {
"instance": "Same"
};
}
if (_obj instanceof $36$_Down) {
return {
"instance": "Down"
};
}
if (_obj instanceof $36$_Up) {
return {
"instance": "Up"
};
}
if (_obj instanceof $36$_NoBounce) {
return {
"instance": "NoBounce"
};
}
if (_obj instanceof $36$_VBounce) {
return {
"instance": "VBounce"
};
}
if (_obj instanceof $36$_HBounce) {
return {
"instance": "HBounce"
};
}
if (_obj instanceof $36$_Rect) {
return {
"instance": "Rect",
"slot1": Fay$$fayToJs(["unknown"], _(_obj.slot1))
};
}
if (_obj instanceof $36$_Coroutine) {
return {
"instance": "Coroutine",
"runC": Fay$$fayToJs(["function", [
["unknown"],
["unknown"]
]], _(_obj.runC))
};
}
if (_obj instanceof $36$_Stream) {
return {
"instance": "Stream",
"slot1": Fay$$fayToJs(["function", [
["unknown"],
["unknown"]
]], _(_obj.slot1))
};
}
return obj;
};
var Fay$$jsToFayUserDefined = function(type, obj) {
if (obj["instance"] === "EQ") {
return new $36$_EQ();
}
if (obj["instance"] === "LT") {
return new $36$_LT();
}
if (obj["instance"] === "GT") {
return new $36$_GT();
}
if (obj["instance"] === "Nothing") {
return new $36$_Nothing();
}
if (obj["instance"] === "Just") {
return new $36$_Just(Fay$$jsToFay(["unknown"], obj["slot1"]));
}
if (obj["instance"] === "Same") {
return new $36$_Same();
}
if (obj["instance"] === "Down") {
return new $36$_Down();
}
if (obj["instance"] === "Up") {
return new $36$_Up();
}
if (obj["instance"] === "NoBounce") {
return new $36$_NoBounce();
}
if (obj["instance"] === "VBounce") {
return new $36$_VBounce();
}
if (obj["instance"] === "HBounce") {
return new $36$_HBounce();
}
if (obj["instance"] === "Rect") {
return new $36$_Rect(Fay$$jsToFay(["unknown"], obj["slot1"]));
}
if (obj["instance"] === "Coroutine") {
return new $36$_Coroutine(Fay$$jsToFay(["function", [
["unknown"],
["unknown"]
]], obj["runC"]));
}
if (obj["instance"] === "Stream") {
return new $36$_Stream(Fay$$jsToFay(["function", [
["unknown"],
["unknown"]
]], obj["slot1"]));
}
return obj;
};
// Exports
this.reverse = reverse;
this.otherwise = otherwise;
this.fromIntegral = fromIntegral;
this.max = max;
this.min = min;
this.mod = mod;
this.length = length;
this.$_const = $_const;
this.mapM_ = mapM_;
this.forM_ = forM_;
this.intercalate = intercalate;
this.prependToAll = prependToAll;
this.intersperse = intersperse;
this.lookup = lookup;
this.foldl = foldl;
this.foldr = foldr;
this.concat = concat;
this.conc = conc;
this.$36$ = $36$;
this.$43$$43$ = $43$$43$;
this.$46$ = $46$;
this.maybe = maybe;
this.flip = flip;
this.zip = zip;
this.zipWith = zipWith;
this.enumFromTo = enumFromTo;
this.enumFrom = enumFrom;
this.when = when;
this.insertBy = insertBy;
this.sortBy = sortBy;
this.compare = compare;
this.sort = sort;
this.elem = elem;
this.nub$39$ = nub$39$;
this.nub = nub;
this.map = map;
this.$_null = $_null;
this.not = not;
this.filter = filter;
this.any = any;
this.find = find;
this.fst = fst;
this.snd = snd;
this.fromRational = fromRational;
this.fromInteger = fromInteger;
this.show = show;
this.logF = logF;
this.logS = logS;
this.showRect = showRect;
this.log2 = log2;
this.log = log;
this.div = div;
this.abs = abs;
this.game = game;
this.resettingBallPos = resettingBallPos;
this.ballPos = ballPos;
this.restartWhen = restartWhen;
this.playerSpeed = playerSpeed;
this.playerPos = playerPos;
this.batBounce = batBounce;
this.wallBounce = wallBounce;
this.wallCollision = wallCollision;
this.batCollision = batCollision;
this.mkRect = mkRect;
this.bounce = bounce;
this.vecAdd = vecAdd;
this.vecMul = vecMul;
this.bottomWall = bottomWall;
this.topWall = topWall;
this.ballInitVel = ballInitVel;
this.ballSize = ballSize;
this.ballInitPos = ballInitPos;
this.startPos = startPos;
this.batSize = batSize;
this.batSpeed = batSpeed;
this.logD = logD;
this.showTup = showTup;
this.main = main;
this.$_void = $_void;
// Built-ins
this._ = _;
this.$ = $;
this.$fayToJs = Fay$$fayToJs;
this.$jsToFay = Fay$$jsToFay;
};;
var main = new Tests();
main._(main.main);
-- Arrow definitions
arr = arrC
first = firstC
second = secondC
(<<<) :: Coroutine b o -> Coroutine i b -> Coroutine i o
cof <<< cog = Coroutine $ \i ->
let (x, cog') = runC cog i
(y, cof') = runC cof x
in (y, cof' <<< cog')
(>>>) = flip (<<<)
(***) :: Coroutine i o -> Coroutine i' o' -> Coroutine (i, i') (o, o')
f *** g = first f >>> second g
(&&&) :: Coroutine i o -> Coroutine i o' -> Coroutine i (o, o')
f &&& g = arr (\a -> (a, a)) >>> f *** g
firstC :: Coroutine i o -> Coroutine (i, i') (o, i')
firstC co = Coroutine $ \(a,b) ->
let (c, co') = runC co a
in ((c,b), firstC co')
secondC :: Coroutine i o -> Coroutine (i', i) (i', o)
secondC f = arr swap >>> first f >>> arr swap
where
swap :: (x, y) -> (y, x)
swap tup = let (x, y) = tup in (y, x)
arrC :: (i -> o) -> Coroutine i o
arrC f = Coroutine $ \i -> (f i, arr f)
-- instance ArrowLoop Coroutine
loop = loopC
loopC :: Coroutine (b,d) (c,d) -> Coroutine b c
loopC co = Coroutine $ \b ->
let ((c, d), co') = runC co (b,d)
in (c, loopC co')
takeN :: Double -> [i] -> Coroutine i o -> [o]
takeN 0 _ _ = []
takeN _ [] _ = []
takeN n (i:is) co = o:takeN (n-1) is co' where
(o, co') = runC co i
fac :: Coroutine Double Double
fac = loopC (arr (uncurry (*)) >>> idC &&& delay 1)
main :: Fay ()
main = ready $ do
let facs = takeN 5 [1..5] (fac >>> arr logD)
forM_ facs void
logD :: Double -> Fay ()
logD = ffi "console.log(%1)"
{- I get the following in ghci
(snap) λ> takeN 5 [1..5] fac
[1.0,2.0,6.0,24.0,120.0]
And I get 1 NaN NaN NaN NaN logged in chrome
-}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment