[Haskell-cafe] Is (==) commutative?

Twan van Laarhoven twanvl at gmail.com
Tue Jul 24 14:49:30 CEST 2012

On 24/07/12 14:39, Jonas Almström Duregård wrote:
> Hi,
> I suppose you need to define what commutativity means in the presence
> of undefined values. For instance if error "0" is different from error
> "1" then you do not have commutativity. Also nontermination needs to
> be considered, for instance "(fix $ \x->x) == undefined" typically
> fails to terminate but "undefined == (fix $ \x->x)" typically yields
> an error.
> Regards,
> Jonas

In the usual Haskell semantics, all bottoms are considered to be the same. In 
other words, there is only one. You could implement this by setting undefined to 
nontermination, and error _ = undefined. In fact, the Haskell report does 
exactly this. Any error messages you get are only visible in IO land, where 
anything can happen anyway.

So  _|_ == x  = _|_  holds for (almost) all types, except perhaps for (). Though 
in practice also  undefined == () = undefined.


More information about the Haskell-Cafe mailing list