@@ -8,7 +8,7 @@ import qualified Type.Constrain.Expression as TcExpr
8import qualified Type.Constrain.Declaration as TcDecl
8import qualified Type.Constrain.Declaration as TcDecl
9import qualified Type.Solve as Solve
9import qualified Type.Solve as Solve
11−import SourceSyntax.Module
11+import SourceSyntax.Module as Module
12import qualified SourceSyntax.Expression as Expr
12import qualified SourceSyntax.Expression as Expr
13import SourceSyntax.PrettyPrint
13import SourceSyntax.PrettyPrint
14import Text.PrettyPrint
14import Text.PrettyPrint
@@ -23,8 +23,9 @@ import System.IO.Unsafe -- Possible to switch over to the ST monad instead of
24infer :: Interfaces -> MetadataModule t v -> Either [Doc] (Map.Map String T.Variable)
24infer :: Interfaces -> MetadataModule t v -> Either [Doc] (Map.Map String T.Variable)
25infer interfaces' modul = unsafePerformIO $ do
25infer interfaces' modul = unsafePerformIO $ do
26+ let insert (name,method) dict = Map.insertWith (++) name [method] dict
26− let localImports = Map.fromList (imports modul)
27+ localImports = foldr insert Map.empty (imports modul)
27− interfaces = Map.intersectionWithKey canonicalize localImports interfaces'
28+ interfaces = Map.intersectionWithKey Module.canonicalize localImports interfaces'
29-- mapM print (concatMap iAdts (Map.elems interfaces))
30-- mapM print (concatMap iAdts (Map.elems interfaces))
@@ -33,20 +34,11 @@ infer interfaces' modul = unsafePerformIO $ do
33 do (_, vars, args, result) <- Env.freshDataScheme env name
34 do (_, vars, args, result) <- Env.freshDataScheme env name
34 return (name, (vars, foldr (T.==>) result args))
35 return (name, (vars, foldr (T.==>) result args))
36− let locals = Map.intersectionWithKey combine localImports interfaces
37− combine name importMethod interface =
38− let tipes = iTypes interface in
40− As alias -> Map.mapKeys (\v -> alias ++ "." ++ v) tipes
41− Hiding hidens -> foldr Map.delete tipes hidens
42− Importing visibles ->
43− Map.intersection tipes (Map.fromList [ (v,()) | v <- visibles ])
45-- mapM print (map Map.toList $ Map.elems locals)
37-- mapM print (map Map.toList $ Map.elems locals)
46-- mapM print (imports modul)
38-- mapM print (imports modul)
48 importedVars <-
40 importedVars <-
49− forM (concatMap Map.toList $ Map.elems locals) $ \(name,tipe) ->
41+ forM (concatMap (Map.toList . iTypes) $ Map.elems interfaces) $ \(name,tipe) ->
50 (,) name `fmap` Env.instantiateType env tipe Map.empty
42 (,) name `fmap` Env.instantiateType env tipe Map.empty
52 let allTypes = ctors ++ importedVars
44 let allTypes = ctors ++ importedVars