@@ -116,7 +116,7 @@ unifyTypes t1 t2 = rethrow (mkErrorStack ("Error unifying type " ++ prettyPrintT
116116 unifyTypes' (TypeApp t3 t4) (TypeApp t5 t6) = do
117117 t3 `unifyTypes` t5
118118 t4 `unifyTypes` t6
119− unifyTypes' (Skolem s1 _) (Skolem s2 _) | s1 == s2 = return ()
119+ unifyTypes' (Skolem _ s1 _) (Skolem _ s2 _) | s1 == s2 = return ()
120120 unifyTypes' r1@RCons{} r2 = unifyRows r1 r2
121121 unifyTypes' r1 r2@RCons{} = unifyRows r1 r2
122122 unifyTypes' r1@REmpty r2 = unifyRows r1 r2
@@ -155,7 +155,7 @@ unifyRows r1 r2 =
155155 unifyRows' row r others u'
156156 unifyRows' [] REmpty [] REmpty = return ()
157157 unifyRows' [] (TypeVar v1) [] (TypeVar v2) | v1 == v2 = return ()
158− unifyRows' [] (Skolem s1 _) [] (Skolem s2 _) | s1 == s2 = return ()
158+ unifyRows' [] (Skolem _ s1 _) [] (Skolem _ s2 _) | s1 == s2 = return ()
159159 unifyRows' sd3 r3 sd4 r4 = throwError . strMsg $ "Cannot unify (" ++ prettyPrintRow (rowFromList (sd3, r3)) ++ ") with (" ++ prettyPrintRow (rowFromList (sd4, r4)) ++ ")"
160160
161161-- |
@@ -333,7 +333,8 @@ entails env moduleName context = solve (sortedNubBy canonicalizeDictionary (filt
333333 -- Make sure the types unify with the types in the superclass implication
334334 , subst <- maybeToList . (>>= verifySubstitution) . fmap concat $ zipWithM (typeHeadsAreEqual moduleName env) tys' suTyArgs
335335 -- Finally, satisfy the subclass constraint
336− , suDict <- go trySuperclasses' subclassName (map (applySubst subst . TypeVar) args) ]
336+ , args' <- maybeToList $ mapM (applySubst subst . TypeVar) args
337+ , suDict <- go True subclassName args' ]
337338
338339 -- Create dictionaries for subgoals which still need to be solved by calling go recursively
339340 -- E.g. the goal (Show a, Show b) => Show (Either a b) can be satisfied if the current type
@@ -364,11 +365,11 @@ entails env moduleName context = solve (sortedNubBy canonicalizeDictionary (filt
364365 guard (all (pairwise (unifiesWith env) . map snd) grps)
365366 return $ map head grps
366367 -- Apply a substitution to a type
367− applySubst :: [(String, Type)] -> Type -> Type
368− applySubst subst = everywhere (mkT replace)
368+ applySubst :: [(String, Type)] -> Type -> Maybe Type
369+ applySubst subst = everywhereM (mkM replace)
369370 where
370− replace t@(TypeVar v) = fromMaybe t $ lookup v subst
371− replace other = other
371+ replace (TypeVar v) = lookup v subst
372+ replace other = Just other
372373 -- Choose the simplest DictionaryValues from a list of candidates
373374 -- The reason for this function is as follows:
374375 -- When considering overlapping instances, we don't want to consider the same dictionary
@@ -399,7 +400,7 @@ pairwise p (x : xs) = all (p x) xs && pairwise p xs
399400unifiesWith :: Environment -> Type -> Type -> Bool
400401unifiesWith _ (TUnknown _) _ = True
401402unifiesWith _ _ (TUnknown _) = True
402−unifiesWith _ (Skolem s1 _) (Skolem s2 _) | s1 == s2 = True
403+unifiesWith _ (Skolem _ s1 _) (Skolem _ s2 _) | s1 == s2 = True
403404unifiesWith _ (TypeVar v1) (TypeVar v2) | v1 == v2 = True
404405unifiesWith _ (TypeConstructor c1) (TypeConstructor c2) | c1 == c2 = True
405406unifiesWith e (TypeApp h1 t1) (TypeApp h2 t2) = unifiesWith e h1 h2 && unifiesWith e t1 t2
@@ -415,7 +416,7 @@ unifiesWith _ _ _ = False
415416-- and return a substitution from type variables to types which makes the type heads unify.
416417--
417418typeHeadsAreEqual :: ModuleName -> Environment -> Type -> Type -> Maybe [(String, Type)]
418−typeHeadsAreEqual _ _ (Skolem s1 _) (Skolem s2 _) | s1 == s2 = Just []
419+typeHeadsAreEqual _ _ (Skolem _ s1 _) (Skolem _ s2 _) | s1 == s2 = Just []
419420typeHeadsAreEqual _ _ t (TypeVar v) = Just [(v, t)]
420421typeHeadsAreEqual _ _ (TypeConstructor c1) (TypeConstructor c2) | c1 == c2 = Just []
421422typeHeadsAreEqual m e (TypeApp h1 t1) (TypeApp h2 t2) = (++) <$> typeHeadsAreEqual m e h1 h2 <*> typeHeadsAreEqual m e t1 t2
@@ -449,7 +450,7 @@ skolemEscapeCheck root@TypedValue{} =
449450 collectSkolems :: Type -> [SkolemScope]
450451 collectSkolems = nub . everything (++) (mkQ [] collect)
451452 where
452− collect (Skolem _ scope) = [scope]
453+ collect (Skolem _ _ scope) = [scope]
453454 collect _ = []
454455 go _ scos = ([], scos)
455456 findBindingScope :: SkolemScope -> Maybe Value
@@ -782,7 +783,7 @@ newSkolemScope = SkolemScope . runUnknown <$> fresh'
782783-- Skolemize a type variable by replacing its instances with fresh skolem constants
783784--
784785skolemize :: String -> Int -> SkolemScope -> Type -> Type
785−skolemize ident sko scope = replaceTypeVars ident (Skolem sko scope)
786+skolemize ident sko scope = replaceTypeVars ident (Skolem ident sko scope)
786787
787788-- |
788789-- This function has one purpose - to skolemize type variables appearing in a
@@ -955,7 +956,7 @@ checkProperties ps row lax = let (ts, r') = rowToList row in go ps ts r' where
955956 go [] [] REmpty = return []
956957 go [] [] u@(TUnknown _) = do u =?= REmpty
957958 return []
958− go [] [] (Skolem _ _) | lax = return []
959+ go [] [] (Skolem _ _ _) | lax = return []
959960 go [] ((p, _): _) _ | lax = return []
960961 | otherwise = throwError $ mkErrorStack ("Object does not have property " ++ p) (Just (ValueError (ObjectLiteral ps)))
961962 go ((p,_):_) [] REmpty = throwError $ mkErrorStack ("Property " ++ p ++ " is not present in closed object type " ++ prettyPrintRow row) (Just (ValueError (ObjectLiteral ps)))