Skip to content

Instantly share code, notes, and snippets.

@5outh
Created August 15, 2012 22:37
Show Gist options
  • Save 5outh/3364345 to your computer and use it in GitHub Desktop.
Save 5outh/3364345 to your computer and use it in GitHub Desktop.
EqOrd
instance Eq Fraction where
(/=) f = not . (==) f
(==) f f' = (x == x') && (y == y')
where (Frac x y) = simplify f
(Frac x' y') = simplify f'
instance Ord Fraction where
compare (Frac a b) (Frac c d) = compare (a `quot` b) (c `quot` d)
(<) f = (==) LT . compare f
(>) f = (==) GT . compare f
(>=) f = not . (<) f
(<=) f = not . (>) f
max f f' = if f < f' then f' else f
min f f' = if f < f' then f else f'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment