Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> I mean that it's not even so well defined mathematically.

Which part of it isn't? The distinction between "potentially non-terminating" and its negation is exactly the distinction between partial and total functions.



The definition of pure function (or, dually, side effect) is difficult to pin down. I've heard a number of definitions, but the best ones are far more technical than you'd see in casual conversation and the casual ones often admit holes.


> I've heard a number of definitions, but the best ones are far more technical than you'd see in casual conversation

To be sure, but there's a big difference between casual definitions being subtly wrong and:

> I mean that it's not even so well defined mathematically.

Most mathematical definitions, at least the interesting ones, aren't really suitable for casual conversation!


Right, so I think where we're disagreeing is that the casual ones are subtly wrong. I think they're often pretty significantly wrong and that this post was essentially poking into that notion. When purity gets on the table lots of divergent ideas tend to be tossed out to nail it down and a lot of confusion results.

The best casual definition I know of is "a pure function, f, is one such that all variation in the function's result arises from variation in its input and that all information from the function's call is contained in its result: throwing the result away is equivalent to having never called the function"

A bit of a mouthful, but it's intuitive and arises from a formal definition that works out pretty nicely. Otoh, it's complex enough that it's rarely used in its complete form. Finally, it's still subtle enough that it can lead to questions about what side effects are exactly (non-termination is an immediate example).

Anyway, I just want to continue to suggest that understanding pure functions, really, is a more difficult task than people make it out to be.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

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

Search: