git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Improve instance propagation #272
dd2ff52Phil Freeman
src/Language/PureScript/TypeChecker.hs+2−5
@@ -175,13 +175,10 @@ typeCheckAll mainModuleName moduleName (d@(FixityDeclaration _ name) : rest) = d
175 return $ d : ds
175 return $ d : ds
176typeCheckAll mainModuleName currentModule (d@(ImportDeclaration moduleName _) : rest) = do
176typeCheckAll mainModuleName currentModule (d@(ImportDeclaration moduleName _) : rest) = do
177 env <- getEnv
177 env <- getEnv
178− let instances = filter (\tcd ->
179− let Qualified (Just mn) _ = tcdName tcd in
178+ let instances = filter (\tcd -> let Qualified (Just mn) _ = tcdName tcd in moduleName == mn) (typeClassDictionaries env)
180− moduleName == mn && tcdType tcd == TCDRegular
181− ) (typeClassDictionaries env)
182 forM_ instances $ \tcd -> do
179 forM_ instances $ \tcd -> do
183 let (Qualified _ ident) = tcdName tcd
180 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) }]
185 ds <- typeCheckAll mainModuleName currentModule rest
182 ds <- typeCheckAll mainModuleName currentModule rest
186 return $ d : ds
183 return $ d : ds
187typeCheckAll mainModuleName moduleName (d@(TypeClassDeclaration pn args tys) : rest) = do
184typeCheckAll 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
288 filterModule (TypeClassDictionaryInScope { tcdName = Qualified (Just mn) _ }) | mn == moduleName = True
288 filterModule (TypeClassDictionaryInScope { tcdName = Qualified (Just mn) _ }) | mn == moduleName = True
289 filterModule (TypeClassDictionaryInScope { tcdName = Qualified Nothing _ }) = True
289 filterModule (TypeClassDictionaryInScope { tcdName = Qualified Nothing _ }) = True
290 filterModule _ = False
290 filterModule _ = False
291− canonicalizeDictionary :: TypeClassDictionaryInScope -> Qualified Ident
292− canonicalizeDictionary (TypeClassDictionaryInScope { tcdType = TCDRegular, tcdName = nm }) = nm
293− canonicalizeDictionary (TypeClassDictionaryInScope { tcdType = TCDAlias nm }) = nm
294 -- Ensure that a substitution is valid
291 -- Ensure that a substitution is valid
295 verifySubstitution :: [(String, Type)] -> Maybe [(String, Type)]
292 verifySubstitution :: [(String, Type)] -> Maybe [(String, Type)]
296 verifySubstitution subst = do
293 verifySubstitution subst = do
src/Language/PureScript/Values.hs+7
@@ -173,6 +173,13 @@ data TypeClassDictionaryType
173 --
173 --
174 | TCDAlias (Qualified Ident) deriving (Show, Eq, Data, Typeable)
174 | TCDAlias (Qualified Ident) deriving (Show, Eq, Data, Typeable)
175
175
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+
176-- |
183-- |
177-- A statement in a do-notation block
184-- A statement in a do-notation block
178--
185--