@@ -21,7 +21,7 @@ module Language.PureScript.TypeChecker.Entailment (
2121
2222import Data.Function (on )
2323import Data.List
24- import Data.Maybe (maybeToList )
24+ import Data.Maybe (fromMaybe , maybeToList )
2525import Data.Foldable (foldMap )
2626import qualified Data.Map as M
2727
@@ -47,17 +47,17 @@ 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 -> [TypeClassDictionaryInScope ] -> Constraint -> Bool -> Check Expr
51- entails env moduleName context = solve (sortedNubBy canonicalizeDictionary ( filter filterModule context) )
50+ entails :: Environment -> ModuleName -> M. Map ( Maybe ModuleName ) [TypeClassDictionaryInScope ] -> Constraint -> Bool -> Check Expr
51+ entails env moduleName context = solve (sortedNubBy canonicalizeDictionary dictsInScope )
5252 where
5353 sortedNubBy :: (Ord k ) => (v -> k ) -> [v ] -> [v ]
5454 sortedNubBy f vs = M. elems (M. fromList (map (f &&& id ) vs))
5555
56- -- Filter out type dictionaries which are in scope in the current module
57- filterModule :: TypeClassDictionaryInScope -> Bool
58- filterModule ( TypeClassDictionaryInScope { tcdName = Qualified ( Just mn) _ }) | mn == moduleName = True
59- filterModule ( TypeClassDictionaryInScope { tcdName = Qualified Nothing _ }) = True
60- filterModule _ = False
56+ dictsInScope :: [ TypeClassDictionaryInScope ]
57+ dictsInScope = findDicts Nothing ++ findDicts ( Just moduleName)
58+
59+ findDicts :: Maybe ModuleName -> [ TypeClassDictionaryInScope ]
60+ findDicts = fromMaybe [] . flip M. lookup context
6161
6262 solve :: [TypeClassDictionaryInScope ] -> Constraint -> Bool -> Check Expr
6363 solve context' (className, tys) trySuperclasses = do
0 commit comments