I have derived a statement (theorem?) that puzzles me. I wonder if my logic is sound.
Any commutative non-strict function
f :: a -> a -> b
is a constant.
Commutativity is understood including the bottoms, i.e. f x y
and f y x
either both terminate, or both don't.
My informal reasoning is as follows. Suppose f
is a non-strict function. Then there exists a
such that either f a ⊥
or f ⊥ a
terminate. If f
is commutative, then both should terminate. But then f
cannot scrutinise either of its arguments. (If it scrutinises the first argument first, then f ⊥ a
must be ⊥
, and vice versa). So it must be a constant function.
Is this reasoning correct?
It clearly fails if f
is allowed to scrutinise both arguments at the same time and succeed if either one is not a ⊥
. But are such functions allowed in (some reasonably conservative extension of) Haskell?