@@ -117,3 +117,26 @@ typeCheckAll (FixityDeclaration _ name : rest) = do
117typeCheckAll (ModuleDeclaration name decls : rest) = do
117typeCheckAll (ModuleDeclaration name decls : rest) = do
118 withModule name $ typeCheckAll decls
118 withModule name $ typeCheckAll decls
119 typeCheckAll rest
119 typeCheckAll rest
120+typeCheckAll (ImportDeclaration modulePath idents : rest) = do
122+ omp <- checkModulePath `fmap` get
123+ rethrow errorMessage $
124+ guardWith "module does not exist" $ moduleExists env
127+ let idents = map snd $ filterModule env
128+ rethrow errorMessage $
129+ bindIdents idents omp env
132+ rethrow errorMessage $
133+ bindIdents idents omp env
135+ where errorMessage = (("Error importing " ++ show modulePath ++ ": ") ++)
136+ filterModule env = filter (\(m, _) -> m == modulePath) (M.keys (names env))
137+ moduleExists env = not $ null $ filterModule env
138+ bindIdents idents omp env =
139+ forM_ idents $ \ident ->
140+ case M.lookup (modulePath, ident) (names env) of
141+ Nothing -> throwError $ show modulePath ++ "." ++ show ident ++ " is undefined"
142+ Just (pt, _) -> putEnv (env { names = M.insert (omp, ident) (pt, Alias modulePath ident) (names env) })