memory management - Why don't purely functional languages use reference counting? -


In functional languages ​​only, the data is irreversible, with reference calculations, changing the data already created to create a reference cycle It seems that it seems that the use of reference calculations without worrying about the possibility of fully functional language cycle. What is right? If so, why do not they?

I understand that in many cases the reference count is slower than GC, but at least it reduces break time. It would be good to have the option of using reference calculations in such cases where there are bad times at breaks.

Your question is based on a faulty assumption, circular references and irreversible data are entirely possible. Consider the example # which uses irreversible data to create a circular reference.

  class node {public readonly node other; Public node () {other = new node (this); } Public node (node ​​node) {other = node; }}  

This type of move can be done in many functional languages ​​and therefore any collection mechanism should deal with the possibility of circular references. I am not saying that a reg counting system is impossible with a circular reference, just to be dealt with it.

edited by

In response to the comment ... it is trivial in Haskell

  Data node a = node {Other :: node A} RecursiveNode = node {other = recursiveNode}  

and more effort than difficult in SML.

  datatype 'node = node of the unit - & gt; A node val recursive node: unit node = funny mkRecursiveNode () = noct mkRecursiveNode in mkRecursiveNode () end  

No changes are necessary.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -