That's why Haskell people use state monads isn't it? There must be special GHC tricks to recognize that past state is no longer live so it can therefore compile to mutating the state object
@ionchy If you need efficiency, genuine state is always available. Also record fields can be marked mutable
@ionchy As far as I know State (from transformers) has no special magic. ST on the other hand does (it's basically a safe wrapper around IO), but they are designed for somewhat different things.
@ionchy Realistically the way allocations get optimized out is probably that ghc replaces e.g. a traversal over a state monad with plain tail recursion with unboxed arguments.
A Mastodon instance for programming language theorists and mathematicians. Or just anyone who wants to hang out.