@@ -38,7 +38,6 @@ import Control.Monad.Writer.Class (tell)
3838
3939import Language.PureScript.AST
4040import Language.PureScript.Errors
41−import Language.PureScript.Environment
4241import Language.PureScript.Names
4342import Language.PureScript.TypeChecker.Monad
4443import Language.PureScript.TypeChecker.Unify
@@ -50,8 +49,8 @@ import qualified Language.PureScript.Constants as C
5049-- Check that the current set of type class dictionaries entail the specified type class goal, and, if so,
5150-- return a type class dictionary reference.
5251--
53−entails :: Environment -> ModuleName -> M.Map (Maybe ModuleName) (M.Map (Qualified ProperName) (M.Map (Qualified Ident) TypeClassDictionaryInScope)) -> Constraint -> Check Expr
54−entails env moduleName context = solve
52+entails :: ModuleName -> M.Map (Maybe ModuleName) (M.Map (Qualified ProperName) (M.Map (Qualified Ident) TypeClassDictionaryInScope)) -> Constraint -> Check Expr
53+entails moduleName context = solve
5554 where
5655 forClassName :: Qualified ProperName -> [TypeClassDictionaryInScope]
5756 forClassName cn = findDicts cn Nothing ++ findDicts cn (Just moduleName)
@@ -70,7 +69,7 @@ entails env moduleName context = solve
7069 let instances = do
7170 tcd <- forClassName className'
7271 -- Make sure the type unifies with the type in the type instance definition
73− subst <- maybeToList . (>>= verifySubstitution) . fmap concat $ zipWithM (typeHeadsAreEqual moduleName env) tys' (tcdInstanceTypes tcd)
72+ subst <- maybeToList . (>>= verifySubstitution) . fmap concat $ zipWithM (typeHeadsAreEqual moduleName) tys' (tcdInstanceTypes tcd)
7473 return (subst, tcd)
7574 (subst, tcd) <- unique instances
7675 -- Solve any necessary subgoals
@@ -128,7 +127,7 @@ entails env moduleName context = solve
128127 verifySubstitution :: [(String, Type)] -> Maybe [(String, Type)]
129128 verifySubstitution subst = do
130129 let grps = groupBy ((==) `on` fst) . sortBy (compare `on` fst) $ subst
131− guard (all (pairwise (unifiesWith env) . map snd) grps)
130+ guard (all (pairwise unifiesWith . map snd) grps)
132131 return $ map head grps
133132
134133 valUndefined :: Expr
@@ -138,21 +137,21 @@ entails env moduleName context = solve
138137-- Check whether the type heads of two types are equal (for the purposes of type class dictionary lookup),
139138-- and return a substitution from type variables to types which makes the type heads unify.
140139--
141−typeHeadsAreEqual :: ModuleName -> Environment -> Type -> Type -> Maybe [(String, Type)]
142−typeHeadsAreEqual _ _ (Skolem _ s1 _) (Skolem _ s2 _) | s1 == s2 = Just []
143−typeHeadsAreEqual _ _ t (TypeVar v) = Just [(v, t)]
144−typeHeadsAreEqual _ _ (TypeConstructor c1) (TypeConstructor c2) | c1 == c2 = Just []
145−typeHeadsAreEqual m e (TypeApp h1 t1) (TypeApp h2 t2) = (++) <$> typeHeadsAreEqual m e h1 h2
146− <*> typeHeadsAreEqual m e t1 t2
147−typeHeadsAreEqual _ _ REmpty REmpty = Just []
148−typeHeadsAreEqual m e r1@(RCons _ _ _) r2@(RCons _ _ _) =
140+typeHeadsAreEqual :: ModuleName -> Type -> Type -> Maybe [(String, Type)]
141+typeHeadsAreEqual _ (Skolem _ s1 _) (Skolem _ s2 _) | s1 == s2 = Just []
142+typeHeadsAreEqual _ t (TypeVar v) = Just [(v, t)]
143+typeHeadsAreEqual _ (TypeConstructor c1) (TypeConstructor c2) | c1 == c2 = Just []
144+typeHeadsAreEqual m (TypeApp h1 t1) (TypeApp h2 t2) = (++) <$> typeHeadsAreEqual m h1 h2
145+ <*> typeHeadsAreEqual m t1 t2
146+typeHeadsAreEqual _ REmpty REmpty = Just []
147+typeHeadsAreEqual m r1@RCons{} r2@RCons{} =
149148 let (s1, r1') = rowToList r1
150149 (s2, r2') = rowToList r2
151150
152151 int = [ (t1, t2) | (name, t1) <- s1, (name', t2) <- s2, name == name' ]
153152 sd1 = [ (name, t1) | (name, t1) <- s1, name `notElem` map fst s2 ]
154153 sd2 = [ (name, t2) | (name, t2) <- s2, name `notElem` map fst s1 ]
155− in (++) <$> foldMap (\(t1, t2) -> typeHeadsAreEqual m e t1 t2) int
154+ in (++) <$> foldMap (uncurry (typeHeadsAreEqual m)) int
156155 <*> go sd1 r1' sd2 r2'
157156 where
158157 go :: [(String, Type)] -> Type -> [(String, Type)] -> Type -> Maybe [(String, Type)]
@@ -162,7 +161,7 @@ typeHeadsAreEqual m e r1@(RCons _ _ _) r2@(RCons _ _ _) =
162161 go [] (Skolem _ s1 _) [] (Skolem _ s2 _) | s1 == s2 = Just []
163162 go sd r [] (TypeVar v) = Just [(v, rowFromList (sd, r))]
164163 go _ _ _ _ = Nothing
165−typeHeadsAreEqual _ _ _ _ = Nothing
164+typeHeadsAreEqual _ _ _ = Nothing
166165
167166-- |
168167-- Check all values in a list pairwise match a predicate