All functional values are equal, but some are more equal than others ![]()
As other responders have mentioned, function equality is not in general decidable. You can of course try to check approximate equality using property-based testing techniques where you evaluate it at a range of randomly generated arguments.
For the theoretically inclined, this leads to a recognition that even within what functional programming calls “values”, there is an important sub-distinction:
-
Values that do not contain any lambdas can be compared for structural equality. They correlate to so-called “Normal Form” in lambda calculus.
-
Values containing uninvoked/unreduced lambdas cannot. They remain unresolved, not yet fully evaluated. In lambda calculus, they require “beta reduction” to normal form, although that isn’t guaranteed to be possible (since it involves supplying parameters to uninvoked functions.)
Values in set 2 can’t readily support assertEqual(a, b) on in unit tests, so the distinction has practical ramifications. Perhaps this use-case is where your question originated? It was for me.