-
Notifications
You must be signed in to change notification settings - Fork 24
Open
Labels
purs-0.15A reminder to address this issue or merge this PR before we release PureScript v0.15.0A reminder to address this issue or merge this PR before we release PureScript v0.15.0type: breaking changeA change that requires a major version bump.A change that requires a major version bump.
Description
Originally reported here.
There's an unexpected call to Control_Monad_ST_Internal.modify
in the JS output of the following function:
simulate :: Number -> Number -> Int -> Number
simulate x0 v0 time =
run do
ref <- new { x: x0, v: v0 }
for 0 (time * 1000) \_ ->
modify
( \o ->
{ v: o.v - 9.81 * 0.001
, x: o.x + o.v * 0.001
}
)
ref
final <- read ref
pure final.x
var ref = { value: { x: x0, v: v0 } };
Control_Monad_ST_Internal["for"](0)(time * 1000 | 0)(function (v) {
return Control_Monad_ST_Internal.modify(function (o) {
return {
v: o.v - 9.81 * 1.0e-3,
x: o.x + o.v * 1.0e-3
};
})(ref);
})();
The original version of the book shows a more optimized JS output that does not make a call to modify
:
var ref = { x: x0, v: v0 };
Control_Monad_Eff.forE(0)(time * 1000 | 0)(function (i) {
return function __do() {
ref = (function (o) {
return {
v: o.v - 9.81 * 1.0e-3,
x: o.x + o.v * 1.0e-3
};
})(ref);
return Prelude.unit;
};
})();
return ref.x;
deni64k and nythrox
Metadata
Metadata
Assignees
Labels
purs-0.15A reminder to address this issue or merge this PR before we release PureScript v0.15.0A reminder to address this issue or merge this PR before we release PureScript v0.15.0type: breaking changeA change that requires a major version bump.A change that requires a major version bump.