@@ -47,20 +47,14 @@ newtype Work = Work Integer deriving (Show, Eq, Ord, Num)
47-- Check that the current set of type class dictionaries entail the specified type class goal, and, if so,
47-- Check that the current set of type class dictionaries entail the specified type class goal, and, if so,
48-- return a type class dictionary reference.
48-- return a type class dictionary reference.
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
51entails env moduleName context = solve
51entails env moduleName context = solve
53− byClassName :: M.Map (Qualified ProperName) [TypeClassDictionaryInScope]
53+ forClassName :: Qualified ProperName -> [TypeClassDictionaryInScope]
54− byClassName = M.fromListWith (++) $ (\tcd -> (tcdClassName tcd, [tcd])) <$> sortedNubBy canonicalizeDictionary dictsInScope
54+ forClassName cn = findDicts cn Nothing ++ findDicts cn (Just moduleName)
56− sortedNubBy :: (Ord k) => (v -> k) -> [v] -> [v]
57− sortedNubBy f vs = M.elems (M.fromList (map (f &&& id) vs))
59− dictsInScope :: [TypeClassDictionaryInScope]
60− dictsInScope = findDicts Nothing ++ findDicts (Just moduleName)
62− findDicts :: Maybe ModuleName -> [TypeClassDictionaryInScope]
56+ findDicts :: Qualified ProperName -> Maybe ModuleName -> [TypeClassDictionaryInScope]
63− findDicts = fromMaybe [] . flip M.lookup context
57+ findDicts cn = maybe [] M.elems . (>>= M.lookup cn) . flip M.lookup context
65 solve :: Constraint -> Bool -> Check Expr
59 solve :: Constraint -> Bool -> Check Expr
66 solve (className, tys) trySuperclasses = do
60 solve (className, tys) trySuperclasses = do
@@ -76,7 +70,7 @@ entails env moduleName context = solve
77 directInstances :: StateT Work [] DictionaryValue
71 directInstances :: StateT Work [] DictionaryValue
78 directInstances = do
72 directInstances = do
79− tcd <- lift . fromMaybe [] $ M.lookup className' byClassName
73+ tcd <- lift $ forClassName className'
80 -- Make sure the type unifies with the type in the type instance definition
74 -- Make sure the type unifies with the type in the type instance definition
81 subst <- lift . maybeToList . (>>= verifySubstitution) . fmap concat $ zipWithM (typeHeadsAreEqual moduleName env) tys' (tcdInstanceTypes tcd)
75 subst <- lift . maybeToList . (>>= verifySubstitution) . fmap concat $ zipWithM (typeHeadsAreEqual moduleName env) tys' (tcdInstanceTypes tcd)
82 -- Solve any necessary subgoals
76 -- Solve any necessary subgoals