X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=GHC%2FClasses.hs;h=3e3e72f0b67fdd580485e9167ec1ee1ec9968b89;hb=3a8b769484788cb3874e9c695543712eb3330b7f;hp=c1532f29c5f99c1f3d58f5d64b229da5b8939eae;hpb=cf6637d9de1129c603950925a83237ed03116350;p=ghc-base.git diff --git a/GHC/Classes.hs b/GHC/Classes.hs index c1532f2..3e3e72f 100644 --- a/GHC/Classes.hs +++ b/GHC/Classes.hs @@ -20,6 +20,7 @@ module GHC.Classes where import GHC.Bool +import GHC.Integer -- GHC.Magic is used in some derived instances import GHC.Magic () import GHC.Ordering @@ -96,6 +97,16 @@ instance Eq Char where (C# c1) == (C# c2) = c1 `eqChar#` c2 (C# c1) /= (C# c2) = c1 `neChar#` c2 +instance Eq Integer where + (==) = eqInteger + (/=) = neqInteger + +instance Eq Float where + (F# x) == (F# y) = x `eqFloat#` y + +instance Eq Double where + (D# x) == (D# y) = x ==## y + -- | The 'Ord' class is used for totally ordered datatypes. -- -- Instances of 'Ord' can be derived for any user-defined @@ -184,6 +195,35 @@ instance Ord Char where (C# c1) <= (C# c2) = c1 `leChar#` c2 (C# c1) < (C# c2) = c1 `ltChar#` c2 +instance Ord Integer where + (<=) = leInteger + (>) = gtInteger + (<) = ltInteger + (>=) = geInteger + compare = compareInteger + +instance Ord Float where + (F# x) `compare` (F# y) + = if x `ltFloat#` y then LT + else if x `eqFloat#` y then EQ + else GT + + (F# x) < (F# y) = x `ltFloat#` y + (F# x) <= (F# y) = x `leFloat#` y + (F# x) >= (F# y) = x `geFloat#` y + (F# x) > (F# y) = x `gtFloat#` y + +instance Ord Double where + (D# x) `compare` (D# y) + = if x <## y then LT + else if x ==## y then EQ + else GT + + (D# x) < (D# y) = x <## y + (D# x) <= (D# y) = x <=## y + (D# x) >= (D# y) = x >=## y + (D# x) > (D# y) = x >## y + -- OK, so they're technically not part of a class...: -- Boolean functions