+-- When printing code that contains original names, we need to map the
+-- original names back to something the user understands. This is the
+-- purpose of the pair of functions that gets passed around
+-- when rendering 'SDoc'.
+
+-- | given an /original/ name, this function tells you which module
+-- name it should be qualified with when printing for the user, if
+-- any. For example, given @Control.Exception.catch@, which is in scope
+-- as @Exception.catch@, this fuction will return @Just "Exception"@.
+-- Note that the return value is a ModuleName, not a Module, because
+-- in source code, names are qualified by ModuleNames.
+type QueryQualifyName = Module -> OccName -> QualifyName
+
+-- See Note [Printing original names] in HscTypes
+data QualifyName -- given P:M.T
+ = NameUnqual -- refer to it as "T"
+ | NameQual ModuleName -- refer to it as "X.T" for the supplied X
+ | NameNotInScope1
+ -- it is not in scope at all, but M.T is not bound in the current
+ -- scope, so we can refer to it as "M.T"
+ | NameNotInScope2
+ -- it is not in scope at all, and M.T is already bound in the
+ -- current scope, so we must refer to it as "P:M.T"
+
+
+-- | For a given module, we need to know whether to print it with
+-- a package name to disambiguate it.
+type QueryQualifyModule = Module -> Bool
+
+type PrintUnqualified = (QueryQualifyName, QueryQualifyModule)
+
+alwaysQualifyNames :: QueryQualifyName
+alwaysQualifyNames m _ = NameQual (moduleName m)
+
+neverQualifyNames :: QueryQualifyName
+neverQualifyNames _ _ = NameUnqual
+
+alwaysQualifyModules :: QueryQualifyModule
+alwaysQualifyModules _ = True
+
+neverQualifyModules :: QueryQualifyModule
+neverQualifyModules _ = False
+
+alwaysQualify, neverQualify :: PrintUnqualified
+alwaysQualify = (alwaysQualifyNames, alwaysQualifyModules)
+neverQualify = (neverQualifyNames, neverQualifyModules)
+
+defaultUserStyle, defaultDumpStyle :: PprStyle