From a5fe5b9378937a35fa7921c6ed62ec9efa059934 Mon Sep 17 00:00:00 2001 From: Krasimir Angelov Date: Tue, 5 Sep 2017 09:46:43 +0200 Subject: [PATCH] added exprHash in the Haskell binding --- src/runtime/haskell-bind/PGF2.hsc | 10 ++++++++++ src/runtime/haskell-bind/PGF2/FFI.hs | 3 +++ 2 files changed, 13 insertions(+) diff --git a/src/runtime/haskell-bind/PGF2.hsc b/src/runtime/haskell-bind/PGF2.hsc index 037145ee6..f2f1b4113 100644 --- a/src/runtime/haskell-bind/PGF2.hsc +++ b/src/runtime/haskell-bind/PGF2.hsc @@ -39,6 +39,7 @@ module PGF2 (-- * PGF mkFloat,unFloat, mkMeta,unMeta, mkCId, + exprHash, treeProbability, -- ** Types @@ -323,6 +324,15 @@ treeProbability (PGF p _) (Expr c_expr touch1) = touch1 return (realToFrac res) +exprHash :: Int32 -> Expr -> Int32 +exprHash h (Expr c_expr touch1) = + unsafePerformIO $ do + h <- pgf_expr_hash (fromIntegral h) c_expr + touch1 + return (fromIntegral h) + + + ----------------------------------------------------------------------------- -- Graphviz diff --git a/src/runtime/haskell-bind/PGF2/FFI.hs b/src/runtime/haskell-bind/PGF2/FFI.hs index 3870e2fba..ce4dd6983 100644 --- a/src/runtime/haskell-bind/PGF2/FFI.hs +++ b/src/runtime/haskell-bind/PGF2/FFI.hs @@ -328,6 +328,9 @@ foreign import ccall "pgf/expr.h pgf_expr_arity" foreign import ccall "pgf/expr.h pgf_expr_eq" pgf_expr_eq :: PgfExpr -> PgfExpr -> IO CInt +foreign import ccall "pgf/expr.h pgf_expr_hash" + pgf_expr_hash :: Word -> PgfExpr -> IO Word + foreign import ccall "pgf/expr.h pgf_compute_tree_probability" pgf_compute_tree_probability :: Ptr PgfPGF -> PgfExpr -> IO CFloat