De-orphan the Eq/Ord Char instances
authorIan Lynagh <igloo@earth.li>
Mon, 23 Nov 2009 20:22:53 +0000 (20:22 +0000)
committerIan Lynagh <igloo@earth.li>
Mon, 23 Nov 2009 20:22:53 +0000 (20:22 +0000)
GHC/Base.lhs
GHC/Classes.hs

index c1db364..52d1252 100644 (file)
@@ -468,20 +468,6 @@ by Unicode, use 'Prelude.toEnum' and 'Prelude.fromEnum' from the
 'Prelude.Enum' class respectively (or equivalently 'ord' and 'chr').
 -}
 
--- We don't use deriving for Eq and Ord, because for Ord the derived
--- instance defines only compare, which takes two primops.  Then
--- '>' uses compare, and therefore takes two primops instead of one.
-
-instance Eq Char where
-    (C# c1) == (C# c2) = c1 `eqChar#` c2
-    (C# c1) /= (C# c2) = c1 `neChar#` c2
-
-instance Ord Char where
-    (C# c1) >  (C# c2) = c1 `gtChar#` c2
-    (C# c1) >= (C# c2) = c1 `geChar#` c2
-    (C# c1) <= (C# c2) = c1 `leChar#` c2
-    (C# c1) <  (C# c2) = c1 `ltChar#` c2
-
 {-# RULES
 "x# `eqChar#` x#" forall x#. x# `eqChar#` x# = True
 "x# `neChar#` x#" forall x#. x# `neChar#` x# = False
index d1c18af..af810fb 100644 (file)
@@ -21,6 +21,8 @@ import GHC.Bool
 -- GHC.Magic is used in some derived instances
 import GHC.Magic ()
 import GHC.Ordering
+import GHC.Prim
+import GHC.Types
 
 infix  4  ==, /=, <, <=, >=, >
 infixr 3  &&
@@ -61,6 +63,10 @@ instance Eq Ordering where
     GT == GT = True
     _  == _  = False
 
+instance Eq Char where
+    (C# c1) == (C# c2) = c1 `eqChar#` c2
+    (C# c1) /= (C# c2) = c1 `neChar#` c2
+
 -- | The 'Ord' class is used for totally ordered datatypes.
 --
 -- Instances of 'Ord' can be derived for any user-defined
@@ -113,6 +119,15 @@ instance Ord Ordering where
     _  <= EQ = False
     GT <= GT = True
 
+-- We don't use deriving for Ord Char, because for Ord the derived
+-- instance defines only compare, which takes two primops.  Then
+-- '>' uses compare, and therefore takes two primops instead of one.
+instance Ord Char where
+    (C# c1) >  (C# c2) = c1 `gtChar#` c2
+    (C# c1) >= (C# c2) = c1 `geChar#` c2
+    (C# c1) <= (C# c2) = c1 `leChar#` c2
+    (C# c1) <  (C# c2) = c1 `ltChar#` c2
+
 -- OK, so they're technically not part of a class...:
 
 -- Boolean functions