我的预期结果如下:
*Main> unify [Var "x",Var "x"] [Obj "a", Obj "a"] NoBindings
Bindings fromList [("x",a)]但是,这会导致以下错误:
Not in scope: data constructor H.HashMap我的代码如下:
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发布于 2014-04-26 22:08:47
Data.HashMap.Strict模块公开数据类型HashMap,但不导出其数据构造函数。相反,它导出empty和singleton函数:
empty :: HashMap k v
singleton :: (Hashable k) => k -> v -> HashMap k v后者可用于您的情况:
unify [Var x,Var x1] [Obj a,Obj a1] NoBindings
| x==x1 = Bindings (H.singleton x a)
| otherwise = error $show x1https://stackoverflow.com/questions/23316914
复制相似问题