When you update a record in OCaml does the object get reallocated

I think so. It wouldn't be clever enough to know that I no longer need the object anymore all the time and compile it to a mutation appropriately

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

Follow

@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.

Sign in to participate in the conversation
Cybrespace

cybrespace: the social hub of the information superhighway jack in to the mastodon fediverse today and surf the dataflow through our cybrepunk, slightly glitchy web portal support us on patreon or liberapay!