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

timothyhobbs at seznam.cz timothyhobbs at seznam.cz
Tue Jul 24 14:44:25 CEST 2012


There's always this, for ALL types a :(  So even where you would think that 
the documentation can claim that a given Eq instance follows the law of 
commutativity, it really cannot.





Prelude Control.Concurrent System.IO.Unsafe> do m <- newEmptyMVar ;putMVar m
1 ; print $ (unsafePerformIO (do v <- takeMVar m; putMVar m 2; return v)) ==
(unsafePerformIO (do v <- takeMVar m; putMVar m 1 ; return v)) ; print $ 
(unsafePerformIO (do v <- takeMVar m; putMVar m 1; return v)) == 
(unsafePerformIO (do v <- takeMVar m; putMVar m 2 ; return v))
False
True


---------- Původní zpráva ----------
Od: Jonas Almström Duregård <jonas.duregard at chalmers.se>
Datum: 24. 7. 2012
Předmět: Re: [Haskell-cafe] Is (==) commutative?
"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

On 24 July 2012 10:10, Christian Sternagel <c.sternagel at gmail.com> wrote:
> Dear all,
>
> with respect to formal verification of Haskell code I was wondering 
whether
> (==) of the Eq class is intended to be commutative (for many classes such
> requirements are informally stated in their description, since Eq does not
> have such a statement, I'm asking here). Or are there any known cases 
where
> commutativity of (==) is violated (due to strictness issues)?
>
> cheers
>
> chris
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
(http://www.haskell.org/mailman/listinfo/haskell-cafe)

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe at haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
(http://www.haskell.org/mailman/listinfo/haskell-cafe)"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120724/b4b0f6c4/attachment.htm>


More information about the Haskell-Cafe mailing list