@@ -51,25 +51,41 @@ instance Binary ModuleInterface where
5151 get = ModuleInterface <$> get <*> get
5252
5353
54−canonicalize :: String -> ImportMethod -> ModuleInterface -> ModuleInterface
55−canonicalize prefix importMethod interface =
56− let addPrefix name = prefix ++ "." ++ name
57−
58− newName (tipe,_,_) =
59− case importMethod of
60− As name -> (tipe, name ++ "." ++ tipe)
61− Hiding vs -> (tipe, if tipe `elem` vs then addPrefix tipe else tipe)
62− Importing vs -> (tipe, if tipe `elem` vs then tipe else addPrefix tipe)
63− newNames = Map.fromList . map newName $ iAdts interface
64−
65− rename name = Map.findWithDefault name name newNames
66−
67− renameADT (name, tvars, ctors) =
68− (rename name, tvars, map (second (map (renameType rename))) ctors)
69− in ModuleInterface {
70− iTypes = Map.map (renameType rename) (iTypes interface),
71− iAdts = map renameADT (iAdts interface)
72− }
54+canonicalize :: String -> [ImportMethod] -> ModuleInterface -> ModuleInterface
55+canonicalize prefix importMethods interface =
56+ ModuleInterface { iTypes = Map.unions (map iTypes ifaces)
57+ , iAdts = concatMap iAdts ifaces }
58+ where
59+ ifaces = map (canonicalizeHelp prefix interface) importMethods
60+
61+
62+canonicalizeHelp :: String -> ModuleInterface -> ImportMethod -> ModuleInterface
63+canonicalizeHelp prefix interface importMethod =
64+ ModuleInterface {
65+ iTypes = renameNames $ Map.map (renameType rename) (iTypes interface),
66+ iAdts = map renameADT (iAdts interface)
67+ }
68+ where
69+ addPrefix name = prefix ++ "." ++ name
70+
71+ newName (tipe,_,_) =
72+ case importMethod of
73+ As name -> (tipe, name ++ "." ++ tipe)
74+ Hiding vs -> (tipe, if tipe `elem` vs then addPrefix tipe else tipe)
75+ Importing vs -> (tipe, if tipe `elem` vs then tipe else addPrefix tipe)
76+ newNames = Map.fromList . map newName $ iAdts interface
77+
78+ rename name = Map.findWithDefault name name newNames
79+
80+ renameADT (name, tvars, ctors) =
81+ (rename name, tvars, map (second (map (renameType rename))) ctors)
82+
83+ renameNames tipes =
84+ case importMethod of
85+ As alias -> Map.mapKeys (\v -> alias ++ "." ++ v) tipes
86+ Hiding hidens -> foldr Map.delete tipes hidens
87+ Importing visibles ->
88+ Map.intersection tipes (Map.fromList [ (v,()) | v <- visibles ])
7389
7490renameType :: (String -> String) -> Type -> Type
7591renameType find tipe =