summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKrasimir Angelov <kr.angelov@gmail.com>2017-09-04 14:49:44 +0200
committerKrasimir Angelov <kr.angelov@gmail.com>2017-09-04 14:49:44 +0200
commit71c4b4a24640a0bc593527660bda16f61e729cc0 (patch)
tree150fa28ece964fc139df06a1b492358bf17b8324 /src
parentda091824a38c789b875156b89382c9f44debdc18 (diff)
instance Eq Expr in the Haskell binding
Diffstat (limited to 'src')
-rw-r--r--src/runtime/c/pgf/expr.c2
-rw-r--r--src/runtime/c/pgf/expr.h2
-rw-r--r--src/runtime/haskell-bind/PGF2/Expr.hsc7
3 files changed, 9 insertions, 2 deletions
diff --git a/src/runtime/c/pgf/expr.c b/src/runtime/c/pgf/expr.c
index 4e9f5ca89..f9fcd1442 100644
--- a/src/runtime/c/pgf/expr.c
+++ b/src/runtime/c/pgf/expr.c
@@ -1037,7 +1037,7 @@ pgf_literal_eq(PgfLiteral lit1, PgfLiteral lit2)
return false;
}
-PGF_API bool
+PGF_API int
pgf_expr_eq(PgfExpr e1, PgfExpr e2)
{
GuVariantInfo ei1 = gu_variant_open(e1);
diff --git a/src/runtime/c/pgf/expr.h b/src/runtime/c/pgf/expr.h
index e28db7f31..6492f8d18 100644
--- a/src/runtime/c/pgf/expr.h
+++ b/src/runtime/c/pgf/expr.h
@@ -185,7 +185,7 @@ pgf_read_type(GuIn* in, GuPool* pool, GuExn* err);
PGF_API_DECL bool
pgf_literal_eq(PgfLiteral lit1, PgfLiteral lit2);
-PGF_API_DECL bool
+PGF_API_DECL int
pgf_expr_eq(PgfExpr e1, PgfExpr e2);
PGF_API_DECL bool
diff --git a/src/runtime/haskell-bind/PGF2/Expr.hsc b/src/runtime/haskell-bind/PGF2/Expr.hsc
index af3afeef5..a03a24be3 100644
--- a/src/runtime/haskell-bind/PGF2/Expr.hsc
+++ b/src/runtime/haskell-bind/PGF2/Expr.hsc
@@ -34,6 +34,13 @@ data Expr = Expr {expr :: PgfExpr, touchExpr :: Touch}
instance Show Expr where
show = showExpr []
+instance Eq Expr where
+ (Expr e1 e1_touch) == (Expr e2 e2_touch) =
+ unsafePerformIO $ do
+ res <- pgf_expr_eq e1 e2
+ e1_touch >> e2_touch
+ return (res /= 0)
+
-- | Constructs an expression by lambda abstraction
mkAbs :: BindType -> CId -> Expr -> Expr
mkAbs bind_type var (Expr body bodyTouch) =