My expected result as follows:
*Main> unify [Var "x",Var "x"] [Obj "a", Obj "a"] NoBindings
Bindings fromList [("x",a)]
However, this results in the following error:
Not in scope: data constructor H.HashMap
My code is as follows:
import qualified Data.List as L
import qualified Data.HashMap.Strict as H
import qualified Data.HashSet as S
data Pattern = Var String
| GVar Int
| Obj String
| Funct String [Pattern]
| Prim String
deriving Eq
data Bindings = Fail
| NoBindings
| Bindings (H.HashMap String Pattern)
deriving Show
unify :: [Pattern] -> [Pattern] ->Bindings -> Bindings
unify _ _ Fail = Fail
unify [Var x,Var x1] [Obj a,Obj a1] NoBindings
| x==x1 = Bindings (H.HashMap x a)
| otherwise = error $show x1
Alex
8,3617 gold badges54 silver badges80 bronze badges
asked Apr 26, 2014 at 21:53
1 Answer 1
The Data.HashMap.Strict
module exposes the data type HashMap
, but doesn't export its data constructors. It exports the empty
and singleton
functions instead:
empty :: HashMap k v
singleton :: (Hashable k) => k -> v -> HashMap k v
The latter can be used in your case:
unify [Var x,Var x1] [Obj a,Obj a1] NoBindings
| x==x1 = Bindings (H.singleton x a)
| otherwise = error $show x1
answered Apr 26, 2014 at 22:08
Sign up to request clarification or add additional context in comments.
Comments
lang-hs