Closed Eloitor closed 4 years ago
To elaborate, the current JS back-end evaluates all branches of a case
expression, because those are compiled to raw function applications (val(case_a, case_b, case_c, ...)
), which aren't evaluated lazily in JavaScript. This can be avoided by manually inserting + func : T
below the case
, as suggested on the documentation. A more long-term solution would be to make the JS compiler lazy, or to make -r
default to the upcoming Haskell compiler, which is lazy.
Formality was reworked entirely and the compiler is much smarter, but it still lacks laziness on cases. Must be added.
This has a recursive call inside each case
So, when compiled to JS, every case would recurse, being accidentally exponential.
A temporary solution: insert
+ toBrainFuck : List(Instruction) -> String
insidetoBrainFuck
, below the secondcase
. This will pass the recursive calls linearly to each branches, preventing this problem from happening. it is also a very good practice in general, interaction nets like that style.On the long term, we can make the JS compiler lazy by wrapping every value inside a
()=>...
closure