From 6cf3c70a4418d2a297c39df4bc684ea31c51c7f5 Mon Sep 17 00:00:00 2001 From: Joscha Date: Sun, 12 Nov 2017 23:36:21 +0000 Subject: [PATCH] Make Expression an instance of Eq typeclass --- lambda.hs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lambda.hs b/lambda.hs index 5f477c2..be6b033 100644 --- a/lambda.hs +++ b/lambda.hs @@ -33,8 +33,12 @@ instance (Show s) => Show (Expression s) where show_ c (ELambda s e@(EExpr _ _)) = "\\" ++ s ++ ".(" ++ show_ (s : c) e ++ ")" show_ c (ELambda s e) = "\\" ++ s ++ "." ++ show_ (s : c) e -instance (Eq s) => Eq (Expression s) where - -- TODO: Implement this +instance Eq (Expression s) where + (ESymbol _) == (ESymbol _) = True + (EReference a) == (EReference b) = a == b + (EExpr a b) == (EExpr c d) = a == c && b == d + (ELambda _ a) == (ELambda _ b) = a == b + _ == _ = False insertExpr :: Expression s -> Expression s -> Expression s insertExpr = insert_ 0