Recusion patterns

runCodeInner : ProgState -> ProgState
runCodeInner step =
    case step of
        Running state ->
            let
                tmp =
                    doStep state
            in
            runCodeInner tmp

        --Running state ->
        --    state
        --        |> doStep
        --        |> runCodeInner
        --
        _ ->
            step

This snippet is from my Advent of Code work. My original code was the commented out part and I was getting a stack overflow. I had reached a question where there were warnings that things could take a while on slow computers, so I had a feeling that the issue was my recursion pattern.

I’m not an expert in ‘tail recursion’ but I thought the original code was tail recursive? It seems not, but that my alternative is and completed quickly. Something to do with evaluating it to tmp then I guess?

There’s clearly something I can learn here about how recursion works in Elm and would welcome feedback on that.

This is a change with the desugaring of |> in 0.19. Previously, this happened early on, now it happens after tail-recursion is recognized.

Tail-recursive statements now have to look like f x y z. The seemingly equivalent z |> f x y is not recognized as tail-recursive.

Just like @folkertdev said. An issue was raised in the compiler, which you can read here: https://github.com/elm/compiler/issues/1770

Yikes - this feels like a real gotcha at the heart of Elm. Thanks for pointing me to the issue