News for hackers. Stuff that matters.
Re:Total Functional Programming (2004) [pdf] by nyrikki on Thursday March 07, 2024 @12:34PM (#39631845)
Very big difference between pure and total functions.

Pure functions are memoryless and deterministic.

Total functions are defined for all elements in its domain.

Square (x²) is a total function. Reciprocal (1/x) is not, since 0 is a real number, but has no reciprocal.

“Total” and “pure” are orthogonal concepts.

A pure functions that raises an error with the input 0/0 is not total, and you can have total functions that aren't pure.

Re:Total Functional Programming (2004) [pdf] by mrkeen on Thursday March 07, 2024 @01:29PM (#39632734)
> Total functions are defined for all elements in its domain.

Do you include "same-output-for-the-same-input" as part of defined?

Re:Total Functional Programming (2004) [pdf] by nyrikki on Thursday March 07, 2024 @04:06PM (#39634580)
In context of This paper, where they are talking about Total forms of pure functions, yes

But in general no.

I could say have a total function with an internal counter that adds 1 each time it was run.

That would still be a total function, but not pure.