@@ -50,52 +50,3 @@ data ModuleInterface = ModuleInterface {
5050instance Binary ModuleInterface where
5151 put modul = put (iTypes modul) >> put (iAdts modul) >> put (iAliases modul)
5252 get = ModuleInterface <$> get <*> get <*> get
53−
54−
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 }
60− where
61− ifaces = map (canonicalizeHelp prefix interface) importMethods
62−
63−
64−canonicalizeHelp :: String -> ModuleInterface -> ImportMethod -> ModuleInterface
65−canonicalizeHelp prefix interface importMethod =
66− ModuleInterface {
67− iTypes = renameNames $ Map.map (renameType rename) (iTypes interface),
68− iAdts = map renameADT (iAdts interface),
69− iAliases = iAliases interface
70− }
71− where
72− addPrefix name = prefix ++ "." ++ name
73−
74− newName (tipe,_,_) =
75− case importMethod of
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
80−
81− rename name = Map.findWithDefault name name newNames
82−
83− renameADT (name, tvars, ctors) =
84− (rename name, tvars, map (second (map (renameType rename))) ctors)
85−
86− renameNames tipes =
87− case importMethod of
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 ])
92−
93−renameType :: (String -> String) -> Type -> Type
94−renameType find tipe =
95− let rnm = renameType find in
96− case tipe of
97− Lambda a b -> Lambda (rnm a) (rnm b)
98− Var x -> Var x
99− Data name ts -> Data (find name) (map rnm ts)
100− EmptyRecord -> EmptyRecord
101− Record fields ext -> Record (map (second rnm) fields) (rnm ext)