- About Scala
- In the Enterprise
- Scala Community
- Language Research
- In the Press
- The Scala Team
- Scala's Prehistory
- Contact Us
- Learning Scala
- Tour of Scala
- Scala API
- Setup & Getting Started
- Programming Guides
- Other Guides
- Code Examples
- Scala Developers
the scala purity test
Tue, 2011-10-04, 17:42
On Tue, Oct 4, 2011 at 9:28 AM, Adriaan Moors wrote:
>> a pure function that throws an exception
> ... is not a pure function -- at least not for the definition of "pure" that
> I'm? used to from the same book of definitions, throwing an exception is
> considered an effect (the throws clause in Java is actually part of a
> lightweight type and effect system)
Can we go to extempore's big book of questions asked via comments?
This arose in the course of fixing issues in the optimizer where
the -optimise compiled code behaved differently, leading back to
the assessment performed by the following method, which though it is
called "isPureExpr" seems to be testing something different than that
in your "big book of definitions."
/** Is tree a stable and pure expression?
* !!! Clarification on what is meant by "pure" here would be appreciated.
* This implementation allows both modules and lazy vals, which are pure in
* the sense that they always return the same result, but which are also
* side effecting. So for now, "pure" != "not side effecting".
def isPureExpr(tree: Tree): Boolean = ...
So, if purity means what you suggest (which is what my book of definitions
says too) this function is wrongly named. What is the right name? Is
it "isReferentiallyTransparent" or... ?