How to automatically convert clean code to code that uses volatile arrays for efficiency?

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.

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.

+5
source share
2 answers

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 ( , ), .

+4

" ", , , , (, , ) .

, , : , , . ; , , . , , , , . , , , , , , .

Mutable , , , . Haskell accum Data.Array, , , ST.

, , .

: , , , . , , - .

0

All Articles