Zuletzt geändert: Mo, 24.04.2006

«K12/K13» EqClass.hs «PDF», «POD»



Download
module EqClass where

data EqClass a = EqClass a deriving (Show)

instance (Eq t) => Eq (EqClass t) where
  (EqClass a) == (EqClass b) = a == b

instance (Ord t) => Ord (EqClass t) where
  (EqClass a) <= (EqClass b) = a <= b

instance (Num t) => Num (EqClass t) where
  (+) = op2 (+)
  (-) = op2 (-)
  (*) = op2 (*)
  abs         = op1 abs
  signum      = op1 signum
  negate      = op1 negate
  fromInteger = EqClass . fromInteger

op1 :: (a -> b) -> EqClass a -> EqClass b
op1 f (EqClass m) = EqClass $ f m

op2 :: (a -> b -> c) -> EqClass a -> EqClass b -> EqClass c
op2 f (EqClass m) (EqClass n) = EqClass $ f m n