git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
simplify ImportDeclaration type checker
f9c9dd2Bogdan Popa
src/Language/PureScript/TypeChecker.hs+8−13
@@ -120,18 +120,12 @@ typeCheckAll (ModuleDeclaration name decls : rest) = do
120typeCheckAll (ImportDeclaration modulePath idents : rest) = do
120typeCheckAll (ImportDeclaration modulePath idents : rest) = do
121 env <- getEnv
121 env <- getEnv
122 omp <- checkModulePath `fmap` get
122 omp <- checkModulePath `fmap` get
123− rethrow errorMessage $
123+ rethrow errorMessage $ do
124− guardWith "module does not exist" $ moduleExists env
124+ guardWith "module does not exist" $ moduleExists env
125− case idents of
125+ case idents of
126− Nothing -> do
127− let idents = map snd $ filterModule env
126+ Nothing -> bindIdents (map snd $ filterModule env) omp env
128− rethrow errorMessage $
129− bindIdents idents omp env
130− typeCheckAll rest
131− Just idents -> do
132− rethrow errorMessage $
133− bindIdents idents omp env
127+ Just idents -> bindIdents idents omp env
134− typeCheckAll rest
128+ typeCheckAll rest
135 where errorMessage = (("Error importing " ++ show modulePath ++ ": ") ++)
129 where errorMessage = (("Error importing " ++ show modulePath ++ ": ") ++)
136 filterModule env = filter (\(m, _) -> m == modulePath) (M.keys (names env))
130 filterModule env = filter (\(m, _) -> m == modulePath) (M.keys (names env))
137 moduleExists env = not $ null $ filterModule env
131 moduleExists env = not $ null $ filterModule env
@@ -140,4 +134,5 @@ typeCheckAll (ImportDeclaration modulePath idents : rest) = do
140 case M.lookup (modulePath, ident) (names env) of
134 case M.lookup (modulePath, ident) (names env) of
141 Nothing -> throwError $ show modulePath ++ "." ++ show ident ++ " is undefined"
135 Nothing -> throwError $ show modulePath ++ "." ++ show ident ++ " is undefined"
142 Just (pt, _) -> getEnv >>= \env' ->
136 Just (pt, _) -> getEnv >>= \env' ->
143− putEnv (env' { names = M.insert (omp, ident) (pt, Alias modulePath ident) (names env') })
137+ putEnv (env' { names = M.insert (omp, ident) (pt, Alias modulePath ident)
138+ (names env') })