Hacker News new | past | comments | ask | show | jobs | submit login

"A referentially-transparent function will always give the same result for a given input. But we can’t say this about functions that throw exceptions. At any moment, they might throw an exception instead of returning a value."

That's the premise of the article and it is demonstrably false. You throw exceptions in a reproducible manner based on input, not a RNG!




Imagine a signature like this:

function oneDividedByX(x: Double): Double

oneDividedByX(2) // 1/2

oneDividedByX(3) // 1/3

and so on.. Except with zero. With zero you get an exception, however nothing in function signature mentions about such result. You only expect a double

In Either case - it solves the problem, because the signature would be like this:

function oneDividedByX(x: Double): Either[ComputingError, Double]

As for throwing exceptions - it can be done in pure way, but catching exceptions cannot


Yup. Pretty sure the most referentially transparent function will stop if you unplug the power.




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: