@@ -47,20 +47,14 @@ newtype Work = Work Integer deriving (Show, Eq, Ord, Num)
4747-- Check that the current set of type class dictionaries entail the specified type class goal, and, if so,
4848-- return a type class dictionary reference.
4949--
50−entails :: Environment -> ModuleName -> M.Map (Maybe ModuleName) [TypeClassDictionaryInScope] -> Constraint -> Bool -> Check Expr
50+entails :: Environment -> ModuleName -> M.Map (Maybe ModuleName) (M.Map (Qualified ProperName) (M.Map (Qualified Ident) TypeClassDictionaryInScope)) -> Constraint -> Bool -> Check Expr
5151entails env moduleName context = solve
5252 where
53− byClassName :: M.Map (Qualified ProperName) [TypeClassDictionaryInScope]
54− byClassName = M.fromListWith (++) $ (\tcd -> (tcdClassName tcd, [tcd])) <$> sortedNubBy canonicalizeDictionary dictsInScope
53+ forClassName :: Qualified ProperName -> [TypeClassDictionaryInScope]
54+ forClassName cn = findDicts cn Nothing ++ findDicts cn (Just moduleName)
5555
56− sortedNubBy :: (Ord k) => (v -> k) -> [v] -> [v]
57− sortedNubBy f vs = M.elems (M.fromList (map (f &&& id) vs))
58−
59− dictsInScope :: [TypeClassDictionaryInScope]
60− dictsInScope = findDicts Nothing ++ findDicts (Just moduleName)
61−
62− findDicts :: Maybe ModuleName -> [TypeClassDictionaryInScope]
63− findDicts = fromMaybe [] . flip M.lookup context
56+ findDicts :: Qualified ProperName -> Maybe ModuleName -> [TypeClassDictionaryInScope]
57+ findDicts cn = maybe [] M.elems . (>>= M.lookup cn) . flip M.lookup context
6458
6559 solve :: Constraint -> Bool -> Check Expr
6660 solve (className, tys) trySuperclasses = do
@@ -76,7 +70,7 @@ entails env moduleName context = solve
7670 where
7771 directInstances :: StateT Work [] DictionaryValue
7872 directInstances = do
79− tcd <- lift . fromMaybe [] $ M.lookup className' byClassName
73+ tcd <- lift $ forClassName className'
8074 -- Make sure the type unifies with the type in the type instance definition
8175 subst <- lift . maybeToList . (>>= verifySubstitution) . fmap concat $ zipWithM (typeHeadsAreEqual moduleName env) tys' (tcdInstanceTypes tcd)
8276 -- Solve any necessary subgoals