module RationalHO
  ( Rat, makeRat, numer, denom, showRat,
    negRat, addRat, subRat, mulRat, divRat, eqRat )
where

import RationalCore
-- import RationalDeferGCD

-- First-order Operations

negRat :: Rat -> Rat 
negRat x = makeRat (- numer x) (denom x)

addRat, subRat, mulRat, divRat :: Rat -> Rat -> Rat 
addRat x y = makeRat (numer x * denom y + numer y * denom x) (denom x * denom y) 
subRat x y = makeRat (numer x * denom y - numer y * denom x) (denom x * denom y) 
mulRat x y = makeRat (numer x * numer y)                     (denom x * denom y) 
divRat x y = makeRat (numer x * denom y)                     (denom x * numer y) 

-- REDEFINED from Rational (first order version)
-- eqRat :: Rat -> Rat -> Bool 
-- eqRat x y = (numer x) * (denom y) == (numer y) * (denom x)      

-- ADDED to Rational
compareRat :: (Int -> Int -> Bool) -> Rat -> Rat -> Bool 
compareRat r x y = r (numer x * denom y) (denom x * numer y) 

eqRat,neqRat,ltRat,leqRat,gtRat,geqRat :: Rat -> Rat -> Bool 
eqRat   = compareRat (==) 
neqRat  = compareRat (/=) 
ltRat   = compareRat (<)  
leqRat  = compareRat (<=) 
gtRat   = compareRat (>)  
geqRat  = compareRat (>=)
