import Prelude hiding (Rational) data Rational = Rat Integer Integer deriving Show -- Rat n d represents number n / d -- task: basic arithmetic timesRational, plusRational :: Rational -> Rational -> Rational timesRational (Rat n1 d1) (Rat n2 d2) = normalizeRat (Rat (n1 * n2) (d1 * d2)) plusRational (Rat n1 d1) (Rat n2 d2) = normalizeRat (Rat (n1 * d2 + n2 * d1) (d1 * d2)) normalizeRat :: Rational -> Rational normalizeRat (Rat n d) = let g = gcd n d n1 = n `div` g d1 = d `div` g in if d1 > 0 then Rat n1 d1 else if d1 == 0 then error "div by 0" else Rat (- n1) (- d1) negateRational, inverseRational :: Rational -> Rational negateRational = undefined inverseRational = undefined -- (==) :: Rational -> Rational -> Bool createRational :: Integer -> Integer -> Rational createRational = undefined