git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Improve instance propagation #272
commitdd2ff52e4429ceba4346a98c562990319c29abad authorPhil Freeman <paf31@cantab.net> dateWed 12 Mar 2014, 21:58 (13 years ago) parent9dbb031
3 files changed+9−8
src/Language/PureScript/TypeChecker.hs+2−5 src/Language/PureScript/TypeChecker/Types.hs−3 src/Language/PureScript/Values.hs+7
src/Language/PureScript/TypeChecker.hs+2−5
@@ -175,13 +175,10 @@ typeCheckAll mainModuleName moduleName (d@(FixityDeclaration _ name) : rest) = d
175175 return $ d : ds
176176typeCheckAll mainModuleName currentModule (d@(ImportDeclaration moduleName _) : rest) = do
177177 env <- getEnv
178− let instances = filter (\tcd ->
179− let Qualified (Just mn) _ = tcdName tcd in
180− moduleName == mn && tcdType tcd == TCDRegular
181− ) (typeClassDictionaries env)
178+ let instances = filter (\tcd -> let Qualified (Just mn) _ = tcdName tcd in moduleName == mn) (typeClassDictionaries env)
182179 forM_ instances $ \tcd -> do
183180 let (Qualified _ ident) = tcdName tcd
184− addTypeClassDictionaries [tcd { tcdName = Qualified (Just currentModule) ident, tcdType = TCDAlias (tcdName tcd) }]
181+ addTypeClassDictionaries [tcd { tcdName = Qualified (Just currentModule) ident, tcdType = TCDAlias (canonicalizeDictionary tcd) }]
185182 ds <- typeCheckAll mainModuleName currentModule rest
186183 return $ d : ds
187184typeCheckAll mainModuleName moduleName (d@(TypeClassDeclaration pn args tys) : rest) = do
src/Language/PureScript/TypeChecker/Types.hs−3
@@ -288,9 +288,6 @@ entails moduleName context goal@(className, tys) = do
288288 filterModule (TypeClassDictionaryInScope { tcdName = Qualified (Just mn) _ }) | mn == moduleName = True
289289 filterModule (TypeClassDictionaryInScope { tcdName = Qualified Nothing _ }) = True
290290 filterModule _ = False
291− canonicalizeDictionary :: TypeClassDictionaryInScope -> Qualified Ident
292− canonicalizeDictionary (TypeClassDictionaryInScope { tcdType = TCDRegular, tcdName = nm }) = nm
293− canonicalizeDictionary (TypeClassDictionaryInScope { tcdType = TCDAlias nm }) = nm
294291 -- Ensure that a substitution is valid
295292 verifySubstitution :: [(String, Type)] -> Maybe [(String, Type)]
296293 verifySubstitution subst = do
src/Language/PureScript/Values.hs+7
@@ -173,6 +173,13 @@ data TypeClassDictionaryType
173173 --
174174 | TCDAlias (Qualified Ident) deriving (Show, Eq, Data, Typeable)
175175
176+-- |
177+-- Find the original dictionary which a type class dictionary in scope refers to
178+--
179+canonicalizeDictionary :: TypeClassDictionaryInScope -> Qualified Ident
180+canonicalizeDictionary (TypeClassDictionaryInScope { tcdType = TCDRegular, tcdName = nm }) = nm
181+canonicalizeDictionary (TypeClassDictionaryInScope { tcdType = TCDAlias nm }) = nm
182+
176183-- |
177184-- A statement in a do-notation block
178185--