-- modify the import interface in the client modules.
refactorInClientMod origModName destModName pns ((inscps, exps,mod, ts), fileName)
  = do (mod', ((ts',m),_)) <- 
          runStateT ( do mod'<-rmItemsFromImport mod pns
                         mod''<- if isUsedByMod pns mod
                                  then do let qual=getQualifier destModName mod                                          
                                          addImport fileName destModName pns =<< replaceQualifier pns qual mod'
                                  else if itemIsImportedByDefault destModName mod && causeAmbiguity pns mod'
                                         then addHiding destModName mod' pns
                                         else return mod'
                         return mod'' 
                    ) ((ts,unmodified),(-1000,0)) 
       return ((fileName,m),(ts',mod'))



--add a definition name to the import. If the module is not imported yet, then create a new import decl.
-- addImport::String->HsName.ModuleName->[PName]->HsModuleP->HsModuleP
refactorInClientMod origModName destModName pns ((inscps, exps,mod, ts), fileName)
  = do (mod', ((ts',m),_)) <- 
          runStateT ( do mod'<-rmItemsFromImport mod pns
                         mod''<- if isUsedByMod pns mod
                                  then do let qual=getQualifier destModName mod                                          
                                          addImport fileName destModName pns =<< replaceQualifier pns qual mod'
                                  else if itemIsImportedByDefault destModName mod && causeAmbiguity pns mod'
                                         then addHiding destModName mod' pns
                                         else return mod'
                         return mod'' 
                    ) ((ts,unmodified),(-1000,0)) 
       return ((fileName,m),(ts',mod'))



--add a definition name to the import. If the module is not imported yet, then create a new import decl.
-- addImport::String->HsName.ModuleName->[PName]->HsModuleP->HsModuleP
refactorInClientMod origModName destModName pns ((inscps, exps,mod, ts), fileName)
  = do (mod', ((ts',m),_)) <- 
          runStateT ( do mod'<-rmItemsFromImport mod pns
                         mod''<- if isUsedByMod pns mod
                                  then do let qual=getQualifier destModName mod                                          
                                          addImport fileName destModName pns =<< replaceQualifier pns qual mod'
                                  else if itemIsImportedByDefault destModName mod && causeAmbiguity pns mod'
                                         then addHiding destModName mod' pns
                                         else return mod'
                         return mod'' 
                    ) ((ts,unmodified),(-1000,0)) 
       return ((fileName,m),(ts',mod'))



--add a definition name to the import. If the module is not imported yet, then create a new import decl.
-- addImport::String->HsName.ModuleName->[PName]->HsModuleP->HsModuleP