Skip to content

Instantly share code, notes, and snippets.

@nothingnesses
Last active May 31, 2021 13:08
Show Gist options
  • Save nothingnesses/87fe319bfec4b53e965c7f690023f840 to your computer and use it in GitHub Desktop.
Save nothingnesses/87fe319bfec4b53e965c7f690023f840 to your computer and use it in GitHub Desktop.
Bitburner Netscript PureScript FFI

I've included a pre-built index.js in case you can't be arsed to install the deps and build it yourselves, in which case, you can just skip to the Testing section. The in-game server you test this on also needs about 40Gb free RAM.

Building

  • You need purs (PureScript compiler) and spago (PureScript package manager).
  • The way I've installed them is to install the nix package manager, then clone this repo, then run nix-shell from within that repo, which should eventually give you a shell with all the needed deps installed.
  • You can then cd into the dir containing these files, then run sh build.sh.

Testing

  • In-game, copy the contents of mock_ns.js above the empty main function of a new js/ns script, named temp.js.
  • Copy the contents of index.js into the body of main.
  • The final line of code in the body of main should be something like PS["Main"].main();. In the parens, you can place either ns or a (which just has a naïve implementation of sleep) or b (which has a more complex mocked version of sleep) to test the different outcomes.

Outcome

When running temp.js using ns as argument to PS["Main"].main();, the Promise returned by sleep never seems to get resolved, whereas sleep seems to work ok as implemented in the mocks.

#!/bin/sh
mkdir -p src/
mv Main.purs ./src/Main.purs
mv Main.js ./src/Main.js
spago bundle-app
// Generated by purs bundle 0.14.1
var PS = {};
(function($PS) {
// Generated by purs version 0.14.1
"use strict";
$PS["Control.Alt"] = $PS["Control.Alt"] || {};
var exports = $PS["Control.Alt"];
var Alt = function (Functor0, alt) {
this.Functor0 = Functor0;
this.alt = alt;
};
var alt = function (dict) {
return dict.alt;
};
exports["Alt"] = Alt;
exports["alt"] = alt;
})(PS);
(function($PS) {
// Generated by purs version 0.14.1
"use strict";
$PS["Control.Semigroupoid"] = $PS["Control.Semigroupoid"] || {};
var exports = $PS["Control.Semigroupoid"];
var Semigroupoid = function (compose) {
this.compose = compose;
};
var semigroupoidFn = new Semigroupoid(function (f) {
return function (g) {
return function (x) {
return f(g(x));
};
};
});
exports["semigroupoidFn"] = semigroupoidFn;
})(PS);
(function($PS) {
// Generated by purs version 0.14.1
"use strict";
$PS["Control.Category"] = $PS["Control.Category"] || {};
var exports = $PS["Control.Category"];
var Control_Semigroupoid = $PS["Control.Semigroupoid"];
var Category = function (Semigroupoid0, identity) {
this.Semigroupoid0 = Semigroupoid0;
this.identity = identity;
};
var identity = function (dict) {
return dict.identity;
};
var categoryFn = new Category(function () {
return Control_Semigroupoid.semigroupoidFn;
}, function (x) {
return x;
});
exports["identity"] = identity;
exports["categoryFn"] = categoryFn;
})(PS);
(function($PS) {
// Generated by purs version 0.14.1
"use strict";
$PS["Data.Function"] = $PS["Data.Function"] || {};
var exports = $PS["Data.Function"];
var flip = function (f) {
return function (b) {
return function (a) {
return f(a)(b);
};
};
};
var $$const = function (a) {
return function (v) {
return a;
};
};
exports["flip"] = flip;
exports["const"] = $$const;
})(PS);
(function(exports) {
"use strict";
exports.unit = {};
})(PS["Data.Unit"] = PS["Data.Unit"] || {});
(function($PS) {
// Generated by purs version 0.14.1
"use strict";
$PS["Data.Unit"] = $PS["Data.Unit"] || {};
var exports = $PS["Data.Unit"];
var $foreign = $PS["Data.Unit"];
exports["unit"] = $foreign.unit;
})(PS);
(function($PS) {
// Generated by purs version 0.14.1
"use strict";
$PS["Data.Functor"] = $PS["Data.Functor"] || {};
var exports = $PS["Data.Functor"];
var Data_Function = $PS["Data.Function"];
var Data_Unit = $PS["Data.Unit"];
var Functor = function (map) {
this.map = map;
};
var map = function (dict) {
return dict.map;
};
var $$void = function (dictFunctor) {
return map(dictFunctor)(Data_Function["const"](Data_Unit.unit));
};
var voidRight = function (dictFunctor) {
return function (x) {
return map(dictFunctor)(Data_Function["const"](x));
};
};
exports["Functor"] = Functor;
exports["map"] = map;
exports["void"] = $$void;
exports["voidRight"] = voidRight;
})(PS);
(function($PS) {
// Generated by purs version 0.14.1
"use strict";
$PS["Control.Apply"] = $PS["Control.Apply"] || {};
var exports = $PS["Control.Apply"];
var Control_Category = $PS["Control.Category"];
var Data_Function = $PS["Data.Function"];
var Data_Functor = $PS["Data.Functor"];
var Apply = function (Functor0, apply) {
this.Functor0 = Functor0;
this.apply = apply;
};
var apply = function (dict) {
return dict.apply;
};
var applySecond = function (dictApply) {
return function (a) {
return function (b) {
return apply(dictApply)(Data_Functor.map(dictApply.Functor0())(Data_Function["const"](Control_Category.identity(Control_Category.categoryFn)))(a))(b);
};
};
};
exports["Apply"] = Apply;
exports["apply"] = apply;
exports["applySecond"] = applySecond;
})(PS);
(function($PS) {
// Generated by purs version 0.14.1
"use strict";
$PS["Control.Applicative"] = $PS["Control.Applicative"] || {};
var exports = $PS["Control.Applicative"];
var Control_Apply = $PS["Control.Apply"];
var Applicative = function (Apply0, pure) {
this.Apply0 = Apply0;
this.pure = pure;
};
var pure = function (dict) {
return dict.pure;
};
var liftA1 = function (dictApplicative) {
return function (f) {
return function (a) {
return Control_Apply.apply(dictApplicative.Apply0())(pure(dictApplicative)(f))(a);
};
};
};
exports["Applicative"] = Applicative;
exports["pure"] = pure;
exports["liftA1"] = liftA1;
})(PS);
(function($PS) {
// Generated by purs version 0.14.1
"use strict";
$PS["Control.Bind"] = $PS["Control.Bind"] || {};
var exports = $PS["Control.Bind"];
var Data_Function = $PS["Data.Function"];
var Bind = function (Apply0, bind) {
this.Apply0 = Apply0;
this.bind = bind;
};
var Discard = function (discard) {
this.discard = discard;
};
var discard = function (dict) {
return dict.discard;
};
var bind = function (dict) {
return dict.bind;
};
var bindFlipped = function (dictBind) {
return Data_Function.flip(bind(dictBind));
};
var discardUnit = new Discard(function (dictBind) {
return bind(dictBind);
});
exports["Bind"] = Bind;
exports["bind"] = bind;
exports["bindFlipped"] = bindFlipped;
exports["discard"] = discard;
exports["discardUnit"] = discardUnit;
})(PS);
(function($PS) {
// Generated by purs version 0.14.1
"use strict";
$PS["Control.Monad"] = $PS["Control.Monad"] || {};
var exports = $PS["Control.Monad"];
var Control_Applicative = $PS["Control.Applicative"];
var Control_Bind = $PS["Control.Bind"];
var Monad = function (Applicative0, Bind1) {
this.Applicative0 = Applicative0;
this.Bind1 = Bind1;
};
var ap = function (dictMonad) {
return function (f) {
return function (a) {
return Control_Bind.bind(dictMonad.Bind1())(f)(function (f$prime) {
return Control_Bind.bind(dictMonad.Bind1())(a)(function (a$prime) {
return Control_Applicative.pure(dictMonad.Applicative0())(f$prime(a$prime));
});
});
};
};
};
exports["Monad"] = Monad;
exports["ap"] = ap;
})(PS);
(function($PS) {
// Generated by purs version 0.14.1
"use strict";
$PS["Data.Either"] = $PS["Data.Either"] || {};
var exports = $PS["Data.Either"];
var Data_Functor = $PS["Data.Functor"];
var Left = (function () {
function Left(value0) {
this.value0 = value0;
};
Left.create = function (value0) {
return new Left(value0);
};
return Left;
})();
var Right = (function () {
function Right(value0) {
this.value0 = value0;
};
Right.create = function (value0) {
return new Right(value0);
};
return Right;
})();
var functorEither = new Data_Functor.Functor(function (f) {
return function (m) {
if (m instanceof Left) {
return new Left(m.value0);
};
if (m instanceof Right) {
return new Right(f(m.value0));
};
throw new Error("Failed pattern match at Data.Either (line 31, column 1 - line 31, column 52): " + [ m.constructor.name ]);
};
});
var either = function (v) {
return function (v1) {
return function (v2) {
if (v2 instanceof Left) {
return v(v2.value0);
};
if (v2 instanceof Right) {
return v1(v2.value0);
};
throw new Error("Failed pattern match at Data.Either (line 208, column 1 - line 208, column 64): " + [ v.constructor.name, v1.constructor.name, v2.constructor.name ]);
};
};
};
exports["Left"] = Left;
exports["Right"] = Right;
exports["either"] = either;
exports["functorEither"] = functorEither;
})(PS);
(function($PS) {
// Generated by purs version 0.14.1
"use strict";
$PS["Control.Monad.Error.Class"] = $PS["Control.Monad.Error.Class"] || {};
var exports = $PS["Control.Monad.Error.Class"];
var Control_Applicative = $PS["Control.Applicative"];
var Data_Either = $PS["Data.Either"];
var Data_Functor = $PS["Data.Functor"];
var MonadThrow = function (Monad0, throwError) {
this.Monad0 = Monad0;
this.throwError = throwError;
};
var MonadError = function (MonadThrow0, catchError) {
this.MonadThrow0 = MonadThrow0;
this.catchError = catchError;
};
var throwError = function (dict) {
return dict.throwError;
};
var catchError = function (dict) {
return dict.catchError;
};
var $$try = function (dictMonadError) {
return function (a) {
return catchError(dictMonadError)(Data_Functor.map(((((dictMonadError.MonadThrow0()).Monad0()).Bind1()).Apply0()).Functor0())(Data_Either.Right.create)(a))((function () {
var $17 = Control_Applicative.pure(((dictMonadError.MonadThrow0()).Monad0()).Applicative0());
return function ($18) {
return $17(Data_Either.Left.create($18));
};
})());
};
};
exports["throwError"] = throwError;
exports["MonadThrow"] = MonadThrow;
exports["MonadError"] = MonadError;
exports["try"] = $$try;
})(PS);
(function($PS) {
// Generated by purs version 0.14.1
"use strict";
$PS["Data.Semigroup"] = $PS["Data.Semigroup"] || {};
var exports = $PS["Data.Semigroup"];
var Semigroup = function (append) {
this.append = append;
};
var append = function (dict) {
return dict.append;
};
exports["Semigroup"] = Semigroup;
exports["append"] = append;
})(PS);
(function($PS) {
// Generated by purs version 0.14.1
"use strict";
$PS["Control.Monad.Except.Trans"] = $PS["Control.Monad.Except.Trans"] || {};
var exports = $PS["Control.Monad.Except.Trans"];
var Control_Alt = $PS["Control.Alt"];
var Control_Applicative = $PS["Control.Applicative"];
var Control_Apply = $PS["Control.Apply"];
var Control_Bind = $PS["Control.Bind"];
var Control_Monad = $PS["Control.Monad"];
var Control_Monad_Error_Class = $PS["Control.Monad.Error.Class"];
var Data_Either = $PS["Data.Either"];
var Data_Functor = $PS["Data.Functor"];
var Data_Semigroup = $PS["Data.Semigroup"];
var ExceptT = function (x) {
return x;
};
var runExceptT = function (v) {
return v;
};
var mapExceptT = function (f) {
return function (v) {
return f(v);
};
};
var functorExceptT = function (dictFunctor) {
return new Data_Functor.Functor(function (f) {
return mapExceptT(Data_Functor.map(dictFunctor)(Data_Functor.map(Data_Either.functorEither)(f)));
});
};
var monadExceptT = function (dictMonad) {
return new Control_Monad.Monad(function () {
return applicativeExceptT(dictMonad);
}, function () {
return bindExceptT(dictMonad);
});
};
var bindExceptT = function (dictMonad) {
return new Control_Bind.Bind(function () {
return applyExceptT(dictMonad);
}, function (v) {
return function (k) {
return Control_Bind.bind(dictMonad.Bind1())(v)(Data_Either.either((function () {
var $91 = Control_Applicative.pure(dictMonad.Applicative0());
return function ($92) {
return $91(Data_Either.Left.create($92));
};
})())(function (a) {
var v1 = k(a);
return v1;
}));
};
});
};
var applyExceptT = function (dictMonad) {
return new Control_Apply.Apply(function () {
return functorExceptT(((dictMonad.Bind1()).Apply0()).Functor0());
}, Control_Monad.ap(monadExceptT(dictMonad)));
};
var applicativeExceptT = function (dictMonad) {
return new Control_Applicative.Applicative(function () {
return applyExceptT(dictMonad);
}, (function () {
var $93 = Control_Applicative.pure(dictMonad.Applicative0());
return function ($94) {
return ExceptT($93(Data_Either.Right.create($94)));
};
})());
};
var monadThrowExceptT = function (dictMonad) {
return new Control_Monad_Error_Class.MonadThrow(function () {
return monadExceptT(dictMonad);
}, (function () {
var $103 = Control_Applicative.pure(dictMonad.Applicative0());
return function ($104) {
return ExceptT($103(Data_Either.Left.create($104)));
};
})());
};
var altExceptT = function (dictSemigroup) {
return function (dictMonad) {
return new Control_Alt.Alt(function () {
return functorExceptT(((dictMonad.Bind1()).Apply0()).Functor0());
}, function (v) {
return function (v1) {
return Control_Bind.bind(dictMonad.Bind1())(v)(function (rm) {
if (rm instanceof Data_Either.Right) {
return Control_Applicative.pure(dictMonad.Applicative0())(new Data_Either.Right(rm.value0));
};
if (rm instanceof Data_Either.Left) {
return Control_Bind.bind(dictMonad.Bind1())(v1)(function (rn) {
if (rn instanceof Data_Either.Right) {
return Control_Applicative.pure(dictMonad.Applicative0())(new Data_Either.Right(rn.value0));
};
if (rn instanceof Data_Either.Left) {
return Control_Applicative.pure(dictMonad.Applicative0())(new Data_Either.Left(Data_Semigroup.append(dictSemigroup)(rm.value0)(rn.value0)));
};
throw new Error("Failed pattern match at Control.Monad.Except.Trans (line 87, column 9 - line 89, column 49): " + [ rn.constructor.name ]);
});
};
throw new Error("Failed pattern match at Control.Monad.Except.Trans (line 83, column 5 - line 89, column 49): " + [ rm.constructor.name ]);
});
};
});
};
};
exports["runExceptT"] = runExceptT;
exports["functorExceptT"] = functorExceptT;
exports["applicativeExceptT"] = applicativeExceptT;
exports["altExceptT"] = altExceptT;
exports["monadThrowExceptT"] = monadThrowExceptT;
})(PS);
(function(exports) {
"use strict";
// module Unsafe.Coerce
exports.unsafeCoerce = function (x) {
return x;
};
})(PS["Unsafe.Coerce"] = PS["Unsafe.Coerce"] || {});
(function($PS) {
// Generated by purs version 0.14.1
"use strict";
$PS["Unsafe.Coerce"] = $PS["Unsafe.Coerce"] || {};
var exports = $PS["Unsafe.Coerce"];
var $foreign = $PS["Unsafe.Coerce"];
exports["unsafeCoerce"] = $foreign.unsafeCoerce;
})(PS);
(function($PS) {
// Generated by purs version 0.14.1
"use strict";
$PS["Safe.Coerce"] = $PS["Safe.Coerce"] || {};
var exports = $PS["Safe.Coerce"];
var Unsafe_Coerce = $PS["Unsafe.Coerce"];
var coerce = function (dictCoercible) {
return Unsafe_Coerce.unsafeCoerce;
};
exports["coerce"] = coerce;
})(PS);
(function($PS) {
// Generated by purs version 0.14.1
"use strict";
$PS["Data.Newtype"] = $PS["Data.Newtype"] || {};
var exports = $PS["Data.Newtype"];
var Safe_Coerce = $PS["Safe.Coerce"];
var unwrap = function (dictNewtype) {
return Safe_Coerce.coerce();
};
exports["unwrap"] = unwrap;
})(PS);
(function($PS) {
// Generated by purs version 0.14.1
"use strict";
$PS["Control.Monad.Except"] = $PS["Control.Monad.Except"] || {};
var exports = $PS["Control.Monad.Except"];
var Control_Monad_Except_Trans = $PS["Control.Monad.Except.Trans"];
var Data_Newtype = $PS["Data.Newtype"];
var runExcept = (function () {
var $0 = Data_Newtype.unwrap();
return function ($1) {
return $0(Control_Monad_Except_Trans.runExceptT($1));
};
})();
exports["runExcept"] = runExcept;
})(PS);
(function($PS) {
// Generated by purs version 0.14.1
"use strict";
$PS["Control.Parallel.Class"] = $PS["Control.Parallel.Class"] || {};
var exports = $PS["Control.Parallel.Class"];
var Parallel = function (Applicative1, Monad0, parallel, sequential) {
this.Applicative1 = Applicative1;
this.Monad0 = Monad0;
this.parallel = parallel;
this.sequential = sequential;
};
var sequential = function (dict) {
return dict.sequential;
};
var parallel = function (dict) {
return dict.parallel;
};
exports["parallel"] = parallel;
exports["sequential"] = sequential;
exports["Parallel"] = Parallel;
})(PS);
(function(exports) {
"use strict";
exports.foldrArray = function (f) {
return function (init) {
return function (xs) {
var acc = init;
var len = xs.length;
for (var i = len - 1; i >= 0; i--) {
acc = f(xs[i])(acc);
}
return acc;
};
};
};
exports.foldlArray = function (f) {
return function (init) {
return function (xs) {
var acc = init;
var len = xs.length;
for (var i = 0; i < len; i++) {
acc = f(acc)(xs[i]);
}
return acc;
};
};
};
})(PS["Data.Foldable"] = PS["Data.Foldable"] || {});
(function($PS) {
// Generated by purs version 0.14.1
"use strict";
$PS["Data.Monoid"] = $PS["Data.Monoid"] || {};
var exports = $PS["Data.Monoid"];
var Monoid = function (Semigroup0, mempty) {
this.Semigroup0 = Semigroup0;
this.mempty = mempty;
};
var mempty = function (dict) {
return dict.mempty;
};
exports["Monoid"] = Monoid;
exports["mempty"] = mempty;
})(PS);
(function($PS) {
// Generated by purs version 0.14.1
"use strict";
$PS["Data.Foldable"] = $PS["Data.Foldable"] || {};
var exports = $PS["Data.Foldable"];
var $foreign = $PS["Data.Foldable"];
var Control_Applicative = $PS["Control.Applicative"];
var Control_Apply = $PS["Control.Apply"];
var Data_Monoid = $PS["Data.Monoid"];
var Data_Semigroup = $PS["Data.Semigroup"];
var Data_Unit = $PS["Data.Unit"];
var Foldable = function (foldMap, foldl, foldr) {
this.foldMap = foldMap;
this.foldl = foldl;
this.foldr = foldr;
};
var foldr = function (dict) {
return dict.foldr;
};
var traverse_ = function (dictApplicative) {
return function (dictFoldable) {
return function (f) {
return foldr(dictFoldable)((function () {
var $313 = Control_Apply.applySecond(dictApplicative.Apply0());
return function ($314) {
return $313(f($314));
};
})())(Control_Applicative.pure(dictApplicative)(Data_Unit.unit));
};
};
};
var foldl = function (dict) {
return dict.foldl;
};
var foldMapDefaultR = function (dictFoldable) {
return function (dictMonoid) {
return function (f) {
return foldr(dictFoldable)(function (x) {
return function (acc) {
return Data_Semigroup.append(dictMonoid.Semigroup0())(f(x))(acc);
};
})(Data_Monoid.mempty(dictMonoid));
};
};
};
var foldableArray = new Foldable(function (dictMonoid) {
return foldMapDefaultR(foldableArray)(dictMonoid);
}, $foreign.foldlArray, $foreign.foldrArray);
exports["Foldable"] = Foldable;
exports["foldr"] = foldr;
exports["foldl"] = foldl;
exports["traverse_"] = traverse_;
exports["foldableArray"] = foldableArray;
})(PS);
(function($PS) {
// Generated by purs version 0.14.1
"use strict";
$PS["Control.Parallel"] = $PS["Control.Parallel"] || {};
var exports = $PS["Control.Parallel"];
var Control_Category = $PS["Control.Category"];
var Control_Parallel_Class = $PS["Control.Parallel.Class"];
var Data_Foldable = $PS["Data.Foldable"];
var parTraverse_ = function (dictParallel) {
return function (dictFoldable) {
return function (f) {
var $17 = Control_Parallel_Class.sequential(dictParallel);
var $18 = Data_Foldable.traverse_(dictParallel.Applicative1())(dictFoldable)((function () {
var $20 = Control_Parallel_Class.parallel(dictParallel);
return function ($21) {
return $20(f($21));
};
})());
return function ($19) {
return $17($18($19));
};
};
};
};
var parSequence_ = function (dictParallel) {
return function (dictFoldable) {
return parTraverse_(dictParallel)(dictFoldable)(Control_Category.identity(Control_Category.categoryFn));
};
};
exports["parSequence_"] = parSequence_;
})(PS);
(function($PS) {
// Generated by purs version 0.14.1
"use strict";
$PS["Control.Plus"] = $PS["Control.Plus"] || {};
var exports = $PS["Control.Plus"];
var Plus = function (Alt0, empty) {
this.Alt0 = Alt0;
this.empty = empty;
};
var empty = function (dict) {
return dict.empty;
};
exports["Plus"] = Plus;
exports["empty"] = empty;
})(PS);
(function(exports) {
// module Control.Promise
exports.promise = function (f) {
return function () {
return new Promise(function (success, error) {
var succF = function (s) { return function() { return success(s); } };
var failF = function (s) { return function() { return error(s); } };
// This indicates the aff was wrong?
try { f(succF)(failF)(); }
catch (e) {
error(e);
}
});
};
};
exports.thenImpl = function(promise) {
return function(errCB) {
return function(succCB) {
return function() {
promise.then(succCB, errCB);
};
};
};
};
})(PS["Control.Promise"] = PS["Control.Promise"] || {});
(function($PS) {
// Generated by purs version 0.14.1
"use strict";
$PS["Data.Identity"] = $PS["Data.Identity"] || {};
var exports = $PS["Data.Identity"];
var Control_Applicative = $PS["Control.Applicative"];
var Control_Apply = $PS["Control.Apply"];
var Control_Bind = $PS["Control.Bind"];
var Control_Monad = $PS["Control.Monad"];
var Data_Functor = $PS["Data.Functor"];
var Identity = function (x) {
return x;
};
var functorIdentity = new Data_Functor.Functor(function (f) {
return function (m) {
return f(m);
};
});
var applyIdentity = new Control_Apply.Apply(function () {
return functorIdentity;
}, function (v) {
return function (v1) {
return v(v1);
};
});
var bindIdentity = new Control_Bind.Bind(function () {
return applyIdentity;
}, function (v) {
return function (f) {
return f(v);
};
});
var applicativeIdentity = new Control_Applicative.Applicative(function () {
return applyIdentity;
}, Identity);
var monadIdentity = new Control_Monad.Monad(function () {
return applicativeIdentity;
}, function () {
return bindIdentity;
});
exports["functorIdentity"] = functorIdentity;
exports["monadIdentity"] = monadIdentity;
})(PS);
(function($PS) {
// Generated by purs version 0.14.1
"use strict";
$PS["Data.NonEmpty"] = $PS["Data.NonEmpty"] || {};
var exports = $PS["Data.NonEmpty"];
var Control_Plus = $PS["Control.Plus"];
var NonEmpty = (function () {
function NonEmpty(value0, value1) {
this.value0 = value0;
this.value1 = value1;
};
NonEmpty.create = function (value0) {
return function (value1) {
return new NonEmpty(value0, value1);
};
};
return NonEmpty;
})();
var singleton = function (dictPlus) {
return function (a) {
return new NonEmpty(a, Control_Plus.empty(dictPlus));
};
};
exports["NonEmpty"] = NonEmpty;
exports["singleton"] = singleton;
})(PS);
(function($PS) {
// Generated by purs version 0.14.1
"use strict";
$PS["Data.List.Types"] = $PS["Data.List.Types"] || {};
var exports = $PS["Data.List.Types"];
var Control_Alt = $PS["Control.Alt"];
var Control_Plus = $PS["Control.Plus"];
var Data_Foldable = $PS["Data.Foldable"];
var Data_Function = $PS["Data.Function"];
var Data_Functor = $PS["Data.Functor"];
var Data_Monoid = $PS["Data.Monoid"];
var Data_NonEmpty = $PS["Data.NonEmpty"];
var Data_Semigroup = $PS["Data.Semigroup"];
var Nil = (function () {
function Nil() {
};
Nil.value = new Nil();
return Nil;
})();
var Cons = (function () {
function Cons(value0, value1) {
this.value0 = value0;
this.value1 = value1;
};
Cons.create = function (value0) {
return function (value1) {
return new Cons(value0, value1);
};
};
return Cons;
})();
var NonEmptyList = function (x) {
return x;
};
var toList = function (v) {
return new Cons(v.value0, v.value1);
};
var listMap = function (f) {
var chunkedRevMap = function ($copy_chunksAcc) {
return function ($copy_v) {
var $tco_var_chunksAcc = $copy_chunksAcc;
var $tco_done = false;
var $tco_result;
function $tco_loop(chunksAcc, v) {
if (v instanceof Cons && (v.value1 instanceof Cons && v.value1.value1 instanceof Cons)) {
$tco_var_chunksAcc = new Cons(v, chunksAcc);
$copy_v = v.value1.value1.value1;
return;
};
var unrolledMap = function (v1) {
if (v1 instanceof Cons && (v1.value1 instanceof Cons && v1.value1.value1 instanceof Nil)) {
return new Cons(f(v1.value0), new Cons(f(v1.value1.value0), Nil.value));
};
if (v1 instanceof Cons && v1.value1 instanceof Nil) {
return new Cons(f(v1.value0), Nil.value);
};
return Nil.value;
};
var reverseUnrolledMap = function ($copy_v1) {
return function ($copy_acc) {
var $tco_var_v1 = $copy_v1;
var $tco_done1 = false;
var $tco_result;
function $tco_loop(v1, acc) {
if (v1 instanceof Cons && (v1.value0 instanceof Cons && (v1.value0.value1 instanceof Cons && v1.value0.value1.value1 instanceof Cons))) {
$tco_var_v1 = v1.value1;
$copy_acc = new Cons(f(v1.value0.value0), new Cons(f(v1.value0.value1.value0), new Cons(f(v1.value0.value1.value1.value0), acc)));
return;
};
$tco_done1 = true;
return acc;
};
while (!$tco_done1) {
$tco_result = $tco_loop($tco_var_v1, $copy_acc);
};
return $tco_result;
};
};
$tco_done = true;
return reverseUnrolledMap(chunksAcc)(unrolledMap(v));
};
while (!$tco_done) {
$tco_result = $tco_loop($tco_var_chunksAcc, $copy_v);
};
return $tco_result;
};
};
return chunkedRevMap(Nil.value);
};
var functorList = new Data_Functor.Functor(listMap);
var foldableList = new Data_Foldable.Foldable(function (dictMonoid) {
return function (f) {
return Data_Foldable.foldl(foldableList)(function (acc) {
var $205 = Data_Semigroup.append(dictMonoid.Semigroup0())(acc);
return function ($206) {
return $205(f($206));
};
})(Data_Monoid.mempty(dictMonoid));
};
}, function (f) {
var go = function ($copy_b) {
return function ($copy_v) {
var $tco_var_b = $copy_b;
var $tco_done = false;
var $tco_result;
function $tco_loop(b, v) {
if (v instanceof Nil) {
$tco_done = true;
return b;
};
if (v instanceof Cons) {
$tco_var_b = f(b)(v.value0);
$copy_v = v.value1;
return;
};
throw new Error("Failed pattern match at Data.List.Types (line 112, column 12 - line 114, column 30): " + [ v.constructor.name ]);
};
while (!$tco_done) {
$tco_result = $tco_loop($tco_var_b, $copy_v);
};
return $tco_result;
};
};
return go;
}, function (f) {
return function (b) {
var rev = (function () {
var go = function ($copy_acc) {
return function ($copy_v) {
var $tco_var_acc = $copy_acc;
var $tco_done1 = false;
var $tco_result;
function $tco_loop(acc, v) {
if (v instanceof Nil) {
$tco_done1 = true;
return acc;
};
if (v instanceof Cons) {
$tco_var_acc = new Cons(v.value0, acc);
$copy_v = v.value1;
return;
};
throw new Error("Failed pattern match at Data.List.Types (line 108, column 7 - line 108, column 23): " + [ acc.constructor.name, v.constructor.name ]);
};
while (!$tco_done1) {
$tco_result = $tco_loop($tco_var_acc, $copy_v);
};
return $tco_result;
};
};
return go(Nil.value);
})();
var $207 = Data_Foldable.foldl(foldableList)(Data_Function.flip(f))(b);
return function ($208) {
return $207(rev($208));
};
};
});
var semigroupList = new Data_Semigroup.Semigroup(function (xs) {
return function (ys) {
return Data_Foldable.foldr(foldableList)(Cons.create)(ys)(xs);
};
});
var semigroupNonEmptyList = new Data_Semigroup.Semigroup(function (v) {
return function (as$prime) {
return new Data_NonEmpty.NonEmpty(v.value0, Data_Semigroup.append(semigroupList)(v.value1)(toList(as$prime)));
};
});
var altList = new Control_Alt.Alt(function () {
return functorList;
}, Data_Semigroup.append(semigroupList));
var plusList = new Control_Plus.Plus(function () {
return altList;
}, Nil.value);
exports["NonEmptyList"] = NonEmptyList;
exports["plusList"] = plusList;
exports["semigroupNonEmptyList"] = semigroupNonEmptyList;
})(PS);
(function(exports) {
"use strict";
exports.pureE = function (a) {
return function () {
return a;
};
};
exports.bindE = function (a) {
return function (f) {
return function () {
return f(a())();
};
};
};
})(PS["Effect"] = PS["Effect"] || {});
(function($PS) {
// Generated by purs version 0.14.1
"use strict";
$PS["Effect"] = $PS["Effect"] || {};
var exports = $PS["Effect"];
var $foreign = $PS["Effect"];
var Control_Applicative = $PS["Control.Applicative"];
var Control_Apply = $PS["Control.Apply"];
var Control_Bind = $PS["Control.Bind"];
var Control_Monad = $PS["Control.Monad"];
var Data_Functor = $PS["Data.Functor"];
var monadEffect = new Control_Monad.Monad(function () {
return applicativeEffect;
}, function () {
return bindEffect;
});
var bindEffect = new Control_Bind.Bind(function () {
return applyEffect;
}, $foreign.bindE);
var applyEffect = new Control_Apply.Apply(function () {
return functorEffect;
}, Control_Monad.ap(monadEffect));
var applicativeEffect = new Control_Applicative.Applicative(function () {
return applyEffect;
}, $foreign.pureE);
var functorEffect = new Data_Functor.Functor(Control_Applicative.liftA1(applicativeEffect));
exports["functorEffect"] = functorEffect;
})(PS);
(function(exports) {
/* globals setImmediate, clearImmediate, setTimeout, clearTimeout */
/* eslint-disable no-unused-vars, no-prototype-builtins, no-use-before-define, no-unused-labels, no-param-reassign */
"use strict";
var Aff = function () {
// A unique value for empty.
var EMPTY = {};
/*
An awkward approximation. We elide evidence we would otherwise need in PS for
efficiency sake.
data Aff eff a
= Pure a
| Throw Error
| Catch (Aff eff a) (Error -> Aff eff a)
| Sync (Eff eff a)
| Async ((Either Error a -> Eff eff Unit) -> Eff eff (Canceler eff))
| forall b. Bind (Aff eff b) (b -> Aff eff a)
| forall b. Bracket (Aff eff b) (BracketConditions eff b) (b -> Aff eff a)
| forall b. Fork Boolean (Aff eff b) ?(Fiber eff b -> a)
| Sequential (ParAff aff a)
*/
var PURE = "Pure";
var THROW = "Throw";
var CATCH = "Catch";
var SYNC = "Sync";
var ASYNC = "Async";
var BIND = "Bind";
var BRACKET = "Bracket";
var FORK = "Fork";
var SEQ = "Sequential";
/*
data ParAff eff a
= forall b. Map (b -> a) (ParAff eff b)
| forall b. Apply (ParAff eff (b -> a)) (ParAff eff b)
| Alt (ParAff eff a) (ParAff eff a)
| ?Par (Aff eff a)
*/
var MAP = "Map";
var APPLY = "Apply";
var ALT = "Alt";
// Various constructors used in interpretation
var CONS = "Cons"; // Cons-list, for stacks
var RESUME = "Resume"; // Continue indiscriminately
var RELEASE = "Release"; // Continue with bracket finalizers
var FINALIZER = "Finalizer"; // A non-interruptible effect
var FINALIZED = "Finalized"; // Marker for finalization
var FORKED = "Forked"; // Reference to a forked fiber, with resumption stack
var FIBER = "Fiber"; // Actual fiber reference
var THUNK = "Thunk"; // Primed effect, ready to invoke
function Aff(tag, _1, _2, _3) {
this.tag = tag;
this._1 = _1;
this._2 = _2;
this._3 = _3;
}
function AffCtr(tag) {
var fn = function (_1, _2, _3) {
return new Aff(tag, _1, _2, _3);
};
fn.tag = tag;
return fn;
}
function nonCanceler(error) {
return new Aff(PURE, void 0);
}
function runEff(eff) {
try {
eff();
} catch (error) {
setTimeout(function () {
throw error;
}, 0);
}
}
function runSync(left, right, eff) {
try {
return right(eff());
} catch (error) {
return left(error);
}
}
function runAsync(left, eff, k) {
try {
return eff(k)();
} catch (error) {
k(left(error))();
return nonCanceler;
}
}
var Scheduler = function () {
var limit = 1024;
var size = 0;
var ix = 0;
var queue = new Array(limit);
var draining = false;
function drain() {
var thunk;
draining = true;
while (size !== 0) {
size--;
thunk = queue[ix];
queue[ix] = void 0;
ix = (ix + 1) % limit;
thunk();
}
draining = false;
}
return {
isDraining: function () {
return draining;
},
enqueue: function (cb) {
var i, tmp;
if (size === limit) {
tmp = draining;
drain();
draining = tmp;
}
queue[(ix + size) % limit] = cb;
size++;
if (!draining) {
drain();
}
}
};
}();
function Supervisor(util) {
var fibers = {};
var fiberId = 0;
var count = 0;
return {
register: function (fiber) {
var fid = fiberId++;
fiber.onComplete({
rethrow: true,
handler: function (result) {
return function () {
count--;
delete fibers[fid];
};
}
})();
fibers[fid] = fiber;
count++;
},
isEmpty: function () {
return count === 0;
},
killAll: function (killError, cb) {
return function () {
if (count === 0) {
return cb();
}
var killCount = 0;
var kills = {};
function kill(fid) {
kills[fid] = fibers[fid].kill(killError, function (result) {
return function () {
delete kills[fid];
killCount--;
if (util.isLeft(result) && util.fromLeft(result)) {
setTimeout(function () {
throw util.fromLeft(result);
}, 0);
}
if (killCount === 0) {
cb();
}
};
})();
}
for (var k in fibers) {
if (fibers.hasOwnProperty(k)) {
killCount++;
kill(k);
}
}
fibers = {};
fiberId = 0;
count = 0;
return function (error) {
return new Aff(SYNC, function () {
for (var k in kills) {
if (kills.hasOwnProperty(k)) {
kills[k]();
}
}
});
};
};
}
};
}
// Fiber state machine
var SUSPENDED = 0; // Suspended, pending a join.
var CONTINUE = 1; // Interpret the next instruction.
var STEP_BIND = 2; // Apply the next bind.
var STEP_RESULT = 3; // Handle potential failure from a result.
var PENDING = 4; // An async effect is running.
var RETURN = 5; // The current stack has returned.
var COMPLETED = 6; // The entire fiber has completed.
function Fiber(util, supervisor, aff) {
// Monotonically increasing tick, increased on each asynchronous turn.
var runTick = 0;
// The current branch of the state machine.
var status = SUSPENDED;
// The current point of interest for the state machine branch.
var step = aff; // Successful step
var fail = null; // Failure step
var interrupt = null; // Asynchronous interrupt
// Stack of continuations for the current fiber.
var bhead = null;
var btail = null;
// Stack of attempts and finalizers for error recovery. Every `Cons` is also
// tagged with current `interrupt` state. We use this to track which items
// should be ignored or evaluated as a result of a kill.
var attempts = null;
// A special state is needed for Bracket, because it cannot be killed. When
// we enter a bracket acquisition or finalizer, we increment the counter,
// and then decrement once complete.
var bracketCount = 0;
// Each join gets a new id so they can be revoked.
var joinId = 0;
var joins = null;
var rethrow = true;
// Each invocation of `run` requires a tick. When an asynchronous effect is
// resolved, we must check that the local tick coincides with the fiber
// tick before resuming. This prevents multiple async continuations from
// accidentally resuming the same fiber. A common example may be invoking
// the provided callback in `makeAff` more than once, but it may also be an
// async effect resuming after the fiber was already cancelled.
function run(localRunTick) {
var tmp, result, attempt;
while (true) {
tmp = null;
result = null;
attempt = null;
switch (status) {
case STEP_BIND:
status = CONTINUE;
try {
step = bhead(step);
if (btail === null) {
bhead = null;
} else {
bhead = btail._1;
btail = btail._2;
}
} catch (e) {
status = RETURN;
fail = util.left(e);
step = null;
}
break;
case STEP_RESULT:
if (util.isLeft(step)) {
status = RETURN;
fail = step;
step = null;
} else if (bhead === null) {
status = RETURN;
} else {
status = STEP_BIND;
step = util.fromRight(step);
}
break;
case CONTINUE:
switch (step.tag) {
case BIND:
if (bhead) {
btail = new Aff(CONS, bhead, btail);
}
bhead = step._2;
status = CONTINUE;
step = step._1;
break;
case PURE:
if (bhead === null) {
status = RETURN;
step = util.right(step._1);
} else {
status = STEP_BIND;
step = step._1;
}
break;
case SYNC:
status = STEP_RESULT;
step = runSync(util.left, util.right, step._1);
break;
case ASYNC:
status = PENDING;
step = runAsync(util.left, step._1, function (result) {
return function () {
if (runTick !== localRunTick) {
return;
}
runTick++;
Scheduler.enqueue(function () {
// It's possible to interrupt the fiber between enqueuing and
// resuming, so we need to check that the runTick is still
// valid.
if (runTick !== localRunTick + 1) {
return;
}
status = STEP_RESULT;
step = result;
run(runTick);
});
};
});
return;
case THROW:
status = RETURN;
fail = util.left(step._1);
step = null;
break;
// Enqueue the Catch so that we can call the error handler later on
// in case of an exception.
case CATCH:
if (bhead === null) {
attempts = new Aff(CONS, step, attempts, interrupt);
} else {
attempts = new Aff(CONS, step, new Aff(CONS, new Aff(RESUME, bhead, btail), attempts, interrupt), interrupt);
}
bhead = null;
btail = null;
status = CONTINUE;
step = step._1;
break;
// Enqueue the Bracket so that we can call the appropriate handlers
// after resource acquisition.
case BRACKET:
bracketCount++;
if (bhead === null) {
attempts = new Aff(CONS, step, attempts, interrupt);
} else {
attempts = new Aff(CONS, step, new Aff(CONS, new Aff(RESUME, bhead, btail), attempts, interrupt), interrupt);
}
bhead = null;
btail = null;
status = CONTINUE;
step = step._1;
break;
case FORK:
status = STEP_RESULT;
tmp = Fiber(util, supervisor, step._2);
if (supervisor) {
supervisor.register(tmp);
}
if (step._1) {
tmp.run();
}
step = util.right(tmp);
break;
case SEQ:
status = CONTINUE;
step = sequential(util, supervisor, step._1);
break;
}
break;
case RETURN:
bhead = null;
btail = null;
// If the current stack has returned, and we have no other stacks to
// resume or finalizers to run, the fiber has halted and we can
// invoke all join callbacks. Otherwise we need to resume.
if (attempts === null) {
status = COMPLETED;
step = interrupt || fail || step;
} else {
// The interrupt status for the enqueued item.
tmp = attempts._3;
attempt = attempts._1;
attempts = attempts._2;
switch (attempt.tag) {
// We cannot recover from an unmasked interrupt. Otherwise we should
// continue stepping, or run the exception handler if an exception
// was raised.
case CATCH:
// We should compare the interrupt status as well because we
// only want it to apply if there has been an interrupt since
// enqueuing the catch.
if (interrupt && interrupt !== tmp && bracketCount === 0) {
status = RETURN;
} else if (fail) {
status = CONTINUE;
step = attempt._2(util.fromLeft(fail));
fail = null;
}
break;
// We cannot resume from an unmasked interrupt or exception.
case RESUME:
// As with Catch, we only want to ignore in the case of an
// interrupt since enqueing the item.
if (interrupt && interrupt !== tmp && bracketCount === 0 || fail) {
status = RETURN;
} else {
bhead = attempt._1;
btail = attempt._2;
status = STEP_BIND;
step = util.fromRight(step);
}
break;
// If we have a bracket, we should enqueue the handlers,
// and continue with the success branch only if the fiber has
// not been interrupted. If the bracket acquisition failed, we
// should not run either.
case BRACKET:
bracketCount--;
if (fail === null) {
result = util.fromRight(step);
// We need to enqueue the Release with the same interrupt
// status as the Bracket that is initiating it.
attempts = new Aff(CONS, new Aff(RELEASE, attempt._2, result), attempts, tmp);
// We should only coninue as long as the interrupt status has not changed or
// we are currently within a non-interruptable finalizer.
if (interrupt === tmp || bracketCount > 0) {
status = CONTINUE;
step = attempt._3(result);
}
}
break;
// Enqueue the appropriate handler. We increase the bracket count
// because it should not be cancelled.
case RELEASE:
attempts = new Aff(CONS, new Aff(FINALIZED, step, fail), attempts, interrupt);
status = CONTINUE;
// It has only been killed if the interrupt status has changed
// since we enqueued the item, and the bracket count is 0. If the
// bracket count is non-zero then we are in a masked state so it's
// impossible to be killed.
if (interrupt && interrupt !== tmp && bracketCount === 0) {
step = attempt._1.killed(util.fromLeft(interrupt))(attempt._2);
} else if (fail) {
step = attempt._1.failed(util.fromLeft(fail))(attempt._2);
} else {
step = attempt._1.completed(util.fromRight(step))(attempt._2);
}
fail = null;
bracketCount++;
break;
case FINALIZER:
bracketCount++;
attempts = new Aff(CONS, new Aff(FINALIZED, step, fail), attempts, interrupt);
status = CONTINUE;
step = attempt._1;
break;
case FINALIZED:
bracketCount--;
status = RETURN;
step = attempt._1;
fail = attempt._2;
break;
}
}
break;
case COMPLETED:
for (var k in joins) {
if (joins.hasOwnProperty(k)) {
rethrow = rethrow && joins[k].rethrow;
runEff(joins[k].handler(step));
}
}
joins = null;
// If we have an interrupt and a fail, then the thread threw while
// running finalizers. This should always rethrow in a fresh stack.
if (interrupt && fail) {
setTimeout(function () {
throw util.fromLeft(fail);
}, 0);
// If we have an unhandled exception, and no other fiber has joined
// then we need to throw the exception in a fresh stack.
} else if (util.isLeft(step) && rethrow) {
setTimeout(function () {
// Guard on reathrow because a completely synchronous fiber can
// still have an observer which was added after-the-fact.
if (rethrow) {
throw util.fromLeft(step);
}
}, 0);
}
return;
case SUSPENDED:
status = CONTINUE;
break;
case PENDING: return;
}
}
}
function onComplete(join) {
return function () {
if (status === COMPLETED) {
rethrow = rethrow && join.rethrow;
join.handler(step)();
return function () {};
}
var jid = joinId++;
joins = joins || {};
joins[jid] = join;
return function() {
if (joins !== null) {
delete joins[jid];
}
};
};
}
function kill(error, cb) {
return function () {
if (status === COMPLETED) {
cb(util.right(void 0))();
return function () {};
}
var canceler = onComplete({
rethrow: false,
handler: function (/* unused */) {
return cb(util.right(void 0));
}
})();
switch (status) {
case SUSPENDED:
interrupt = util.left(error);
status = COMPLETED;
step = interrupt;
run(runTick);
break;
case PENDING:
if (interrupt === null) {
interrupt = util.left(error);
}
if (bracketCount === 0) {
if (status === PENDING) {
attempts = new Aff(CONS, new Aff(FINALIZER, step(error)), attempts, interrupt);
}
status = RETURN;
step = null;
fail = null;
run(++runTick);
}
break;
default:
if (interrupt === null) {
interrupt = util.left(error);
}
if (bracketCount === 0) {
status = RETURN;
step = null;
fail = null;
}
}
return canceler;
};
}
function join(cb) {
return function () {
var canceler = onComplete({
rethrow: false,
handler: cb
})();
if (status === SUSPENDED) {
run(runTick);
}
return canceler;
};
}
return {
kill: kill,
join: join,
onComplete: onComplete,
isSuspended: function () {
return status === SUSPENDED;
},
run: function () {
if (status === SUSPENDED) {
if (!Scheduler.isDraining()) {
Scheduler.enqueue(function () {
run(runTick);
});
} else {
run(runTick);
}
}
}
};
}
function runPar(util, supervisor, par, cb) {
// Table of all forked fibers.
var fiberId = 0;
var fibers = {};
// Table of currently running cancelers, as a product of `Alt` behavior.
var killId = 0;
var kills = {};
// Error used for early cancelation on Alt branches.
var early = new Error("[ParAff] Early exit");
// Error used to kill the entire tree.
var interrupt = null;
// The root pointer of the tree.
var root = EMPTY;
// Walks a tree, invoking all the cancelers. Returns the table of pending
// cancellation fibers.
function kill(error, par, cb) {
var step = par;
var head = null;
var tail = null;
var count = 0;
var kills = {};
var tmp, kid;
loop: while (true) {
tmp = null;
switch (step.tag) {
case FORKED:
if (step._3 === EMPTY) {
tmp = fibers[step._1];
kills[count++] = tmp.kill(error, function (result) {
return function () {
count--;
if (count === 0) {
cb(result)();
}
};
});
}
// Terminal case.
if (head === null) {
break loop;
}
// Go down the right side of the tree.
step = head._2;
if (tail === null) {
head = null;
} else {
head = tail._1;
tail = tail._2;
}
break;
case MAP:
step = step._2;
break;
case APPLY:
case ALT:
if (head) {
tail = new Aff(CONS, head, tail);
}
head = step;
step = step._1;
break;
}
}
if (count === 0) {
cb(util.right(void 0))();
} else {
// Run the cancelation effects. We alias `count` because it's mutable.
kid = 0;
tmp = count;
for (; kid < tmp; kid++) {
kills[kid] = kills[kid]();
}
}
return kills;
}
// When a fiber resolves, we need to bubble back up the tree with the
// result, computing the applicative nodes.
function join(result, head, tail) {
var fail, step, lhs, rhs, tmp, kid;
if (util.isLeft(result)) {
fail = result;
step = null;
} else {
step = result;
fail = null;
}
loop: while (true) {
lhs = null;
rhs = null;
tmp = null;
kid = null;
// We should never continue if the entire tree has been interrupted.
if (interrupt !== null) {
return;
}
// We've made it all the way to the root of the tree, which means
// the tree has fully evaluated.
if (head === null) {
cb(fail || step)();
return;
}
// The tree has already been computed, so we shouldn't try to do it
// again. This should never happen.
// TODO: Remove this?
if (head._3 !== EMPTY) {
return;
}
switch (head.tag) {
case MAP:
if (fail === null) {
head._3 = util.right(head._1(util.fromRight(step)));
step = head._3;
} else {
head._3 = fail;
}
break;
case APPLY:
lhs = head._1._3;
rhs = head._2._3;
// If we have a failure we should kill the other side because we
// can't possible yield a result anymore.
if (fail) {
head._3 = fail;
tmp = true;
kid = killId++;
kills[kid] = kill(early, fail === lhs ? head._2 : head._1, function (/* unused */) {
return function () {
delete kills[kid];
if (tmp) {
tmp = false;
} else if (tail === null) {
join(fail, null, null);
} else {
join(fail, tail._1, tail._2);
}
};
});
if (tmp) {
tmp = false;
return;
}
} else if (lhs === EMPTY || rhs === EMPTY) {
// We can only proceed if both sides have resolved.
return;
} else {
step = util.right(util.fromRight(lhs)(util.fromRight(rhs)));
head._3 = step;
}
break;
case ALT:
lhs = head._1._3;
rhs = head._2._3;
// We can only proceed if both have resolved or we have a success
if (lhs === EMPTY && util.isLeft(rhs) || rhs === EMPTY && util.isLeft(lhs)) {
return;
}
// If both sides resolve with an error, we should continue with the
// first error
if (lhs !== EMPTY && util.isLeft(lhs) && rhs !== EMPTY && util.isLeft(rhs)) {
fail = step === lhs ? rhs : lhs;
step = null;
head._3 = fail;
} else {
head._3 = step;
tmp = true;
kid = killId++;
// Once a side has resolved, we need to cancel the side that is still
// pending before we can continue.
kills[kid] = kill(early, step === lhs ? head._2 : head._1, function (/* unused */) {
return function () {
delete kills[kid];
if (tmp) {
tmp = false;
} else if (tail === null) {
join(step, null, null);
} else {
join(step, tail._1, tail._2);
}
};
});
if (tmp) {
tmp = false;
return;
}
}
break;
}
if (tail === null) {
head = null;
} else {
head = tail._1;
tail = tail._2;
}
}
}
function resolve(fiber) {
return function (result) {
return function () {
delete fibers[fiber._1];
fiber._3 = result;
join(result, fiber._2._1, fiber._2._2);
};
};
}
// Walks the applicative tree, substituting non-applicative nodes with
// `FORKED` nodes. In this tree, all applicative nodes use the `_3` slot
// as a mutable slot for memoization. In an unresolved state, the `_3`
// slot is `EMPTY`. In the cases of `ALT` and `APPLY`, we always walk
// the left side first, because both operations are left-associative. As
// we `RETURN` from those branches, we then walk the right side.
function run() {
var status = CONTINUE;
var step = par;
var head = null;
var tail = null;
var tmp, fid;
loop: while (true) {
tmp = null;
fid = null;
switch (status) {
case CONTINUE:
switch (step.tag) {
case MAP:
if (head) {
tail = new Aff(CONS, head, tail);
}
head = new Aff(MAP, step._1, EMPTY, EMPTY);
step = step._2;
break;
case APPLY:
if (head) {
tail = new Aff(CONS, head, tail);
}
head = new Aff(APPLY, EMPTY, step._2, EMPTY);
step = step._1;
break;
case ALT:
if (head) {
tail = new Aff(CONS, head, tail);
}
head = new Aff(ALT, EMPTY, step._2, EMPTY);
step = step._1;
break;
default:
// When we hit a leaf value, we suspend the stack in the `FORKED`.
// When the fiber resolves, it can bubble back up the tree.
fid = fiberId++;
status = RETURN;
tmp = step;
step = new Aff(FORKED, fid, new Aff(CONS, head, tail), EMPTY);
tmp = Fiber(util, supervisor, tmp);
tmp.onComplete({
rethrow: false,
handler: resolve(step)
})();
fibers[fid] = tmp;
if (supervisor) {
supervisor.register(tmp);
}
}
break;
case RETURN:
// Terminal case, we are back at the root.
if (head === null) {
break loop;
}
// If we are done with the right side, we need to continue down the
// left. Otherwise we should continue up the stack.
if (head._1 === EMPTY) {
head._1 = step;
status = CONTINUE;
step = head._2;
head._2 = EMPTY;
} else {
head._2 = step;
step = head;
if (tail === null) {
head = null;
} else {
head = tail._1;
tail = tail._2;
}
}
}
}
// Keep a reference to the tree root so it can be cancelled.
root = step;
for (fid = 0; fid < fiberId; fid++) {
fibers[fid].run();
}
}
// Cancels the entire tree. If there are already subtrees being canceled,
// we need to first cancel those joins. We will then add fresh joins for
// all pending branches including those that were in the process of being
// canceled.
function cancel(error, cb) {
interrupt = util.left(error);
var innerKills;
for (var kid in kills) {
if (kills.hasOwnProperty(kid)) {
innerKills = kills[kid];
for (kid in innerKills) {
if (innerKills.hasOwnProperty(kid)) {
innerKills[kid]();
}
}
}
}
kills = null;
var newKills = kill(error, root, cb);
return function (killError) {
return new Aff(ASYNC, function (killCb) {
return function () {
for (var kid in newKills) {
if (newKills.hasOwnProperty(kid)) {
newKills[kid]();
}
}
return nonCanceler;
};
});
};
}
run();
return function (killError) {
return new Aff(ASYNC, function (killCb) {
return function () {
return cancel(killError, killCb);
};
});
};
}
function sequential(util, supervisor, par) {
return new Aff(ASYNC, function (cb) {
return function () {
return runPar(util, supervisor, par, cb);
};
});
}
Aff.EMPTY = EMPTY;
Aff.Pure = AffCtr(PURE);
Aff.Throw = AffCtr(THROW);
Aff.Catch = AffCtr(CATCH);
Aff.Sync = AffCtr(SYNC);
Aff.Async = AffCtr(ASYNC);
Aff.Bind = AffCtr(BIND);
Aff.Bracket = AffCtr(BRACKET);
Aff.Fork = AffCtr(FORK);
Aff.Seq = AffCtr(SEQ);
Aff.ParMap = AffCtr(MAP);
Aff.ParApply = AffCtr(APPLY);
Aff.ParAlt = AffCtr(ALT);
Aff.Fiber = Fiber;
Aff.Supervisor = Supervisor;
Aff.Scheduler = Scheduler;
Aff.nonCanceler = nonCanceler;
return Aff;
}();
exports._pure = Aff.Pure;
exports._throwError = Aff.Throw;
exports._catchError = function (aff) {
return function (k) {
return Aff.Catch(aff, k);
};
};
exports._map = function (f) {
return function (aff) {
if (aff.tag === Aff.Pure.tag) {
return Aff.Pure(f(aff._1));
} else {
return Aff.Bind(aff, function (value) {
return Aff.Pure(f(value));
});
}
};
};
exports._bind = function (aff) {
return function (k) {
return Aff.Bind(aff, k);
};
};
exports._liftEffect = Aff.Sync;
exports._parAffMap = function (f) {
return function (aff) {
return Aff.ParMap(f, aff);
};
};
exports._parAffApply = function (aff1) {
return function (aff2) {
return Aff.ParApply(aff1, aff2);
};
};
exports.makeAff = Aff.Async;
exports._makeFiber = function (util, aff) {
return function () {
return Aff.Fiber(util, null, aff);
};
};
exports._sequential = Aff.Seq;
})(PS["Effect.Aff"] = PS["Effect.Aff"] || {});
(function($PS) {
// Generated by purs version 0.14.1
"use strict";
$PS["Effect.Class"] = $PS["Effect.Class"] || {};
var exports = $PS["Effect.Class"];
var MonadEffect = function (Monad0, liftEffect) {
this.Monad0 = Monad0;
this.liftEffect = liftEffect;
};
var liftEffect = function (dict) {
return dict.liftEffect;
};
exports["liftEffect"] = liftEffect;
exports["MonadEffect"] = MonadEffect;
})(PS);
(function(exports) {
"use strict";
// module Partial.Unsafe
exports._unsafePartial = function (f) {
return f();
};
})(PS["Partial.Unsafe"] = PS["Partial.Unsafe"] || {});
(function(exports) {
"use strict";
// module Partial
exports._crashWith = function (msg) {
throw new Error(msg);
};
})(PS["Partial"] = PS["Partial"] || {});
(function($PS) {
// Generated by purs version 0.14.1
"use strict";
$PS["Partial"] = $PS["Partial"] || {};
var exports = $PS["Partial"];
var $foreign = $PS["Partial"];
var crashWith = function (dictPartial) {
return $foreign["_crashWith"];
};
exports["crashWith"] = crashWith;
})(PS);
(function($PS) {
// Generated by purs version 0.14.1
"use strict";
$PS["Partial.Unsafe"] = $PS["Partial.Unsafe"] || {};
var exports = $PS["Partial.Unsafe"];
var $foreign = $PS["Partial.Unsafe"];
var Partial = $PS["Partial"];
var unsafePartial = $foreign["_unsafePartial"];
var unsafeCrashWith = function (msg) {
return unsafePartial(function (dictPartial) {
return Partial.crashWith()(msg);
});
};
exports["unsafeCrashWith"] = unsafeCrashWith;
})(PS);
(function($PS) {
// Generated by purs version 0.14.1
"use strict";
$PS["Effect.Aff"] = $PS["Effect.Aff"] || {};
var exports = $PS["Effect.Aff"];
var $foreign = $PS["Effect.Aff"];
var Control_Applicative = $PS["Control.Applicative"];
var Control_Apply = $PS["Control.Apply"];
var Control_Bind = $PS["Control.Bind"];
var Control_Monad = $PS["Control.Monad"];
var Control_Monad_Error_Class = $PS["Control.Monad.Error.Class"];
var Control_Parallel = $PS["Control.Parallel"];
var Control_Parallel_Class = $PS["Control.Parallel.Class"];
var Data_Either = $PS["Data.Either"];
var Data_Foldable = $PS["Data.Foldable"];
var Data_Function = $PS["Data.Function"];
var Data_Functor = $PS["Data.Functor"];
var Data_Monoid = $PS["Data.Monoid"];
var Data_Semigroup = $PS["Data.Semigroup"];
var Data_Unit = $PS["Data.Unit"];
var Effect = $PS["Effect"];
var Effect_Class = $PS["Effect.Class"];
var Partial_Unsafe = $PS["Partial.Unsafe"];
var Unsafe_Coerce = $PS["Unsafe.Coerce"];
var functorParAff = new Data_Functor.Functor($foreign["_parAffMap"]);
var functorAff = new Data_Functor.Functor($foreign["_map"]);
var ffiUtil = (function () {
var unsafeFromRight = function (v) {
if (v instanceof Data_Either.Right) {
return v.value0;
};
if (v instanceof Data_Either.Left) {
return Partial_Unsafe.unsafeCrashWith("unsafeFromRight: Left");
};
throw new Error("Failed pattern match at Effect.Aff (line 404, column 21 - line 406, column 54): " + [ v.constructor.name ]);
};
var unsafeFromLeft = function (v) {
if (v instanceof Data_Either.Left) {
return v.value0;
};
if (v instanceof Data_Either.Right) {
return Partial_Unsafe.unsafeCrashWith("unsafeFromLeft: Right");
};
throw new Error("Failed pattern match at Effect.Aff (line 399, column 20 - line 401, column 54): " + [ v.constructor.name ]);
};
var isLeft = function (v) {
if (v instanceof Data_Either.Left) {
return true;
};
if (v instanceof Data_Either.Right) {
return false;
};
throw new Error("Failed pattern match at Effect.Aff (line 394, column 12 - line 396, column 20): " + [ v.constructor.name ]);
};
return {
isLeft: isLeft,
fromLeft: unsafeFromLeft,
fromRight: unsafeFromRight,
left: Data_Either.Left.create,
right: Data_Either.Right.create
};
})();
var makeFiber = function (aff) {
return $foreign["_makeFiber"](ffiUtil, aff);
};
var launchAff = function (aff) {
return function __do() {
var fiber = makeFiber(aff)();
fiber.run();
return fiber;
};
};
var launchAff_ = (function () {
var $40 = Data_Functor["void"](Effect.functorEffect);
return function ($41) {
return $40(launchAff($41));
};
})();
var applyParAff = new Control_Apply.Apply(function () {
return functorParAff;
}, $foreign["_parAffApply"]);
var monadAff = new Control_Monad.Monad(function () {
return applicativeAff;
}, function () {
return bindAff;
});
var bindAff = new Control_Bind.Bind(function () {
return applyAff;
}, $foreign["_bind"]);
var applyAff = new Control_Apply.Apply(function () {
return functorAff;
}, Control_Monad.ap(monadAff));
var applicativeAff = new Control_Applicative.Applicative(function () {
return applyAff;
}, $foreign["_pure"]);
var monadEffectAff = new Effect_Class.MonadEffect(function () {
return monadAff;
}, $foreign["_liftEffect"]);
var monadThrowAff = new Control_Monad_Error_Class.MonadThrow(function () {
return monadAff;
}, $foreign["_throwError"]);
var monadErrorAff = new Control_Monad_Error_Class.MonadError(function () {
return monadThrowAff;
}, $foreign["_catchError"]);
var runAff = function (k) {
return function (aff) {
return launchAff(Control_Bind.bindFlipped(bindAff)((function () {
var $46 = Effect_Class.liftEffect(monadEffectAff);
return function ($47) {
return $46(k($47));
};
})())(Control_Monad_Error_Class["try"](monadErrorAff)(aff)));
};
};
var runAff_ = function (k) {
return function (aff) {
return Data_Functor["void"](Effect.functorEffect)(runAff(k)(aff));
};
};
var parallelAff = new Control_Parallel_Class.Parallel(function () {
return applicativeParAff;
}, function () {
return monadAff;
}, Unsafe_Coerce.unsafeCoerce, $foreign["_sequential"]);
var applicativeParAff = new Control_Applicative.Applicative(function () {
return applyParAff;
}, (function () {
var $50 = Control_Parallel_Class.parallel(parallelAff);
var $51 = Control_Applicative.pure(applicativeAff);
return function ($52) {
return $50($51($52));
};
})());
var semigroupCanceler = new Data_Semigroup.Semigroup(function (v) {
return function (v1) {
return function (err) {
return Control_Parallel.parSequence_(parallelAff)(Data_Foldable.foldableArray)([ v(err), v1(err) ]);
};
};
});
var nonCanceler = Data_Function["const"](Control_Applicative.pure(applicativeAff)(Data_Unit.unit));
var monoidCanceler = new Data_Monoid.Monoid(function () {
return semigroupCanceler;
}, nonCanceler);
exports["launchAff_"] = launchAff_;
exports["runAff_"] = runAff_;
exports["applicativeAff"] = applicativeAff;
exports["bindAff"] = bindAff;
exports["monadEffectAff"] = monadEffectAff;
exports["monoidCanceler"] = monoidCanceler;
exports["makeAff"] = $foreign.makeAff;
})(PS);
(function(exports) {
"use strict";
exports.error = function (msg) {
return new Error(msg);
};
})(PS["Effect.Exception"] = PS["Effect.Exception"] || {});
(function($PS) {
// Generated by purs version 0.14.1
"use strict";
$PS["Effect.Exception"] = $PS["Effect.Exception"] || {};
var exports = $PS["Effect.Exception"];
var $foreign = $PS["Effect.Exception"];
exports["error"] = $foreign.error;
})(PS);
(function(exports) {
"use strict";
exports.tagOf = function (value) {
return Object.prototype.toString.call(value).slice(8, -1);
};
})(PS["Foreign"] = PS["Foreign"] || {});
(function($PS) {
// Generated by purs version 0.14.1
"use strict";
$PS["Data.Boolean"] = $PS["Data.Boolean"] || {};
var exports = $PS["Data.Boolean"];
var otherwise = true;
exports["otherwise"] = otherwise;
})(PS);
(function($PS) {
// Generated by purs version 0.14.1
"use strict";
$PS["Data.List.NonEmpty"] = $PS["Data.List.NonEmpty"] || {};
var exports = $PS["Data.List.NonEmpty"];
var Data_List_Types = $PS["Data.List.Types"];
var Data_NonEmpty = $PS["Data.NonEmpty"];
var singleton = (function () {
var $172 = Data_NonEmpty.singleton(Data_List_Types.plusList);
return function ($173) {
return Data_List_Types.NonEmptyList($172($173));
};
})();
exports["singleton"] = singleton;
})(PS);
(function($PS) {
// Generated by purs version 0.14.1
"use strict";
$PS["Foreign"] = $PS["Foreign"] || {};
var exports = $PS["Foreign"];
var $foreign = $PS["Foreign"];
var Control_Applicative = $PS["Control.Applicative"];
var Control_Monad_Error_Class = $PS["Control.Monad.Error.Class"];
var Control_Monad_Except_Trans = $PS["Control.Monad.Except.Trans"];
var Data_Boolean = $PS["Data.Boolean"];
var Data_List_NonEmpty = $PS["Data.List.NonEmpty"];
var Unsafe_Coerce = $PS["Unsafe.Coerce"];
var TypeMismatch = (function () {
function TypeMismatch(value0, value1) {
this.value0 = value0;
this.value1 = value1;
};
TypeMismatch.create = function (value0) {
return function (value1) {
return new TypeMismatch(value0, value1);
};
};
return TypeMismatch;
})();
var unsafeFromForeign = Unsafe_Coerce.unsafeCoerce;
var fail = function (dictMonad) {
var $118 = Control_Monad_Error_Class.throwError(Control_Monad_Except_Trans.monadThrowExceptT(dictMonad));
return function ($119) {
return $118(Data_List_NonEmpty.singleton($119));
};
};
var unsafeReadTagged = function (dictMonad) {
return function (tag) {
return function (value) {
if ($foreign.tagOf(value) === tag) {
return Control_Applicative.pure(Control_Monad_Except_Trans.applicativeExceptT(dictMonad))(unsafeFromForeign(value));
};
if (Data_Boolean.otherwise) {
return fail(dictMonad)(new TypeMismatch(tag, $foreign.tagOf(value)));
};
throw new Error("Failed pattern match at Foreign (line 110, column 1 - line 110, column 71): " + [ tag.constructor.name, value.constructor.name ]);
};
};
};
var readString = function (dictMonad) {
return unsafeReadTagged(dictMonad)("String");
};
exports["unsafeReadTagged"] = unsafeReadTagged;
exports["readString"] = readString;
})(PS);
(function($PS) {
// Generated by purs version 0.14.1
"use strict";
$PS["Control.Promise"] = $PS["Control.Promise"] || {};
var exports = $PS["Control.Promise"];
var $foreign = $PS["Control.Promise"];
var Control_Alt = $PS["Control.Alt"];
var Control_Bind = $PS["Control.Bind"];
var Control_Category = $PS["Control.Category"];
var Control_Monad_Except = $PS["Control.Monad.Except"];
var Control_Monad_Except_Trans = $PS["Control.Monad.Except.Trans"];
var Data_Either = $PS["Data.Either"];
var Data_Functor = $PS["Data.Functor"];
var Data_Identity = $PS["Data.Identity"];
var Data_List_Types = $PS["Data.List.Types"];
var Data_Monoid = $PS["Data.Monoid"];
var Effect = $PS["Effect"];
var Effect_Aff = $PS["Effect.Aff"];
var Effect_Class = $PS["Effect.Class"];
var Effect_Exception = $PS["Effect.Exception"];
var Foreign = $PS["Foreign"];
var toAff$prime = function (customCoerce) {
return function (p) {
return Effect_Aff.makeAff(function (cb) {
return Data_Functor.voidRight(Effect.functorEffect)(Data_Monoid.mempty(Effect_Aff.monoidCanceler))($foreign.thenImpl(p)(function ($1) {
return cb(Data_Either.Left.create(customCoerce($1)))();
})(function ($2) {
return cb(Data_Either.Right.create($2))();
}));
});
};
};
var fromAff = function (aff) {
return $foreign.promise(function (succ) {
return function (err) {
return Effect_Aff.runAff_(Data_Either.either(err)(succ))(aff);
};
});
};
var coerce = function (fn) {
return Data_Either.either(function (v) {
return Effect_Exception.error("Promise failed, couldn't extract JS Error or String");
})(Control_Category.identity(Control_Category.categoryFn))(Control_Monad_Except.runExcept(Control_Alt.alt(Control_Monad_Except_Trans.altExceptT(Data_List_Types.semigroupNonEmptyList)(Data_Identity.monadIdentity))(Foreign.unsafeReadTagged(Data_Identity.monadIdentity)("Error")(fn))(Data_Functor.map(Control_Monad_Except_Trans.functorExceptT(Data_Identity.functorIdentity))(Effect_Exception.error)(Foreign.readString(Data_Identity.monadIdentity)(fn)))));
};
var toAff = toAff$prime(coerce);
var toAffE = function (f) {
return Control_Bind.bind(Effect_Aff.bindAff)(Effect_Class.liftEffect(Effect_Aff.monadEffectAff)(f))(toAff);
};
exports["fromAff"] = fromAff;
exports["toAffE"] = toAffE;
})(PS);
(function(exports) {
"use strict";
exports.now = function () {
return Date.now();
};
})(PS["Effect.Now"] = PS["Effect.Now"] || {});
(function($PS) {
// Generated by purs version 0.14.1
"use strict";
$PS["Effect.Now"] = $PS["Effect.Now"] || {};
var exports = $PS["Effect.Now"];
var $foreign = $PS["Effect.Now"];
exports["now"] = $foreign.now;
})(PS);
(function(exports) {
"use strict";
exports.mkEffectFn1 = function mkEffectFn1(fn) {
return function(x) {
return fn(x)();
};
};
})(PS["Effect.Uncurried"] = PS["Effect.Uncurried"] || {});
(function($PS) {
// Generated by purs version 0.14.1
"use strict";
$PS["Effect.Uncurried"] = $PS["Effect.Uncurried"] || {};
var exports = $PS["Effect.Uncurried"];
var $foreign = $PS["Effect.Uncurried"];
exports["mkEffectFn1"] = $foreign.mkEffectFn1;
})(PS);
(function(exports) {
"use strict";
exports.pure_promise_1 = function(func) {
return function(a) {
return function() {
return func(a);
};
};
};
})(PS["Main"] = PS["Main"] || {});
(function($PS) {
// Generated by purs version 0.14.1
"use strict";
$PS["Main"] = $PS["Main"] || {};
var exports = $PS["Main"];
var $foreign = $PS["Main"];
var Control_Applicative = $PS["Control.Applicative"];
var Control_Bind = $PS["Control.Bind"];
var Control_Promise = $PS["Control.Promise"];
var Data_Unit = $PS["Data.Unit"];
var Effect_Aff = $PS["Effect.Aff"];
var Effect_Class = $PS["Effect.Class"];
var Effect_Now = $PS["Effect.Now"];
var Effect_Uncurried = $PS["Effect.Uncurried"];
var main$prime = function (js_module) {
var tprint = function (input) {
return Effect_Class.liftEffect(Effect_Aff.monadEffectAff)(function __do() {
js_module.tprint(input);
return Data_Unit.unit;
});
};
var sleep = (function () {
var $0 = $foreign.pure_promise_1(js_module.sleep);
return function ($1) {
return Control_Promise.toAffE($0($1));
};
})();
return Control_Promise.fromAff(Effect_Class.liftEffect(Effect_Aff.monadEffectAff)(Effect_Aff.launchAff_((function () {
var sleep2000 = sleep(2000);
return Control_Bind.discard(Control_Bind.discardUnit)(Effect_Aff.bindAff)(Control_Bind.bind(Effect_Aff.bindAff)(Effect_Class.liftEffect(Effect_Aff.monadEffectAff)(Effect_Now.now))(tprint))(function () {
return Control_Bind.discard(Control_Bind.discardUnit)(Effect_Aff.bindAff)(sleep2000)(function () {
return Control_Bind.discard(Control_Bind.discardUnit)(Effect_Aff.bindAff)(Control_Bind.bind(Effect_Aff.bindAff)(Effect_Class.liftEffect(Effect_Aff.monadEffectAff)(Effect_Now.now))(tprint))(function () {
return Control_Bind.discard(Control_Bind.discardUnit)(Effect_Aff.bindAff)(sleep2000)(function () {
return Control_Bind.discard(Control_Bind.discardUnit)(Effect_Aff.bindAff)(Control_Bind.bind(Effect_Aff.bindAff)(Effect_Class.liftEffect(Effect_Aff.monadEffectAff)(Effect_Now.now))(tprint))(function () {
return Control_Bind.discard(Control_Bind.discardUnit)(Effect_Aff.bindAff)(tprint(js_module.scan()))(function () {
return Control_Applicative.pure(Effect_Aff.applicativeAff)(Data_Unit.unit);
});
});
});
});
});
});
})())));
};
var main = Effect_Uncurried.mkEffectFn1(main$prime);
exports["main"] = main;
})(PS);
PS["Main"].main();
"use strict";
exports.pure_promise_1 = function(func) {
return function(a) {
return function() {
return func(a);
};
};
};
module Main (main) where
import Prelude (Unit, discard, pure, unit, ($), (>>=), (<<<))
import Effect (Effect)
import Effect.Aff (Aff, launchAff_)
import Data.Function.Uncurried (Fn0, runFn0)
import Effect.Uncurried (EffectFn1, mkEffectFn1, runEffectFn1)
import Control.Promise (Promise, fromAff, toAffE)
import Effect.Class (liftEffect)
import Effect.Now (now)
foreign import pure_promise_1 :: forall a b. (b -> Promise a) -> b -> Effect (Promise a)
type JSModule = {
tprint :: forall a. EffectFn1 a Unit,
scan :: Fn0 (Array String),
sleep :: Int -> Promise Unit
}
main' :: JSModule -> Effect (Promise Unit)
main' js_module = let
sleep :: Int -> Aff Unit
sleep =
toAffE <<< pure_promise_1 js_module.sleep
tprint :: forall a. a -> Aff Unit
tprint input =
liftEffect $ do
runEffectFn1 js_module.tprint input
pure unit in
-- End of definitions, start of procedures.
fromAff $ liftEffect $ launchAff_ do
let sleep' = sleep 2000
liftEffect now >>= tprint
sleep'
liftEffect now >>= tprint
sleep'
liftEffect now >>= tprint
tprint $ runFn0 js_module.scan
pure unit
main :: EffectFn1 JSModule (Promise Unit)
main = mkEffectFn1 main'
const a = {
tprint: console.log,
scan: () => ["foo", "bar", "baz"],
sleep: duration_ms => new Promise(resolve => setTimeout(resolve, duration_ms)),
};
const makeRuntimeErrorMsg = function(caller, msg) {
return "";
};
const setTimeoutRef = window.setTimeout.bind(window);
function netscriptDelay(time, workerScript) {
return new Promise(function(resolve) {
workerScript.delay = setTimeoutRef(() => {
workerScript.delay = null;
resolve();
}, time);
workerScript.delayResolve = resolve;
});
}
const workerScript = {
log: (func, txt) => console.log(`${func}: ${txt}`),
delay: null,
delayResolve: () => null
};
const b = {
tprint: console.log,
scan: () => ["foo", "bar", "baz"],
sleep: function(time){
if (time === undefined) {
throw makeRuntimeErrorMsg("sleep", "Takes 1 argument.");
}
workerScript.log("sleep", `Sleeping for ${time} milliseconds`);
return netscriptDelay(time, workerScript).then(function() {
return Promise.resolve(true);
});
},
};
let upstream =
https://github.com/purescript/package-sets/releases/download/psc-0.14.1-20210516/packages.dhall sha256:f5e978371d4cdc4b916add9011021509c8d869f4c3f6d0d2694c0e03a85046c8
in upstream
{ name = "bitburner_scripts"
, dependencies =
[ "aff"
, "aff-promise"
, "console"
, "effect"
, "functions"
, "now"
, "prelude"
, "psci-support"
]
, packages = ./packages.dhall
, sources = [ "src/**/*.purs", "test/**/*.purs" ]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment