shithub: MicroHs

Download patch

ref: b79d312287d7e631dcd3588fc5aa1e24542c3fdd
parent: 88418242b481380a48f7100b7b1e3164f6366c97
author: Lennart Augustsson <lennart@augustsson.net>
date: Thu Nov 2 10:35:16 EDT 2023

More Eq

--- a/src/MicroHs/Desugar.hs
+++ b/src/MicroHs/Desugar.hs
@@ -346,7 +346,7 @@
       let
         idOf (p:_, _, _) = pConOf p
         idOf _ = impossible
-        grps = groupEq (on eqCon idOf) arms
+        grps = groupEq (on (==) idOf) arms
         oneGroup grp = S.do
           let
             (pat:_, _, _) : _ = grp
--- a/src/MicroHs/Exp.hs
+++ b/src/MicroHs/Exp.hs
@@ -16,7 +16,7 @@
 import Data.Char
 import Data.List
 import MicroHs.Ident
-import MicroHs.Expr(Lit(..), showLit, eqLit)
+import MicroHs.Expr(Lit(..), showLit)
 import Text.PrettyPrint.HughesPJ
 --Ximport Control.DeepSeq
 --Ximport Compat
@@ -62,7 +62,7 @@
   (==) (Var i1)    (Var i2)    = i1 == i2
   (==) (App f1 a1) (App f2 a2) = f1 == f2 && a1 == a2
   (==) (Lam i1 e1) (Lam i2 e2) = i1 == i2 && e1 == e2
-  (==) (Lit l1)    (Lit l2)    = eqLit l1 l2
+  (==) (Lit l1)    (Lit l2)    = l1 == l2
   (==) _           _           = False
 
 data MaybeApp = NotApp | IsApp Exp Exp
--- a/src/MicroHs/Expr.hs
+++ b/src/MicroHs/Expr.hs
@@ -7,7 +7,7 @@
   EDef(..), showEDefs,
   Expr(..), eLam, eEqns, showExpr,
   Listish(..),
-  Lit(..), showLit, eqLit,
+  Lit(..), showLit,
   EBind(..), showEBind, showEBinds,
   Eqn(..),
   EStmt(..),
@@ -23,7 +23,7 @@
   LHS,
   Constr(..), ConstrField,
   ConTyInfo,
-  Con(..), conIdent, conArity, eqCon, getSLocCon,
+  Con(..), conIdent, conArity, getSLocCon,
   tupleConstr, getTupleConstr,
   mkTupleSel,
   subst,
@@ -115,8 +115,7 @@
   = ConData ConTyInfo Ident
   | ConNew Ident
   | ConLit Lit
---  | ConTup Int
-  --Xderiving(Show, Eq)
+  --Xderiving(Show)
 
 data Listish
   = LList [Expr]
@@ -138,11 +137,11 @@
 conArity (ConNew _) = 1
 conArity (ConLit _) = 0
 
-eqCon :: Con -> Con -> Bool
-eqCon (ConData _ i) (ConData _ j) = i == j
-eqCon (ConNew    i) (ConNew    j) = i == j
-eqCon (ConLit    l) (ConLit    k) = eqLit   l k
-eqCon _             _             = False
+instance Eq Con where
+  (==) (ConData _ i) (ConData _ j) = i == j
+  (==) (ConNew    i) (ConNew    j) = i == j
+  (==) (ConLit    l) (ConLit    k) = l == k
+  (==) _             _             = False
 
 data Lit
   = LInt Int
@@ -151,16 +150,16 @@
   | LStr String
   | LPrim String
   | LForImp String
-  --Xderiving (Show, Eq)
+  --Xderiving (Show)
 --Winstance NFData Lit where rnf (LInt i) = rnf i; rnf (LDouble d) = rnf d; rnf (LChar c) = rnf c; rnf (LStr s) = rnf s; rnf (LPrim s) = rnf s; rnf (LForImp s) = rnf s
 
-eqLit :: Lit -> Lit -> Bool
-eqLit (LInt x)  (LInt  y) = x == y
-eqLit (LChar x) (LChar y) = x == y
-eqLit (LStr  x) (LStr  y) = x == y
-eqLit (LPrim x) (LPrim y) = x == y
-eqLit (LForImp x) (LForImp y) = x == y
-eqLit _         _         = False
+instance Eq Lit where
+  (==) (LInt x)  (LInt  y) = x == y
+  (==) (LChar x) (LChar y) = x == y
+  (==) (LStr  x) (LStr  y) = x == y
+  (==) (LPrim x) (LPrim y) = x == y
+  (==) (LForImp x) (LForImp y) = x == y
+  (==) _         _         = False
 
 type ECaseArm = (EPat, EAlts)
 
--