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.