[Haskell-cafe] commutativity

Patrick Browne patrick.browne at dit.ie
Sat Oct 30 06:55:48 EDT 2010

Below are two questions on commutative operations in Haskell.

infixl 5 `com`
com :: Int -> Int -> Int
x `com` y  = (x + y)
commutative com a b = (a `com` b) == (b`com`a)

-- 1 + 3 == 3 + 1
-- This gives true by virtue of the value of LHS and RHS being equal
after the plus operation

-- Question 1
-- commutative com 1 3
-- This also gives true. Is it because of commutative equation or
because of the plus operation?

-- Question 2
-- In Haskell can commutativity be specified as a property of infix

This message has been scanned for content and viruses by the DIT Information Services E-Mail Scanning Service, and is believed to be clean. http://www.dit.ie

More information about the Haskell-Cafe mailing list