/ Published in: Java
Haskell uses static dispatch for overloaded methods, in addition it has an extension to write rules that optimize Haskell dispatching code.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
-- Enabling the extension {-# OPTIONS -fglasgow-exts #-} -- Equal like class class MEEq a where (=-=) :: a -> a -> Bool -- Instances with no implementation instance MEEq () instance MEEq Bool instance MEEq Int -- The rewrite rule {-# RULES "eq/Bool" (=-=) = eq_Bool :: Bool -> Bool -> Bool "eq/Unit" (=-=) = eq_Unit :: () -> () -> Bool #-} main = do print $ True =-= False print $ () =-= () -- This fails (at runtime!) since we didn't define a rule for it print $ 7 =-= (8 :: Int) -- Makes sure to fail any instance that doesn't have an implementation on compile time {-# RULES "Unable to resolve instance resolution" (=-=) = (=-=) #-}