Don't like ads? PRO users don't see any ads ;-)
Guest

complejos...

By: a guest on Mar 20th, 2012  |  syntax: Haskell  |  size: 0.51 KB  |  hits: 37  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.  
  2. module Main (main) where
  3.  
  4.  
  5. import System.Environment
  6.  
  7.  
  8. data Complex = Complex (Int, Int)
  9.  
  10.  
  11. instance Show Complex where
  12.   show a = "(" ++ show (pairFst a) ++ ", " ++ show (pairSnd a) ++ ")"
  13.  
  14. instance Eq Complex where
  15.   x == y = (pairFst x == pairFst y) && (pairSnd y == pairSnd x)
  16.  
  17.  
  18. pairFst :: Complex -> Int
  19. pairFst (Pair (a, b)) = a
  20.  
  21. pairSnd :: Complex -> Int
  22. pairSnd (Pair (a, b)) = b
  23.  
  24.  
  25. main :: IO ()
  26. main = let a = Pair (1, 1)
  27.            b = Pair (1, 1)
  28.            in putStrLn $ show $ a == b