Simulating algebraic effects in JavaScript