This is Haskell's question, but I am also interested in answers to other languages. Is there a way to automatically translate purely functional code written to process lists or immutable arrays without any destructive updates, into code that uses mutable arrays for efficiency?
In Haskell, the generated code will either execute in the monad ST(in this case everything will be wrapped in runSTor runSTArray) or in the monad IO, I assume.
ST
runST
runSTArray
IO
What interests me most is the general solutions that work for any type of element.
I thought I saw it before, but I canโt remember where. If it does not exist yet, it would be interesting for me to create it.
Implementing a functional language using destructive updates is an optimization of memory management. If the old value is no longer used, it is safe to reuse the old memory to store the new values. Finding out that the value will no longer be used is a difficult problem, so reuse is still manual.
. , - . - , .
, SAC, . SAC ( , ), .
" ", , , , (, , ) .
, , : , , . ; , , . , , , , . , , , , , , .
Mutable , , , . Haskell accum Data.Array, , , ST.
accum
Data.Array
, , .
: , , , . , , - .