For this function on symmetric equality over tuples,
symEq :: Eq a => (a,a) -> (a,a) -> Bool
symEq (x,y) (u,v) = (x,y) == (u,v) || (x,y) == (v,u)
With the ViewPatterns
you can achieve something that resembles the Erlang and Prolog pattern matching style:
{-# LANGUAGE ViewPatterns #-}
swap (a,b) = (b,a)
symEq :: Eq a => (a,a) -> (a,a) -> Bool
symEq a ((==a) -> True) = True
symEq a ((==a).swap -> True) = True
symEq _ _ = False
Note how the a
in (==a)
refers to the first function argument - bound names of earlier function parameters may be used in the view patterns of later parameters.
More details on ViewPatterns may be found here.