shithub: MicroHs

Download patch

ref: 2aa587b57630793b669a34b5de365d81b97efe47
parent: c68f7b44d2527a78af7b5d661a9cddd253144ba9
author: Lennart Augustsson <lennart@augustsson.net>
date: Wed Nov 8 11:38:14 EST 2023

Use more primCompare

--- a/lib/Data/Char.hs
+++ b/lib/Data/Char.hs
@@ -22,6 +22,7 @@
   (/=) = primCharNE
 
 instance Ord Char where
+  compare = primCompare
   (<)  = primCharLT
   (<=) = primCharLE
   (>)  = primCharGT
@@ -35,7 +36,7 @@
   x <  y  =  primCompare x y == LT
   x <= y  =  primCompare x y /= GT
   x >  y  =  primCompare x y == GT
-  x >=  y =  primCompare x y /= GT
+  x >= y  =  primCompare x y /= LT
 
 -- ASCII only for now
 instance Bounded Char where
--- a/lib/Data/Int.hs
+++ b/lib/Data/Int.hs
@@ -47,6 +47,7 @@
   (/=) = primIntNE
 
 instance Ord Int where
+  compare = primCompare
   (<)  = primIntLT
   (<=) = primIntLE
   (>)  = primIntGT
--- a/lib/Primitives.hs
+++ b/lib/Primitives.hs
@@ -151,7 +151,8 @@
 --primEqual  :: forall a . a -> a -> Bool
 --primEqual  = primitive "equal"
 
-primCompare :: [Char] -> [Char] -> Ordering
+-- Works for Int, Char, String
+primCompare :: forall a . a -> a -> Ordering
 primCompare  = primitive "compare"
 
 primStringEQ  :: [Char] -> [Char] -> Bool
--