From 8c1dbdd562bbc3e7c014d0561e8b7185a586b194 Mon Sep 17 00:00:00 2001 From: Ian Lynagh Date: Mon, 23 Nov 2009 21:56:35 +0000 Subject: [PATCH] De-orphan the Eq/Ord [a] instances --- GHC/Base.lhs | 18 ------------------ GHC/Classes.hs | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/GHC/Base.lhs b/GHC/Base.lhs index 52d1252..2093ab6 100644 --- a/GHC/Base.lhs +++ b/GHC/Base.lhs @@ -237,24 +237,6 @@ class Monad m where %********************************************************* \begin{code} --- do explicitly: deriving (Eq, Ord) --- to avoid weird names like con2tag_[]# - -instance (Eq a) => Eq [a] where - {-# SPECIALISE instance Eq [Char] #-} - [] == [] = True - (x:xs) == (y:ys) = x == y && xs == ys - _xs == _ys = False - -instance (Ord a) => Ord [a] where - {-# SPECIALISE instance Ord [Char] #-} - compare [] [] = EQ - compare [] (_:_) = LT - compare (_:_) [] = GT - compare (x:xs) (y:ys) = case compare x y of - EQ -> compare xs ys - other -> other - instance Functor [] where fmap = map diff --git a/GHC/Classes.hs b/GHC/Classes.hs index af810fb..4a639b9 100644 --- a/GHC/Classes.hs +++ b/GHC/Classes.hs @@ -45,6 +45,12 @@ class Eq a where x /= y = not (x == y) x == y = not (x /= y) +instance (Eq a) => Eq [a] where + {-# SPECIALISE instance Eq [Char] #-} + [] == [] = True + (x:xs) == (y:ys) = x == y && xs == ys + _xs == _ys = False + -- XXX This doesn't work: -- deriving instance Eq Bool -- : @@ -100,6 +106,15 @@ class (Eq a) => Ord a where max x y = if x <= y then y else x min x y = if x <= y then x else y +instance (Ord a) => Ord [a] where + {-# SPECIALISE instance Ord [Char] #-} + compare [] [] = EQ + compare [] (_:_) = LT + compare (_:_) [] = GT + compare (x:xs) (y:ys) = case compare x y of + EQ -> compare xs ys + other -> other + -- XXX This doesn't work: -- deriving instance Ord Bool -- : -- 1.7.10.4