-- http://cgi.cse.unsw.edu.au/~dons/blog/2008/05/12 -- http://www.haskell.org/ghc/docs/latest/html/users_guide/rewrite-rules.html -- Required to enable the rewrite rules {-# OPTIONS_GHC -fglasgow-exts -O #-} -- Don't like the warnings {-# OPTIONS_GHC -w #-} -- For debugging, we can -ddump-rules, and -ddump-simpl-stats {-# RULES "rule1" (=-=) = eq_Bool :: Bool -> Bool -> Bool "rule2" (=-=) = eq_Unit :: () -> () -> Bool "bad" (=-=) = (=-=) #-} class MEEq a where (=-=) :: a -> a -> Bool instance MEEq () instance MEEq Bool instance MEEq Int eq_Bool :: Bool -> Bool -> Bool eq_Bool True True = True eq_Bool False False = True eq_Bool _ _ = False eq_Unit :: () -> () -> Bool eq_Unit () () = True main = do print $ True =-= False print $ () =-= () -- print $ 7 =-= (8 :: Int) -- INFINITE compile-time loop