Arc Forumnew | comments | leaders | submitlogin
4 points by viergroupie 6139 days ago | link | parent

I imagine a conservative purity analyzer wouldn't be too difficult to write. Mark a set of primitives as pure. An expression is pure if it is composed of pure primitives or other pure expressions. If an FFI is involved, you'll probably have to manually annotate foreign functions as pure or impure. How does that sound?


4 points by Darmani 6139 days ago | link

A purity analyzer would need to be a little more complex than that - the "=" operator would be pure or impure depending on the scope of the location being set. The simple way to solve that would be to make locations created within any lexical context that is discarded with the completion of the function pure and those without impure, although they may be slightly complicated.

Of course, some situations, such as code that sets unset values in an outside hash table to the default value, may arguably be "pure" functional code, although dealing with such things is outside the domain of a "conservative" purity analyzer.

-----