@@ -21,6 +21,7 @@ module Language.PureScript.TypeChecker.Monad where
2121import Language.PureScript.Types
2222import Language.PureScript.Kinds
2323import Language.PureScript.Names
24+import Language.PureScript.Declarations (canonicalizeDictionary)
2425import Language.PureScript.Environment
2526import Language.PureScript.TypeClassDictionaries
2627import Language.PureScript.Options
@@ -63,7 +64,8 @@ bindTypes newNames action = do
6364withTypeClassDictionaries :: (MonadState CheckState m) => [TypeClassDictionaryInScope] -> m a -> m a
6465withTypeClassDictionaries entries action = do
6566 orig <- get
66− modify $ \st -> st { checkEnv = (checkEnv st) { typeClassDictionaries = entries ++ (typeClassDictionaries . checkEnv $ st) } }
67+ let mentries = M.fromList [ ((canonicalizeDictionary entry, mn), entry) | entry@TypeClassDictionaryInScope{ tcdName = Qualified mn _ } <- entries ]
68+ modify $ \st -> st { checkEnv = (checkEnv st) { typeClassDictionaries = (typeClassDictionaries . checkEnv $ st) `M.union` mentries } }
6769 a <- action
6870 modify $ \st -> st { checkEnv = (checkEnv st) { typeClassDictionaries = typeClassDictionaries . checkEnv $ orig } }
6971 return a
@@ -72,7 +74,7 @@ withTypeClassDictionaries entries action = do
7274-- Get the currently available list of type class dictionaries
7375--
7476getTypeClassDictionaries :: (Functor m, MonadState CheckState m) => m [TypeClassDictionaryInScope]
75−getTypeClassDictionaries = typeClassDictionaries . checkEnv <$> get
77+getTypeClassDictionaries = M.elems . typeClassDictionaries . checkEnv <$> get
7678
7779-- |
7880-- Temporarily bind a collection of names to local variables