2

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

3

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.