The compiler misses an opportunity for tail-call optimization when the self call happens inside a case clause guarded with assign (<-) expression.
Compile module
module Test where
fixPokemonHp :: Int -> Int
fixPokemonHp x = case x of
n | _ <- n -> fixPokemonHp x
_ -> fixPokemonHp x
Produce some tail recursive code
// Generated by purs version 0.13.8
"use strict";
var fixPokemonHp = function (x) {
var v = function (v1) {
return fixPokemonHp(x);
};
return fixPokemonHp(x);
};
module.exports = {
fixPokemonHp: fixPokemonHp
};
btw I am using Arch Linux
Add any other context about the problem here.
0.13.8
Same thing for
fixPokemonHp :: Int -> Int
fixPokemonHp x = case x of
n | n == n && true -> fixPokemonHp x
_ -> fixPokemonHp x
(works)
fixPokemonHp :: Int -> Int
fixPokemonHp x = case x of
n | n == n, true -> fixPokemonHp x
_ -> fixPokemonHp x
(does not)
Context:
Together with @radrow we are working on an Erlang to Purescript transpiler - we rely on tail recursion heavily.
https://github.com/gorbak25/erlscripten
Most helpful comment
Context:
Together with @radrow we are working on an Erlang to Purescript transpiler - we rely on tail recursion heavily.
https://github.com/gorbak25/erlscripten