@@ -50,52 +50,3 @@ data ModuleInterface = ModuleInterface {
50instance Binary ModuleInterface where
50instance Binary ModuleInterface where
51 put modul = put (iTypes modul) >> put (iAdts modul) >> put (iAliases modul)
51 put modul = put (iTypes modul) >> put (iAdts modul) >> put (iAliases modul)
52 get = ModuleInterface <$> get <*> get <*> get
52 get = ModuleInterface <$> get <*> get <*> get
55−canonicalize :: String -> [ImportMethod] -> ModuleInterface -> ModuleInterface
56−canonicalize prefix importMethods interface =
57− ModuleInterface { iTypes = Map.unions (map iTypes ifaces)
58− , iAdts = concatMap iAdts ifaces
59− , iAliases = concatMap iAliases ifaces }
61− ifaces = map (canonicalizeHelp prefix interface) importMethods
64−canonicalizeHelp :: String -> ModuleInterface -> ImportMethod -> ModuleInterface
65−canonicalizeHelp prefix interface importMethod =
67− iTypes = renameNames $ Map.map (renameType rename) (iTypes interface),
68− iAdts = map renameADT (iAdts interface),
69− iAliases = iAliases interface
72− addPrefix name = prefix ++ "." ++ name
76− As name -> (tipe, name ++ "." ++ tipe)
77− Hiding vs -> (tipe, if tipe `elem` vs then addPrefix tipe else tipe)
78− Importing vs -> (tipe, if tipe `elem` vs then tipe else addPrefix tipe)
79− newNames = Map.fromList . map newName $ iAdts interface
81− rename name = Map.findWithDefault name name newNames
83− renameADT (name, tvars, ctors) =
84− (rename name, tvars, map (second (map (renameType rename))) ctors)
88− As alias -> Map.mapKeys (\v -> alias ++ "." ++ v) tipes
89− Hiding hidens -> foldr Map.delete tipes hidens
90− Importing visibles ->
91− Map.intersection tipes (Map.fromList [ (v,()) | v <- visibles ])
93−renameType :: (String -> String) -> Type -> Type
94−renameType find tipe =
95− let rnm = renameType find in
97− Lambda a b -> Lambda (rnm a) (rnm b)
99− Data name ts -> Data (find name) (map rnm ts)
100− EmptyRecord -> EmptyRecord
101− Record fields ext -> Record (map (second rnm) fields) (rnm ext)