diff --git a/CHANGES b/CHANGES
deleted file mode 100644
--- a/CHANGES
+++ /dev/null
@@ -1,486 +0,0 @@
-Changes in version 2.9.4
-
-  * Require GHC >= 7.2
-
-  * Support Alex 3.x
-
-Changes in version 2.9.3
-
-  [This is the version that comes with GHC 7.2.1 although it claims it's 2.9.2!]
-
-  * Build with GHC 7.2.1
-
-  * Support blank lines in results of examples
-
-  * A type signature for multiple names generates one signature in the output
-
-  * Minor bug fixes
-
-Changes in version 2.9.2
-
-  * Build with GHC 7.0.2
-
-  * Write Hoogle output in utf8; fixes GHC build on Windows
-
-Changes in version 2.9.1
-
-  * Fix build in GHC tree
-
-  * Improve .cabal file
-
-Changes in version 2.9.0
-
-  * Drop support for ghc < 7
-
-  * New flag --qual for qualification of names
-
-  * Print doc coverage information to stdout when generating docs
-
-  * Include an 'All' option in the A-Z subdivided index
-
-  * Make TOC group header identifiers validate
-
-  * Minor changes to the API
-
-Changes in the version that comes with GHC 7.0.1
-  
-  [This version claims it is 2.8.0 but is actually based on 2.8.1]
-
-  * Fix URL creation on Windows: Use / not \ in URLs.
-
-  * Support GHC 7.0
-
-Changes in version 2.8.1
-
-  * Fix build on Windows with MinGW
-
-Changes in version 2.8.0
-
-  * HTML backend completely rewritten to generate semantically rich XHTML
-    using the xhtml package.
-
-  * New default CSS based on the color scheme chosen for the new Haskell
-    wiki, with a pull-out tab for the synopsis.
-
-  * Theme engine based on CSS files. Themes can be switched from the
-    header menu. (New flags --built-in-themes and --theme. The latter
-    is an alias for --css which now has extended semantics).
-
-  * Markup support for executable examples/unit-tests. To be used with an
-    upcoming version of the DocTest program.
-
-  * Addition of a LaTeX backend.
-
-  * Frames-mode can be enabled from the header menu.
-
-  * Path to source entities can be specified per package, so that source
-    links work for cross-package documentation.
-
-  * Support for a second form of enumerated lists (1. 2. etc).
-
-  * Additions and changes to the Haddock API.
-
-  * New flag --no-tmp-comp-dir to tell Haddock to write and pick up
-    compilation files (.o, .hi, etc) to/from GHC's output directory instead
-    of a temporary directory.
-
-  * Various bug fixes.
-
------------------------------------------------------------------------------
-
-Changes in version 2.6.1 (bug fix release from the stable branch)
-
-  * Fix #128
-
------------------------------------------------------------------------------
-
-Changes in version 2.7.2
-
-  * Add Paths_haddock to library
-
------------------------------------------------------------------------------
-
-Changes in version 2.7.1:
-
-  * Fix problems with library part of .cabal file
-
------------------------------------------------------------------------------
-
-Changes in version 2.7.0:
-
-  * Instances can be commented
-
-  * The Haddock API now exposes more of the internals of Haddock
-
-  * Bug fixes (most importantly #128)
-
------------------------------------------------------------------------------
-
-Changes in version 2.6.0:
-
-  * Drop support for GHC 6.10.*
-
-  * Add support for GHC 6.12.1
-
-  * Cross-package documentation: full documentation show up when re-exporting
-    things coming from external packages
-
-  * Lexing and parsing the Haddock comment markup is now done in Haddock
-    again, instead of in GHC
-
-  * Slightly prettier printing of instance heads
-
-  * Support platforms for which GHC has no native code generator
-
-  * Add a flag --print-ghc-libdir
-
-  * Minor bug fixes
-
------------------------------------------------------------------------------
-
-Changed in version 2.5.0:
-
-  * Drop support for GHC 6.8.*
-
-  * Add support for GHC 6.10.3 and 6.10.4
-
-  * Revert to the old multi-page index for large packages (#106)
-
-  * Show GADT records in the generated documentation
-
-  * Create output directory if it doesn't exist (#104)
-
-  * Use the native codegen instead of compiling via C for TH modules
-
-  * Add --use-unicode flag for displaying prettier versions of common symbols
-
-  * Mutiple verbosity levels: remove --verbose and add --verbosity=n
-
------------------------------------------------------------------------------
-
-Changed in version 2.4.2:
-
-  * Support GHC 6.10.2
-
-  * Haddock no longer crashes on Template Haskell modules (#68)
-    (only with GHC 6.10.2 or above)
-
-  * Fix problem with Template Haskell-generated declarations disappearing (#59)
-
-  * Generate two anchors for each link for compatibility between IE and Opera
-    (#45)
-
-  * Improved error messages
-
-  * Show re-exports from external packages again (GHC ticket #2746)
-
-  * Store hidden modules in .haddock files again (needed by the haddock
-    library)
-
-  * Avoid processing boot modules
-
-  * Pragmas may exist between document comments and declarations
-
-  * Do not indicate that a constructor argument is unboxed
-
-  * Fix problem with with non-working links to ghc-prim
-
-  * Allow referring to a specific section within a module in a module link
-    (#65)
-
-  * Fixes to the Hoogle backend
-  
-  * Improvements to the haddock library
-
-  * Many other fixes (including #67, #69, #58, #57)
-
------------------------------------------------------------------------------
-
-Changed in version 2.4.1:
-
-  * Depend on base 4.* when GHC >= 6.9, otherwise 3.*
-
------------------------------------------------------------------------------
-
-Changed in version 2.4.0:
-
-  * Add framed view of the HTML documentation
-
-  * Build with GHC 6.8.2 and 6.8.3 again
-
-  * Support images in documentation comments again
-
-  * Small improvements to the Hoogle output
-
-  * A few bugs has been fixed
-
------------------------------------------------------------------------------
-
-Changed in version 2.3.0:
-
-  * Support for GHC 6.10.1
-
-  * Slightly improved space usage
-
-  * Fix a bug that made hidden modules show up in the contents & index pages
-
-  * Fix a bug that made Haddock load modules twice
-
-  * Improvements to the Hoogle output
-
------------------------------------------------------------------------------
-
-Changed in version 2.2.2:
-
-  * Relax version dependency on ghc-paths
-
------------------------------------------------------------------------------
-
-Changes in version 2.2.1:
-
-  * Support for GHC 6.8.3
-
-  * The Hoogle backend is back, thanks to Neil Mitchell. The plan is to be
-    compatible with the upcoming Hoogle 4 pre-release
-
-  * Show associated types in the documentation for class declarations
-
-  * Show type family declarations
-
-  * Show type equality predicates
-
-  * Major bug fixes (#1 and #44)
-
-  * It is no longer required to specify the path to GHC's lib dir
-
-  * Remove unnecessary parenthesis in type signatures
-
------------------------------------------------------------------------------
-
-Changes in version 2.1.0:
-
-  * Fix a bug that made links point to the defining module instead
-    of the "best" one (e.g Int pointing to GHC.Base instead of Data.Int)
-
-  * Fix a couple of smaller bugs
-
-  * The representation of DocName was changed in the library
-
-  * Add a flag --no-warnings for turning off warnings
-
------------------------------------------------------------------------------
-
-Changes in version 2.0.0.0:
-
-  * The GHC API is used as the front-end
-
-  * Haddock now understands all syntax understood by GHC 6.8.2
-
-  * Haddock can generate documentation for some of the language extensions
-    in GHC 6.8.2
-
-  * Format of module attributes has changed. The only way of specifiying
-    module attributes is via a new OPTIONS_HADDOCK pragma. Example: 
-    {-# OPTIONS_HADDOCK hide, prune #-}
-
-  * Haddock understands literate source files
-
-  * Add a small library to read Haddock's interface files
-
-  * Add a flag -B for passing the path to the GHC lib dir
-
-  * Add a flag --optghc for passing options to GHC
-
-  * Add a flag --ghc-version for printing the GHC version
-
-  * Remove --use-package, --allow-missing-html, --ghc-pkg, in favour of only
-    supporting --read-interface
-
-  * Remove --package flag, the GHC flag -package-name can be used instead
-
-  * Remove --no-implicit-prelude flag, the GHC flag -XNoImplicitPrelude can
-    be used instead
-
------------------------------------------------------------------------------
-
-Changes in version 0.9:
-
-  * Infix type operators, e.g., first :: a~>a' -> (a,b)~>(a',b)
-
-  * Add a search box to the index page which automatically narrows
-    the index to the search as you type (thanks to Neil Mitchell).
-
-  * Add a --ghc-pkg flag
-
-  * Add a flag --allow-missing-html
-
-  * URL expansion for %%, %L, %{LINE}
-
-  * added substitution %{FILE///c}
-
-  * Lexing of /.../ is now more like '...', in that a / character must
-    be matched by another / character on the same line, otherwise it
-    is treated as a literal '/'.  This removes a common source of
-    accidental parse errors in documentation.
-
-  * Various bugs were fixed.
-
-  * Cabal 1.2 is now required, and Haddock builds with GHC 6.8.x.
-
------------------------------------------------------------------------------
-
-Changes in version 0.8:
-
-  * Haddock has a Cabal build system, and will build on Windows without
-    Cygwin or MSYS.  GHC 6.4 or later is required.
-
-  * New options: --comments-base, --comments-module, --comments-entity
-    for generating links to pages (eg. wiki) for collecting user comments.
-
-  * New options: --source-base, --source-module, --source-entity
-    for generating links to source code.  Haddock now understands
-    {-# LINE #-} pragmas, which means it can figure out the correct
-    name for the source file even if the file is preprocessed.
-
-  * Haddock generates output for populating the Hoogle search engine.
-
-  * New markup <<url>> for including images.
-
------------------------------------------------------------------------------
-
-Changes in version 0.7:
-
-  * Changes in the way Haddock decides where to direct hyperlinks.  Each entity
-    is now assigned a single "home" module, and all hyperlinks are directed
-    to that module.  See the docs ("Hyperlinking and re-exported entities")
-    for details.
-
-  * New options --ignore-all-exports, --hide
-
-  * New option --use-package for creating documentation that hyperlinks to
-    the HTML documentation for existing packages on your system.  It works
-    by querying ghc-pkg for the location of the Haddock interface and
-    HTML for the given package.
-
-  * Parts of the HTML documentation, notably lists of instances, are
-    now "collapsible" with a +/- button.  Also, the contents page is now
-    in the form of tree in which subtrees can be collapsed.
-
-  * Support for Microsoft DevHelp and HtmlHelp 2.0 formats.
-
-  * Support for a short description for each module for the contents page.
-
-  * Compiles with GHC 6.4+
-
-  * Various bugfixes
-
------------------------------------------------------------------------------
-
-Changes in version 0.6:
-
-  * Implicit parameters, zip comprehensions and 'mdo' are now
-    supported by the parser.
-
-  * Some lexical bugs were fixed, mainly concerning literal paragraphs
-    next to non-literal paragraphs.
-
-  * New options:  --gen-index, --use-index, --gen-contents and --use-contents,
-    for generting a combined index and contents for several libraries
-    from the appropriate .haddock files.
-
-  * There is now one index rather than separate Function/Constructor and
-    Type/Class indices.  Where a name refers to several entities, these
-    are listed separately in the index.
-
-  * New option: -v, elicits more verbose warnings.  Some warnings are
-    now turned off by default; Haddock should be a little less noisy
-    in general.
-
-  * Markup for definition lists has been added.  See the documentation 
-    for details.
-
-  * New option: --package for setting the package name.  The package
-    is listed alongside each module name in the combined contents.
-
-  * Entities which are re-exported from another package now at least
-    leave a hyperlink in the generated HTML, rather than nothing at all.
-
-  * Some fixes for bugs which caused incorrect hyperlinks in the
-    generated HTML.  In particular, instances should now be linked
-    correctly.
-
-  * Some aesthetic improvements to the generated HTML.
-
------------------------------------------------------------------------------
-
-Changes in version 0.5:
-
-  * Compiles with recent versions of GHC.
-
-  * A few bugs have been fixed.
-
-  * New labelling/linking feature (see "Anchors" in the manual).
-
------------------------------------------------------------------------------
-
-Changes in version 0.4:
-
-  * Import declarations which list entities in parentheses, or with
-    hiding clauses, are now properly supported.  Modulo one or two
-    small infelicities, the full Haskell modules system is now supported.
-
-  * Haddock is now more flexible about the placing of separators
-    (commas, semicolons) in relation to doc comments.
-
-  * There is support for generating and reading "interface files"
-    which describe the exports of a set of modules.  This is useful
-    for generating documentation which hyperlinks to
-    previously-generated documentation.
-    
-  * Support for generating the extra files required by the Microsoft
-    Help compiler.
-
-  * New option: --prologue specifies a file of documentation which is
-    placed on the contents page.
-
-  * Many bugs fixed
-
------------------------------------------------------------------------------
-Changes in version 0.3:
-  
-  * Documentation on individual function arguments is now implemented 
-  
-  * Links can be made to identifiers that aren't in scope, by using
-    the fully qualified name.
-
-  * Instances are collected and listed with the appropriate classes
-    and datatypes (not for derived instances yet).
-
-  * Single quotes are only interpreted specially when they surround a
-    legal Haskell identifier, otherwise they are treated literally.
-
-  * Bird-tracked text is now literal.  If you want marked-up text in
-    a code block, use the @...@ notation instead.
-
-  * Various changes to the layout, it generally looks nicer now.
-
-  * Various bugs fixed.
-
------------------------------------------------------------------------------
-Changes in version 0.2:
-
-  * The [...] markup for typewriter font has been changed to @...@.
-
-  * Module attributes introduced (see the documentation for details).
-
-  * {- ... -} style comments may now be used for documentation annotations
-
-  * Recursive modules are detected and reported as an error.
-
-  * Existential constructors and rank-N types are now groked by the parser
-
-  * Some type rendering cleaned up
-
-  * `abc' is accepted as well as 'abc' to markup an identifier
-
-  * Several bugs fixed, and error messages improved.
diff --git a/CHANGES.md b/CHANGES.md
new file mode 100644
--- /dev/null
+++ b/CHANGES.md
@@ -0,0 +1,893 @@
+## Changes in 2.29.1
+ * Fix build on GHC 9.2
+
+## Changes in 2.29.0
+ * Fixes for memory leaks and performance improvements
+
+## Changes in 2.28.0
+ * Support qualified and unqualified names in `--ignore-link-symbol`
+
+## Changes in 2.24.0
+
+ * Reify oversaturated data family instances correctly (#1103)
+
+ * Removed the majority of Haddock's possible `panic` routes through
+   the TTG refactor to make extension variants empty
+
+## Changes in 2.23.0
+
+ * "Linuwial" is the new default theme (#721, #782, #949)
+
+ * Fix style switcher (enabled by `--built-in-themes`) (#949)
+
+ * Support inline markup in markdown-style links (#875)
+
+ * The hyperlinker backend has been re-engineered to use HIE files
+   and display type annotations on expressions (#977)
+
+ * The hyperlinker backend lexer is now more incremental, faster, and
+   more memory efficient (#977)
+
+ * Add an "Instances" menu item to the HTML backend for controlling
+   settings related to expanding/collapsing instances (#1007)
+
+ * Improved identifier links including value/type namespaces, and
+   hyperlinking of parenthesized/backticked identifiers
+
+ * Substantial bugfixes for converting `TyThing` back into source
+   declarations (#1003, #1005, #1022, #1020)
+
+ * `--show-interface` now outputs to stdout (instead of stderr)
+
+ * Render associated type defaults and also improve rendering of
+   default method signatures
+
+ * Many fixes to the LaTeX backend, mostly focused on not crashing
+   as well as generating LaTeX source that compiles
+
+ * More flexible parsing of the module header
+
+## Changes in version 2.22.0
+
+ * Make `--package-version` optional for `--hoogle` (#899)
+
+ * Support type and data families in the LaTeX backend (#734)
+
+ * Support pattern synonyms in the Hoogle backend (#947)
+
+## Changes in version 2.21.0
+
+ * Overhaul handling of data declarations in XHTML and LaTeX. Adds support for
+   documenting individual arguments of constructors/patterns (#709)
+
+ * Actually list all fixities for `--hoogle` (#871)
+
+ * Fix broken instance source links (#869)
+
+ * Avoiding line breaks due to ling line in the output of `--hoogle` (#868)
+
+ * Capture docs on type family instances (#867)
+
+## Changes in version 2.20.0
+
+ * Show where instances are defined (#748)
+
+ * `@since` includes package name (#452, #550, #749)
+
+## Changes in version 2.19.0.1
+
+ * Support for linking unicode operators (#458)
+
+ * Hyperlinker: Fix file handle leak in (#763)
+
+## Changes in version 2.19.0
+
+ * Haddock now supports tables in documentation inspired by reSTs grid tables
+
+ * `--quickjump` allows for quick navigation in documentation on hackage and
+   other documentation hosting sites.
+
+ * A --reexport flag, which can be used to add extra modules to the
+   top-level module tree
+
+ * Haddock no longer reports coverage statistics for hidden modules. By default
+   cabal-install marks all package internal modules as hidden.
+
+ * Haddock now writes additional information about the documentation to `meta.json`
+
+ * Fix renaming of type variables after specializing instance method signatures (#613)
+
+ * Move markup related data types to haddock-library
+
+ * Fix: Show empty constraint contexts in pattern type signatures (#663)
+
+ * Fix: Generate constraint signatures for constructors exported as pattern
+   synonyms (#663)
+
+ * The hyperlinker backend now uses the GHC lexer instead of a custom one.
+   This notably fixes rendering of quasiquotes.
+
+ * Overhaul Haddock's rendering of kind signatures so that invisible kind
+   parameters are not printed (#681) (Fixes #544)
+
+ * Recognise `SPDX-License-Identifier` as alias for `License` in module header
+   parser (#743)
+
+ * Remove the response file related utilities, and use the ones that
+   come with `base` (Trac #13896)
+
+ * Remove the response file related utilities, and use the ones that
+   come with `base` (Trac #13896)
+
+## Changes in version 2.18.1
+
+ * Synopsis is working again (#599)
+
+ * Per-argument documentation on class methods working again (#647)
+
+ * Support user defined signatures on pattern synonyms
+
+ * Support for bundled pattern synonyms (#494, #551, #626)
+
+## Changes in version 2.17.4
+
+ * Fix 'internal error: links: UnhelpfulSpan' (#554, #565)
+
+ * Hyperlink backend knows about `DataKinds` (#510)
+
+ * Fix rendering of class methods for `Eq` and `Ord` (#549)
+
+ * Export `MDoc` and `toInstalledIface` from `Haddock.Types`
+
+## Changes in version 2.17.3.1
+
+ * Disable `NFData` instances for GHC types when GHC >= 8.0.2 (#537)
+
+## Changes in version 2.17.3
+
+ * Remove framed view of the HTML documentation
+
+## Changes in version 2.17.2
+
+ * Fix portability of documentation building within GHC
+
+## Changes in version 2.17.1
+
+ * Included with GHC 8.0.1
+
+ * Fixed Makefile for GHC installation
+
+ * Fixed clean rule of GHC Makefile
+
+## Changes in version 2.17.0 (not released)
+
+ * Support typesetting of mathematical expressions via Mathjax (#397)
+
+ * Describe orphan instances defined in a module in its documentation (#449)
+
+ * Produce specialized type signatures for typeclass methods (#425)
+
+ * Support GCC-like response files (#470)
+
+## Changes in version 2.16.2
+
+ * Generate hyperlinked source ourselves (#410, part of GSOC 2015)
+
+ * Fix expansion icon for user-collapsible sections (#412)
+
+ * Break up response file arguments on newlines
+
+ * Various HTML fixes (#301, #406, #407, #421)
+
+ * Line anchors in hyperlinked source (#420)
+
+## Changes in version 2.16.1
+
+ * Don't default to type constructors for out-of-scope names (#253 and
+   #375)
+
+ * Fix Hoogle display of constructors (#361)
+
+ * Fully qualify names in Hoogle instances output (#263)
+
+ * Output method documentation in Hoogle backend (#259)
+
+ * Don't print instance safety information in Hoogle (#168)
+
+ * Expand response files in arguments (#285)
+
+ * Build the main executable with -threaded (#399)
+
+ * Use SrcSpan of declarations for inferred type sigs (#207)
+
+ * Fix cross-module instance locations (#383)
+
+ * Fix alignment of Source link for instances in Firefox (#384)
+
+## Changes in version 2.16.0
+
+ * Experimental collapsible header support (#335)
+
+ * Add support for markdown links and images
+
+ * Allow an optional colon after the closing bracket of definition lists.
+   This is to disambiguate them from markdown links and will be require with a
+   future release.
+
+ * Fix re-exports of built-in type families (#310)
+
+ * Fix parsing of infix identifiers such as ``elem``.
+
+ * Print missing docs by default and add --no-print-missing-docs
+
+ * parser: now parses out some meta data too, breaking the API
+
+ * parser: markdown syntax for images and URLs is now accepted:
+   <<foo>> style for images and <foo bar> style for links is now
+   considered deprecated. <foo> for links is still OK.
+
+ * parser: add support for @since element: this is paragraph-level
+   element of the form ‘@since x.y.z’ where x.y.z is the version
+   number. The way it is rendered is subject to change.
+
+ * properly render package ID (not package key) in index (#329)
+
+ * links to source location of class instance definitions
+
+ * Fix code blocks in presence of Windows line endings
+
+ * Deal better with long synopsis lines (#151)
+
+## Changes in version 2.15.0
+
+ * Always read in prologue files as UTF8 (#286 and Cabal #1721)
+
+ * parser: don't wrap headers in DocParagraph (#307)
+
+ * parser: don't mangle append order for nested lists (pandoc #1346)
+
+ * parser: preserve list ordering in certain scenarios (#313)
+
+ * parser: update the attoparsec version used internally giving slight
+   parsing performance boost.
+
+ * Move development to be against latest GHC release and not GHC HEAD.
+
+ * Further split up the package to separate the executable from the
+   library, necessary by things like GHCJS. We now have
+   ‘haddock-library’ which are the parts that don't use GHC API,
+   ‘haddock-api’ which are (some of) the parts that do use GHC API and
+   ‘haddock’ which merely provides the executable.
+
+ * Export few extra functions in the API.
+
+ * Add compatibility with GHC 7.8.2.
+
+ * Omit unnecessary ‘forall’s (#315 and #86)
+
+ * Remove some files which were really old or did not belong in the
+   repository in the first place.
+
+## Changes in version 2.14.3
+
+ * Fix parsing of identifiers with ^ or ⋆ in them (#298)
+
+ * Fix anchors (#308)
+
+## Changes in version 2.14.2
+
+ * Always drop --split-objs GHC flag for performance reasons (#292)
+
+ * Print kind signatures GADTs (#85)
+
+ * Drop single leading whitespace when reasonable from @-style blocks (#201)
+
+ * Fix crashes associated with exporting data family record selectors (#294)
+
+## Changes in version 2.14.1
+
+ * Render * and -> with their UnicodeSyntax equivalents if -U is enabled
+
+ * Display minimal complete definitions for type classes
+
+ * Hide right hand side of TF instances with hidden names on the RHS
+
+## Changes in version 2.14.0
+
+ * Print entities with missing documentation (#258)
+
+ * Print a warning message when given `-optghc` instead of `--optghc` (#5)
+
+ * Add `--compatible-interface-versions` (#231)
+
+ * Allow to generate latex documentation for FFI declarations (#247)
+
+ * Add copyright and license information to generated documentation
+
+ * Improved to Unicode support
+
+ * Bold markup support
+
+ * Nested paragraphs
+
+ * Better escaping
+
+ * Header markup
+
+ * Parser should no longer fail to parse any markup
+
+ * {-# OPTIONS_HADDOCK show-extensions #-} pragma will show the GHC extensions
+   enabled in the module.
+
+ * Properly render License field (#271)
+
+ * Print type/data family instances (for exported types only)
+
+ * Fix display of poly-kinded type operators (#189)
+
+ * PatternSynonyms support
+
+ * Fix display of implicit parameters (#260)
+
+ * Fix rendering of Contents when links are present (#276)
+
+ * Fix documentation duplication on record fields (#195)
+
+ * Add `--source-entity-line` for exact line links (eg. things defined
+   inside TH splices) (#79)
+
+ * Display fixity information for names with nonstandard fixities
+
+ * Bird tracks specified like "> code" no longer suffer from an extra leading
+   space in the code output
+
+## Changes in version 2.13.2
+
+ * Handle HsExplicitListTy in renamer (#213)
+
+ * Allow haddock markup in deprecation messages
+
+ * Export more types from Documentation.Haddock
+
+ * Include everything that is required to run the test suite with the cabal
+   package (#230)
+
+## Changes in version 2.13.1
+
+ * Hide instances that are "internal" to a module
+
+ * Add support for properties in documentation
+
+ * Fix a bug with spurious superclass constraints
+
+ * Fix and extend the Haddock API
+
+## Changes in version 2.12.0
+
+ * Labeled URLs (e.g <http://example.net/ some label>)
+
+ * Improved memory usage (new dependency: deepseq)
+
+## Changes in version 2.11.0
+
+ * Show deprecation messages for identifiers
+
+ * List identifiers declared on the same line (with a common type) separately
+
+ * Don't crash on unicode strings in doc comments
+
+ * Fix reporting of modules safe haskell mode
+
+ * Fix a case where we were generating invalid xhtml
+
+ * Improved --qual option (no crashes, proper error messages)
+
+ * A new --qual option "aliased" which qualifies identifiers by the module alias
+   used in the source code
+
+ * The Haddock API restores GHC's static flags after invocation
+
+ * Access to unexported identifiers through the Haddock API again
+
+## Changes in version 2.10.0
+
+ * Require GHC >= 7.4
+
+ * Safe Haskell indications on module pages
+
+ * Type declarations on identifiers no longer necessary
+
+ * Add flag --interface-version
+
+ * Warn when comment refers to in-scope identifier without documentation
+
+ * Bug fix: links to out-of-scope things (#78)
+
+ * Bug fix: module references to other packages work again
+
+## Changes in version 2.9.4
+
+  * Require GHC >= 7.2
+
+  * Support Alex 3.x
+
+## Changes in version 2.9.3
+
+  [This is the version that comes with GHC 7.2.1 although it claims it's 2.9.2!]
+
+  * Build with GHC 7.2.1
+
+  * Support blank lines in results of examples
+
+  * A type signature for multiple names generates one signature in the output
+
+  * Minor bug fixes
+
+## Changes in version 2.9.2
+
+  * Build with GHC 7.0.2
+
+  * Write Hoogle output in utf8; fixes GHC build on Windows
+
+## Changes in version 2.9.1
+
+  * Fix build in GHC tree
+
+  * Improve .cabal file
+
+## Changes in version 2.9.0
+
+  * Drop support for ghc < 7
+
+  * New flag --qual for qualification of names
+
+  * Print doc coverage information to stdout when generating docs
+
+  * Include an 'All' option in the A-Z subdivided index
+
+  * Make TOC group header identifiers validate
+
+  * Minor changes to the API
+
+## Changes in the version that comes with GHC 7.0.1
+
+  [This version claims it is 2.8.0 but is actually based on 2.8.1]
+
+  * Fix URL creation on Windows: Use / not \ in URLs.
+
+  * Support GHC 7.0
+
+## Changes in version 2.8.1
+
+  * Fix build on Windows with MinGW
+
+## Changes in version 2.8.0
+
+  * HTML backend completely rewritten to generate semantically rich XHTML
+    using the xhtml package.
+
+  * New default CSS based on the color scheme chosen for the new Haskell
+    wiki, with a pull-out tab for the synopsis.
+
+  * Theme engine based on CSS files. Themes can be switched from the
+    header menu. (New flags --built-in-themes and --theme. The latter
+    is an alias for --css which now has extended semantics).
+
+  * Markup support for executable examples/unit-tests. To be used with an
+    upcoming version of the DocTest program.
+
+  * Addition of a LaTeX backend.
+
+  * Frames-mode can be enabled from the header menu.
+
+  * Path to source entities can be specified per package, so that source
+    links work for cross-package documentation.
+
+  * Support for a second form of enumerated lists (1. 2. etc).
+
+  * Additions and changes to the Haddock API.
+
+  * New flag --no-tmp-comp-dir to tell Haddock to write and pick up
+    compilation files (.o, .hi, etc) to/from GHC's output directory instead
+    of a temporary directory.
+
+  * Various bug fixes.
+
+-----------------------------------------------------------------------------
+
+## Changes in version 2.6.1 (bug fix release from the stable branch)
+
+  * Fix #128
+
+-----------------------------------------------------------------------------
+
+## Changes in version 2.7.2
+
+  * Add Paths_haddock to library
+
+-----------------------------------------------------------------------------
+
+## Changes in version 2.7.1:
+
+  * Fix problems with library part of .cabal file
+
+-----------------------------------------------------------------------------
+
+## Changes in version 2.7.0:
+
+  * Instances can be commented
+
+  * The Haddock API now exposes more of the internals of Haddock
+
+  * Bug fixes (most importantly #128)
+
+-----------------------------------------------------------------------------
+
+## Changes in version 2.6.0:
+
+  * Drop support for GHC 6.10.*
+
+  * Add support for GHC 6.12.1
+
+  * Cross-package documentation: full documentation show up when re-exporting
+    things coming from external packages
+
+  * Lexing and parsing the Haddock comment markup is now done in Haddock
+    again, instead of in GHC
+
+  * Slightly prettier printing of instance heads
+
+  * Support platforms for which GHC has no native code generator
+
+  * Add a flag --print-ghc-libdir
+
+  * Minor bug fixes
+
+-----------------------------------------------------------------------------
+
+Changed in version 2.5.0:
+
+  * Drop support for GHC 6.8.*
+
+  * Add support for GHC 6.10.3 and 6.10.4
+
+  * Revert to the old multi-page index for large packages (#106)
+
+  * Show GADT records in the generated documentation
+
+  * Create output directory if it doesn't exist (#104)
+
+  * Use the native codegen instead of compiling via C for TH modules
+
+  * Add --use-unicode flag for displaying prettier versions of common symbols
+
+  * Multiple verbosity levels: remove --verbose and add --verbosity=n
+
+-----------------------------------------------------------------------------
+
+Changed in version 2.4.2:
+
+  * Support GHC 6.10.2
+
+  * Haddock no longer crashes on Template Haskell modules (#68)
+    (only with GHC 6.10.2 or above)
+
+  * Fix problem with Template Haskell-generated declarations disappearing (#59)
+
+  * Generate two anchors for each link for compatibility between IE and Opera
+    (#45)
+
+  * Improved error messages
+
+  * Show re-exports from external packages again (GHC ticket #2746)
+
+  * Store hidden modules in .haddock files again (needed by the haddock
+    library)
+
+  * Avoid processing boot modules
+
+  * Pragmas may exist between document comments and declarations
+
+  * Do not indicate that a constructor argument is unboxed
+
+  * Fix problem with non-working links to ghc-prim
+
+  * Allow referring to a specific section within a module in a module link
+    (#65)
+
+  * Fixes to the Hoogle backend
+
+  * Improvements to the haddock library
+
+  * Many other fixes (including #67, #69, #58, #57)
+
+-----------------------------------------------------------------------------
+
+Changed in version 2.4.1:
+
+  * Depend on base 4.* when GHC >= 6.9, otherwise 3.*
+
+-----------------------------------------------------------------------------
+
+Changed in version 2.4.0:
+
+  * Add framed view of the HTML documentation
+
+  * Build with GHC 6.8.2 and 6.8.3 again
+
+  * Support images in documentation comments again
+
+  * Small improvements to the Hoogle output
+
+  * A few bugs has been fixed
+
+-----------------------------------------------------------------------------
+
+Changed in version 2.3.0:
+
+  * Support for GHC 6.10.1
+
+  * Slightly improved space usage
+
+  * Fix a bug that made hidden modules show up in the contents & index pages
+
+  * Fix a bug that made Haddock load modules twice
+
+  * Improvements to the Hoogle output
+
+-----------------------------------------------------------------------------
+
+Changed in version 2.2.2:
+
+  * Relax version dependency on ghc-paths
+
+-----------------------------------------------------------------------------
+
+## Changes in version 2.2.1:
+
+  * Support for GHC 6.8.3
+
+  * The Hoogle backend is back, thanks to Neil Mitchell. The plan is to be
+    compatible with the upcoming Hoogle 4 pre-release
+
+  * Show associated types in the documentation for class declarations
+
+  * Show type family declarations
+
+  * Show type equality predicates
+
+  * Major bug fixes (#1 and #44)
+
+  * It is no longer required to specify the path to GHC's lib dir
+
+  * Remove unnecessary parenthesis in type signatures
+
+-----------------------------------------------------------------------------
+
+## Changes in version 2.1.0:
+
+  * Fix a bug that made links point to the defining module instead
+    of the "best" one (e.g Int pointing to GHC.Base instead of Data.Int)
+
+  * Fix a couple of smaller bugs
+
+  * The representation of DocName was changed in the library
+
+  * Add a flag --no-warnings for turning off warnings
+
+-----------------------------------------------------------------------------
+
+## Changes in version 2.0.0.0:
+
+  * The GHC API is used as the front-end
+
+  * Haddock now understands all syntax understood by GHC 6.8.2
+
+  * Haddock can generate documentation for some of the language extensions
+    in GHC 6.8.2
+
+  * Format of module attributes has changed. The only way of specifying
+    module attributes is via a new OPTIONS_HADDOCK pragma. Example:
+    {-# OPTIONS_HADDOCK hide, prune #-}
+
+  * Haddock understands literate source files
+
+  * Add a small library to read Haddock's interface files
+
+  * Add a flag -B for passing the path to the GHC lib dir
+
+  * Add a flag --optghc for passing options to GHC
+
+  * Add a flag --ghc-version for printing the GHC version
+
+  * Remove --use-package, --allow-missing-html, --ghc-pkg, in favour of only
+    supporting --read-interface
+
+  * Remove --package flag, the GHC flag -package-name can be used instead
+
+  * Remove --no-implicit-prelude flag, the GHC flag -XNoImplicitPrelude can
+    be used instead
+
+-----------------------------------------------------------------------------
+
+## Changes in version 0.9:
+
+  * Infix type operators, e.g., first :: a~>a' -> (a,b)~>(a',b)
+
+  * Add a search box to the index page which automatically narrows
+    the index to the search as you type (thanks to Neil Mitchell).
+
+  * Add a --ghc-pkg flag
+
+  * Add a flag --allow-missing-html
+
+  * URL expansion for %%, %L, %{LINE}
+
+  * added substitution %{FILE///c}
+
+  * Lexing of /.../ is now more like '...', in that a / character must
+    be matched by another / character on the same line, otherwise it
+    is treated as a literal '/'.  This removes a common source of
+    accidental parse errors in documentation.
+
+  * Various bugs were fixed.
+
+  * Cabal 1.2 is now required, and Haddock builds with GHC 6.8.x.
+
+-----------------------------------------------------------------------------
+
+## Changes in version 0.8:
+
+  * Haddock has a Cabal build system, and will build on Windows without
+    Cygwin or MSYS.  GHC 6.4 or later is required.
+
+  * New options: --comments-base, --comments-module, --comments-entity
+    for generating links to pages (eg. wiki) for collecting user comments.
+
+  * New options: --source-base, --source-module, --source-entity
+    for generating links to source code.  Haddock now understands
+    {-# LINE #-} pragmas, which means it can figure out the correct
+    name for the source file even if the file is preprocessed.
+
+  * Haddock generates output for populating the Hoogle search engine.
+
+  * New markup <<url>> for including images.
+
+-----------------------------------------------------------------------------
+
+## Changes in version 0.7:
+
+  * ## Changes in the way Haddock decides where to direct hyperlinks.  Each entity
+    is now assigned a single "home" module, and all hyperlinks are directed
+    to that module.  See the docs ("Hyperlinking and re-exported entities")
+    for details.
+
+  * New options --ignore-all-exports, --hide
+
+  * New option --use-package for creating documentation that hyperlinks to
+    the HTML documentation for existing packages on your system.  It works
+    by querying ghc-pkg for the location of the Haddock interface and
+    HTML for the given package.
+
+  * Parts of the HTML documentation, notably lists of instances, are
+    now "collapsible" with a +/- button.  Also, the contents page is now
+    in the form of tree in which subtrees can be collapsed.
+
+  * Support for Microsoft DevHelp and HtmlHelp 2.0 formats.
+
+  * Support for a short description for each module for the contents page.
+
+  * Compiles with GHC 6.4+
+
+  * Various bugfixes
+
+-----------------------------------------------------------------------------
+
+## Changes in version 0.6:
+
+  * Implicit parameters, zip comprehensions and 'mdo' are now
+    supported by the parser.
+
+  * Some lexical bugs were fixed, mainly concerning literal paragraphs
+    next to non-literal paragraphs.
+
+  * New options:  --gen-index, --use-index, --gen-contents and --use-contents,
+    for generting a combined index and contents for several libraries
+    from the appropriate .haddock files.
+
+  * There is now one index rather than separate Function/Constructor and
+    Type/Class indices.  Where a name refers to several entities, these
+    are listed separately in the index.
+
+  * New option: -v, elicits more verbose warnings.  Some warnings are
+    now turned off by default; Haddock should be a little less noisy
+    in general.
+
+  * Markup for definition lists has been added.  See the documentation
+    for details.
+
+  * New option: --package for setting the package name.  The package
+    is listed alongside each module name in the combined contents.
+
+  * Entities which are re-exported from another package now at least
+    leave a hyperlink in the generated HTML, rather than nothing at all.
+
+  * Some fixes for bugs which caused incorrect hyperlinks in the
+    generated HTML.  In particular, instances should now be linked
+    correctly.
+
+  * Some aesthetic improvements to the generated HTML.
+
+-----------------------------------------------------------------------------
+
+## Changes in version 0.5:
+
+  * Compiles with recent versions of GHC.
+
+  * A few bugs have been fixed.
+
+  * New labelling/linking feature (see "Anchors" in the manual).
+
+-----------------------------------------------------------------------------
+
+## Changes in version 0.4:
+
+  * Import declarations which list entities in parentheses, or with
+    hiding clauses, are now properly supported.  Modulo one or two
+    small infelicities, the full Haskell modules system is now supported.
+
+  * Haddock is now more flexible about the placing of separators
+    (commas, semicolons) in relation to doc comments.
+
+  * There is support for generating and reading "interface files"
+    which describe the exports of a set of modules.  This is useful
+    for generating documentation which hyperlinks to
+    previously-generated documentation.
+
+  * Support for generating the extra files required by the Microsoft
+    Help compiler.
+
+  * New option: --prologue specifies a file of documentation which is
+    placed on the contents page.
+
+  * Many bugs fixed
+
+-----------------------------------------------------------------------------
+## Changes in version 0.3:
+
+  * Documentation on individual function arguments is now implemented
+
+  * Links can be made to identifiers that aren't in scope, by using
+    the fully qualified name.
+
+  * Instances are collected and listed with the appropriate classes
+    and datatypes (not for derived instances yet).
+
+  * Single quotes are only interpreted specially when they surround a
+    legal Haskell identifier, otherwise they are treated literally.
+
+  * Bird-tracked text is now literal.  If you want marked-up text in
+    a code block, use the @...@ notation instead.
+
+  * Various changes to the layout, it generally looks nicer now.
+
+  * Various bugs fixed.
+
+-----------------------------------------------------------------------------
+## Changes in version 0.2:
+
+  * The [...] markup for typewriter font has been changed to @...@.
+
+  * Module attributes introduced (see the documentation for details).
+
+  * {- ... -} style comments may now be used for documentation annotations
+
+  * Recursive modules are detected and reported as an error.
+
+  * Existential constructors and rank-N types are now groked by the parser
+
+  * Some type rendering cleaned up
+
+  * `abc' is accepted as well as 'abc' to markup an identifier
+
+  * Several bugs fixed, and error messages improved.
diff --git a/LICENSE b/LICENSE
--- a/LICENSE
+++ b/LICENSE
@@ -1,23 +1,26 @@
-Copyright 2002-2010, Simon Marlow.  All rights reserved.
+Copyright (c) 2002-2010, Simon Marlow
+All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
+modification, are permitted provided that the following conditions are
+met:
 
-- Redistributions of source code must retain the above copyright notice,
-this list of conditions and the following disclaimer.
- 
-- Redistributions in binary form must reproduce the above copyright notice,
-this list of conditions and the following disclaimer in the documentation
-and/or other materials provided with the distribution.
- 
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS "AS IS" AND ANY
-EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE
-LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
-BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
-OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
-IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+1. Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the
+   distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/README b/README
deleted file mode 100644
--- a/README
+++ /dev/null
@@ -1,48 +0,0 @@
-Haddock, a Haskell Documentation Tool
-=====================================
-
-This is Haddock, a tool for automatically generating documentation
-from annotated Haskell source code.  It is primary intended for
-documenting library interfaces, but it should be useful for any kind
-of Haskell code.
-
-Like other systems ([1],[2]), Haddock lets you write documentation
-annotations next to the definitions of functions and types in the
-source code, in a syntax that is easy on the eye when writing the
-source code (no heavyweight mark-up).  The documentation generated by
-Haddock is fully hyperlinked - click on a type name in a type
-signature to go straight to the definition, and documentation, for
-that type.
-
-Haddock understands Haskell's module system, so you can structure your
-code however you like without worrying that internal structure will be
-exposed in the generated documentation.  For example, it is common to
-implement a library in several modules, but define the external API by
-having a single module which re-exports parts of these implementation
-modules.  Using Haddock, you can still write documentation annotations
-next to the actual definitions of the functions and types in the
-library, but the documentation annotations from the implementation
-will be propagated to the external API when the documentation is
-generated.  Abstract types and classes are handled correctly.  In
-fact, even without any documentation annotations, Haddock can generate
-useful documentation from your source code.
-
-Haddock can generate documentation in multiple formats; currently HTML
-is implemented, and there is partial support for generating DocBook.
-The generated HTML uses stylesheets, so you need a fairly up-to-date
-browser to view it properly (Mozilla, Konqueror, Opera, and IE 6
-should all be ok).
-
-Full documentation can be found in the doc/ subdirectory, in DocBook
-format.
-
-Please send questions and suggestions to:
-
-David Waern <david.waern@gmail.com> or
-Simon Marlow <simonmar@microsoft.com>
-
-
-[1] IDoc - A No Frills Haskell Interface Documentation System
-    http://www.cse.unsw.edu.au/~chak/haskell/idoc/
-
-[2] HDoc http://www.fmi.uni-passau.de/~groessli/hdoc/
diff --git a/README.md b/README.md
new file mode 100644
--- /dev/null
+++ b/README.md
@@ -0,0 +1,34 @@
+# Haddock [![CI][CI badge]][CI page] [![Hackage][Hackage badge]][Hackage page]
+
+Haddock is the standard tool for generating documentation from Haskell code.
+Full documentation about Haddock itself can be found in the `doc/` subdirectory,
+in [reStructuredText][reST] format.
+
+## Project overview
+
+This project consists of three packages:
+
+ * `haddock`: provides the `haddock` executable. It is implemented as a tiny
+    wrapper around `haddock-api`'s `Documentation.Haddock.haddock` function.
+
+ * `haddock-api`: contains the program logic of the `haddock` tool.
+   [The haddocks for the `Documentation.Haddock` module][Documentation.Haddock]
+   offer a good overview of the functionality.
+
+ * `haddock-library`: is concerned with the parsing and processing of the
+   Haddock markup language. Unlike the other packages, it is expected to build
+   on a fairly wide range of GHC versions.
+
+## Contributing
+
+See [CONTRIBUTING.md](CONTRIBUTING.md) to see how to make contributions to the
+project.
+
+
+[CI page]: https://github.com/haskell/haddock/actions/workflows/ci.yml
+[CI badge]: https://github.com/haskell/haddock/actions/workflows/ci.yml/badge.svg
+[Hackage page]: https://hackage.haskell.org/package/haddock
+[Hackage badge]: https://img.shields.io/hackage/v/haddock.svg
+[reST]: https://www.sphinx-doc.org/en/master/usage/restructuredtext/index.html
+[Documentation.Haddock]: http://hackage.haskell.org/package/haddock-api/docs/Documentation-Haddock.html
+[cabal v2]: https://cabal.readthedocs.io/en/latest/nix-local-build-overview.html
diff --git a/Setup.lhs b/Setup.lhs
--- a/Setup.lhs
+++ b/Setup.lhs
@@ -1,5 +1,3 @@
-#! /usr/bin/runhaskell
-\begin{code}
-import Distribution.Simple
-main = defaultMain
-\end{code}
+#!/usr/bin/env runhaskell
+> import Distribution.Simple
+> main = defaultMain
diff --git a/dist/build/haddock/haddock-tmp/Haddock/Lex.hs b/dist/build/haddock/haddock-tmp/Haddock/Lex.hs
deleted file mode 100644
--- a/dist/build/haddock/haddock-tmp/Haddock/Lex.hs
+++ /dev/null
@@ -1,428 +0,0 @@
-{-# LANGUAGE CPP,MagicHash #-}
-{-# LINE 10 "src/Haddock/Lex.x" #-}
-
-{-# LANGUAGE BangPatterns #-}   -- Generated by Alex
-{-# OPTIONS -Wwarn -w #-}
--- The above warning supression flag is a temporary kludge.
--- While working on this module you are encouraged to remove it and fix
--- any warnings in the module. See
---     http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings
--- for details
-
-module Haddock.Lex (
-	Token(..),
-	LToken,
-	tokenise
- ) where
-
-import Lexer hiding (Token)
-import Parser ( parseIdentifier )
-import StringBuffer
-import RdrName
-import SrcLoc
-import DynFlags
-import FastString
-
-import Data.Char
-import Data.Word (Word8)
-import Numeric
-import System.IO.Unsafe
-
-#if __GLASGOW_HASKELL__ >= 603
-#include "ghcconfig.h"
-#elif defined(__GLASGOW_HASKELL__)
-#include "config.h"
-#endif
-#if __GLASGOW_HASKELL__ >= 503
-import Data.Array
-import Data.Char (ord)
-import Data.Array.Base (unsafeAt)
-#else
-import Array
-import Char (ord)
-#endif
-#if __GLASGOW_HASKELL__ >= 503
-import GHC.Exts
-#else
-import GlaExts
-#endif
-alex_base :: AlexAddr
-alex_base = AlexA# "\xf8\xff\xff\xff\xfc\xff\xff\xff\xf2\x00\x00\x00\xfe\xff\xff\xff\xe8\x01\x00\x00\xde\x02\x00\x00\x03\x00\x00\x00\x03\x01\x00\x00\xd4\x03\x00\x00\x12\x00\x00\x00\xca\x04\x00\x00\xc0\x05\x00\x00\xd2\x01\x00\x00\x24\x00\x00\x00\xb9\x02\x00\x00\x40\x06\x00\x00\xc0\x06\x00\x00\x40\x07\x00\x00\xc0\x07\x00\x00\x40\x08\x00\x00\xc0\x08\x00\x00\x40\x09\x00\x00\xc0\x09\x00\x00\x40\x0a\x00\x00\xc0\x0a\x00\x00\x40\x0b\x00\x00\xc0\x0b\x00\x00\x40\x0c\x00\x00\xc0\x0c\x00\x00\x40\x0d\x00\x00\xc0\x0d\x00\x00\x40\x0e\x00\x00\xc0\x0e\x00\x00\x00\x00\x00\x00\x31\x0f\x00\x00\x00\x00\x00\x00\xa2\x0f\x00\x00\x00\x00\x00\x00\x13\x10\x00\x00\x00\x00\x00\x00\x84\x10\x00\x00\x00\x00\x00\x00\xf5\x10\x00\x00\x00\x00\x00\x00\x66\x11\x00\x00\x00\x00\x00\x00\xd7\x11\x00\x00\x00\x00\x00\x00\x48\x12\x00\x00\x00\x00\x00\x00\x2f\x04\x00\x00\x00\x00\x00\x00\x31\x05\x00\x00\x00\x00\x00\x00\x89\x12\x00\x00\x00\x00\x00\x00\xca\x12\x00\x00\x00\x00\x00\x00\x0b\x13\x00\x00\x00\x00\x00\x00\x4c\x13\x00\x00\x00\x00\x00\x00\xbd\x13\x00\x00\x00\x00\x00\x00\xfe\x13\x00\x00\xd0\x02\x00\x00\xcd\x00\x00\x00\x00\x00\x00\x00\x3f\x14\x00\x00\x3f\x15\x00\x00\xff\x14\x00\x00\x00\x00\x00\x00\xff\x15\x00\x00\xbf\x15\x00\x00\x00\x00\x00\x00\xbf\x16\x00\x00\x7f\x16\x00\x00\x00\x00\x00\x00\x7f\x17\x00\x00\x3f\x17\x00\x00\x00\x00\x00\x00\x3f\x18\x00\x00\xff\x17\x00\x00\x00\x00\x00\x00\xff\x18\x00\x00\xbf\x18\x00\x00\x00\x00\x00\x00\xd3\xff\xff\xff\x00\x00\x00\x00\x00\x19\x00\x00\x30\x00\x00\x00\x00\x1a\x00\x00\xc0\x19\x00\x00\x00\x00\x00\x00\xc0\x1a\x00\x00\x80\x1a\x00\x00\x00\x00\x00\x00\x76\x1b\x00\x00\x6c\x1c\x00\x00\xd4\xff\xff\xff\x1d\x01\x00\x00\x6c\x1d\x00\x00\xf5\x1a\x00\x00\x00\x00\x00\x00\xd5\xff\xff\xff\xec\x02\x00\x00\x3c\x00\x00\x00\xd6\xff\xff\xff\x00\x00\x00\x00\xd7\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xd8\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xd9\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\xcb\x1d\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xe3\x1d\x00\x00\xd9\x1e\x00\x00\xcd\x1e\x00\x00\xf6\xff\xff\xff\xcf\x1f\x00\x00\xc5\x20\x00\x00\x00\x00\x00\x00\xbb\x21\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"#
-
-alex_table :: AlexAddr
-alex_table = AlexA# "\x00\x00\x07\x00\x6c\x00\x07\x00\x07\x00\x07\x00\x76\x00\x64\x00\x77\x00\x64\x00\x64\x00\x64\x00\x69\x00\x75\x00\x69\x00\x69\x00\x69\x00\x63\x00\x78\x00\x74\x00\x6e\x00\x6b\x00\x68\x00\x7c\x00\x07\x00\x42\x00\x00\x00\x00\x00\x00\x00\x00\x00\x64\x00\x00\x00\x5a\x00\x00\x00\x6f\x00\x69\x00\x00\x00\x6f\x00\x00\x00\x00\x00\x6a\x00\x6a\x00\x6a\x00\x6a\x00\x6a\x00\x6a\x00\x6a\x00\x6a\x00\x6a\x00\x6a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x6d\x00\x00\x00\x00\x00\x00\x00\x00\x00\x71\x00\x57\x00\x00\x00\x00\x00\x00\x00\x00\x00\x73\x00\x09\x00\x09\x00\x09\x00\x09\x00\x09\x00\x09\x00\x09\x00\x09\x00\x09\x00\x09\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x70\x00\x0d\x00\x0d\x00\x0d\x00\x0d\x00\x0d\x00\x0d\x00\x0d\x00\x0d\x00\x0d\x00\x0d\x00\x00\x00\x84\x00\x09\x00\x09\x00\x09\x00\x09\x00\x09\x00\x09\x00\x09\x00\x09\x00\x09\x00\x09\x00\x72\x00\x00\x00\x6a\x00\x6a\x00\x6a\x00\x6a\x00\x6a\x00\x6a\x00\x6a\x00\x6a\x00\x6a\x00\x6a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x65\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x66\x00\x0f\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x59\x00\x12\x00\x3d\x00\x3d\x00\x3d\x00\x3e\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x8c\x00\x0d\x00\x0d\x00\x0d\x00\x0d\x00\x0d\x00\x0d\x00\x0d\x00\x0d\x00\x0d\x00\x0d\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x07\x00\x6c\x00\x07\x00\x07\x00\x07\x00\x00\x00\x00\x00\x00\x00\x7b\x00\x86\x00\x00\x00\x00\x00\x89\x00\x88\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x87\x00\x00\x00\x07\x00\x00\x00\x41\x00\x64\x00\x77\x00\x64\x00\x64\x00\x64\x00\x5a\x00\x00\x00\x6f\x00\x8b\x00\x00\x00\x6f\x00\x00\x00\x7b\x00\x6a\x00\x6a\x00\x6a\x00\x6a\x00\x6a\x00\x6a\x00\x6a\x00\x6a\x00\x6a\x00\x6a\x00\x64\x00\x00\x00\x00\x00\x00\x00\x6d\x00\x00\x00\x00\x00\x00\x00\x41\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x8a\x00\x8e\x00\x00\x00\x00\x00\x88\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x57\x00\x00\x00\x00\x00\x70\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x5b\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5c\x00\x11\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x40\x00\x1a\x00\x2d\x00\x2d\x00\x2d\x00\x2e\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x79\x00\x0c\x00\x00\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x81\x00\x00\x00\x00\x00\x0c\x00\x0c\x00\x00\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x00\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x00\x00\x0c\x00\x00\x00\x0c\x00\x0c\x00\x82\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x00\x00\x0c\x00\x00\x00\x0c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x54\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x55\x00\x13\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3c\x00\x1b\x00\x2b\x00\x2b\x00\x2b\x00\x2c\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x7a\x00\x0e\x00\x0e\x00\x0e\x00\x0e\x00\x0e\x00\x0e\x00\x0e\x00\x0e\x00\x0e\x00\x0e\x00\x00\x00\x85\x00\x69\x00\x75\x00\x69\x00\x69\x00\x69\x00\x0e\x00\x0e\x00\x0e\x00\x0e\x00\x0e\x00\x0e\x00\x0e\x00\x0e\x00\x0e\x00\x0e\x00\x0e\x00\x0e\x00\x0e\x00\x0e\x00\x0e\x00\x0e\x00\x00\x00\x00\x00\x69\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0e\x00\x0e\x00\x0e\x00\x0e\x00\x0e\x00\x0e\x00\x00\x00\x00\x00\x00\x00\x0e\x00\x0e\x00\x0e\x00\x0e\x00\x0e\x00\x0e\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x73\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0e\x00\x0e\x00\x0e\x00\x0e\x00\x0e\x00\x0e\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x51\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x52\x00\x14\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x3a\x00\x1c\x00\x29\x00\x29\x00\x29\x00\x2a\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x8c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x7b\x00\x86\x00\x00\x00\x00\x00\x89\x00\x88\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x87\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x8b\x00\x00\x00\x00\x00\x00\x00\x7b\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x8a\x00\x8f\x00\x00\x00\x00\x00\x88\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x5b\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5c\x00\x11\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x40\x00\x1a\x00\x2d\x00\x2d\x00\x2d\x00\x2e\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x7f\x00\x46\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x48\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x49\x00\x17\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x34\x00\x1f\x00\x23\x00\x23\x00\x23\x00\x24\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x49\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x45\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x46\x00\x18\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x32\x00\x20\x00\x21\x00\x21\x00\x21\x00\x22\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x65\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x67\x00\x5e\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x5b\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x0f\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x58\x00\x54\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x56\x00\x51\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x53\x00\x4e\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x4b\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x48\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x45\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x10\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x11\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x13\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x3b\x00\x14\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x39\x00\x15\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x16\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x17\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x18\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x32\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x34\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x36\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x38\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x3a\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x3c\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x40\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x44\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x4c\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x4f\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x52\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x55\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x59\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x5c\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x5f\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x66\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x7d\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x4b\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4c\x00\x16\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x36\x00\x1e\x00\x25\x00\x25\x00\x25\x00\x26\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x7e\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x4e\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x50\x00\x4f\x00\x15\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x37\x00\x38\x00\x1d\x00\x27\x00\x27\x00\x27\x00\x28\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x0c\x00\xff\xff\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x81\x00\x00\x00\x00\x00\x0c\x00\x0c\x00\x00\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x7f\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x00\x00\x0c\x00\x00\x00\x0c\x00\x0c\x00\x82\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x00\x00\x0c\x00\x00\x00\x0c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x48\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x4a\x00\x49\x00\x17\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x33\x00\x34\x00\x1f\x00\x23\x00\x23\x00\x23\x00\x24\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0c\x00\x00\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x00\x00\x00\x00\x0c\x00\x0c\x00\x00\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x80\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x00\x00\x0c\x00\x00\x00\x0c\x00\x0c\x00\x00\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x0c\x00\x00\x00\x0c\x00\x00\x00\x0c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x45\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x47\x00\x46\x00\x18\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x31\x00\x32\x00\x20\x00\x21\x00\x21\x00\x21\x00\x22\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x5e\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x5f\x00\x10\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x43\x00\x44\x00\x19\x00\x2f\x00\x2f\x00\x2f\x00\x30\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x62\x00\x00\x00\x7d\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x4b\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4d\x00\x4c\x00\x16\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x35\x00\x36\x00\x1e\x00\x25\x00\x25\x00\x25\x00\x26\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x8c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\x00\x00\x00\x00\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x00\x00\x00\x00\x00\x00\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\x00\x00\x00\x00\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x5b\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5d\x00\x5c\x00\x11\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x3f\x00\x40\x00\x1a\x00\x2d\x00\x2d\x00\x2d\x00\x2e\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"#
-
-alex_check :: AlexAddr
-alex_check = AlexA# "\xff\xff\x09\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x0a\x00\x09\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x09\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x3e\x00\x3e\x00\x3e\x00\x3e\x00\x3e\x00\x3e\x00\x3e\x00\x20\x00\x23\x00\xff\xff\xff\xff\xff\xff\xff\xff\x20\x00\xff\xff\x28\x00\xff\xff\x2a\x00\x20\x00\xff\xff\x2d\x00\xff\xff\xff\xff\x30\x00\x31\x00\x32\x00\x33\x00\x34\x00\x35\x00\x36\x00\x37\x00\x38\x00\x39\x00\xff\xff\xff\xff\xff\xff\xff\xff\x3e\x00\xff\xff\xff\xff\xff\xff\xff\xff\x29\x00\x3e\x00\xff\xff\xff\xff\xff\xff\xff\xff\x3e\x00\x30\x00\x31\x00\x32\x00\x33\x00\x34\x00\x35\x00\x36\x00\x37\x00\x38\x00\x39\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x5b\x00\x30\x00\x31\x00\x32\x00\x33\x00\x34\x00\x35\x00\x36\x00\x37\x00\x38\x00\x39\x00\xff\xff\x3b\x00\x30\x00\x31\x00\x32\x00\x33\x00\x34\x00\x35\x00\x36\x00\x37\x00\x38\x00\x39\x00\x2e\x00\xff\xff\x30\x00\x31\x00\x32\x00\x33\x00\x34\x00\x35\x00\x36\x00\x37\x00\x38\x00\x39\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x80\x00\x81\x00\x82\x00\x83\x00\x84\x00\x85\x00\x86\x00\x87\x00\x88\x00\x89\x00\x8a\x00\x8b\x00\x8c\x00\x8d\x00\x8e\x00\x8f\x00\x90\x00\x91\x00\x92\x00\x93\x00\x94\x00\x95\x00\x96\x00\x97\x00\x98\x00\x99\x00\x9a\x00\x9b\x00\x9c\x00\x9d\x00\x9e\x00\x9f\x00\xa0\x00\xa1\x00\xa2\x00\xa3\x00\xa4\x00\xa5\x00\xa6\x00\xa7\x00\xa8\x00\xa9\x00\xaa\x00\xab\x00\xac\x00\xad\x00\xae\x00\xaf\x00\xb0\x00\xb1\x00\xb2\x00\xb3\x00\xb4\x00\xb5\x00\xb6\x00\xb7\x00\xb8\x00\xb9\x00\xba\x00\xbb\x00\xbc\x00\xbd\x00\xbe\x00\xbf\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\x0a\x00\x30\x00\x31\x00\x32\x00\x33\x00\x34\x00\x35\x00\x36\x00\x37\x00\x38\x00\x39\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x09\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\xff\xff\xff\xff\xff\xff\x22\x00\x23\x00\xff\xff\xff\xff\x26\x00\x27\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x2f\x00\xff\xff\x20\x00\xff\xff\x58\x00\x09\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x28\x00\xff\xff\x2a\x00\x3c\x00\xff\xff\x2d\x00\xff\xff\x40\x00\x30\x00\x31\x00\x32\x00\x33\x00\x34\x00\x35\x00\x36\x00\x37\x00\x38\x00\x39\x00\x20\x00\xff\xff\xff\xff\xff\xff\x3e\x00\xff\xff\xff\xff\xff\xff\x78\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x5c\x00\x5d\x00\xff\xff\xff\xff\x60\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x3e\x00\xff\xff\xff\xff\x5b\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x80\x00\x81\x00\x82\x00\x83\x00\x84\x00\x85\x00\x86\x00\x87\x00\x88\x00\x89\x00\x8a\x00\x8b\x00\x8c\x00\x8d\x00\x8e\x00\x8f\x00\x90\x00\x91\x00\x92\x00\x93\x00\x94\x00\x95\x00\x96\x00\x97\x00\x98\x00\x99\x00\x9a\x00\x9b\x00\x9c\x00\x9d\x00\x9e\x00\x9f\x00\xa0\x00\xa1\x00\xa2\x00\xa3\x00\xa4\x00\xa5\x00\xa6\x00\xa7\x00\xa8\x00\xa9\x00\xaa\x00\xab\x00\xac\x00\xad\x00\xae\x00\xaf\x00\xb0\x00\xb1\x00\xb2\x00\xb3\x00\xb4\x00\xb5\x00\xb6\x00\xb7\x00\xb8\x00\xb9\x00\xba\x00\xbb\x00\xbc\x00\xbd\x00\xbe\x00\xbf\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\x0a\x00\x21\x00\xff\xff\x23\x00\x24\x00\x25\x00\x26\x00\x27\x00\xff\xff\xff\xff\x2a\x00\x2b\x00\xff\xff\x2d\x00\x2e\x00\x2f\x00\x30\x00\x31\x00\x32\x00\x33\x00\x34\x00\x35\x00\x36\x00\x37\x00\x38\x00\x39\x00\x3a\x00\xff\xff\x3c\x00\x3d\x00\x3e\x00\x3f\x00\x40\x00\x41\x00\x42\x00\x43\x00\x44\x00\x45\x00\x46\x00\x47\x00\x48\x00\x49\x00\x4a\x00\x4b\x00\x4c\x00\x4d\x00\x4e\x00\x4f\x00\x50\x00\x51\x00\x52\x00\x53\x00\x54\x00\x55\x00\x56\x00\x57\x00\x58\x00\x59\x00\x5a\x00\xff\xff\x5c\x00\xff\xff\x5e\x00\x5f\x00\x60\x00\x61\x00\x62\x00\x63\x00\x64\x00\x65\x00\x66\x00\x67\x00\x68\x00\x69\x00\x6a\x00\x6b\x00\x6c\x00\x6d\x00\x6e\x00\x6f\x00\x70\x00\x71\x00\x72\x00\x73\x00\x74\x00\x75\x00\x76\x00\x77\x00\x78\x00\x79\x00\x7a\x00\xff\xff\x7c\x00\xff\xff\x7e\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x80\x00\x81\x00\x82\x00\x83\x00\x84\x00\x85\x00\x86\x00\x87\x00\x88\x00\x89\x00\x8a\x00\x8b\x00\x8c\x00\x8d\x00\x8e\x00\x8f\x00\x90\x00\x91\x00\x92\x00\x93\x00\x94\x00\x95\x00\x96\x00\x97\x00\x98\x00\x99\x00\x9a\x00\x9b\x00\x9c\x00\x9d\x00\x9e\x00\x9f\x00\xa0\x00\xa1\x00\xa2\x00\xa3\x00\xa4\x00\xa5\x00\xa6\x00\xa7\x00\xa8\x00\xa9\x00\xaa\x00\xab\x00\xac\x00\xad\x00\xae\x00\xaf\x00\xb0\x00\xb1\x00\xb2\x00\xb3\x00\xb4\x00\xb5\x00\xb6\x00\xb7\x00\xb8\x00\xb9\x00\xba\x00\xbb\x00\xbc\x00\xbd\x00\xbe\x00\xbf\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\x0a\x00\x30\x00\x31\x00\x32\x00\x33\x00\x34\x00\x35\x00\x36\x00\x37\x00\x38\x00\x39\x00\xff\xff\x3b\x00\x09\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x41\x00\x42\x00\x43\x00\x44\x00\x45\x00\x46\x00\x30\x00\x31\x00\x32\x00\x33\x00\x34\x00\x35\x00\x36\x00\x37\x00\x38\x00\x39\x00\xff\xff\xff\xff\x20\x00\xff\xff\xff\xff\xff\xff\xff\xff\x41\x00\x42\x00\x43\x00\x44\x00\x45\x00\x46\x00\xff\xff\xff\xff\xff\xff\x61\x00\x62\x00\x63\x00\x64\x00\x65\x00\x66\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x3e\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x61\x00\x62\x00\x63\x00\x64\x00\x65\x00\x66\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x80\x00\x81\x00\x82\x00\x83\x00\x84\x00\x85\x00\x86\x00\x87\x00\x88\x00\x89\x00\x8a\x00\x8b\x00\x8c\x00\x8d\x00\x8e\x00\x8f\x00\x90\x00\x91\x00\x92\x00\x93\x00\x94\x00\x95\x00\x96\x00\x97\x00\x98\x00\x99\x00\x9a\x00\x9b\x00\x9c\x00\x9d\x00\x9e\x00\x9f\x00\xa0\x00\xa1\x00\xa2\x00\xa3\x00\xa4\x00\xa5\x00\xa6\x00\xa7\x00\xa8\x00\xa9\x00\xaa\x00\xab\x00\xac\x00\xad\x00\xae\x00\xaf\x00\xb0\x00\xb1\x00\xb2\x00\xb3\x00\xb4\x00\xb5\x00\xb6\x00\xb7\x00\xb8\x00\xb9\x00\xba\x00\xbb\x00\xbc\x00\xbd\x00\xbe\x00\xbf\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\x0a\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x22\x00\x23\x00\xff\xff\xff\xff\x26\x00\x27\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x2f\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x3c\x00\xff\xff\xff\xff\xff\xff\x40\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x5c\x00\x5d\x00\xff\xff\xff\xff\x60\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x80\x00\x81\x00\x82\x00\x83\x00\x84\x00\x85\x00\x86\x00\x87\x00\x88\x00\x89\x00\x8a\x00\x8b\x00\x8c\x00\x8d\x00\x8e\x00\x8f\x00\x90\x00\x91\x00\x92\x00\x93\x00\x94\x00\x95\x00\x96\x00\x97\x00\x98\x00\x99\x00\x9a\x00\x9b\x00\x9c\x00\x9d\x00\x9e\x00\x9f\x00\xa0\x00\xa1\x00\xa2\x00\xa3\x00\xa4\x00\xa5\x00\xa6\x00\xa7\x00\xa8\x00\xa9\x00\xaa\x00\xab\x00\xac\x00\xad\x00\xae\x00\xaf\x00\xb0\x00\xb1\x00\xb2\x00\xb3\x00\xb4\x00\xb5\x00\xb6\x00\xb7\x00\xb8\x00\xb9\x00\xba\x00\xbb\x00\xbc\x00\xbd\x00\xbe\x00\xbf\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\x0a\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x23\x00\xbf\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x80\x00\x81\x00\x82\x00\x83\x00\x84\x00\x85\x00\x86\x00\x87\x00\x88\x00\x89\x00\x8a\x00\x8b\x00\x8c\x00\x8d\x00\x8e\x00\x8f\x00\x90\x00\x91\x00\x92\x00\x93\x00\x94\x00\x95\x00\x96\x00\x97\x00\x98\x00\x99\x00\x9a\x00\x9b\x00\x9c\x00\x9d\x00\x9e\x00\x9f\x00\xa0\x00\xa1\x00\xa2\x00\xa3\x00\xa4\x00\xa5\x00\xa6\x00\xa7\x00\xa8\x00\xa9\x00\xaa\x00\xab\x00\xac\x00\xad\x00\xae\x00\xaf\x00\xb0\x00\xb1\x00\xb2\x00\xb3\x00\xb4\x00\xb5\x00\xb6\x00\xb7\x00\xb8\x00\xb9\x00\xba\x00\xbb\x00\xbc\x00\xbd\x00\xbe\x00\xbf\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\x0a\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x2f\x00\xbf\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x80\x00\x81\x00\x82\x00\x83\x00\x84\x00\x85\x00\x86\x00\x87\x00\x88\x00\x89\x00\x8a\x00\x8b\x00\x8c\x00\x8d\x00\x8e\x00\x8f\x00\x90\x00\x91\x00\x92\x00\x93\x00\x94\x00\x95\x00\x96\x00\x97\x00\x98\x00\x99\x00\x9a\x00\x9b\x00\x9c\x00\x9d\x00\x9e\x00\x9f\x00\xa0\x00\xa1\x00\xa2\x00\xa3\x00\xa4\x00\xa5\x00\xa6\x00\xa7\x00\xa8\x00\xa9\x00\xaa\x00\xab\x00\xac\x00\xad\x00\xae\x00\xaf\x00\xb0\x00\xb1\x00\xb2\x00\xb3\x00\xb4\x00\xb5\x00\xb6\x00\xb7\x00\xb8\x00\xb9\x00\xba\x00\xbb\x00\xbc\x00\xbd\x00\xbe\x00\xbf\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\x80\x00\x81\x00\x82\x00\x83\x00\x84\x00\x85\x00\x86\x00\x87\x00\x88\x00\x89\x00\x8a\x00\x8b\x00\x8c\x00\x8d\x00\x8e\x00\x8f\x00\x90\x00\x91\x00\x92\x00\x93\x00\x94\x00\x95\x00\x96\x00\x97\x00\x98\x00\x99\x00\x9a\x00\x9b\x00\x9c\x00\x9d\x00\x9e\x00\x9f\x00\xa0\x00\xa1\x00\xa2\x00\xa3\x00\xa4\x00\xa5\x00\xa6\x00\xa7\x00\xa8\x00\xa9\x00\xaa\x00\xab\x00\xac\x00\xad\x00\xae\x00\xaf\x00\xb0\x00\xb1\x00\xb2\x00\xb3\x00\xb4\x00\xb5\x00\xb6\x00\xb7\x00\xb8\x00\xb9\x00\xba\x00\xbb\x00\xbc\x00\xbd\x00\xbe\x00\xbf\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\x80\x00\x81\x00\x82\x00\x83\x00\x84\x00\x85\x00\x86\x00\x87\x00\x88\x00\x89\x00\x8a\x00\x8b\x00\x8c\x00\x8d\x00\x8e\x00\x8f\x00\x90\x00\x91\x00\x92\x00\x93\x00\x94\x00\x95\x00\x96\x00\x97\x00\x98\x00\x99\x00\x9a\x00\x9b\x00\x9c\x00\x9d\x00\x9e\x00\x9f\x00\xa0\x00\xa1\x00\xa2\x00\xa3\x00\xa4\x00\xa5\x00\xa6\x00\xa7\x00\xa8\x00\xa9\x00\xaa\x00\xab\x00\xac\x00\xad\x00\xae\x00\xaf\x00\xb0\x00\xb1\x00\xb2\x00\xb3\x00\xb4\x00\xb5\x00\xb6\x00\xb7\x00\xb8\x00\xb9\x00\xba\x00\xbb\x00\xbc\x00\xbd\x00\xbe\x00\xbf\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\x80\x00\x81\x00\x82\x00\x83\x00\x84\x00\x85\x00\x86\x00\x87\x00\x88\x00\x89\x00\x8a\x00\x8b\x00\x8c\x00\x8d\x00\x8e\x00\x8f\x00\x90\x00\x91\x00\x92\x00\x93\x00\x94\x00\x95\x00\x96\x00\x97\x00\x98\x00\x99\x00\x9a\x00\x9b\x00\x9c\x00\x9d\x00\x9e\x00\x9f\x00\xa0\x00\xa1\x00\xa2\x00\xa3\x00\xa4\x00\xa5\x00\xa6\x00\xa7\x00\xa8\x00\xa9\x00\xaa\x00\xab\x00\xac\x00\xad\x00\xae\x00\xaf\x00\xb0\x00\xb1\x00\xb2\x00\xb3\x00\xb4\x00\xb5\x00\xb6\x00\xb7\x00\xb8\x00\xb9\x00\xba\x00\xbb\x00\xbc\x00\xbd\x00\xbe\x00\xbf\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\x80\x00\x81\x00\x82\x00\x83\x00\x84\x00\x85\x00\x86\x00\x87\x00\x88\x00\x89\x00\x8a\x00\x8b\x00\x8c\x00\x8d\x00\x8e\x00\x8f\x00\x90\x00\x91\x00\x92\x00\x93\x00\x94\x00\x95\x00\x96\x00\x97\x00\x98\x00\x99\x00\x9a\x00\x9b\x00\x9c\x00\x9d\x00\x9e\x00\x9f\x00\xa0\x00\xa1\x00\xa2\x00\xa3\x00\xa4\x00\xa5\x00\xa6\x00\xa7\x00\xa8\x00\xa9\x00\xaa\x00\xab\x00\xac\x00\xad\x00\xae\x00\xaf\x00\xb0\x00\xb1\x00\xb2\x00\xb3\x00\xb4\x00\xb5\x00\xb6\x00\xb7\x00\xb8\x00\xb9\x00\xba\x00\xbb\x00\xbc\x00\xbd\x00\xbe\x00\xbf\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\x80\x00\x81\x00\x82\x00\x83\x00\x84\x00\x85\x00\x86\x00\x87\x00\x88\x00\x89\x00\x8a\x00\x8b\x00\x8c\x00\x8d\x00\x8e\x00\x8f\x00\x90\x00\x91\x00\x92\x00\x93\x00\x94\x00\x95\x00\x96\x00\x97\x00\x98\x00\x99\x00\x9a\x00\x9b\x00\x9c\x00\x9d\x00\x9e\x00\x9f\x00\xa0\x00\xa1\x00\xa2\x00\xa3\x00\xa4\x00\xa5\x00\xa6\x00\xa7\x00\xa8\x00\xa9\x00\xaa\x00\xab\x00\xac\x00\xad\x00\xae\x00\xaf\x00\xb0\x00\xb1\x00\xb2\x00\xb3\x00\xb4\x00\xb5\x00\xb6\x00\xb7\x00\xb8\x00\xb9\x00\xba\x00\xbb\x00\xbc\x00\xbd\x00\xbe\x00\xbf\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\x80\x00\x81\x00\x82\x00\x83\x00\x84\x00\x85\x00\x86\x00\x87\x00\x88\x00\x89\x00\x8a\x00\x8b\x00\x8c\x00\x8d\x00\x8e\x00\x8f\x00\x90\x00\x91\x00\x92\x00\x93\x00\x94\x00\x95\x00\x96\x00\x97\x00\x98\x00\x99\x00\x9a\x00\x9b\x00\x9c\x00\x9d\x00\x9e\x00\x9f\x00\xa0\x00\xa1\x00\xa2\x00\xa3\x00\xa4\x00\xa5\x00\xa6\x00\xa7\x00\xa8\x00\xa9\x00\xaa\x00\xab\x00\xac\x00\xad\x00\xae\x00\xaf\x00\xb0\x00\xb1\x00\xb2\x00\xb3\x00\xb4\x00\xb5\x00\xb6\x00\xb7\x00\xb8\x00\xb9\x00\xba\x00\xbb\x00\xbc\x00\xbd\x00\xbe\x00\xbf\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\x80\x00\x81\x00\x82\x00\x83\x00\x84\x00\x85\x00\x86\x00\x87\x00\x88\x00\x89\x00\x8a\x00\x8b\x00\x8c\x00\x8d\x00\x8e\x00\x8f\x00\x90\x00\x91\x00\x92\x00\x93\x00\x94\x00\x95\x00\x96\x00\x97\x00\x98\x00\x99\x00\x9a\x00\x9b\x00\x9c\x00\x9d\x00\x9e\x00\x9f\x00\xa0\x00\xa1\x00\xa2\x00\xa3\x00\xa4\x00\xa5\x00\xa6\x00\xa7\x00\xa8\x00\xa9\x00\xaa\x00\xab\x00\xac\x00\xad\x00\xae\x00\xaf\x00\xb0\x00\xb1\x00\xb2\x00\xb3\x00\xb4\x00\xb5\x00\xb6\x00\xb7\x00\xb8\x00\xb9\x00\xba\x00\xbb\x00\xbc\x00\xbd\x00\xbe\x00\xbf\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\x80\x00\x81\x00\x82\x00\x83\x00\x84\x00\x85\x00\x86\x00\x87\x00\x88\x00\x89\x00\x8a\x00\x8b\x00\x8c\x00\x8d\x00\x8e\x00\x8f\x00\x90\x00\x91\x00\x92\x00\x93\x00\x94\x00\x95\x00\x96\x00\x97\x00\x98\x00\x99\x00\x9a\x00\x9b\x00\x9c\x00\x9d\x00\x9e\x00\x9f\x00\xa0\x00\xa1\x00\xa2\x00\xa3\x00\xa4\x00\xa5\x00\xa6\x00\xa7\x00\xa8\x00\xa9\x00\xaa\x00\xab\x00\xac\x00\xad\x00\xae\x00\xaf\x00\xb0\x00\xb1\x00\xb2\x00\xb3\x00\xb4\x00\xb5\x00\xb6\x00\xb7\x00\xb8\x00\xb9\x00\xba\x00\xbb\x00\xbc\x00\xbd\x00\xbe\x00\xbf\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\x80\x00\x81\x00\x82\x00\x83\x00\x84\x00\x85\x00\x86\x00\x87\x00\x88\x00\x89\x00\x8a\x00\x8b\x00\x8c\x00\x8d\x00\x8e\x00\x8f\x00\x90\x00\x91\x00\x92\x00\x93\x00\x94\x00\x95\x00\x96\x00\x97\x00\x98\x00\x99\x00\x9a\x00\x9b\x00\x9c\x00\x9d\x00\x9e\x00\x9f\x00\xa0\x00\xa1\x00\xa2\x00\xa3\x00\xa4\x00\xa5\x00\xa6\x00\xa7\x00\xa8\x00\xa9\x00\xaa\x00\xab\x00\xac\x00\xad\x00\xae\x00\xaf\x00\xb0\x00\xb1\x00\xb2\x00\xb3\x00\xb4\x00\xb5\x00\xb6\x00\xb7\x00\xb8\x00\xb9\x00\xba\x00\xbb\x00\xbc\x00\xbd\x00\xbe\x00\xbf\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\x80\x00\x81\x00\x82\x00\x83\x00\x84\x00\x85\x00\x86\x00\x87\x00\x88\x00\x89\x00\x8a\x00\x8b\x00\x8c\x00\x8d\x00\x8e\x00\x8f\x00\x90\x00\x91\x00\x92\x00\x93\x00\x94\x00\x95\x00\x96\x00\x97\x00\x98\x00\x99\x00\x9a\x00\x9b\x00\x9c\x00\x9d\x00\x9e\x00\x9f\x00\xa0\x00\xa1\x00\xa2\x00\xa3\x00\xa4\x00\xa5\x00\xa6\x00\xa7\x00\xa8\x00\xa9\x00\xaa\x00\xab\x00\xac\x00\xad\x00\xae\x00\xaf\x00\xb0\x00\xb1\x00\xb2\x00\xb3\x00\xb4\x00\xb5\x00\xb6\x00\xb7\x00\xb8\x00\xb9\x00\xba\x00\xbb\x00\xbc\x00\xbd\x00\xbe\x00\xbf\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\x80\x00\x81\x00\x82\x00\x83\x00\x84\x00\x85\x00\x86\x00\x87\x00\x88\x00\x89\x00\x8a\x00\x8b\x00\x8c\x00\x8d\x00\x8e\x00\x8f\x00\x90\x00\x91\x00\x92\x00\x93\x00\x94\x00\x95\x00\x96\x00\x97\x00\x98\x00\x99\x00\x9a\x00\x9b\x00\x9c\x00\x9d\x00\x9e\x00\x9f\x00\xa0\x00\xa1\x00\xa2\x00\xa3\x00\xa4\x00\xa5\x00\xa6\x00\xa7\x00\xa8\x00\xa9\x00\xaa\x00\xab\x00\xac\x00\xad\x00\xae\x00\xaf\x00\xb0\x00\xb1\x00\xb2\x00\xb3\x00\xb4\x00\xb5\x00\xb6\x00\xb7\x00\xb8\x00\xb9\x00\xba\x00\xbb\x00\xbc\x00\xbd\x00\xbe\x00\xbf\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\x80\x00\x81\x00\x82\x00\x83\x00\x84\x00\x85\x00\x86\x00\x87\x00\x88\x00\x89\x00\x8a\x00\x8b\x00\x8c\x00\x8d\x00\x8e\x00\x8f\x00\x90\x00\x91\x00\x92\x00\x93\x00\x94\x00\x95\x00\x96\x00\x97\x00\x98\x00\x99\x00\x9a\x00\x9b\x00\x9c\x00\x9d\x00\x9e\x00\x9f\x00\xa0\x00\xa1\x00\xa2\x00\xa3\x00\xa4\x00\xa5\x00\xa6\x00\xa7\x00\xa8\x00\xa9\x00\xaa\x00\xab\x00\xac\x00\xad\x00\xae\x00\xaf\x00\xb0\x00\xb1\x00\xb2\x00\xb3\x00\xb4\x00\xb5\x00\xb6\x00\xb7\x00\xb8\x00\xb9\x00\xba\x00\xbb\x00\xbc\x00\xbd\x00\xbe\x00\xbf\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\x80\x00\x81\x00\x82\x00\x83\x00\x84\x00\x85\x00\x86\x00\x87\x00\x88\x00\x89\x00\x8a\x00\x8b\x00\x8c\x00\x8d\x00\x8e\x00\x8f\x00\x90\x00\x91\x00\x92\x00\x93\x00\x94\x00\x95\x00\x96\x00\x97\x00\x98\x00\x99\x00\x9a\x00\x9b\x00\x9c\x00\x9d\x00\x9e\x00\x9f\x00\xa0\x00\xa1\x00\xa2\x00\xa3\x00\xa4\x00\xa5\x00\xa6\x00\xa7\x00\xa8\x00\xa9\x00\xaa\x00\xab\x00\xac\x00\xad\x00\xae\x00\xaf\x00\xb0\x00\xb1\x00\xb2\x00\xb3\x00\xb4\x00\xb5\x00\xb6\x00\xb7\x00\xb8\x00\xb9\x00\xba\x00\xbb\x00\xbc\x00\xbd\x00\xbe\x00\xbf\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\x80\x00\x81\x00\x82\x00\x83\x00\x84\x00\x85\x00\x86\x00\x87\x00\x88\x00\x89\x00\x8a\x00\x8b\x00\x8c\x00\x8d\x00\x8e\x00\x8f\x00\x90\x00\x91\x00\x92\x00\x93\x00\x94\x00\x95\x00\x96\x00\x97\x00\x98\x00\x99\x00\x9a\x00\x9b\x00\x9c\x00\x9d\x00\x9e\x00\x9f\x00\xa0\x00\xa1\x00\xa2\x00\xa3\x00\xa4\x00\xa5\x00\xa6\x00\xa7\x00\xa8\x00\xa9\x00\xaa\x00\xab\x00\xac\x00\xad\x00\xae\x00\xaf\x00\xb0\x00\xb1\x00\xb2\x00\xb3\x00\xb4\x00\xb5\x00\xb6\x00\xb7\x00\xb8\x00\xb9\x00\xba\x00\xbb\x00\xbc\x00\xbd\x00\xbe\x00\xbf\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\x80\x00\x81\x00\x82\x00\x83\x00\x84\x00\x85\x00\x86\x00\x87\x00\x88\x00\x89\x00\x8a\x00\x8b\x00\x8c\x00\x8d\x00\x8e\x00\x8f\x00\x90\x00\x91\x00\x92\x00\x93\x00\x94\x00\x95\x00\x96\x00\x97\x00\x98\x00\x99\x00\x9a\x00\x9b\x00\x9c\x00\x9d\x00\x9e\x00\x9f\x00\xa0\x00\xa1\x00\xa2\x00\xa3\x00\xa4\x00\xa5\x00\xa6\x00\xa7\x00\xa8\x00\xa9\x00\xaa\x00\xab\x00\xac\x00\xad\x00\xae\x00\xaf\x00\xb0\x00\xb1\x00\xb2\x00\xb3\x00\xb4\x00\xb5\x00\xb6\x00\xb7\x00\xb8\x00\xb9\x00\xba\x00\xbb\x00\xbc\x00\xbd\x00\xbe\x00\xbf\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\x80\x00\x81\x00\x82\x00\x83\x00\x84\x00\x85\x00\x86\x00\x87\x00\x88\x00\x89\x00\x8a\x00\x8b\x00\x8c\x00\x8d\x00\x8e\x00\x8f\x00\x90\x00\x91\x00\x92\x00\x93\x00\x94\x00\x95\x00\x96\x00\x97\x00\x98\x00\x99\x00\x9a\x00\x9b\x00\x9c\x00\x9d\x00\x9e\x00\x9f\x00\xa0\x00\xa1\x00\xa2\x00\xa3\x00\xa4\x00\xa5\x00\xa6\x00\xa7\x00\xa8\x00\xa9\x00\xaa\x00\xab\x00\xac\x00\xad\x00\xae\x00\xaf\x00\xb0\x00\xb1\x00\xb2\x00\xb3\x00\xb4\x00\xb5\x00\xb6\x00\xb7\x00\xb8\x00\xb9\x00\xba\x00\xbb\x00\xbc\x00\xbd\x00\xbe\x00\xbf\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\x80\x00\x81\x00\x82\x00\x83\x00\x84\x00\x85\x00\x86\x00\x87\x00\x88\x00\x89\x00\x8a\x00\x8b\x00\x8c\x00\x8d\x00\x8e\x00\x8f\x00\x90\x00\x91\x00\x92\x00\x93\x00\x94\x00\x95\x00\x96\x00\x97\x00\x98\x00\x99\x00\x9a\x00\x9b\x00\x9c\x00\x9d\x00\x9e\x00\x9f\x00\xa0\x00\xa1\x00\xa2\x00\xa3\x00\xa4\x00\xa5\x00\xa6\x00\xa7\x00\xa8\x00\xa9\x00\xaa\x00\xab\x00\xac\x00\xad\x00\xae\x00\xaf\x00\xb0\x00\xb1\x00\xb2\x00\xb3\x00\xb4\x00\xb5\x00\xb6\x00\xb7\x00\xb8\x00\xb9\x00\xba\x00\xbb\x00\xbc\x00\xbd\x00\xbe\x00\xbf\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\x80\x00\x81\x00\x82\x00\x83\x00\x84\x00\x85\x00\x86\x00\x87\x00\x88\x00\x89\x00\x8a\x00\x8b\x00\x8c\x00\x8d\x00\x8e\x00\x8f\x00\x90\x00\x91\x00\x92\x00\x93\x00\x94\x00\x95\x00\x96\x00\x97\x00\x98\x00\x99\x00\x9a\x00\x9b\x00\x9c\x00\x9d\x00\x9e\x00\x9f\x00\xa0\x00\xa1\x00\xa2\x00\xa3\x00\xa4\x00\xa5\x00\xa6\x00\xa7\x00\xa8\x00\xa9\x00\xaa\x00\xab\x00\xac\x00\xad\x00\xae\x00\xaf\x00\xb0\x00\xb1\x00\xb2\x00\xb3\x00\xb4\x00\xb5\x00\xb6\x00\xb7\x00\xb8\x00\xb9\x00\xba\x00\xbb\x00\xbc\x00\xbd\x00\xbe\x00\xbf\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\x8f\x00\x90\x00\x91\x00\x92\x00\x93\x00\x94\x00\x95\x00\x96\x00\x97\x00\x98\x00\x99\x00\x9a\x00\x9b\x00\x9c\x00\x9d\x00\x9e\x00\x9f\x00\xa0\x00\xa1\x00\xa2\x00\xa3\x00\xa4\x00\xa5\x00\xa6\x00\xa7\x00\xa8\x00\xa9\x00\xaa\x00\xab\x00\xac\x00\xad\x00\xae\x00\xaf\x00\xb0\x00\xb1\x00\xb2\x00\xb3\x00\xb4\x00\xb5\x00\xb6\x00\xb7\x00\xb8\x00\xb9\x00\xba\x00\xbb\x00\xbc\x00\xbd\x00\xbe\x00\xbf\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\x8f\x00\x90\x00\x91\x00\x92\x00\x93\x00\x94\x00\x95\x00\x96\x00\x97\x00\x98\x00\x99\x00\x9a\x00\x9b\x00\x9c\x00\x9d\x00\x9e\x00\x9f\x00\xa0\x00\xa1\x00\xa2\x00\xa3\x00\xa4\x00\xa5\x00\xa6\x00\xa7\x00\xa8\x00\xa9\x00\xaa\x00\xab\x00\xac\x00\xad\x00\xae\x00\xaf\x00\xb0\x00\xb1\x00\xb2\x00\xb3\x00\xb4\x00\xb5\x00\xb6\x00\xb7\x00\xb8\x00\xb9\x00\xba\x00\xbb\x00\xbc\x00\xbd\x00\xbe\x00\xbf\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\x8f\x00\x90\x00\x91\x00\x92\x00\x93\x00\x94\x00\x95\x00\x96\x00\x97\x00\x98\x00\x99\x00\x9a\x00\x9b\x00\x9c\x00\x9d\x00\x9e\x00\x9f\x00\xa0\x00\xa1\x00\xa2\x00\xa3\x00\xa4\x00\xa5\x00\xa6\x00\xa7\x00\xa8\x00\xa9\x00\xaa\x00\xab\x00\xac\x00\xad\x00\xae\x00\xaf\x00\xb0\x00\xb1\x00\xb2\x00\xb3\x00\xb4\x00\xb5\x00\xb6\x00\xb7\x00\xb8\x00\xb9\x00\xba\x00\xbb\x00\xbc\x00\xbd\x00\xbe\x00\xbf\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\x8f\x00\x90\x00\x91\x00\x92\x00\x93\x00\x94\x00\x95\x00\x96\x00\x97\x00\x98\x00\x99\x00\x9a\x00\x9b\x00\x9c\x00\x9d\x00\x9e\x00\x9f\x00\xa0\x00\xa1\x00\xa2\x00\xa3\x00\xa4\x00\xa5\x00\xa6\x00\xa7\x00\xa8\x00\xa9\x00\xaa\x00\xab\x00\xac\x00\xad\x00\xae\x00\xaf\x00\xb0\x00\xb1\x00\xb2\x00\xb3\x00\xb4\x00\xb5\x00\xb6\x00\xb7\x00\xb8\x00\xb9\x00\xba\x00\xbb\x00\xbc\x00\xbd\x00\xbe\x00\xbf\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\x8f\x00\x90\x00\x91\x00\x92\x00\x93\x00\x94\x00\x95\x00\x96\x00\x97\x00\x98\x00\x99\x00\x9a\x00\x9b\x00\x9c\x00\x9d\x00\x9e\x00\x9f\x00\xa0\x00\xa1\x00\xa2\x00\xa3\x00\xa4\x00\xa5\x00\xa6\x00\xa7\x00\xa8\x00\xa9\x00\xaa\x00\xab\x00\xac\x00\xad\x00\xae\x00\xaf\x00\xb0\x00\xb1\x00\xb2\x00\xb3\x00\xb4\x00\xb5\x00\xb6\x00\xb7\x00\xb8\x00\xb9\x00\xba\x00\xbb\x00\xbc\x00\xbd\x00\xbe\x00\xbf\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\x8f\x00\x90\x00\x91\x00\x92\x00\x93\x00\x94\x00\x95\x00\x96\x00\x97\x00\x98\x00\x99\x00\x9a\x00\x9b\x00\x9c\x00\x9d\x00\x9e\x00\x9f\x00\xa0\x00\xa1\x00\xa2\x00\xa3\x00\xa4\x00\xa5\x00\xa6\x00\xa7\x00\xa8\x00\xa9\x00\xaa\x00\xab\x00\xac\x00\xad\x00\xae\x00\xaf\x00\xb0\x00\xb1\x00\xb2\x00\xb3\x00\xb4\x00\xb5\x00\xb6\x00\xb7\x00\xb8\x00\xb9\x00\xba\x00\xbb\x00\xbc\x00\xbd\x00\xbe\x00\xbf\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\x8f\x00\x90\x00\x91\x00\x92\x00\x93\x00\x94\x00\x95\x00\x96\x00\x97\x00\x98\x00\x99\x00\x9a\x00\x9b\x00\x9c\x00\x9d\x00\x9e\x00\x9f\x00\xa0\x00\xa1\x00\xa2\x00\xa3\x00\xa4\x00\xa5\x00\xa6\x00\xa7\x00\xa8\x00\xa9\x00\xaa\x00\xab\x00\xac\x00\xad\x00\xae\x00\xaf\x00\xb0\x00\xb1\x00\xb2\x00\xb3\x00\xb4\x00\xb5\x00\xb6\x00\xb7\x00\xb8\x00\xb9\x00\xba\x00\xbb\x00\xbc\x00\xbd\x00\xbe\x00\xbf\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\x8f\x00\x90\x00\x91\x00\x92\x00\x93\x00\x94\x00\x95\x00\x96\x00\x97\x00\x98\x00\x99\x00\x9a\x00\x9b\x00\x9c\x00\x9d\x00\x9e\x00\x9f\x00\xa0\x00\xa1\x00\xa2\x00\xa3\x00\xa4\x00\xa5\x00\xa6\x00\xa7\x00\xa8\x00\xa9\x00\xaa\x00\xab\x00\xac\x00\xad\x00\xae\x00\xaf\x00\xb0\x00\xb1\x00\xb2\x00\xb3\x00\xb4\x00\xb5\x00\xb6\x00\xb7\x00\xb8\x00\xb9\x00\xba\x00\xbb\x00\xbc\x00\xbd\x00\xbe\x00\xbf\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\xbf\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\xbf\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\xbf\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\xbf\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\x8f\x00\x90\x00\x91\x00\x92\x00\x93\x00\x94\x00\x95\x00\x96\x00\x97\x00\x98\x00\x99\x00\x9a\x00\x9b\x00\x9c\x00\x9d\x00\x9e\x00\x9f\x00\xa0\x00\xa1\x00\xa2\x00\xa3\x00\xa4\x00\xa5\x00\xa6\x00\xa7\x00\xa8\x00\xa9\x00\xaa\x00\xab\x00\xac\x00\xad\x00\xae\x00\xaf\x00\xb0\x00\xb1\x00\xb2\x00\xb3\x00\xb4\x00\xb5\x00\xb6\x00\xb7\x00\xb8\x00\xb9\x00\xba\x00\xbb\x00\xbc\x00\xbd\x00\xbe\x00\xbf\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\xbf\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\xbf\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\x00\x00\x01\x00\x02\x00\x03\x00\x04\x00\x05\x00\x06\x00\x07\x00\x08\x00\x09\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x0e\x00\x0f\x00\x10\x00\x11\x00\x12\x00\x13\x00\x14\x00\x15\x00\x16\x00\x17\x00\x18\x00\x19\x00\x1a\x00\x1b\x00\x1c\x00\x1d\x00\x1e\x00\x1f\x00\x20\x00\x21\x00\x22\x00\x23\x00\x24\x00\x25\x00\x26\x00\x27\x00\x28\x00\x29\x00\x2a\x00\x2b\x00\x2c\x00\x2d\x00\x2e\x00\x2f\x00\x30\x00\x31\x00\x32\x00\x33\x00\x34\x00\x35\x00\x36\x00\x37\x00\x38\x00\x39\x00\x3a\x00\x3b\x00\x3c\x00\x3d\x00\x3e\x00\x3f\x00\x40\x00\x41\x00\x42\x00\x43\x00\x44\x00\x45\x00\x46\x00\x47\x00\x48\x00\x49\x00\x4a\x00\x4b\x00\x4c\x00\x4d\x00\x4e\x00\x4f\x00\x50\x00\x51\x00\x52\x00\x53\x00\x54\x00\x55\x00\x56\x00\x57\x00\x58\x00\x59\x00\x5a\x00\x5b\x00\x5c\x00\x5d\x00\x5e\x00\x5f\x00\x60\x00\x61\x00\x62\x00\x63\x00\x64\x00\x65\x00\x66\x00\x67\x00\x68\x00\x69\x00\x6a\x00\x6b\x00\x6c\x00\x6d\x00\x6e\x00\x6f\x00\x70\x00\x71\x00\x72\x00\x73\x00\x74\x00\x75\x00\x76\x00\x77\x00\x78\x00\x79\x00\x7a\x00\x7b\x00\x7c\x00\x7d\x00\x7e\x00\x7f\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\x00\x00\x01\x00\x02\x00\x03\x00\x04\x00\x05\x00\x06\x00\x07\x00\x08\x00\x09\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x0e\x00\x0f\x00\x10\x00\x11\x00\x12\x00\x13\x00\x14\x00\x15\x00\x16\x00\x17\x00\x18\x00\x19\x00\x1a\x00\x1b\x00\x1c\x00\x1d\x00\x1e\x00\x1f\x00\x20\x00\x21\x00\x22\x00\x23\x00\x24\x00\x25\x00\x26\x00\x27\x00\x28\x00\x29\x00\x2a\x00\x2b\x00\x2c\x00\x2d\x00\x2e\x00\x2f\x00\x30\x00\x31\x00\x32\x00\x33\x00\x34\x00\x35\x00\x36\x00\x37\x00\x38\x00\x39\x00\x3a\x00\x3b\x00\x3c\x00\x3d\x00\x3e\x00\x3f\x00\x40\x00\x41\x00\x42\x00\x43\x00\x44\x00\x45\x00\x46\x00\x47\x00\x48\x00\x49\x00\x4a\x00\x4b\x00\x4c\x00\x4d\x00\x4e\x00\x4f\x00\x50\x00\x51\x00\x52\x00\x53\x00\x54\x00\x55\x00\x56\x00\x57\x00\x58\x00\x59\x00\x5a\x00\x5b\x00\x5c\x00\x5d\x00\x5e\x00\x5f\x00\x60\x00\x61\x00\x62\x00\x63\x00\x64\x00\x65\x00\x66\x00\x67\x00\x68\x00\x69\x00\x6a\x00\x6b\x00\x6c\x00\x6d\x00\x6e\x00\x6f\x00\x70\x00\x71\x00\x72\x00\x73\x00\x74\x00\x75\x00\x76\x00\x77\x00\x78\x00\x79\x00\x7a\x00\x7b\x00\x7c\x00\x7d\x00\x7e\x00\x7f\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\x00\x00\x01\x00\x02\x00\x03\x00\x04\x00\x05\x00\x06\x00\x07\x00\x08\x00\x09\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x0e\x00\x0f\x00\x10\x00\x11\x00\x12\x00\x13\x00\x14\x00\x15\x00\x16\x00\x17\x00\x18\x00\x19\x00\x1a\x00\x1b\x00\x1c\x00\x1d\x00\x1e\x00\x1f\x00\x20\x00\x21\x00\x22\x00\x23\x00\x24\x00\x25\x00\x26\x00\x27\x00\x28\x00\x29\x00\x2a\x00\x2b\x00\x2c\x00\x2d\x00\x2e\x00\x2f\x00\x30\x00\x31\x00\x32\x00\x33\x00\x34\x00\x35\x00\x36\x00\x37\x00\x38\x00\x39\x00\x3a\x00\x3b\x00\x3c\x00\x3d\x00\x3e\x00\x3f\x00\x40\x00\x41\x00\x42\x00\x43\x00\x44\x00\x45\x00\x46\x00\x47\x00\x48\x00\x49\x00\x4a\x00\x4b\x00\x4c\x00\x4d\x00\x4e\x00\x4f\x00\x50\x00\x51\x00\x52\x00\x53\x00\x54\x00\x55\x00\x56\x00\x57\x00\x58\x00\x59\x00\x5a\x00\x5b\x00\x5c\x00\x5d\x00\x5e\x00\x5f\x00\x60\x00\x61\x00\x62\x00\x63\x00\x64\x00\x65\x00\x66\x00\x67\x00\x68\x00\x69\x00\x6a\x00\x6b\x00\x6c\x00\x6d\x00\x6e\x00\x6f\x00\x70\x00\x71\x00\x72\x00\x73\x00\x74\x00\x75\x00\x76\x00\x77\x00\x78\x00\x79\x00\x7a\x00\x7b\x00\x7c\x00\x7d\x00\x7e\x00\x7f\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\x00\x00\x01\x00\x02\x00\x03\x00\x04\x00\x05\x00\x06\x00\x07\x00\x08\x00\x09\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x0e\x00\x0f\x00\x10\x00\x11\x00\x12\x00\x13\x00\x14\x00\x15\x00\x16\x00\x17\x00\x18\x00\x19\x00\x1a\x00\x1b\x00\x1c\x00\x1d\x00\x1e\x00\x1f\x00\x20\x00\x21\x00\x22\x00\x23\x00\x24\x00\x25\x00\x26\x00\x27\x00\x28\x00\x29\x00\x2a\x00\x2b\x00\x2c\x00\x2d\x00\x2e\x00\x2f\x00\x30\x00\x31\x00\x32\x00\x33\x00\x34\x00\x35\x00\x36\x00\x37\x00\x38\x00\x39\x00\x3a\x00\x3b\x00\x3c\x00\x3d\x00\x3e\x00\x3f\x00\x40\x00\x41\x00\x42\x00\x43\x00\x44\x00\x45\x00\x46\x00\x47\x00\x48\x00\x49\x00\x4a\x00\x4b\x00\x4c\x00\x4d\x00\x4e\x00\x4f\x00\x50\x00\x51\x00\x52\x00\x53\x00\x54\x00\x55\x00\x56\x00\x57\x00\x58\x00\x59\x00\x5a\x00\x5b\x00\x5c\x00\x5d\x00\x5e\x00\x5f\x00\x60\x00\x61\x00\x62\x00\x63\x00\x64\x00\x65\x00\x66\x00\x67\x00\x68\x00\x69\x00\x6a\x00\x6b\x00\x6c\x00\x6d\x00\x6e\x00\x6f\x00\x70\x00\x71\x00\x72\x00\x73\x00\x74\x00\x75\x00\x76\x00\x77\x00\x78\x00\x79\x00\x7a\x00\x7b\x00\x7c\x00\x7d\x00\x7e\x00\x7f\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\x00\x00\x01\x00\x02\x00\x03\x00\x04\x00\x05\x00\x06\x00\x07\x00\x08\x00\x09\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x0e\x00\x0f\x00\x10\x00\x11\x00\x12\x00\x13\x00\x14\x00\x15\x00\x16\x00\x17\x00\x18\x00\x19\x00\x1a\x00\x1b\x00\x1c\x00\x1d\x00\x1e\x00\x1f\x00\x20\x00\x21\x00\x22\x00\x23\x00\x24\x00\x25\x00\x26\x00\x27\x00\x28\x00\x29\x00\x2a\x00\x2b\x00\x2c\x00\x2d\x00\x2e\x00\x2f\x00\x30\x00\x31\x00\x32\x00\x33\x00\x34\x00\x35\x00\x36\x00\x37\x00\x38\x00\x39\x00\x3a\x00\x3b\x00\x3c\x00\x3d\x00\x3e\x00\x3f\x00\x40\x00\x41\x00\x42\x00\x43\x00\x44\x00\x45\x00\x46\x00\x47\x00\x48\x00\x49\x00\x4a\x00\x4b\x00\x4c\x00\x4d\x00\x4e\x00\x4f\x00\x50\x00\x51\x00\x52\x00\x53\x00\x54\x00\x55\x00\x56\x00\x57\x00\x58\x00\x59\x00\x5a\x00\x5b\x00\x5c\x00\x5d\x00\x5e\x00\x5f\x00\x60\x00\x61\x00\x62\x00\x63\x00\x64\x00\x65\x00\x66\x00\x67\x00\x68\x00\x69\x00\x6a\x00\x6b\x00\x6c\x00\x6d\x00\x6e\x00\x6f\x00\x70\x00\x71\x00\x72\x00\x73\x00\x74\x00\x75\x00\x76\x00\x77\x00\x78\x00\x79\x00\x7a\x00\x7b\x00\x7c\x00\x7d\x00\x7e\x00\x7f\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\x00\x00\x01\x00\x02\x00\x03\x00\x04\x00\x05\x00\x06\x00\x07\x00\x08\x00\x09\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x0e\x00\x0f\x00\x10\x00\x11\x00\x12\x00\x13\x00\x14\x00\x15\x00\x16\x00\x17\x00\x18\x00\x19\x00\x1a\x00\x1b\x00\x1c\x00\x1d\x00\x1e\x00\x1f\x00\x20\x00\x21\x00\x22\x00\x23\x00\x24\x00\x25\x00\x26\x00\x27\x00\x28\x00\x29\x00\x2a\x00\x2b\x00\x2c\x00\x2d\x00\x2e\x00\x2f\x00\x30\x00\x31\x00\x32\x00\x33\x00\x34\x00\x35\x00\x36\x00\x37\x00\x38\x00\x39\x00\x3a\x00\x3b\x00\x3c\x00\x3d\x00\x3e\x00\x3f\x00\x40\x00\x41\x00\x42\x00\x43\x00\x44\x00\x45\x00\x46\x00\x47\x00\x48\x00\x49\x00\x4a\x00\x4b\x00\x4c\x00\x4d\x00\x4e\x00\x4f\x00\x50\x00\x51\x00\x52\x00\x53\x00\x54\x00\x55\x00\x56\x00\x57\x00\x58\x00\x59\x00\x5a\x00\x5b\x00\x5c\x00\x5d\x00\x5e\x00\x5f\x00\x60\x00\x61\x00\x62\x00\x63\x00\x64\x00\x65\x00\x66\x00\x67\x00\x68\x00\x69\x00\x6a\x00\x6b\x00\x6c\x00\x6d\x00\x6e\x00\x6f\x00\x70\x00\x71\x00\x72\x00\x73\x00\x74\x00\x75\x00\x76\x00\x77\x00\x78\x00\x79\x00\x7a\x00\x7b\x00\x7c\x00\x7d\x00\x7e\x00\x7f\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\xbf\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\x00\x00\x01\x00\x02\x00\x03\x00\x04\x00\x05\x00\x06\x00\x07\x00\x08\x00\x09\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x0e\x00\x0f\x00\x10\x00\x11\x00\x12\x00\x13\x00\x14\x00\x15\x00\x16\x00\x17\x00\x18\x00\x19\x00\x1a\x00\x1b\x00\x1c\x00\x1d\x00\x1e\x00\x1f\x00\x20\x00\x21\x00\x22\x00\x23\x00\x24\x00\x25\x00\x26\x00\x27\x00\x28\x00\x29\x00\x2a\x00\x2b\x00\x2c\x00\x2d\x00\x2e\x00\x2f\x00\x30\x00\x31\x00\x32\x00\x33\x00\x34\x00\x35\x00\x36\x00\x37\x00\x38\x00\x39\x00\x3a\x00\x3b\x00\x3c\x00\x3d\x00\x3e\x00\x3f\x00\x40\x00\x41\x00\x42\x00\x43\x00\x44\x00\x45\x00\x46\x00\x47\x00\x48\x00\x49\x00\x4a\x00\x4b\x00\x4c\x00\x4d\x00\x4e\x00\x4f\x00\x50\x00\x51\x00\x52\x00\x53\x00\x54\x00\x55\x00\x56\x00\x57\x00\x58\x00\x59\x00\x5a\x00\x5b\x00\x5c\x00\x5d\x00\x5e\x00\x5f\x00\x60\x00\x61\x00\x62\x00\x63\x00\x64\x00\x65\x00\x66\x00\x67\x00\x68\x00\x69\x00\x6a\x00\x6b\x00\x6c\x00\x6d\x00\x6e\x00\x6f\x00\x70\x00\x71\x00\x72\x00\x73\x00\x74\x00\x75\x00\x76\x00\x77\x00\x78\x00\x79\x00\x7a\x00\x7b\x00\x7c\x00\x7d\x00\x7e\x00\x7f\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\x00\x00\x01\x00\x02\x00\x03\x00\x04\x00\x05\x00\x06\x00\x07\x00\x08\x00\x09\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x0e\x00\x0f\x00\x10\x00\x11\x00\x12\x00\x13\x00\x14\x00\x15\x00\x16\x00\x17\x00\x18\x00\x19\x00\x1a\x00\x1b\x00\x1c\x00\x1d\x00\x1e\x00\x1f\x00\x20\x00\x21\x00\x22\x00\x23\x00\x24\x00\x25\x00\x26\x00\x27\x00\x28\x00\x29\x00\x2a\x00\x2b\x00\x2c\x00\x2d\x00\x2e\x00\x2f\x00\x30\x00\x31\x00\x32\x00\x33\x00\x34\x00\x35\x00\x36\x00\x37\x00\x38\x00\x39\x00\x3a\x00\x3b\x00\x3c\x00\x3d\x00\x3e\x00\x3f\x00\x40\x00\x41\x00\x42\x00\x43\x00\x44\x00\x45\x00\x46\x00\x47\x00\x48\x00\x49\x00\x4a\x00\x4b\x00\x4c\x00\x4d\x00\x4e\x00\x4f\x00\x50\x00\x51\x00\x52\x00\x53\x00\x54\x00\x55\x00\x56\x00\x57\x00\x58\x00\x59\x00\x5a\x00\x5b\x00\x5c\x00\x5d\x00\x5e\x00\x5f\x00\x60\x00\x61\x00\x62\x00\x63\x00\x64\x00\x65\x00\x66\x00\x67\x00\x68\x00\x69\x00\x6a\x00\x6b\x00\x6c\x00\x6d\x00\x6e\x00\x6f\x00\x70\x00\x71\x00\x72\x00\x73\x00\x74\x00\x75\x00\x76\x00\x77\x00\x78\x00\x79\x00\x7a\x00\x7b\x00\x7c\x00\x7d\x00\x7e\x00\x7f\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\x0a\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x3e\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\xff\xff\x80\x00\x81\x00\x82\x00\x83\x00\x84\x00\x85\x00\x86\x00\x87\x00\x88\x00\x89\x00\x8a\x00\x8b\x00\x8c\x00\x8d\x00\x8e\x00\x8f\x00\x90\x00\x91\x00\x92\x00\x93\x00\x94\x00\x95\x00\x96\x00\x97\x00\x98\x00\x99\x00\x9a\x00\x9b\x00\x9c\x00\x9d\x00\x9e\x00\x9f\x00\xa0\x00\xa1\x00\xa2\x00\xa3\x00\xa4\x00\xa5\x00\xa6\x00\xa7\x00\xa8\x00\xa9\x00\xaa\x00\xab\x00\xac\x00\xad\x00\xae\x00\xaf\x00\xb0\x00\xb1\x00\xb2\x00\xb3\x00\xb4\x00\xb5\x00\xb6\x00\xb7\x00\xb8\x00\xb9\x00\xba\x00\xbb\x00\xbc\x00\xbd\x00\xbe\x00\xbf\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\x0a\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x3e\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x80\x00\x81\x00\x82\x00\x83\x00\x84\x00\x85\x00\x86\x00\x87\x00\x88\x00\x89\x00\x8a\x00\x8b\x00\x8c\x00\x8d\x00\x8e\x00\x8f\x00\x90\x00\x91\x00\x92\x00\x93\x00\x94\x00\x95\x00\x96\x00\x97\x00\x98\x00\x99\x00\x9a\x00\x9b\x00\x9c\x00\x9d\x00\x9e\x00\x9f\x00\xa0\x00\xa1\x00\xa2\x00\xa3\x00\xa4\x00\xa5\x00\xa6\x00\xa7\x00\xa8\x00\xa9\x00\xaa\x00\xab\x00\xac\x00\xad\x00\xae\x00\xaf\x00\xb0\x00\xb1\x00\xb2\x00\xb3\x00\xb4\x00\xb5\x00\xb6\x00\xb7\x00\xb8\x00\xb9\x00\xba\x00\xbb\x00\xbc\x00\xbd\x00\xbe\x00\xbf\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\x00\x00\x01\x00\x02\x00\x03\x00\x04\x00\x05\x00\x06\x00\x07\x00\x08\x00\x09\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x0e\x00\x0f\x00\x10\x00\x11\x00\x12\x00\x13\x00\x14\x00\x15\x00\x16\x00\x17\x00\x18\x00\x19\x00\x1a\x00\x1b\x00\x1c\x00\x1d\x00\x1e\x00\x1f\x00\x20\x00\x21\x00\x22\x00\x23\x00\x24\x00\x25\x00\x26\x00\x27\x00\x28\x00\x29\x00\x2a\x00\x2b\x00\x2c\x00\x2d\x00\x2e\x00\x2f\x00\x30\x00\x31\x00\x32\x00\x33\x00\x34\x00\x35\x00\x36\x00\x37\x00\x38\x00\x39\x00\x3a\x00\x3b\x00\x3c\x00\x3d\x00\x3e\x00\x3f\x00\x40\x00\x41\x00\x42\x00\x43\x00\x44\x00\x45\x00\x46\x00\x47\x00\x48\x00\x49\x00\x4a\x00\x4b\x00\x4c\x00\x4d\x00\x4e\x00\x4f\x00\x50\x00\x51\x00\x52\x00\x53\x00\x54\x00\x55\x00\x56\x00\x57\x00\x58\x00\x59\x00\x5a\x00\x5b\x00\x5c\x00\x5d\x00\x5e\x00\x5f\x00\x60\x00\x61\x00\x62\x00\x63\x00\x64\x00\x65\x00\x66\x00\x67\x00\x68\x00\x69\x00\x6a\x00\x6b\x00\x6c\x00\x6d\x00\x6e\x00\x6f\x00\x70\x00\x71\x00\x72\x00\x73\x00\x74\x00\x75\x00\x76\x00\x77\x00\x78\x00\x79\x00\x7a\x00\x7b\x00\x7c\x00\x7d\x00\x7e\x00\x7f\x00\x21\x00\x0a\x00\x23\x00\x24\x00\x25\x00\x26\x00\x27\x00\xff\xff\xff\xff\x2a\x00\x2b\x00\xff\xff\x2d\x00\x2e\x00\x2f\x00\x30\x00\x31\x00\x32\x00\x33\x00\x34\x00\x35\x00\x36\x00\x37\x00\x38\x00\x39\x00\x3a\x00\x23\x00\x3c\x00\x3d\x00\x3e\x00\x3f\x00\x40\x00\x41\x00\x42\x00\x43\x00\x44\x00\x45\x00\x46\x00\x47\x00\x48\x00\x49\x00\x4a\x00\x4b\x00\x4c\x00\x4d\x00\x4e\x00\x4f\x00\x50\x00\x51\x00\x52\x00\x53\x00\x54\x00\x55\x00\x56\x00\x57\x00\x58\x00\x59\x00\x5a\x00\xff\xff\x5c\x00\xff\xff\x5e\x00\x5f\x00\x60\x00\x61\x00\x62\x00\x63\x00\x64\x00\x65\x00\x66\x00\x67\x00\x68\x00\x69\x00\x6a\x00\x6b\x00\x6c\x00\x6d\x00\x6e\x00\x6f\x00\x70\x00\x71\x00\x72\x00\x73\x00\x74\x00\x75\x00\x76\x00\x77\x00\x78\x00\x79\x00\x7a\x00\xff\xff\x7c\x00\xff\xff\x7e\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x80\x00\x81\x00\x82\x00\x83\x00\x84\x00\x85\x00\x86\x00\x87\x00\x88\x00\x89\x00\x8a\x00\x8b\x00\x8c\x00\x8d\x00\x8e\x00\x8f\x00\x90\x00\x91\x00\x92\x00\x93\x00\x94\x00\x95\x00\x96\x00\x97\x00\x98\x00\x99\x00\x9a\x00\x9b\x00\x9c\x00\x9d\x00\x9e\x00\x9f\x00\xa0\x00\xa1\x00\xa2\x00\xa3\x00\xa4\x00\xa5\x00\xa6\x00\xa7\x00\xa8\x00\xa9\x00\xaa\x00\xab\x00\xac\x00\xad\x00\xae\x00\xaf\x00\xb0\x00\xb1\x00\xb2\x00\xb3\x00\xb4\x00\xb5\x00\xb6\x00\xb7\x00\xb8\x00\xb9\x00\xba\x00\xbb\x00\xbc\x00\xbd\x00\xbe\x00\xbf\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\x0a\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x21\x00\xff\xff\x23\x00\x24\x00\x25\x00\x26\x00\x27\x00\xff\xff\xff\xff\x2a\x00\x2b\x00\xff\xff\x2d\x00\x2e\x00\x2f\x00\x30\x00\x31\x00\x32\x00\x33\x00\x34\x00\x35\x00\x36\x00\x37\x00\x38\x00\x39\x00\x3a\x00\x2f\x00\x3c\x00\x3d\x00\x3e\x00\x3f\x00\x40\x00\x41\x00\x42\x00\x43\x00\x44\x00\x45\x00\x46\x00\x47\x00\x48\x00\x49\x00\x4a\x00\x4b\x00\x4c\x00\x4d\x00\x4e\x00\x4f\x00\x50\x00\x51\x00\x52\x00\x53\x00\x54\x00\x55\x00\x56\x00\x57\x00\x58\x00\x59\x00\x5a\x00\xff\xff\x5c\x00\xff\xff\x5e\x00\x5f\x00\xff\xff\x61\x00\x62\x00\x63\x00\x64\x00\x65\x00\x66\x00\x67\x00\x68\x00\x69\x00\x6a\x00\x6b\x00\x6c\x00\x6d\x00\x6e\x00\x6f\x00\x70\x00\x71\x00\x72\x00\x73\x00\x74\x00\x75\x00\x76\x00\x77\x00\x78\x00\x79\x00\x7a\x00\xff\xff\x7c\x00\xff\xff\x7e\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x80\x00\x81\x00\x82\x00\x83\x00\x84\x00\x85\x00\x86\x00\x87\x00\x88\x00\x89\x00\x8a\x00\x8b\x00\x8c\x00\x8d\x00\x8e\x00\x8f\x00\x90\x00\x91\x00\x92\x00\x93\x00\x94\x00\x95\x00\x96\x00\x97\x00\x98\x00\x99\x00\x9a\x00\x9b\x00\x9c\x00\x9d\x00\x9e\x00\x9f\x00\xa0\x00\xa1\x00\xa2\x00\xa3\x00\xa4\x00\xa5\x00\xa6\x00\xa7\x00\xa8\x00\xa9\x00\xaa\x00\xab\x00\xac\x00\xad\x00\xae\x00\xaf\x00\xb0\x00\xb1\x00\xb2\x00\xb3\x00\xb4\x00\xb5\x00\xb6\x00\xb7\x00\xb8\x00\xb9\x00\xba\x00\xbb\x00\xbc\x00\xbd\x00\xbe\x00\xbf\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\x0a\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x80\x00\x81\x00\x82\x00\x83\x00\x84\x00\x85\x00\x86\x00\x87\x00\x88\x00\x89\x00\x8a\x00\x8b\x00\x8c\x00\x8d\x00\x8e\x00\x8f\x00\x90\x00\x91\x00\x92\x00\x93\x00\x94\x00\x95\x00\x96\x00\x97\x00\x98\x00\x99\x00\x9a\x00\x9b\x00\x9c\x00\x9d\x00\x9e\x00\x9f\x00\xa0\x00\xa1\x00\xa2\x00\xa3\x00\xa4\x00\xa5\x00\xa6\x00\xa7\x00\xa8\x00\xa9\x00\xaa\x00\xab\x00\xac\x00\xad\x00\xae\x00\xaf\x00\xb0\x00\xb1\x00\xb2\x00\xb3\x00\xb4\x00\xb5\x00\xb6\x00\xb7\x00\xb8\x00\xb9\x00\xba\x00\xbb\x00\xbc\x00\xbd\x00\xbe\x00\xbf\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\x0a\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x3c\x00\xff\xff\x3e\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x80\x00\x81\x00\x82\x00\x83\x00\x84\x00\x85\x00\x86\x00\x87\x00\x88\x00\x89\x00\x8a\x00\x8b\x00\x8c\x00\x8d\x00\x8e\x00\x8f\x00\x90\x00\x91\x00\x92\x00\x93\x00\x94\x00\x95\x00\x96\x00\x97\x00\x98\x00\x99\x00\x9a\x00\x9b\x00\x9c\x00\x9d\x00\x9e\x00\x9f\x00\xa0\x00\xa1\x00\xa2\x00\xa3\x00\xa4\x00\xa5\x00\xa6\x00\xa7\x00\xa8\x00\xa9\x00\xaa\x00\xab\x00\xac\x00\xad\x00\xae\x00\xaf\x00\xb0\x00\xb1\x00\xb2\x00\xb3\x00\xb4\x00\xb5\x00\xb6\x00\xb7\x00\xb8\x00\xb9\x00\xba\x00\xbb\x00\xbc\x00\xbd\x00\xbe\x00\xbf\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00\x0a\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x22\x00\x23\x00\xff\xff\xff\xff\x26\x00\x27\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x2f\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x3c\x00\xff\xff\xff\xff\xff\xff\x40\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x5c\x00\x5d\x00\xff\xff\xff\xff\x60\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x80\x00\x81\x00\x82\x00\x83\x00\x84\x00\x85\x00\x86\x00\x87\x00\x88\x00\x89\x00\x8a\x00\x8b\x00\x8c\x00\x8d\x00\x8e\x00\x8f\x00\x90\x00\x91\x00\x92\x00\x93\x00\x94\x00\x95\x00\x96\x00\x97\x00\x98\x00\x99\x00\x9a\x00\x9b\x00\x9c\x00\x9d\x00\x9e\x00\x9f\x00\xa0\x00\xa1\x00\xa2\x00\xa3\x00\xa4\x00\xa5\x00\xa6\x00\xa7\x00\xa8\x00\xa9\x00\xaa\x00\xab\x00\xac\x00\xad\x00\xae\x00\xaf\x00\xb0\x00\xb1\x00\xb2\x00\xb3\x00\xb4\x00\xb5\x00\xb6\x00\xb7\x00\xb8\x00\xb9\x00\xba\x00\xbb\x00\xbc\x00\xbd\x00\xbe\x00\xbf\x00\xc0\x00\xc1\x00\xc2\x00\xc3\x00\xc4\x00\xc5\x00\xc6\x00\xc7\x00\xc8\x00\xc9\x00\xca\x00\xcb\x00\xcc\x00\xcd\x00\xce\x00\xcf\x00\xd0\x00\xd1\x00\xd2\x00\xd3\x00\xd4\x00\xd5\x00\xd6\x00\xd7\x00\xd8\x00\xd9\x00\xda\x00\xdb\x00\xdc\x00\xdd\x00\xde\x00\xdf\x00\xe0\x00\xe1\x00\xe2\x00\xe3\x00\xe4\x00\xe5\x00\xe6\x00\xe7\x00\xe8\x00\xe9\x00\xea\x00\xeb\x00\xec\x00\xed\x00\xee\x00\xef\x00\xf0\x00\xf1\x00\xf2\x00\xf3\x00\xf4\x00\xf5\x00\xf6\x00\xf7\x00\xf8\x00\xf9\x00\xfa\x00\xfb\x00\xfc\x00\xfd\x00\xfe\x00\xff\x00"#
-
-alex_deflt :: AlexAddr
-alex_deflt = AlexA# "\xff\xff\x01\x00\x8d\x00\xff\xff\x04\x00\x05\x00\xff\xff\xff\xff\x8d\x00\xff\xff\x0a\x00\x0b\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x31\x00\x31\x00\x33\x00\x33\x00\x35\x00\x35\x00\x37\x00\x37\x00\x39\x00\x39\x00\x3b\x00\x3b\x00\x3f\x00\x3f\x00\x43\x00\x43\x00\x47\x00\x47\x00\x4a\x00\x4a\x00\x4d\x00\x4d\x00\x50\x00\x50\x00\x53\x00\x53\x00\x56\x00\x56\x00\x58\x00\x58\x00\x5d\x00\x5d\x00\xff\xff\xff\xff\x60\x00\x60\x00\x0b\x00\x0b\x00\x0b\x00\x0a\x00\x0a\x00\x0a\x00\x61\x00\x61\x00\x61\x00\x62\x00\x62\x00\x62\x00\x05\x00\x05\x00\x05\x00\x04\x00\x04\x00\x04\x00\xff\xff\x67\x00\x67\x00\xff\xff\x8d\x00\x8d\x00\x8d\x00\x83\x00\x83\x00\x83\x00\x61\x00\x62\x00\xff\xff\xff\xff\x01\x00\x01\x00\x01\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x0a\x00\x0b\x00\xff\xff\xff\xff\x83\x00\x61\x00\xff\xff\x8d\x00\xff\xff\xff\xff"#
-
-alex_accept = listArray (0::Int,143) [[(AlexAcc (alex_action_7))],[(AlexAcc (alex_action_12))],[],[(AlexAcc (alex_action_15))],[],[],[(AlexAcc (alex_action_11))],[(AlexAcc (alex_action_7))],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[(AlexAccSkip)],[(AlexAcc (alex_action_1))],[(AlexAcc (alex_action_2))],[(AlexAcc (alex_action_3))],[(AlexAcc (alex_action_4))],[(AlexAcc (alex_action_5))],[(AlexAcc (alex_action_6))],[(AlexAcc (alex_action_8))],[(AlexAcc (alex_action_9))],[(AlexAcc (alex_action_10))],[(AlexAcc (alex_action_12))],[(AlexAcc (alex_action_13))],[(AlexAcc (alex_action_14))],[(AlexAcc (alex_action_16))],[(AlexAcc (alex_action_17))],[(AlexAcc (alex_action_18))],[(AlexAcc (alex_action_19))],[(AlexAcc (alex_action_20))],[(AlexAcc (alex_action_20))],[(AlexAcc (alex_action_21))],[(AlexAcc (alex_action_22))],[(AlexAcc (alex_action_23))],[(AlexAcc (alex_action_23))],[(AlexAcc (alex_action_24))],[(AlexAcc (alex_action_25))],[(AlexAcc (alex_action_26))],[(AlexAcc (alex_action_27))],[(AlexAcc (alex_action_27))],[(AlexAcc (alex_action_27))],[(AlexAcc (alex_action_27))],[(AlexAcc (alex_action_27))],[(AlexAcc (alex_action_27))],[(AlexAcc (alex_action_28))],[(AlexAcc (alex_action_29))],[(AlexAcc (alex_action_30))],[(AlexAcc (alex_action_31))]]
-{-# LINE 113 "src/Haddock/Lex.x" #-}
-
--- | A located token
-type LToken = (Token, AlexPosn)
-
-data Token
-  = TokPara
-  | TokNumber
-  | TokBullet
-  | TokDefStart
-  | TokDefEnd
-  | TokSpecial Char
-  | TokIdent [RdrName]
-  | TokString String
-  | TokURL String
-  | TokPic String
-  | TokEmphasis String
-  | TokAName String
-  | TokBirdTrack String
-  | TokExamplePrompt String
-  | TokExampleExpression String
-  | TokExampleResult String
---  deriving Show
-
-tokenPos :: LToken -> (Int, Int)
-tokenPos t = let AlexPn _ line col = snd t in (line, col)
-
--- -----------------------------------------------------------------------------
--- Alex support stuff
-
--- XXX: copied the posn wrapper code from Alex to make this lexer work
--- with both Alex 2.x and Alex 3.x.  However, we are not using the
--- Unicode/UTF-8 support in Alex 3.x, and Unicode documentation will
--- probably get mangled.
-
-type AlexInput = (AlexPosn,     -- current position,
-                  Char,         -- previous char
-                  String)       -- current input string
-
-alexInputPrevChar :: AlexInput -> Char
-alexInputPrevChar (p,c,s) = c
-
-alexGetByte :: AlexInput -> Maybe (Word8,AlexInput)
-alexGetByte (p,c,[]) = Nothing
-alexGetByte (p,_,(c:s))  = let p' = alexMove p c
-                              in p' `seq`  Just (fromIntegral (ord c), (p', c, s))
-
--- for compat with Alex 2.x:
-alexGetChar :: AlexInput -> Maybe (Char,AlexInput)
-alexGetChar i = case alexGetByte i of
-                  Nothing     -> Nothing
-                  Just (b,i') -> Just (chr (fromIntegral b), i')
-
-alexMove :: AlexPosn -> Char -> AlexPosn
-alexMove (AlexPn a l c) '\t' = AlexPn (a+1)  l     (((c+7) `div` 8)*8+1)
-alexMove (AlexPn a l c) '\n' = AlexPn (a+1) (l+1)   1
-alexMove (AlexPn a l c) _    = AlexPn (a+1)  l     (c+1)
-
-data AlexPosn = AlexPn !Int !Int !Int
-        deriving (Eq,Show)
-
-type StartCode = Int
-type Action = AlexPosn -> String -> StartCode -> (StartCode -> [LToken]) -> DynFlags -> [LToken]
-
-tokenise :: DynFlags -> String -> (Int, Int) -> [LToken]
-tokenise dflags str (line, col) = let toks = go (posn, '\n', eofHack str) para in {-trace (show toks)-} toks
-  where
-    posn = AlexPn 0 line col
-
-    go inp@(pos, _, str) sc =
-	  case alexScan inp sc of
-		AlexEOF -> []
-		AlexError _ -> error "lexical error"
-		AlexSkip  inp' _       -> go inp' sc
-		AlexToken inp'@(pos',_,_) len act -> act pos (take len str) sc (\sc -> go inp' sc) dflags
-
--- NB. we add a final \n to the string, (see comment in the beginning of line
--- production above).
-eofHack str = str++"\n"
-
-andBegin  :: Action -> StartCode -> Action
-andBegin act new_sc = \pos str _ cont dflags -> act pos str new_sc cont dflags
-
-token :: Token -> Action
-token t = \pos _ sc cont _ -> (t, pos) : cont sc
-
-strtoken, strtokenNL :: (String -> Token) -> Action
-strtoken t = \pos str sc cont _ -> (t str, pos) : cont sc
-strtokenNL t = \pos str sc cont _ -> (t (filter (/= '\r') str), pos) : cont sc
--- ^ We only want LF line endings in our internal doc string format, so we
--- filter out all CRs.
-
-begin :: StartCode -> Action
-begin sc = \_ _ _ cont _ -> cont sc
-
--- -----------------------------------------------------------------------------
--- Lex a string as a Haskell identifier
-
-ident :: Action
-ident pos str sc cont dflags = 
-  case strToHsQNames dflags loc id of
-	Just names -> (TokIdent names, pos) : cont sc
-	Nothing -> (TokString str, pos) : cont sc
- where id = init (tail str)
-       -- TODO: Get the real filename here. Maybe we should just be
-       --       using GHC SrcLoc's ourself?
-       filename = mkFastString "<unknown file>"
-       loc = case pos of
-             AlexPn _ line col ->
-                 mkRealSrcLoc filename line col
-
-strToHsQNames :: DynFlags -> RealSrcLoc -> String -> Maybe [RdrName]
-strToHsQNames dflags loc str0 = 
-#if MIN_VERSION_ghc(7,1,0)
-  let buffer = stringToStringBuffer str0
-#else
-  let buffer = unsafePerformIO (stringToStringBuffer str0)
-#endif
-      pstate = mkPState dflags buffer loc
-      result = unP parseIdentifier pstate 
-  in case result of 
-       POk _ name -> Just [unLoc name] 
-       _ -> Nothing
-
-
-birdtrack,def,example,exampleexpr,exampleresult,line,para,string :: Int
-birdtrack = 1
-def = 2
-example = 3
-exampleexpr = 4
-exampleresult = 5
-line = 6
-para = 7
-string = 8
-alex_action_1 =  begin birdtrack 
-alex_action_2 =  strtoken TokExamplePrompt `andBegin` exampleexpr 
-alex_action_3 =  token TokBullet `andBegin` string 
-alex_action_4 =  token TokDefStart `andBegin` def 
-alex_action_5 =  token TokNumber `andBegin` string 
-alex_action_6 =  token TokNumber `andBegin` string 
-alex_action_7 =  begin string 
-alex_action_8 =  begin birdtrack 
-alex_action_9 =  strtoken TokExamplePrompt `andBegin` exampleexpr 
-alex_action_10 =  token TokPara `andBegin` para 
-alex_action_11 =  begin string 
-alex_action_12 =  strtokenNL TokBirdTrack `andBegin` line 
-alex_action_13 =  token TokPara `andBegin` para 
-alex_action_14 =  strtoken TokExamplePrompt `andBegin` exampleexpr 
-alex_action_15 =  begin exampleresult 
-alex_action_16 =  strtokenNL TokExampleExpression `andBegin` example 
-alex_action_17 =  strtokenNL TokExampleResult `andBegin` example 
-alex_action_18 =  strtoken $ \s -> TokSpecial (head s) 
-alex_action_19 =  strtoken $ \s -> TokPic (init $ init $ tail $ tail s) 
-alex_action_20 =  strtoken $ \s -> TokURL (init (tail s)) 
-alex_action_21 =  strtoken $ \s -> TokAName (init (tail s)) 
-alex_action_22 =  strtoken $ \s -> TokEmphasis (init (tail s)) 
-alex_action_23 =  ident 
-alex_action_24 =  strtoken (TokString . tail) 
-alex_action_25 =  strtoken $ \s -> TokString [chr (read (init (drop 2 s)))] 
-alex_action_26 =  strtoken $ \s -> case readHex (init (drop 3 s)) of [(n,_)] -> TokString [chr n] 
-alex_action_27 =  strtoken TokString 
-alex_action_28 =  strtokenNL TokString `andBegin` line 
-alex_action_29 =  strtoken TokString 
-alex_action_30 =  token TokDefEnd `andBegin` string 
-alex_action_31 =  strtoken TokString 
-{-# LINE 1 "templates/GenericTemplate.hs" #-}
-{-# LINE 1 "templates/GenericTemplate.hs" #-}
-{-# LINE 1 "<built-in>" #-}
-{-# LINE 1 "<command-line>" #-}
-{-# LINE 1 "templates/GenericTemplate.hs" #-}
--- -----------------------------------------------------------------------------
--- ALEX TEMPLATE
---
--- This code is in the PUBLIC DOMAIN; you may copy it freely and use
--- it for any purpose whatsoever.
-
--- -----------------------------------------------------------------------------
--- INTERNALS and main scanner engine
-
-{-# LINE 37 "templates/GenericTemplate.hs" #-}
-
-{-# LINE 47 "templates/GenericTemplate.hs" #-}
-
-
-data AlexAddr = AlexA# Addr#
-
-#if __GLASGOW_HASKELL__ < 503
-uncheckedShiftL# = shiftL#
-#endif
-
-{-# INLINE alexIndexInt16OffAddr #-}
-alexIndexInt16OffAddr (AlexA# arr) off =
-#ifdef WORDS_BIGENDIAN
-  narrow16Int# i
-  where
-        i    = word2Int# ((high `uncheckedShiftL#` 8#) `or#` low)
-        high = int2Word# (ord# (indexCharOffAddr# arr (off' +# 1#)))
-        low  = int2Word# (ord# (indexCharOffAddr# arr off'))
-        off' = off *# 2#
-#else
-  indexInt16OffAddr# arr off
-#endif
-
-
-
-
-
-{-# INLINE alexIndexInt32OffAddr #-}
-alexIndexInt32OffAddr (AlexA# arr) off = 
-#ifdef WORDS_BIGENDIAN
-  narrow32Int# i
-  where
-   !i    = word2Int# ((b3 `uncheckedShiftL#` 24#) `or#`
-		     (b2 `uncheckedShiftL#` 16#) `or#`
-		     (b1 `uncheckedShiftL#` 8#) `or#` b0)
-   !b3   = int2Word# (ord# (indexCharOffAddr# arr (off' +# 3#)))
-   !b2   = int2Word# (ord# (indexCharOffAddr# arr (off' +# 2#)))
-   !b1   = int2Word# (ord# (indexCharOffAddr# arr (off' +# 1#)))
-   !b0   = int2Word# (ord# (indexCharOffAddr# arr off'))
-   !off' = off *# 4#
-#else
-  indexInt32OffAddr# arr off
-#endif
-
-
-
-
-
-#if __GLASGOW_HASKELL__ < 503
-quickIndex arr i = arr ! i
-#else
--- GHC >= 503, unsafeAt is available from Data.Array.Base.
-quickIndex = unsafeAt
-#endif
-
-
-
-
--- -----------------------------------------------------------------------------
--- Main lexing routines
-
-data AlexReturn a
-  = AlexEOF
-  | AlexError  !AlexInput
-  | AlexSkip   !AlexInput !Int
-  | AlexToken  !AlexInput !Int a
-
--- alexScan :: AlexInput -> StartCode -> AlexReturn a
-alexScan input (I# (sc))
-  = alexScanUser undefined input (I# (sc))
-
-alexScanUser user input (I# (sc))
-  = case alex_scan_tkn user input 0# input sc AlexNone of
-	(AlexNone, input') ->
-		case alexGetByte input of
-			Nothing -> 
-
-
-
-				   AlexEOF
-			Just _ ->
-
-
-
-				   AlexError input'
-
-	(AlexLastSkip input'' len, _) ->
-
-
-
-		AlexSkip input'' len
-
-	(AlexLastAcc k input''' len, _) ->
-
-
-
-		AlexToken input''' len k
-
-
--- Push the input through the DFA, remembering the most recent accepting
--- state it encountered.
-
-alex_scan_tkn user orig_input len input s last_acc =
-  input `seq` -- strict in the input
-  let 
-	new_acc = (check_accs (alex_accept `quickIndex` (I# (s))))
-  in
-  new_acc `seq`
-  case alexGetByte input of
-     Nothing -> (new_acc, input)
-     Just (c, new_input) -> 
-
-
-
-	let
-		(base) = alexIndexInt32OffAddr alex_base s
-		((I# (ord_c))) = fromIntegral c
-		(offset) = (base +# ord_c)
-		(check)  = alexIndexInt16OffAddr alex_check offset
-		
-		(new_s) = if (offset >=# 0#) && (check ==# ord_c)
-			  then alexIndexInt16OffAddr alex_table offset
-			  else alexIndexInt16OffAddr alex_deflt s
-	in
-	case new_s of 
-	    -1# -> (new_acc, input)
-		-- on an error, we want to keep the input *before* the
-		-- character that failed, not after.
-    	    _ -> alex_scan_tkn user orig_input (if c < 0x80 || c >= 0xC0 then (len +# 1#) else len)
-                                                -- note that the length is increased ONLY if this is the 1st byte in a char encoding)
-			new_input new_s new_acc
-
-  where
-	check_accs [] = last_acc
-	check_accs (AlexAcc a : _) = AlexLastAcc a input (I# (len))
-	check_accs (AlexAccSkip : _)  = AlexLastSkip  input (I# (len))
-	check_accs (AlexAccPred a predx : rest)
-	   | predx user orig_input (I# (len)) input
-	   = AlexLastAcc a input (I# (len))
-	check_accs (AlexAccSkipPred predx : rest)
-	   | predx user orig_input (I# (len)) input
-	   = AlexLastSkip input (I# (len))
-	check_accs (_ : rest) = check_accs rest
-
-data AlexLastAcc a
-  = AlexNone
-  | AlexLastAcc a !AlexInput !Int
-  | AlexLastSkip  !AlexInput !Int
-
-instance Functor AlexLastAcc where
-    fmap f AlexNone = AlexNone
-    fmap f (AlexLastAcc x y z) = AlexLastAcc (f x) y z
-    fmap f (AlexLastSkip x y) = AlexLastSkip x y
-
-data AlexAcc a user
-  = AlexAcc a
-  | AlexAccSkip
-  | AlexAccPred a (AlexAccPred user)
-  | AlexAccSkipPred (AlexAccPred user)
-
-type AlexAccPred user = user -> AlexInput -> Int -> AlexInput -> Bool
-
--- -----------------------------------------------------------------------------
--- Predicates on a rule
-
-alexAndPred p1 p2 user in1 len in2
-  = p1 user in1 len in2 && p2 user in1 len in2
-
---alexPrevCharIsPred :: Char -> AlexAccPred _ 
-alexPrevCharIs c _ input _ _ = c == alexInputPrevChar input
-
-alexPrevCharMatches f _ input _ _ = f (alexInputPrevChar input)
-
---alexPrevCharIsOneOfPred :: Array Char Bool -> AlexAccPred _ 
-alexPrevCharIsOneOf arr _ input _ _ = arr ! alexInputPrevChar input
-
---alexRightContext :: Int -> AlexAccPred _
-alexRightContext (I# (sc)) user _ _ input = 
-     case alex_scan_tkn user input 0# input sc AlexNone of
-	  (AlexNone, _) -> False
-	  _ -> True
-	-- TODO: there's no need to find the longest
-	-- match when checking the right context, just
-	-- the first match will do.
-
--- used by wrappers
-iUnbox (I# (i)) = i
diff --git a/dist/build/haddock/haddock-tmp/Haddock/Parse.hs b/dist/build/haddock/haddock-tmp/Haddock/Parse.hs
deleted file mode 100644
--- a/dist/build/haddock/haddock-tmp/Haddock/Parse.hs
+++ /dev/null
@@ -1,819 +0,0 @@
-{-# OPTIONS_GHC -w #-}
-{-# OPTIONS -fglasgow-exts -cpp #-}
-{-# LANGUAGE BangPatterns #-} -- required for versions of Happy before 1.18.6
-{-# OPTIONS -Wwarn -w #-}
--- The above warning supression flag is a temporary kludge.
--- While working on this module you are encouraged to remove it and fix
--- any warnings in the module. See
---     http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings
--- for details
-
-module Haddock.Parse where
-
-import Haddock.Lex
-import Haddock.Types (Doc(..), Example(Example))
-import Haddock.Doc
-import HsSyn
-import RdrName
-import Data.Char  (isSpace)
-import Data.Maybe (fromMaybe)
-import Data.List  (stripPrefix)
-import qualified Data.Array as Happy_Data_Array
-import qualified GHC.Exts as Happy_GHC_Exts
-
--- parser produced by Happy Version 1.18.6
-
-newtype HappyAbsSyn  = HappyAbsSyn HappyAny
-#if __GLASGOW_HASKELL__ >= 607
-type HappyAny = Happy_GHC_Exts.Any
-#else
-type HappyAny = forall a . a
-#endif
-happyIn5 :: (Doc RdrName) -> (HappyAbsSyn )
-happyIn5 x = Happy_GHC_Exts.unsafeCoerce# x
-{-# INLINE happyIn5 #-}
-happyOut5 :: (HappyAbsSyn ) -> (Doc RdrName)
-happyOut5 x = Happy_GHC_Exts.unsafeCoerce# x
-{-# INLINE happyOut5 #-}
-happyIn6 :: (Doc RdrName) -> (HappyAbsSyn )
-happyIn6 x = Happy_GHC_Exts.unsafeCoerce# x
-{-# INLINE happyIn6 #-}
-happyOut6 :: (HappyAbsSyn ) -> (Doc RdrName)
-happyOut6 x = Happy_GHC_Exts.unsafeCoerce# x
-{-# INLINE happyOut6 #-}
-happyIn7 :: (Doc RdrName) -> (HappyAbsSyn )
-happyIn7 x = Happy_GHC_Exts.unsafeCoerce# x
-{-# INLINE happyIn7 #-}
-happyOut7 :: (HappyAbsSyn ) -> (Doc RdrName)
-happyOut7 x = Happy_GHC_Exts.unsafeCoerce# x
-{-# INLINE happyOut7 #-}
-happyIn8 :: (Doc RdrName) -> (HappyAbsSyn )
-happyIn8 x = Happy_GHC_Exts.unsafeCoerce# x
-{-# INLINE happyIn8 #-}
-happyOut8 :: (HappyAbsSyn ) -> (Doc RdrName)
-happyOut8 x = Happy_GHC_Exts.unsafeCoerce# x
-{-# INLINE happyOut8 #-}
-happyIn9 :: ((Doc RdrName, Doc RdrName)) -> (HappyAbsSyn )
-happyIn9 x = Happy_GHC_Exts.unsafeCoerce# x
-{-# INLINE happyIn9 #-}
-happyOut9 :: (HappyAbsSyn ) -> ((Doc RdrName, Doc RdrName))
-happyOut9 x = Happy_GHC_Exts.unsafeCoerce# x
-{-# INLINE happyOut9 #-}
-happyIn10 :: (Doc RdrName) -> (HappyAbsSyn )
-happyIn10 x = Happy_GHC_Exts.unsafeCoerce# x
-{-# INLINE happyIn10 #-}
-happyOut10 :: (HappyAbsSyn ) -> (Doc RdrName)
-happyOut10 x = Happy_GHC_Exts.unsafeCoerce# x
-{-# INLINE happyOut10 #-}
-happyIn11 :: (Doc RdrName) -> (HappyAbsSyn )
-happyIn11 x = Happy_GHC_Exts.unsafeCoerce# x
-{-# INLINE happyIn11 #-}
-happyOut11 :: (HappyAbsSyn ) -> (Doc RdrName)
-happyOut11 x = Happy_GHC_Exts.unsafeCoerce# x
-{-# INLINE happyOut11 #-}
-happyIn12 :: ([Example]) -> (HappyAbsSyn )
-happyIn12 x = Happy_GHC_Exts.unsafeCoerce# x
-{-# INLINE happyIn12 #-}
-happyOut12 :: (HappyAbsSyn ) -> ([Example])
-happyOut12 x = Happy_GHC_Exts.unsafeCoerce# x
-{-# INLINE happyOut12 #-}
-happyIn13 :: (Example) -> (HappyAbsSyn )
-happyIn13 x = Happy_GHC_Exts.unsafeCoerce# x
-{-# INLINE happyIn13 #-}
-happyOut13 :: (HappyAbsSyn ) -> (Example)
-happyOut13 x = Happy_GHC_Exts.unsafeCoerce# x
-{-# INLINE happyOut13 #-}
-happyIn14 :: (String) -> (HappyAbsSyn )
-happyIn14 x = Happy_GHC_Exts.unsafeCoerce# x
-{-# INLINE happyIn14 #-}
-happyOut14 :: (HappyAbsSyn ) -> (String)
-happyOut14 x = Happy_GHC_Exts.unsafeCoerce# x
-{-# INLINE happyOut14 #-}
-happyIn15 :: (Doc RdrName) -> (HappyAbsSyn )
-happyIn15 x = Happy_GHC_Exts.unsafeCoerce# x
-{-# INLINE happyIn15 #-}
-happyOut15 :: (HappyAbsSyn ) -> (Doc RdrName)
-happyOut15 x = Happy_GHC_Exts.unsafeCoerce# x
-{-# INLINE happyOut15 #-}
-happyIn16 :: (Doc RdrName) -> (HappyAbsSyn )
-happyIn16 x = Happy_GHC_Exts.unsafeCoerce# x
-{-# INLINE happyIn16 #-}
-happyOut16 :: (HappyAbsSyn ) -> (Doc RdrName)
-happyOut16 x = Happy_GHC_Exts.unsafeCoerce# x
-{-# INLINE happyOut16 #-}
-happyIn17 :: (Doc RdrName) -> (HappyAbsSyn )
-happyIn17 x = Happy_GHC_Exts.unsafeCoerce# x
-{-# INLINE happyIn17 #-}
-happyOut17 :: (HappyAbsSyn ) -> (Doc RdrName)
-happyOut17 x = Happy_GHC_Exts.unsafeCoerce# x
-{-# INLINE happyOut17 #-}
-happyIn18 :: (Doc RdrName) -> (HappyAbsSyn )
-happyIn18 x = Happy_GHC_Exts.unsafeCoerce# x
-{-# INLINE happyIn18 #-}
-happyOut18 :: (HappyAbsSyn ) -> (Doc RdrName)
-happyOut18 x = Happy_GHC_Exts.unsafeCoerce# x
-{-# INLINE happyOut18 #-}
-happyIn19 :: (String) -> (HappyAbsSyn )
-happyIn19 x = Happy_GHC_Exts.unsafeCoerce# x
-{-# INLINE happyIn19 #-}
-happyOut19 :: (HappyAbsSyn ) -> (String)
-happyOut19 x = Happy_GHC_Exts.unsafeCoerce# x
-{-# INLINE happyOut19 #-}
-happyInTok :: (LToken) -> (HappyAbsSyn )
-happyInTok x = Happy_GHC_Exts.unsafeCoerce# x
-{-# INLINE happyInTok #-}
-happyOutTok :: (HappyAbsSyn ) -> (LToken)
-happyOutTok x = Happy_GHC_Exts.unsafeCoerce# x
-{-# INLINE happyOutTok #-}
-
-
-happyActOffsets :: HappyAddr
-happyActOffsets = HappyA# "\xff\xff\x2e\x00\x10\x00\x70\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x68\x00\x00\x00\x2e\x00\x00\x00\x66\x00\x2e\x00\x61\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1f\x00\x1f\x00\x64\x00\x5a\x00\x00\x00\x00\x00\x53\x00\x53\x00\x47\x00\xff\xff\x00\x00\xff\xff\x3f\x00\x00\x00\x00\x00\x00\x00\x3a\x00\x49\x00\x46\x00\x3b\x00\x66\x00\x66\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x2e\x00\x00\x00\x00\x00\x00\x00\x2d\x00\x00\x00\x00\x00\x00\x00\x00\x00"#
-
-happyGotoOffsets :: HappyAddr
-happyGotoOffsets = HappyA# "\x5d\x00\x92\x00\x78\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x26\x00\x00\x00\x8e\x00\x00\x00\x1d\x00\x67\x00\x2a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x8a\x00\x81\x00\x2c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x4f\x00\x00\x00\x41\x00\x1a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x06\x00\x00\x00\x00\x00\x12\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x2f\x00\x00\x00\x00\x00\x00\x00\xfa\xff\x00\x00\x00\x00\x00\x00\x00\x00"#
-
-happyDefActions :: HappyAddr
-happyDefActions = HappyA# "\xfa\xff\x00\x00\x00\x00\x00\x00\xf9\xff\xf8\xff\xf7\xff\xf6\xff\xf1\xff\xf0\xff\xec\xff\xf2\xff\xe6\xff\xe5\xff\x00\x00\x00\x00\x00\x00\xde\xff\xdd\xff\xdc\xff\xdf\xff\x00\x00\x00\x00\xee\xff\x00\x00\xdb\xff\xe0\xff\x00\x00\x00\x00\xfb\xff\xfa\xff\xfc\xff\xfa\xff\xea\xff\xef\xff\xf4\xff\xf5\xff\x00\x00\xd9\xff\x00\x00\x00\x00\xe1\xff\x00\x00\xe7\xff\xed\xff\xe3\xff\xe2\xff\xe4\xff\x00\x00\xd8\xff\xda\xff\xeb\xff\xe8\xff\xfd\xff\xe9\xff\xf3\xff"#
-
-happyCheck :: HappyAddr
-happyCheck = HappyA# "\xff\xff\x02\x00\x03\x00\x09\x00\x05\x00\x06\x00\x07\x00\x08\x00\x09\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x0c\x00\x0d\x00\x10\x00\x11\x00\x12\x00\x02\x00\x03\x00\x0e\x00\x05\x00\x06\x00\x07\x00\x08\x00\x09\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x0c\x00\x0d\x00\x10\x00\x02\x00\x12\x00\x09\x00\x05\x00\x06\x00\x07\x00\x08\x00\x09\x00\x0c\x00\x0d\x00\x0c\x00\x0d\x00\x07\x00\x08\x00\x10\x00\x02\x00\x12\x00\x06\x00\x05\x00\x06\x00\x07\x00\x08\x00\x09\x00\x0e\x00\x0a\x00\x0b\x00\x0e\x00\x0d\x00\x02\x00\x10\x00\x05\x00\x12\x00\x00\x00\x01\x00\x02\x00\x03\x00\x04\x00\x05\x00\x06\x00\x07\x00\x08\x00\x04\x00\x0a\x00\x0b\x00\x0e\x00\x0d\x00\x00\x00\x01\x00\x02\x00\x03\x00\x04\x00\x05\x00\x06\x00\x07\x00\x08\x00\x11\x00\x0a\x00\x0b\x00\x12\x00\x0d\x00\x00\x00\x01\x00\x02\x00\x03\x00\x04\x00\x05\x00\x06\x00\x07\x00\x08\x00\x13\x00\x0a\x00\x0b\x00\x0f\x00\x0d\x00\x05\x00\x06\x00\x07\x00\x08\x00\x09\x00\x0c\x00\x0a\x00\x0b\x00\x12\x00\x0d\x00\x0d\x00\x10\x00\x11\x00\x12\x00\x01\x00\x02\x00\x03\x00\x04\x00\x05\x00\x06\x00\x07\x00\x08\x00\x11\x00\x0a\x00\x0b\x00\xff\xff\x0d\x00\x05\x00\x06\x00\x07\x00\x08\x00\xff\xff\x0a\x00\x0b\x00\xff\xff\x0d\x00\x05\x00\x06\x00\x07\x00\x08\x00\xff\xff\x0a\x00\x0b\x00\xff\xff\x0d\x00\x0a\x00\x0b\x00\xff\xff\x0d\x00\x0a\x00\x0b\x00\xff\xff\x0d\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"#
-
-happyTable :: HappyAddr
-happyTable = HappyA# "\x00\x00\x0f\x00\x10\x00\x36\x00\x11\x00\x12\x00\x13\x00\x14\x00\x15\x00\x16\x00\x17\x00\x18\x00\x19\x00\x2d\x00\x29\x00\x1a\x00\x1f\x00\x1b\x00\x0f\x00\x10\x00\x31\x00\x11\x00\x12\x00\x13\x00\x14\x00\x15\x00\x16\x00\x17\x00\x18\x00\x19\x00\x2e\x00\x29\x00\x1a\x00\x0f\x00\x1b\x00\x33\x00\x11\x00\x12\x00\x13\x00\x14\x00\x15\x00\x28\x00\x29\x00\x18\x00\x19\x00\x2c\x00\x0a\x00\x1a\x00\x0f\x00\x1b\x00\x22\x00\x11\x00\x12\x00\x13\x00\x14\x00\x15\x00\x25\x00\x37\x00\x0c\x00\x35\x00\x0d\x00\x30\x00\x1a\x00\x33\x00\x1b\x00\x35\x00\x1d\x00\x04\x00\x05\x00\x06\x00\x07\x00\x08\x00\x09\x00\x0a\x00\x31\x00\x0b\x00\x0c\x00\x35\x00\x0d\x00\x1f\x00\x1d\x00\x04\x00\x05\x00\x06\x00\x07\x00\x08\x00\x09\x00\x0a\x00\x21\x00\x0b\x00\x0c\x00\x27\x00\x0d\x00\x1c\x00\x1d\x00\x04\x00\x05\x00\x06\x00\x07\x00\x08\x00\x09\x00\x0a\x00\xff\xff\x0b\x00\x0c\x00\x22\x00\x0d\x00\x11\x00\x12\x00\x13\x00\x14\x00\x15\x00\x18\x00\x27\x00\x0c\x00\x27\x00\x0d\x00\x19\x00\x1a\x00\x2b\x00\x1b\x00\x03\x00\x04\x00\x05\x00\x06\x00\x07\x00\x08\x00\x09\x00\x0a\x00\x21\x00\x0b\x00\x0c\x00\x00\x00\x0d\x00\x23\x00\x08\x00\x09\x00\x0a\x00\x00\x00\x0b\x00\x0c\x00\x00\x00\x0d\x00\x24\x00\x08\x00\x09\x00\x0a\x00\x00\x00\x0b\x00\x0c\x00\x00\x00\x0d\x00\x2b\x00\x0c\x00\x00\x00\x0d\x00\x1b\x00\x0c\x00\x00\x00\x0d\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"#
-
-happyReduceArr = Happy_Data_Array.array (2, 39) [
-	(2 , happyReduce_2),
-	(3 , happyReduce_3),
-	(4 , happyReduce_4),
-	(5 , happyReduce_5),
-	(6 , happyReduce_6),
-	(7 , happyReduce_7),
-	(8 , happyReduce_8),
-	(9 , happyReduce_9),
-	(10 , happyReduce_10),
-	(11 , happyReduce_11),
-	(12 , happyReduce_12),
-	(13 , happyReduce_13),
-	(14 , happyReduce_14),
-	(15 , happyReduce_15),
-	(16 , happyReduce_16),
-	(17 , happyReduce_17),
-	(18 , happyReduce_18),
-	(19 , happyReduce_19),
-	(20 , happyReduce_20),
-	(21 , happyReduce_21),
-	(22 , happyReduce_22),
-	(23 , happyReduce_23),
-	(24 , happyReduce_24),
-	(25 , happyReduce_25),
-	(26 , happyReduce_26),
-	(27 , happyReduce_27),
-	(28 , happyReduce_28),
-	(29 , happyReduce_29),
-	(30 , happyReduce_30),
-	(31 , happyReduce_31),
-	(32 , happyReduce_32),
-	(33 , happyReduce_33),
-	(34 , happyReduce_34),
-	(35 , happyReduce_35),
-	(36 , happyReduce_36),
-	(37 , happyReduce_37),
-	(38 , happyReduce_38),
-	(39 , happyReduce_39)
-	]
-
-happy_n_terms = 20 :: Int
-happy_n_nonterms = 15 :: Int
-
-happyReduce_2 = happySpecReduce_3  0# happyReduction_2
-happyReduction_2 happy_x_3
-	happy_x_2
-	happy_x_1
-	 =  case happyOut6 happy_x_1 of { happy_var_1 -> 
-	case happyOut5 happy_x_3 of { happy_var_3 -> 
-	happyIn5
-		 (docAppend happy_var_1 happy_var_3
-	)}}
-
-happyReduce_3 = happySpecReduce_2  0# happyReduction_3
-happyReduction_3 happy_x_2
-	happy_x_1
-	 =  case happyOut5 happy_x_2 of { happy_var_2 -> 
-	happyIn5
-		 (happy_var_2
-	)}
-
-happyReduce_4 = happySpecReduce_1  0# happyReduction_4
-happyReduction_4 happy_x_1
-	 =  case happyOut6 happy_x_1 of { happy_var_1 -> 
-	happyIn5
-		 (happy_var_1
-	)}
-
-happyReduce_5 = happySpecReduce_0  0# happyReduction_5
-happyReduction_5  =  happyIn5
-		 (DocEmpty
-	)
-
-happyReduce_6 = happySpecReduce_1  1# happyReduction_6
-happyReduction_6 happy_x_1
-	 =  case happyOut7 happy_x_1 of { happy_var_1 -> 
-	happyIn6
-		 (DocUnorderedList [happy_var_1]
-	)}
-
-happyReduce_7 = happySpecReduce_1  1# happyReduction_7
-happyReduction_7 happy_x_1
-	 =  case happyOut8 happy_x_1 of { happy_var_1 -> 
-	happyIn6
-		 (DocOrderedList [happy_var_1]
-	)}
-
-happyReduce_8 = happySpecReduce_1  1# happyReduction_8
-happyReduction_8 happy_x_1
-	 =  case happyOut9 happy_x_1 of { happy_var_1 -> 
-	happyIn6
-		 (DocDefList [happy_var_1]
-	)}
-
-happyReduce_9 = happySpecReduce_1  1# happyReduction_9
-happyReduction_9 happy_x_1
-	 =  case happyOut10 happy_x_1 of { happy_var_1 -> 
-	happyIn6
-		 (happy_var_1
-	)}
-
-happyReduce_10 = happySpecReduce_2  2# happyReduction_10
-happyReduction_10 happy_x_2
-	happy_x_1
-	 =  case happyOut10 happy_x_2 of { happy_var_2 -> 
-	happyIn7
-		 (happy_var_2
-	)}
-
-happyReduce_11 = happySpecReduce_2  3# happyReduction_11
-happyReduction_11 happy_x_2
-	happy_x_1
-	 =  case happyOut10 happy_x_2 of { happy_var_2 -> 
-	happyIn8
-		 (happy_var_2
-	)}
-
-happyReduce_12 = happyReduce 4# 4# happyReduction_12
-happyReduction_12 (happy_x_4 `HappyStk`
-	happy_x_3 `HappyStk`
-	happy_x_2 `HappyStk`
-	happy_x_1 `HappyStk`
-	happyRest)
-	 = case happyOut15 happy_x_2 of { happy_var_2 -> 
-	case happyOut15 happy_x_4 of { happy_var_4 -> 
-	happyIn9
-		 ((happy_var_2, happy_var_4)
-	) `HappyStk` happyRest}}
-
-happyReduce_13 = happySpecReduce_1  5# happyReduction_13
-happyReduction_13 happy_x_1
-	 =  case happyOut15 happy_x_1 of { happy_var_1 -> 
-	happyIn10
-		 (docParagraph happy_var_1
-	)}
-
-happyReduce_14 = happySpecReduce_1  5# happyReduction_14
-happyReduction_14 happy_x_1
-	 =  case happyOut11 happy_x_1 of { happy_var_1 -> 
-	happyIn10
-		 (DocCodeBlock happy_var_1
-	)}
-
-happyReduce_15 = happySpecReduce_1  5# happyReduction_15
-happyReduction_15 happy_x_1
-	 =  case happyOut12 happy_x_1 of { happy_var_1 -> 
-	happyIn10
-		 (DocExamples happy_var_1
-	)}
-
-happyReduce_16 = happySpecReduce_2  6# happyReduction_16
-happyReduction_16 happy_x_2
-	happy_x_1
-	 =  case happyOutTok happy_x_1 of { ((TokBirdTrack happy_var_1,_)) -> 
-	case happyOut11 happy_x_2 of { happy_var_2 -> 
-	happyIn11
-		 (docAppend (DocString happy_var_1) happy_var_2
-	)}}
-
-happyReduce_17 = happySpecReduce_1  6# happyReduction_17
-happyReduction_17 happy_x_1
-	 =  case happyOutTok happy_x_1 of { ((TokBirdTrack happy_var_1,_)) -> 
-	happyIn11
-		 (DocString happy_var_1
-	)}
-
-happyReduce_18 = happySpecReduce_2  7# happyReduction_18
-happyReduction_18 happy_x_2
-	happy_x_1
-	 =  case happyOut13 happy_x_1 of { happy_var_1 -> 
-	case happyOut12 happy_x_2 of { happy_var_2 -> 
-	happyIn12
-		 (happy_var_1 : happy_var_2
-	)}}
-
-happyReduce_19 = happySpecReduce_1  7# happyReduction_19
-happyReduction_19 happy_x_1
-	 =  case happyOut13 happy_x_1 of { happy_var_1 -> 
-	happyIn12
-		 ([happy_var_1]
-	)}
-
-happyReduce_20 = happySpecReduce_3  8# happyReduction_20
-happyReduction_20 happy_x_3
-	happy_x_2
-	happy_x_1
-	 =  case happyOutTok happy_x_1 of { ((TokExamplePrompt happy_var_1,_)) -> 
-	case happyOutTok happy_x_2 of { ((TokExampleExpression happy_var_2,_)) -> 
-	case happyOut14 happy_x_3 of { happy_var_3 -> 
-	happyIn13
-		 (makeExample happy_var_1 happy_var_2 (lines happy_var_3)
-	)}}}
-
-happyReduce_21 = happySpecReduce_2  8# happyReduction_21
-happyReduction_21 happy_x_2
-	happy_x_1
-	 =  case happyOutTok happy_x_1 of { ((TokExamplePrompt happy_var_1,_)) -> 
-	case happyOutTok happy_x_2 of { ((TokExampleExpression happy_var_2,_)) -> 
-	happyIn13
-		 (makeExample happy_var_1 happy_var_2 []
-	)}}
-
-happyReduce_22 = happySpecReduce_2  9# happyReduction_22
-happyReduction_22 happy_x_2
-	happy_x_1
-	 =  case happyOutTok happy_x_1 of { ((TokExampleResult happy_var_1,_)) -> 
-	case happyOut14 happy_x_2 of { happy_var_2 -> 
-	happyIn14
-		 (happy_var_1 ++ happy_var_2
-	)}}
-
-happyReduce_23 = happySpecReduce_1  9# happyReduction_23
-happyReduction_23 happy_x_1
-	 =  case happyOutTok happy_x_1 of { ((TokExampleResult happy_var_1,_)) -> 
-	happyIn14
-		 (happy_var_1
-	)}
-
-happyReduce_24 = happySpecReduce_2  10# happyReduction_24
-happyReduction_24 happy_x_2
-	happy_x_1
-	 =  case happyOut16 happy_x_1 of { happy_var_1 -> 
-	case happyOut15 happy_x_2 of { happy_var_2 -> 
-	happyIn15
-		 (docAppend happy_var_1 happy_var_2
-	)}}
-
-happyReduce_25 = happySpecReduce_1  10# happyReduction_25
-happyReduction_25 happy_x_1
-	 =  case happyOut16 happy_x_1 of { happy_var_1 -> 
-	happyIn15
-		 (happy_var_1
-	)}
-
-happyReduce_26 = happySpecReduce_1  11# happyReduction_26
-happyReduction_26 happy_x_1
-	 =  case happyOut18 happy_x_1 of { happy_var_1 -> 
-	happyIn16
-		 (happy_var_1
-	)}
-
-happyReduce_27 = happySpecReduce_3  11# happyReduction_27
-happyReduction_27 happy_x_3
-	happy_x_2
-	happy_x_1
-	 =  case happyOut17 happy_x_2 of { happy_var_2 -> 
-	happyIn16
-		 (DocMonospaced happy_var_2
-	)}
-
-happyReduce_28 = happySpecReduce_2  12# happyReduction_28
-happyReduction_28 happy_x_2
-	happy_x_1
-	 =  case happyOut17 happy_x_2 of { happy_var_2 -> 
-	happyIn17
-		 (docAppend (DocString "\n") happy_var_2
-	)}
-
-happyReduce_29 = happySpecReduce_2  12# happyReduction_29
-happyReduction_29 happy_x_2
-	happy_x_1
-	 =  case happyOut18 happy_x_1 of { happy_var_1 -> 
-	case happyOut17 happy_x_2 of { happy_var_2 -> 
-	happyIn17
-		 (docAppend happy_var_1 happy_var_2
-	)}}
-
-happyReduce_30 = happySpecReduce_1  12# happyReduction_30
-happyReduction_30 happy_x_1
-	 =  case happyOut18 happy_x_1 of { happy_var_1 -> 
-	happyIn17
-		 (happy_var_1
-	)}
-
-happyReduce_31 = happySpecReduce_1  13# happyReduction_31
-happyReduction_31 happy_x_1
-	 =  case happyOutTok happy_x_1 of { ((TokString happy_var_1,_)) -> 
-	happyIn18
-		 (DocString happy_var_1
-	)}
-
-happyReduce_32 = happySpecReduce_1  13# happyReduction_32
-happyReduction_32 happy_x_1
-	 =  case happyOutTok happy_x_1 of { ((TokEmphasis happy_var_1,_)) -> 
-	happyIn18
-		 (DocEmphasis (DocString happy_var_1)
-	)}
-
-happyReduce_33 = happySpecReduce_1  13# happyReduction_33
-happyReduction_33 happy_x_1
-	 =  case happyOutTok happy_x_1 of { ((TokURL happy_var_1,_)) -> 
-	happyIn18
-		 (DocURL happy_var_1
-	)}
-
-happyReduce_34 = happySpecReduce_1  13# happyReduction_34
-happyReduction_34 happy_x_1
-	 =  case happyOutTok happy_x_1 of { ((TokPic happy_var_1,_)) -> 
-	happyIn18
-		 (DocPic happy_var_1
-	)}
-
-happyReduce_35 = happySpecReduce_1  13# happyReduction_35
-happyReduction_35 happy_x_1
-	 =  case happyOutTok happy_x_1 of { ((TokAName happy_var_1,_)) -> 
-	happyIn18
-		 (DocAName happy_var_1
-	)}
-
-happyReduce_36 = happySpecReduce_1  13# happyReduction_36
-happyReduction_36 happy_x_1
-	 =  case happyOutTok happy_x_1 of { ((TokIdent happy_var_1,_)) -> 
-	happyIn18
-		 (DocIdentifier happy_var_1
-	)}
-
-happyReduce_37 = happySpecReduce_3  13# happyReduction_37
-happyReduction_37 happy_x_3
-	happy_x_2
-	happy_x_1
-	 =  case happyOut19 happy_x_2 of { happy_var_2 -> 
-	happyIn18
-		 (DocModule happy_var_2
-	)}
-
-happyReduce_38 = happySpecReduce_1  14# happyReduction_38
-happyReduction_38 happy_x_1
-	 =  case happyOutTok happy_x_1 of { ((TokString happy_var_1,_)) -> 
-	happyIn19
-		 (happy_var_1
-	)}
-
-happyReduce_39 = happySpecReduce_2  14# happyReduction_39
-happyReduction_39 happy_x_2
-	happy_x_1
-	 =  case happyOutTok happy_x_1 of { ((TokString happy_var_1,_)) -> 
-	case happyOut19 happy_x_2 of { happy_var_2 -> 
-	happyIn19
-		 (happy_var_1 ++ happy_var_2
-	)}}
-
-happyNewToken action sts stk [] =
-	happyDoAction 19# notHappyAtAll action sts stk []
-
-happyNewToken action sts stk (tk:tks) =
-	let cont i = happyDoAction i tk action sts stk tks in
-	case tk of {
-	(TokSpecial '/',_) -> cont 1#;
-	(TokSpecial '@',_) -> cont 2#;
-	(TokDefStart,_) -> cont 3#;
-	(TokDefEnd,_) -> cont 4#;
-	(TokSpecial '\"',_) -> cont 5#;
-	(TokURL happy_dollar_dollar,_) -> cont 6#;
-	(TokPic happy_dollar_dollar,_) -> cont 7#;
-	(TokAName happy_dollar_dollar,_) -> cont 8#;
-	(TokEmphasis happy_dollar_dollar,_) -> cont 9#;
-	(TokBullet,_) -> cont 10#;
-	(TokNumber,_) -> cont 11#;
-	(TokBirdTrack happy_dollar_dollar,_) -> cont 12#;
-	(TokExamplePrompt happy_dollar_dollar,_) -> cont 13#;
-	(TokExampleResult happy_dollar_dollar,_) -> cont 14#;
-	(TokExampleExpression happy_dollar_dollar,_) -> cont 15#;
-	(TokIdent happy_dollar_dollar,_) -> cont 16#;
-	(TokPara,_) -> cont 17#;
-	(TokString happy_dollar_dollar,_) -> cont 18#;
-	_ -> happyError' (tk:tks)
-	}
-
-happyError_ tk tks = happyError' (tk:tks)
-
-happyThen :: () => Maybe a -> (a -> Maybe b) -> Maybe b
-happyThen = (>>=)
-happyReturn :: () => a -> Maybe a
-happyReturn = (return)
-happyThen1 m k tks = (>>=) m (\a -> k a tks)
-happyReturn1 :: () => a -> b -> Maybe a
-happyReturn1 = \a tks -> (return) a
-happyError' :: () => [(LToken)] -> Maybe a
-happyError' = happyError
-
-parseParas tks = happySomeParser where
-  happySomeParser = happyThen (happyParse 0# tks) (\x -> happyReturn (happyOut5 x))
-
-parseString tks = happySomeParser where
-  happySomeParser = happyThen (happyParse 1# tks) (\x -> happyReturn (happyOut15 x))
-
-happySeq = happyDontSeq
-
-
-happyError :: [LToken] -> Maybe a
-happyError toks = Nothing
-
--- | Create an 'Example', stripping superfluous characters as appropriate
-makeExample :: String -> String -> [String] -> Example
-makeExample prompt expression result =
-  Example
-	(strip expression)	-- we do not care about leading and trailing
-				-- whitespace in expressions, so drop them
-	result'
-  where
-	-- 1. drop trailing whitespace from the prompt, remember the prefix
-	(prefix, _) = span isSpace prompt
-
-	-- 2. drop, if possible, the exact same sequence of whitespace
-	-- characters from each result line
-	--
-	-- 3. interpret lines that only contain the string "<BLANKLINE>" as an
-	-- empty line
-	result' = map (substituteBlankLine . tryStripPrefix prefix) result
-	  where
-		tryStripPrefix xs ys = fromMaybe ys $ stripPrefix xs ys
-
-		substituteBlankLine "<BLANKLINE>" = ""
-		substituteBlankLine line          = line
-
--- | Remove all leading and trailing whitespace
-strip :: String -> String
-strip = dropWhile isSpace . reverse . dropWhile isSpace . reverse
-{-# LINE 1 "templates/GenericTemplate.hs" #-}
-{-# LINE 1 "templates/GenericTemplate.hs" #-}
-{-# LINE 1 "<built-in>" #-}
-{-# LINE 1 "<command-line>" #-}
-{-# LINE 1 "templates/GenericTemplate.hs" #-}
--- Id: GenericTemplate.hs,v 1.26 2005/01/14 14:47:22 simonmar Exp 
-
-{-# LINE 30 "templates/GenericTemplate.hs" #-}
-
-
-data Happy_IntList = HappyCons Happy_GHC_Exts.Int# Happy_IntList
-
-
-
-
-
-{-# LINE 51 "templates/GenericTemplate.hs" #-}
-
-{-# LINE 61 "templates/GenericTemplate.hs" #-}
-
-{-# LINE 70 "templates/GenericTemplate.hs" #-}
-
-infixr 9 `HappyStk`
-data HappyStk a = HappyStk a (HappyStk a)
-
------------------------------------------------------------------------------
--- starting the parse
-
-happyParse start_state = happyNewToken start_state notHappyAtAll notHappyAtAll
-
------------------------------------------------------------------------------
--- Accepting the parse
-
--- If the current token is 0#, it means we've just accepted a partial
--- parse (a %partial parser).  We must ignore the saved token on the top of
--- the stack in this case.
-happyAccept 0# tk st sts (_ `HappyStk` ans `HappyStk` _) =
-	happyReturn1 ans
-happyAccept j tk st sts (HappyStk ans _) = 
-	(happyTcHack j (happyTcHack st)) (happyReturn1 ans)
-
------------------------------------------------------------------------------
--- Arrays only: do the next action
-
-
-
-happyDoAction i tk st
-	= {- nothing -}
-
-
-	  case action of
-		0#		  -> {- nothing -}
-				     happyFail i tk st
-		-1# 	  -> {- nothing -}
-				     happyAccept i tk st
-		n | (n Happy_GHC_Exts.<# (0# :: Happy_GHC_Exts.Int#)) -> {- nothing -}
-
-				     (happyReduceArr Happy_Data_Array.! rule) i tk st
-				     where rule = (Happy_GHC_Exts.I# ((Happy_GHC_Exts.negateInt# ((n Happy_GHC_Exts.+# (1# :: Happy_GHC_Exts.Int#))))))
-		n		  -> {- nothing -}
-
-
-				     happyShift new_state i tk st
-				     where (new_state) = (n Happy_GHC_Exts.-# (1# :: Happy_GHC_Exts.Int#))
-   where (off)    = indexShortOffAddr happyActOffsets st
-         (off_i)  = (off Happy_GHC_Exts.+# i)
-	 check  = if (off_i Happy_GHC_Exts.>=# (0# :: Happy_GHC_Exts.Int#))
-			then (indexShortOffAddr happyCheck off_i Happy_GHC_Exts.==#  i)
-			else False
-         (action)
-          | check     = indexShortOffAddr happyTable off_i
-          | otherwise = indexShortOffAddr happyDefActions st
-
-{-# LINE 130 "templates/GenericTemplate.hs" #-}
-
-
-indexShortOffAddr (HappyA# arr) off =
-	Happy_GHC_Exts.narrow16Int# i
-  where
-        i = Happy_GHC_Exts.word2Int# (Happy_GHC_Exts.or# (Happy_GHC_Exts.uncheckedShiftL# high 8#) low)
-        high = Happy_GHC_Exts.int2Word# (Happy_GHC_Exts.ord# (Happy_GHC_Exts.indexCharOffAddr# arr (off' Happy_GHC_Exts.+# 1#)))
-        low  = Happy_GHC_Exts.int2Word# (Happy_GHC_Exts.ord# (Happy_GHC_Exts.indexCharOffAddr# arr off'))
-        off' = off Happy_GHC_Exts.*# 2#
-
-
-
-
-
-data HappyAddr = HappyA# Happy_GHC_Exts.Addr#
-
-
-
-
------------------------------------------------------------------------------
--- HappyState data type (not arrays)
-
-{-# LINE 163 "templates/GenericTemplate.hs" #-}
-
------------------------------------------------------------------------------
--- Shifting a token
-
-happyShift new_state 0# tk st sts stk@(x `HappyStk` _) =
-     let (i) = (case Happy_GHC_Exts.unsafeCoerce# x of { (Happy_GHC_Exts.I# (i)) -> i }) in
---     trace "shifting the error token" $
-     happyDoAction i tk new_state (HappyCons (st) (sts)) (stk)
-
-happyShift new_state i tk st sts stk =
-     happyNewToken new_state (HappyCons (st) (sts)) ((happyInTok (tk))`HappyStk`stk)
-
--- happyReduce is specialised for the common cases.
-
-happySpecReduce_0 i fn 0# tk st sts stk
-     = happyFail 0# tk st sts stk
-happySpecReduce_0 nt fn j tk st@((action)) sts stk
-     = happyGoto nt j tk st (HappyCons (st) (sts)) (fn `HappyStk` stk)
-
-happySpecReduce_1 i fn 0# tk st sts stk
-     = happyFail 0# tk st sts stk
-happySpecReduce_1 nt fn j tk _ sts@((HappyCons (st@(action)) (_))) (v1`HappyStk`stk')
-     = let r = fn v1 in
-       happySeq r (happyGoto nt j tk st sts (r `HappyStk` stk'))
-
-happySpecReduce_2 i fn 0# tk st sts stk
-     = happyFail 0# tk st sts stk
-happySpecReduce_2 nt fn j tk _ (HappyCons (_) (sts@((HappyCons (st@(action)) (_))))) (v1`HappyStk`v2`HappyStk`stk')
-     = let r = fn v1 v2 in
-       happySeq r (happyGoto nt j tk st sts (r `HappyStk` stk'))
-
-happySpecReduce_3 i fn 0# tk st sts stk
-     = happyFail 0# tk st sts stk
-happySpecReduce_3 nt fn j tk _ (HappyCons (_) ((HappyCons (_) (sts@((HappyCons (st@(action)) (_))))))) (v1`HappyStk`v2`HappyStk`v3`HappyStk`stk')
-     = let r = fn v1 v2 v3 in
-       happySeq r (happyGoto nt j tk st sts (r `HappyStk` stk'))
-
-happyReduce k i fn 0# tk st sts stk
-     = happyFail 0# tk st sts stk
-happyReduce k nt fn j tk st sts stk
-     = case happyDrop (k Happy_GHC_Exts.-# (1# :: Happy_GHC_Exts.Int#)) sts of
-	 sts1@((HappyCons (st1@(action)) (_))) ->
-        	let r = fn stk in  -- it doesn't hurt to always seq here...
-       		happyDoSeq r (happyGoto nt j tk st1 sts1 r)
-
-happyMonadReduce k nt fn 0# tk st sts stk
-     = happyFail 0# tk st sts stk
-happyMonadReduce k nt fn j tk st sts stk =
-        happyThen1 (fn stk tk) (\r -> happyGoto nt j tk st1 sts1 (r `HappyStk` drop_stk))
-       where (sts1@((HappyCons (st1@(action)) (_)))) = happyDrop k (HappyCons (st) (sts))
-             drop_stk = happyDropStk k stk
-
-happyMonad2Reduce k nt fn 0# tk st sts stk
-     = happyFail 0# tk st sts stk
-happyMonad2Reduce k nt fn j tk st sts stk =
-       happyThen1 (fn stk tk) (\r -> happyNewToken new_state sts1 (r `HappyStk` drop_stk))
-       where (sts1@((HappyCons (st1@(action)) (_)))) = happyDrop k (HappyCons (st) (sts))
-             drop_stk = happyDropStk k stk
-
-             (off) = indexShortOffAddr happyGotoOffsets st1
-             (off_i) = (off Happy_GHC_Exts.+# nt)
-             (new_state) = indexShortOffAddr happyTable off_i
-
-
-
-
-happyDrop 0# l = l
-happyDrop n (HappyCons (_) (t)) = happyDrop (n Happy_GHC_Exts.-# (1# :: Happy_GHC_Exts.Int#)) t
-
-happyDropStk 0# l = l
-happyDropStk n (x `HappyStk` xs) = happyDropStk (n Happy_GHC_Exts.-# (1#::Happy_GHC_Exts.Int#)) xs
-
------------------------------------------------------------------------------
--- Moving to a new state after a reduction
-
-
-happyGoto nt j tk st = 
-   {- nothing -}
-   happyDoAction j tk new_state
-   where (off) = indexShortOffAddr happyGotoOffsets st
-         (off_i) = (off Happy_GHC_Exts.+# nt)
-         (new_state) = indexShortOffAddr happyTable off_i
-
-
-
-
------------------------------------------------------------------------------
--- Error recovery (0# is the error token)
-
--- parse error if we are in recovery and we fail again
-happyFail  0# tk old_st _ stk =
---	trace "failing" $ 
-    	happyError_ tk
-
-{-  We don't need state discarding for our restricted implementation of
-    "error".  In fact, it can cause some bogus parses, so I've disabled it
-    for now --SDM
-
--- discard a state
-happyFail  0# tk old_st (HappyCons ((action)) (sts)) 
-						(saved_tok `HappyStk` _ `HappyStk` stk) =
---	trace ("discarding state, depth " ++ show (length stk))  $
-	happyDoAction 0# tk action sts ((saved_tok`HappyStk`stk))
--}
-
--- Enter error recovery: generate an error token,
---                       save the old token and carry on.
-happyFail  i tk (action) sts stk =
---      trace "entering error recovery" $
-	happyDoAction 0# tk action sts ( (Happy_GHC_Exts.unsafeCoerce# (Happy_GHC_Exts.I# (i))) `HappyStk` stk)
-
--- Internal happy errors:
-
-notHappyAtAll :: a
-notHappyAtAll = error "Internal Happy error\n"
-
------------------------------------------------------------------------------
--- Hack to get the typechecker to accept our action functions
-
-
-happyTcHack :: Happy_GHC_Exts.Int# -> a -> a
-happyTcHack x y = y
-{-# INLINE happyTcHack #-}
-
-
------------------------------------------------------------------------------
--- Seq-ing.  If the --strict flag is given, then Happy emits 
---	happySeq = happyDoSeq
--- otherwise it emits
--- 	happySeq = happyDontSeq
-
-happyDoSeq, happyDontSeq :: a -> b -> b
-happyDoSeq   a b = a `seq` b
-happyDontSeq a b = b
-
------------------------------------------------------------------------------
--- Don't inline any functions from the template.  GHC has a nasty habit
--- of deciding to inline happyGoto everywhere, which increases the size of
--- the generated parser quite a bit.
-
-
-{-# NOINLINE happyDoAction #-}
-{-# NOINLINE happyTable #-}
-{-# NOINLINE happyCheck #-}
-{-# NOINLINE happyActOffsets #-}
-{-# NOINLINE happyGotoOffsets #-}
-{-# NOINLINE happyDefActions #-}
-
-{-# NOINLINE happyShift #-}
-{-# NOINLINE happySpecReduce_0 #-}
-{-# NOINLINE happySpecReduce_1 #-}
-{-# NOINLINE happySpecReduce_2 #-}
-{-# NOINLINE happySpecReduce_3 #-}
-{-# NOINLINE happyReduce #-}
-{-# NOINLINE happyMonadReduce #-}
-{-# NOINLINE happyGoto #-}
-{-# NOINLINE happyFail #-}
-
--- end of Happy Template.
diff --git a/doc/Makefile b/doc/Makefile
--- a/doc/Makefile
+++ b/doc/Makefile
@@ -1,6 +1,8 @@
-include config.mk
+SPHINX_BUILD ?= sphinx-build
 
-XML_DOC = haddock
-INSTALL_XML_DOC = haddock
+all : html
 
-include docbook-xml.mk
+.PHONY : html
+
+html :
+	$(SPHINX_BUILD) -b html . .build-html
diff --git a/doc/README b/doc/README
deleted file mode 100644
--- a/doc/README
+++ /dev/null
@@ -1,25 +0,0 @@
-Haddock documentation
----------------------
-
-The documentation is in DocBook XML format.  You need some tools to
-process it: at least xsltproc, and the DocBook XML DTD and XSL
-stylesheets.  There's a configure script to detect the right way to
-process the documentation on your system, and a Makefile to actually
-do the processing (so, on Windows, you'll need Cygwin or MSys in
-addition to the DocBook XML tools).  To build the HTML documentation:
-
-   $ ./configure
-   $ make html
-
-which leaves the HTML documentation in a haddock/ subdirectory.
-
-Printable documentation can also be produced, eg.:
-
-   $ make pdf
-
-or
-
-   $ make ps
-
-Generating the printed formats requires more tools (fop or xmltex) and
-tends to be a bit harder.
diff --git a/doc/README.md b/doc/README.md
new file mode 100644
--- /dev/null
+++ b/doc/README.md
@@ -0,0 +1,10 @@
+# Haddock documentation
+
+The documentation is in ReStructuredText format. You need
+[Sphinx](http://www.sphinx-doc.org/) to process it. To build the HTML
+documentation,
+
+    $ make html
+
+which leaves the HTML documentation the `.build-html/` subdirectory.
+
diff --git a/doc/aclocal.m4 b/doc/aclocal.m4
deleted file mode 100644
--- a/doc/aclocal.m4
+++ /dev/null
@@ -1,174 +0,0 @@
-# FP_GEN_DOCBOOK_XML
-# ------------------
-# Generates a DocBook XML V4.2 document in conftest.xml.
-AC_DEFUN([FP_GEN_DOCBOOK_XML],
-[rm -f conftest.xml
-cat > conftest.xml << EOF
-<?xml version="1.0" encoding="iso-8859-1"?>
-<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
-   "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
-<book id="test">
-  <title>A DocBook Test Document</title>
-  <chapter id="id-one">
-    <title>A Chapter Title</title>
-    <para>This is a paragraph, referencing <xref linkend="id-two"/>.</para>
-  </chapter>
-  <chapter id="id-two">
-    <title>Another Chapter Title</title>
-    <para>This is another paragraph, referencing <xref linkend="id-one"/>.</para>
-  </chapter>
-</book>
-EOF
-]) # FP_GEN_DOCBOOK_XML
-
-
-# FP_PROG_XSLTPROC
-# ----------------
-# Sets the output variable XsltprocCmd to the full path of the XSLT processor
-# xsltproc. XsltprocCmd is empty if xsltproc could not be found.
-AC_DEFUN([FP_PROG_XSLTPROC],
-[AC_PATH_PROG([XsltprocCmd], [xsltproc])
-if test -z "$XsltprocCmd"; then
-  AC_MSG_WARN([cannot find xsltproc in your PATH, you will not be able to build the documentation])
-fi
-])# FP_PROG_XSLTPROC
-
-
-# FP_DIR_DOCBOOK_XSL(XSL-DIRS)
-# ----------------------------
-# Check which of the directories XSL-DIRS contains DocBook XSL stylesheets. The
-# output variable DIR_DOCBOOK_XSL will contain the first usable directory or
-# will be empty if none could be found.
-AC_DEFUN([FP_DIR_DOCBOOK_XSL],
-[AC_REQUIRE([FP_PROG_XSLTPROC])dnl
-if test -n "$XsltprocCmd"; then
-  AC_CACHE_CHECK([for DocBook XSL stylesheet directory], fp_cv_dir_docbook_xsl,
-  [FP_GEN_DOCBOOK_XML
-  fp_cv_dir_docbook_xsl=no
-  for fp_var in $1; do
-     if $XsltprocCmd ${fp_var}/html/docbook.xsl conftest.xml > /dev/null 2>&1; then
-        fp_cv_dir_docbook_xsl=$fp_var
-        break
-     fi
-  done
-  rm -rf conftest*])
-fi
-if test x"$fp_cv_dir_docbook_xsl" = xno; then
-  AC_MSG_WARN([cannot find DocBook XSL stylesheets, you will not be able to build the documentation])
-  DIR_DOCBOOK_XSL=
-else
-  DIR_DOCBOOK_XSL=$fp_cv_dir_docbook_xsl
-fi
-AC_SUBST([DIR_DOCBOOK_XSL])
-])# FP_DIR_DOCBOOK_XSL
-
-
-# FP_PROG_XMLLINT
-# ----------------
-# Sets the output variable XmllintCmd to the full path of the XSLT processor
-# xmllint. XmllintCmd is empty if xmllint could not be found.
-AC_DEFUN([FP_PROG_XMLLINT],
-[AC_PATH_PROG([XmllintCmd], [xmllint])
-if test -z "$XmllintCmd"; then
-  AC_MSG_WARN([cannot find xmllint in your PATH, you will not be able to validate your documentation])
-fi
-])# FP_PROG_XMLLINT
-
-
-# FP_CHECK_DOCBOOK_DTD
-# --------------------
-AC_DEFUN([FP_CHECK_DOCBOOK_DTD],
-[AC_REQUIRE([FP_PROG_XMLLINT])dnl
-if test -n "$XmllintCmd"; then
-  AC_MSG_CHECKING([for DocBook DTD])
-  FP_GEN_DOCBOOK_XML
-  if $XmllintCmd --valid --noout conftest.xml > /dev/null 2>&1; then
-    AC_MSG_RESULT([ok])
-  else
-    AC_MSG_RESULT([failed])
-    AC_MSG_WARN([cannot find a DTD for DocBook XML V4.2, you will not be able to validate your documentation])
-    AC_MSG_WARN([check your XML_CATALOG_FILES environment variable and/or /etc/xml/catalog])
-  fi
-  rm -rf conftest*
-fi
-])# FP_CHECK_DOCBOOK_DTD
-
-
-# FP_GEN_FO
-# ------------------
-# Generates a formatting objects document in conftest.fo.
-AC_DEFUN([FP_GEN_FO],
-[rm -f conftest.fo
-cat > conftest.fo << EOF
-<?xml version="1.0"?>
-<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
-  <fo:layout-master-set>
-    <fo:simple-page-master master-name="blank">
-      <fo:region-body/>
-    </fo:simple-page-master>
-  </fo:layout-master-set>
-  <fo:page-sequence master-reference="blank">
-    <fo:flow flow-name="xsl-region-body">
-      <fo:block>
-        Test!
-      </fo:block>
-    </fo:flow>
-  </fo:page-sequence>
-</fo:root>
-EOF
-]) # FP_GEN_FO
-
-
-# FP_PROG_FOP
-# -----------
-# Set the output variable 'FopCmd' to the first working 'fop' in the current
-# 'PATH'. Note that /usr/bin/fop is broken in SuSE 9.1 (unpatched), so try
-# /usr/share/fop/fop.sh in that case (or no 'fop'), too.
-AC_DEFUN([FP_PROG_FOP],
-[AC_PATH_PROGS([FopCmd1], [fop])
-if test -n "$FopCmd1"; then
-  AC_CACHE_CHECK([for $FopCmd1 usability], [fp_cv_fop_usability],
-    [FP_GEN_FO
-    if "$FopCmd1" -fo conftest.fo -ps conftest.ps > /dev/null 2>&1; then
-      fp_cv_fop_usability=yes
-    else
-      fp_cv_fop_usability=no
-    fi
-    rm -rf conftest*])
-  if test x"$fp_cv_fop_usability" = xyes; then
-     FopCmd=$FopCmd1
-  fi
-fi
-if test -z "$FopCmd"; then
-  AC_PATH_PROGS([FopCmd2], [fop.sh], , [/usr/share/fop])
-  FopCmd=$FopCmd2
-fi
-AC_SUBST([FopCmd])
-])# FP_PROG_FOP
-
-
-# FP_PROG_FO_PROCESSOR
-# --------------------
-# Try to find an FO processor. PassiveTeX output is sometimes a bit strange, so
-# try FOP first. Sets the output variables FopCmd, XmltexCmd, DvipsCmd, and
-# PdfxmltexCmd.
-AC_DEFUN([FP_PROG_FO_PROCESSOR],
-[AC_REQUIRE([FP_PROG_FOP])
-AC_PATH_PROG([XmltexCmd], [xmltex])
-AC_PATH_PROG([DvipsCmd], [dvips])
-if test -z "$FopCmd"; then
-  if test -z "$XmltexCmd"; then
-    AC_MSG_WARN([cannot find an FO => DVI converter, you will not be able to build DVI or PostScript documentation])
-  else
-    if test -z "$DvipsCmd"; then
-      AC_MSG_WARN([cannot find a DVI  => PS converter, you will not be able to build PostScript documentation])
-    fi
-  fi
-  AC_PATH_PROG([PdfxmltexCmd], [pdfxmltex])
-  if test -z "$PdfxmltexCmd"; then
-    AC_MSG_WARN([cannot find an FO => PDF converter, you will not be able to build PDF documentation])
-  fi
-elif test -z "$XmltexCmd"; then
-  AC_MSG_WARN([cannot find an FO => DVI converter, you will not be able to build DVI documentation])
-fi
-])# FP_PROG_FO_PROCESSOR
diff --git a/doc/common-errors.rst b/doc/common-errors.rst
new file mode 100644
--- /dev/null
+++ b/doc/common-errors.rst
@@ -0,0 +1,19 @@
+Common Errors
+=============
+
+``parse error on input ‘-- | xxx’``
+-----------------------------------
+
+This is probably caused by the ``-- | xxx`` comment not following a declaration. I.e. use ``-- xxx`` instead. See :ref:`top-level-declaration`.
+
+``parse error on input ‘-- $ xxx’``
+-----------------------------------
+
+You've probably commented out code like::
+
+  f x
+    $ xxx
+    
+``-- $`` is a special syntax for named chunks, see :ref:`named-chunks`. You can fix this by escaping the ``$``::
+
+  -- \$ xxx
diff --git a/doc/conf.py b/doc/conf.py
new file mode 100644
--- /dev/null
+++ b/doc/conf.py
@@ -0,0 +1,68 @@
+# -*- coding: utf-8 -*-
+
+import sys
+import os
+import shlex
+
+extensions = []
+
+source_suffix = '.rst'
+master_doc = 'index'
+
+# General information about the project.
+project = u'Haddock'
+copyright = u'2016, Simon Marlow'
+author = u'Simon Marlow'
+version = '1.0'
+release = '1.0'
+
+language = 'en'
+
+# List of patterns, relative to source directory, that match files and
+# directories to ignore when looking for source files.
+exclude_patterns = ['.build']
+todo_include_todos = False
+
+# Syntax highlighting
+highlight_language = 'haskell'
+pygments_style = 'tango'
+
+# -- Options for HTML output ----------------------------------------------
+
+htmlhelp_basename = 'Haddockdoc'
+
+
+# -- Options for LaTeX output ---------------------------------------------
+
+latex_elements = { }
+
+# Grouping the document tree into LaTeX files. List of tuples
+# (source start file, target name, title,
+#  author, documentclass [howto, manual, or own class]).
+latex_documents = [
+  (master_doc, 'Haddock.tex', u'Haddock Documentation',
+   u'Simon Marlow', 'manual'),
+]
+
+
+# -- Options for manual page output ---------------------------------------
+
+# One entry per manual page. List of tuples
+# (source start file, name, description, authors, manual section).
+man_pages = [
+    (master_doc, 'haddock', u'Haddock Documentation',
+     [author], 1)
+]
+
+
+# -- Options for Texinfo output -------------------------------------------
+
+# Grouping the document tree into Texinfo files. List of tuples
+# (source start file, target name, title, author,
+#  dir menu entry, description, category)
+texinfo_documents = [
+  (master_doc, 'Haddock', u'Haddock Documentation',
+   author, 'Haddock', 'One line description of project.',
+   'Miscellaneous'),
+]
+
diff --git a/doc/config.mk.in b/doc/config.mk.in
deleted file mode 100644
--- a/doc/config.mk.in
+++ /dev/null
@@ -1,15 +0,0 @@
-#-----------------------------------------------------------------------------
-# DocBook XML stuff
-
-XSLTPROC		= @XsltprocCmd@
-XMLLINT			= @XmllintCmd@
-FOP			= @FopCmd@
-XMLTEX			= @XmltexCmd@
-PDFXMLTEX		= @PdfxmltexCmd@
-DVIPS			= @DvipsCmd@
-
-DIR_DOCBOOK_XSL		= @DIR_DOCBOOK_XSL@
-
-XSLTPROC_LABEL_OPTS	= --stringparam toc.section.depth 3 \
-			  --stringparam section.autolabel 1 \
-			  --stringparam section.label.includes.component.label 1
diff --git a/doc/configure.ac b/doc/configure.ac
deleted file mode 100644
--- a/doc/configure.ac
+++ /dev/null
@@ -1,12 +0,0 @@
-
-AC_INIT([Haddock docs], [1.0], [simonmar@microsoft.com], [])
-
-AC_CONFIG_SRCDIR([Makefile])
-
-dnl ** check for DocBook toolchain
-FP_CHECK_DOCBOOK_DTD
-FP_DIR_DOCBOOK_XSL([/usr/share/xml/docbook/stylesheet/nwalsh/current /usr/share/xml/docbook/stylesheet/nwalsh /usr/share/sgml/docbook/docbook-xsl-stylesheets* /usr/share/sgml/docbook/xsl-stylesheets* /opt/kde?/share/apps/ksgmltools2/docbook/xsl /usr/share/docbook-xsl /usr/share/sgml/docbkxsl /usr/local/share/xsl/docbook /sw/share/xml/xsl/docbook-xsl /usr/share/xml/docbook/xsl-stylesheets-*])
-FP_PROG_FO_PROCESSOR
-
-AC_CONFIG_FILES([config.mk])
-AC_OUTPUT
diff --git a/doc/docbook-xml.mk b/doc/docbook-xml.mk
deleted file mode 100644
--- a/doc/docbook-xml.mk
+++ /dev/null
@@ -1,130 +0,0 @@
-#-----------------------------------------------------------------------------
-# DocBook XML
-
-.PHONY: html html-no-chunks chm HxS fo dvi ps pdf
-
-ifneq "$(XML_DOC)" ""
-
-all :: html
-
-# multi-file XML document: main document name is specified in $(XML_DOC),
-# sub-documents (.xml files) listed in $(XML_SRCS).
-
-ifeq "$(XML_SRCS)" ""
-XML_SRCS = $(wildcard *.xml)
-endif
-
-XML_HTML           = $(addsuffix /index.html,$(basename $(XML_DOC)))
-XML_HTML_NO_CHUNKS = $(addsuffix .html,$(XML_DOC))
-XML_CHM            = $(addsuffix .chm,$(XML_DOC))
-XML_HxS            = $(addsuffix .HxS,$(XML_DOC))
-XML_FO             = $(addsuffix .fo,$(XML_DOC))
-XML_DVI            = $(addsuffix .dvi,$(XML_DOC))
-XML_PS             = $(addsuffix .ps,$(XML_DOC))
-XML_PDF            = $(addsuffix .pdf,$(XML_DOC))
-
-$(XML_HTML) $(XML_NO_CHUNKS_HTML) $(XML_FO) $(XML_DVI) $(XML_PS) $(XML_PDF) :: $(XML_SRCS)
-
-html           :: $(XML_HTML)
-html-no-chunks :: $(XML_HTML_NO_CHUNKS)
-chm            :: $(XML_CHM)
-HxS            :: $(XML_HxS)
-fo             :: $(XML_FO)
-dvi            :: $(XML_DVI)
-ps             :: $(XML_PS)
-pdf            :: $(XML_PDF)
-
-CLEAN_FILES += $(XML_HTML_NO_CHUNKS) $(XML_FO) $(XML_DVI) $(XML_PS) $(XML_PDF)
-
-FPTOOLS_CSS     = fptools.css
-
-clean ::
-	$(RM) -rf $(XML_DOC).out $(basename $(XML_DOC)) $(basename $(XML_DOC))-htmlhelp
-
-validate ::
-	$(XMLLINT) --valid --noout $(XMLLINT_OPTS) $(XML_DOC).xml
-endif
-
-#-----------------------------------------------------------------------------
-# DocBook XML suffix rules
-#
-
-%.html : %.xml
-	$(XSLTPROC) --output $@ \
-		    --stringparam html.stylesheet $(FPTOOLS_CSS) \
-		    $(XSLTPROC_LABEL_OPTS) $(XSLTPROC_OPTS) \
-		    $(DIR_DOCBOOK_XSL)/html/docbook.xsl $<
-
-%/index.html : %.xml
-	$(RM) -rf $(dir $@)
-	$(XSLTPROC) --stringparam base.dir $(dir $@) \
-		    --stringparam use.id.as.filename 1 \
-		    --stringparam html.stylesheet $(FPTOOLS_CSS) \
-		    $(XSLTPROC_LABEL_OPTS) $(XSLTPROC_OPTS) \
-		    $(DIR_DOCBOOK_XSL)/html/chunk.xsl $<
-	cp $(FPTOOLS_CSS) $(dir $@)
-
-# Note: Numeric labeling seems to be uncommon for HTML Help
-%-htmlhelp/index.html : %.xml
-	$(RM) -rf $(dir $@)
-	$(XSLTPROC) --stringparam base.dir $(dir $@) \
-		    --stringparam manifest.in.base.dir 1 \
-		    --stringparam htmlhelp.chm "..\\"$(basename $<).chm \
-		    $(XSLTPROC_OPTS) \
-		    $(DIR_DOCBOOK_XSL)/htmlhelp/htmlhelp.xsl $<
-
-%-htmlhelp2/collection.HxC : %.xml
-	$(RM) -rf $(dir $@)
-	$(XSLTPROC) --stringparam base.dir $(dir $@) \
-		    --stringparam use.id.as.filename 1 \
-		    --stringparam manifest.in.base.dir 1 \
-		    $(XSLTPROC_OPTS) \
-		    $(DIR_DOCBOOK_XSL)/htmlhelp2/htmlhelp2.xsl $<
-
-# TODO: Detect hhc & Hxcomp via autoconf
-#
-# Two obstacles here:
-#
-# * The reason for the strange "if" below is that hhc returns 0 on error and 1
-#   on success, the opposite of what shells and make expect.
-#
-# * There seems to be some trouble with DocBook indices, but the *.chm looks OK,
-#   anyway, therefore we pacify make by "|| true". Ugly...
-#
-%.chm : %-htmlhelp/index.html
-	( cd $(dir $<) && if hhc htmlhelp.hhp ; then false ; else true ; fi ) || true
-
-%.HxS : %-htmlhelp2/collection.HxC
-	( cd $(dir $<) && if Hxcomp -p collection.HxC -o ../$@ ; then false ; else true ; fi )
-
-%.fo : %.xml
-	$(XSLTPROC) --output $@ \
-		    --stringparam draft.mode no \
-		    $(XSLTPROC_LABEL_OPTS) $(XSLTPROC_OPTS) \
-		    $(DIR_DOCBOOK_XSL)/fo/docbook.xsl $<
-
-ifeq "$(FOP)" ""
-ifneq "$(PDFXMLTEX)" ""
-%.pdf : %.fo
-	$(PDFXMLTEX) $<
-	if grep "LaTeX Warning: Label(s) may have changed.Rerun to get cross-references right." $(basename $@).log > /dev/null ; then \
-	  $(PDFXMLTEX) $< ; \
-	  $(PDFXMLTEX) $< ; \
-	fi
-endif
-else
-%.ps : %.fo
-	$(FOP) $(FOP_OPTS) -fo $< -ps $@
-
-%.pdf : %.fo
-	$(FOP) $(FOP_OPTS) -fo $< -pdf $@
-endif
-
-ifneq "$(XMLTEX)" ""
-%.dvi : %.fo
-	$(XMLTEX) $<
-	if grep "LaTeX Warning: Label(s) may have changed.Rerun to get cross-references right." $(basename $@).log > /dev/null ; then \
-	  $(XMLTEX) $< ; \
-	  $(XMLTEX) $< ; \
-	fi
-endif
diff --git a/doc/fptools.css b/doc/fptools.css
deleted file mode 100644
--- a/doc/fptools.css
+++ /dev/null
@@ -1,36 +0,0 @@
-div {
-  font-family: sans-serif;
-  color: black;
-  background: white
-}
-
-h1, h2, h3, h4, h5, h6, p.title { color: #005A9C }
-
-h1 { font:            170% sans-serif }
-h2 { font:            140% sans-serif }
-h3 { font:            120% sans-serif }
-h4 { font: bold       100% sans-serif }
-h5 { font: italic     100% sans-serif }
-h6 { font: small-caps 100% sans-serif }
-
-pre {
-  font-family: monospace;
-  border-width: 1px;
-  border-style: solid;
-  padding: 0.3em
-}
-
-pre.screen         { color: #006400 }
-pre.programlisting { color: maroon }
-
-div.example {
-  background-color: #fffcf5;
-  margin: 1ex 0em;
-  border: solid #412e25 1px;
-  padding: 0ex 0.4em
-}
-
-a:link    { color:      #0000C8 }
-a:hover   { background: #FFFFA8 }
-a:active  { color:      #D00000 }
-a:visited { color:      #680098 }
diff --git a/doc/haddock.xml b/doc/haddock.xml
deleted file mode 100644
--- a/doc/haddock.xml
+++ /dev/null
@@ -1,1856 +0,0 @@
-<?xml version="1.0" encoding="iso-8859-1"?>
-<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
-   "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
-
-<book id="haddock">
-  <bookinfo>
-    <date>2004-08-02</date>
-    <title>Haddock User Guide</title>
-    <author>
-      <firstname>Simon</firstname>
-      <surname>Marlow</surname>
-    </author>
-    <address><email>marlowsd@gmail.com</email></address>
-    <author>
-      <firstname>David</firstname>
-      <surname>Waern</surname>
-    </author>
-    <address><email>david.waern@gmail.com</email></address>
-    <copyright>
-      <year>2010</year>
-      <holder>Simon Marlow, David Waern</holder>
-    </copyright>
-    <abstract>
-      <para>This document describes Haddock version 2.9.4, a Haskell
-      documentation tool.</para>
-    </abstract>
-  </bookinfo>
-
-  <!-- Table of contents -->
-  <toc></toc>
-
-  <chapter id="introduction">
-    <title>Introduction</title>
-
-    <para>This is Haddock, a tool for automatically generating
-    documentation from annotated Haskell source code.  Haddock was
-    designed with several goals in mind:</para>
-
-    <itemizedlist>
-      <listitem>
-	<para>When documenting APIs, it is desirable to keep the
-	documentation close to the actual interface or implementation
-	of the API, preferably in the same file, to reduce the risk
-	that the two become out of sync.  Haddock therefore lets you
-	write the documentation for an entity (function, type, or
-	class) next to the definition of the entity in the source
-	code.</para>
-      </listitem>
-      <listitem>
-	<para>There is a tremendous amount of useful API documentation
-	that can be extracted from just the bare source code,
-	including types of exported functions, definitions of data
-	types and classes, and so on.  Haddock can therefore generate
-	documentation from a set of straight Haskell 98 modules, and
-	the documentation will contain precisely the interface that is
-	available to a programmer using those modules.</para>
-      </listitem>
-      <listitem>
-	<para>Documentation annotations in the source code should be
-	easy on the eye when editing the source code itself, so as not
-	to obsure the code and to make reading and writing
-	documentation annotations easy.  The easier it is to write
-	documentation, the more likely the programmer is to do it.
-	Haddock therefore uses lightweight markup in its annotations,
-	taking several ideas from <ulink
-	url="http://www.cse.unsw.edu.au/~chak/haskell/idoc/">IDoc</ulink>.
-	In fact, Haddock can understand IDoc-annotated source
-	code.</para>
-      </listitem>
-      <listitem>
-	<para>The documentation should not expose any of the structure
-	of the implementation, or to put it another way, the
-	implementer of the API should be free to structure the
-	implementation however he or she wishes, without exposing any
-	of that structure to the consumer.  In practical terms, this
-	means that while an API may internally consist of several
-	Haskell modules, we often only want to expose a single module
-	to the user of the interface, where this single module just
-	re-exports the relevant parts of the implementation
-	modules.</para>
-
-	<para>Haddock therefore understands the Haskell module system
-	and can generate documentation which hides not only
-	non-exported entities from the interface, but also the
-	internal module structure of the interface.  A documentation
-	annotation can still be placed next to the implementation, and
-	it will be propagated to the external module in the generated
-	documentation.</para>
-      </listitem>
-      <listitem>
-	<para>Being able to move around the documentation by following
-	hyperlinks is essential.  Documentation generated by Haddock
-	is therefore littered with hyperlinks: every type and class
-	name is a link to the corresponding definition, and
-	user-written documentation annotations can contain identifiers
-	which are linked automatically when the documentation is
-	generated.</para>
-      </listitem>
-      <listitem>
-	<para>We might want documentation in multiple formats - online
-	and printed, for example.  Haddock comes with HTML, LaTeX,
-  and Hoogle backends, and it is structured in such a way that adding new
-	back-ends is straightforward.</para>
-      </listitem>
-    </itemizedlist>
-
-    <section id="obtaining">
-      <title>Obtaining Haddock</title>
-
-      <para>Distributions (source &amp; binary) of Haddock can be obtained
-      from its <ulink url="http://www.haskell.org/haddock/">web
-      site</ulink>.</para>
-
-      <para>Up-to-date sources can also be obtained from our public
-      darcs repository.  The Haddock sources are at
-      <literal>http://code.haskell.org/haddock</literal>.  See
-      <ulink url="http://www.darcs.net/">darcs.net</ulink> for more
-      information on the darcs version control utility.</para>
-    </section>
-
-    <section id="license">
-      <title>License</title>
-
-      <para>The following license covers this documentation, and the
-      Haddock source code, except where otherwise indicated.</para>
-
-      <blockquote>
-	<para>Copyright 2002-2010, Simon Marlow.  All rights reserved.</para>
-
-	<para>Redistribution and use in source and binary forms, with
-        or without modification, are permitted provided that the
-        following conditions are met:</para>
-
-	<itemizedlist>
-	  <listitem>
-	    <para>Redistributions of source code must retain the above
-            copyright notice, this list of conditions and the
-            following disclaimer.</para>
-	  </listitem>
-	  <listitem>
-	    <para>Redistributions in binary form must reproduce the
-            above copyright notice, this list of conditions and the
-            following disclaimer in the documentation and/or other
-            materials provided with the distribution.</para>
-	  </listitem>
-	</itemizedlist>
-
-	<para>THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS "AS
-        IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-        LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
-        FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
-        SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT,
-        INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-        DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-        SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-        OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-        LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-        (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
-        THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
-        OF SUCH DAMAGE.</para>
-      </blockquote>
-    </section>
-
-    <section>
-      <title>Contributors</title>
-      <para>Haddock was originally written by Simon Marlow. Since it is an open source
-      project, many people have contributed to its development over the years.
-      Below is a list of contributors in alphabetical order that we hope is
-      somewhat complete. If you think you are missing from this list, please contact
-      us.
-      </para>
-      <itemizedlist>
-	<listitem>Ashley Yakeley</listitem>
-	<listitem>Benjamin Franksen</listitem>
-	<listitem>Brett Letner</listitem>
-        <listitem>Clemens Fruhwirth</listitem>
-        <listitem>Conal Elliott</listitem>
-        <listitem>David Waern</listitem> 
-        <listitem>Duncan Coutts</listitem>
-        <listitem>George Pollard</listitem>
-        <listitem>George Russel</listitem>
-        <listitem>Hal Daume</listitem>
-        <listitem>Ian Lynagh</listitem>
-        <listitem>Isaac Dupree</listitem>
-        <listitem>Joachim Breitner</listitem>
-        <listitem>Krasimir Angelov</listitem>
-        <listitem>Lennart Augustsson</listitem>
-        <listitem>Luke Plant</listitem>
-        <listitem>Malcolm Wallace</listitem>
-        <listitem>Mark Lentczner</listitem>
-        <listitem>Mark Shields</listitem>
-        <listitem>Neil Mitchell</listitem>
-        <listitem>Mike Thomas</listitem>
-        <listitem>Manuel Chakravarty</listitem>
-        <listitem>Oliver Brown</listitem>
-        <listitem>Roman Cheplyaka</listitem>
-        <listitem>Ross Paterson</listitem>
-        <listitem>Simon Hengel</listitem>
-        <listitem>Simon Marlow</listitem>
-        <listitem>Simon Peyton-Jones</listitem>
-        <listitem>Sigbjorn Finne</listitem>
-        <listitem>Stefan O'Rear</listitem>
-        <listitem>Sven Panne</listitem>
-        <listitem>Thomas Schilling</listitem>
-        <listitem>Wolfgang Jeltsch</listitem>
-        <listitem>Yitzchak Gale</listitem>
-      </itemizedlist>
-    </section>
-    <section>
-      <title>Acknowledgements</title>
-
-      <para>Several documentation systems provided the inspiration for
-      Haddock, most notably:</para>
-
-      <itemizedlist>
-	<listitem>
-	  <para><ulink
-          url="http://www.cse.unsw.edu.au/~chak/haskell/idoc/">
-          IDoc</ulink></para>
-	</listitem>
-	<listitem>
-	  <para><ulink
-	  url="http://www.fmi.uni-passau.de/~groessli/hdoc/">HDoc</ulink></para>
-	</listitem>
-	<listitem>
-	  <para><ulink url="http://www.stack.nl/~dimitri/doxygen/">
-          Doxygen</ulink></para>
-	</listitem>
-      </itemizedlist>
-
-      <para>and probably several others I've forgotten.</para>
-
-      <para>Thanks to the the members
-      of <email>haskelldoc@haskell.org</email>,
-      <email>haddock@projects.haskell.org</email> and everyone who
-      contributed to the many libraries that Haddock makes use
-      of.</para>
-    </section>
-
-  </chapter>
-
-  <chapter id="invoking">
-    <title>Invoking Haddock</title>
-    <para>Haddock is invoked from the command line, like so:</para>
-
-    <cmdsynopsis>
-      <command>haddock</command>
-      <arg rep="repeat"><replaceable>option</replaceable></arg>
-      <arg rep="repeat" choice="plain"><replaceable>file</replaceable></arg>
-    </cmdsynopsis>
-
-    <para>Where each <replaceable>file</replaceable> is a filename
-    containing a Haskell source module (.hs) or a Literate Haskell source
-    module (.lhs) or just a module name.</para>
-
-    <para>All the modules specified on the command line will be
-    processed together.  When one module refers to an entity in
-    another module being processed, the documentation will link
-    directly to that entity.</para>
-
-    <para>Entities that cannot be found, for example because they are
-    in a module that isn't being processed as part of the current
-    batch, simply won't be hyperlinked in the generated
-    documentation.  Haddock will emit warnings listing all the
-    indentifiers it couldn't resolve.</para>
-
-    <para>The modules should <emphasis>not</emphasis> be mutually
-    recursive, as Haddock don't like swimming in circles.</para>
-
-    <para>You must also specify an option for the output format.
-    Currently only the <option>-h</option> option for HTML and the
-    <option>--hoogle</option> option for outputting Hoogle data are
-    functional.</para>
-
-    <para>The packaging
-    tool <ulink url="http://www.haskell.org/ghc/docs/latest/html/Cabal/index.html">Cabal</ulink>
-    has Haddock support, and is often used instead of invoking Haddock
-    directly.</para>
-
-    <para>The following options are available:</para>
-
-    <variablelist>
-
-      <varlistentry>
-	<term>
-          <indexterm><primary><option>-B</option></primary></indexterm>
-          <option>-B</option> <replaceable>dir</replaceable>
-        </term>
-	<listitem>
-	  <para>Tell GHC that that its lib directory is
-    <replaceable>dir</replaceable>. Can be used to override the default path.</para>
-	</listitem>
-      </varlistentry>
-
-      <varlistentry>
-	<term>
-          <indexterm><primary><option>-o</option></primary></indexterm>
-          <option>-o</option> <replaceable>dir</replaceable>
-        </term>
-	<term>
-          <indexterm><primary><option>--odir</option></primary></indexterm>
-          <option>--odir</option>=<replaceable>dir</replaceable>
-        </term>
-	<listitem>
-	  <para>Generate files into <replaceable>dir</replaceable>
-	  instead of the current directory.</para>
-	</listitem>
-      </varlistentry>
-
-      <varlistentry>
-	<term>
-	  <indexterm><primary><option>-l</option></primary></indexterm>
-          <option>-l</option> <replaceable>dir</replaceable>
-        </term>
-	<term>
-	  <indexterm><primary><option>--lib</option></primary></indexterm>
-          <option>--lib</option>=<replaceable>dir</replaceable>
-        </term>
-	<listitem>
-	  <para>Use Haddock auxiliary files (themes, javascript, etc...) in <replaceable>dir</replaceable>.</para>
-	</listitem>
-      </varlistentry>
-
-      <varlistentry>
-	<term>
-	  <indexterm><primary><option>-i</option></primary></indexterm>
-          <option>-i</option> <replaceable>path</replaceable>,<replaceable>file</replaceable>
-        </term>
-	<term>
-	  <indexterm><primary><option>--read-interface</option></primary></indexterm>
-          <option>--read-interface</option>=<replaceable>path</replaceable>,<replaceable>file</replaceable>
-        </term>
-	<listitem>
-	  <para>Read the interface file in
-	  <replaceable>file</replaceable>, which must have been
-	  produced by running Haddock with the
-	  <option>--dump-interface</option> option.  The interface
-	  describes a set of modules whose HTML documentation is
-	  located in <replaceable>path</replaceable> (which may be a
-	  relative pathname).  The <replaceable>path</replaceable> is
-	  optional, and defaults to <quote>.</quote>.</para>
-
-	  <para>This option allows Haddock to produce separate sets of
-	  documentation with hyperlinks between them.  The
-	  <replaceable>path</replaceable> is used to direct hyperlinks
-	  to point to the right files; so make sure you don't move the
-	  HTML files later or these links will break.  Using a
-	  relative <replaceable>path</replaceable> means that a
-	  documentation subtree can still be moved around without
-	  breaking links.</para>
-
-	  <para>Multiple <option>--read-interface</option> options may
-	  be given.</para>
-	</listitem>
-      </varlistentry>
-
-      <varlistentry>
-	<term>
-  	  <indexterm><primary><option>-D</option></primary></indexterm>
-          <option>-D</option> <replaceable>file</replaceable>
-        </term>
-	<term>
-	  <indexterm><primary><option>--dump-interface</option></primary></indexterm>
-          <option>--dump-interface</option>=<replaceable>file</replaceable>
-        </term>
-	<listitem>
-	  <para>Produce an <firstterm>interface
-	  file</firstterm><footnote><para>Haddock interface files are
-	  not the same as Haskell interface files, I just couldn't
-	  think of a better name.</para> </footnote>
-	  in the file <replaceable>file</replaceable>.  An interface
-	  file contains information Haddock needs to produce more
-	  documentation that refers to the modules currently being
-	  processed - see the <option>--read-interface</option> option
-	  for more details.  The interface file is in a binary format;
-	  don't try to read it.</para>
-	</listitem>
-      </varlistentry>
-
-      <varlistentry>
-	<term>
-	  <indexterm><primary><option>-h</option></primary></indexterm>
-          <option>-h</option>
-        </term>
-	<term>
-	  <indexterm><primary><option>--html</option></primary></indexterm>
-          <option>--html</option>
-        </term>
-	<listitem>
-	  <para>Generate documentation in HTML format.  Several files
-	  will be generated into the current directory (or the
-	  specified directory if the <option>-o</option> option is
-	  given), including the following:</para>
-	  <variablelist>
-	    <varlistentry>
-	      <term><filename><replaceable>module</replaceable>.html</filename></term>
-	      <term><filename>mini_<replaceable>module</replaceable>.html</filename></term>
-	      <listitem>
-		<para>An HTML page for each
-		<replaceable>module</replaceable>, and a "mini" page for
-		each used when viewing in frames.</para>
-	      </listitem>
-	    </varlistentry>
-	    <varlistentry>
-	      <term><filename>index.html</filename></term>
-	      <listitem>
-		<para>The top level page of the documentation: lists
-		the modules available, using indentation to represent
-		the hierarchy if the modules are hierarchical.</para>
-	      </listitem>
-	    </varlistentry>
-	    <varlistentry>
-	      <term><filename>doc-index.html</filename></term>
-	      <term><filename>doc-index-<replaceable>X</replaceable>.html</filename></term>
-	      <listitem>
-		<para>The alphabetic index, possibly split into multiple
-		pages if big enough.</para>
-	      </listitem>
-	    </varlistentry>
-	    <varlistentry>
-	      <term><filename>frames.html</filename></term>
-	      <listitem>
-		<para>The top level document when viewing in frames.</para>
-	      </listitem>
-	    </varlistentry>
-	    <varlistentry>
-	      <term><filename><replaceable>some</replaceable>.css</filename></term>
-	      <term><filename><replaceable>etc...</replaceable></filename></term>
-	      <listitem>
-		<para>Files needed for the themes used. Specify your themes
-		using the <option>--theme</option> option.</para>
-	      </listitem>
-	    </varlistentry>
-	    <varlistentry>
-	      <term><filename>haddock-util.js</filename></term>
-	      <listitem>
-		<para>Some JavaScript utilities used to implement some of the
-		dynamic features like collapsable sections, and switching to
-		frames view.</para>
-	      </listitem>
-	    </varlistentry>
-	  </variablelist>
-	</listitem>
-      </varlistentry>
-
-      <varlistentry>
-        <term>
-          <indexterm><primary><option>--latex</option></primary></indexterm>
-          <option>--latex</option>
-        </term>
-        <listitem>
-          <para>Generate documentation in LaTeX format.  Several files
-          will be generated into the current directory (or the
-            specified directory if the <option>-o</option> option is
-            given), including the following:</para>
-          
-	  <variablelist>
-	    <varlistentry>
-	      <term><filename><replaceable>package</replaceable>.tex</filename></term>
-	      <listitem>
-                <para>The top-level LaTeX source file; to format the
-                documentation into PDF you might run something like
-                  this:</para>
-<screen>
-$ pdflatex <replaceable>package</replaceable>.tex</screen>
-              </listitem>
-            </varlistentry>
-            <varlistentry>
-              <term><filename>haddock.sty</filename></term>
-              <listitem>
-                <para>The default style.  The file contains
-                definitions for various macros used in the LaTeX
-                sources generated by Haddock; to change the way the
-                formatted output looks, you might want to override
-                these by specifying your own style with
-                the <option>--latex-style</option> option.</para>
-              </listitem>
-            </varlistentry>
-            <varlistentry>
-              <term><filename><replaceable>module</replaceable>.tex</filename></term>
-              <listitem>
-                <para>The LaTeX documentation for
-                each <replaceable>module</replaceable>.</para>
-              </listitem>
-            </varlistentry>
-          </variablelist>
-        </listitem>
-      </varlistentry>
-
-      <varlistentry>
-        <term>
-          <indexterm><primary><option>--latex-style</option></primary></indexterm>
-          <option>--latex-style=<replaceable>style</replaceable></option>
-        </term>
-        <listitem>
-          <para>This option lets you override the default style used
-            by the LaTeX generated by the <option>--latex</option> option.
-            Normally Haddock puts a
-            standard <filename>haddock.sty</filename> in the output
-            directory, and includes the
-            command <literal>\usepackage{haddock}</literal> in the
-            LaTeX source.  If this option is given,
-            then <filename>haddock.sty</filename> is not generated,
-            and the command is
-            instead <literal>\usepackage{<replaceable>style</replaceable>}</literal>.
-          </para>
-        </listitem>
-      </varlistentry>
-
-      <varlistentry>
-	<term>
-	  <indexterm><primary><option>-S</option></primary></indexterm>
-          <option>-S</option>
-        </term>
-	<term>
-	  <indexterm><primary><option>--docbook</option></primary></indexterm>
-          <option>--docbook</option>
-        </term>
-	<listitem>
-	  <para>Reserved for future use (output documentation in DocBook XML
-	  format).</para>
-	</listitem>
-      </varlistentry>
-
-      <varlistentry>
-	<term>
-	  <indexterm><primary><option>--source-base</option></primary></indexterm>
-          <option>--source-base</option>=<replaceable>URL</replaceable>
-        </term>
-	<term>
-	  <indexterm><primary><option>--source-module</option></primary></indexterm>
-          <option>--source-module</option>=<replaceable>URL</replaceable>
-        </term>
-	<term>
-	  <indexterm><primary><option>--source-entity</option></primary></indexterm>
-          <option>--source-entity</option>=<replaceable>URL</replaceable>
-        </term>
-	<listitem>
-	  <para>Include links to the source files in the generated
-	  documentation. Use the <option>--source-base</option> option to add a
-	  source code link in the header bar of the contents and index pages.
-	  Use the <option>--source-module</option> to add a source code link in
-	  the header bar of each module page. Use the
-	  <option>--source-entity</option> option to add a source code link
-	  next to the documentation for every value and type in each module.
-	  </para>
-	  
-	  <para>In each case <replaceable>URL</replaceable> is the base URL
-	  where the source files can be found.  For the per-module and
-	  per-entity URLs, the following substitutions are made within the
-	  string <replaceable>URL</replaceable>:</para>
-
-	  <itemizedlist>
-	    <listitem>
-	      <para>The string <literal>%M</literal> or <literal>%{MODULE}</literal>
-	      is replaced by the module name. Note that for the per-entity URLs
-	      this is the name of the <emphasis>exporting</emphasis> module.</para>
-	    </listitem>
-	    <listitem>
-	      <para>The string <literal>%F</literal> or <literal>%{FILE}</literal>
-	      is replaced by the original source file name. Note that for the
-	      per-entity URLs this is the name of the <emphasis>defining</emphasis>
-	      module.</para>
-	    </listitem>
-	    <listitem>
-	      <para>The string <literal>%N</literal> or <literal>%{NAME}</literal>
-	      is replaced by the name of the exported value or type. This is
-	      only valid for the <option>--source-entity</option> option.</para>
-	    </listitem>
-	    <listitem>
-	      <para>The string <literal>%K</literal> or <literal>%{KIND}</literal>
-	      is replaced by a flag indicating whether the exported name is a value
-	      '<literal>v</literal>' or a type '<literal>t</literal>'. This is
-	      only valid for the <option>--source-entity</option> option.</para>
-	    </listitem>
-	    <listitem>
-	      <para>The string <literal>%L</literal> or <literal>%{LINE}</literal>
-	      is replaced by the number of the line where the exported value or
-	      type is defined. This is only valid for the
-	      <option>--source-entity</option> option.</para>
-	    </listitem>
-	    <listitem>
-	      <para>The string <literal>%%</literal> is replaced by
-	      <literal>%</literal>.</para>
-      </listitem>
-
-	  </itemizedlist>
-
-	  <para>For example, if your sources are online under some directory,
-	  you would say
-	  <literal>haddock --source-base=<replaceable>url</replaceable>/
-	  --source-module=<replaceable>url</replaceable>/%F</literal></para>
-	  
-	  <para>If you have html versions of your sources online with anchors
-	  for each type and function name, you would say
-	  <literal>haddock --source-base=<replaceable>url</replaceable>/
-	  --source-module=<replaceable>url</replaceable>/%M.html
-	  --source-entity=<replaceable>url</replaceable>/%M.html#%N</literal></para>
-
-	  <para>For the <literal>%{MODULE}</literal> substitution you may want to
-	  replace the '<literal>.</literal>' character in the module names with
-	  some other character (some web servers are known to get confused by
-	  multiple '<literal>.</literal>' characters in a file name). To
-	  replace it with a character <replaceable>c</replaceable> use
-	  <literal>%{MODULE/./<replaceable>c</replaceable>}</literal>.</para>
-
-	  <para>Similarly, for the <literal>%{FILE}</literal> substitution
-          you may want to replace the '<literal>/</literal>' character in
-          the file names with some other character (especially for links
-          to colourised entity source code with a shared css file).  To replace
-          it with a character <replaceable>c</replaceable> use
-          <literal>%{FILE///<replaceable>c</replaceable>}</literal>/</para>
-
-          <para>One example of a tool that can generate syntax-highlighted
-          HTML from your source code, complete with anchors suitable for use
-          from haddock, is
-          <ulink url="http://www.cs.york.ac.uk/fp/darcs/hscolour">hscolour</ulink>.</para>
-
-	</listitem>
-      </varlistentry>
-
-      <varlistentry>
-	<term>
-	  <indexterm><primary><option>-s</option></primary></indexterm>
-          <option>-s</option> <replaceable>URL</replaceable>
-        </term>
-	<term>
-	  <indexterm><primary><option>--source</option></primary></indexterm>
-          <option>--source</option>=<replaceable>URL</replaceable>
-        </term>
-	<listitem>
-	  <para>Deprecated aliases for <option>--source-module</option></para>
-	</listitem>
-      </varlistentry>
-
-      <varlistentry>
-	<term>
-	  <indexterm><primary><option>--comments-base</option></primary></indexterm>
-          <option>--comments-base</option>=<replaceable>URL</replaceable>
-        </term>
-	<term>
-	  <indexterm><primary><option>--comments-module</option></primary></indexterm>
-          <option>--comments-module</option>=<replaceable>URL</replaceable>
-        </term>
-	<term>
-	  <indexterm><primary><option>--comments-entity</option></primary></indexterm>
-          <option>--comments-entity</option>=<replaceable>URL</replaceable>
-        </term>
-	<listitem>
-	  <para>Include links to pages where readers may comment on the
-	  documentation. This feature would typically be used in conjunction
-	  with a Wiki system.</para>
-	  
-	  <para>Use the <option>--comments-base</option> option to add a
-	  user comments link in the header bar of the contents and index pages.
-	  Use the <option>--comments-module</option> to add a user comments
-	  link in the header bar of each module page. Use the
-	  <option>--comments-entity</option> option to add a comments link
-	  next to the documentation for every value and type in each module.
-	  </para>
-	  
-	  <para>In each case <replaceable>URL</replaceable> is the base URL
-	  where the corresponding comments page can be found.  For the
-	  per-module and per-entity URLs the same substitutions are made as
-	  with the <option>--source-module</option> and
-	  <option>--source-entity</option> options above.</para>
-
-	  <para>For example, if you want to link the contents page to a wiki
-	  page, and every module to subpages, you would say
-	  <literal>haddock --comments-base=<replaceable>url</replaceable>
-	  --comments-module=<replaceable>url</replaceable>/%M</literal></para>
-	  
-	  <para>If your Wiki system doesn't like the '<literal>.</literal>' character
-	  in Haskell module names, you can replace it with a different character. For
-	  example to replace the '<literal>.</literal>' characters with
-	  '<literal>_</literal>' use <literal>haddock
-	  --comments-base=<replaceable>url</replaceable>
-	  --comments-module=<replaceable>url</replaceable>/%{MODULE/./_}</literal>
-	  Similarly, you can replace the '<literal>/</literal>' in a file name (may
-	  be useful for entity comments, but probably not.) </para>
-
-	</listitem>
-      </varlistentry>
-
-      <varlistentry>
-	<term>
-	  <indexterm><primary><option>--theme</option></primary></indexterm>
-          <option>--theme</option>=<replaceable>path</replaceable>
-        </term>
-	<listitem>
-	  <para>Specify a theme to be used for HTML (<option>--html</option>)
-	  documentation. If given multiple times then the pages will use the
-	  first theme given by default, and have alternate style sheets for
-	  the others. The reader can switch between themes with browsers that
-	  support alternate style sheets, or with the "Style" menu that gets 
-	  added when the page is loaded. If
-	  no themes are specified, then just the default built-in theme
-	  ("Ocean") is used.
-	  </para>
-	  
-	  <para>The <replaceable>path</replaceable> parameter can be one of:
-	  </para>
-
-	  <itemizedlist>
-	    <listitem>
-	      <para>A <emphasis>directory</emphasis>: The base name of
-	      the directory becomes the name of the theme. The directory
-	      must contain exactly one
-	      <filename><replaceable>some</replaceable>.css</filename> file.
-	      Other files, usually image files, will be copied, along with
-	      the <filename><replaceable>some</replaceable>.css</filename>
-	      file, into the generated output directory.</para>
-	    </listitem>
-	    <listitem>
-	      <para>A <emphasis>CSS file</emphasis>: The base name of
-	      the file becomes the name of the theme.</para>
-	    </listitem>
-	    <listitem>
-	      <para>The <emphasis>name</emphasis> of a built-in theme
-	      ("Ocean" or "Classic").</para>
-	    </listitem>
-	  </itemizedlist>
-	</listitem>
-      </varlistentry>
-
-      <varlistentry>
-	<term>
-	  <indexterm><primary><option>--built-in-themes</option></primary></indexterm>
-          <option>--built-in-themes</option>
-        </term>
-	<listitem>
-	  <para>Includes the built-in themes ("Ocean" and "Classic").
-	  Can be combined with <option>--theme</option>. Note that order
-	  matters: The first specified theme will be the default.</para>
-	</listitem>
-      </varlistentry>
-
-      <varlistentry>
-	<term>
-	  <indexterm><primary><option>-c</option></primary></indexterm>
-          <option>-c</option> <replaceable>file</replaceable>
-        </term>
-	<term>
-	  <indexterm><primary><option>--css</option></primary></indexterm>
-          <option>--css</option>=<replaceable>file</replaceable>
-        </term>
-	<listitem>
-	  <para>Deprecated aliases for <option>--theme</option></para>
-	</listitem>
-      </varlistentry>
-
-      <varlistentry>
-	<term>
-	  <indexterm><primary><option>-p</option></primary></indexterm>
-          <option>-p</option> <replaceable>file</replaceable>
-        </term>
-	<term>
-	  <indexterm><primary><option>--prologue</option></primary></indexterm>
-          <option>--prologue</option>=<replaceable>file</replaceable>
-        </term>
-	<listitem>
-	  <para>Specify a file containing documentation which is
-	  placed on the main contents page under the heading
-	  &ldquo;Description&rdquo;.  The file is parsed as a normal
-	  Haddock doc comment (but the comment markers are not
-	  required).</para>
-	</listitem>
-      </varlistentry>
-
-      <varlistentry>
-        <term>
-          <indexterm><primary><option>-t</option></primary></indexterm>
-          <option>-t</option> <replaceable>title</replaceable>
-        </term>
-        <term>
-          <indexterm><primary><option>--title</option></primary></indexterm>
-          <option>--title</option>=<replaceable>title</replaceable>
-        </term>
-	<listitem>
-	  <para>Use <replaceable>title</replaceable> as the page
-	  heading for each page in the documentation.This will
-	  normally be the name of the library being documented.</para>
-
-	  <para>The title should be a plain string (no markup
-	  please!).</para>
-	</listitem>
-      </varlistentry>
-
-      <varlistentry>
-        <term>
-          <indexterm><primary><option>-q</option></primary></indexterm>
-          <option>-q</option> <replaceable>mode</replaceable>
-        </term>
-        <term>
-          <indexterm><primary><option>--qual</option></primary></indexterm>
-          <option>--qual</option>=<replaceable>mode</replaceable>
-        </term>
-        <listitem>
-            <para>
-                Specify how identifiers are qualified.
-            </para>
-            <para>
-                <replaceable>mode</replaceable> should be one of
-                <itemizedlist>
-                    <listitem>
-                        <para>none (default): don't qualify any identifiers</para>
-                    </listitem>
-                    <listitem>
-                        <para>full: always qualify identifiers completely</para>
-                    </listitem>
-                    <listitem>
-                        <para>local: only qualify identifiers that are not part
-                            of the module</para>
-                    </listitem>
-                    <listitem>
-                        <para>relative: like local, but strip name of the module
-                            from qualifications of identifiers in submodules</para>
-                    </listitem>
-                </itemizedlist>
-            </para>
-            <para>
-                Example: If you generate documentation for module A, then the
-                identifiers A.x, A.B.y and C.z are qualified as follows.
-            </para>
-            <para>
-                <itemizedlist>
-                    <listitem>
-                        none: x, y, z
-                    </listitem>
-                    <listitem>
-                        full: A.x, A.B.y, C.z
-                    </listitem>
-                    <listitem>
-                        local: x, A.B.y, C.z
-                    </listitem>
-                    <listitem>
-                        relative: x, B.y, C.z
-                    </listitem>
-                </itemizedlist>
-	        </para>
-	    </listitem>
-      </varlistentry>
-
-      <varlistentry>
-        <term>
-          <indexterm><primary><option>-?</option></primary></indexterm>
-          <option>-?</option>
-        </term>
-        <term>
-          <indexterm><primary><option>--help</option></primary></indexterm>
-          <option>--help</option>
-        </term>
-	<listitem>
-	  <para>Display help and exit.</para>
-	</listitem>
-      </varlistentry>
-
-      <varlistentry>
-        <term>
-          <indexterm><primary><option>-V</option></primary></indexterm>
-          <option>-V</option>
-        </term>
-        <term>
-          <indexterm><primary><option>--version</option></primary></indexterm>
-          <option>--version</option>
-        </term>
-	<listitem>
-	  <para>Output version information and exit.</para>
-	</listitem>
-      </varlistentry>
-
-      <varlistentry>
-        <term>
-          <indexterm><primary><option>-v</option></primary></indexterm>
-          <option>-v</option>
-        </term>
-        <term>
-          <indexterm><primary><option>--verbose</option></primary></indexterm>
-          <option>--verbose</option>
-        </term>
-	<listitem>
-	  <para>Increase verbosity.  Currently this will cause Haddock
-	  to emit some extra warnings, in particular about modules
-	  which were imported but it had no information about (this is
-	  often quite normal; for example when there is no information
-	  about the <literal>Prelude</literal>).</para>
-	</listitem>
-      </varlistentry>
-
-      <varlistentry>
-        <term>
-          <indexterm><primary><option>--use-contents</option></primary></indexterm>
-          <option>--use-contents=<replaceable>URL</replaceable></option>
-        </term>
-        <term>
-          <indexterm><primary><option>--use-index</option></primary></indexterm>
-          <option>--use-index=<replaceable>URL</replaceable></option>
-        </term>
-	<listitem>
-	  <para>When generating HTML, do not generate an index.
-	  Instead, redirect the Contents and/or Index link on each page to
-	  <replaceable>URL</replaceable>.  This option is intended for
-	  use in conjuction with <option>--gen-contents</option> and/or 
-	  <option>--gen-index</option> for
-	  generating a separate contents and/or index covering multiple
-	  libraries.</para>
-	</listitem>
-      </varlistentry>
-
-      <varlistentry>
-        <term>
-          <indexterm><primary><option>--gen-contents</option></primary></indexterm>
-          <option>--gen-contents</option>
-        </term>
-        <term>
-          <indexterm><primary><option>--gen-index</option></primary></indexterm>
-          <option>--gen-index</option>
-        </term>
-	<listitem>
-	  <para>Generate an HTML contents and/or index containing entries pulled 
-	  from all the specified interfaces (interfaces are specified using
-	  <option>-i</option> or <option>--read-interface</option>).
-	  This is used to generate a single contents and/or index for multiple 
-	  sets of Haddock documentation.</para>
-	</listitem>
-      </varlistentry>
-
-      <varlistentry>
-	<term>
-	  <indexterm><primary><option>--ignore-all-exports</option></primary>
-	  </indexterm>
-	  <option>--ignore-all-exports</option>
-	</term>
-	<listitem>
-	  <para>Causes Haddock to behaves as if every module has the
-	    <literal>ignore-exports</literal> attribute (<xref
-	      linkend="module-attributes" />).  This might be useful for
-	    generating implementation documentation rather than interface
-	    documentation, for example.</para>
-	</listitem>
-      </varlistentry>
-
-      <varlistentry>
-	<term>
-	  <indexterm><primary><option>--hide</option></primary>
-	  </indexterm>
-	  <option>--hide</option>&nbsp;<replaceable>module</replaceable>
-	</term>
-	<listitem>
-	  <para>Causes Haddock to behaves as if module
-	    <replaceable>module</replaceable> has the <literal>hide</literal>
-	    atribute. (<xref linkend="module-attributes" />).</para>
-	</listitem>
-      </varlistentry>
-      
-      <varlistentry>
-	<term>
-          <indexterm><primary><option>--optghc</option></primary></indexterm>
-          <option>--optghc</option>=<replaceable>option</replaceable>
-        </term>
-	<listitem>
-	  <para>Pass <replaceable>option</replaceable> to GHC.</para>
-	</listitem>
-      </varlistentry>
-
-      <varlistentry>
-        <term>
-          <indexterm><primary><option>-w</option></primary></indexterm>
-          <option>-w</option>
-        </term>
-        <term>
-          <indexterm><primary><option>--no-warnings</option></primary></indexterm>
-          <option>--no-warnings</option>
-        </term>
-	<listitem>
-	  <para>Turn off all warnings.</para>
-	</listitem>
-      </varlistentry>
-
-      <varlistentry>
-        <term>
-          <indexterm><primary><option>--no-tmp-comp-dir</option></primary></indexterm>
-          <option>--no-tmp-comp-dir</option>
-        </term>
-	<listitem>
-          <para>
-          Do not use a temporary directory for reading and writing compilation output files
-          (<literal>.o</literal>, <literal>.hi</literal>, and stub files). Instead, use the
-          present directory or another directory that you have explicitly told GHC to use
-          via the <literal>--optghc</literal> flag.
-          </para>
-          <para>
-          This flag can be used to avoid recompilation if compilation files already exist.
-          Compilation files are produced when Haddock has to process modules that make use of
-          Template Haskell, in which case Haddock compiles the modules using the GHC API.  
-          </para>
-	</listitem>
-      </varlistentry>
-    </variablelist>
-
-    <section id="cpp">
-      <title>Using literate or pre-processed source</title>
-
-      <para>Since Haddock uses GHC internally, both plain and 
-            literate Haskell sources are accepted without the need for the user
-            to do anything. To use the C pre-processor, however,
-            the user must pass the the <option>-cpp</option> option to GHC 
-            using <option>--optghc</option>.
-      </para>
-    </section>
-
-  </chapter>
-
-  <chapter id="markup">
-    <title>Documentation and Markup</title>
-
-    <para>Haddock understands special documentation annotations in the
-    Haskell source file and propagates these into the generated
-    documentation.  The annotations are purely optional: if there are
-    no annotations, Haddock will just generate documentation that
-    contains the type signatures, data type declarations, and class
-    declarations exported by each of the modules being
-    processed.</para>
-
-    <section>
-      <title>Documenting a top-level declaration</title>
-
-      <para>The simplest example of a documentation annotation is for
-      documenting any top-level declaration (function type signature,
-      type declaration, or class declaration).  For example, if the
-      source file contains the following type signature:</para>
-
-<programlisting>
-square :: Int -> Int
-square x = x * x
-</programlisting>
-
-    <para>Then we can document it like this:</para>
-
-<programlisting>
--- |The 'square' function squares an integer.
-square :: Int -> Int
-square x = x * x
-</programlisting>
-
-
-      <para>The <quote><literal>-- |</literal></quote> syntax begins a
-      documentation annotation, which applies to the
-      <emphasis>following</emphasis> declaration in the source file.
-      Note that the annotation is just a comment in Haskell &mdash; it
-      will be ignored by the Haskell compiler.</para>
-
-      <para>The declaration following a documentation annotation
-      should be one of the following:</para>
-      <itemizedlist>
-	<listitem>
-	  <para>A type signature for a top-level function,</para>
-	</listitem>
-	<listitem>
-	  <para>A <literal>data</literal> declaration,</para>
-	</listitem>
-	<listitem>
-	  <para>A <literal>newtype</literal> declaration,</para>
-	</listitem>
-	<listitem>
-	  <para>A <literal>type</literal> declaration, or</para>
-	</listitem>
-	<listitem>
-	  <para>A <literal>class</literal> declaration.</para>
-	</listitem>
-      </itemizedlist>
-
-      <para>If the annotation is followed by a different kind of
-      declaration, it will probably be ignored by Haddock.</para>
-
-      <para>Some people like to write their documentation
-      <emphasis>after</emphasis> the declaration; this is possible in
-      Haddock too:</para>
-
-<programlisting>
-square :: Int -> Int
--- ^The 'square' function squares an integer.
-square x = x * x
-</programlisting>
-
-      <para>Note that Haddock doesn't contain a Haskell type system
-      &mdash; if you don't write the type signature for a function,
-      then Haddock can't tell what its type is and it won't be
-      included in the documentation.</para>
-
-      <para>Documentation annotations may span several lines; the
-      annotation continues until the first non-comment line in the
-      source file.  For example:</para>
-
-<programlisting>
--- |The 'square' function squares an integer.
--- It takes one argument, of type 'Int'.
-square :: Int -> Int
-square x = x * x
-</programlisting>
-
-      <para>You can also use Haskell's nested-comment style for
-      documentation annotations, which is sometimes more convenient
-      when using multi-line comments:</para>
-
-<programlisting>
-{-|
-  The 'square' function squares an integer.
-  It takes one argument, of type 'Int'.
--}
-square :: Int -> Int
-square x = x * x
-</programlisting>
-
-    </section>
-    <section>
-      <title>Documenting parts of a declaration</title>
-
-      <para>In addition to documenting the whole declaration, in some
-      cases we can also document individual parts of the
-      declaration.</para>
-
-      <section>
-	<title>Class methods</title>
-
-	<para>Class methods are documented in the same way as top
-	level type signatures, by using either the
-	<quote><literal>--&nbsp;|</literal></quote> or
-	<quote><literal>--&nbsp;^</literal></quote>
-	annotations:</para>
-
-<programlisting>
-class C a where
-   -- | This is the documentation for the 'f' method
-   f :: a -> Int
-   -- | This is the documentation for the 'g' method
-   g :: Int -> a
-</programlisting>
-      </section>
-
-      <section>
-	<title>Constructors and record fields</title>
-
-	<para>Constructors are documented like so:</para>
-
-<programlisting>
-data T a b
-  -- | This is the documentation for the 'C1' constructor
-  = C1 a b
-  -- | This is the documentation for the 'C2' constructor
-  | C2 a b
-</programlisting>
-
-	<para>or like this:</para>
-
-<programlisting>
-data T a b
-  = C1 a b  -- ^ This is the documentation for the 'C1' constructor
-  | C2 a b  -- ^ This is the documentation for the 'C2' constructor
-</programlisting>
-
-	<para>Record fields are documented using one of these
-	styles:</para>
-
-<programlisting>
-data R a b =
-  C { -- | This is the documentation for the 'a' field
-      a :: a,
-      -- | This is the documentation for the 'b' field
-      b :: b
-    }
-
-data R a b =
-  C { a :: a  -- ^ This is the documentation for the 'a' field
-    , b :: b  -- ^ This is the documentation for the 'b' field
-    }
-</programlisting>
-
-        <para>Alternative layout styles are generally accepted by
-        Haddock - for example doc comments can appear before or after
-        the comma in separated lists such as the list of record fields
-        above.</para>
-      </section>
-
-      <section>
-	<title>Function arguments</title>
-
-	<para>Individual arguments to a function may be documented
-	like this:</para>
-
-<programlisting>
-f  :: Int      -- ^ The 'Int' argument
-   -> Float    -- ^ The 'Float' argument
-   -> IO ()    -- ^ The return value
-</programlisting>
-      </section>
-    </section>
-
-    <section>
-      <title>The module description</title>
-
-      <para>A module may contain a documentation comment before the
-      module header, in which case this comment is interpreted by
-      Haddock as an overall description of the module itself, and
-      placed in a section entitled <quote>Description</quote> in the
-      documentation for the module.  For example:</para>
-
-<programlisting>
--- | This is the description for module "Foo"
-module Foo where
-...
-</programlisting>
-    </section>
-
-    <section>
-      <title>Controlling the documentation structure</title>
-
-      <para>Haddock produces interface documentation that lists only
-      the entities actually exported by the module.  The documentation
-      for a module will include <emphasis>all</emphasis> entities
-      exported by that module, even if they were re-exported by
-      another module.  The only exception is when Haddock can't see
-      the declaration for the re-exported entity, perhaps because it
-      isn't part of the batch of modules currently being
-      processed.</para>
-
-      <para>However, to Haddock the export list has even more
-      significance than just specifying the entities to be included in
-      the documentation.  It also specifies the
-      <emphasis>order</emphasis> that entities will be listed in the
-      generated documentation.  This leaves the programmer free to
-      implement functions in any order he/she pleases, and indeed in
-      any <emphasis>module</emphasis> he/she pleases, but still
-      specify the order that the functions should be documented in the
-      export list.  Indeed, many programmers already do this: the
-      export list is often used as a kind of ad-hoc interface
-      documentation, with headings, groups of functions, type
-      signatures and declarations in comments.</para>
-
-      <para>You can insert headings and sub-headings in the
-      documentation by including annotations at the appropriate point
-      in the export list.  For example:</para>
-
-<programlisting>
-module Foo (
-  -- * Classes
-  C(..),
-  -- * Types
-  -- ** A data type
-  T,
-  -- ** A record
-  R,
-  -- * Some functions
-  f, g
-  ) where
-</programlisting>
-
-      <para>Headings are introduced with the syntax
-      <quote><literal>--&nbsp;*</literal></quote>,
-      <quote><literal>--&nbsp;**</literal></quote> and so on, where
-      the number of <literal>*</literal>s indicates the level of the
-      heading (section, sub-section, sub-sub-section, etc.).</para>
-
-      <para>If you use section headings, then Haddock will generate a
-      table of contents at the top of the module documentation for
-      you.</para>
-
-      <para>The alternative style of placing the commas at the
-      beginning of each line is also supported. eg.:</para>
-
-<programlisting>
-module Foo (
-  -- * Classes
-  , C(..)
-  -- * Types
-  -- ** A data type
-  , T
-  -- ** A record
-  , R
-  -- * Some functions
-  , f
-  , g
-  ) where
-</programlisting>
-
-      <section>
-	<title>Re-exporting an entire module</title>
-
-	<para>Haskell allows you to re-export the entire contents of a
-	module (or at least, everything currently in scope that was
-	imported from a given module) by listing it in the export
-	list:</para>
-
-<programlisting>
-module A (
-  module B,
-  module C
- ) where
-</programlisting>
-
-	<para>What will the Haddock-generated documentation for this
-	module look like?  Well, it depends on how the modules
-	<literal>B</literal> and <literal>C</literal> are imported.
-	If they are imported wholly and without any
-	<literal>hiding</literal> qualifiers, then the documentation
-	will just contain a cross-reference to the documentation for
-	<literal>B</literal> and <literal>C</literal>.  However, if
-	the modules are not <emphasis>completely</emphasis>
-	re-exported, for example:</para>
-
-<programlisting>
-module A (
-  module B,
-  module C
- ) where
-
-import B hiding (f)
-import C (a, b)
-</programlisting>
-
-	<para>then Haddock behaves as if the set of entities
-	re-exported from <literal>B</literal> and <literal>C</literal>
-	had been listed explicitly in the export
-	list<footnote><para>NOTE: this is not fully implemented at the
-	time of writing (version 0.2).  At the moment, Haddock always
-	inserts a cross-reference.</para>
-	  </footnote>.</para>
-
-	<para>The exception to this rule is when the re-exported
-	module is declared with the <literal>hide</literal> attribute
-	(<xref linkend="module-attributes"/>), in which case the module
-	is never cross-referenced; the contents are always expanded in
-	place in the re-exporting module.</para>
-      </section>
-
-      <section>
-	<title>Omitting the export list</title>
-
-	<para>If there is no export list in the module, how does
-	Haddock generate documentation?  Well, when the export list is
-	omitted, e.g.:</para>
-
-<programlisting>module Foo where</programlisting>
-
-	<para>this is equivalent to an export list which mentions
-	every entity defined at the top level in this module, and
-	Haddock treats it in the same way.  Furthermore, the generated
-	documentation will retain the order in which entities are
-	defined in the module.  In this special case the module body
-	may also include section headings (normally they would be
-	ignored by Haddock).</para>
-      </section>
-    </section>
-
-    <section>
-      <title>Named chunks of documentation</title>
-
-      <para>Occasionally it is desirable to include a chunk of
-      documentation which is not attached to any particular Haskell
-      declaration.  There are two ways to do this:</para>
-
-      <itemizedlist>
-	<listitem>
-	  <para>The documentation can be included in the export list
-	  directly, e.g.:</para>
-
-<programlisting>
-module Foo (
-   -- * A section heading
-
-   -- | Some documentation not attached to a particular Haskell entity
-   ...
- ) where
-</programlisting>
-	</listitem>
-
-	<listitem>
-	  <para>If the documentation is large and placing it inline in
-	  the export list might bloat the export list and obscure the
-	  structure, then it can be given a name and placed out of
-	  line in the body of the module.  This is achieved with a
-	  special form of documentation annotation
-	  <quote><literal>--&nbsp;$</literal></quote>:</para>
-
-<programlisting>
-module Foo (
-   -- * A section heading
-
-   -- $doc
-   ...
- ) where
-
--- $doc
--- Here is a large chunk of documentation which may be referred to by
--- the name $doc.
-</programlisting>
-
-	  <para>The documentation chunk is given a name, which is the
-	  sequence of alphanumeric characters directly after the
-	  <quote><literal>--&nbsp;$</literal></quote>, and it may be
-	  referred to by the same name in the export list.</para>
-	</listitem>
-      </itemizedlist>
-    </section>
-
-    <section id="hyperlinking">
-      <title>Hyperlinking and re-exported entities</title>
-
-      <para>When Haddock renders a type in the generated
-      documentation, it hyperlinks all the type constructors and class
-      names in that type to their respective definitions.  But for a
-      given type constructor or class there may be several modules
-      re-exporting it, and therefore several modules whose
-      documentation contains the definition of that type or class
-      (possibly including the current module!) so which one do we link
-      to?</para>
-
-      <para>Let's look at an example.  Suppose we have three modules
-      <literal>A</literal>, <literal>B</literal> and
-      <literal>C</literal> defined as follows:</para>
-
-<programlisting>
-module A (T) where
-data T a = C a
-
-module B (f) where
-import A
-f :: T Int -> Int
-f (C i) = i
-
-module C (T, f) where
-import A
-import B
-</programlisting>
-
-      <para>Module <literal>A</literal> exports a datatype
-      <literal>T</literal>.  Module <literal>B</literal> imports
-      <literal>A</literal> and exports a function <literal>f</literal>
-      whose type refers to <literal>T</literal>.  Also, both
-	<literal>T</literal> and <literal>f</literal> are re-exported from
-	module C.</para>
-
-      <para>Haddock takes the view that each entity has a
-	<emphasis>home</emphasis> module; that is, the module that the library
-	designer would most like to direct the user to, to find the
-	documentation for that entity.  So, Haddock makes all links to an entity
-	point to the home module.  The one exception is when the entity is also
-      exported by the current module: Haddock makes a local link if it
-	can.</para>
-
-      <para>How is the home module for an entity determined?
-	Haddock uses the following rules:</para>
-
-      <itemizedlist>
-	<listitem>
-	  <para>If modules A and B both export the entity, and module A imports
-	    (directly or indirectly) module B, then B is preferred.</para>
-	</listitem>
-	<listitem>
-	  <para>A module with the <literal>hide</literal> attribute is never
-	    chosen as the home.</para>
-	</listitem>
-	<listitem>
-	  <para>A module with the <literal>not-home</literal> atribute is only
-	    chosen if there are no other modules to choose.</para>
-	</listitem>
-      </itemizedlist>
-
-      <para>If multiple modules fit the criteria, then one is chosen at
-	random.  If no modules fit the criteria (because the candidates are all
-      hidden), then Haddock will issue a warning for each reference to an
-	entity without a home.</para>
-
-      <para>In the example above, module <literal>A</literal> is chosen as the
-	home for <literal>T</literal> because it does not import any other
-	module that exports <literal>T</literal>.  The link from
-	<literal>f</literal>'s
-	type in module <literal>B</literal> will therefore point to
-	<literal>A.T</literal>.  However, <literal>C</literal> also exports
-	<literal>T</literal> and <literal>f</literal>, and the link from
-	<literal>f</literal>'s type in <literal>C</literal> will therefore
-	point locally to <literal>C.T</literal>.</para>
-    </section>
-
-    <section id="module-attributes">
-      <title>Module Attributes</title>
-
-      <para>Certain attributes may be specified for each module which
-      affects the way that Haddock generates documentation for that
-      module.  Attributes are specified in a comma-separated list in an
-      <literal>{-# OPTIONS_HADDOCK ... #-}</literal> pragma at the
-      top of the module, either before or after the module
-      description.  For example:</para>
-
-<programlisting>
-{-# OPTIONS_HADDOCK hide, prune, ignore-exports #-}
-
--- |Module description
-module A where
-...
-</programlisting>
-
-      <para>The options and module description can be in either order.</para>
-
-      <para>The following attributes are currently understood by
-      Haddock:</para>
-
-      <variablelist>
-	<varlistentry>
-          <term>
-            <indexterm><primary><literal>hide</literal></primary></indexterm>
-            <literal>hide</literal>
-          </term>
-	  <listitem>
-	    <para>Omit this module from the generated documentation,
-	    but nevertheless propagate definitions and documentation
-	    from within this module to modules that re-export those
-	    definitions.</para>
-	  </listitem>
-	</varlistentry>
-
-	<varlistentry>
-          <term>
-            <indexterm><primary><literal>hide</literal></primary></indexterm>
-            <literal>prune</literal>
-          </term>
-	  <listitem>
-	    <para>Omit definitions that have no documentation
-	    annotations from the generated documentation.</para>
-	  </listitem>
-	</varlistentry>
-
-	<varlistentry>
-          <term>
-            <indexterm><primary><literal>ignore-exports</literal></primary></indexterm>
-            <literal>ignore-exports</literal>
-          </term>
-	  <listitem>
-	    <para>Ignore the export list.  Generate documentation as
-	    if the module had no export list - i.e. all the top-level
-	    declarations are exported, and section headings may be
-	    given in the body of the module.</para>
-	  </listitem>
-	</varlistentry>
-
-	<varlistentry>
-	  <term>
-	    <indexterm><primary><literal>not-home</literal></primary></indexterm>
-      <literal>not-home</literal>
-	  </term>
-	  <listitem>
-	    <para>Indicates that the current module should not be considered to
-	      be the home module for each entity it exports,
-	      unless that entity is not exported from any other module.  See
-	      <xref linkend="hyperlinking" /> for more details.</para>
-	  </listitem>
-	</varlistentry>
-      </variablelist>
-
-    </section>
-
-    <section>
-      <title>Markup</title>
-
-      <para>Haddock understands certain textual cues inside
-      documentation annotations that tell it how to render the
-      documentation.  The cues (or <quote>markup</quote>) have been
-      designed to be simple and mnemonic in ASCII so that the
-      programmer doesn't have to deal with heavyweight annotations
-      when editing documentation comments.</para>
-
-      <section>
-	<title>Paragraphs</title>
-
-	<para>One or more blank lines separates two paragraphs in a
-	documentation comment.</para>
-      </section>
-
-      <section>
-	<title>Special characters</title>
-
-	<para>The following characters have special meanings in
-	documentation comments: <literal>\</literal>, <literal>/</literal>,
-	<literal>'</literal>, <literal>`</literal>,
-	<literal>"</literal>, <literal>@</literal>,
-	<literal>&lt;</literal>.  To insert a literal occurrence of
-	one of these special characters, precede it with a backslash
-	(<literal>\</literal>).</para>
-
-        <para>Additionally, the character <literal>&gt;</literal> has
-        a special meaning at the beginning of a line, and the
-        following characters have special meanings at the beginning of
-        a paragraph:
-        <literal>*</literal>, <literal>-</literal>.  These characters
-        can also be escaped using <literal>\</literal>.</para>
-
-        <para>Furthermore, the character sequence <literal>&gt;&gt;&gt;</literal>
-        has a special meaning at the beginning of a line. To
-        escape it, just prefix the characters in the sequence with a
-        backslash.</para>
-      </section>
-
-      <section>
-	<title>Character references</title>
-
-	<para>Although Haskell source files may contain any character
-	from the Unicode character set, the encoding of these characters
-	as bytes varies between systems, so that only source files
-	restricted to the ASCII character set are portable.  Other
-	characters may be specified in character and string literals
-	using Haskell character escapes.  To represent such characters
-	in documentation comments, Haddock supports SGML-style numeric
-	character references of the forms
-	<literal>&amp;#</literal><replaceable>D</replaceable><literal>;</literal>
-	and
-	<literal>&amp;#x</literal><replaceable>H</replaceable><literal>;</literal>
-	where <replaceable>D</replaceable> and <replaceable>H</replaceable>
-	are decimal and hexadecimal numbers denoting a code position
-	in Unicode (or ISO 10646).  For example, the references
-	<literal>&amp;#x3BB;</literal>, <literal>&amp;#x3bb;</literal>
-	and <literal>&amp;#955;</literal> all represent the lower-case
-	letter lambda.</para>
-      </section>
-
-      <section>
-	<title>Code Blocks</title>
-
-	<para>Displayed blocks of code are indicated by surrounding a
-	paragraph with <literal>@...@</literal> or by preceding each
-	line of a paragraph with <literal>&gt;</literal> (we often
-	call these &ldquo;bird tracks&rdquo;).  For
-	example:</para>
-
-<programlisting>
--- | This documentation includes two blocks of code:
---
--- @
---     f x = x + x
--- @
---
--- &gt;  g x = x * 42
-</programlisting>
-
-	<para>There is an important difference between the two forms
-        of code block: in the bird-track form, the text to the right
-        of the &lsquo;<literal>></literal>&rsquo; is interpreted
-        literally, whereas the <literal>@...@</literal> form
-        interprets markup as normal inside the code block.</para>
-      </section>
-
-      <section>
-	<title>Examples</title>
-
-	<para> Haddock has markup support for examples of interaction with a
-  <emphasis>read-eval-print loop (REPL)</emphasis>.  An
-	example is introduced with
-	<literal>&gt;&gt;&gt;</literal> followed by an expression followed
-	by zero or more result lines:</para>
-
-<programlisting>
--- | Two examples are given bellow:
---
--- &gt;&gt;&gt; fib 10
--- 55
---
--- &gt;&gt;&gt; putStrLn "foo\nbar"
--- foo
--- bar
-</programlisting>
-	<para>Result lines that only contain the string
-	<literal>&lt;BLANKLINE&gt;</literal> are rendered as blank lines in the
-	generated documenation.</para>
-      </section>
-
-
-      <section>
-	<title>Hyperlinked Identifiers</title>
-
-	<para>Referring to a Haskell identifier, whether it be a type,
-	class, constructor, or function, is done by surrounding it
-	with single quotes:</para>
-
-<programlisting>
--- | This module defines the type 'T'.
-</programlisting>
-
-	<para>If there is an entity <literal>T</literal> in scope in
-	the current module, then the documentation will hyperlink the
-	reference in the text to the definition of
-	<literal>T</literal> (if the output format supports
-	hyperlinking, of course; in a printed format it might instead
-	insert a page reference to the definition).</para>
-
-	<para>It is also possible to refer to entities that are not in
-	scope in the current module, by giving the full qualified name
-	of the entity:</para>
-
-<programlisting>
--- | The identifier 'M.T' is not in scope
-</programlisting>
-
-	<para>If <literal>M.T</literal> is not otherwise in scope,
-	then Haddock will simply emit a link pointing to the entity
-	<literal>T</literal> exported from module <literal>M</literal>
-	(without checking to see whether either <literal>M</literal>
-	or <literal>M.T</literal> exist).</para>
-
-	<para>To make life easier for documentation writers, a quoted
-	identifier is only interpreted as such if the quotes surround
-	a lexically valid Haskell identifier.  This means, for
-	example, that it normally isn't necessary to escape the single
-	quote when used as an apostrophe:</para>
-
-<programlisting>
--- | I don't have to escape my apostrophes; great, isn't it?
-</programlisting>
-
-	<para>For compatibility with other systems, the following
-	alternative form of markup is accepted<footnote><para>
-	We chose not to use this as the primary markup for
-	identifiers because strictly speaking the <literal>`</literal>
-	character should not be used as a left quote, it is a grave accent.</para>
-	  </footnote>: <literal>`T'</literal>.</para>
-      </section>
-
-      <section>
-	<title>Emphasis and Monospaced text</title>
-
-	<para>Emphasis may be added by surrounding text with
-	<literal>/.../</literal>.</para>
-
-	<para>Monospaced (or typewriter) text is indicated by
-	surrounding it with <literal>@...@</literal>.  Other markup is
-	valid inside a monospaced span: for example
-	<literal>@'f'&nbsp;a&nbsp;b@</literal> will hyperlink the
-	identifier <literal>f</literal> inside the code fragment.</para>
-      </section>
-
-      <section>
-	<title>Linking to modules</title>
-
-	<para>Linking to a module is done by surrounding the module
-	name with double quotes:</para>
-
-<programlisting>
--- | This is a reference to the "Foo" module.
-</programlisting>
-
-      </section>
-
-      <section>
-	<title>Itemized and Enumerated lists</title>
-
-	<para>A bulleted item is represented by preceding a paragraph
-	with either <quote><literal>*</literal></quote> or
-	<quote><literal>-</literal></quote>.  A sequence of bulleted
-	paragraphs is rendered as an itemized list in the generated
-	documentation, eg.:</para>
-
-<programlisting>
--- | This is a bulleted list:
---
---     * first item
---
---     * second item
-</programlisting>
-
-	<para>An enumerated list is similar, except each paragraph
-	must be preceded by either
-	<quote><literal>(<replaceable>n</replaceable>)</literal></quote>
-	or
-	<quote><literal><replaceable>n</replaceable>.</literal></quote>
-	where <replaceable>n</replaceable> is any integer.  e.g.</para>
-
-<programlisting>
--- | This is an enumerated list:
---
---     (1) first item
---
---     2. second item
-</programlisting>
-      </section>
-
-      <section>
-	<title>Definition lists</title>
-
-	<para>Definition lists are written as follows:</para>
-
-<programlisting>
--- | This is a definition list:
---
---   [@foo@] The description of @foo@.
---
---   [@bar@] The description of @bar@.
-</programlisting>
-
-	<para>To produce output something like this:</para>
-
-	<variablelist>
-	  <varlistentry>
-	    <term><literal>foo</literal></term>
-	    <listitem>
-	      <para>The description of <literal>foo</literal>.</para>
-	    </listitem>
-	  </varlistentry>
-	  <varlistentry>
-	    <term><literal>bar</literal></term>
-	    <listitem>
-	      <para>The description of <literal>bar</literal>.</para>
-	    </listitem>
-	  </varlistentry>
-	</variablelist>
-
-	<para>Each paragraph should be preceded by the
-	&ldquo;definition term&rdquo; enclosed in square brackets.
-	The square bracket characters have no special meaning outside
-	the beginning of a definition paragraph.  That is, if a
-	paragraph begins with a <literal>[</literal> character, then
-	it is assumed to be a definition paragraph, and the next
-	<literal>]</literal> character found will close the definition
-	term.  Other markup operators may be used freely within the
-	definition term.</para>
-      </section>
-
-      <section>
-	<title>URLs</title>
-
-	<para>A URL can be included in a documentation comment by
-	surrounding it in angle brackets:
-	<literal>&lt;...&gt;</literal>.  If the output format supports
-	it, the URL will be turned into a hyperlink when
-	rendered.</para>
-      </section>
-
-      <section>
-	<title>Anchors</title>
-
-	<para>Sometimes it is useful to be able to link to a point in
-	the documentation which doesn't correspond to a particular
-	entity.  For that purpose, we allow <emphasis>anchors</emphasis> to be
-	included in a documentation comment.  The syntax is
-	<literal>#<replaceable>label</replaceable>#</literal>, where
-	<replaceable>label</replaceable> is the name of the anchor.
-	An anchor is invisible in the generated documentation.</para>
-
-	<para>To link to an anchor from elsewhere, use the syntax
-	<literal>"<replaceable>module</replaceable>#<replaceable>label</replaceable>"</literal>
-	where <replaceable>module</replaceable> is the module name
-	containing the anchor, and <replaceable>label</replaceable> is
-	the anchor label.  The module does not have to be local, it
-	can be imported via an interface.</para>
-      </section>
-    </section>
-  </chapter>
-  <index/>
-</book>
diff --git a/doc/index.rst b/doc/index.rst
new file mode 100644
--- /dev/null
+++ b/doc/index.rst
@@ -0,0 +1,23 @@
+Welcome to Haddock's documentation!
+===================================
+
+This is Haddock, a tool for automatically generating documentation from
+annotated Haskell source code.
+
+Contents:
+
+.. toctree::
+   :maxdepth: 2
+
+   intro
+   invoking
+   markup
+   common-errors
+   multi-components
+
+
+Indices and tables
+==================
+
+* :ref:`genindex`
+* :ref:`search`
diff --git a/doc/intro.rst b/doc/intro.rst
new file mode 100644
--- /dev/null
+++ b/doc/intro.rst
@@ -0,0 +1,124 @@
+Introduction
+============
+
+This is Haddock, a tool for automatically generating documentation from
+annotated Haskell source code. Haddock was designed with several goals
+in mind:
+
+-  When documenting APIs, it is desirable to keep the documentation
+   close to the actual interface or implementation of the API,
+   preferably in the same file, to reduce the risk that the two become
+   out of sync. Haddock therefore lets you write the documentation for
+   an entity (function, type, or class) next to the definition of the
+   entity in the source code.
+
+-  There is a tremendous amount of useful API documentation that can be
+   extracted from just the bare source code, including types of exported
+   functions, definitions of data types and classes, and so on. Haddock
+   can therefore generate documentation from a set of straight Haskell
+   98 modules, and the documentation will contain precisely the
+   interface that is available to a programmer using those modules.
+
+-  Documentation annotations in the source code should be easy on the
+   eye when editing the source code itself, so as not to obscure the
+   code and to make reading and writing documentation annotations easy.
+   The easier it is to write documentation, the more likely the
+   programmer is to do it. Haddock therefore uses lightweight markup in
+   its annotations, taking several ideas from
+   `IDoc <https://web.archive.org/web/20180621053227/http://www.cse.unsw.edu.au/~chak/haskell/idoc/>`__. In fact,
+   Haddock can understand IDoc-annotated source code.
+
+-  The documentation should not expose any of the structure of the
+   implementation, or to put it another way, the implementer of the API
+   should be free to structure the implementation however he or she
+   wishes, without exposing any of that structure to the consumer. In
+   practical terms, this means that while an API may internally consist
+   of several Haskell modules, we often only want to expose a single
+   module to the user of the interface, where this single module just
+   re-exports the relevant parts of the implementation modules.
+
+   Haddock therefore understands the Haskell module system and can
+   generate documentation which hides not only non-exported entities
+   from the interface, but also the internal module structure of the
+   interface. A documentation annotation can still be placed next to the
+   implementation, and it will be propagated to the external module in
+   the generated documentation.
+
+-  Being able to move around the documentation by following hyperlinks
+   is essential. Documentation generated by Haddock is therefore
+   littered with hyperlinks: every type and class name is a link to the
+   corresponding definition, and user-written documentation annotations
+   can contain identifiers which are linked automatically when the
+   documentation is generated.
+
+-  We might want documentation in multiple formats - online and printed,
+   for example. Haddock comes with HTML, LaTeX, and Hoogle backends, and
+   it is structured in such a way that adding new backends is
+   straightforward.
+
+Obtaining Haddock
+-----------------
+
+Haddock is distributed with GHC distributions, and will automatically be provided if you use 
+`ghcup <https://www.haskell.org/ghcup>`__, for instance.
+
+Up-to-date sources can also be obtained from our public GitHub
+repository. The Haddock sources are at
+``https://github.com/haskell/haddock``.
+
+License
+-------
+
+The following license covers this documentation, and the Haddock source
+code, except where otherwise indicated.
+
+    Copyright (c) 2002-2010, Simon Marlow
+    All rights reserved.
+
+    Redistribution and use in source and binary forms, with or without
+    modification, are permitted provided that the following conditions are
+    met:
+
+    1. Redistributions of source code must retain the above copyright
+       notice, this list of conditions and the following disclaimer.
+
+    2. Redistributions in binary form must reproduce the above copyright
+       notice, this list of conditions and the following disclaimer in the
+       documentation and/or other materials provided with the
+       distribution.
+
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+    A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+    OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+    SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+    LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+Contributors
+------------
+
+A list of contributors to the project can be seen at
+``https://github.com/haskell/haddock/graphs/contributors``.
+
+Acknowledgements
+----------------
+
+Several documentation systems provided the inspiration for Haddock, most
+notably:
+
+-  `IDoc <https://web.archive.org/web/20180621053227/http://www.cse.unsw.edu.au/~chak/haskell/idoc/>`__
+
+-  `HDoc <https://mail.haskell.org/pipermail/haskelldoc/2001-April/000067.html>`__
+
+-  `Doxygen <https://www.doxygen.nl/index.html>`__
+
+and probably several others I've forgotten.
+
+Thanks to the the members of haskelldoc@haskell.org,
+haddock@projects.haskell.org and everyone who contributed to the many
+libraries that Haddock makes use of.
diff --git a/doc/invoking.rst b/doc/invoking.rst
new file mode 100644
--- /dev/null
+++ b/doc/invoking.rst
@@ -0,0 +1,563 @@
+Invoking Haddock
+================
+
+Haddock is invoked from the command line, like so:
+
+.. code-block:: none
+
+    haddock [option ...] file ...
+
+Where each ``file`` is a filename containing a Haskell source module (.hs)
+or a Literate Haskell source module (.lhs) or just a module name.
+
+All the modules specified on the command line will be processed
+together. When one module refers to an entity in another module being
+processed, the documentation will link directly to that entity.
+
+Entities that cannot be found, for example because they are in a module
+that isn't being processed as part of the current batch, simply won't be
+hyperlinked in the generated documentation. Haddock will emit warnings
+listing all the identifiers it couldn't resolve.
+
+The modules should *not* be mutually recursive, as Haddock don't like
+swimming in circles.
+
+Note that while older version would fail on invalid markup, this is
+considered a bug in the new versions. If you ever get failed parsing
+message, please report it.
+
+You must also specify an option for the output format. Currently only
+the :option:`--html` option for HTML, the :option:`--hoogle` option for
+outputting Hoogle data, and the :option:`--latex` option are functional.
+
+The packaging tool
+`Cabal <http://www.haskell.org/ghc/docs/latest/html/Cabal/index.html>`__
+has Haddock support, and is often used instead of invoking Haddock
+directly.
+
+The following options are available:
+
+.. option:: -B <dir>
+
+    Tell GHC that its lib directory is dir. Can be used to override
+    the default path.
+
+.. option:: -o <dir>
+            --odir=<dir>
+
+    Generate files into dir instead of the current directory.
+
+.. option:: -l <dir>
+            --lib=<dir>
+
+    Use Haddock auxiliary files (themes, javascript, etc...) in dir.
+
+.. option:: -i <file>
+            --read-interface=<file>
+            -i <docpath>,<file>
+            --read-interface=<docpath>,<file>
+            -i <docpath>,<srcpath>,<file>
+            --read-interface=<docpath>,<srcpath>,<file>
+            -i <docpath>,<srcpath>,<visibility>,<file>
+
+    Read the interface file in file, which must have been produced by
+    running Haddock with the :option:`--dump-interface` option. The interface
+    describes a set of modules whose HTML documentation is located in
+    docpath (which may be a relative pathname). The docpath is optional,
+    and defaults to “.”. The srcpath is optional but has no default
+    value.
+
+    This option allows Haddock to produce separate sets of documentation
+    with hyperlinks between them. The docpath is used to direct
+    hyperlinks to point to the right files; so make sure you don't move
+    the HTML files later or these links will break. Using a relative
+    docpath means that a documentation subtree can still be moved around
+    without breaking links.
+
+    Similarly to docpath, srcpath is used generate cross-package
+    hyperlinks but within sources rendered with :option:`--hyperlinked-source`
+    option.
+
+    If visibility is set to `hidden`, modules from that interface file will
+    not be listed in haddock generated content file.
+
+    Multiple :option:`--read-interface` options may be given.
+
+.. option:: -D <file>
+            --dump-interface=<file>
+
+    Produce an interface file [1]_ in the file file. An interface file
+    contains information Haddock needs to produce more documentation
+    that refers to the modules currently being processed - see the
+    :option:`--read-interface` option for more details. The interface file is
+    in a binary format; don't try to read it.
+
+.. option:: --show-interface=<file>
+
+    Dumps a binary interface file to stdout in a human readable fashion.
+    Uses json as output format.
+
+.. [1]
+   Haddock interface files are not the same as Haskell interface files,
+   I just couldn't think of a better name.
+
+.. option:: --html, -h
+
+    Generate documentation in HTML format. Several files will be
+    generated into the current directory (or the specified directory if
+    the :option:`-o` option is given), including the following:
+
+    ``module.html``; ``mini_module.html``
+        An HTML page for each module, and a "mini" page for each used
+        when viewing their synopsis.
+
+    ``index.html``
+        The top level page of the documentation: lists the modules
+        available, using indentation to represent the hierarchy if the
+        modules are hierarchical.
+
+    ``doc-index.html``; ``doc-index-X.html``
+        The alphabetic index, possibly split into multiple pages if big
+        enough.
+
+    ``some.css``; ``etc...``
+        Files needed for the themes used. Specify your themes using the
+        :option:`--theme` option.
+
+    ``haddock-util.js``
+        Some JavaScript utilities used to implement some of the dynamic
+        features like collapsible sections.
+
+.. option:: --mathjax
+
+    Specify a custom URL for a mathjax-compatible JS script. By default,
+    this is set to `MathJax
+    <https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML>`_.
+
+.. option:: --latex
+
+    Generate documentation in LaTeX format. Several files will be
+    generated into the current directory (or the specified directory if
+    the :option:`-o` option is given), including the following:
+
+    ``package.tex``
+        The top-level LaTeX source file; to format the documentation
+        into PDF you might run something like this: ::
+
+            $ pdflatex package.tex
+
+    ``haddock.sty``
+        The default style. The file contains definitions for various
+        macros used in the LaTeX sources generated by Haddock; to change
+        the way the formatted output looks, you might want to override
+        these by specifying your own style with the :option:`--latex-style`
+        option.
+
+    ``module.tex``
+        The LaTeX documentation for each module.
+
+.. option:: --latex-style=<style>
+
+    This option lets you override the default style used by the LaTeX
+    generated by the :option:`--latex` option. Normally Haddock puts a
+    standard ``haddock.sty`` in the output directory, and includes the
+    command ``\usepackage{haddock}`` in the LaTeX source. If this option
+    is given, then ``haddock.sty`` is not generated, and the command is
+    instead ``\usepackage{style}``.
+
+.. option:: --hoogle
+
+    Generate an index file for the
+    `Hoogle <http://hackage.haskell.org/package/hoogle>`_ search engine.
+    One text file will be generated into the current directory (or the
+    specified directory if the :option:`-o` is given). Note that
+    the :option:`--package-name` is required.
+
+    Since the output is intended to be parsed by Hoogle, some conventions
+    need to be upheld:
+
+      * Every entity should span exactly one line. ::
+
+            newtype ReaderT r (m :: * -> *) a :: * -> (* -> *) -> * -> *
+          
+        The one exception to this rule is classes. The body of a class
+        is split up with one class member per line, an opening brace on
+        the line of the header, and a closing brace on a new line after
+        the class. ::
+
+            class Foo a where {
+                foo :: a -> a -> Baz a;
+                type family Baz a;
+                type Baz a = [(a, a)];
+            }
+      
+      * Entites that are exported only indirectly (for instance data
+        constructors visible via a ``ReaderT(..)`` export) have their names
+        wrapped in square brackets. ::
+
+            [ReaderT] :: (r -> m a) -> ReaderT r m a
+            [runReaderT] :: ReaderT r m a -> r -> m a
+
+
+.. option:: --hyperlinked-source
+
+    Generate hyperlinked source code (as HTML web page). All rendered
+    files will be put into ``src/`` subfolder of output directory.
+
+    Usually, this should be used in combination with :option:`--html` option -
+    generated documentation will then contain references to appropriate
+    code fragments. Previously, this behaviour could be achieved by
+    generating sources using external tool and specifying
+    :option:`--source-base`, :option:`--source-module`, :option:`--source-entity` and
+    related options. Note that these flags are ignored once
+    :option:`--hyperlinked-source` is set.
+
+    In order to make cross-package source hyperlinking possible,
+    appropriate source paths have to be set up when providing interface
+    files using :option:`--read-interface` option.
+
+.. option:: --source-css=<style>
+
+    Use custom CSS file for sources rendered by the
+    :option:`--hyperlinked-source` option. If no custom style file is
+    provided, Haddock will use default one.
+
+.. option:: -S, --docbook
+
+    Reserved for future use (output documentation in DocBook XML
+    format).
+
+.. option:: --base-url=<url>
+
+    Base url for static assets (eg. css, javascript, json files etc.).
+    When present, static assets are not copied.  This option is useful
+    when creating documentation for multiple packages, it allows to have
+    a single copy of static assets served from the given url.
+
+.. option:: --source-base=<url>
+            --source-module=<url>
+            --source-entity=<url>
+            --source-entity-line=<url>
+
+    Include links to the source files in the generated documentation.
+    Use the :option:`--source-base` option to add a source code link in the
+    header bar of the contents and index pages. Use the
+    :option:`--source-module` to add a source code link in the header bar of
+    each module page. Use the :option:`--source-entity` option to add a source
+    code link next to the documentation for every value and type in each
+    module. :option:`--source-entity-line` is a flag that gets used for
+    entities that need to link to an exact source location rather than a
+    name, eg. since they were defined inside a Template Haskell splice.
+
+    In each case URL is the base URL where the source files can be
+    found. For the per-module and per-entity URLs, the following
+    substitutions are made within the string URL:
+
+    -  The string ``%M`` or ``%{MODULE}`` is replaced by the module
+       name. Note that for the per-entity URLs this is the name of the
+       *exporting* module.
+
+    -  The string ``%F`` or ``%{FILE}`` is replaced by the original
+       source file name. Note that for the per-entity URLs this is the
+       name of the *defining* module.
+
+    -  The string ``%N`` or ``%{NAME}`` is replaced by the name of the
+       exported value or type. This is only valid for the
+       :option:`--source-entity` option.
+
+    -  The string ``%K`` or ``%{KIND}`` is replaced by a flag indicating
+       whether the exported name is a value ``v`` or a type
+       ``t``. This is only valid for the :option:`--source-entity` option.
+
+    -  The string ``%L`` or ``%{LINE}`` is replaced by the number of the
+       line where the exported value or type is defined. This is only
+       valid for the :option:`--source-entity` option.
+
+    -  The string ``%%`` is replaced by ``%``.
+
+    For example, if your sources are online under some directory, you
+    would say ``haddock --source-base=url/ --source-module=url/%F``
+
+    If you have html versions of your sources online with anchors for
+    each type and function name, you would say
+    ``haddock --source-base=url/ --source-module=url/%M.html --source-entity=url/%M.html#%N``
+
+    For the ``%{MODULE}`` substitution you may want to replace the
+    ``.`` character in the module names with some other character
+    (some web servers are known to get confused by multiple ``.``
+    characters in a file name). To replace it with a character c use
+    ``%{MODULE/./c}``.
+
+    Similarly, for the ``%{FILE}`` substitution you may want to replace
+    the ``/`` character in the file names with some other character
+    (especially for links to colourised entity source code with a shared
+    css file). To replace it with a character c use ``%{FILE///c}``/
+
+    One example of a tool that can generate syntax-highlighted HTML from
+    your source code, complete with anchors suitable for use from
+    haddock, is
+    `hscolour <http://www.cs.york.ac.uk/fp/darcs/hscolour>`__.
+
+.. option:: -s <url>
+            --source=<url>
+
+    Deprecated aliases for :option:`--source-module`
+
+.. option:: --comments-base=<url>
+            --comments-module=<url>
+            --comments-entity=<url>
+
+    documentation. This feature would typically be used in conjunction
+    with a Wiki system.
+
+    Use the :option:`--comments-base` option to add a user comments link in
+    the header bar of the contents and index pages. Use the
+    :option:`--comments-module` to add a user comments link in the header bar
+    of each module page. Use the :option:`--comments-entity` option to add a
+    comments link next to the documentation for every value and type in
+    each module.
+
+    In each case URL is the base URL where the corresponding comments
+    page can be found. For the per-module and per-entity URLs the same
+    substitutions are made as with the :option:`--source-module` and
+    :option:`--source-entity` options above.
+
+    For example, if you want to link the contents page to a wiki page,
+    and every module to subpages, you would say
+    ``haddock --comments-base=url --comments-module=url/%M``
+
+    If your Wiki system doesn't like the ``.`` character in Haskell
+    module names, you can replace it with a different character. For
+    example to replace the ``.`` characters with ``_`` use
+    ``haddock --comments-base=url --comments-module=url/%{MODULE/./_}``.
+    Similarly, you can replace the ``/`` in a file name (may be useful for
+    entity comments, but probably not).
+
+.. option:: --theme=<path>
+
+    Specify a theme to be used for HTML (:option:`--html`) documentation. If
+    given multiple times then the pages will use the first theme given
+    by default, and have alternate style sheets for the others. The
+    reader can switch between themes with browsers that support
+    alternate style sheets, or with the "Style" menu that gets added
+    when the page is loaded. If no themes are specified, then just the
+    default built-in theme ("Linuwial") is used.
+
+    The path parameter can be one of:
+
+    -  A *directory*: The base name of the directory becomes the name of
+       the theme. The directory must contain exactly one ``some.css``
+       file. Other files, usually image files, will be copied, along
+       with the ``some.css`` file, into the generated output directory.
+
+    -  A *CSS file*: The base name of the file becomes the name of the
+       theme.
+
+    -  The *name* of a built-in theme ("Linuwial", "Ocean", or "Classic").
+
+.. option:: --built-in-themes
+
+    Includes the built-in themes ("Linuwial", "Ocean", and "Classic"). Can be
+    combined with :option:`--theme`. Note that order matters: The first
+    specified theme will be the default.
+
+.. option:: --use-unicode
+
+    Enable use of Unicode characters in HTML output.
+
+.. option:: -c <file>
+            --css=<file>
+
+    Deprecated aliases for :option:`--theme`
+
+.. option:: -p <file>
+            --prologue=<file>
+
+    Specify a file containing documentation which is placed on the main
+    contents page under the heading “Description”. The file is parsed as
+    a normal Haddock doc comment (but the comment markers are not
+    required).
+
+.. option:: -t <title>
+            --title=<title>
+
+    Use title as the page heading for each page in the
+    documentation.This will normally be the name of the library being
+    documented.
+
+    The title should be a plain string (no markup please!).
+
+.. option:: --package-name=<name>
+
+    Specify the name of the package being documented.
+
+.. option:: --package-version=<version>
+
+    Specify the version of the package being documented.
+
+.. option:: -q <mode>
+            --qual=<mode>
+
+    Specify how identifiers are qualified.
+
+    mode should be one of
+
+    -  ``none`` (default): don't qualify any identifiers
+
+    -  ``full``: always qualify identifiers completely
+
+    -  ``local``: only qualify identifiers that are not part of the module
+
+    -  ``relative``: like local, but strip name of the module from
+       qualifications of identifiers in submodules
+
+    Example: If you generate documentation for module A, then the
+    identifiers A.x, A.B.y and C.z are qualified as follows.
+
+    -  none: x, y, z
+
+    -  full: A.x, A.B.y, C.z
+
+    -  local: x, A.B.y, C.z
+
+    -  relative: x, B.y, C.z
+
+.. option:: --since-qual=<mode>
+
+    Specify how ``@since`` annotations are qualified.
+
+    mode should be one of
+
+    -  ``always`` (default): always qualify ``@since`` annotations with
+       a package name and version
+
+    -  ``only-external``: only qualify ``@since`` annotations with a
+       package name and version when they do not come from the current
+       package
+
+.. option:: -?
+            --help
+
+    Display help and exit.
+
+.. option:: -V
+            --version
+
+    Output version information and exit.
+
+.. option:: --ghc-version
+
+    Output the version of GHC which Haddock expects to find at :option:-B
+    and exit.
+
+.. option:: --print-ghc-path
+
+    Output the path to the GHC (which Haddock computes based on :option:-B)
+    and exit.
+
+.. option:: --print-ghc-libdir
+
+    Output the path to the GHC ``lib`` directory (which Haddock computes
+    based on :option:-B) and exit.
+
+.. option:: -v
+            --verbose
+
+    Increase verbosity. Currently this will cause Haddock to emit some
+    extra warnings, in particular about modules which were imported but
+    it had no information about (this is often quite normal; for example
+    when there is no information about the ``Prelude``).
+
+.. option:: --use-contents=<url>
+            --use-index=<url>
+
+    When generating HTML, do not generate an index. Instead, redirect
+    the Contents and/or Index link on each page to URL. This option is
+    intended for use in conjunction with :option:`--gen-contents` and/or
+    :option:`--gen-index` for generating a separate contents and/or index
+    covering multiple libraries.
+
+.. option:: --gen-contents
+            --gen-index
+
+    Generate an HTML contents and/or index containing entries pulled
+    from all the specified interfaces (interfaces are specified using
+    :option:`-i` or :option:`--read-interface`). This is used to generate a single
+    contents and/or index for multiple sets of Haddock documentation.
+
+.. option:: --ignore-all-exports
+
+    Causes Haddock to behave as if every module has the
+    ``ignore-exports`` attribute (:ref:`module-attrs`). This might be useful for
+    generating implementation documentation rather than interface
+    documentation, for example.
+
+.. option:: --hide <module>
+
+    Causes Haddock to behave as if module module has the ``hide``
+    attribute. (:ref:`module-attrs`).
+
+.. option:: --show <module>
+
+    Causes Haddock to behave as if module module does not have the ``hide``
+    attribute. (:ref:`module-attrs`).
+
+.. option:: --show-all
+
+    Causes Haddock to behave as if no modules have the ``hide`` attribute.
+    (:ref:`module-attrs`).
+
+.. option:: --show-extensions <module>
+
+    Causes Haddock to behave as if module module has the
+    ``show-extensions`` attribute. (:ref:`module-attrs`).
+
+.. option:: --optghc=<option>
+
+    Pass option to GHC. Note that there is a double dash there, unlike
+    for GHC.
+
+.. option:: -w
+            --no-warnings
+
+    Turn off all warnings.
+
+.. option:: --interface-version
+
+    Prints out the version of the binary Haddock interface files that
+    this version of Haddock generates.
+
+.. option:: --compatible-interface-versions
+
+    Prints out space-separated versions of binary Haddock interface
+    files that this version of Haddock is compatible with.
+
+.. option:: --bypass-interface-version-check
+
+    **DANGEROUS** Causes Haddock to ignore the interface versions of
+    binary Haddock interface files. This can make Haddock crash during
+    deserialization of interface files.
+
+.. option:: --no-tmp-comp-dir
+
+    Do not use a temporary directory for reading and writing compilation
+    output files (``.o``, ``.hi``, and stub files). Instead, use the
+    present directory or another directory that you have explicitly told
+    GHC to use via the :option:`--optghc` flag.
+
+    This flag can be used to avoid recompilation if compilation files
+    already exist. Compilation files are produced when Haddock has to
+    process modules that make use of Template Haskell, in which case
+    Haddock compiles the modules using the GHC API.
+
+.. option:: --print-missing-docs
+
+    Print extra information about any undocumented entities.
+
+Using literate or pre-processed source
+--------------------------------------
+
+Since Haddock uses GHC internally, both plain and literate Haskell
+sources are accepted without the need for the user to do anything. To
+use the C pre-processor, however, the user must pass the ``-cpp``
+option to GHC using :option:`--optghc`.
diff --git a/doc/markup.rst b/doc/markup.rst
new file mode 100644
--- /dev/null
+++ b/doc/markup.rst
@@ -0,0 +1,1264 @@
+Documentation and Markup
+========================
+
+Haddock understands special documentation annotations in the Haskell
+source file and propagates these into the generated documentation. The
+annotations are purely optional: if there are no annotations, Haddock
+will just generate documentation that contains the type signatures, data
+type declarations, and class declarations exported by each of the
+modules being processed.
+
+.. _top-level-declaration:
+
+Documenting a Top-Level Declaration
+-----------------------------------
+
+The simplest example of a documentation annotation is for documenting
+any top-level declaration (function type signature, type declaration, or
+class declaration). For example, if the source file contains the
+following type signature: ::
+
+    square :: Int -> Int
+    square x = x * x
+
+Then we can document it like this: ::
+
+    -- |The 'square' function squares an integer.
+    square :: Int -> Int
+    square x = x * x
+
+The ``-- |`` syntax begins a documentation annotation, which applies
+to the *following* declaration in the source file. Note that the
+annotation is just a comment in Haskell — it will be ignored by the
+Haskell compiler.
+
+The declaration following a documentation annotation should be one of
+the following:
+
+-  A type signature for a top-level function,
+
+-  A definition for a top-level function with no type signature,
+
+-  A ``data`` declaration,
+
+-  A ``pattern`` declaration,
+
+-  A ``newtype`` declaration,
+
+-  A ``type`` declaration
+
+-  A ``class`` declaration,
+
+-  An ``instance`` declaration,
+
+-  A ``data family`` or ``type family`` declaration, or
+
+-  A ``data instance`` or ``type instance`` declaration.
+
+If the annotation is followed by a different kind of declaration, it
+will probably be ignored by Haddock.
+
+Some people like to write their documentation *after* the declaration;
+this is possible in Haddock too: ::
+
+    square :: Int -> Int
+    -- ^The 'square' function squares an integer.
+    square x = x * x
+
+Since Haddock uses the GHC API internally, it can infer types for
+top-level functions without type signatures. However, you're
+encouraged to add explicit type signatures for all top-level
+functions, to make your source code more readable for your users, and
+at times to avoid GHC inferring overly general type signatures that
+are less helpful to your users.
+
+Documentation annotations may span several lines; the annotation
+continues until the first non-comment line in the source file. For
+example: ::
+
+    -- |The 'square' function squares an integer.
+    -- It takes one argument, of type 'Int'.
+    square :: Int -> Int
+    square x = x * x
+
+You can also use Haskell's nested-comment style for documentation
+annotations, which is sometimes more convenient when using multi-line
+comments: ::
+
+    {-|
+      The 'square' function squares an integer.
+      It takes one argument, of type 'Int'.
+    -}
+    square :: Int -> Int
+    square x = x * x
+
+Documenting Parts of a Declaration
+----------------------------------
+
+In addition to documenting the whole declaration, in some cases we can
+also document individual parts of the declaration.
+
+Class Methods
+~~~~~~~~~~~~~
+
+Class methods are documented in the same way as top level type
+signatures, by using either the ``-- |`` or ``-- ^`` annotations: ::
+
+    class C a where
+       -- | This is the documentation for the 'f' method
+       f :: a -> Int
+       -- | This is the documentation for the 'g' method
+       g :: Int -> a
+
+Associated type and data families can also be annotated in this way.
+
+Constructors and Record Fields
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Constructors are documented like so: ::
+
+    data T a b
+      -- | This is the documentation for the 'C1' constructor
+      = C1 a b
+      -- | This is the documentation for the 'C2' constructor
+      | C2 a b
+
+or like this: ::
+
+    data T a b
+      = C1   -- ^ This is the documentation for the 'C1' constructor
+          a  -- ^ This is the documentation for the argument of type 'a'
+          b  -- ^ This is the documentation for the argument of type 'b'
+
+There is one edge case that is handled differently: only one ``-- ^``
+annotation occurring after the constructor and all its arguments is
+applied to the constructor, not its last argument: ::
+
+    data T a b
+      = C1 a b  -- ^ This is the documentation for the 'C1' constructor
+      | C2 a b  -- ^ This is the documentation for the 'C2' constructor
+
+Record fields are documented using one of these styles: ::
+
+    data R a b =
+      C { -- | This is the documentation for the 'a' field
+          a :: a,
+          -- | This is the documentation for the 'b' field
+          b :: b
+        }
+
+    data R a b =
+      C { a :: a  -- ^ This is the documentation for the 'a' field
+        , b :: b  -- ^ This is the documentation for the 'b' field
+        }
+
+Alternative layout styles are generally accepted by Haddock - for
+example doc comments can appear before or after the comma in separated
+lists such as the list of record fields above.
+
+In cases where more than one constructor exports a field with the same
+name, the documentation attached to the first occurrence of the field
+will be used, even if a comment is not present. ::
+
+    data T a = A { someField :: a -- ^ Doc for someField of A
+                 }
+             | B { someField :: a -- ^ Doc for someField of B
+                 }
+
+In the above example, all occurrences of ``someField`` in the
+documentation are going to be documented with
+``Doc for someField of A``. Note that Haddock versions 2.14.0 and before
+would join up documentation of each field and render the result. The
+reason for this seemingly weird behaviour is the fact that ``someField``
+is actually the same (partial) function.
+
+Deriving clauses
+~~~~~~~~~~~~~~~~
+
+Most instances are top-level, so can be documented as in
+:ref:`top-level-declaration`. The exception to this is instance that are
+come from a ``deriving`` clause on a datatype declaration. These can
+be documented like this: ::
+
+    data D a = L a | M
+      deriving ( Eq   -- ^ @since 4.5
+               , Ord  -- ^ default 'Ord' instance
+               )
+
+This also scales to the various GHC extensions for deriving: ::
+
+    newtype T a = T a
+      deriving          Show     -- ^ derivation of 'Show'
+      deriving stock  ( Eq       -- ^ stock derivation of 'Eq'
+                      , Foldable -- ^ stock derivation of 'Foldable'
+                      )
+      deriving newtype  Ord      -- ^ newtype derivation of 'Ord'
+      deriving anyclass Read     -- ^ unsafe derivation of 'Read'
+      deriving        ( Eq1      -- ^ deriving 'Eq1' via 'Identity'
+                      , Ord1     -- ^ deriving 'Ord1' via 'Identity'
+                      ) via Identity
+
+Function Arguments
+~~~~~~~~~~~~~~~~~~
+
+Individual arguments to a function may be documented like this: ::
+
+    f  :: Int      -- ^ The 'Int' argument
+       -> Float    -- ^ The 'Float' argument
+       -> IO ()    -- ^ The return value
+
+Pattern synonyms, GADT-style data constructors, and class methods also
+support this style of documentation.
+
+.. _module-description:
+
+The Module Description
+----------------------
+
+A module itself may be documented with multiple fields that can then be
+displayed by the backend. In particular, the HTML backend displays all
+the fields it currently knows about. We first show the most complete
+module documentation example and then talk about the fields. ::
+
+    {-|
+    Module      : W
+    Description : Short description
+    Copyright   : (c) Some Person, 2013
+                      Someone Else, 2014
+    License     : GPL-3
+    Maintainer  : sample@email.com
+    Stability   : experimental
+    Portability : POSIX
+
+    Here is a longer description of this module, containing some
+    commentary with @some markup@.
+    -}
+    module W where
+    ...
+
+All fields are optional but they must be in order if they do appear.
+Multi-line fields are accepted but the consecutive lines have to start
+indented more than their label. If your label is indented one space, as
+is often the case with the ``--`` syntax, the consecutive lines have
+to start at two spaces at the very least. For example, above we saw a
+multiline ``Copyright`` field: ::
+
+    {-|
+    ...
+    Copyright   : (c) Some Person, 2013
+                      Someone Else, 2014
+    ...
+    -}
+
+That could equivalently be written as: ::
+
+    -- | ...
+    -- Copyright:
+    --  (c) Some Person, 2013
+    --  Someone Else, 2014
+    -- ...
+
+or as: ::
+
+    -- | ...
+    -- Copyright: (c) Some Person, 2013
+    --     Someone Else, 2014
+    -- ...
+
+but not as: ::
+
+    -- | ...
+    -- Copyright: (c) Some Person, 2013
+    -- Someone Else, 2014
+    -- ...
+
+since the ``Someone`` needs to be indented more than the
+``Copyright``.
+
+Whether new lines and other formatting in multiline fields is
+preserved depends on the field type. For example, new lines in the
+``Copyright`` field are preserved, but new lines in the
+``Description`` field are not; leading whitespace is not preserved in
+either [#backend]_. Please note that we do not enforce the format for
+any of the fields and the established formats are just a convention.
+
+.. [#backend] Technically, whitespace and newlines in the
+   ``Description`` field are preserved verbatim by the HTML backend,
+   but because most browsers collapse whitespace in HTML, they don't
+   render as such. But other backends may render this whitespace.
+
+Fields of the Module Description
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+The ``Module`` field specifies the current module name. Since the module
+name can be inferred automatically from the source file, it doesn't
+affect the output of any of the backends. But you might want to
+include it for any other tools that might be parsing these comments
+without the help of GHC.
+
+The ``Description`` field accepts some short text which outlines the
+general purpose of the module. If you're generating HTML, it will show
+up next to the module link in the module index.
+
+The ``Copyright``, ``License``, ``Maintainer`` and ``Stability`` fields should
+be obvious. An alternative spelling for the ``License`` field is accepted
+as ``Licence`` but the output will always prefer ``License``.
+
+The ``Portability`` field has seen varied use by different library
+authors. Some people put down things like operating system constraints
+there while others put down which GHC extensions are used in the module.
+Note that you might want to consider using the ``show-extensions`` module
+flag for the latter (see :ref:`module-attrs`).
+
+Finally, a module may contain a documentation comment before the
+module header, in which case this comment is interpreted by Haddock as
+an overall description of the module itself, and placed in a section
+entitled ``Description`` in the documentation for the module. All the
+usual Haddock :ref:`markup` is valid in this comment.
+
+Controlling the Documentation Structure
+---------------------------------------
+
+Haddock produces interface documentation that lists only the entities
+actually exported by the module. If there is no export list then all
+entities defined by the module are exported.
+
+The documentation for a module will
+include *all* entities exported by that module, even if they were
+re-exported from another module. The only exception is when Haddock can't
+see the declaration for the re-exported entity, perhaps because it isn't
+part of the batch of modules currently being processed.
+
+To Haddock the export list has even more significance than just
+specifying the entities to be included in the documentation. It also
+specifies the *order* that entities will be listed in the generated
+documentation. This leaves the programmer free to implement functions in
+any order he/she pleases, and indeed in any *module* he/she pleases, but
+still specify the order that the functions should be documented in the
+export list. Indeed, many programmers already do this: the export list
+is often used as a kind of ad-hoc interface documentation, with
+headings, groups of functions, type signatures and declarations in
+comments.
+
+In the next section we give examples illustrating most of the
+structural markup features. After the examples we go into more detail
+explaining the related markup, namely :ref:`section-headings`,
+:ref:`named-chunks`, and :ref:`re-exporting-entire-module`.
+
+.. _structure-examples:
+
+Documentation Structure Examples
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+We now give several examples that produce similar results and
+illustrate most of the structural markup features. The first two
+examples use an export list, but the third example does not.
+
+The first example, using an export list with :ref:`section-headings`
+and inline section descriptions: ::
+
+    module Image
+      ( -- * Image importers
+        --
+        -- | There is a "smart" importer, 'readImage', that determines
+        -- the image format from the file extension, and several
+        -- "dumb" format-specific importers that decode the file as
+        -- the specified type.
+        readImage
+      , readPngImage
+      , readGifImage
+      , ...
+        -- * Image exporters
+        -- ...
+      ) where
+
+    import Image.Types ( Image )
+
+    -- | Read an image, guessing the format from the file name.
+    readImage :: FilePath -> IO Image
+    readImage = ...
+
+    -- | Read a GIF.
+    readGifImage :: FilePath -> IO Image
+    readGifImage = ...
+
+    -- | Read a PNG.
+    readPngImage :: FilePath -> IO Image
+    readPngImage = ...
+
+    ...
+
+Note that the order of the entities ``readPngImage`` and
+``readGifImage`` in the export list is different from the order of the
+actual declarations farther down; the order in the export list is the
+order used in the generated docs. Also, the imported ``Image`` type
+itself is not re-exported, so it will not be included in the rendered
+docs (see :ref:`hyperlinking-re-exported`).
+
+The second example, using an export list with a section description
+defined elsewhere (the ``$imageImporters``; see :ref:`named-chunks`):
+::
+
+    module Image
+      ( -- * Image importers
+        --
+        -- $imageImporters
+        readImage
+      , readPngImage
+      , readGifImage
+      , ...
+        -- * Image exporters
+        -- ...
+      ) where
+
+    import Image.Types ( Image )
+
+    -- $imageImporters
+    --
+    -- There is a "smart" importer, 'readImage', that determines the
+    -- image format from the file extension, and several "dumb"
+    -- format-specific importers that decode the file as the specified
+    -- type.
+
+    -- | Read an image, guessing the format from the file name.
+    readImage :: FilePath -> IO Image
+    readImage = ...
+
+    -- | Read a GIF.
+    readGifImage :: FilePath -> IO Image
+    readGifImage = ...
+
+    -- | Read a PNG.
+    readPngImage :: FilePath -> IO Image
+    readPngImage = ...
+
+    ...
+
+This produces the same rendered docs as the first example, but the
+source code itself is arguably more readable, since the documentation
+for the group of importer functions is closer to their definitions.
+
+The third example, without an export list: ::
+
+    module Image where
+
+    import Image.Types ( Image )
+
+    -- * Image importers
+    --
+    -- $imageImporters
+    --
+    -- There is a "smart" importer, 'readImage', that determines the
+    -- image format from the file extension, and several "dumb"
+    -- format-specific importers that decode the file as the specified
+    -- type.
+
+    -- | Read an image, guessing the format from the file name.
+    readImage :: FilePath -> IO Image
+    readImage = ...
+
+    -- | Read a GIF.
+    readGifImage :: FilePath -> IO Image
+    readGifImage = ...
+
+    -- | Read a PNG.
+    readPngImage :: FilePath -> IO Image
+    readPngImage = ...
+
+    ...
+
+    -- * Image exporters
+    -- ...
+
+Note that the section headers (e.g. ``-- * Image importers``) now
+appear in the module body itself, and that the section documentation
+is still given using :ref:`named-chunks`. Unlike in the first example
+when using an export list, the named chunk syntax ``$imageImporters``
+*must* be used for the section documentation; attempting to use the
+``-- | ...`` syntax to document the image importers here will wrongly
+associate the documentation chunk with the next definition!
+
+.. _section-headings:
+
+Section Headings
+~~~~~~~~~~~~~~~~
+
+You can insert headings and sub-headings in the documentation by
+including annotations at the appropriate point in the export list, or
+in the module body directly when not using an export list.
+
+For example: ::
+
+    module Foo (
+      -- * Classes
+      C(..),
+      -- * Types
+      -- ** A data type
+      T,
+      -- ** A record
+      R,
+      -- * Some functions
+      f, g
+      ) where
+
+Headings are introduced with the syntax ``-- *``, ``-- **`` and so
+on, where the number of ``*``\ s indicates the level of the heading
+(section, sub-section, sub-sub-section, etc.).
+
+If you use section headings, then Haddock will generate a table of
+contents at the top of the module documentation for you.
+
+By default, when generating HTML documentation Haddock will create an
+anchor to each section of the form ``#g:n``, where ``n`` is an integer
+that might change as you add new section headings. If you want to
+create stable links, you can add an explicit anchor (see
+:ref:`anchors`) after the section heading: ::
+
+  module Foo (
+    -- * Classes #classes#
+    C(..)
+  ) where
+
+This will create an HTML anchor ``#g:classes`` to the section.
+
+The alternative style of placing the commas at the beginning of each
+line is also supported, e.g.: ::
+
+    module Foo (
+      -- * Classes
+        C(..)
+      -- * Types
+      -- ** A data type
+      , T
+      -- ** A record
+      , R
+      -- * Some functions
+      , f
+      , g
+      ) where
+
+When not using an export list, you may insert section headers in the
+module body. Such section headers associate with all entities
+declared up until the next section header. For example: ::
+
+    module Foo where
+
+    -- * Classes
+    class C a where ...
+
+    -- * Types
+    -- ** A data type
+    data T = ...
+
+    -- ** A record
+    data R = ...
+
+    -- * Some functions
+    f :: ...
+    f = ...
+    g :: ...
+    g = ...
+
+.. _re-exporting-entire-module:
+
+Re-Exporting an Entire Module
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Haskell allows you to re-export the entire contents of a module (or at
+least, everything currently in scope that was imported from a given
+module) by listing it in the export list: ::
+
+    module A (
+      module B,
+      module C
+     ) where
+
+What will the Haddock-generated documentation for this module look like?
+Well, it depends on how the modules ``B`` and ``C`` are imported. If
+they are imported wholly and without any ``hiding`` qualifiers, then the
+documentation will just contain a cross-reference to the documentation
+for ``B`` and ``C``.
+
+However, if the modules are not *completely* re-exported, for example:
+::
+
+    module A (
+      module B,
+      module C
+     ) where
+
+    import B hiding (f)
+    import C (a, b)
+
+then Haddock behaves as if the set of entities re-exported from ``B``
+and ``C`` had been listed explicitly in the export list.
+
+The exception to this rule is when the re-exported module is declared
+with the ``hide`` attribute (see :ref:`module-attrs`), in which
+case the module is
+never cross-referenced; the contents are always expanded in place in the
+re-exporting module.
+
+.. _named-chunks:
+
+(Named) Chunks of Documentation
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+It is often desirable to include a chunk of documentation which is not
+attached to any particular Haskell declaration, for example, when
+giving summary documentation for a group of related definitions (see
+:ref:`structure-examples`). In addition to including such documentation
+chunks at the top of the file, as part of the
+:ref:`module-description`, you can also associate them with
+:ref:`section-headings`.
+
+There are several ways to associate documentation chunks with section
+headings, depending on whether you are using an export list or not:
+
+-  The documentation can be included in the export list directly, by
+   preceding it with a ``-- |``. For example: ::
+
+       module Foo (
+          -- * A section heading
+
+          -- | Some documentation not attached to a particular Haskell entity
+          ...
+        ) where
+
+   In this case the chunk is not "named".
+
+-  If the documentation is large and placing it inline in the export
+   list might bloat the export list and obscure the structure, then it
+   can be given a name and placed out of line in the body of the module.
+   This is achieved with a special form of documentation annotation
+   ``-- $``, which we call a *named chunk*: ::
+
+       module Foo (
+          -- * A section heading
+
+          -- $doc
+          ...
+        ) where
+
+       -- $doc
+       -- Here is a large chunk of documentation which may be referred to by
+       -- the name $doc.
+
+   The documentation chunk is given a name of your choice (here
+   ``doc``), which is the sequence of alphanumeric characters directly
+   after the ``-- $``, and it may be referred to by the same name in
+   the export list. Note that named chunks must come *after* any
+   imports in the module body.
+
+-  If you aren't using an export list, then your only choice is to use
+   a named chunk with the ``-- $`` syntax. For example: ::
+
+       module Foo where
+
+       -- * A section heading
+       --
+       -- $doc
+       -- Here is a large chunk of documentation which may be referred to by
+       -- the name $doc.
+
+   Just like with entity declarations when not using an export list,
+   named chunks of documentation are associated with the preceding
+   section header here, or with the implicit top-level documentation
+   section if there is no preceding section header.
+
+   **Warning**: the form used in the first bullet above, where the
+   chunk is not named, *does not work* when you aren't using an
+   export list. For example: ::
+
+       module Foo where
+
+       -- * A section heading
+       --
+       -- | Some documentation not attached to a particular Haskell entity
+
+       -- | The fooifier.
+       foo :: ...
+
+   will result in ``Some documentation not ...`` being attached to the
+   *next* entity declaration, here ``foo``, in addition to any other
+   documentation that next entity already has!
+
+.. _hyperlinking-re-exported:
+
+Hyperlinking and Re-Exported Entities
+-------------------------------------
+
+When Haddock renders a type in the generated documentation, it
+hyperlinks all the type constructors and class names in that type to
+their respective definitions. But for a given type constructor or class
+there may be several modules re-exporting it, and therefore several
+modules whose documentation contains the definition of that type or
+class (possibly including the current module!) so which one do we link
+to?
+
+Let's look at an example. Suppose we have three modules ``A``, ``B`` and
+``C`` defined as follows: ::
+
+    module A (T) where
+    data T a = C a
+
+    module B (f) where
+    import A
+    f :: T Int -> Int
+    f (C i) = i
+
+    module C (T, f) where
+    import A
+    import B
+
+Module ``A`` exports a datatype ``T``. Module ``B`` imports ``A`` and
+exports a function ``f`` whose type refers to ``T``. Also, both ``T``
+and ``f`` are re-exported from module C.
+
+Haddock takes the view that each entity has a *home* module; that is,
+the module that the library designer would most like to direct the user
+to, to find the documentation for that entity. So, Haddock makes all
+links to an entity point to the home module. The one exception is when
+the entity is also exported by the current module: Haddock makes a local
+link if it can.
+
+How is the home module for an entity determined? Haddock uses the
+following rules:
+
+-  If modules A and B both export the entity, and module A imports
+   (directly or indirectly) module B, then B is preferred.
+
+-  A module with the ``hide`` attribute is never chosen as the home.
+
+-  A module with the ``not-home`` attribute is only chosen if there are
+   no other modules to choose.
+
+If multiple modules fit the criteria, then one is chosen at random. If
+no modules fit the criteria (because the candidates are all hidden),
+then Haddock will issue a warning for each reference to an entity
+without a home.
+
+In the example above, module ``A`` is chosen as the home for ``T``
+because it does not import any other module that exports ``T``. The link
+from ``f``'s type in module ``B`` will therefore point to ``A.T``.
+However, ``C`` also exports ``T`` and ``f``, and the link from ``f``'s
+type in ``C`` will therefore point locally to ``C.T``.
+
+.. _module-attrs:
+
+Module Attributes
+-----------------
+
+Certain attributes may be specified for each module which affect the
+way that Haddock generates documentation for that module. Attributes are
+specified in a comma-separated list in an
+``{-# OPTIONS_HADDOCK ... #-}`` pragma at the top of the module, either
+before or after the module description. For example: ::
+
+    {-# OPTIONS_HADDOCK hide, prune, ignore-exports #-}
+
+    -- |Module description
+    module A where
+    ...
+
+The options and module description can be in either order.
+
+The following attributes are currently understood by Haddock:
+
+``hide``
+    Omit this module from the generated documentation, but nevertheless
+    propagate definitions and documentation from within this module to
+    modules that re-export those definitions.
+
+``prune``
+    Omit definitions that have no documentation annotations from the
+    generated documentation.
+
+``ignore-exports``
+    Ignore the export list. Generate documentation as if the module had
+    no export list - i.e. all the top-level declarations are exported,
+    and section headings may be given in the body of the module.
+
+``not-home``
+    Indicates that the current module should not be considered to be the
+    home module for each entity it exports, unless that entity is not
+    exported from any other module. See :ref:`hyperlinking-re-exported`
+    for more details.
+
+``show-extensions``
+    Indicates that we should render the extensions used in this module
+    in the resulting documentation. This will only render if the output
+    format supports it. If Language is set, it will be shown as well and
+    all the extensions implied by it won't. All enabled extensions will
+    be rendered, including those implied by their more powerful
+    versions.
+
+.. _markup:
+
+Markup
+------
+
+Haddock understands certain textual cues inside documentation
+annotations that tell it how to render the documentation. The cues (or
+“markup”) have been designed to be simple and mnemonic in ASCII so
+the programmer doesn't have to deal with heavyweight annotations when
+editing documentation comments.
+
+Paragraphs
+~~~~~~~~~~
+
+One or more blank lines separates two paragraphs in a documentation
+comment.
+
+Special Characters
+~~~~~~~~~~~~~~~~~~
+
+The following characters have special meanings in documentation comments:
+``\``, ``/``, ``'``, `````, ``"``, ``@``, ``<``, ``$``, ``#``. To insert a
+literal occurrence of one of these special characters, precede it with a
+backslash (``\``).
+
+Additionally, the character ``>`` has a special meaning at the beginning
+of a line, and the following characters have special meanings at the
+beginning of a paragraph: ``*``, ``-``. These characters can also be
+escaped using ``\``.
+
+Furthermore, the character sequence ``>>>`` has a special meaning at the
+beginning of a line. To escape it, just prefix the characters in the
+sequence with a backslash.
+
+Character References
+~~~~~~~~~~~~~~~~~~~~
+
+Although Haskell source files may contain any character from the Unicode
+character set, the encoding of these characters as bytes varies between
+systems. Consequently, only source files restricted to the ASCII character set
+are portable. Other characters may be specified in character and string
+literals using Haskell character escapes. To represent such characters
+in documentation comments, Haddock supports SGML-style numeric character
+references of the forms ``&#``\ D\ ``;`` and ``&#x``\ H\ ``;`` where D
+and H are decimal and hexadecimal numbers denoting a code position in
+Unicode (or ISO 10646). For example, the references ``&#x3BB;``,
+``&#x3bb;`` and ``&#955;`` all represent the lower-case letter lambda.
+
+Code Blocks
+~~~~~~~~~~~
+
+Displayed blocks of code are indicated by surrounding a paragraph with
+``@...@`` or by preceding each line of a paragraph with ``>`` (we often
+call these “bird tracks”). For example: ::
+
+    -- | This documentation includes two blocks of code:
+    --
+    -- @
+    --     f x = x + x
+    -- @
+    --
+    -- >  g x = x * 42
+
+There is an important difference between the two forms of code block: in
+the bird-track form, the text to the right of the ‘\ ``>``\ ’ is
+interpreted literally, whereas the ``@...@`` form interprets markup as
+normal inside the code block. In particular, ``/`` is markup for italics,
+and so e.g. ``@x / y / z@`` renders as ``x`` followed by italic
+``y`` with no slashes, followed by ``z``.
+
+Examples
+~~~~~~~~
+
+Haddock has markup support for examples of interaction with a
+*read-eval-print loop (REPL)*. An example is introduced with ``>>>``
+followed by an expression followed by zero or more result lines: ::
+
+    -- | Two examples are given below:
+    --
+    -- >>> fib 10
+    -- 55
+    --
+    -- >>> putStrLn "foo\nbar"
+    -- foo
+    -- bar
+
+Result lines that only contain the string ``<BLANKLINE>`` are rendered
+as blank lines in the generated documentation.
+
+Properties
+~~~~~~~~~~
+
+Haddock provides markup for properties: ::
+
+    -- | Addition is commutative:
+    --
+    -- prop> a + b = b + a
+
+This allows third-party applications to extract and verify them.
+
+Hyperlinked Identifiers
+~~~~~~~~~~~~~~~~~~~~~~~
+
+Referring to a Haskell identifier, whether it be a type, class,
+constructor, or function, is done by surrounding it with a combination
+of single quotes and backticks. For example: ::
+
+    -- | This module defines the type 'T'.
+
+```T``` is also ok. ``'T``` and ```T'`` are accepted but less common.
+
+If there is an entity ``T`` in scope in the current module, then the
+documentation will hyperlink the reference in the text to the definition
+of ``T`` (if the output format supports hyperlinking, of course; in a
+printed format it might instead insert a page reference to the
+definition).
+
+It is also possible to refer to entities that are not in scope in the
+current module, by giving the full qualified name of the entity: ::
+
+    -- | The identifier 'M.T' is not in scope
+
+If ``M.T`` is not otherwise in scope, then Haddock will simply emit a
+link pointing to the entity ``T`` exported from module ``M`` (without
+checking to see whether either ``M`` or ``M.T`` exist).
+
+Since values and types live in different namespaces in Haskell, it is possible
+for a reference such as ``'X'`` to be ambiguous. In such a case, Haddock
+defaults to pointing to the type. The ambiguity can be overcome by explicitly
+specifying a namespace, by way of a ``v`` (for value) or ``t`` (for type)
+immediately before the link: ::
+
+    -- | An implicit reference to  'X', the type constructor
+    --   An explicit reference to v'X', the data constructor
+    --   An explicit reference to t'X', the type constructor
+    data X = X
+
+To make life easier for documentation writers, a quoted identifier is
+only interpreted as such if the quotes surround a lexically valid
+Haskell identifier. This means, for example, that it normally isn't
+necessary to escape the single quote when used as an apostrophe: ::
+
+    -- | I don't have to escape my apostrophes; great, isn't it?
+
+Nothing special is needed to hyperlink identifiers which contain
+apostrophes themselves: to hyperlink ``foo'`` one would simply type
+``'foo''``. Hyperlinking operators works in exactly the same way. ::
+
+    -- | A prefix operator @'(++)'@ and an infix identifier @'`elem`'@.
+
+Emphasis, Bold and Monospaced Styled Text
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Text can be emphasized, made bold (strong) or monospaced (typewriter font) 
+by surrounding it with slashes, double-underscores or at-symbols: ::
+
+    -- | This is /emphasized text/, __bold text__ and @monospaced text@.
+
+Note that those styled texts must be kept on the same line: ::
+
+    -- | Styles /do not work
+    -- | when continuing on the next line/
+
+Other markup is valid inside emphasized, bold and monospaced text.
+
+Frequent special cases: 
+
+* To have a forward slash inside of emphasis, just escape it: ``/fo\/o/``.
+* There's no need to escape a single underscore if you need it
+  bold: ``__This_text_with_underscores_is_bold__``.
+* ``@'f' a b@`` will hyperlink the identifier ``f`` inside the code
+  fragment.
+* ``@__FILE__@`` will render ``FILE`` in bold with no underscores, 
+  which may not be what you had in mind.
+
+Linking to Modules
+~~~~~~~~~~~~~~~~~~
+
+Linking to a module is done by surrounding the module name with double
+quotes: ::
+
+    -- | This is a reference to the "Foo" module.
+
+A basic check is done on the syntax of the header name to ensure that it
+is valid before turning it into a link but unlike with identifiers,
+whether the module is in scope isn't checked and will always be turned
+into a link.
+
+It is also possible to specify alternate text for the generated link
+using syntax analogous to that used for URLs: ::
+
+  -- | This is a reference to [the main module]("Module.Main").
+
+Itemized and Enumerated Lists
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+A bulleted item is represented by preceding a paragraph with either
+“``*``” or “``-``”. A sequence of bulleted paragraphs is rendered as an
+itemized list in the generated documentation, e.g.: ::
+
+    -- | This is a bulleted list:
+    --
+    --     * first item
+    --
+    --     * second item
+
+An enumerated list is similar, except each paragraph must be preceded by
+either “``(n)``” or “``n.``” where n is any integer. e.g. ::
+
+    -- | This is an enumerated list:
+    --
+    --     (1) first item
+    --
+    --     2. second item
+
+Lists of the same type don't have to be separated by a newline: ::
+
+    -- | This is an enumerated list:
+    --
+    --     (1) first item
+    --     2. second item
+    --
+    -- This is a bulleted list:
+    --
+    --     * first item
+    --     * second item
+
+You can have more than one line of content in a list element: ::
+
+    -- |
+    -- * first item
+    -- and more content for the first item
+    -- * second item
+    -- and more content for the second item
+
+You can even nest whole paragraphs inside of list elements. The rules
+are 4 spaces for each indentation level. You're required to use a
+newline before such nested paragraphs: ::
+
+    {-|
+    * Beginning of list
+    This belongs to the list above!
+
+        > nested
+        > bird
+        > tracks
+
+        * Next list
+        More of the indented list.
+
+            * Deeper
+
+                @
+                even code blocks work
+                @
+
+                * Deeper
+
+                        1. Even deeper!
+                        2. No newline separation even in indented lists.
+    -}
+
+The indentation of the first list item is honoured. That is, in the
+following example the items are on the same level. Before Haddock
+2.16.1, the second item would have been nested under the first item
+which was unexpected. ::
+
+    {-|
+        * foo
+
+        * bar
+    -}
+
+Definition Lists
+~~~~~~~~~~~~~~~~
+
+Definition lists are written as follows: ::
+
+    -- | This is a definition list:
+    --
+    --   [@foo@]: The description of @foo@.
+    --
+    --   [@bar@]: The description of @bar@.
+
+To produce output something like this:
+
+``foo``
+    The description of ``foo``.
+
+``bar``
+    The description of ``bar``.
+
+Each paragraph should be preceded by the “definition term” enclosed in
+square brackets and followed by a colon. Other markup operators may be
+used freely within the definition term. You can escape ``]`` with a
+backslash as usual.
+
+Same rules about nesting and no newline separation as for bulleted and
+numbered lists apply.
+
+URLs
+~~~~
+
+A URL can be included in a documentation comment by surrounding it in
+angle brackets, for example: ::
+
+    <http://example.com>
+
+If the output format supports it, the URL will be turned into a
+hyperlink when rendered.
+
+If Haddock sees something that looks like a URL (such as something
+starting with ``http://`` or ``ssh://``) where the URL markup is valid,
+it will automatically make it a hyperlink.
+
+Links
+~~~~~
+
+Haddock supports Markdown syntax for inline links. A link consists of a
+link text and a URL. The link text is enclosed in square brackets and
+followed by the URL enclosed in regular parentheses, for example: ::
+
+    [some link](http://example.com)
+
+The link text is used as a description for the URL if the output
+format supports it.
+   
+Images
+~~~~~~
+
+Haddock supports Markdown syntax for inline images. This resembles the
+syntax for links, but starts with an exclamation mark. An example looks
+like this: ::
+
+    ![image description](pathtoimage.png)
+
+If the output format supports it, the image will be rendered inside the
+documentation. The image description is used as replacement text and/or
+an image title.
+
+Mathematics / LaTeX
+~~~~~~~~~~~~~~~~~~~
+
+Haddock supports LaTeX syntax for rendering mathematical notation. The
+delimiters are ``\[...\]`` for displayed mathematics and ``\(...\)``
+for in-line mathematics. An example looks like this: ::
+
+  \[
+  f(a) = \frac{1}{2\pi i}\oint_\gamma \frac{f(z)}{z-a}\,\mathrm{d}z
+  \]
+
+If the output format supports it, the mathematics will be rendered
+inside the documentation. For example, the HTML backend will display
+the mathematics via `MathJax <https://www.mathjax.org>`__.
+
+Grid Tables
+~~~~~~~~~~~
+
+Inspired by reSTs grid tables, Haddock supports a complete table representation
+via grid-like "ASCII art". Grid tables are described with a visual grid made
+up of the characters "-", "=", "|", and "+". The hyphen ("-") is used for
+horizontal lines (row separators). The equals sign ("=") may be used to
+separate optional header rows from the table body. The vertical bar ("|") is
+used for vertical lines (column separators). The plus sign ("+") is used for
+intersections of horizontal and vertical lines. ::
+
+    -- | This is a grid table:
+    --
+    -- +------------------------+------------+----------+----------+
+    -- | Header row, column 1   | Header 2   | Header 3 | Header 4 |
+    -- | (header rows optional) |            |          |          |
+    -- +========================+============+==========+==========+
+    -- | body row 1, column 1   | column 2   | column 3 | column 4 |
+    -- +------------------------+------------+----------+----------+
+    -- | body row 2             | Cells may span columns.          |
+    -- +------------------------+------------+---------------------+
+    -- | body row 3             | Cells may  | \[                  |
+    -- +------------------------+ span rows. | f(n) = \sum_{i=1}   |
+    -- | body row 4             |            | \]                  |
+    -- +------------------------+------------+---------------------+
+
+.. _anchors:
+
+Anchors
+~~~~~~~
+
+Sometimes it is useful to be able to link to a point in the
+documentation which doesn't correspond to a particular entity. For that
+purpose, we allow *anchors* to be included in a documentation comment.
+The syntax is ``#label#``, where label is the name of the anchor. An
+anchor is invisible in the generated documentation.
+
+To link to an anchor from elsewhere, use the syntax ``"module#label"``
+where module is the module name containing the anchor, and label is the
+anchor label. The module does not have to be local, it can be imported
+via an interface. Please note that in Haddock versions 2.13.x and
+earlier, the syntax was ``"module\#label"``. It is considered deprecated
+and will be removed in the future.
+
+Headings
+~~~~~~~~
+
+Headings inside of comment documentation are possible by preceding them
+with a number of ``=``\ s. From 1 to 6 are accepted. Extra ``=``\ s will
+be treated as belonging to the text of the heading. Note that it's up to
+the output format to decide how to render the different levels. ::
+
+    -- |
+    -- = Heading level 1 with some /emphasis/
+    -- Something underneath the heading.
+    --
+    -- == /Subheading/
+    -- More content.
+    --
+    -- === Subsubheading
+    -- Even more content.
+
+Note that while headings have to start on a new paragraph, we allow
+paragraph-level content to follow these immediately. ::
+
+    -- |
+    -- = Heading level 1 with some __bold__
+    -- Something underneath the heading.
+    --
+    -- == /Subheading/
+    -- More content.
+    --
+    -- === Subsubheading
+    -- >>> examples are only allowed at the start of paragraphs
+
+As of 2.15.1, there's experimental (read: subject to change or get
+removed) support for collapsible headers: simply wrap your existing
+header title in underscores, as per bold syntax. The collapsible section
+will stretch until the end of the comment or until a header of equal or
+smaller number of ``=``\ s. ::
+
+    -- |
+    -- === __Examples:__
+    -- >>> Some very long list of examples
+    --
+    -- ==== This still falls under the collapse
+    -- Some specialised examples
+    --
+    -- === This is does not go into the collapsable section.
+    -- More content.
+
+Metadata
+~~~~~~~~
+
+Since Haddock 2.16.0, some support for embedding metadata in the
+comments has started to appear. The use of such data aims to standardise
+various community conventions in how such information is conveyed and to
+provide uniform rendering.
+
+Since
+^^^^^
+
+``@since`` annotation can be used to convey information about when the
+function was introduced or when it has changed in a way significant to
+the user. ``@since`` is a paragraph-level element. While multiple such
+annotations are not an error, only the one to appear in the comment last
+will be used. ``@since`` has to be followed with a version number, no
+further description is currently allowed. The meaning of this feature is
+subject to change in the future per user feedback. ::
+
+    -- |
+    -- Some comment
+    --
+    -- @since 1.2.3
diff --git a/doc/multi-components.rst b/doc/multi-components.rst
new file mode 100644
--- /dev/null
+++ b/doc/multi-components.rst
@@ -0,0 +1,48 @@
+Haddocks of multiple components
+===============================
+
+Haddock supports building documentation of multiple components.  First, one
+needs to build haddocks of all components which can be done with:
+
+.. code-block:: none
+
+    cabal haddock --haddock-html \
+                  --haddock-quickjump \
+                  --haddock-option="--use-index=../doc-index.html" \
+                  --haddock-option="--use-contents=../index.html" \
+                  --haddock-option="--base-url=.." \
+                  all
+
+The new ``--base-url`` option will allow to access the static files from the
+main directory (in this example its the relative ``./..`` directory).  It will
+also prevent ``haddock`` from copying its static files to each of the
+documentation folders, we're only need a single copy of them where the
+``--base-url`` option points to.
+
+The second step requires to copy all the haddocks to a common directory, let's
+say ``./docs``,  this will depend on your project and it might look like:
+
+.. code-block:: none
+
+    cp -r dist-newstyle/build/x86_64-linux/ghc-9.0.1/package-a-0.1.0.0/doc/html/package-a/ docs
+    cp -r dist-newstyle/build/x86_64-linux/ghc-9.0.1/package-b-0.1.0.0/doc/html/package-b/ docs
+
+Note that you can also include documentation of other packages in this way,
+e.g. ``base``, but you need to know where it is hidden on your hard-drive.
+
+To build html and js (``quickjump``) indexes one can now invoke ``haddock`` with:
+
+.. code-block:: none
+
+    haddock \
+      -o docs \
+      --quickjump --gen-index --gen-contents \
+      --read-interface=package-a,docs/package-a/package-a.haddock \
+      --read-interface=package-b,docs/package-b/package-b.haddock
+
+Note: the ``PATH`` in ``--read-interface=PATH,...`` must be a relative url of
+a package it points to (relative to the ``docs`` directory).
+
+There's an example project which shows how to do that posted `here
+<https://github.com/coot/haddock-example>`_, which haddocks are served on
+`github-pages <https://coot.github.io/haddock-example>`_.
diff --git a/driver/Main.hs b/driver/Main.hs
new file mode 100644
--- /dev/null
+++ b/driver/Main.hs
@@ -0,0 +1,7 @@
+module Main where
+
+import Documentation.Haddock (haddock)
+import GHC.ResponseFile (getArgsWithResponseFiles)
+
+main :: IO ()
+main = getArgsWithResponseFiles >>= haddock
diff --git a/examples/A.hs b/examples/A.hs
deleted file mode 100644
--- a/examples/A.hs
+++ /dev/null
@@ -1,2 +0,0 @@
-module A where
-data A = A
diff --git a/examples/B.hs b/examples/B.hs
deleted file mode 100644
--- a/examples/B.hs
+++ /dev/null
@@ -1,2 +0,0 @@
-module B ( module A ) where
-import A
diff --git a/examples/Bug1.hs b/examples/Bug1.hs
deleted file mode 100644
--- a/examples/Bug1.hs
+++ /dev/null
@@ -1,6 +0,0 @@
-module Bug1 where
-
--- | We should have different anchors for constructors and types\/classes.  This
--- hyperlink should point to the type constructor by default: 'T'.
-data T = T
-
diff --git a/examples/Bug2.hs b/examples/Bug2.hs
deleted file mode 100644
--- a/examples/Bug2.hs
+++ /dev/null
@@ -1,4 +0,0 @@
-module Bug2 ( x ) where
-import B
-x :: A
-x = A
diff --git a/examples/Bug3.hs b/examples/Bug3.hs
deleted file mode 100644
--- a/examples/Bug3.hs
+++ /dev/null
@@ -1,6 +0,0 @@
-module Bug3 where
-
--- | /multi-line
--- emphasis/
-foo :: Int
-
diff --git a/examples/Bug4.hs b/examples/Bug4.hs
deleted file mode 100644
--- a/examples/Bug4.hs
+++ /dev/null
@@ -1,4 +0,0 @@
-module Bug4 where
--- | don't use apostrophe's in the wrong place's
-foo :: Int
-
diff --git a/examples/Bug6.hs b/examples/Bug6.hs
deleted file mode 100644
--- a/examples/Bug6.hs
+++ /dev/null
@@ -1,23 +0,0 @@
--- | Exporting records.
-module Bug6( A(A), B(B), b, C(C,c1,c2), D(D,d1), E(E) ) where
-
--- |
--- This record is exported without its field
-data A = A { a :: Int }
-
--- |
--- .. with its field, but the field is named separately in the export list
--- (should still be visible as a field name)
-data B = B { b :: Int }
-
--- |
--- .. with fields names as subordinate names in the export
-data C = C { c1 :: Int, c2 :: Int }
-
--- |
--- .. with only some of the fields exported (we can't handle this one -
--- how do we render the declaration?)
-data D = D { d1 :: Int, d2 :: Int }
-
--- | a newtype with a field
-newtype E = E { e :: Int }
diff --git a/examples/Bug7.hs b/examples/Bug7.hs
deleted file mode 100644
--- a/examples/Bug7.hs
+++ /dev/null
@@ -1,12 +0,0 @@
--- | This module caused a duplicate instance in the documentation for the Foo
--- type.
-module Bug7  where
-
--- | The Foo datatype
-data Foo = Foo
-
--- | The Bar class
-class Bar x y
-
--- | Just one instance
-instance Bar Foo Foo
diff --git a/examples/Bug8.hs b/examples/Bug8.hs
deleted file mode 100644
--- a/examples/Bug8.hs
+++ /dev/null
@@ -1,8 +0,0 @@
-infix -->
-infix --->
-
-data Typ = Type (String,[Typ])
-         | TFree (String, [String])
-
-x --> y = Type("fun",[s,t])
-(--->) = flip $ foldr (-->)
diff --git a/examples/Bug9.hs b/examples/Bug9.hs
deleted file mode 100644
--- a/examples/Bug9.hs
+++ /dev/null
@@ -1,6 +0,0 @@
--- Haddock 0.6 didn't parse this module, because the qualified
--- identifier C.safe was incorrectly lexed as 3 tokens.
-
-module Check where
-import qualified Foo as C
-check = undefined { C.safe = 3 }
diff --git a/examples/Hash.hs b/examples/Hash.hs
deleted file mode 100644
--- a/examples/Hash.hs
+++ /dev/null
@@ -1,45 +0,0 @@
-{- |
-  Implementation of fixed-size hash tables, with a type 
-  class for constructing hash values for structured types.
--}
-module Hash (
-  -- * The @HashTable@ type
-  HashTable,
-
-  -- ** Operations on @HashTable@s
-  new, insert, lookup,
-
-  -- * The @Hash@ class
-  Hash(..),
- ) where
-
-import Array
-
--- | A hash table with keys of type @key@ and values of type @val@.
--- The type @key@ should be an instance of 'Eq'.
-data HashTable key val = HashTable Int (Array Int [(key,val)])
-
--- | Builds a new hash table with a given size
-new :: (Eq key, Hash key) => Int -> IO (HashTable key val)
-
--- | Inserts a new element into the hash table
-insert :: (Eq key, Hash key) => key -> val -> IO ()
-
--- | Looks up a key in the hash table, returns @'Just' val@ if the key
--- was found, or 'Nothing' otherwise.
-lookup 	:: Hash key => key -> IO (Maybe val)
-
--- | A class of types which can be hashed.
-class Hash a where
-   -- | hashes the value of type @a@ into an 'Int'
-   hash :: a -> Int
-
-instance Hash Int where
-   hash = id
-
-instance Hash Float where
-   hash = trunc
-
-instance (Hash a, Hash b) => Hash (a,b) where
-   hash (a,b) = hash a `xor` hash b
-
diff --git a/examples/Hidden.hs b/examples/Hidden.hs
deleted file mode 100644
--- a/examples/Hidden.hs
+++ /dev/null
@@ -1,4 +0,0 @@
--- #hide
-module Hidden where
-hidden :: Int -> Int
-hidden a = a
diff --git a/examples/Makefile b/examples/Makefile
deleted file mode 100644
--- a/examples/Makefile
+++ /dev/null
@@ -1,11 +0,0 @@
-TOP = ..
-include $(TOP)/mk/boilerplate.mk
-
-all :: index.html
-
-index.html : $(HS_SRCS) $(HADDOCK_INPLACE)
-	$(HADDOCK_INPLACE) -h $(HS_SRCS)
-
-CLEAN_FILES += index.html
-
-include $(TOP)/mk/target.mk
diff --git a/examples/NoLayout.hs b/examples/NoLayout.hs
deleted file mode 100644
--- a/examples/NoLayout.hs
+++ /dev/null
@@ -1,4 +0,0 @@
-module NoLayout where {
-  -- | the class 'C'
-  g :: Int;
- }
diff --git a/examples/Test.hs b/examples/Test.hs
deleted file mode 100644
--- a/examples/Test.hs
+++ /dev/null
@@ -1,410 +0,0 @@
------------------------------------------------------------------------------
--- |
--- Module      :  Test
--- Copyright   :  (c) Simon Marlow 2002
--- License     :  BSD-style
--- 
--- Maintainer  :  libraries@haskell.org
--- Stability   :  provisional
--- Portability :  portable
---
--- This module illustrates & tests most of the features of Haddock.
--- Testing references from the description: 'T', 'f', 'g', 'Visible.visible'.
---
------------------------------------------------------------------------------
-
--- This is plain comment, ignored by Haddock.
-
-module Test ( 
-
-	-- Section headings are introduced with '-- *':
-	-- * Type declarations
-
-	-- Subsection headings are introduced with '-- **' and so on.
-	-- ** Data types
-	T(..), T2, T3(..), T4(..), T5(..), T6(..),
-	N1(..), N2(..), N3(..), N4, N5(..), N6(..), N7(..),
-
-	-- ** Records
-	R(..), R1(..),
-
-	-- | test that we can export record selectors on their own:
-	p, q, u,
-
-	-- * Class declarations
-	C(a,b), D(..), E, F(..),
-	
-	-- | Test that we can export a class method on its own:
-	a,
-
-	-- * Function types
-	f, g,
-
-	-- * Auxiliary stuff
-
-	-- $aux1
-
-	-- $aux2
-
-	-- $aux3
-
-	-- $aux4
-
-	-- $aux5
-
-	-- $aux6
-
-	-- $aux7
-
-	-- $aux8
-
-	-- $aux9
-
-	-- $aux10
-
-	-- $aux11
-
-	-- $aux12
-
-	-- | This is some inline documentation in the export list
-	--
-	-- > a code block using bird-tracks
-	-- > each line must begin with > (which isn't significant unless it
-	-- > is at the beginning of the line).
-
-	-- * A hidden module
-	module Hidden,
-
-	-- * A visible module
-	module Visible,
-
-	{-| nested-style doc comments -}
-
-	-- * Existential \/ Universal types
-	Ex(..),
-
-	-- * Type signatures with argument docs
-	k, l, m, o,
-
-	-- * A section
-	-- and without an intervening comma:
-	-- ** A subsection 
-
-{-|
- > a literal line
-
- $ a non /literal/ line $
--}
-
-	f'
-   ) where
-
-import Hidden
-import Visible
-import Data.Maybe
-
-bla = Nothing
-
--- | This comment applies to the /following/ declaration
--- and it continues until the next non-comment line
-data T a b
- = A Int (Maybe Float) -- ^ This comment describes the 'A' constructor
- | -- | This comment describes the 'B' constructor
-   B (T a b, T Int Float) -- ^ 
-
--- | An abstract data declaration
-data T2 a b = T2 a b
-
--- | A data declaration with no documentation annotations on the constructors
-data T3 a b = A1 a | B1 b
-
--- A data declaration with no documentation annotations at all
-data T4 a b = A2 a | B2 b
-
--- A data declaration documentation on the constructors only
-data T5 a b
-  = A3 a -- ^ documents 'A3'
-  | B3 b -- ^ documents 'B3'
-
--- | Testing alternative comment styles
-data T6
-  -- | This is the doc for 'A4'
-  = A4
-  | B4
-  | -- ^ This is the doc for 'B4'
-
-    -- | This is the doc for 'C4'
-    C4
-
--- | A newtype
-newtype N1 a = N1 a
-
--- | A newtype with a fieldname
-newtype N2 a b = N2 {n :: a b}
-
--- | A newtype with a fieldname, documentation on the field
-newtype N3 a b = N3 {n3 :: a b -- ^ this is the 'n3' field 
-		    }
-
--- | An abstract newtype - we show this one as data rather than newtype because
--- the difference isn\'t visible to the programmer for an abstract type.
-newtype N4 a b = N4 a
-
-newtype N5 a b = N5 {n5 :: a b -- ^ no docs on the datatype or the constructor
-		    }
-
-newtype N6 a b = N6 {n6 :: a b
-		    }
-		 -- ^ docs on the constructor only
-
--- | docs on the newtype and the constructor
-newtype N7 a b = N7 {n7 :: a b
-		    }
-		-- ^ The 'N7' constructor
-		 
-
-class (D a) => C a  where
-   -- |this is a description of the 'a' method
-   a :: IO a
-   b :: [a]
-   -- ^ this is a description of the 'b' method
-   c :: a -- c is hidden in the export list
-
--- ^ This comment applies to the /previous/ declaration (the 'C' class)
-
-class D a where
-   d :: T a b
-   e :: (a,a)
--- ^ This is a class declaration with no separate docs for the methods
-
-instance D Int where
-  d = undefined
-  e = undefined
-
--- instance with a qualified class name
-instance Test.D Float where
-  d = undefined
-  e = undefined
-
-class E a where
-  ee :: a
--- ^ This is a class declaration with no methods (or no methods exported)
-
--- This is a class declaration with no documentation at all
-class F a where
-  ff :: a
-
--- | This is the documentation for the 'R' record, which has four fields,
--- 'p', 'q', 'r', and 's'.
-data R = 
-  -- | This is the 'C1' record constructor, with the following fields:
-  C1 { p :: Int -- ^ This comment applies to the 'p' field
-     , q :: forall a . a->a  -- ^ This comment applies to the 'q' field
-     , -- | This comment applies to both 'r' and 's'
-       r,s :: Int
-     }
-  | C2 { t :: T1 -> (T2 Int Int)-> (T3 Bool Bool) -> (T4 Float Float) -> T5 () (),
-       u,v :: Int
-     }
-  -- ^ This is the 'C2' record constructor, also with some fields:
-
--- | Testing different record commenting styles
-data R1 
-  -- | This is the 'C3' record constructor
-  = C3 { 
-	-- | The 's1' record selector
-	  s1 :: Int
-	-- | The 's2' record selector
-	, s2 :: Int
-	, s3 :: Int  -- NOTE: In the original examples/Test.hs in Haddock, there is an extra "," here.
-                     -- Since GHC doesn't allow that, I have removed it in this file. 
-	-- ^ The 's3' record selector
-     }
-
--- These section headers are only used when there is no export list to
--- give the structure of the documentation:
-
--- * This is a section header (level 1)
--- ** This is a section header (level 2)
--- *** This is a section header (level 3)
-
-{-|
-In a comment string we can refer to identifiers in scope with
-single quotes like this: 'T', and we can refer to modules by
-using double quotes: "Foo".  We can add emphasis /like this/.
-
-   * This is a bulleted list
-
-   - This is the next item (different kind of bullet)
-
-   (1) This is an ordered list
- 
-   2. This is the next item (different kind of bullet)
-
-@
-     This is a block of code, which can include other markup: 'R'
-     formatting
-               is
-                 significant
-@
-
-> this is another block of code
-
-We can also include URLs in documentation: <http://www.haskell.org/>.
--}
-
-f :: C a => a -> Int
-
--- | we can export foreign declarations too
-foreign import ccall g :: Int -> IO CInt
-
--- | this doc string has a parse error in it: \'
-h :: Int
-h = 42
-
-
--- $aux1 This is some documentation that is attached to a name ($aux1)
--- rather than a source declaration.  The documentation may be
--- referred to in the export list using its name.
---
--- @ code block in named doc @
-
--- $aux2 This is some documentation that is attached to a name ($aux2)
-
--- $aux3
--- @ code block on its own in named doc @
-
--- $aux4
---
--- @ code block on its own in named doc (after newline) @
-
-{- $aux5 a nested, named doc comment
-
-   with a paragraph,
-
-   @ and a code block @
--}
-
--- some tests for various arrangements of code blocks:
-
-{- $aux6
->test
->test1
-
-@ test2
-  test3
-@
--}
-
-{- $aux7
-@
-test1
-test2
-@
--}
-
-{- $aux8
->test3
->test4
--}
-
-{- $aux9
-@
-test1
-test2
-@
-
->test3
->test4
--}
-
-{- $aux10
->test3
->test4
-
-@
-test1
-test2
-@
--}
-
--- This one is currently wrong (Haddock 0.4).  The @...@ part is
--- interpreted as part of the bird-tracked code block.
-{- $aux11
-aux11:
-
->test3
->test4
-
-@
-test1
-test2
-@
--}
-
--- $aux12
--- > foo
--- 
--- > bar
--- 
-
--- | A data-type using existential\/universal types
-data Ex a 
-  = forall b . C b => Ex1 b
-  | forall b . Ex2 b
-  | forall b . C a => Ex3 b -- NOTE: I have added "forall b" here make GHC accept this file 
-  | Ex4 (forall a . a -> a)
-
--- | This is a function with documentation for each argument
-k :: T () () 	  -- ^ This argument has type 'T'
-  -> (T2 Int Int) -- ^ This argument has type 'T2 Int Int'
-  -> (T3 Bool Bool -> T4 Float Float) -- ^ This argument has type @T3 Bool Bool -> T4 Float Float@
-  -> T5 () ()	  -- ^ This argument has a very long description that should
-		  -- hopefully cause some wrapping to happen when it is finally
-		  -- rendered by Haddock in the generated HTML page.
-  -> IO ()	  -- ^ This is the result type
-
--- This function has arg docs but no docs for the function itself
-l :: (Int, Int, Float) -- ^ takes a triple
-  -> Int -- ^ returns an 'Int'
-
--- | This function has some arg docs 
-m :: R
-  -> N1 ()	-- ^ one of the arguments
-  -> IO Int	-- ^ and the return value
-
--- | This function has some arg docs but not a return value doc
-
--- can't use the original name ('n') with GHC
-newn :: R		-- ^ one of the arguments, an 'R'
-     -> N1 ()		-- ^ one of the arguments
-     -> IO Int
-newn = undefined 
-
-
--- | A foreign import with argument docs
-foreign import ccall unsafe 
- o :: Float  -- ^ The input float
-   -> IO Float  -- ^ The output float
-
--- | We should be able to escape this: \#\#\#
-
--- p :: Int 
--- can't use the above original definition with GHC
-newp :: Int  
-newp = undefined
-
--- | a function with a prime can be referred to as 'f'' 
--- but f' doesn't get link'd 'f\''
-f' :: Int
-
-
--- Add some definitions here so that this file can be compiled with GHC
-
-data T1
-f = undefined
-f' = undefined
-type CInt = Int  
-k = undefined
-l = undefined
-m = undefined
diff --git a/examples/Visible.hs b/examples/Visible.hs
deleted file mode 100644
--- a/examples/Visible.hs
+++ /dev/null
@@ -1,3 +0,0 @@
-module Visible where
-visible :: Int -> Int
-visible a = a
diff --git a/examples/hide-bug/A.hs b/examples/hide-bug/A.hs
deleted file mode 100644
--- a/examples/hide-bug/A.hs
+++ /dev/null
@@ -1,2 +0,0 @@
--- #hide
-module A where { data T = MkT; f :: T; f = MkT }
diff --git a/examples/hide-bug/B.hs b/examples/hide-bug/B.hs
deleted file mode 100644
--- a/examples/hide-bug/B.hs
+++ /dev/null
@@ -1,5 +0,0 @@
-module B(Test, vis) where 
-
-vis = id
-
-data Test = Test
diff --git a/examples/hide-bug/C.hs b/examples/hide-bug/C.hs
deleted file mode 100644
--- a/examples/hide-bug/C.hs
+++ /dev/null
@@ -1,6 +0,0 @@
-module C(C.bla) where 
-
-import D
-
-bla :: Test
-bla = undefined
diff --git a/examples/hide-bug/D.hs b/examples/hide-bug/D.hs
deleted file mode 100644
--- a/examples/hide-bug/D.hs
+++ /dev/null
@@ -1,7 +0,0 @@
--- The link to the type T in the doc for this module should point to 
--- B.T, not A.T.  Bug fixed in rev 1.59 of Main.hs.
-module D(Test, hej) where 
-
-import B
-
-hej = vis
diff --git a/haddock-api/src/Documentation/Haddock.hs b/haddock-api/src/Documentation/Haddock.hs
new file mode 100644
--- /dev/null
+++ b/haddock-api/src/Documentation/Haddock.hs
@@ -0,0 +1,89 @@
+-----------------------------------------------------------------------------
+-- |
+-- Module      :  Documentation.Haddock
+-- Copyright   :  (c) David Waern 2010
+-- License     :  BSD-like
+--
+-- Maintainer  :  haddock@projects.haskellorg
+-- Stability   :  experimental
+-- Portability :  portable
+--
+-- The Haddock API: A rudimentary, highly experimental API exposing some of
+-- the internals of Haddock. Don't expect it to be stable.
+-----------------------------------------------------------------------------
+module Documentation.Haddock (
+
+  -- * Interface
+  Interface(..),
+  InstalledInterface(..),
+  toInstalledIface,
+  createInterfaces,
+  processModules,
+
+  -- * Export items & declarations
+  ExportItem(..),
+  DocForDecl,
+  FnArgsDoc,
+
+  -- * Cross-referencing
+  LinkEnv,
+  DocName(..),
+
+  -- * Instances
+  DocInstance,
+  InstHead,
+
+  -- * Documentation comments
+  Doc,
+  MDoc,
+  DocH(..),
+  Example(..),
+  Hyperlink(..),
+  DocMarkup,
+  DocMarkupH(..),
+  Documentation(..),
+  ArgMap,
+  AliasMap,
+  WarningMap,
+  DocMap,
+  HaddockModInfo(..),
+  markup,
+
+  -- * Interface files
+  InterfaceFile(..),
+  readInterfaceFile,
+  freshNameCache,
+
+  -- * Flags and options
+  Flag(..),
+  DocOption(..),
+
+  -- * Error handling
+  HaddockException(..),
+
+  -- * Program entry point
+  haddock,
+  haddockWithGhc,
+  getGhcDirs,
+  withGhc
+) where
+
+import Documentation.Haddock.Markup (markup)
+import Haddock.InterfaceFile
+import Haddock.Interface
+import Haddock.Types
+import Haddock.Options
+import Haddock
+
+
+-- | Create 'Interface' structures from a given list of Haddock command-line
+-- flags and file or module names (as accepted by 'haddock' executable).  Flags
+-- that control documentation generation or show help or version information
+-- are ignored.
+createInterfaces
+  :: [Flag]         -- ^ A list of command-line flags
+  -> [String]       -- ^ File or module names
+  -> IO [Interface] -- ^ Resulting list of interfaces
+createInterfaces flags modules = do
+  (_, ifaces, _) <- withGhc flags (readPackagesAndProcessModules flags modules)
+  return ifaces
diff --git a/haddock-api/src/Haddock.hs b/haddock-api/src/Haddock.hs
new file mode 100644
--- /dev/null
+++ b/haddock-api/src/Haddock.hs
@@ -0,0 +1,799 @@
+{-# LANGUAGE BangPatterns        #-}
+{-# LANGUAGE CPP                 #-}
+{-# LANGUAGE LambdaCase          #-}
+{-# LANGUAGE NamedFieldPuns      #-}
+{-# LANGUAGE OverloadedStrings   #-}
+{-# LANGUAGE Rank2Types          #-}
+{-# LANGUAGE ScopedTypeVariables #-}
+{-# LANGUAGE TupleSections       #-}
+{-# OPTIONS_GHC -Wwarn           #-}
+-----------------------------------------------------------------------------
+-- |
+-- Module      :  Haddock
+-- Copyright   :  (c) Simon Marlow 2003-2006,
+--                    David Waern  2006-2010,
+--                    Mateusz Kowalczyk 2014
+-- License     :  BSD-like
+--
+-- Maintainer  :  haddock@projects.haskell.org
+-- Stability   :  experimental
+-- Portability :  portable
+--
+-- Haddock - A Haskell Documentation Tool
+--
+-- Program entry point and top-level code.
+-----------------------------------------------------------------------------
+module Haddock (
+  haddock,
+  haddockWithGhc,
+  getGhcDirs,
+  readPackagesAndProcessModules,
+  withGhc
+) where
+
+import Haddock.Backends.Xhtml
+import Haddock.Backends.Xhtml.Meta
+import Haddock.Backends.Xhtml.Themes (getThemes)
+import Haddock.Backends.LaTeX
+import Haddock.Backends.Hoogle
+import Haddock.Backends.Hyperlinker
+import Haddock.Interface
+import Haddock.Interface.Json
+import Haddock.Parser
+import Haddock.Types
+import Haddock.Version
+import Haddock.InterfaceFile
+import Haddock.Options
+import Haddock.Utils
+import Haddock.GhcUtils (modifySessionDynFlags, setOutputDir)
+
+import Control.DeepSeq (force)
+import Control.Monad hiding (forM_)
+import Control.Monad.IO.Class (MonadIO(..))
+import Data.Bifunctor (second)
+import Data.Foldable (forM_, foldl')
+import Data.Traversable (for)
+import Data.List (find, isPrefixOf, nub)
+import Control.Exception
+import Data.Maybe
+import Data.IORef
+import Data.Map.Strict (Map)
+import Data.Version (makeVersion)
+import qualified Data.Map.Strict as Map
+import System.IO
+import System.Exit
+import System.FilePath
+
+#ifdef IN_GHC_TREE
+import System.Environment (getExecutablePath)
+#else
+import qualified GHC.Paths as GhcPaths
+import Paths_haddock_api (getDataDir)
+#endif
+import System.Directory (doesDirectoryExist, getTemporaryDirectory)
+
+import Text.ParserCombinators.ReadP (readP_to_S)
+import GHC hiding (verbosity)
+import GHC.Settings.Config
+import GHC.Driver.Config.Logger (initLogFlags)
+import GHC.Driver.Env
+import GHC.Driver.Session hiding (projectVersion, verbosity)
+import GHC.Utils.Error
+import GHC.Utils.Logger
+import GHC.Types.Name.Cache
+import GHC.Unit
+import GHC.Utils.Panic (handleGhcException)
+import GHC.Data.FastString
+
+--------------------------------------------------------------------------------
+-- * Exception handling
+--------------------------------------------------------------------------------
+
+
+handleTopExceptions :: IO a -> IO a
+handleTopExceptions =
+  handleNormalExceptions . handleHaddockExceptions . handleGhcExceptions
+
+
+-- | Either returns normally or throws an ExitCode exception;
+-- all other exceptions are turned into exit exceptions.
+handleNormalExceptions :: IO a -> IO a
+handleNormalExceptions inner =
+  (inner `onException` hFlush stdout)
+  `catches`
+  [  Handler (\(code :: ExitCode) -> exitWith code)
+
+  ,  Handler (\(ex :: AsyncException) ->
+       case ex of
+         StackOverflow -> do
+           putStrLn "stack overflow: use -g +RTS -K<size> to increase it"
+           exitFailure
+         _ -> do
+           putStrLn ("haddock: " ++ show ex)
+           exitFailure)
+
+  ,  Handler (\(ex :: SomeException) -> do
+        putStrLn ("haddock: internal error: " ++ show ex)
+        exitFailure)
+  ]
+
+
+handleHaddockExceptions :: IO a -> IO a
+handleHaddockExceptions inner =
+  catches inner [Handler handler]
+  where
+    handler (e::HaddockException) = do
+      putStrLn $ "haddock: " ++ show e
+      exitFailure
+
+
+handleGhcExceptions :: IO a -> IO a
+handleGhcExceptions =
+  -- error messages propagated as exceptions
+  handleGhcException $ \e -> do
+    hFlush stdout
+    print (e :: GhcException)
+    exitFailure
+
+
+-------------------------------------------------------------------------------
+-- * Top level
+-------------------------------------------------------------------------------
+
+
+-- | Run Haddock with given list of arguments.
+--
+-- Haddock's own main function is defined in terms of this:
+--
+-- > main = getArgs >>= haddock
+haddock :: [String] -> IO ()
+haddock args = haddockWithGhc withGhc args
+
+haddockWithGhc :: (forall a. [Flag] -> Ghc a -> IO a) -> [String] -> IO ()
+haddockWithGhc ghc args = handleTopExceptions $ do
+
+  -- Parse command-line flags and handle some of them initially.
+  -- TODO: unify all of this (and some of what's in the 'render' function),
+  -- into one function that returns a record with a field for each option,
+  -- or which exits with an error or help message.
+  (flags, files) <- parseHaddockOpts args
+  shortcutFlags flags
+  qual <- rightOrThrowE (qualification flags)
+  sinceQual <- rightOrThrowE (sinceQualification flags)
+
+  -- Inject dynamic-too into ghc options if the ghc we are using was built with
+  -- dynamic linking
+  flags'' <- ghc flags $ do
+        df <- getDynFlags
+        case lookup "GHC Dynamic" (compilerInfo df) of
+          Just "YES" -> return $ Flag_OptGhc "-dynamic-too" : flags
+          _ -> return flags
+
+  -- Inject `-j` into ghc options, if given to Haddock
+  flags' <- pure $ case optParCount flags'' of
+    Nothing       -> flags''
+    Just Nothing  -> Flag_OptGhc "-j" : flags''
+    Just (Just n) -> Flag_OptGhc ("-j" ++ show n) : flags''
+
+  -- Whether or not to bypass the interface version check
+  let noChecks = Flag_BypassInterfaceVersonCheck `elem` flags
+
+  -- Create a temporary directory and redirect GHC output there (unless user
+  -- requested otherwise).
+  --
+  -- Output dir needs to be set before calling 'depanal' since 'depanal' uses it
+  -- to compute output file names that are stored in the 'DynFlags' of the
+  -- resulting 'ModSummary's.
+  let withDir | Flag_NoTmpCompDir `elem` flags = id
+              | otherwise = withTempOutputDir
+
+  -- Output warnings about potential misuse of some flags
+  unless (Flag_NoWarnings `elem` flags) $ do
+    hypSrcWarnings flags
+    mapM_ (hPutStrLn stderr) (optGhcWarnings args)
+    when noChecks $
+      hPutStrLn stderr noCheckWarning
+
+  ghc flags' $ withDir $ do
+    dflags <- getDynFlags
+    logger <- getLogger
+    !unit_state <- hsc_units <$> getSession
+
+    -- If any --show-interface was used, show the given interfaces
+    forM_ (optShowInterfaceFile flags) $ \path -> liftIO $ do
+      name_cache <- freshNameCache
+      mIfaceFile <- readInterfaceFiles name_cache [(("", Nothing), Visible, path)] noChecks
+      forM_ mIfaceFile $ \(_,_,_, ifaceFile) -> do
+        putMsg logger $ renderJson (jsonInterfaceFile ifaceFile)
+
+    -- If we were given source files to generate documentation from, do it
+    if not (null files) then do
+      (packages, ifaces, homeLinks) <- readPackagesAndProcessModules flags files
+      let packageInfo = PackageInfo { piPackageName =
+                                        fromMaybe (PackageName mempty) (optPackageName flags)
+                                    , piPackageVersion =
+                                        fromMaybe (makeVersion []) (optPackageVersion flags)
+                                    }
+
+      -- Dump an "interface file" (.haddock file), if requested.
+      forM_ (optDumpInterfaceFile flags) $ \path -> liftIO $ do
+        writeInterfaceFile path InterfaceFile {
+            ifInstalledIfaces = map toInstalledIface ifaces
+          , ifPackageInfo     = packageInfo
+          , ifLinkEnv         = homeLinks
+          }
+
+      -- Render the interfaces.
+      liftIO $ renderStep logger dflags unit_state flags sinceQual qual packages ifaces
+
+    -- If we were not given any input files, error if documentation was
+    -- requested
+    else do
+      when (any (`elem` [Flag_Html, Flag_Hoogle, Flag_LaTeX]) flags) $
+        throwE "No input file(s)."
+
+      -- Get packages supplied with --read-interface.
+      name_cache <- liftIO $ freshNameCache
+      packages <- liftIO $ readInterfaceFiles name_cache (readIfaceArgs flags) noChecks
+
+      -- Render even though there are no input files (usually contents/index).
+      liftIO $ renderStep logger dflags unit_state flags sinceQual qual packages []
+
+-- | Run the GHC action using a temporary output directory
+withTempOutputDir :: Ghc a -> Ghc a
+withTempOutputDir action = do
+  tmp <- liftIO getTemporaryDirectory
+  x   <- liftIO getProcessID
+  let dir = tmp </> ".haddock-" ++ show x
+  modifySessionDynFlags (setOutputDir dir)
+  withTempDir dir action
+
+-- | Create warnings about potential misuse of -optghc
+optGhcWarnings :: [String] -> [String]
+optGhcWarnings = map format . filter (isPrefixOf "-optghc")
+  where
+    format arg = concat ["Warning: `", arg, "' means `-o ", drop 2 arg, "', did you mean `-", arg, "'?"]
+
+-- | Create a warning about bypassing the interface version check
+noCheckWarning :: String
+noCheckWarning = "Warning: `--bypass-interface-version-check' can cause " ++
+                 "Haddock to crash when reading Haddock interface files."
+
+withGhc :: [Flag] -> Ghc a -> IO a
+withGhc flags action = do
+  libDir <- fmap (fromMaybe (error "No GhcDir found") . snd) (getGhcDirs flags)
+
+  -- Catches all GHC source errors, then prints and re-throws them.
+  let handleSrcErrors action' = flip handleSourceError action' $ \err -> do
+        printException err
+        liftIO exitFailure
+      needHieFiles = Flag_HyperlinkedSource `elem` flags
+
+  withGhc' libDir needHieFiles (ghcFlags flags) (\_ -> handleSrcErrors action)
+
+
+readPackagesAndProcessModules :: [Flag] -> [String]
+                              -> Ghc ([(DocPaths, Visibility, FilePath, InterfaceFile)], [Interface], LinkEnv)
+readPackagesAndProcessModules flags files = do
+    -- Whether or not we bypass the interface file version check
+    let noChecks = Flag_BypassInterfaceVersonCheck `elem` flags
+
+    -- Read package dependency interface files supplied with --read-interface
+    name_cache <- hsc_NC <$> getSession
+    packages <- liftIO $ readInterfaceFiles name_cache (readIfaceArgs flags) noChecks
+
+    -- Create the interfaces for the given modules -- this is the core part of Haddock
+    let ifaceFiles = map (\(_, _, _, ifaceFile) -> ifaceFile) packages
+    (ifaces, homeLinks) <- processModules (verbosity flags) files flags ifaceFiles
+
+    return (packages, ifaces, homeLinks)
+
+
+renderStep :: Logger -> DynFlags -> UnitState -> [Flag] -> SinceQual -> QualOption
+           -> [(DocPaths, Visibility, FilePath, InterfaceFile)] -> [Interface] -> IO ()
+renderStep logger dflags unit_state flags sinceQual nameQual pkgs interfaces = do
+  updateHTMLXRefs (map (\(docPath, _ifaceFilePath, _showModules, ifaceFile) ->
+                          ( case baseUrl flags of
+                              Nothing  -> fst docPath
+                              Just url -> url </> packageName (ifUnitId ifaceFile)
+                          , ifaceFile)) pkgs)
+  let
+    installedIfaces =
+      map
+        (\(_, showModules, ifaceFilePath, ifaceFile)
+          -> (ifaceFilePath, mkPackageInterfaces showModules ifaceFile))
+        pkgs
+    extSrcMap = Map.fromList $ do
+      ((_, Just path), _, _, ifile) <- pkgs
+      iface <- ifInstalledIfaces ifile
+      return (instMod iface, path)
+  render logger dflags unit_state flags sinceQual nameQual interfaces installedIfaces extSrcMap
+  where
+    -- get package name from unit-id
+    packageName :: Unit -> String
+    packageName unit =
+      case lookupUnit unit_state unit of
+        Nothing  -> show unit
+        Just pkg -> unitPackageNameString pkg
+
+-- | Render the interfaces with whatever backend is specified in the flags.
+render :: Logger -> DynFlags -> UnitState -> [Flag] -> SinceQual -> QualOption -> [Interface]
+       -> [(FilePath, PackageInterfaces)] -> Map Module FilePath -> IO ()
+render log' dflags unit_state flags sinceQual qual ifaces packages extSrcMap = do
+
+  let
+    packageInfo = PackageInfo { piPackageName    = fromMaybe (PackageName mempty)
+                                                 $ optPackageName flags
+                              , piPackageVersion = fromMaybe (makeVersion [])
+                                                 $ optPackageVersion flags
+                              }
+
+    title                = fromMaybe "" (optTitle flags)
+    unicode              = Flag_UseUnicode `elem` flags
+    pretty               = Flag_PrettyHtml `elem` flags
+    opt_wiki_urls        = wikiUrls          flags
+    opt_base_url         = baseUrl           flags
+    opt_contents_url     = optContentsUrl    flags
+    opt_index_url        = optIndexUrl       flags
+    odir                 = outputDir         flags
+    opt_latex_style      = optLaTeXStyle     flags
+    opt_source_css       = optSourceCssFile  flags
+    opt_mathjax          = optMathjax        flags
+    dflags'
+      | unicode          = gopt_set dflags Opt_PrintUnicodeSyntax
+      | otherwise        = dflags
+    logger               = setLogFlags log' (initLogFlags dflags')
+
+    visibleIfaces    = [ i | i <- ifaces, OptHide `notElem` ifaceOptions i ]
+
+    -- /All/ interfaces including external package modules, grouped by
+    -- interface file (package).
+    allPackages      :: [PackageInterfaces]
+    allPackages      = [PackageInterfaces
+                         { piPackageInfo = packageInfo
+                         , piVisibility  = Visible
+                         , piInstalledInterfaces  = map toInstalledIface ifaces
+                         }]
+                    ++ map snd packages
+
+    -- /All/ visible interfaces including external package modules, grouped by
+    -- interface file (package).
+    allVisiblePackages :: [PackageInterfaces]
+    allVisiblePackages = [ pinfo { piInstalledInterfaces =
+                                     filter (\i -> OptHide `notElem` instOptions i)
+                                            piInstalledInterfaces
+                                 }
+                         | pinfo@PackageInterfaces
+                             { piVisibility = Visible
+                             , piInstalledInterfaces
+                             } <- allPackages
+                         ]
+
+    -- /All/ installed interfaces.
+    allInstalledIfaces :: [InstalledInterface]
+    allInstalledIfaces = concatMap (piInstalledInterfaces . snd) packages
+
+    pkgMod           = fmap ifaceMod (listToMaybe ifaces)
+    pkgKey           = fmap moduleUnit pkgMod
+    pkgStr           = fmap unitString pkgKey
+    pkgNameVer       = modulePackageInfo unit_state flags pkgMod
+    pkgName          = fmap (unpackFS . (\(PackageName n) -> n)) (fst pkgNameVer)
+    sincePkg         = case sinceQual of
+                         External -> pkgName
+                         Always -> Nothing
+
+    (srcBase, srcModule, srcEntity, srcLEntity) = sourceUrls flags
+
+    srcModule'
+      | Flag_HyperlinkedSource `elem` flags = Just hypSrcModuleUrlFormat
+      | otherwise = srcModule
+
+    srcMap = Map.union
+      (Map.map SrcExternal extSrcMap)
+      (Map.fromList [ (ifaceMod iface, SrcLocal) | iface <- ifaces ])
+
+    pkgSrcMap = Map.mapKeys moduleUnit extSrcMap
+    pkgSrcMap'
+      | Flag_HyperlinkedSource `elem` flags
+      , Just k <- pkgKey
+      = Map.insert k hypSrcModuleNameUrlFormat pkgSrcMap
+      | Just srcNameUrl <- srcEntity
+      , Just k <- pkgKey
+      = Map.insert k srcNameUrl pkgSrcMap
+      | otherwise = pkgSrcMap
+
+    -- TODO: Get these from the interface files as with srcMap
+    pkgSrcLMap'
+      | Flag_HyperlinkedSource `elem` flags
+      , Just k <- pkgKey
+      = Map.singleton k hypSrcModuleLineUrlFormat
+      | Just path <- srcLEntity
+      , Just k <- pkgKey
+      = Map.singleton k path
+      | otherwise = Map.empty
+
+    sourceUrls' = (srcBase, srcModule', pkgSrcMap', pkgSrcLMap')
+
+    installedMap :: Map Module InstalledInterface
+    installedMap = Map.fromList [ (unwire (instMod iface), iface) | iface <- allInstalledIfaces ]
+
+    -- The user gives use base-4.9.0.0, but the InstalledInterface
+    -- records the *wired in* identity base.  So untranslate it
+    -- so that we can service the request.
+    unwire :: Module -> Module
+    unwire m = m { moduleUnit = unwireUnit unit_state (moduleUnit m) }
+
+  reexportedIfaces <- concat `fmap` (for (reexportFlags flags) $ \mod_str -> do
+    let warn' = hPutStrLn stderr . ("Warning: " ++)
+    case readP_to_S parseHoleyModule mod_str of
+      [(m, "")]
+        | Just iface <- Map.lookup m installedMap
+        -> return [iface]
+        | otherwise
+        -> warn' ("Cannot find reexported module '" ++ mod_str ++ "'") >> return []
+      _ -> warn' ("Cannot parse reexported module flag '" ++ mod_str ++ "'") >> return [])
+
+  libDir   <- getHaddockLibDir flags
+  !prologue <- force <$> getPrologue dflags' flags
+  themes   <- getThemes libDir flags >>= either bye return
+
+  let withQuickjump = Flag_QuickJumpIndex `elem` flags
+      withBaseURL = isJust
+                  . find (\flag -> case flag of
+                           Flag_BaseURL base_url ->
+                             base_url /= "." && base_url /= "./"
+                           _ -> False
+                         )
+                  $ flags
+
+  when (Flag_GenIndex `elem` flags) $ do
+    withTiming logger "ppHtmlIndex" (const ()) $ do
+      _ <- {-# SCC ppHtmlIndex #-}
+           ppHtmlIndex odir title pkgStr
+                  themes opt_mathjax opt_contents_url sourceUrls' opt_wiki_urls
+                  withQuickjump
+                  (concatMap piInstalledInterfaces allVisiblePackages) pretty
+      return ()
+
+    unless withBaseURL $
+      copyHtmlBits odir libDir themes withQuickjump
+
+  when (Flag_GenContents `elem` flags) $ do
+    withTiming logger "ppHtmlContents" (const ()) $ do
+      _ <- {-# SCC ppHtmlContents #-}
+           ppHtmlContents unit_state odir title pkgStr
+                     themes opt_mathjax opt_index_url sourceUrls' opt_wiki_urls
+                     withQuickjump
+                     allVisiblePackages True prologue pretty
+                     sincePkg (makeContentsQual qual)
+      return ()
+    copyHtmlBits odir libDir themes withQuickjump
+
+  when withQuickjump $ void $
+            ppJsonIndex odir sourceUrls' opt_wiki_urls
+                        unicode Nothing qual
+                        ifaces
+                        ( nub
+                        . map fst
+                        . filter ((== Visible) . piVisibility . snd)
+                        $ packages)
+
+  when (Flag_Html `elem` flags) $ do
+    withTiming logger "ppHtml" (const ()) $ do
+      _ <- {-# SCC ppHtml #-}
+           ppHtml unit_state title pkgStr visibleIfaces reexportedIfaces odir
+                  prologue
+                  themes opt_mathjax sourceUrls' opt_wiki_urls opt_base_url
+                  opt_contents_url opt_index_url unicode sincePkg packageInfo
+                  qual pretty withQuickjump
+      return ()
+    unless withBaseURL $ do
+      copyHtmlBits odir libDir themes withQuickjump
+      writeHaddockMeta odir withQuickjump
+
+  -- TODO: we throw away Meta for both Hoogle and LaTeX right now,
+  -- might want to fix that if/when these two get some work on them
+  when (Flag_Hoogle `elem` flags) $ do
+    case pkgNameVer of
+      (Just (PackageName pkgNameFS), mpkgVer) ->
+          let
+            pkgNameStr | unpackFS pkgNameFS == "main" && title /= [] = title
+                       | otherwise = unpackFS pkgNameFS
+
+            pkgVer =
+              fromMaybe (makeVersion []) mpkgVer
+          in ppHoogle dflags' pkgNameStr pkgVer title (fmap _doc prologue)
+               visibleIfaces odir
+      _ -> putStrLn . unlines $
+          [ "haddock: Unable to find a package providing module "
+            ++ maybe "<no-mod>" (moduleNameString . moduleName) pkgMod
+            ++ ", skipping Hoogle."
+          , ""
+          , "         Perhaps try specifying the desired package explicitly"
+            ++ " using the --package-name"
+          , "         and --package-version arguments."
+          ]
+
+  when (Flag_LaTeX `elem` flags) $ do
+    withTiming logger "ppLatex" (const ()) $ do
+      _ <- {-# SCC ppLatex #-}
+           ppLaTeX title pkgStr visibleIfaces odir (fmap _doc prologue) opt_latex_style
+                   libDir
+      return ()
+
+  when (Flag_HyperlinkedSource `elem` flags && not (null ifaces)) $ do
+    withTiming logger "ppHyperlinkedSource" (const ()) $ do
+      _ <- {-# SCC ppHyperlinkedSource #-}
+           ppHyperlinkedSource (verbosity flags) odir libDir opt_source_css pretty srcMap ifaces
+      return ()
+
+
+-------------------------------------------------------------------------------
+-- * Reading and dumping interface files
+-------------------------------------------------------------------------------
+
+
+readInterfaceFiles :: NameCache
+                   -> [(DocPaths, Visibility, FilePath)]
+                   -> Bool
+                   -> IO [(DocPaths, Visibility, FilePath, InterfaceFile)]
+readInterfaceFiles name_cache_accessor pairs bypass_version_check = do
+  catMaybes `liftM` mapM ({-# SCC readInterfaceFile #-} tryReadIface) pairs
+  where
+    -- try to read an interface, warn if we can't
+    tryReadIface (paths, vis, file) =
+      readInterfaceFile name_cache_accessor file bypass_version_check >>= \case
+        Left err -> do
+          putStrLn ("Warning: Cannot read " ++ file ++ ":")
+          putStrLn ("   " ++ err)
+          putStrLn "Skipping this interface."
+          return Nothing
+        Right f -> return (Just (paths, vis, file, f))
+
+
+-------------------------------------------------------------------------------
+-- * Creating a GHC session
+-------------------------------------------------------------------------------
+
+
+-- | Start a GHC session with the -haddock flag set. Also turn off
+-- compilation and linking. Then run the given 'Ghc' action.
+withGhc' :: String -> Bool -> [String] -> (DynFlags -> Ghc a) -> IO a
+withGhc' libDir needHieFiles flags ghcActs = runGhc (Just libDir) $ do
+    logger <- getLogger
+    dynflags' <- parseGhcFlags logger =<< getSessionDynFlags
+
+    -- We disable pattern match warnings because than can be very
+    -- expensive to check
+    let dynflags'' = unsetPatternMatchWarnings $ updOptLevel 0 dynflags'
+
+    -- ignore the following return-value, which is a list of packages
+    -- that may need to be re-linked: Haddock doesn't do any
+    -- dynamic or static linking at all!
+    _ <- setSessionDynFlags dynflags''
+    ghcActs dynflags''
+  where
+    -- ignore sublists of flags that start with "+RTS" and end in "-RTS"
+    --
+    -- See https://github.com/haskell/haddock/issues/666
+    filterRtsFlags :: [String] -> [String]
+    filterRtsFlags flgs = foldr go (const []) flgs True
+      where go "-RTS" func _ = func True
+            go "+RTS" func _ = func False
+            go _      func False = func False
+            go arg    func True = arg : func True
+
+    parseGhcFlags :: MonadIO m => Logger -> DynFlags -> m DynFlags
+    parseGhcFlags logger dynflags = do
+      -- TODO: handle warnings?
+
+      let extra_opts | needHieFiles = [Opt_WriteHie, Opt_Haddock]
+                     | otherwise = [Opt_Haddock]
+          dynflags' = (foldl' gopt_set dynflags extra_opts)
+                        { backend = noBackend
+                        , ghcMode = CompManager
+                        , ghcLink = NoLink
+                        }
+          flags' = filterRtsFlags flags
+
+      (dynflags'', rest, _) <- parseDynamicFlags logger dynflags' (map noLoc flags')
+      if not (null rest)
+        then throwE ("Couldn't parse GHC options: " ++ unwords flags')
+        else return dynflags''
+
+unsetPatternMatchWarnings :: DynFlags -> DynFlags
+unsetPatternMatchWarnings dflags =
+  foldl' wopt_unset dflags pattern_match_warnings
+  where
+    pattern_match_warnings =
+      [ Opt_WarnIncompletePatterns
+      , Opt_WarnIncompleteUniPatterns
+      , Opt_WarnIncompletePatternsRecUpd
+      , Opt_WarnOverlappingPatterns
+      ]
+
+-------------------------------------------------------------------------------
+-- * Misc
+-------------------------------------------------------------------------------
+
+
+getHaddockLibDir :: [Flag] -> IO FilePath
+getHaddockLibDir flags =
+  case [str | Flag_Lib str <- flags] of
+    [] -> do
+#ifdef IN_GHC_TREE
+
+      -- When in the GHC tree, we should be able to locate the "lib" folder
+      -- based on the location of the current executable.
+      base_dir <- getBaseDir      -- Provided by GHC
+      let res_dirs = [ d | Just d <- [base_dir] ] ++
+
+#else
+
+      -- When Haddock was installed by @cabal@, the resources (which are listed
+      -- under @data-files@ in the Cabal file) will have been copied to a
+      -- special directory.
+      data_dir <- getDataDir      -- Provided by Cabal
+      let res_dirs = [ data_dir ] ++
+
+#endif
+
+      -- When Haddock is built locally (eg. regular @cabal new-build@), the data
+      -- directory does not exist and we are probably invoking from either
+      -- @./haddock-api@ or @./@
+                     [ "resources"
+                     , "haddock-api/resources"
+                     ]
+
+      res_dir <- check res_dirs
+      case res_dir of
+        Just p -> return p
+        _      -> die "Haddock's resource directory does not exist!\n"
+
+    fs -> return (last fs)
+  where
+    -- Pick the first path that corresponds to a directory that exists
+    check :: [FilePath] -> IO (Maybe FilePath)
+    check [] = pure Nothing
+    check (path : other_paths) = do
+      exists <- doesDirectoryExist path
+      if exists then pure (Just path) else check other_paths
+
+-- | Find the @lib@ directory for GHC and the path to @ghc@
+getGhcDirs :: [Flag] -> IO (Maybe FilePath, Maybe FilePath)
+getGhcDirs flags = do
+
+#ifdef IN_GHC_TREE
+  base_dir <- getBaseDir
+  let ghc_path = Nothing
+#else
+  let base_dir = Just GhcPaths.libdir
+      ghc_path = Just GhcPaths.ghc
+#endif
+
+  -- If the user explicitly specifies a lib dir, use that
+  let ghc_dir = case [ dir | Flag_GhcLibDir dir <- flags ] of
+                  [] -> base_dir
+                  xs -> Just (last xs)
+
+  pure (ghc_path, ghc_dir)
+
+
+#ifdef IN_GHC_TREE
+
+-- | See 'getBaseDir' in "SysTools.BaseDir"
+getBaseDir :: IO (Maybe FilePath)
+getBaseDir = do
+
+  -- Getting executable path can fail. Turn that into 'Nothing'
+  exec_path_opt <- catch (Just <$> getExecutablePath)
+                         (\(_ :: SomeException) -> pure Nothing)
+
+  -- Check that the path we are about to return actually exists
+  case exec_path_opt of
+    Nothing -> pure Nothing
+    Just exec_path -> do
+      let base_dir = takeDirectory (takeDirectory exec_path) </> "lib"
+      exists <- doesDirectoryExist base_dir
+      pure (if exists then Just base_dir else Nothing)
+
+#endif
+
+shortcutFlags :: [Flag] -> IO ()
+shortcutFlags flags = do
+  usage <- getUsage
+
+  when (Flag_Help             `elem` flags) (bye usage)
+  when (Flag_Version          `elem` flags) byeVersion
+  when (Flag_InterfaceVersion `elem` flags) (bye (show binaryInterfaceVersion ++ "\n"))
+  when (Flag_CompatibleInterfaceVersions `elem` flags)
+    (bye (unwords (map show binaryInterfaceVersionCompatibility) ++ "\n"))
+  when (Flag_GhcVersion       `elem` flags) (bye (cProjectVersion ++ "\n"))
+
+  when (Flag_PrintGhcPath `elem` flags) $ do
+    path <- fmap fst (getGhcDirs flags)
+    bye $ fromMaybe "not available" path ++ "\n"
+
+  when (Flag_PrintGhcLibDir `elem` flags) $ do
+    dir <- fmap snd (getGhcDirs flags)
+    bye $ fromMaybe "not available" dir ++ "\n"
+
+  when (Flag_UseUnicode `elem` flags && Flag_Html `notElem` flags) $
+    throwE "Unicode can only be enabled for HTML output."
+
+  when ((Flag_GenIndex `elem` flags || Flag_GenContents `elem` flags)
+        && Flag_Html `elem` flags) $
+    throwE "-h/--html cannot be used with --gen-index or --gen-contents"
+
+  when ((Flag_GenIndex `elem` flags || Flag_GenContents `elem` flags)
+        && Flag_Hoogle `elem` flags) $
+    throwE "--hoogle cannot be used with --gen-index or --gen-contents"
+
+  when ((Flag_GenIndex `elem` flags || Flag_GenContents `elem` flags)
+        && Flag_LaTeX `elem` flags) $
+    throwE "--latex cannot be used with --gen-index or --gen-contents"
+  where
+    byeVersion = bye $
+      "Haddock version " ++ projectVersion ++ ", (c) Simon Marlow 2006\n"
+      ++ "Ported to use the GHC API by David Waern 2006-2008\n"
+
+
+-- | Generate some warnings about potential misuse of @--hyperlinked-source@.
+hypSrcWarnings :: [Flag] -> IO ()
+hypSrcWarnings flags = do
+    when (hypSrc && any isSourceUrlFlag flags) $
+        hPutStrLn stderr $ concat
+            [ "Warning: "
+            , "--source-* options are ignored when "
+            , "--hyperlinked-source is enabled."
+            ]
+    when (not hypSrc && any isSourceCssFlag flags) $
+        hPutStrLn stderr $ concat
+            [ "Warning: "
+            , "source CSS file is specified but "
+            , "--hyperlinked-source is disabled."
+            ]
+  where
+    hypSrc :: Bool
+    hypSrc = Flag_HyperlinkedSource `elem` flags
+
+    isSourceUrlFlag :: Flag -> Bool
+    isSourceUrlFlag (Flag_SourceBaseURL _) = True
+    isSourceUrlFlag (Flag_SourceModuleURL _) = True
+    isSourceUrlFlag (Flag_SourceEntityURL _) = True
+    isSourceUrlFlag (Flag_SourceLEntityURL _) = True
+    isSourceUrlFlag _ = False
+
+    isSourceCssFlag :: Flag -> Bool
+    isSourceCssFlag (Flag_SourceCss _) = True
+    isSourceCssFlag _ = False
+
+
+updateHTMLXRefs :: [(FilePath, InterfaceFile)] -> IO ()
+updateHTMLXRefs packages = do
+  let !modMap     = force $ Map.fromList mapping
+      !modNameMap = force $ Map.fromList mapping'
+  writeIORef html_xrefs_ref  modMap
+  writeIORef html_xrefs_ref' modNameMap
+  where
+    mapping = [ (instMod iface, html) | (html, ifaces) <- packages
+              , iface <- ifInstalledIfaces ifaces ]
+    mapping' = [ (moduleName m, html) | (m, html) <- mapping ]
+
+
+getPrologue :: DynFlags -> [Flag] -> IO (Maybe (MDoc RdrName))
+getPrologue dflags flags =
+  case [filename | Flag_Prologue filename <- flags ] of
+    [] -> return Nothing
+    [filename] -> do
+      h <- openFile filename ReadMode
+      hSetEncoding h utf8
+      str <- hGetContents h -- semi-closes the handle
+      return . Just $! second (fmap rdrName) $ parseParas dflags Nothing str
+    _ -> throwE "multiple -p/--prologue options"
+
+
+rightOrThrowE :: Either String b -> IO b
+rightOrThrowE (Left msg) = throwE msg
+rightOrThrowE (Right x) = pure x
+
diff --git a/haddock-api/src/Haddock/Backends/HaddockDB.hs b/haddock-api/src/Haddock/Backends/HaddockDB.hs
new file mode 100644
--- /dev/null
+++ b/haddock-api/src/Haddock/Backends/HaddockDB.hs
@@ -0,0 +1,175 @@
+-----------------------------------------------------------------------------
+-- |
+-- Module      :  Haddock.Backends.HaddockDB
+-- Copyright   :  (c) Simon Marlow 2003
+-- License     :  BSD-like
+--
+-- Maintainer  :  haddock@projects.haskell.org
+-- Stability   :  experimental
+-- Portability :  portable
+-----------------------------------------------------------------------------
+module Haddock.Backends.HaddockDB (ppDocBook) where
+
+{-
+import HaddockTypes
+import HaddockUtil
+import HsSyn2
+
+import Text.PrettyPrint
+-}
+
+-----------------------------------------------------------------------------
+-- Printing the results in DocBook format
+
+ppDocBook :: a
+ppDocBook = error "not working"
+{-
+ppDocBook :: FilePath -> [(Module, Interface)] -> String
+ppDocBook odir mods = render (ppIfaces mods)
+
+ppIfaces mods
+  =  text "<!DOCTYPE BOOK PUBLIC \"-//OASIS//DTD DocBook V3.1//EN\" ["
+  $$ text "]>"
+  $$ text "<book>"
+  $$ text "<bookinfo>"
+  $$ text "<author><othername>HaskellDoc version 0.0</othername></author>"
+  $$ text "</bookinfo>"
+  $$ text "<article>"
+  $$ vcat (map do_mod mods)
+  $$ text "</article></book>"
+  where
+     do_mod (Module mod, iface)
+        =  text "<sect1 id=\"sec-" <> text mod <> text "\">"
+        $$ text "<title><literal>"
+	   <> text mod
+	   <> text "</literal></title>"
+	$$ text "<indexterm><primary><literal>"
+	   <> text mod
+	   <> text "</literal></primary></indexterm>"
+	$$ text "<variablelist>"
+	$$ vcat (map (do_export mod) (eltsFM (iface_decls iface)))
+	$$ text "</variablelist>"
+	$$ text "</sect1>"
+
+     do_export mod decl | (nm:_) <- declBinders decl
+	=  text "<varlistentry id=" <> ppLinkId mod nm <> char '>'
+	$$ text "<term><literal>"
+		<> do_decl decl
+		<> text "</literal></term>"
+	$$ text "<listitem>"
+	$$ text "<para>"
+	$$ text "</para>"
+	$$ text "</listitem>"
+	$$ text "</varlistentry>"
+     do_export _ _ = empty
+
+     do_decl (HsTypeSig _ [nm] ty _)
+	=  ppHsName nm <> text " :: " <> ppHsType ty
+     do_decl (HsTypeDecl _ nm args ty _)
+	=  hsep ([text "type", ppHsName nm ]
+		 ++ map ppHsName args
+		 ++ [equals, ppHsType ty])
+     do_decl (HsNewTypeDecl loc ctx nm args con drv _)
+	= hsep ([text "data", ppHsName nm] -- data, not newtype
+		++ map ppHsName args
+		) <+> equals <+> ppHsConstr con -- ToDo: derivings
+     do_decl (HsDataDecl loc ctx nm args cons drv _)
+	= hsep ([text "data", {-ToDo: context-}ppHsName nm]
+	        ++ map ppHsName args)
+            <+> vcat (zipWith (<+>) (equals : repeat (char '|'))
+                                    (map ppHsConstr cons))
+     do_decl (HsClassDecl loc ty fds decl _)
+	= hsep [text "class", ppHsType ty]
+     do_decl decl
+	= empty
+
+ppHsConstr :: HsConDecl -> Doc
+ppHsConstr (HsRecDecl pos name tvs ctxt fieldList maybe_doc) =
+	 ppHsName name
+	 <> (braces . hsep . punctuate comma . map ppField $ fieldList)
+ppHsConstr (HsConDecl pos name tvs ctxt typeList maybe_doc) =
+	 hsep (ppHsName name : map ppHsBangType typeList)
+
+ppField (HsFieldDecl ns ty doc)
+   = hsep (punctuate comma (map ppHsName ns) ++
+	 	[text "::", ppHsBangType ty])
+
+ppHsBangType :: HsBangType -> Doc
+ppHsBangType (HsBangedTy ty) = char '!' <> ppHsType ty
+ppHsBangType (HsUnBangedTy ty) = ppHsType ty
+
+ppHsContext :: HsContext -> Doc
+ppHsContext []      = empty
+ppHsContext context = parenList (map (\ (a,b) -> ppHsQName a <+>
+					 hsep (map ppHsAType b)) context)
+
+ppHsType :: HsType -> Doc
+ppHsType (HsForAllType _ Nothing context htype) =
+     hsep [ ppHsContext context, text "=>", ppHsType htype]
+ppHsType (HsForAllType fvf (Just tvs) [] htype) =
+     hsep (text "forall" : map ppHsName tvs ++ pprHsForAllSeparator fvf :
+       [ppHsType htype])
+ppHsType (HsForAllType fvf (Just tvs) context htype) =
+     hsep (text "forall" : map ppHsName tvs ++ pprHsForAllSeparator fvf :
+	   ppHsContext context : text "=>" : [ppHsType htype])
+ppHsType (HsTyFun a b) = fsep [ppHsBType a, text "-&gt;", ppHsType b]
+ppHsType (HsTyIP n t)  = fsep [(char '?' <> ppHsName n), text "::", ppHsType t]
+ppHsType t = ppHsBType t
+
+ppHsForAllSeparator :: ForallVisFlag -> Doc
+ppHsForAllSeparator ForallVis   = text "-&gt;"
+ppHsForAllSeparator ForallInvis = text "."
+
+ppHsBType (HsTyApp (HsTyCon (Qual (Module "Prelude") (HsTyClsName (HsSpecial "[]")))) b )
+  = brackets $ ppHsType b
+ppHsBType (HsTyApp a b) = fsep [ppHsBType a, ppHsAType b]
+ppHsBType t = ppHsAType t
+
+ppHsAType :: HsType -> Doc
+ppHsAType (HsTyTuple True l)  = parenList . map ppHsType $ l
+ppHsAType (HsTyTuple False l) = ubxParenList . map ppHsType $ l
+-- special case
+ppHsAType (HsTyApp (HsTyCon (Qual (Module "Prelude") (HsTyClsName (HsSpecial "[]")))) b )
+  = brackets $ ppHsType b
+ppHsAType (HsTyVar name) = ppHsName name
+ppHsAType (HsTyCon name) = ppHsQName name
+ppHsAType t = parens $ ppHsType t
+
+ppHsQName :: HsQName -> Doc
+ppHsQName (UnQual str)			= ppHsName str
+ppHsQName n@(Qual (Module mod) str)
+	 | n == unit_con_name		= ppHsName str
+	 | isSpecial str 		= ppHsName str
+	 | otherwise
+		=  text "<link linkend=" <> ppLinkId mod str <> char '>'
+		<> ppHsName str
+		<> text "</link>"
+
+isSpecial (HsTyClsName id) | HsSpecial _ <- id = True
+isSpecial (HsVarName id) | HsSpecial _ <- id = True
+isSpecial _ = False
+
+ppHsName :: HsName -> Doc
+ppHsName (HsTyClsName id) = ppHsIdentifier id
+ppHsName (HsVarName id) = ppHsIdentifier id
+
+ppHsIdentifier :: HsIdentifier -> Doc
+ppHsIdentifier (HsIdent str)	= text str
+ppHsIdentifier (HsSymbol str) = text str
+ppHsIdentifier (HsSpecial str) = text str
+
+ppLinkId :: String -> HsName -> Doc
+ppLinkId mod str
+  = hcat [char '\"', text mod, char '.', ppHsName str, char '\"']
+
+-- -----------------------------------------------------------------------------
+-- * Misc
+
+parenList :: [Doc] -> Doc
+parenList = parens . fsep . punctuate comma
+
+ubxParenList :: [Doc] -> Doc
+ubxParenList = ubxparens . fsep . punctuate comma
+
+ubxparens p = text "(#" <> p <> text "#)"
+-}
diff --git a/haddock-api/src/Haddock/Backends/Hoogle.hs b/haddock-api/src/Haddock/Backends/Hoogle.hs
new file mode 100644
--- /dev/null
+++ b/haddock-api/src/Haddock/Backends/Hoogle.hs
@@ -0,0 +1,428 @@
+{-# LANGUAGE FlexibleContexts #-}
+{-# LANGUAGE TypeFamilies #-}
+
+-----------------------------------------------------------------------------
+-- |
+-- Module      :  Haddock.Backends.Hoogle
+-- Copyright   :  (c) Neil Mitchell 2006-2008
+-- License     :  BSD-like
+--
+-- Maintainer  :  haddock@projects.haskell.org
+-- Stability   :  experimental
+-- Portability :  portable
+--
+-- Write out Hoogle compatible documentation
+-- http://www.haskell.org/hoogle/
+-----------------------------------------------------------------------------
+module Haddock.Backends.Hoogle (
+    -- * Main entry point to Hoogle output generation
+    ppHoogle
+
+    -- * Utilities for generating Hoogle output during interface creation
+  , ppExportD
+  , outWith
+  ) where
+
+import Documentation.Haddock.Markup
+import Haddock.GhcUtils
+import Haddock.Types hiding (Version)
+import Haddock.Utils hiding (out)
+
+import GHC
+import GHC.Driver.Ppr
+import GHC.Plugins (TopLevelFlag(..))
+import GHC.Utils.Outputable as Outputable
+import GHC.Utils.Panic
+import GHC.Unit.State
+
+import Data.Char
+import Data.Foldable (toList)
+import Data.List (intercalate, isPrefixOf)
+import Data.Maybe
+import Data.Version
+
+import System.Directory
+import System.FilePath
+
+prefix :: [String]
+prefix = ["-- Hoogle documentation, generated by Haddock"
+         ,"-- See Hoogle, http://www.haskell.org/hoogle/"
+         ,""]
+
+
+ppHoogle :: DynFlags -> String -> Version -> String -> Maybe (Doc RdrName) -> [Interface] -> FilePath -> IO ()
+ppHoogle dflags package version synopsis prologue ifaces odir = do
+    let -- Since Hoogle is line based, we want to avoid breaking long lines.
+        dflags' = dflags{ pprCols = maxBound }
+        filename = package ++ ".txt"
+        contents = prefix ++
+                   docWith dflags' (drop 2 $ dropWhile (/= ':') synopsis) prologue ++
+                   ["@package " ++ package] ++
+                   ["@version " ++ showVersion version
+                   | not (null (versionBranch version))
+                   ] ++
+                   concat [ppModule dflags' i | i <- ifaces, OptHide `notElem` ifaceOptions i]
+    createDirectoryIfMissing True odir
+    writeUtf8File (odir </> filename) (unlines contents)
+
+ppModule :: DynFlags -> Interface -> [String]
+ppModule dflags iface =
+  "" : ppDocumentation dflags (ifaceDoc iface) ++
+  ["module " ++ moduleString (ifaceMod iface)] ++
+  concatMap ppExportItem (ifaceRnExportItems $ iface) ++
+  map (fromMaybe "" . haddockClsInstPprHoogle) (ifaceInstances iface)
+
+-- | If the export item is an 'ExportDecl', get the attached Hoogle textual
+-- database entries for that export declaration.
+ppExportItem :: ExportItem DocNameI -> [String]
+ppExportItem (ExportDecl RnExportD { rnExpDHoogle = o }) = o
+ppExportItem _                                           = []
+
+---------------------------------------------------------------------
+-- Utility functions
+
+dropHsDocTy :: HsSigType GhcRn -> HsSigType GhcRn
+dropHsDocTy = drop_sig_ty
+    where
+        drop_sig_ty (HsSig x a b)  = HsSig x a (drop_lty b)
+        drop_sig_ty x@XHsSigType{} = x
+
+        drop_lty (L src x) = L src (drop_ty x)
+
+        drop_ty (HsForAllTy x a e) = HsForAllTy x a (drop_lty e)
+        drop_ty (HsQualTy x a e) = HsQualTy x a (drop_lty e)
+        drop_ty (HsBangTy x a b) = HsBangTy x a (drop_lty b)
+        drop_ty (HsAppTy x a b) = HsAppTy x (drop_lty a) (drop_lty b)
+        drop_ty (HsAppKindTy x a b) = HsAppKindTy x (drop_lty a) (drop_lty b)
+        drop_ty (HsFunTy x w a b) = HsFunTy x w (drop_lty a) (drop_lty b)
+        drop_ty (HsListTy x a) = HsListTy x (drop_lty a)
+        drop_ty (HsTupleTy x a b) = HsTupleTy x a (map drop_lty b)
+        drop_ty (HsOpTy x p a b c) = HsOpTy x p (drop_lty a) b (drop_lty c)
+        drop_ty (HsParTy x a) = HsParTy x (drop_lty a)
+        drop_ty (HsKindSig x a b) = HsKindSig x (drop_lty a) b
+        drop_ty (HsDocTy _ a _) = drop_ty $ unL a
+        drop_ty x = x
+
+outHsSigType :: DynFlags -> HsSigType GhcRn -> String
+outHsSigType dflags = out dflags . reparenSigType . dropHsDocTy
+
+outWith :: Outputable a => (SDoc -> String) -> a -> [Char]
+outWith p = f . unwords . map (dropWhile isSpace) . lines . p . ppr
+    where
+        f xs | " <document comment>" `isPrefixOf` xs = f $ drop 19 xs
+        f (x:xs) = x : f xs
+        f [] = []
+
+out :: Outputable a => DynFlags -> a -> String
+out dflags = outWith $ showSDoc dflags
+
+operator :: String -> String
+operator (x:xs) | not (isAlphaNum x) && x `notElem` "_' ([{" = '(' : x:xs ++ ")"
+operator x = x
+
+commaSeparate :: Outputable a => DynFlags -> [a] -> String
+commaSeparate dflags = showSDoc dflags . interpp'SP
+
+---------------------------------------------------------------------
+-- How to print each export
+
+ppExportD :: DynFlags -> ExportD GhcRn -> [String]
+ppExportD dflags
+    ExportD
+      { expDDecl     = L _ decl
+      , expDPats     = bundledPats
+      , expDMbDoc    = mbDoc
+      , expDSubDocs  = subdocs
+      , expDFixities = fixities
+      }
+  = let
+      -- Since Hoogle is line based, we want to avoid breaking long lines.
+      dflags' = dflags{ pprCols = maxBound }
+    in
+      concat
+        [ ppDocumentation dflags' dc ++ f d
+        | (d, (dc, _)) <- (decl, mbDoc) : bundledPats
+        ] ++ ppFixities
+  where
+    f :: HsDecl GhcRn -> [String]
+    f (TyClD _ d@DataDecl{})  = ppData dflags d subdocs
+    f (TyClD _ d@SynDecl{})   = ppSynonym dflags d
+    f (TyClD _ d@ClassDecl{}) = ppClass dflags d subdocs
+    f (TyClD _ (FamDecl _ d)) = ppFam dflags d
+    f (ForD _ (ForeignImport _ name typ _)) = [pp_sig dflags [name] typ]
+    f (ForD _ (ForeignExport _ name typ _)) = [pp_sig dflags [name] typ]
+    f (SigD _ sig) = ppSig dflags sig
+    f _ = []
+
+    ppFixities :: [String]
+    ppFixities = concatMap (ppFixity dflags) fixities
+
+
+ppSigWithDoc :: DynFlags -> Sig GhcRn -> [(Name, DocForDecl Name)] -> [String]
+ppSigWithDoc dflags sig subdocs = case sig of
+    TypeSig _ names t -> concatMap (mkDocSig "" (dropWildCards t)) names
+    PatSynSig _ names t -> concatMap (mkDocSig "pattern " t) names
+    _ -> []
+  where
+    mkDocSig leader typ n = mkSubdocN dflags n subdocs
+                                      [leader ++ pp_sig dflags [n] typ]
+
+ppSig :: DynFlags -> Sig GhcRn -> [String]
+ppSig dflags x  = ppSigWithDoc dflags x []
+
+pp_sig :: DynFlags -> [LocatedN Name] -> LHsSigType GhcRn -> String
+pp_sig dflags names (L _ typ)  =
+    operator prettyNames ++ " :: " ++ outHsSigType dflags typ
+    where
+      prettyNames = intercalate ", " $ map (out dflags) names
+
+-- note: does not yet output documentation for class methods
+ppClass :: DynFlags -> TyClDecl GhcRn -> [(Name, DocForDecl Name)] -> [String]
+ppClass dflags decl@(ClassDecl {}) subdocs =
+  (out dflags decl{tcdSigs=[], tcdATs=[], tcdATDefs=[], tcdMeths=emptyLHsBinds}
+    ++ ppTyFams) :  ppMethods
+    where
+
+        ppMethods = concat . map (ppSig' . unLoc . add_ctxt) $ tcdSigs decl
+        ppSig' = flip (ppSigWithDoc dflags) subdocs
+
+        add_ctxt = addClassContext (tcdName decl) (tyClDeclTyVars decl)
+
+        ppTyFams
+            | null $ tcdATs decl = ""
+            | otherwise = (" " ++) . showSDoc dflags . whereWrapper $ concat
+                [ map pprTyFam (tcdATs decl)
+                , map (pprTyFamInstDecl NotTopLevel . unLoc) (tcdATDefs decl)
+                ]
+
+        pprTyFam :: LFamilyDecl GhcRn -> SDoc
+        pprTyFam (L _ at) = vcat' $ map text $
+            mkSubdocN dflags (fdLName at) subdocs (ppFam dflags at)
+
+        whereWrapper elems = vcat'
+            [ text "where" <+> lbrace
+            , nest 4 . vcat . map (Outputable.<> semi) $ elems
+            , rbrace
+            ]
+ppClass _ _non_cls_decl _ = []
+ppFam :: DynFlags -> FamilyDecl GhcRn -> [String]
+ppFam dflags decl@(FamilyDecl { fdInfo = info })
+  = [out dflags decl']
+  where
+    decl' = case info of
+              -- We don't need to print out a closed type family's equations
+              -- for Hoogle, so pretend it doesn't have any.
+              ClosedTypeFamily{} -> decl { fdInfo = OpenTypeFamily }
+              _                  -> decl
+
+ppSynonym :: DynFlags -> TyClDecl GhcRn -> [String]
+ppSynonym dflags x = [out dflags x]
+
+ppData :: DynFlags -> TyClDecl GhcRn -> [(Name, DocForDecl Name)] -> [String]
+ppData dflags decl@DataDecl { tcdLName = name, tcdTyVars = tvs, tcdFixity = fixity, tcdDataDefn = defn } subdocs
+    = out dflags (ppDataDefnHeader (pp_vanilla_decl_head name tvs fixity) defn) :
+      concatMap (ppCtor dflags decl subdocs . unLoc) (dd_cons defn)
+    where
+ppData _ _ _ = panic "ppData"
+
+-- | for constructors, and named-fields...
+lookupCon :: DynFlags -> [(Name, DocForDecl Name)] -> LocatedN Name -> [String]
+lookupCon dflags subdocs (L _ name) = case lookup name subdocs of
+  Just (d, _) -> ppDocumentation dflags d
+  _ -> []
+
+ppCtor :: DynFlags -> TyClDecl GhcRn -> [(Name, DocForDecl Name)] -> ConDecl GhcRn -> [String]
+ppCtor dflags dat subdocs con@ConDeclH98 { con_args = con_args' }
+  -- AZ:TODO get rid of the concatMap
+   = concatMap (lookupCon dflags subdocs) [con_name con] ++ f con_args'
+    where
+        f (PrefixCon _ args) = [typeSig name $ (map hsScaledThing args) ++ [resType]]
+        f (InfixCon a1 a2) = f $ PrefixCon [] [a1,a2]
+        f (RecCon (L _ recs)) = f (PrefixCon [] $ map (hsLinear . cd_fld_type . unLoc) recs) ++ concat
+                          [(concatMap (lookupCon dflags subdocs . noLocA . foExt . unLoc) (cd_fld_names r)) ++
+                           [out dflags (map (foExt . unLoc) $ cd_fld_names r) `typeSig` [resType, cd_fld_type r]]
+                          | r <- map unLoc recs]
+
+        funs = foldr1 (\x y -> reL $ HsFunTy noAnn (HsUnrestrictedArrow noHsUniTok) x y)
+        apps = foldl1 (\x y -> reL $ HsAppTy noExtField x y)
+
+        typeSig nm flds = operator nm ++ " :: " ++
+                          outHsSigType dflags (unL $ mkEmptySigType $ funs flds)
+
+        -- We print the constructors as comma-separated list. See GHC
+        -- docs for con_names on why it is a list to begin with.
+        name = commaSeparate dflags . toList $ unL <$> getConNames con
+
+        tyVarArg (UserTyVar _ _ n) = HsTyVar noAnn NotPromoted n
+        tyVarArg (KindedTyVar _ _ n lty) = HsKindSig noAnn (reL (HsTyVar noAnn NotPromoted n)) lty
+        tyVarArg _ = panic "ppCtor"
+
+        resType = apps $ map reL $
+                        (HsTyVar noAnn NotPromoted (reL (tcdName dat))) :
+                        map (tyVarArg . unLoc) (hsQTvExplicit $ tyClDeclTyVars dat)
+
+ppCtor dflags _dat subdocs (ConDeclGADT { con_names = names
+                                        , con_bndrs = L _ outer_bndrs
+                                        , con_mb_cxt = mcxt
+                                        , con_g_args = args
+                                        , con_res_ty = res_ty })
+   = concatMap (lookupCon dflags subdocs) names ++ [typeSig]
+    where
+        typeSig = operator name ++ " :: " ++ outHsSigType dflags con_sig_ty
+        name = out dflags $ unL <$> names
+        con_sig_ty = HsSig noExtField outer_bndrs theta_ty where
+          theta_ty = case mcxt of
+            Just theta -> noLocA (HsQualTy { hst_xqual = noExtField, hst_ctxt = theta, hst_body = tau_ty })
+            Nothing -> tau_ty
+          tau_ty = foldr mkFunTy res_ty $
+            case args of PrefixConGADT pos_args -> map hsScaledThing pos_args
+                         RecConGADT (L _ flds) _ -> map (cd_fld_type . unL) flds
+          mkFunTy a b = noLocA (HsFunTy noAnn (HsUnrestrictedArrow noHsUniTok) a b)
+
+ppFixity :: DynFlags -> (Name, Fixity) -> [String]
+ppFixity dflags (name, fixity) = [out dflags ((FixitySig noExtField [noLocA name] fixity) :: FixitySig GhcRn)]
+
+
+---------------------------------------------------------------------
+-- DOCUMENTATION
+
+ppDocumentation :: Outputable o => DynFlags -> Documentation o -> [String]
+ppDocumentation dflags (Documentation d w) = mdoc dflags d ++ doc dflags w
+
+
+doc :: Outputable o => DynFlags -> Maybe (Doc o) -> [String]
+doc dflags = docWith dflags ""
+
+mdoc :: Outputable o => DynFlags -> Maybe (MDoc o) -> [String]
+mdoc dflags = docWith dflags "" . fmap _doc
+
+docWith :: Outputable o => DynFlags -> String -> Maybe (Doc o) -> [String]
+docWith _ [] Nothing = []
+docWith dflags header d
+  = ("":) $ zipWith (++) ("-- | " : repeat "--   ") $
+    lines header ++ ["" | header /= "" && isJust d] ++
+    maybe [] (showTags . markup (markupTag dflags)) d
+
+mkSubdocN :: DynFlags -> LocatedN Name -> [(Name, DocForDecl Name)] -> [String] -> [String]
+mkSubdocN dflags n subdocs s = mkSubdoc dflags (n2l n) subdocs s
+
+mkSubdoc :: DynFlags -> LocatedA Name -> [(Name, DocForDecl Name)] -> [String] -> [String]
+mkSubdoc dflags n subdocs s = concatMap (ppDocumentation dflags) getDoc ++ s
+ where
+   getDoc = maybe [] (return . fst) (lookup (unLoc n) subdocs)
+
+data Tag = TagL Char [Tags] | TagP Tags | TagPre Tags | TagInline String Tags | Str String
+           deriving Show
+
+type Tags = [Tag]
+
+box :: (a -> b) -> a -> [b]
+box f x = [f x]
+
+str :: String -> [Tag]
+str a = [Str a]
+
+-- want things like paragraph, pre etc to be handled by blank lines in the source document
+-- and things like \n and \t converted away
+-- much like blogger in HTML mode
+-- everything else wants to be included as tags, neatly nested for some (ul,li,ol)
+-- or inlne for others (a,i,tt)
+-- entities (&,>,<) should always be appropriately escaped
+
+markupTag :: Outputable o => DynFlags -> DocMarkup o [Tag]
+markupTag dflags = Markup {
+  markupParagraph            = box TagP,
+  markupEmpty                = str "",
+  markupString               = str,
+  markupAppend               = (++),
+  markupIdentifier           = box (TagInline "a") . str . out dflags,
+  markupIdentifierUnchecked  = box (TagInline "a") . str . showWrapped (out dflags . snd),
+  markupModule               = \(ModLink m label) -> box (TagInline "a") (fromMaybe (str m) label),
+  markupWarning              = box (TagInline "i"),
+  markupEmphasis             = box (TagInline "i"),
+  markupBold                 = box (TagInline "b"),
+  markupMonospaced           = box (TagInline "tt"),
+  markupPic                  = const $ str " ",
+  markupMathInline           = const $ str "<math>",
+  markupMathDisplay          = const $ str "<math>",
+  markupUnorderedList        = box (TagL 'u'),
+  markupOrderedList          = box (TagL 'o') . map snd,
+  markupDefList              = box (TagL 'u') . map (\(a,b) -> TagInline "i" a : Str " " : b),
+  markupCodeBlock            = box TagPre,
+  markupHyperlink            = \(Hyperlink url mLabel) -> box (TagInline "a") (fromMaybe (str url) mLabel),
+  markupAName                = const $ str "",
+  markupProperty             = box TagPre . str,
+  markupExample              = box TagPre . str . unlines . map exampleToString,
+  markupHeader               = \(Header l h) -> box (TagInline $ "h" ++ show l) h,
+  markupTable                = \(Table _ _) -> str "TODO: table"
+  }
+
+
+showTags :: [Tag] -> [String]
+showTags = intercalate [""] . map showBlock
+
+
+showBlock :: Tag -> [String]
+showBlock (TagP xs) = showInline xs
+showBlock (TagL t xs) = ['<':t:"l>"] ++ mid ++ ['<':'/':t:"l>"]
+    where mid = concatMap (showInline . box (TagInline "li")) xs
+showBlock (TagPre xs) = ["<pre>"] ++ showPre xs ++ ["</pre>"]
+showBlock x = showInline [x]
+
+
+asInline :: Tag -> Tags
+asInline (TagP xs) = xs
+asInline (TagPre xs) = [TagInline "pre" xs]
+asInline (TagL t xs) = [TagInline (t:"l") $ map (TagInline "li") xs]
+asInline x = [x]
+
+
+showInline :: [Tag] -> [String]
+showInline = unwordsWrap 70 . words . concatMap f
+    where
+        fs = concatMap f
+        f (Str x) = escape x
+        f (TagInline s xs) = "<"++s++">" ++ (if s == "li" then trim else id) (fs xs) ++ "</"++s++">"
+        f x = fs $ asInline x
+
+        trim = dropWhile isSpace . reverse . dropWhile isSpace . reverse
+
+
+showPre :: [Tag] -> [String]
+showPre = trimFront . trimLines . lines . concatMap f
+    where
+        trimLines = dropWhile null . reverse . dropWhile null . reverse
+        trimFront xs = map (drop i) xs
+            where
+                ns = [length a | x <- xs, let (a,b) = span isSpace x, b /= ""]
+                i = if null ns then 0 else minimum ns
+
+        fs = concatMap f
+        f (Str x) = escape x
+        f (TagInline s xs) = "<"++s++">" ++ fs xs ++ "</"++s++">"
+        f x = fs $ asInline x
+
+
+unwordsWrap :: Int -> [String] -> [String]
+unwordsWrap n = f n []
+    where
+        f _ s [] = [g s | s /= []]
+        f i s (x:xs) | nx > i = g s : f (n - nx - 1) [x] xs
+                     | otherwise = f (i - nx - 1) (x:s) xs
+            where nx = length x
+
+        g = unwords . reverse
+
+
+escape :: String -> String
+escape = concatMap f
+    where
+        f '<' = "&lt;"
+        f '>' = "&gt;"
+        f '&' = "&amp;"
+        f x = [x]
+
+
+-- | Just like 'vcat' but uses '($+$)' instead of '($$)'.
+vcat' :: [SDoc] -> SDoc
+vcat' = foldr ($+$) empty
diff --git a/haddock-api/src/Haddock/Backends/Hyperlinker.hs b/haddock-api/src/Haddock/Backends/Hyperlinker.hs
new file mode 100644
--- /dev/null
+++ b/haddock-api/src/Haddock/Backends/Hyperlinker.hs
@@ -0,0 +1,114 @@
+{-# LANGUAGE OverloadedStrings #-}
+{-# LANGUAGE PatternSynonyms #-}
+module Haddock.Backends.Hyperlinker
+    ( ppHyperlinkedSource
+    , module Haddock.Backends.Hyperlinker.Types
+    , module Haddock.Backends.Hyperlinker.Utils
+    ) where
+
+
+import Haddock.Types
+import Haddock.Utils (writeUtf8File, out, verbose, Verbosity)
+import Haddock.InterfaceFile
+import Haddock.Backends.Hyperlinker.Renderer
+import Haddock.Backends.Hyperlinker.Parser
+import Haddock.Backends.Hyperlinker.Types
+import Haddock.Backends.Hyperlinker.Utils
+import Haddock.Backends.Xhtml.Utils ( renderToString )
+
+import Data.Maybe
+import System.Directory
+import System.FilePath
+
+import GHC.Iface.Ext.Types  ( pattern HiePath, HieFile(..), HieASTs(..), HieAST(..), SourcedNodeInfo(..) )
+import GHC.Iface.Ext.Binary ( readHieFile, hie_file_result )
+import GHC.Types.SrcLoc     ( realSrcLocSpan, mkRealSrcLoc, srcSpanFile )
+import Data.Map as M
+import GHC.Data.FastString     ( mkFastString )
+import GHC.Unit.Module         ( Module, moduleName )
+
+
+-- | Generate hyperlinked source for given interfaces.
+--
+-- Note that list of interfaces should also contain interfaces normally hidden
+-- when generating documentation. Otherwise this could lead to dead links in
+-- produced source.
+ppHyperlinkedSource :: Verbosity
+                    -> FilePath -- ^ Output directory
+                    -> FilePath -- ^ Resource directory
+                    -> Maybe FilePath -- ^ Custom CSS file path
+                    -> Bool -- ^ Flag indicating whether to pretty-print HTML
+                    -> M.Map Module SrcPath -- ^ Paths to sources
+                    -> [Interface] -- ^ Interfaces for which we create source
+                    -> IO ()
+ppHyperlinkedSource verbosity outdir libdir mstyle pretty srcs' ifaces = do
+    createDirectoryIfMissing True srcdir
+    let cssFile = fromMaybe (defaultCssFile libdir) mstyle
+    copyFile cssFile $ srcdir </> srcCssFile
+    copyFile (libdir </> "html" </> highlightScript) $
+        srcdir </> highlightScript
+    mapM_ (ppHyperlinkedModuleSource verbosity srcdir pretty srcs) ifaces
+  where
+    srcdir = outdir </> hypSrcDir
+    srcs = (srcs', M.mapKeys moduleName srcs')
+
+-- | Generate hyperlinked source for particular interface.
+ppHyperlinkedModuleSource :: Verbosity -> FilePath -> Bool -> SrcMaps -> Interface -> IO ()
+ppHyperlinkedModuleSource verbosity srcdir pretty srcs iface = case ifaceHieFile iface of
+    Just hfp -> do
+        -- Parse the GHC-produced HIE file
+        nc <- freshNameCache
+        HieFile { hie_hs_file = file
+                , hie_asts = HieASTs asts
+                , hie_types = types
+                , hie_hs_src = rawSrc
+                } <- hie_file_result
+                 <$> (readHieFile nc hfp)
+
+        -- Get the AST and tokens corresponding to the source file we want
+        let fileFs = mkFastString file
+            mast | M.size asts == 1 = snd <$> M.lookupMin asts
+                 | otherwise        = M.lookup (HiePath (mkFastString file)) asts
+            tokens' = parse df file rawSrc
+            ast = fromMaybe (emptyHieAst fileFs) mast
+            fullAst = recoverFullIfaceTypes df types ast
+
+        -- Warn if we didn't find an AST, but there were still ASTs
+        if M.null asts
+          then pure ()
+          else out verbosity verbose $ unwords [ "couldn't find ast for"
+                                               , file, show (M.keys asts) ]
+
+        -- The C preprocessor can double the backslashes on tokens (see #19236),
+        -- which means the source spans will not be comparable and we will not
+        -- be able to associate the HieAST with the correct tokens.
+        --
+        -- We work around this by setting the source span of the tokens to the file
+        -- name from the HieAST
+        let tokens = fmap (\tk -> tk {tkSpan = (tkSpan tk){srcSpanFile = srcSpanFile $ nodeSpan fullAst}}) tokens'
+
+        -- Produce and write out the hyperlinked sources
+        writeUtf8File path . renderToString pretty . render' fullAst $ tokens
+    Nothing -> return ()
+  where
+    df = ifaceDynFlags iface
+    render' = render (Just srcCssFile) (Just highlightScript) srcs
+    path = srcdir </> hypSrcModuleFile (ifaceMod iface)
+
+    emptyHieAst fileFs = Node
+      { nodeSpan = realSrcLocSpan (mkRealSrcLoc fileFs 1 0)
+      , nodeChildren = []
+      , sourcedNodeInfo = SourcedNodeInfo mempty
+      }
+
+-- | Name of CSS file in output directory.
+srcCssFile :: FilePath
+srcCssFile = "style.css"
+
+-- | Name of highlight script in output and resource directory.
+highlightScript :: FilePath
+highlightScript = "highlight.js"
+
+-- | Path to default CSS file.
+defaultCssFile :: FilePath -> FilePath
+defaultCssFile libdir = libdir </> "html" </> "solarized.css"
diff --git a/haddock-api/src/Haddock/Backends/Hyperlinker/Parser.hs b/haddock-api/src/Haddock/Backends/Hyperlinker/Parser.hs
new file mode 100644
--- /dev/null
+++ b/haddock-api/src/Haddock/Backends/Hyperlinker/Parser.hs
@@ -0,0 +1,406 @@
+{-# LANGUAGE OverloadedStrings #-}
+{-# OPTIONS_GHC -fno-warn-orphans #-}
+{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}
+module Haddock.Backends.Hyperlinker.Parser (parse) where
+
+import Control.Monad.Trans.Maybe
+import Control.Monad.Trans.Class
+import Control.Applicative ( Alternative(..) )
+import Data.List           ( isPrefixOf, isSuffixOf )
+
+import qualified Data.ByteString as BS
+
+import GHC.Platform
+import GHC.Types.SourceText
+import GHC.Driver.Session
+import GHC.Driver.Config.Diagnostic
+import GHC.Utils.Error     ( pprLocMsgEnvelopeDefault )
+import GHC.Data.FastString ( mkFastString )
+import GHC.Parser.Errors.Ppr ()
+import qualified GHC.Types.Error as E
+import GHC.Parser.Lexer    as Lexer
+                           ( P(..), ParseResult(..), PState(..), Token(..)
+                           , initParserState, lexer, mkParserOpts, getPsErrorMessages)
+import GHC.Data.Bag         ( bagToList )
+import GHC.Utils.Outputable ( text, ($$) )
+import GHC.Utils.Panic      ( panic )
+import GHC.Driver.Ppr       ( showSDoc )
+import GHC.Types.SrcLoc
+import GHC.Data.StringBuffer ( StringBuffer, atEnd )
+
+import Haddock.Backends.Hyperlinker.Types as T
+import Haddock.GhcUtils
+
+-- | Turn source code string into a stream of more descriptive tokens.
+--
+-- Result should retain original file layout (including comments,
+-- whitespace, and CPP).
+parse
+  :: DynFlags      -- ^ Flags for this module
+  -> FilePath      -- ^ Path to the source of this module
+  -> BS.ByteString -- ^ Raw UTF-8 encoded source of this module
+  -> [T.Token]
+parse dflags fpath bs = case unP (go False []) initState of
+    POk _ toks -> reverse toks
+    PFailed pst ->
+      let err:_ = bagToList (E.getMessages $ getPsErrorMessages pst) in
+      panic $ showSDoc dflags $
+        text "Hyperlinker parse error:" $$ pprLocMsgEnvelopeDefault err
+  where
+
+    initState = initParserState pflags buf start
+    buf = stringBufferFromByteString bs
+    start = mkRealSrcLoc (mkFastString fpath) 1 1
+    arch_os = platformArchOS (targetPlatform dflags)
+    pflags = mkParserOpts   (extensionFlags dflags)
+                            (initDiagOpts dflags)
+                            (supportedLanguagesAndExtensions arch_os)
+                            (safeImportsOn dflags)
+                            False -- lex Haddocks as comment tokens
+                            True  -- produce comment tokens
+                            False -- produce position pragmas tokens
+
+    go :: Bool        -- ^ are we currently in a pragma?
+       -> [T.Token]   -- ^ tokens accumulated so far (in reverse)
+       -> P [T.Token]
+    go inPrag toks = do
+      (b, _) <- getInput
+      if not (atEnd b)
+        then do
+          mtok <- runMaybeT (parseCppLine <|> parsePlainTok inPrag)
+          (newToks, inPrag') <- case mtok of
+            Nothing -> unknownLine
+            Just a -> pure a
+          go inPrag' (newToks ++ toks)
+        else
+          pure toks
+
+    -- | Like 'Lexer.lexer', but slower, with a better API, and filtering out empty tokens
+    wrappedLexer :: P (RealLocated Lexer.Token)
+    wrappedLexer = Lexer.lexer False andThen
+      where andThen (L (RealSrcSpan s _) t)
+              | srcSpanStartLine s /= srcSpanEndLine s ||
+                srcSpanStartCol s /= srcSpanEndCol s
+              = pure (L s t)
+            andThen (L (RealSrcSpan s _) ITeof) = pure (L s ITeof)
+            andThen _ = wrappedLexer
+
+    -- | Try to parse a CPP line (can fail)
+    parseCppLine :: MaybeT P ([T.Token], Bool)
+    parseCppLine = MaybeT $ do
+      (b, l) <- getInput
+      case tryCppLine l b of
+        Just (cppBStr, l', b')
+             -> let cppTok = T.Token { tkType = TkCpp
+                                     , tkValue = cppBStr
+                                     , tkSpan = mkRealSrcSpan l l' }
+                in setInput (b', l') *> pure (Just ([cppTok], False))
+        _    -> return Nothing
+
+    -- | Try to parse a regular old token (can fail)
+    parsePlainTok :: Bool -> MaybeT P ([T.Token], Bool)  -- return list is only ever 0-2 elements
+    parsePlainTok inPrag = do
+      (bInit, lInit) <- lift getInput
+      L sp tok <- tryP (Lexer.lexer False return)
+      (bEnd, _) <- lift getInput
+      case sp of
+        UnhelpfulSpan _ -> pure ([], False) -- pretend the token never existed
+        RealSrcSpan rsp _ -> do
+          let typ = if inPrag then TkPragma else classify tok
+              RealSrcLoc lStart _ = srcSpanStart sp -- safe since @sp@ is real
+              (spaceBStr, bStart) = spanPosition lInit lStart bInit
+              inPragDef = inPragma inPrag tok
+
+          (bEnd', inPrag') <- case tok of
+
+            -- Update internal line + file position if this is a LINE pragma
+            ITline_prag _ -> tryOrElse (bEnd, inPragDef) $ do
+              L _ (ITinteger (IL { il_value = line })) <- tryP wrappedLexer
+              L _ (ITstring _ file)                    <- tryP wrappedLexer
+              L spF ITclose_prag                       <- tryP wrappedLexer
+
+              let newLoc = mkRealSrcLoc file (fromIntegral line - 1) (srcSpanEndCol spF)
+              (bEnd'', _) <- lift getInput
+              lift $ setInput (bEnd'', newLoc)
+
+              pure (bEnd'', False)
+
+            -- Update internal column position if this is a COLUMN pragma
+            ITcolumn_prag _ -> tryOrElse (bEnd, inPragDef) $ do
+              L _ (ITinteger (IL { il_value = col }))  <- tryP wrappedLexer
+              L spF ITclose_prag                       <- tryP wrappedLexer
+
+              let newLoc = mkRealSrcLoc (srcSpanFile spF) (srcSpanEndLine spF) (fromIntegral col)
+              (bEnd'', _) <- lift getInput
+              lift $ setInput (bEnd'', newLoc)
+
+              pure (bEnd'', False)
+
+            _ -> pure (bEnd, inPragDef)
+
+          let tokBStr = splitStringBuffer bStart bEnd'
+              plainTok = T.Token { tkType = typ
+                                 , tkValue = tokBStr
+                                 , tkSpan = rsp }
+              spaceTok = T.Token { tkType = TkSpace
+                                 , tkValue = spaceBStr
+                                 , tkSpan = mkRealSrcSpan lInit lStart }
+
+          pure (plainTok : [ spaceTok | not (BS.null spaceBStr) ], inPrag')
+
+    -- | Parse whatever remains of the line as an unknown token (can't fail)
+    unknownLine :: P ([T.Token], Bool)
+    unknownLine = do
+      (b, l) <- getInput
+      let (unkBStr, l', b') = spanLine l b
+          unkTok = T.Token { tkType = TkUnknown
+                           , tkValue = unkBStr
+                           , tkSpan = mkRealSrcSpan l l' }
+      setInput (b', l')
+      pure ([unkTok], False)
+
+
+-- | Get the input
+getInput :: P (StringBuffer, RealSrcLoc)
+getInput = P $ \p@PState { buffer = buf, loc = srcLoc } -> POk p (buf, psRealLoc srcLoc)
+
+-- | Set the input
+setInput :: (StringBuffer, RealSrcLoc) -> P ()
+setInput (buf, srcLoc) =
+  P $ \p@PState{ loc = PsLoc _ buf_loc } ->
+    POk (p { buffer = buf, loc = PsLoc srcLoc buf_loc }) ()
+
+tryP :: P a -> MaybeT P a
+tryP (P f) = MaybeT $ P $ \s -> case f s of
+  POk s' a -> POk s' (Just a)
+  PFailed _ -> POk s Nothing
+
+tryOrElse :: Alternative f => a -> f a -> f a
+tryOrElse x p = p <|> pure x
+
+-- | Classify given tokens as appropriate Haskell token type.
+classify :: Lexer.Token -> TokenType
+classify tok =
+  case tok of
+    ITas                   -> TkKeyword
+    ITcase                 -> TkKeyword
+    ITclass                -> TkKeyword
+    ITdata                 -> TkKeyword
+    ITdefault              -> TkKeyword
+    ITderiving             -> TkKeyword
+    ITdo                {} -> TkKeyword
+    ITelse                 -> TkKeyword
+    IThiding               -> TkKeyword
+    ITforeign              -> TkKeyword
+    ITif                   -> TkKeyword
+    ITimport               -> TkKeyword
+    ITin                   -> TkKeyword
+    ITinfix                -> TkKeyword
+    ITinfixl               -> TkKeyword
+    ITinfixr               -> TkKeyword
+    ITinstance             -> TkKeyword
+    ITlet                  -> TkKeyword
+    ITmodule               -> TkKeyword
+    ITnewtype              -> TkKeyword
+    ITof                   -> TkKeyword
+    ITqualified            -> TkKeyword
+    ITthen                 -> TkKeyword
+    ITtype                 -> TkKeyword
+    ITvia                  -> TkKeyword
+    ITwhere                -> TkKeyword
+
+    ITforall            {} -> TkKeyword
+    ITexport               -> TkKeyword
+    ITlabel                -> TkKeyword
+    ITdynamic              -> TkKeyword
+    ITsafe                 -> TkKeyword
+    ITinterruptible        -> TkKeyword
+    ITunsafe               -> TkKeyword
+    ITstdcallconv          -> TkKeyword
+    ITccallconv            -> TkKeyword
+    ITcapiconv             -> TkKeyword
+    ITprimcallconv         -> TkKeyword
+    ITjavascriptcallconv   -> TkKeyword
+    ITmdo               {} -> TkKeyword
+    ITfamily               -> TkKeyword
+    ITrole                 -> TkKeyword
+    ITgroup                -> TkKeyword
+    ITby                   -> TkKeyword
+    ITusing                -> TkKeyword
+    ITpattern              -> TkKeyword
+    ITstatic               -> TkKeyword
+    ITstock                -> TkKeyword
+    ITanyclass             -> TkKeyword
+
+    ITunit                 -> TkKeyword
+    ITsignature            -> TkKeyword
+    ITdependency           -> TkKeyword
+    ITrequires             -> TkKeyword
+
+    ITinline_prag       {} -> TkPragma
+    ITopaque_prag       {} -> TkPragma
+    ITspec_prag         {} -> TkPragma
+    ITspec_inline_prag  {} -> TkPragma
+    ITsource_prag       {} -> TkPragma
+    ITrules_prag        {} -> TkPragma
+    ITwarning_prag      {} -> TkPragma
+    ITdeprecated_prag   {} -> TkPragma
+    ITline_prag         {} -> TkPragma
+    ITcolumn_prag       {} -> TkPragma
+    ITscc_prag          {} -> TkPragma
+    ITunpack_prag       {} -> TkPragma
+    ITnounpack_prag     {} -> TkPragma
+    ITann_prag          {} -> TkPragma
+    ITcomplete_prag     {} -> TkPragma
+    ITclose_prag           -> TkPragma
+    IToptions_prag      {} -> TkPragma
+    ITinclude_prag      {} -> TkPragma
+    ITlanguage_prag        -> TkPragma
+    ITminimal_prag      {} -> TkPragma
+    IToverlappable_prag {} -> TkPragma
+    IToverlapping_prag  {} -> TkPragma
+    IToverlaps_prag     {} -> TkPragma
+    ITincoherent_prag   {} -> TkPragma
+    ITctype             {} -> TkPragma
+
+    ITdotdot               -> TkGlyph
+    ITcolon                -> TkGlyph
+    ITdcolon            {} -> TkGlyph
+    ITequal                -> TkGlyph
+    ITlam                  -> TkGlyph
+    ITlcase                -> TkGlyph
+    ITlcases               -> TkGlyph
+    ITvbar                 -> TkGlyph
+    ITlarrow            {} -> TkGlyph
+    ITrarrow            {} -> TkGlyph
+    ITlolly             {} -> TkGlyph
+    ITat                   -> TkGlyph
+    ITtilde                -> TkGlyph
+    ITdarrow            {} -> TkGlyph
+    ITminus                -> TkGlyph
+    ITprefixminus          -> TkGlyph
+    ITbang                 -> TkGlyph
+    ITdot                  -> TkOperator
+    ITproj              {} -> TkOperator
+    ITstar              {} -> TkOperator
+    ITtypeApp              -> TkGlyph
+    ITpercent              -> TkGlyph
+
+    ITbiglam               -> TkGlyph
+
+    ITocurly               -> TkSpecial
+    ITccurly               -> TkSpecial
+    ITvocurly              -> TkSpecial
+    ITvccurly              -> TkSpecial
+    ITobrack               -> TkSpecial
+    ITopabrack             -> TkSpecial
+    ITcpabrack             -> TkSpecial
+    ITcbrack               -> TkSpecial
+    IToparen               -> TkSpecial
+    ITcparen               -> TkSpecial
+    IToubxparen            -> TkSpecial
+    ITcubxparen            -> TkSpecial
+    ITsemi                 -> TkSpecial
+    ITcomma                -> TkSpecial
+    ITunderscore           -> TkIdentifier
+    ITbackquote            -> TkSpecial
+    ITsimpleQuote          -> TkSpecial
+
+    ITvarid             {} -> TkIdentifier
+    ITconid             {} -> TkIdentifier
+    ITvarsym            {} -> TkOperator
+    ITconsym            {} -> TkOperator
+    ITqvarid            {} -> TkIdentifier
+    ITqconid            {} -> TkIdentifier
+    ITqvarsym           {} -> TkOperator
+    ITqconsym           {} -> TkOperator
+
+    ITdupipvarid        {} -> TkUnknown
+    ITlabelvarid        {} -> TkUnknown
+
+    ITchar              {} -> TkChar
+    ITstring            {} -> TkString
+    ITinteger           {} -> TkNumber
+    ITrational          {} -> TkNumber
+
+    ITprimchar          {} -> TkChar
+    ITprimstring        {} -> TkString
+    ITprimint           {} -> TkNumber
+    ITprimword          {} -> TkNumber
+    ITprimfloat         {} -> TkNumber
+    ITprimdouble        {} -> TkNumber
+
+    ITopenExpQuote      {} -> TkSpecial
+    ITopenPatQuote         -> TkSpecial
+    ITopenDecQuote         -> TkSpecial
+    ITopenTypQuote         -> TkSpecial
+    ITcloseQuote        {} -> TkSpecial
+    ITopenTExpQuote     {} -> TkSpecial
+    ITcloseTExpQuote       -> TkSpecial
+    ITdollar               -> TkSpecial
+    ITdollardollar         -> TkSpecial
+    ITtyQuote              -> TkSpecial
+    ITquasiQuote        {} -> TkUnknown
+    ITqQuasiQuote       {} -> TkUnknown
+
+    ITproc                 -> TkKeyword
+    ITrec                  -> TkKeyword
+    IToparenbar         {} -> TkGlyph
+    ITcparenbar         {} -> TkGlyph
+    ITlarrowtail        {} -> TkGlyph
+    ITrarrowtail        {} -> TkGlyph
+    ITLarrowtail        {} -> TkGlyph
+    ITRarrowtail        {} -> TkGlyph
+
+    ITcomment_line_prag    -> TkUnknown
+    ITunknown           {} -> TkUnknown
+    ITeof                  -> TkUnknown
+
+    ITlineComment       {} -> TkComment
+    ITdocComment        {} -> TkComment
+    ITdocOptions        {} -> TkComment
+
+    -- The lexer considers top-level pragmas as comments (see `pragState` in
+    -- the GHC lexer for more), so we have to manually reverse this. The
+    -- following is a hammer: it smashes _all_ pragma-like block comments into
+    -- pragmas.
+    ITblockComment c _
+      | isPrefixOf "{-#" c
+      , isSuffixOf "#-}" c -> TkPragma
+      | otherwise          -> TkComment
+
+-- | Classify given tokens as beginning pragmas (or not).
+inPragma :: Bool           -- ^ currently in pragma
+         -> Lexer.Token    -- ^ current token
+         -> Bool           -- ^ new information about whether we are in a pragma
+inPragma _ ITclose_prag = False
+inPragma True _ = True
+inPragma False tok =
+  case tok of
+    ITinline_prag       {} -> True
+    ITopaque_prag       {} -> True
+    ITspec_prag         {} -> True
+    ITspec_inline_prag  {} -> True
+    ITsource_prag       {} -> True
+    ITrules_prag        {} -> True
+    ITwarning_prag      {} -> True
+    ITdeprecated_prag   {} -> True
+    ITline_prag         {} -> True
+    ITcolumn_prag       {} -> True
+    ITscc_prag          {} -> True
+    ITunpack_prag       {} -> True
+    ITnounpack_prag     {} -> True
+    ITann_prag          {} -> True
+    ITcomplete_prag     {} -> True
+    IToptions_prag      {} -> True
+    ITinclude_prag      {} -> True
+    ITlanguage_prag        -> True
+    ITminimal_prag      {} -> True
+    IToverlappable_prag {} -> True
+    IToverlapping_prag  {} -> True
+    IToverlaps_prag     {} -> True
+    ITincoherent_prag   {} -> True
+    ITctype             {} -> True
+
+    _                      -> False
+
diff --git a/haddock-api/src/Haddock/Backends/Hyperlinker/Renderer.hs b/haddock-api/src/Haddock/Backends/Hyperlinker/Renderer.hs
new file mode 100644
--- /dev/null
+++ b/haddock-api/src/Haddock/Backends/Hyperlinker/Renderer.hs
@@ -0,0 +1,294 @@
+{-# LANGUAGE RecordWildCards #-}
+{-# LANGUAGE ViewPatterns #-}
+{-# LANGUAGE OverloadedStrings #-}
+{-# LANGUAGE BangPatterns #-}
+
+module Haddock.Backends.Hyperlinker.Renderer (render) where
+
+
+import Haddock.Backends.Hyperlinker.Types
+import Haddock.Backends.Hyperlinker.Utils
+
+import qualified Data.ByteString as BS
+
+import GHC.Iface.Ext.Types
+import GHC.Iface.Ext.Utils ( isEvidenceContext , emptyNodeInfo )
+import GHC.Unit.Module ( ModuleName, moduleNameString )
+import GHC.Types.Name   ( getOccString, isInternalName, Name, nameModule, nameUnique )
+import GHC.Types.SrcLoc
+import GHC.Types.Unique ( getKey )
+import GHC.Utils.Encoding ( utf8DecodeByteString )
+
+import System.FilePath.Posix ((</>))
+
+import qualified Data.Map as Map
+import qualified Data.Set as Set
+import qualified Data.List as List
+
+import Text.XHtml (Html, HtmlAttr, (!))
+import qualified Text.XHtml as Html
+
+
+type StyleClass = String
+
+-- | Produce the HTML corresponding to a hyperlinked Haskell source
+render
+  :: Maybe FilePath    -- ^ path to the CSS file
+  -> Maybe FilePath    -- ^ path to the JS file
+  -> SrcMaps            -- ^ Paths to sources
+  -> HieAST PrintedType  -- ^ ASTs from @.hie@ files
+  -> [Token]       -- ^ tokens to render
+  -> Html
+render mcss mjs srcs ast tokens = header mcss mjs <> body srcs ast tokens
+
+body :: SrcMaps -> HieAST PrintedType -> [Token] -> Html
+body srcs ast tokens = Html.body . Html.pre $ hypsrc
+  where
+    hypsrc = renderWithAst srcs ast tokens
+
+header :: Maybe FilePath -> Maybe FilePath -> Html
+header Nothing Nothing = Html.noHtml
+header mcss mjs = Html.header $ css mcss <> js mjs
+  where
+    css Nothing = Html.noHtml
+    css (Just cssFile) = Html.thelink Html.noHtml !
+        [ Html.rel "stylesheet"
+        , Html.thetype "text/css"
+        , Html.href cssFile
+        ]
+    js Nothing = Html.noHtml
+    js (Just scriptFile) = Html.script Html.noHtml !
+        [ Html.thetype "text/javascript"
+        , Html.src scriptFile
+        ]
+
+
+splitTokens :: HieAST PrintedType -> [Token] -> ([Token],[Token],[Token])
+splitTokens ast toks = (before,during,after)
+  where
+    (before,rest) = span leftOf toks
+    (during,after) = span inAst rest
+    leftOf t = realSrcSpanEnd (tkSpan t) <= realSrcSpanStart nodeSp
+    inAst t = nodeSp `containsSpan` tkSpan t
+    nodeSp = nodeSpan ast
+
+-- | Turn a list of tokens into hyperlinked sources, threading in relevant link
+-- information from the 'HieAST'.
+renderWithAst :: SrcMaps -> HieAST PrintedType -> [Token] -> Html
+renderWithAst srcs Node{..} toks = anchored $ case toks of
+
+    [tok] | nodeSpan == tkSpan tok -> richToken srcs nodeInfo tok
+
+    -- NB: the GHC lexer lexes backquoted identifiers and parenthesized operators
+    -- as multiple tokens.
+    --
+    --  * @a `elem` b@ turns into @[a, `, elem, `, b]@ (excluding space tokens)
+    --  * @(+) 1 2@    turns into @[(, +, ), 1, 2]@    (excluding space tokens)
+    --
+    -- However, the HIE ast considers @`elem`@ and @(+)@ to be single nodes. In
+    -- order to make sure these get hyperlinked properly, we intercept these
+    -- special sequences of tokens and merge them into just one identifier or
+    -- operator token.
+    [BacktickTok s1, tok@Token{ tkType = TkIdentifier }, BacktickTok s2]
+          | realSrcSpanStart s1 == realSrcSpanStart nodeSpan
+          , realSrcSpanEnd s2   == realSrcSpanEnd nodeSpan
+          -> richToken srcs nodeInfo
+                       (Token{ tkValue = "`" <> tkValue tok <> "`"
+                             , tkType = TkOperator
+                             , tkSpan = nodeSpan })
+    [OpenParenTok s1, tok@Token{ tkType = TkOperator }, CloseParenTok s2]
+          | realSrcSpanStart s1 == realSrcSpanStart nodeSpan
+          , realSrcSpanEnd s2   == realSrcSpanEnd nodeSpan
+          -> richToken srcs nodeInfo
+                       (Token{ tkValue = "(" <> tkValue tok <> ")"
+                             , tkType = TkOperator
+                             , tkSpan = nodeSpan })
+
+    _ -> go nodeChildren toks
+  where
+    nodeInfo = maybe emptyNodeInfo id (Map.lookup SourceInfo $ getSourcedNodeInfo sourcedNodeInfo)
+    go _ [] = mempty
+    go [] xs = foldMap renderToken xs
+    go (cur:rest) xs =
+        foldMap renderToken before <> renderWithAst srcs cur during <> go rest after
+      where
+        (before,during,after) = splitTokens cur xs
+    anchored c = Map.foldrWithKey anchorOne c (nodeIdentifiers nodeInfo)
+    anchorOne n dets c = externalAnchor n d $ internalAnchor n d c
+      where d = identInfo dets
+
+renderToken :: Token -> Html
+renderToken Token{..}
+    | BS.null tkValue = mempty
+    | tkType == TkSpace = renderSpace (srcSpanStartLine tkSpan) tkValue'
+    | otherwise = tokenSpan ! [ multiclass style ]
+  where
+    tkValue' = filterCRLF $ utf8DecodeByteString tkValue
+    style = tokenStyle tkType
+    tokenSpan = Html.thespan (Html.toHtml tkValue')
+
+
+-- | Given information about the source position of definitions, render a token
+richToken :: SrcMaps -> NodeInfo PrintedType -> Token -> Html
+richToken srcs details Token{..}
+    | tkType == TkSpace = renderSpace (srcSpanStartLine tkSpan) tkValue'
+    | otherwise = annotate details $ linked content
+  where
+    tkValue' = filterCRLF $ utf8DecodeByteString tkValue
+    content = tokenSpan ! [ multiclass style ]
+    tokenSpan = Html.thespan (Html.toHtml tkValue')
+    style = tokenStyle tkType ++ concatMap (richTokenStyle (null (nodeType details))) contexts
+
+    contexts = concatMap (Set.elems . identInfo) . Map.elems . nodeIdentifiers $ details
+
+    -- pick an arbitrary non-evidence identifier to hyperlink with
+    identDet = Map.lookupMin $ Map.filter notEvidence $ nodeIdentifiers details
+    notEvidence = not . any isEvidenceContext . identInfo
+
+    -- If we have name information, we can make links
+    linked = case identDet of
+      Just (n,_) -> hyperlink srcs n
+      Nothing -> id
+
+-- | Remove CRLFs from source
+filterCRLF :: String -> String
+filterCRLF ('\r':'\n':cs) = '\n' : filterCRLF cs
+filterCRLF (c:cs) = c : filterCRLF cs
+filterCRLF [] = []
+
+annotate :: NodeInfo PrintedType -> Html -> Html
+annotate  ni content =
+    Html.thespan (annot <> content) ! [ Html.theclass "annot" ]
+  where
+    annot
+      | not (null annotation) =
+          Html.thespan (Html.toHtml annotation) ! [ Html.theclass "annottext" ]
+      | otherwise = mempty
+    annotation = typ ++ identTyps
+    typ = unlines (nodeType ni)
+    typedIdents = [ (n,t) | (n, c@(identType -> Just t)) <- Map.toList $ nodeIdentifiers ni
+                          , not (any isEvidenceContext $ identInfo c) ]
+    identTyps
+      | length typedIdents > 1 || null (nodeType ni)
+          = concatMap (\(n,t) -> printName n ++ " :: " ++ t ++ "\n") typedIdents
+      | otherwise = ""
+
+    printName :: Either ModuleName Name -> String
+    printName = either moduleNameString getOccString
+
+richTokenStyle
+  :: Bool         -- ^ are we lacking a type annotation?
+  -> ContextInfo  -- ^ in what context did this token show up?
+  -> [StyleClass]
+richTokenStyle True  Use               = ["hs-type"]
+richTokenStyle False Use               = ["hs-var"]
+richTokenStyle  _    RecField{}        = ["hs-var"]
+richTokenStyle  _    PatternBind{}     = ["hs-var"]
+richTokenStyle  _    MatchBind{}       = ["hs-var"]
+richTokenStyle  _    TyVarBind{}       = ["hs-type"]
+richTokenStyle  _    ValBind{}         = ["hs-var"]
+richTokenStyle  _    TyDecl            = ["hs-type"]
+richTokenStyle  _    ClassTyDecl{}     = ["hs-type"]
+richTokenStyle  _    Decl{}            = ["hs-var"]
+richTokenStyle  _    IEThing{}         = []  -- could be either a value or type
+richTokenStyle  _    EvidenceVarBind{} = []
+richTokenStyle  _    EvidenceVarUse{}  = []
+
+tokenStyle :: TokenType -> [StyleClass]
+tokenStyle TkIdentifier = ["hs-identifier"]
+tokenStyle TkKeyword = ["hs-keyword"]
+tokenStyle TkString = ["hs-string"]
+tokenStyle TkChar = ["hs-char"]
+tokenStyle TkNumber = ["hs-number"]
+tokenStyle TkOperator = ["hs-operator"]
+tokenStyle TkGlyph = ["hs-glyph"]
+tokenStyle TkSpecial = ["hs-special"]
+tokenStyle TkSpace = []
+tokenStyle TkComment = ["hs-comment"]
+tokenStyle TkCpp = ["hs-cpp"]
+tokenStyle TkPragma = ["hs-pragma"]
+tokenStyle TkUnknown = []
+
+multiclass :: [StyleClass] -> HtmlAttr
+multiclass = Html.theclass . unwords
+
+externalAnchor :: Identifier -> Set.Set ContextInfo -> Html -> Html
+externalAnchor (Right name) contexts content
+  | not (isInternalName name)
+  , any isBinding contexts
+  = Html.thespan content ! [ Html.identifier $ externalAnchorIdent name ]
+externalAnchor _ _ content = content
+
+isBinding :: ContextInfo -> Bool
+isBinding (ValBind RegularBind _ _) = True
+isBinding PatternBind{} = True
+isBinding Decl{} = True
+isBinding (RecField RecFieldDecl _) = True
+isBinding TyVarBind{} = True
+isBinding ClassTyDecl{} = True
+isBinding _ = False
+
+internalAnchor :: Identifier -> Set.Set ContextInfo -> Html -> Html
+internalAnchor (Right name) contexts content
+  | isInternalName name
+  , any isBinding contexts
+  = Html.thespan content ! [ Html.identifier $ internalAnchorIdent name ]
+internalAnchor _ _ content = content
+
+externalAnchorIdent :: Name -> String
+externalAnchorIdent = hypSrcNameUrl
+
+internalAnchorIdent :: Name -> String
+internalAnchorIdent = ("local-" ++) . show . getKey . nameUnique
+
+-- | Generate the HTML hyperlink for an identifier
+hyperlink :: SrcMaps -> Identifier -> Html -> Html
+hyperlink (srcs, srcs') ident = case ident of
+    Right name | isInternalName name -> internalHyperlink name
+               | otherwise -> externalNameHyperlink name
+    Left name -> externalModHyperlink name
+
+  where
+    -- In a Nix environment, we have file:// URLs with absolute paths
+    makeHyperlinkUrl url | List.isPrefixOf "file://" url = url
+    makeHyperlinkUrl url = ".." </> url
+
+    internalHyperlink name content =
+        Html.anchor content ! [ Html.href $ "#" ++ internalAnchorIdent name ]
+
+    externalNameHyperlink name content = case Map.lookup mdl srcs of
+        Just SrcLocal -> Html.anchor content !
+            [ Html.href $ hypSrcModuleNameUrl mdl name ]
+        Just (SrcExternal path) ->
+          let hyperlinkUrl = makeHyperlinkUrl path </> hypSrcModuleNameUrl mdl name
+           in Html.anchor content !
+                [ Html.href $ spliceURL Nothing (Just mdl) (Just name) Nothing hyperlinkUrl ]
+        Nothing -> content
+      where
+        mdl = nameModule name
+
+    externalModHyperlink moduleName content =
+        case Map.lookup moduleName srcs' of
+          Just SrcLocal -> Html.anchor content !
+            [ Html.href $ hypSrcModuleUrl' moduleName ]
+          Just (SrcExternal path) ->
+            let hyperlinkUrl = makeHyperlinkUrl path </> hypSrcModuleUrl' moduleName
+             in Html.anchor content !
+                  [ Html.href $ spliceURL' Nothing (Just moduleName) Nothing Nothing hyperlinkUrl ]
+          Nothing -> content
+
+
+renderSpace :: Int -> String -> Html
+renderSpace !_ "" = Html.noHtml
+renderSpace !line ('\n':rest) = mconcat
+    [ Html.thespan (Html.toHtml '\n')
+    , lineAnchor (line + 1)
+    , renderSpace (line + 1) rest
+    ]
+renderSpace line space =
+    let (hspace, rest) = span (/= '\n') space
+    in (Html.thespan . Html.toHtml) hspace <> renderSpace line rest
+
+
+lineAnchor :: Int -> Html
+lineAnchor line = Html.thespan Html.noHtml ! [ Html.identifier $ hypSrcLineUrl line ]
diff --git a/haddock-api/src/Haddock/Backends/Hyperlinker/Types.hs b/haddock-api/src/Haddock/Backends/Hyperlinker/Types.hs
new file mode 100644
--- /dev/null
+++ b/haddock-api/src/Haddock/Backends/Hyperlinker/Types.hs
@@ -0,0 +1,51 @@
+{-# LANGUAGE PatternSynonyms, OverloadedStrings #-}
+module Haddock.Backends.Hyperlinker.Types where
+
+import qualified GHC
+
+import Data.ByteString  ( ByteString )
+
+import Data.Map (Map)
+
+data Token = Token
+    { tkType :: TokenType
+    , tkValue :: ByteString -- ^ UTF-8 encoded
+    , tkSpan :: {-# UNPACK #-} !Span
+    }
+    deriving (Show)
+
+pattern BacktickTok, OpenParenTok, CloseParenTok :: Span -> Token
+pattern BacktickTok   sp = Token TkSpecial "`" sp
+pattern OpenParenTok  sp = Token TkSpecial "(" sp
+pattern CloseParenTok sp = Token TkSpecial ")" sp
+
+type Position = GHC.RealSrcLoc
+type Span = GHC.RealSrcSpan
+
+data TokenType
+    = TkIdentifier
+    | TkKeyword
+    | TkString
+    | TkChar
+    | TkNumber
+    | TkOperator
+    | TkGlyph
+    | TkSpecial
+    | TkSpace
+    | TkComment
+    | TkCpp
+    | TkPragma
+    | TkUnknown
+    deriving (Show, Eq)
+
+-- | Path for making cross-package hyperlinks in generated sources.
+--
+-- Used in 'SrcMap' to determine whether module originates in current package
+-- or in an external package.
+data SrcPath
+    = SrcExternal FilePath
+    | SrcLocal
+
+-- | Mapping from modules to cross-package source paths.
+type SrcMaps = (Map GHC.Module SrcPath, Map GHC.ModuleName SrcPath)
+
diff --git a/haddock-api/src/Haddock/Backends/Hyperlinker/Utils.hs b/haddock-api/src/Haddock/Backends/Hyperlinker/Utils.hs
new file mode 100644
--- /dev/null
+++ b/haddock-api/src/Haddock/Backends/Hyperlinker/Utils.hs
@@ -0,0 +1,144 @@
+{-# LANGUAGE OverloadedStrings #-}
+module Haddock.Backends.Hyperlinker.Utils
+    ( hypSrcDir, hypSrcModuleFile, hypSrcModuleFile'
+    , hypSrcModuleUrl, hypSrcModuleUrl'
+    , hypSrcNameUrl
+    , hypSrcLineUrl
+    , hypSrcModuleNameUrl, hypSrcModuleLineUrl
+    , hypSrcModuleUrlFormat
+    , hypSrcModuleNameUrlFormat, hypSrcModuleLineUrlFormat
+    , spliceURL, spliceURL'
+
+    -- * HIE file processing
+    , PrintedType
+    , recoverFullIfaceTypes
+    ) where
+
+import Haddock.Utils
+import Haddock.Backends.Xhtml.Utils
+
+import GHC
+import GHC.Iface.Ext.Types ( HieAST(..), HieType(..), HieArgs(..), TypeIndex, HieTypeFlat )
+import GHC.Iface.Type
+import GHC.Types.Name      ( getOccFS, getOccString )
+import GHC.Driver.Ppr      ( showSDoc )
+import GHC.Types.Var       ( VarBndr(..), visArg, invisArg, TypeOrConstraint(..) )
+
+import System.FilePath.Posix ((</>), (<.>))
+
+import qualified Data.Array as A
+
+
+{-# INLINE hypSrcDir #-}
+hypSrcDir :: FilePath
+hypSrcDir = "src"
+
+{-# INLINE hypSrcModuleFile #-}
+hypSrcModuleFile :: Module -> FilePath
+hypSrcModuleFile m = moduleNameString (moduleName m) <.> "html"
+
+hypSrcModuleFile' :: ModuleName -> FilePath
+hypSrcModuleFile' mdl = spliceURL'
+    Nothing (Just mdl) Nothing Nothing moduleFormat
+
+hypSrcModuleUrl :: Module -> String
+hypSrcModuleUrl = hypSrcModuleFile
+
+hypSrcModuleUrl' :: ModuleName -> String
+hypSrcModuleUrl' = hypSrcModuleFile'
+
+{-# INLINE hypSrcNameUrl #-}
+hypSrcNameUrl :: Name -> String
+hypSrcNameUrl = escapeStr . getOccString
+
+{-# INLINE hypSrcLineUrl #-}
+hypSrcLineUrl :: Int -> String
+hypSrcLineUrl line = "line-" ++ show line
+
+{-# INLINE hypSrcModuleNameUrl #-}
+hypSrcModuleNameUrl :: Module -> Name -> String
+hypSrcModuleNameUrl mdl name = hypSrcModuleUrl mdl ++ "#" ++ hypSrcNameUrl name
+
+{-# INLINE hypSrcModuleLineUrl #-}
+hypSrcModuleLineUrl :: Module -> Int -> String
+hypSrcModuleLineUrl mdl line = hypSrcModuleUrl mdl ++ "#" ++ hypSrcLineUrl line
+
+hypSrcModuleUrlFormat :: String
+hypSrcModuleUrlFormat = hypSrcDir </> moduleFormat
+
+hypSrcModuleNameUrlFormat :: String
+hypSrcModuleNameUrlFormat = hypSrcModuleUrlFormat ++ "#" ++ nameFormat
+
+hypSrcModuleLineUrlFormat :: String
+hypSrcModuleLineUrlFormat = hypSrcModuleUrlFormat ++ "#" ++ lineFormat
+
+moduleFormat :: String
+moduleFormat = "%{MODULE}.html"
+
+nameFormat :: String
+nameFormat = "%{NAME}"
+
+lineFormat :: String
+lineFormat = "line-%{LINE}"
+
+
+-- * HIE file processing
+
+-- This belongs in GHC.Iface.Ext.Utils...
+
+-- | Pretty-printed type, ready to be turned into HTML by @xhtml@
+type PrintedType = String
+
+-- | Expand the flattened HIE AST into one where the types printed out and
+-- ready for end-users to look at.
+--
+-- Using just primitives found in GHC's HIE utilities, we could write this as
+-- follows:
+--
+-- > 'recoverFullIfaceTypes' dflags hieTypes hieAst
+-- >     = 'fmap' (\ti -> 'showSDoc' df .
+-- >                      'pprIfaceType' $
+-- >                      'recoverFullType' ti hieTypes)
+-- >       hieAst
+--
+-- However, this is very inefficient (both in time and space) because the
+-- multiple calls to 'recoverFullType' don't share intermediate results. This
+-- function fixes that.
+recoverFullIfaceTypes
+  :: DynFlags
+  -> A.Array TypeIndex HieTypeFlat -- ^ flat types
+  -> HieAST TypeIndex              -- ^ flattened AST
+  -> HieAST PrintedType       -- ^ full AST
+recoverFullIfaceTypes df flattened ast = fmap (printed A.!) ast
+    where
+
+    -- Splitting this out into its own array is also important: we don't want
+    -- to pretty print the same type many times
+    printed :: A.Array TypeIndex PrintedType
+    printed = fmap (showSDoc df . pprIfaceType) unflattened
+
+    -- The recursion in 'unflattened' is crucial - it's what gives us sharing
+    -- between the IfaceType's produced
+    unflattened :: A.Array TypeIndex IfaceType
+    unflattened = fmap (\flatTy -> go (fmap (unflattened A.!) flatTy)) flattened
+
+    -- Unfold an 'HieType' whose subterms have already been unfolded
+    go :: HieType IfaceType -> IfaceType
+    go (HTyVarTy n) = IfaceTyVar (getOccFS n)
+    go (HAppTy a b) = IfaceAppTy a (hieToIfaceArgs b)
+    go (HLitTy l) = IfaceLitTy l
+    go (HForAllTy ((n,k),af) t) = let b = (getOccFS n, k)
+                                  in IfaceForAllTy (Bndr (IfaceTvBndr b) af) t
+    go (HFunTy w a b)  = IfaceFunTy (visArg TypeLike)   w a b          -- t1 -> t2
+    go (HQualTy con b) = IfaceFunTy (invisArg TypeLike) many_ty con b  -- c => t
+    go (HCastTy a) = a
+    go HCoercionTy = IfaceTyVar "<coercion type>"
+    go (HTyConApp a xs) = IfaceTyConApp a (hieToIfaceArgs xs)
+
+    -- This isn't fully faithful - we can't produce the 'Inferred' case
+    hieToIfaceArgs :: HieArgs IfaceType -> IfaceAppArgs
+    hieToIfaceArgs (HieArgs args) = go' args
+      where
+        go' [] = IA_Nil
+        go' ((True ,x):xs) = IA_Arg x Required $ go' xs
+        go' ((False,x):xs) = IA_Arg x Specified $ go' xs
diff --git a/haddock-api/src/Haddock/Backends/LaTeX.hs b/haddock-api/src/Haddock/Backends/LaTeX.hs
new file mode 100644
--- /dev/null
+++ b/haddock-api/src/Haddock/Backends/LaTeX.hs
@@ -0,0 +1,1464 @@
+{-# OPTIONS_GHC -fno-warn-name-shadowing #-}
+{-# LANGUAGE RecordWildCards #-}
+{-# LANGUAGE TypeFamilies #-}
+
+-----------------------------------------------------------------------------
+-- |
+-- Module      :  Haddock.Backends.LaTeX
+-- Copyright   :  (c) Simon Marlow      2010,
+--                    Mateusz Kowalczyk 2013
+-- License     :  BSD-like
+--
+-- Maintainer  :  haddock@projects.haskell.org
+-- Stability   :  experimental
+-- Portability :  portable
+-----------------------------------------------------------------------------
+module Haddock.Backends.LaTeX (
+  ppLaTeX,
+) where
+
+import Documentation.Haddock.Markup
+import Haddock.Doc (combineDocumentation)
+import Haddock.Types
+import Haddock.Utils
+import Haddock.GhcUtils
+import GHC.Utils.Ppr hiding (Doc, quote)
+import qualified GHC.Utils.Ppr as Pretty
+
+import GHC hiding (fromMaybeContext )
+import GHC.Types.Name.Occurrence
+import GHC.Types.Name        ( nameOccName )
+import GHC.Types.Name.Reader ( rdrNameOcc )
+import GHC.Core.Type         ( Specificity(..) )
+import GHC.Data.FastString   ( unpackFS )
+
+import qualified Data.Map as Map
+import System.Directory
+import System.FilePath
+import Data.Char
+import Control.Monad
+import Data.Maybe
+import Data.List            ( sort )
+import Data.List.NonEmpty ( NonEmpty (..) )
+import Data.Foldable ( toList )
+import Prelude hiding ((<>))
+
+{- SAMPLE OUTPUT
+
+\haddockmoduleheading{\texttt{Data.List}}
+\hrulefill
+{\haddockverb\begin{verbatim}
+module Data.List (
+    (++),  head,  last,  tail,  init,  null,  length,  map,  reverse,
+  ) where\end{verbatim}}
+\hrulefill
+
+\section{Basic functions}
+\begin{haddockdesc}
+\item[\begin{tabular}{@{}l}
+head\ ::\ {\char 91}a{\char 93}\ ->\ a
+\end{tabular}]\haddockbegindoc
+Extract the first element of a list, which must be non-empty.
+\par
+
+\end{haddockdesc}
+\begin{haddockdesc}
+\item[\begin{tabular}{@{}l}
+last\ ::\ {\char 91}a{\char 93}\ ->\ a
+\end{tabular}]\haddockbegindoc
+Extract the last element of a list, which must be finite and non-empty.
+\par
+
+\end{haddockdesc}
+-}
+
+
+{- TODO
+ * don't forget fixity!!
+-}
+
+ppLaTeX :: String                       -- Title
+        -> Maybe String                 -- Package name
+        -> [Interface]
+        -> FilePath                     -- destination directory
+        -> Maybe (Doc GHC.RdrName)      -- prologue text, maybe
+        -> Maybe String                 -- style file
+        -> FilePath
+        -> IO ()
+
+ppLaTeX title packageStr visible_ifaces odir prologue maybe_style libdir
+ = do
+   createDirectoryIfMissing True odir
+   when (isNothing maybe_style) $
+     copyFile (libdir </> "latex" </> haddockSty) (odir </> haddockSty)
+   ppLaTeXTop title packageStr odir prologue maybe_style visible_ifaces
+   mapM_ (ppLaTeXModule title odir) visible_ifaces
+
+
+haddockSty :: FilePath
+haddockSty = "haddock.sty"
+
+
+type LaTeX = Pretty.Doc
+
+-- | Default way of rendering a 'LaTeX'. The width is 90 by default (since 100
+-- often overflows the line).
+latex2String :: LaTeX -> String
+latex2String = fullRender (PageMode True) 90 1 txtPrinter ""
+
+ppLaTeXTop
+   :: String
+   -> Maybe String
+   -> FilePath
+   -> Maybe (Doc GHC.RdrName)
+   -> Maybe String
+   -> [Interface]
+   -> IO ()
+
+ppLaTeXTop doctitle packageStr odir prologue maybe_style ifaces = do
+
+  let tex = vcat [
+        text "\\documentclass{book}",
+        text "\\usepackage" <> braces (maybe (text "haddock") text maybe_style),
+        text "\\begin{document}",
+        text "\\begin{titlepage}",
+        text "\\begin{haddocktitle}",
+        text doctitle,
+        text "\\end{haddocktitle}",
+        case prologue of
+           Nothing -> empty
+           Just d  -> vcat [text "\\begin{haddockprologue}",
+                            rdrDocToLaTeX d,
+                            text "\\end{haddockprologue}"],
+        text "\\end{titlepage}",
+        text "\\tableofcontents",
+        vcat [ text "\\input" <> braces (text mdl) | mdl <- mods ],
+        text "\\end{document}"
+        ]
+
+      mods = sort (map (moduleBasename.ifaceMod) ifaces)
+
+      filename = odir </> (fromMaybe "haddock" packageStr <.> "tex")
+
+  writeUtf8File filename (show tex)
+
+
+ppLaTeXModule :: String -> FilePath -> Interface -> IO ()
+ppLaTeXModule _title odir iface = do
+  createDirectoryIfMissing True odir
+  let
+      mdl = ifaceMod iface
+      mdl_str = moduleString mdl
+
+      exports = ifaceRnExportItems iface
+
+      tex = vcat [
+        text "\\haddockmoduleheading" <> braces (text mdl_str),
+        text "\\label{module:" <> text mdl_str <> char '}',
+        text "\\haddockbeginheader",
+        verb $ vcat [
+           text "module" <+> text mdl_str <+> lparen,
+           text "    " <> fsep (punctuate (char ',') $
+                               map exportListItem $
+                               filter forSummary exports),
+           text "  ) where"
+         ],
+        text "\\haddockendheader" $$ text "",
+        description,
+        body
+       ]
+
+      description
+          = (fromMaybe empty . documentationToLaTeX . ifaceRnDoc) iface
+
+      body = processExports exports
+  --
+  writeUtf8File (odir </> moduleLaTeXFile mdl) (fullRender (PageMode True) 80 1 txtPrinter "" tex)
+
+-- | Prints out an entry in a module export list.
+exportListItem :: ExportItem DocNameI -> LaTeX
+exportListItem
+    ( ExportDecl
+      ( RnExportD
+        { rnExpDExpD =
+          ( ExportD
+            { expDDecl    = decl
+            , expDSubDocs = subdocs
+            }
+          )
+        }
+      )
+    )
+  = let (leader, names) = declNames decl
+    in sep (punctuate comma [ leader <+> ppDocBinder name | name <- names ]) <>
+         case subdocs of
+           [] -> empty
+           _  -> parens (sep (punctuate comma (map (ppDocBinder . fst) subdocs)))
+exportListItem (ExportNoDecl y [])
+  = ppDocBinder y
+exportListItem (ExportNoDecl y subs)
+  = ppDocBinder y <> parens (sep (punctuate comma (map ppDocBinder subs)))
+exportListItem (ExportModule mdl)
+  = text "module" <+> text (moduleString mdl)
+exportListItem _
+  = error "exportListItem"
+
+
+-- Deal with a group of undocumented exports together, to avoid lots
+-- of blank vertical space between them.
+processExports :: [ExportItem DocNameI] -> LaTeX
+processExports [] = empty
+processExports (decl : es)
+  | Just sig <- isSimpleSig decl
+  = multiDecl [ ppTypeSig (map getName names) typ False
+              | (names,typ) <- sig:sigs ] $$
+    processExports es'
+  where (sigs, es') = spanWith isSimpleSig es
+processExports (ExportModule mdl : es)
+  = declWithDoc (vcat [ text "module" <+> text (moduleString m) | m <- mdl:mdls ]) Nothing $$
+    processExports es'
+  where (mdls, es') = spanWith isExportModule es
+processExports (e : es) =
+  processExport e $$ processExports es
+
+
+isSimpleSig :: ExportItem DocNameI -> Maybe ([DocName], HsSigType DocNameI)
+isSimpleSig
+    ( ExportDecl
+      ( RnExportD
+        { rnExpDExpD =
+          ExportD
+          { expDDecl  = L _ (SigD _ (TypeSig _ lnames t))
+          , expDMbDoc = (Documentation Nothing Nothing, argDocs)
+          }
+        }
+      )
+    )
+    | Map.null argDocs = Just (map unLoc lnames, unLoc (dropWildCards t))
+isSimpleSig _ = Nothing
+
+
+isExportModule :: ExportItem DocNameI -> Maybe Module
+isExportModule (ExportModule m) = Just m
+isExportModule _ = Nothing
+
+
+processExport :: ExportItem DocNameI -> LaTeX
+processExport (ExportGroup lev _id0 doc)
+  = ppDocGroup lev (docToLaTeX doc)
+processExport (ExportDecl (RnExportD (ExportD decl pats doc subdocs insts fixities _splice) _))
+  = ppDecl decl pats doc insts subdocs fixities
+processExport (ExportNoDecl y [])
+  = ppDocName y
+processExport (ExportNoDecl y subs)
+  = ppDocName y <> parens (sep (punctuate comma (map ppDocName subs)))
+processExport (ExportModule mdl)
+  = declWithDoc (text "module" <+> text (moduleString mdl)) Nothing
+processExport (ExportDoc doc)
+  = docToLaTeX $ _doc doc
+
+
+ppDocGroup :: Int -> LaTeX -> LaTeX
+ppDocGroup lev doc = sec lev <> braces doc
+  where sec 1 = text "\\section"
+        sec 2 = text "\\subsection"
+        sec 3 = text "\\subsubsection"
+        sec _ = text "\\paragraph"
+
+
+-- | Given a declaration, extract out the names being declared
+declNames :: LHsDecl DocNameI
+          -> ( LaTeX           --   to print before each name in an export list
+             , [DocName]       --   names being declared
+             )
+declNames (L _ decl) = case decl of
+  TyClD _ d  -> (empty, [tcdNameI d])
+  SigD _ (TypeSig _ lnames _ ) -> (empty, map unLoc lnames)
+  SigD _ (PatSynSig _ lnames _) -> (text "pattern", map unLoc lnames)
+  ForD _ (ForeignImport _ (L _ n) _ _) -> (empty, [n])
+  ForD _ (ForeignExport _ (L _ n) _ _) -> (empty, [n])
+  _ -> error "declaration not supported by declNames"
+
+
+forSummary :: (ExportItem DocNameI) -> Bool
+forSummary (ExportGroup _ _ _) = False
+forSummary (ExportDoc _)       = False
+forSummary _                    = True
+
+
+moduleLaTeXFile :: Module -> FilePath
+moduleLaTeXFile mdl = moduleBasename mdl ++ ".tex"
+
+
+moduleBasename :: Module -> FilePath
+moduleBasename mdl = map (\c -> if c == '.' then '-' else c)
+                         (moduleNameString (moduleName mdl))
+
+
+-------------------------------------------------------------------------------
+-- * Decls
+-------------------------------------------------------------------------------
+
+-- | Pretty print a declaration
+ppDecl :: LHsDecl DocNameI                         -- ^ decl to print
+       -> [(HsDecl DocNameI, DocForDecl DocName)]  -- ^ all pattern decls
+       -> DocForDecl DocName                       -- ^ documentation for decl
+       -> [DocInstance DocNameI]                   -- ^ all instances
+       -> [(DocName, DocForDecl DocName)]          -- ^ all subdocs
+       -> [(DocName, Fixity)]                      -- ^ all fixities
+       -> LaTeX
+
+ppDecl decl pats (doc, fnArgsDoc) instances subdocs _fxts = case unLoc decl of
+  TyClD _ d@FamDecl {}           -> ppFamDecl False doc instances d unicode
+  TyClD _ d@DataDecl {}          -> ppDataDecl pats instances subdocs (Just doc) d unicode
+  TyClD _ d@SynDecl {}           -> ppTySyn (doc, fnArgsDoc) d unicode
+  TyClD _ d@ClassDecl{}          -> ppClassDecl instances doc subdocs d unicode
+  SigD _ (TypeSig _ lnames ty)   -> ppFunSig Nothing (doc, fnArgsDoc) (map unLoc lnames) (dropWildCards ty) unicode
+  SigD _ (PatSynSig _ lnames ty) -> ppLPatSig (doc, fnArgsDoc) (map unLoc lnames) ty unicode
+  ForD _ d                       -> ppFor (doc, fnArgsDoc) d unicode
+  InstD _ _                      -> empty
+  DerivD _ _                     -> empty
+  _                              -> error "declaration not supported by ppDecl"
+  where
+    unicode = False
+
+
+ppFor :: DocForDecl DocName -> ForeignDecl DocNameI -> Bool -> LaTeX
+ppFor doc (ForeignImport _ (L _ name) typ _) unicode =
+  ppFunSig Nothing doc [name] typ unicode
+ppFor _ _ _ = error "ppFor error in Haddock.Backends.LaTeX"
+--  error "foreign declarations are currently not supported by --latex"
+
+
+-------------------------------------------------------------------------------
+-- * Type families
+-------------------------------------------------------------------------------
+
+-- | Pretty-print a data\/type family declaration
+ppFamDecl :: Bool                     -- ^ is the family associated?
+          -> Documentation DocName    -- ^ this decl's docs
+          -> [DocInstance DocNameI]   -- ^ relevant instances
+          -> TyClDecl DocNameI        -- ^ family to print
+          -> Bool                     -- ^ unicode
+          -> LaTeX
+ppFamDecl associated doc instances decl unicode =
+  declWithDoc (ppFamHeader (tcdFam decl) unicode associated <+> whereBit)
+              (if null body then Nothing else Just (vcat body))
+  $$ instancesBit
+  where
+    body = catMaybes [familyEqns, documentationToLaTeX doc]
+
+    whereBit = case fdInfo (tcdFam decl) of
+      ClosedTypeFamily _ -> keyword "where"
+      _                  -> empty
+
+    familyEqns
+      | FamilyDecl { fdInfo = ClosedTypeFamily (Just eqns) } <- tcdFam decl
+      , not (null eqns)
+      = Just (text "\\haddockbeginargs" $$
+              vcat [ decltt (ppFamDeclEqn eqn) <+> nl | L _ eqn <- eqns ] $$
+              text "\\end{tabulary}\\par")
+      | otherwise = Nothing
+
+    -- Individual equations of a closed type family
+    ppFamDeclEqn :: TyFamInstEqn DocNameI -> LaTeX
+    ppFamDeclEqn (FamEqn { feqn_tycon = L _ n
+                         , feqn_rhs = rhs
+                         , feqn_pats = ts })
+      = hsep [ ppAppNameTypeArgs n ts unicode
+             , equals
+             , ppType unicode (unLoc rhs)
+             ]
+
+    instancesBit = ppDocInstances unicode instances
+
+-- | Print the LHS of a type\/data family declaration.
+ppFamHeader :: FamilyDecl DocNameI  -- ^ family header to print
+            -> Bool                 -- ^ unicode
+            -> Bool                 -- ^ is the family associated?
+            -> LaTeX
+ppFamHeader (FamilyDecl { fdLName = L _ name
+                        , fdTyVars = tvs
+                        , fdInfo = info
+                        , fdResultSig = L _ result
+                        , fdInjectivityAnn = injectivity })
+              unicode associated =
+  famly leader <+> famName <+> famSig <+> injAnn
+  where
+    leader = case info of
+      OpenTypeFamily     -> keyword "type"
+      ClosedTypeFamily _ -> keyword "type"
+      DataFamily         -> keyword "data"
+
+    famly | associated = id
+          | otherwise = (<+> keyword "family")
+
+    famName = ppAppDocNameTyVarBndrs unicode name (hsq_explicit tvs)
+
+    famSig = case result of
+      NoSig _               -> empty
+      KindSig _ kind        -> dcolon unicode <+> ppLKind unicode kind
+      TyVarSig _ (L _ bndr) -> equals <+> ppHsTyVarBndr unicode bndr
+
+    injAnn = case injectivity of
+      Nothing -> empty
+      Just (L _ (InjectivityAnn _ lhs rhs)) -> hsep ( decltt (text "|")
+                                                    : ppLDocName lhs
+                                                    : arrow unicode
+                                                    : map ppLDocName rhs)
+      Just _ -> empty
+
+
+
+-------------------------------------------------------------------------------
+-- * Type Synonyms
+-------------------------------------------------------------------------------
+
+
+-- we skip type patterns for now
+ppTySyn :: DocForDecl DocName -> TyClDecl DocNameI -> Bool -> LaTeX
+
+ppTySyn doc (SynDecl { tcdLName = L _ name, tcdTyVars = ltyvars
+                         , tcdRhs = ltype }) unicode
+  = ppTypeOrFunSig (mkHsImplicitSigTypeI ltype) doc (full, hdr, char '=') unicode
+  where
+    hdr  = hsep (keyword "type"
+                 : ppDocBinder name
+                 : map ppSymName (tyvarNames ltyvars))
+    full = hdr <+> char '=' <+> ppLType unicode ltype
+
+ppTySyn _ _ _ = error "declaration not supported by ppTySyn"
+
+
+-------------------------------------------------------------------------------
+-- * Function signatures
+-------------------------------------------------------------------------------
+
+
+ppFunSig
+  :: Maybe LaTeX         -- ^ a prefix to put right before the signature
+  -> DocForDecl DocName  -- ^ documentation
+  -> [DocName]           -- ^ pattern names in the pattern signature
+  -> LHsSigType DocNameI -- ^ type of the pattern synonym
+  -> Bool                -- ^ unicode
+  -> LaTeX
+ppFunSig leader doc docnames (L _ typ) unicode =
+  ppTypeOrFunSig typ doc
+    ( lead $ ppTypeSig names typ False
+    , lead $ hsep . punctuate comma $ map ppSymName names
+    , dcolon unicode
+    )
+    unicode
+ where
+   names = map getName docnames
+   lead = maybe id (<+>) leader
+
+-- | Pretty-print a pattern synonym
+ppLPatSig :: DocForDecl DocName  -- ^ documentation
+          -> [DocName]           -- ^ pattern names in the pattern signature
+          -> LHsSigType DocNameI -- ^ type of the pattern synonym
+          -> Bool                -- ^ unicode
+          -> LaTeX
+ppLPatSig doc docnames ty unicode
+  = ppFunSig (Just (keyword "pattern")) doc docnames ty unicode
+
+-- | Pretty-print a type, adding documentation to the whole type and its
+-- arguments as needed.
+ppTypeOrFunSig :: HsSigType DocNameI
+               -> DocForDecl DocName  -- ^ documentation
+               -> ( LaTeX             --   first-line (no-argument docs only)
+                  , LaTeX             --   first-line (argument docs only)
+                  , LaTeX             --   type prefix (argument docs only)
+                  )
+               -> Bool                -- ^ unicode
+               -> LaTeX
+ppTypeOrFunSig typ (doc, argDocs) (pref1, pref2, sep0) unicode
+  | Map.null argDocs = declWithDoc pref1 (documentationToLaTeX doc)
+  | otherwise        = declWithDoc pref2 $ Just $
+        text "\\haddockbeginargs" $$
+        vcat (map (uncurry (<->)) (ppSubSigLike unicode typ argDocs [] sep0)) $$
+        text "\\end{tabulary}\\par" $$
+        fromMaybe empty (documentationToLaTeX doc)
+
+-- | This splits up a type signature along @->@ and adds docs (when they exist)
+-- to the arguments. The output is a list of (leader/seperator, argument and
+-- its doc)
+ppSubSigLike :: Bool                  -- ^ unicode
+             -> HsSigType DocNameI    -- ^ type signature
+             -> FnArgsDoc DocName     -- ^ docs to add
+             -> [(DocName, DocForDecl DocName)] -- ^ all subdocs (useful when we have `HsRecTy`)
+             -> LaTeX                 -- ^ seperator (beginning of first line)
+             -> [(LaTeX, LaTeX)]      -- ^ arguments (leader/sep, type)
+ppSubSigLike unicode typ argDocs subdocs leader = do_sig_args 0 leader typ
+  where
+    do_sig_args :: Int -> LaTeX -> HsSigType DocNameI -> [(LaTeX, LaTeX)]
+    do_sig_args n leader (HsSig { sig_bndrs = outer_bndrs, sig_body = ltype }) =
+      case outer_bndrs of
+        HsOuterExplicit{hso_bndrs = bndrs} ->
+          [ ( decltt leader
+            , decltt (ppHsForAllTelescope (mkHsForAllInvisTeleI bndrs) unicode)
+                <+> ppLType unicode ltype
+            ) ]
+        HsOuterImplicit{} -> do_largs n leader ltype
+
+    do_largs :: Int -> LaTeX -> LHsType DocNameI -> [(LaTeX, LaTeX)]
+    do_largs n leader (L _ t) = do_args n leader t
+
+    arg_doc n = rDoc . fmap _doc $ Map.lookup n argDocs
+
+    do_args :: Int -> LaTeX -> HsType DocNameI -> [(LaTeX, LaTeX)]
+    do_args _n leader (HsForAllTy _ tele ltype)
+      = [ ( decltt leader
+          , decltt (ppHsForAllTelescope tele unicode)
+              <+> ppLType unicode ltype
+          ) ]
+    do_args n leader (HsQualTy _ lctxt ltype)
+      = ( decltt leader
+        , decltt (ppLContextNoArrow lctxt unicode) <+> nl
+        ) : do_largs n (darrow unicode) ltype
+
+    do_args n leader (HsFunTy _ _w (L _ (HsRecTy _ fields)) r)
+      = [ (decltt ldr, latex <+> nl)
+        | (L _ field, ldr) <- zip fields (leader <+> gadtOpen : repeat gadtComma)
+        , let latex = ppSideBySideField subdocs unicode field
+        ]
+        ++ do_largs (n+1) (gadtEnd <+> arrow unicode) r
+    do_args n leader (HsFunTy _ _w lt r)
+      = (decltt leader, decltt (ppLFunLhType unicode lt) <-> arg_doc n <+> nl)
+        : do_largs (n+1) (arrow unicode) r
+    do_args n leader t
+      = [ (decltt leader, decltt (ppType unicode t) <-> arg_doc n <+> nl) ]
+
+    -- FIXME: this should be done more elegantly
+    --
+    -- We need 'gadtComma' and 'gadtEnd' to line up with the `{` from
+    -- 'gadtOpen', so we add 3 spaces to cover for `-> `/`:: ` (3 in unicode
+    -- mode since `->` and `::` are rendered as single characters.
+    gadtComma = hcat (replicate (if unicode then 3 else 4) (char ' ')) <> char ','
+    gadtEnd = hcat (replicate (if unicode then 3 else 4) (char ' ')) <> char '}'
+    gadtOpen = char '{'
+
+
+ppTypeSig :: [Name] -> HsSigType DocNameI  -> Bool -> LaTeX
+ppTypeSig nms ty unicode =
+  hsep (punctuate comma $ map ppSymName nms)
+    <+> dcolon unicode
+    <+> ppSigType unicode ty
+
+ppHsOuterTyVarBndrs :: HsOuterTyVarBndrs flag DocNameI -> Bool -> LaTeX
+ppHsOuterTyVarBndrs (HsOuterImplicit{}) _ = empty
+ppHsOuterTyVarBndrs (HsOuterExplicit{hso_bndrs = bndrs}) unicode =
+    hsep (forallSymbol unicode : ppTyVars bndrs) <> dot
+
+ppHsForAllTelescope :: HsForAllTelescope DocNameI -> Bool -> LaTeX
+ppHsForAllTelescope tele unicode = case tele of
+  HsForAllVis { hsf_vis_bndrs = bndrs } ->
+    hsep (forallSymbol unicode : ppTyVars bndrs) <> text "\\" <> arrow unicode
+  HsForAllInvis { hsf_invis_bndrs = bndrs } ->
+    hsep (forallSymbol unicode : ppTyVars bndrs) <> dot
+
+
+ppTyVars :: [LHsTyVarBndr flag DocNameI] -> [LaTeX]
+ppTyVars = map (ppSymName . getName . hsLTyVarNameI)
+
+
+tyvarNames :: LHsQTyVars DocNameI -> [Name]
+tyvarNames = map (getName . hsLTyVarNameI) . hsQTvExplicit
+
+
+declWithDoc :: LaTeX -> Maybe LaTeX -> LaTeX
+declWithDoc decl doc =
+   text "\\begin{haddockdesc}" $$
+   text "\\item[\\begin{tabular}{@{}l}" $$
+   text (latexMonoFilter (latex2String decl)) $$
+   text "\\end{tabular}]" $$
+   maybe empty (\x -> text "{\\haddockbegindoc" $$ x <> text "}") doc $$
+   text "\\end{haddockdesc}"
+
+
+-- in a group of decls, we don't put them all in the same tabular,
+-- because that would prevent the group being broken over a page
+-- boundary (breaks Foreign.C.Error for example).
+multiDecl :: [LaTeX] -> LaTeX
+multiDecl decls =
+   text "\\begin{haddockdesc}" $$
+   vcat [
+      text "\\item[\\begin{tabular}{@{}l}" $$
+      text (latexMonoFilter (latex2String decl)) $$
+      text "\\end{tabular}]"
+      | decl <- decls ] $$
+   text "\\end{haddockdesc}"
+
+
+-------------------------------------------------------------------------------
+-- * Rendering Doc
+-------------------------------------------------------------------------------
+
+
+maybeDoc :: Maybe (Doc DocName) -> LaTeX
+maybeDoc = maybe empty docToLaTeX
+
+
+-- for table cells, we strip paragraphs out to avoid extra vertical space
+-- and don't add a quote environment.
+rDoc  :: Maybe (Doc DocName) -> LaTeX
+rDoc = maybeDoc . fmap latexStripTrailingWhitespace
+
+
+-------------------------------------------------------------------------------
+-- * Class declarations
+-------------------------------------------------------------------------------
+
+
+ppClassHdr :: Bool -> Maybe (LocatedC [LHsType DocNameI]) -> DocName
+           -> LHsQTyVars DocNameI -> [LHsFunDep DocNameI]
+           -> Bool -> LaTeX
+ppClassHdr summ lctxt n tvs fds unicode =
+  keyword "class"
+  <+> (if not (null $ fromMaybeContext lctxt) then ppLContext lctxt unicode else empty)
+  <+> ppAppDocNameNames summ n (tyvarNames tvs)
+  <+> ppFds fds unicode
+
+-- ppFds :: [Located ([LocatedA DocName], [LocatedA DocName])] -> Bool -> LaTeX
+ppFds :: [LHsFunDep DocNameI] -> Bool -> LaTeX
+ppFds fds unicode =
+  if null fds then empty else
+    char '|' <+> hsep (punctuate comma (map (fundep . unLoc) fds))
+  where
+    fundep (FunDep _ vars1 vars2)
+                         = hsep (map (ppDocName . unLoc) vars1) <+> arrow unicode <+>
+                           hsep (map (ppDocName . unLoc) vars2)
+    fundep (XFunDep _) = error "ppFds"
+
+
+-- TODO: associated type defaults, docs on default methods
+ppClassDecl :: [DocInstance DocNameI]
+            -> Documentation DocName -> [(DocName, DocForDecl DocName)]
+            -> TyClDecl DocNameI -> Bool -> LaTeX
+ppClassDecl instances doc subdocs
+  (ClassDecl { tcdCtxt = lctxt, tcdLName = lname, tcdTyVars = ltyvars, tcdFDs = lfds
+             , tcdSigs = lsigs, tcdATs = ats, tcdATDefs = at_defs }) unicode
+  = declWithDoc classheader (if null body then Nothing else Just (vcat body)) $$
+    instancesBit
+  where
+    classheader
+      | null lsigs = hdr unicode
+      | otherwise  = hdr unicode <+> keyword "where"
+
+    hdr = ppClassHdr False lctxt (unLoc lname) ltyvars lfds
+
+    body = catMaybes [documentationToLaTeX doc, body_]
+
+    body_
+      | null lsigs, null ats, null at_defs = Nothing
+      | null ats, null at_defs = Just methodTable
+      | otherwise = Just (atTable $$ methodTable)
+
+    atTable =
+      text "\\haddockpremethods{}" <> emph (text "Associated Types") $$
+      vcat  [ ppFamDecl True (fst doc) [] (FamDecl noExtField decl) True
+            | L _ decl <- ats
+            , let name = unLoc . fdLName $ decl
+                  doc = lookupAnySubdoc name subdocs
+            ]
+
+
+    methodTable =
+      text "\\haddockpremethods{}" <> emph (text "Methods") $$
+      vcat  [ ppFunSig leader doc names typ unicode
+            | L _ (ClassOpSig _ is_def lnames typ) <- lsigs
+            , let doc | is_def = noDocForDecl
+                      | otherwise = lookupAnySubdoc (head names) subdocs
+                  names = map unLoc lnames
+                  leader = if is_def then Just (keyword "default") else Nothing
+            ]
+            -- N.B. taking just the first name is ok. Signatures with multiple
+            -- names are expanded so that each name gets its own signature.
+
+    instancesBit = ppDocInstances unicode instances
+
+ppClassDecl _ _ _ _ _ = error "declaration type not supported by ppShortClassDecl"
+
+ppDocInstances :: Bool -> [DocInstance DocNameI] -> LaTeX
+ppDocInstances _unicode [] = empty
+ppDocInstances unicode (i : rest)
+  | Just ihead <- isUndocdInstance i
+  = declWithDoc (vcat (map (ppInstDecl unicode) (ihead:is))) Nothing $$
+    ppDocInstances unicode rest'
+  | otherwise
+  = ppDocInstance unicode i $$ ppDocInstances unicode rest
+  where
+    (is, rest') = spanWith isUndocdInstance rest
+
+isUndocdInstance :: DocInstance a -> Maybe (InstHead a)
+isUndocdInstance (i,Nothing,_,_) = Just i
+isUndocdInstance (i,Just (MetaDoc _ DocEmpty),_,_) = Just i
+isUndocdInstance _ = Nothing
+
+-- | Print a possibly commented instance. The instance header is printed inside
+-- an 'argBox'. The comment is printed to the right of the box in normal comment
+-- style.
+ppDocInstance :: Bool -> DocInstance DocNameI -> LaTeX
+ppDocInstance unicode (instHead, doc, _, _) =
+  declWithDoc (ppInstDecl unicode instHead) (fmap docToLaTeX $ fmap _doc doc)
+
+
+ppInstDecl :: Bool -> InstHead DocNameI -> LaTeX
+ppInstDecl unicode (InstHead {..}) = case ihdInstType of
+  ClassInst ctx _ _ _ -> keyword "instance" <+> ppContextNoLocs ctx unicode <+> typ
+  TypeInst rhs -> keyword "type" <+> keyword "instance" <+> typ <+> tibody rhs
+  DataInst dd ->
+    let cons = dd_cons (tcdDataDefn dd)
+        pref = case cons of { NewTypeCon _ -> keyword "newtype"; DataTypeCons _ _ -> keyword "data" }
+    in pref <+> keyword "instance" <+> typ
+  where
+    typ = ppAppNameTypes ihdClsName ihdTypes unicode
+    tibody = maybe empty (\t -> equals <+> ppType unicode t)
+
+lookupAnySubdoc :: (Eq name1) =>
+                   name1 -> [(name1, DocForDecl name2)] -> DocForDecl name2
+lookupAnySubdoc n subdocs = case lookup n subdocs of
+  Nothing -> noDocForDecl
+  Just docs -> docs
+
+
+-------------------------------------------------------------------------------
+-- * Data & newtype declarations
+-------------------------------------------------------------------------------
+
+-- | Pretty-print a data declaration
+ppDataDecl :: [(HsDecl DocNameI, DocForDecl DocName)] -- ^ relevant patterns
+           -> [DocInstance DocNameI]                  -- ^ relevant instances
+           -> [(DocName, DocForDecl DocName)]         -- ^ relevant decl docs
+           -> Maybe (Documentation DocName)           -- ^ this decl's docs
+           -> TyClDecl DocNameI                       -- ^ data decl to print
+           -> Bool                                    -- ^ unicode
+           -> LaTeX
+ppDataDecl pats instances subdocs doc dataDecl unicode =
+   declWithDoc (ppDataHeader dataDecl unicode <+> whereBit)
+               (if null body then Nothing else Just (vcat body))
+   $$ instancesBit
+
+  where
+    cons      = dd_cons (tcdDataDefn dataDecl)
+
+    body = catMaybes [doc >>= documentationToLaTeX, constrBit,patternBit]
+
+    (whereBit, leaders)
+      | null cons
+      , null pats = (empty,[])
+      | null cons = (text "where", repeat empty)
+      | otherwise = case toList cons of
+        L _ ConDeclGADT{} : _ -> (text "where", repeat empty)
+        _             -> (empty, (decltt (text "=") : repeat (decltt (text "|"))))
+
+    constrBit
+      | null cons = Nothing
+      | otherwise = Just $
+          text "\\enspace" <+> emph (text "Constructors") <> text "\\par" $$
+          text "\\haddockbeginconstrs" $$
+          vcat (zipWith (ppSideBySideConstr subdocs unicode) leaders (toList cons)) $$
+          text "\\end{tabulary}\\par"
+
+    patternBit
+      | null pats = Nothing
+      | otherwise = Just $
+          text "\\enspace" <+> emph (text "Bundled Patterns") <> text "\\par" $$
+          text "\\haddockbeginconstrs" $$
+          vcat [ empty <-> ppSideBySidePat lnames typ d unicode
+               | (SigD _ (PatSynSig _ lnames typ), d) <- pats
+               ] $$
+          text "\\end{tabulary}\\par"
+
+    instancesBit = ppDocInstances unicode instances
+
+
+-- ppConstrHdr is for (non-GADT) existentials constructors' syntax
+ppConstrHdr
+  :: Bool                    -- ^ print explicit foralls
+  -> [LHsTyVarBndr Specificity DocNameI] -- ^ type variables
+  -> HsContext DocNameI      -- ^ context
+  -> Bool                    -- ^ unicode
+  -> LaTeX
+ppConstrHdr forall_ tvs ctxt unicode = ppForall <> ppCtxt
+  where
+    ppForall
+      | null tvs || not forall_ = empty
+      | otherwise = ppHsForAllTelescope (mkHsForAllInvisTeleI tvs) unicode
+
+    ppCtxt
+      | null ctxt = empty
+      | otherwise = ppContextNoArrow ctxt unicode <+> darrow unicode <> space
+
+
+-- | Pretty-print a constructor
+ppSideBySideConstr :: [(DocName, DocForDecl DocName)]  -- ^ all decl docs
+                   -> Bool                             -- ^ unicode
+                   -> LaTeX                            -- ^ prefix to decl
+                   -> LConDecl DocNameI                -- ^ constructor decl
+                   -> LaTeX
+ppSideBySideConstr subdocs unicode leader (L _ con) =
+  leader <-> decltt decl <-> rDoc mbDoc <+> nl
+  $$ fieldPart
+  where
+    -- Find the name of a constructors in the decl (`getConName` always returns
+    -- a non-empty list)
+    L _ aConName :| _ = getConNamesI con
+
+    occ      = toList $ nameOccName . getName . unLoc <$> getConNamesI con
+
+    ppOcc      = cat (punctuate comma (map ppBinder occ))
+    ppOccInfix = cat (punctuate comma (map ppBinderInfix occ))
+
+    -- Extract out the map of of docs corresponding to the constructors arguments
+    argDocs = maybe Map.empty snd (lookup aConName subdocs)
+    hasArgDocs = not $ Map.null argDocs
+
+    -- First line of the constructor (no doc, no fields, single-line)
+    decl = case con of
+      ConDeclH98{ con_args = det
+                , con_ex_tvs = tyVars
+                , con_forall = forall_
+                , con_mb_cxt = cxt
+                } -> let context = fromMaybeContext cxt
+                         header_ = ppConstrHdr forall_ tyVars context unicode
+                     in case det of
+        -- Prefix constructor, e.g. 'Just a'
+        PrefixCon _ args
+          | hasArgDocs -> header_ <+> ppOcc
+          | otherwise -> hsep [ header_
+                              , ppOcc
+                              , hsep (map (ppLParendType unicode . hsScaledThing) args)
+                              ]
+
+        -- Record constructor, e.g. 'Identity { runIdentity :: a }'
+        RecCon _ ->  header_ <+> ppOcc
+
+        -- Infix constructor, e.g. 'a :| [a]'
+        InfixCon arg1 arg2
+          | hasArgDocs -> header_ <+> ppOcc
+          | otherwise -> hsep [ header_
+                              , ppLParendType unicode (hsScaledThing arg1)
+                              , ppOccInfix
+                              , ppLParendType unicode (hsScaledThing arg2)
+                              ]
+
+      ConDeclGADT{}
+        | hasArgDocs || not (isEmpty fieldPart) -> ppOcc
+        | otherwise -> hsep [ ppOcc
+                            , dcolon unicode
+                            -- ++AZ++ make this prepend "{..}" when it is a record style GADT
+                            , ppLSigType unicode (getGADTConType con)
+                            ]
+
+    fieldPart = case con of
+        ConDeclGADT{con_g_args = con_args'} -> case con_args' of
+          -- GADT record declarations
+          RecConGADT _ _                  -> doConstrArgsWithDocs []
+          -- GADT prefix data constructors
+          PrefixConGADT args | hasArgDocs -> doConstrArgsWithDocs (map hsScaledThing args)
+          _                               -> empty
+
+        ConDeclH98{con_args = con_args'} -> case con_args' of
+          -- H98 record declarations
+          RecCon (L _ fields)             -> doRecordFields fields
+          -- H98 prefix data constructors
+          PrefixCon _ args | hasArgDocs   -> doConstrArgsWithDocs (map hsScaledThing args)
+          -- H98 infix data constructor
+          InfixCon arg1 arg2 | hasArgDocs -> doConstrArgsWithDocs (map hsScaledThing [arg1,arg2])
+          _                               -> empty
+
+    doRecordFields fields =
+      vcat [ empty <-> tt (text begin) <+> ppSideBySideField subdocs unicode field <+> nl
+           | (begin, L _ field) <- zip ("\\qquad \\{" : repeat "\\qquad ,") fields
+           ]
+      $$
+      empty <-> tt (text "\\qquad \\}") <+> nl
+
+    doConstrArgsWithDocs args = vcat $ map (\l -> empty <-> text "\\qquad" <+> l) $ case con of
+      ConDeclH98{} ->
+        [ decltt (ppLParendType unicode arg) <-> rDoc (fmap _doc mdoc) <+> nl
+        | (i, arg) <- zip [0..] args
+        , let mdoc = Map.lookup i argDocs
+        ]
+      ConDeclGADT{} ->
+        [ l <+> text "\\enspace" <+> r
+        | (l,r) <- ppSubSigLike unicode (unLoc (getGADTConType con)) argDocs subdocs (dcolon unicode)
+        ]
+
+
+    -- don't use "con_doc con", in case it's reconstructed from a .hi file,
+    -- or also because we want Haddock to do the doc-parsing, not GHC.
+    mbDoc = case getConNamesI con of
+              cn:|_ -> lookup (unLoc cn) subdocs >>=
+                        fmap _doc . combineDocumentation . fst
+
+
+-- | Pretty-print a record field
+ppSideBySideField :: [(DocName, DocForDecl DocName)] -> Bool -> ConDeclField DocNameI ->  LaTeX
+ppSideBySideField subdocs unicode (ConDeclField _ names ltype _) =
+  decltt (cat (punctuate comma (map (ppBinder . rdrNameOcc . unLoc . foLabel . unLoc) names))
+    <+> dcolon unicode <+> ppLType unicode ltype) <-> rDoc mbDoc
+  where
+    -- don't use cd_fld_doc for same reason we don't use con_doc above
+    -- Where there is more than one name, they all have the same documentation
+    mbDoc = lookup (foExt $ unLoc $ head names) subdocs >>= fmap _doc . combineDocumentation . fst
+
+
+-- | Pretty-print a bundled pattern synonym
+ppSideBySidePat :: [LocatedN DocName]   -- ^ pattern name(s)
+                -> LHsSigType DocNameI  -- ^ type of pattern(s)
+                -> DocForDecl DocName   -- ^ doc map
+                -> Bool                 -- ^ unicode
+                -> LaTeX
+ppSideBySidePat lnames typ (doc, argDocs) unicode =
+  decltt decl <-> rDoc mDoc <+> nl
+  $$ fieldPart
+  where
+    hasArgDocs = not $ Map.null argDocs
+    ppOcc = hsep (punctuate comma (map (ppDocBinder . unLoc) lnames))
+
+    decl | hasArgDocs = keyword "pattern" <+> ppOcc
+         | otherwise = hsep [ keyword "pattern"
+                            , ppOcc
+                            , dcolon unicode
+                            , ppLSigType unicode typ
+                            ]
+
+    fieldPart
+      | not hasArgDocs = empty
+      | otherwise = vcat
+          [ empty <-> text "\\qquad" <+> l <+> text "\\enspace" <+> r
+          | (l,r) <- ppSubSigLike unicode (unLoc typ) argDocs [] (dcolon unicode)
+          ]
+
+    mDoc = fmap _doc $ combineDocumentation doc
+
+
+-- | Print the LHS of a data\/newtype declaration.
+-- Currently doesn't handle 'data instance' decls or kind signatures
+ppDataHeader :: TyClDecl DocNameI -> Bool -> LaTeX
+ppDataHeader (DataDecl { tcdLName = L _ name, tcdTyVars = tyvars
+                       , tcdDataDefn = HsDataDefn { dd_cons = cons, dd_ctxt = ctxt } }) unicode
+  = -- newtype or data
+    (case cons of
+        { NewTypeCon _ -> keyword "newtype"
+        ; DataTypeCons False _ -> keyword "data"
+        ; DataTypeCons True _ -> keyword "type" <+> keyword "data"
+        }) <+>
+    -- context
+    ppLContext ctxt unicode <+>
+    -- T a b c ..., or a :+: b
+    ppAppDocNameNames False name (tyvarNames tyvars)
+ppDataHeader _ _ = error "ppDataHeader: illegal argument"
+
+
+--------------------------------------------------------------------------------
+-- * Type applications
+--------------------------------------------------------------------------------
+
+ppAppDocNameTyVarBndrs :: RenderableBndrFlag flag =>
+  Bool -> DocName -> [LHsTyVarBndr flag DocNameI] -> LaTeX
+ppAppDocNameTyVarBndrs unicode n vs =
+    ppTypeApp n vs ppDN (ppHsTyVarBndr unicode . unLoc)
+  where
+    ppDN = ppBinder . nameOccName . getName
+
+
+-- | Print an application of a DocName to its list of HsTypes
+ppAppNameTypes :: DocName -> [HsType DocNameI] -> Bool -> LaTeX
+ppAppNameTypes n ts unicode = ppTypeApp n ts ppDocName (ppParendType unicode)
+
+ppAppNameTypeArgs :: DocName -> [LHsTypeArg DocNameI] -> Bool -> LaTeX
+ppAppNameTypeArgs n args@(HsValArg _:HsValArg _:_) unicode
+  = ppTypeApp n args ppDocName (ppLHsTypeArg unicode)
+ppAppNameTypeArgs n args unicode
+  = ppDocName n <+> hsep (map (ppLHsTypeArg unicode) args)
+
+-- | Print an application of a DocName and a list of Names
+ppAppDocNameNames :: Bool -> DocName -> [Name] -> LaTeX
+ppAppDocNameNames _summ n ns =
+  ppTypeApp n ns (ppBinder . nameOccName . getName) ppSymName
+
+
+-- | General printing of type applications
+ppTypeApp :: DocName -> [a] -> (DocName -> LaTeX) -> (a -> LaTeX) -> LaTeX
+ppTypeApp n (t1:t2:rest) ppDN ppT
+  | operator, not . null $ rest = parens opApp <+> hsep (map ppT rest)
+  | operator                    = opApp
+  where
+    operator = isNameSym . getName $ n
+    opApp = ppT t1 <+> ppDN n <+> ppT t2
+
+ppTypeApp n ts ppDN ppT = ppDN n <+> hsep (map ppT ts)
+
+-------------------------------------------------------------------------------
+-- * Contexts
+-------------------------------------------------------------------------------
+
+
+ppLContext :: Maybe (LHsContext DocNameI) -> Bool -> LaTeX
+ppLContext Nothing _ = empty
+ppLContext (Just ctxt) unicode  = ppContext (unLoc ctxt) unicode
+
+ppLContextNoArrow :: LHsContext DocNameI -> Bool -> LaTeX
+ppLContextNoArrow ctxt unicode = ppContextNoArrow (unLoc ctxt) unicode
+
+ppContextNoLocsMaybe :: [HsType DocNameI] -> Bool -> Maybe LaTeX
+ppContextNoLocsMaybe [] _ = Nothing
+ppContextNoLocsMaybe cxt unicode = Just $ pp_hs_context cxt unicode
+
+ppContextNoArrow :: HsContext DocNameI -> Bool -> LaTeX
+ppContextNoArrow cxt unicode = fromMaybe empty $
+                               ppContextNoLocsMaybe (map unLoc cxt) unicode
+
+
+ppContextNoLocs :: [HsType DocNameI] -> Bool -> LaTeX
+ppContextNoLocs cxt unicode = maybe empty (<+> darrow unicode) $
+                              ppContextNoLocsMaybe cxt unicode
+
+
+ppContext :: HsContext DocNameI -> Bool -> LaTeX
+ppContext cxt unicode = ppContextNoLocs (map unLoc cxt) unicode
+
+
+pp_hs_context :: [HsType DocNameI] -> Bool -> LaTeX
+pp_hs_context []  _       = empty
+pp_hs_context [p] unicode = ppCtxType unicode p
+pp_hs_context cxt unicode = parenList (map (ppType unicode) cxt)
+
+
+-------------------------------------------------------------------------------
+-- * Types and contexts
+-------------------------------------------------------------------------------
+
+
+ppBang :: HsSrcBang -> LaTeX
+ppBang (HsSrcBang _ _ SrcStrict) = char '!'
+ppBang (HsSrcBang _ _ SrcLazy)   = char '~'
+ppBang _                         = empty
+
+
+tupleParens :: HsTupleSort -> [LaTeX] -> LaTeX
+tupleParens HsUnboxedTuple = ubxParenList
+tupleParens _              = parenList
+
+
+sumParens :: [LaTeX] -> LaTeX
+sumParens = ubxparens . hsep . punctuate (text " |")
+
+
+-------------------------------------------------------------------------------
+-- * Rendering of HsType
+--
+-- Stolen from Html and tweaked for LaTeX generation
+-------------------------------------------------------------------------------
+
+ppLType, ppLParendType, ppLFunLhType :: Bool -> LHsType DocNameI -> LaTeX
+ppLType       unicode y = ppType unicode (unLoc y)
+ppLParendType unicode y = ppParendType unicode (unLoc y)
+ppLFunLhType  unicode y = ppFunLhType unicode (unLoc y)
+
+ppLSigType :: Bool -> LHsSigType DocNameI -> LaTeX
+ppLSigType unicode y = ppSigType unicode (unLoc y)
+
+ppType, ppParendType, ppFunLhType, ppCtxType :: Bool -> HsType DocNameI -> LaTeX
+ppType       unicode ty = ppr_mono_ty (reparenTypePrec PREC_TOP ty) unicode
+ppParendType unicode ty = ppr_mono_ty (reparenTypePrec PREC_TOP ty) unicode
+ppFunLhType  unicode ty = ppr_mono_ty (reparenTypePrec PREC_FUN ty) unicode
+ppCtxType    unicode ty = ppr_mono_ty (reparenTypePrec PREC_CTX ty) unicode
+
+ppSigType :: Bool -> HsSigType DocNameI -> LaTeX
+ppSigType unicode sig_ty = ppr_sig_ty (reparenSigType sig_ty) unicode
+
+ppLHsTypeArg :: Bool -> LHsTypeArg DocNameI -> LaTeX
+ppLHsTypeArg unicode (HsValArg ty) = ppLParendType unicode ty
+ppLHsTypeArg unicode (HsTypeArg _ ki) = atSign unicode <>
+                                       ppLParendType unicode ki
+ppLHsTypeArg _ (HsArgPar _) = text ""
+
+class RenderableBndrFlag flag where
+  ppHsTyVarBndr :: Bool -> HsTyVarBndr flag DocNameI -> LaTeX
+
+instance RenderableBndrFlag () where
+  ppHsTyVarBndr _ (UserTyVar _ _ (L _ name)) = ppDocName name
+  ppHsTyVarBndr unicode (KindedTyVar _ _ (L _ name) kind) =
+    parens (ppDocName name) <+> dcolon unicode <+> ppLKind unicode kind
+
+instance RenderableBndrFlag Specificity where
+  ppHsTyVarBndr _ (UserTyVar _ SpecifiedSpec (L _ name)) = ppDocName name
+  ppHsTyVarBndr _ (UserTyVar _ InferredSpec (L _ name)) = braces $ ppDocName name
+  ppHsTyVarBndr unicode (KindedTyVar _ SpecifiedSpec (L _ name) kind) =
+    parens (ppDocName name) <+> dcolon unicode <+> ppLKind unicode kind
+  ppHsTyVarBndr unicode (KindedTyVar _ InferredSpec (L _ name) kind) =
+    braces (ppDocName name) <+> dcolon unicode <+> ppLKind unicode kind
+
+ppLKind :: Bool -> LHsKind DocNameI -> LaTeX
+ppLKind unicode y = ppKind unicode (unLoc y)
+
+ppKind :: Bool -> HsKind DocNameI -> LaTeX
+ppKind unicode ki = ppr_mono_ty (reparenTypePrec PREC_TOP ki) unicode
+
+-- Drop top-level for-all type variables in user style
+-- since they are implicit in Haskell
+
+ppr_sig_ty :: HsSigType DocNameI -> Bool -> LaTeX
+ppr_sig_ty (HsSig { sig_bndrs = outer_bndrs, sig_body = ltype }) unicode
+  = sep [ ppHsOuterTyVarBndrs outer_bndrs unicode
+        , ppr_mono_lty ltype unicode ]
+
+ppr_mono_lty :: LHsType DocNameI -> Bool -> LaTeX
+ppr_mono_lty ty unicode = ppr_mono_ty (unLoc ty) unicode
+
+
+ppr_mono_ty :: HsType DocNameI -> Bool -> LaTeX
+ppr_mono_ty (HsForAllTy _ tele ty) unicode
+  = sep [ ppHsForAllTelescope tele unicode
+        , ppr_mono_lty ty unicode ]
+ppr_mono_ty (HsQualTy _ ctxt ty) unicode
+  = sep [ ppLContext (Just ctxt) unicode
+        , ppr_mono_lty ty unicode ]
+ppr_mono_ty (HsFunTy _ mult ty1 ty2)   u
+  = sep [ ppr_mono_lty ty1 u
+        , arr <+> ppr_mono_lty ty2 u ]
+   where arr = case mult of
+                 HsLinearArrow _ -> lollipop u
+                 HsUnrestrictedArrow _ -> arrow u
+                 HsExplicitMult _ m _ -> multAnnotation <> ppr_mono_lty m u <+> arrow u
+
+ppr_mono_ty (HsBangTy _ b ty)     u = ppBang b <> ppLParendType u ty
+ppr_mono_ty (HsTyVar _ NotPromoted (L _ name)) _ = ppDocName name
+ppr_mono_ty (HsTyVar _ IsPromoted  (L _ name)) _ = char '\'' <> ppDocName name
+ppr_mono_ty (HsTupleTy _ con tys) u = tupleParens con (map (ppLType u) tys)
+ppr_mono_ty (HsSumTy _ tys) u       = sumParens (map (ppLType u) tys)
+ppr_mono_ty (HsKindSig _ ty kind) u = parens (ppr_mono_lty ty u <+> dcolon u <+> ppLKind u kind)
+ppr_mono_ty (HsListTy _ ty)       u = brackets (ppr_mono_lty ty u)
+ppr_mono_ty (HsIParamTy _ (L _ n) ty) u = ppIPName n <+> dcolon u <+> ppr_mono_lty ty u
+ppr_mono_ty (HsSpliceTy v _)    _ = dataConCantHappen v
+ppr_mono_ty (HsRecTy {})        _ = text "{..}"
+ppr_mono_ty (XHsType {})        _ = error "ppr_mono_ty HsCoreTy"
+ppr_mono_ty (HsExplicitListTy _ IsPromoted tys) u = Pretty.quote $ brackets $ hsep $ punctuate comma $ map (ppLType u) tys
+ppr_mono_ty (HsExplicitListTy _ NotPromoted tys) u = brackets $ hsep $ punctuate comma $ map (ppLType u) tys
+ppr_mono_ty (HsExplicitTupleTy _ tys) u = Pretty.quote $ parenList $ map (ppLType u) tys
+
+ppr_mono_ty (HsAppTy _ fun_ty arg_ty) unicode
+  = hsep [ppr_mono_lty fun_ty unicode, ppr_mono_lty arg_ty unicode]
+
+ppr_mono_ty (HsAppKindTy _ fun_ty arg_ki) unicode
+  = hsep [ppr_mono_lty fun_ty unicode, atSign unicode <> ppr_mono_lty arg_ki unicode]
+
+ppr_mono_ty (HsOpTy _ prom ty1 op ty2) unicode
+  = ppr_mono_lty ty1 unicode <+> ppr_op_prom <+> ppr_mono_lty ty2 unicode
+  where
+    ppr_op_prom | isPromoted prom
+                = char '\'' <> ppr_op
+                | otherwise
+                = ppr_op
+    ppr_op | isSymOcc (getOccName op) = ppLDocName op
+           | otherwise = char '`' <> ppLDocName op <> char '`'
+
+ppr_mono_ty (HsParTy _ ty) unicode
+  = parens (ppr_mono_lty ty unicode)
+--  = ppr_mono_lty ty unicode
+
+ppr_mono_ty (HsDocTy _ ty _) unicode
+  = ppr_mono_lty ty unicode
+
+ppr_mono_ty (HsWildCardTy _) _ = char '_'
+
+ppr_mono_ty (HsTyLit _ t) u = ppr_tylit t u
+ppr_mono_ty (HsStarTy _ isUni) unicode = starSymbol (isUni || unicode)
+
+
+ppr_tylit :: HsTyLit DocNameI -> Bool -> LaTeX
+ppr_tylit (HsNumTy _ n) _ = integer n
+ppr_tylit (HsStrTy _ s) _ = text (show s)
+ppr_tylit (HsCharTy _ c) _ = text (show c)
+  -- XXX: Ok in verbatim, but not otherwise
+  -- XXX: Do something with Unicode parameter?
+
+
+-------------------------------------------------------------------------------
+-- * Names
+-------------------------------------------------------------------------------
+
+
+ppBinder :: OccName -> LaTeX
+ppBinder n
+  | isSymOcc n = parens $ ppOccName n
+  | otherwise  = ppOccName n
+
+ppBinderInfix :: OccName -> LaTeX
+ppBinderInfix n
+  | isSymOcc n = ppOccName n
+  | otherwise  = cat [ char '`', ppOccName n, char '`' ]
+
+ppSymName :: Name -> LaTeX
+ppSymName name
+  | isNameSym name = parens $ ppName name
+  | otherwise = ppName name
+
+
+ppIPName :: HsIPName -> LaTeX
+ppIPName = text . ('?':) . unpackFS . hsIPNameFS
+
+ppOccName :: OccName -> LaTeX
+ppOccName = text . occNameString
+
+
+ppDocName :: DocName -> LaTeX
+ppDocName = ppOccName . nameOccName . getName
+
+ppLDocName :: GenLocated l DocName -> LaTeX
+ppLDocName (L _ d) = ppDocName d
+
+
+ppDocBinder :: DocName -> LaTeX
+ppDocBinder = ppBinder . nameOccName . getName
+
+
+ppName :: Name -> LaTeX
+ppName = ppOccName . nameOccName
+
+
+latexFilter :: String -> String
+latexFilter = foldr latexMunge ""
+
+
+latexMonoFilter :: String -> String
+latexMonoFilter = foldr latexMonoMunge ""
+
+
+latexMunge :: Char -> String -> String
+latexMunge '#'  s = "{\\char '43}" ++ s
+latexMunge '$'  s = "{\\char '44}" ++ s
+latexMunge '%'  s = "{\\char '45}" ++ s
+latexMunge '&'  s = "{\\char '46}" ++ s
+latexMunge '~'  s = "{\\char '176}" ++ s
+latexMunge '_'  s = "{\\char '137}" ++ s
+latexMunge '^'  s = "{\\char '136}" ++ s
+latexMunge '\\' s = "{\\char '134}" ++ s
+latexMunge '{'  s = "{\\char '173}" ++ s
+latexMunge '}'  s = "{\\char '175}" ++ s
+latexMunge '['  s = "{\\char 91}" ++ s
+latexMunge ']'  s = "{\\char 93}" ++ s
+latexMunge c    s = c : s
+
+
+latexMonoMunge :: Char -> String -> String
+latexMonoMunge ' '      (' ':s) = "\\ \\ " ++ s
+latexMonoMunge ' ' ('\\':' ':s) = "\\ \\ " ++ s
+latexMonoMunge '\n' s = '\\' : '\\' : s
+latexMonoMunge c s = latexMunge c s
+
+
+-------------------------------------------------------------------------------
+-- * Doc Markup
+-------------------------------------------------------------------------------
+
+
+latexMarkup :: HasOccName a => DocMarkup (Wrap a) (StringContext -> LaTeX -> LaTeX)
+latexMarkup = Markup
+  { markupParagraph            = \p v -> blockElem (p v (text "\\par"))
+  , markupEmpty                = \_ -> id
+  , markupString               = \s v -> inlineElem (text (fixString v s))
+  , markupAppend               = \l r v -> l v . r v
+  , markupIdentifier           = \i v -> inlineElem (markupId v (fmap occName i))
+  , markupIdentifierUnchecked  = \i v -> inlineElem (markupId v (fmap snd i))
+  , markupModule               =
+      \(ModLink m mLabel) v ->
+        case mLabel of
+          Just lbl -> inlineElem . tt $ lbl v empty
+          Nothing -> inlineElem (let (mdl,_ref) = break (=='#') m
+                                 in (tt (text mdl)))
+  , markupWarning              = \p v -> p v
+  , markupEmphasis             = \p v -> inlineElem (emph (p v empty))
+  , markupBold                 = \p v -> inlineElem (bold (p v empty))
+  , markupMonospaced           = \p v -> inlineElem (markupMonospace p v)
+  , markupUnorderedList        = \p v -> blockElem (itemizedList (map (\p' -> p' v empty) p))
+  , markupPic                  = \p _ -> inlineElem (markupPic p)
+  , markupMathInline           = \p _ -> inlineElem (markupMathInline p)
+  , markupMathDisplay          = \p _ -> blockElem (markupMathDisplay p)
+  , markupOrderedList          = \p v -> blockElem (enumeratedList (map (\(_, p') -> p' v empty) p))
+  , markupDefList              = \l v -> blockElem (descriptionList (map (\(a,b) -> (a v empty, b v empty)) l))
+  , markupCodeBlock            = \p _ -> blockElem (quote (verb (p Verb empty)))
+  , markupHyperlink            = \(Hyperlink u l) v -> inlineElem (markupLink u (fmap (\x -> x v empty) l))
+  , markupAName                = \_ _ -> id -- TODO
+  , markupProperty             = \p _ -> blockElem (quote (verb (text p)))
+  , markupExample              = \e _ -> blockElem (quote (verb (text $ unlines $ map exampleToString e)))
+  , markupHeader               = \(Header l h) p -> blockElem (header l (h p empty))
+  , markupTable                = \(Table h b) p -> blockElem (table h b p)
+  }
+  where
+    blockElem :: LaTeX -> LaTeX -> LaTeX
+    blockElem = ($$)
+
+    inlineElem :: LaTeX -> LaTeX -> LaTeX
+    inlineElem = (<>)
+
+    header 1 d = text "\\section*" <> braces d
+    header 2 d = text "\\subsection*" <> braces d
+    header l d
+      | l > 0 && l <= 6 = text "\\subsubsection*" <> braces d
+    header l _ = error $ "impossible header level in LaTeX generation: " ++ show l
+
+    table _ _ _ = text "{TODO: Table}"
+
+    fixString Plain s = latexFilter s
+    fixString Verb  s = s
+    fixString Mono  s = latexMonoFilter s
+
+    markupMonospace p Verb = p Verb empty
+    markupMonospace p _ = tt (p Mono empty)
+
+    markupLink url mLabel = case mLabel of
+      Just label -> text "\\href" <> braces (text url) <> braces label
+      Nothing    -> text "\\url"  <> braces (text url)
+
+    -- Is there a better way of doing this? Just a space is an arbitrary choice.
+    markupPic (Picture uri title) = parens (imageText title)
+      where
+        imageText Nothing = beg
+        imageText (Just t) = beg <> text " " <> text t
+
+        beg = text "image: " <> text uri
+
+    markupMathInline mathjax = text "\\(" <> text mathjax <> text "\\)"
+
+    markupMathDisplay mathjax = text "\\[" <> text mathjax <> text "\\]"
+
+    markupId v wrappedOcc =
+      case v of
+        Verb  -> text i
+        Mono  -> text "\\haddockid" <> braces (text . latexMonoFilter $ i)
+        Plain -> text "\\haddockid" <> braces (text . latexFilter $ i)
+      where i = showWrapped occNameString wrappedOcc
+
+docToLaTeX :: Doc DocName -> LaTeX
+docToLaTeX doc = markup latexMarkup doc Plain empty
+
+documentationToLaTeX :: Documentation DocName -> Maybe LaTeX
+documentationToLaTeX = fmap docToLaTeX . fmap _doc . combineDocumentation
+
+
+rdrDocToLaTeX :: Doc RdrName -> LaTeX
+rdrDocToLaTeX doc = markup latexMarkup doc Plain empty
+
+
+data StringContext
+  = Plain  -- ^ all special characters have to be escape
+  | Mono   -- ^ on top of special characters, escape space characters
+  | Verb   -- ^ don't escape anything
+
+
+latexStripTrailingWhitespace :: Doc a -> Doc a
+latexStripTrailingWhitespace (DocString s)
+  | null s'   = DocEmpty
+  | otherwise = DocString s
+  where s' = reverse (dropWhile isSpace (reverse s))
+latexStripTrailingWhitespace (DocAppend l r)
+  | DocEmpty <- r' = latexStripTrailingWhitespace l
+  | otherwise      = DocAppend l r'
+  where
+    r' = latexStripTrailingWhitespace r
+latexStripTrailingWhitespace (DocParagraph p) =
+  latexStripTrailingWhitespace p
+latexStripTrailingWhitespace other = other
+
+
+-------------------------------------------------------------------------------
+-- * LaTeX utils
+-------------------------------------------------------------------------------
+
+
+itemizedList :: [LaTeX] -> LaTeX
+itemizedList items =
+  text "\\vbox{\\begin{itemize}" $$
+  vcat (map (text "\\item" $$) items) $$
+  text "\\end{itemize}}"
+
+
+enumeratedList :: [LaTeX] -> LaTeX
+enumeratedList items =
+  text "\\vbox{\\begin{enumerate}" $$
+  vcat (map (text "\\item " $$) items) $$
+  text "\\end{enumerate}}"
+
+
+descriptionList :: [(LaTeX,LaTeX)] -> LaTeX
+descriptionList items =
+  text "\\vbox{\\begin{description}" $$
+  vcat (map (\(a,b) -> text "\\item" <> brackets a <> text "\\hfill \\par" $$ b) items) $$
+  text "\\end{description}}"
+
+
+tt :: LaTeX -> LaTeX
+tt ltx = text "\\haddocktt" <> braces ltx
+
+
+decltt :: LaTeX -> LaTeX
+decltt ltx = text "\\haddockdecltt" <> braces (text filtered)
+  where filtered = latexMonoFilter (latex2String ltx)
+
+emph :: LaTeX -> LaTeX
+emph ltx = text "\\emph" <> braces ltx
+
+bold :: LaTeX -> LaTeX
+bold ltx = text "\\textbf" <> braces ltx
+
+-- TODO: @verbatim@ is too much since
+--
+--   * Haddock supports markup _inside_ of code blocks. Right now, the LaTeX
+--     representing that markup gets printed verbatim
+--   * Verbatim environments are not supported everywhere (example: not nested
+--     inside a @tabulary@ environment)
+verb :: LaTeX -> LaTeX
+verb doc = text "{\\haddockverb\\begin{verbatim}" $$ doc <> text "\\end{verbatim}}"
+   -- NB. swallow a trailing \n in the verbatim text by appending the
+   -- \end{verbatim} directly, otherwise we get spurious blank lines at the
+   -- end of code blocks.
+
+
+quote :: LaTeX -> LaTeX
+quote doc = text "\\begin{quote}" $$ doc $$ text "\\end{quote}"
+
+
+dcolon, arrow, lollipop, darrow, forallSymbol, starSymbol, atSign :: Bool -> LaTeX
+dcolon unicode = text (if unicode then "∷" else "::")
+arrow  unicode = text (if unicode then "→" else "->")
+lollipop unicode = text (if unicode then "⊸" else "%1 ->")
+darrow unicode = text (if unicode then "⇒" else "=>")
+forallSymbol unicode = text (if unicode then "∀" else "forall")
+starSymbol unicode = text (if unicode then "★" else "*")
+atSign unicode = text (if unicode then "@" else "@")
+
+multAnnotation :: LaTeX
+multAnnotation = text "%"
+
+dot :: LaTeX
+dot = char '.'
+
+
+parenList :: [LaTeX] -> LaTeX
+parenList = parens . hsep . punctuate comma
+
+
+ubxParenList :: [LaTeX] -> LaTeX
+ubxParenList = ubxparens . hsep . punctuate comma
+
+
+ubxparens :: LaTeX -> LaTeX
+ubxparens h = text "(#" <+> h <+> text "#)"
+
+
+nl :: LaTeX
+nl = text "\\\\"
+
+
+keyword :: String -> LaTeX
+keyword = text
+
+
+infixr 4 <->  -- combining table cells
+(<->) :: LaTeX -> LaTeX -> LaTeX
+a <-> b = a <+> char '&' <+> b
diff --git a/haddock-api/src/Haddock/Backends/Xhtml.hs b/haddock-api/src/Haddock/Backends/Xhtml.hs
new file mode 100644
--- /dev/null
+++ b/haddock-api/src/Haddock/Backends/Xhtml.hs
@@ -0,0 +1,914 @@
+-----------------------------------------------------------------------------
+-- |
+-- Module      :  Haddock.Backends.Html
+-- Copyright   :  (c) Simon Marlow      2003-2006,
+--                    David Waern       2006-2009,
+--                    Mark Lentczner    2010,
+--                    Mateusz Kowalczyk 2013
+-- License     :  BSD-like
+--
+-- Maintainer  :  haddock@projects.haskell.org
+-- Stability   :  experimental
+-- Portability :  portable
+-----------------------------------------------------------------------------
+{-# LANGUAGE CPP              #-}
+{-# LANGUAGE NamedFieldPuns   #-}
+{-# LANGUAGE TupleSections    #-}
+{-# LANGUAGE TypeApplications #-}
+{-# LANGUAGE TypeFamilies     #-}
+{-# LANGUAGE BangPatterns     #-}
+
+module Haddock.Backends.Xhtml (
+  ppHtml, copyHtmlBits,
+  ppHtmlIndex, ppHtmlContents,
+  ppJsonIndex
+) where
+
+
+import Prelude hiding (div)
+
+import Haddock.Backends.Xhtml.Decl
+import Haddock.Backends.Xhtml.DocMarkup
+import Haddock.Backends.Xhtml.Layout
+import Haddock.Backends.Xhtml.Names
+import Haddock.Backends.Xhtml.Themes
+import Haddock.Backends.Xhtml.Types
+import Haddock.Backends.Xhtml.Utils
+import Haddock.InterfaceFile (PackageInfo (..), PackageInterfaces (..), ppPackageInfo)
+import Haddock.ModuleTree
+import Haddock.Options (Visibility (..))
+import Haddock.Types
+import Haddock.Version
+import Haddock.Utils
+import Haddock.Utils.Json
+import Text.XHtml hiding ( name, title, p, quote )
+import qualified Text.XHtml as XHtml
+import Haddock.GhcUtils
+
+import Control.Monad         ( when, unless )
+import qualified Data.ByteString.Builder as Builder
+import Control.DeepSeq       (force)
+import Data.Bifunctor        ( bimap )
+import Data.Char             ( toUpper, isSpace )
+import Data.Either           ( partitionEithers )
+import Data.Foldable         ( traverse_, foldl')
+import Data.List             ( sortBy, isPrefixOf, intersperse )
+import Data.Maybe
+import System.Directory
+import System.FilePath hiding ( (</>) )
+import qualified System.IO as IO
+import qualified System.FilePath as FilePath
+import Data.Map.Strict       (Map)
+import qualified Data.Map.Strict as Map
+import qualified Data.Set as Set hiding ( Set )
+import Data.Ord              ( comparing )
+
+import GHC hiding ( NoLink, moduleInfo,LexicalFixity(..), anchor )
+import GHC.Types.Name
+import GHC.Unit.State
+
+--------------------------------------------------------------------------------
+-- * Generating HTML documentation
+--------------------------------------------------------------------------------
+
+ppHtml :: UnitState
+       -> String                       -- ^ Title
+       -> Maybe String                 -- ^ Package
+       -> [Interface]
+       -> [InstalledInterface]         -- ^ Reexported interfaces
+       -> FilePath                     -- ^ Destination directory
+       -> Maybe (MDoc GHC.RdrName)     -- ^ Prologue text, maybe
+       -> Themes                       -- ^ Themes
+       -> Maybe String                 -- ^ The mathjax URL (--mathjax)
+       -> SourceURLs                   -- ^ The source URL (--source)
+       -> WikiURLs                     -- ^ The wiki URL (--wiki)
+       -> BaseURL                      -- ^ The base URL (--base-url)
+       -> Maybe String                 -- ^ The contents URL (--use-contents)
+       -> Maybe String                 -- ^ The index URL (--use-index)
+       -> Bool                         -- ^ Whether to use unicode in output (--use-unicode)
+       -> Maybe String                 -- ^ Package name
+       -> PackageInfo                  -- ^ Package info
+       -> QualOption                   -- ^ How to qualify names
+       -> Bool                         -- ^ Output pretty html (newlines and indenting)
+       -> Bool                         -- ^ Also write Quickjump index
+       -> IO ()
+
+ppHtml state doctitle maybe_package ifaces reexported_ifaces odir prologue
+        themes maybe_mathjax_url maybe_source_url maybe_wiki_url
+        maybe_base_url maybe_contents_url maybe_index_url unicode
+        pkg packageInfo qual debug withQuickjump = do
+  let
+    visible_ifaces = filter visible ifaces
+    visible i = OptHide `notElem` ifaceOptions i
+
+  when (isNothing maybe_contents_url) $
+    ppHtmlContents state odir doctitle maybe_package
+        themes maybe_mathjax_url maybe_index_url maybe_source_url maybe_wiki_url
+        withQuickjump
+        [PackageInterfaces
+          { piPackageInfo = packageInfo
+          , piVisibility  = Visible
+          , piInstalledInterfaces = map toInstalledIface visible_ifaces
+                                 ++ reexported_ifaces
+          }]
+        False -- we don't want to display the packages in a single-package contents
+        prologue debug pkg (makeContentsQual qual)
+
+  when (isNothing maybe_index_url) $ do
+    ppHtmlIndex odir doctitle maybe_package
+      themes maybe_mathjax_url maybe_contents_url maybe_source_url maybe_wiki_url
+      withQuickjump
+      (map toInstalledIface visible_ifaces ++ reexported_ifaces) debug
+
+  when withQuickjump $
+    ppJsonIndex odir maybe_source_url maybe_wiki_url unicode pkg qual
+      visible_ifaces []
+
+  mapM_ (ppHtmlModule odir doctitle themes
+           maybe_mathjax_url maybe_source_url maybe_wiki_url maybe_base_url
+           maybe_contents_url maybe_index_url withQuickjump
+           unicode pkg qual debug) visible_ifaces
+
+
+copyHtmlBits :: FilePath -> FilePath -> Themes -> Bool -> IO ()
+copyHtmlBits odir libdir themes withQuickjump = do
+  let
+    libhtmldir = joinPath [libdir, "html"]
+    copyCssFile f = copyFile f (combine odir (takeFileName f))
+    copyLibFile f = copyFile (joinPath [libhtmldir, f]) (joinPath [odir, f])
+  mapM_ copyCssFile (cssFiles themes)
+  copyLibFile haddockJsFile
+  copyCssFile (joinPath [libhtmldir, quickJumpCssFile])
+  when withQuickjump (copyLibFile jsQuickJumpFile)
+  return ()
+
+
+headHtml :: String -> Themes -> Maybe String -> Maybe String -> Html
+headHtml docTitle themes mathjax_url base_url =
+      header ! (maybe [] (\url -> [identifier "head", strAttr "data-base-url" url ]) base_url)
+    <<
+    [ meta ! [ httpequiv "Content-Type", content "text/html; charset=UTF-8"]
+    , meta ! [ XHtml.name "viewport", content "width=device-width, initial-scale=1"]
+    , thetitle << docTitle
+    , styleSheet base_url themes
+    , thelink ! [ rel "stylesheet"
+                , thetype "text/css"
+                , href (withBaseURL base_url quickJumpCssFile) ]
+             << noHtml
+    , thelink ! [ rel "stylesheet", thetype "text/css", href fontUrl] << noHtml
+    , script ! [ src (withBaseURL base_url haddockJsFile)
+               , emptyAttr "async"
+               , thetype "text/javascript" ]
+            << noHtml
+    , script ! [thetype "text/x-mathjax-config"] << primHtml mjConf
+    , script ! [src mjUrl, thetype "text/javascript"] << noHtml
+    ]
+  where
+    fontUrl = "https://fonts.googleapis.com/css?family=PT+Sans:400,400i,700"
+    mjUrl = fromMaybe "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" mathjax_url
+    mjConf = unwords [ "MathJax.Hub.Config({"
+                     ,   "tex2jax: {"
+                     ,     "processClass: \"mathjax\","
+                     ,     "ignoreClass: \".*\""
+                     ,   "}"
+                     , "});" ]
+
+quickJumpButtonLi :: Bool  -- ^ With Quick Jump?
+                  -> Maybe Html
+-- The TypeScript should replace this <li> element, given its id. However, in
+-- case it does not, the element is given content here too.
+quickJumpButtonLi True = Just $ li ! [identifier "quick-jump-button"]
+  << anchor ! [href "#"] << "Quick Jump"
+
+quickJumpButtonLi False = Nothing
+
+srcButton :: SourceURLs -> Maybe Interface -> Maybe Html
+srcButton (Just src_base_url, _, _, _) Nothing =
+  Just (anchor ! [href src_base_url] << "Source")
+srcButton (_, Just src_module_url, _, _) (Just iface) =
+  let url = spliceURL (Just $ ifaceOrigFilename iface)
+                      (Just $ ifaceMod iface) Nothing Nothing src_module_url
+   in Just (anchor ! [href url] << "Source")
+srcButton _ _ =
+  Nothing
+
+
+wikiButton :: WikiURLs -> Maybe Module -> Maybe Html
+wikiButton (Just wiki_base_url, _, _) Nothing =
+  Just (anchor ! [href wiki_base_url] << "User Comments")
+
+wikiButton (_, Just wiki_module_url, _) (Just mdl) =
+  let url = spliceURL Nothing (Just mdl) Nothing Nothing wiki_module_url
+   in Just (anchor ! [href url] << "User Comments")
+
+wikiButton _ _ =
+  Nothing
+
+
+contentsButton :: Maybe String -> Maybe Html
+contentsButton maybe_contents_url
+  = Just (anchor ! [href url] << "Contents")
+  where url = fromMaybe contentsHtmlFile maybe_contents_url
+
+
+indexButton :: Maybe String -> Maybe Html
+indexButton maybe_index_url
+  = Just (anchor ! [href url] << "Index")
+  where url = fromMaybe indexHtmlFile maybe_index_url
+
+
+bodyHtml :: String -> Maybe Interface
+    -> SourceURLs -> WikiURLs
+    -> Maybe String -> Maybe String
+    -> Bool  -- ^ With Quick Jump?
+    -> Html -> Html
+bodyHtml doctitle iface
+           maybe_source_url maybe_wiki_url
+           maybe_contents_url maybe_index_url
+           withQuickjump
+           pageContent =
+  body << [
+    divPackageHeader << [
+      nonEmptySectionName << doctitle,
+      ulist ! [theclass "links", identifier "page-menu"]
+        << catMaybes (quickJumpButtonLi withQuickjump : otherButtonLis)
+      ],
+    divContent << pageContent,
+    divFooter << paragraph << (
+      "Produced by " +++
+      (anchor ! [href projectUrl] << toHtml projectName) +++
+      (" version " ++ projectVersion)
+      )
+    ]
+ where
+  otherButtonLis = (fmap . fmap) (li <<)
+    [ srcButton maybe_source_url iface
+    , wikiButton maybe_wiki_url (ifaceMod <$> iface)
+    , contentsButton maybe_contents_url
+    , indexButton maybe_index_url
+    ]
+
+moduleInfo :: Interface -> Html
+moduleInfo iface =
+   let
+      info = ifaceInfo iface
+
+      doOneEntry :: (String, HaddockModInfo GHC.Name -> Maybe String) -> Maybe HtmlTable
+      doOneEntry (fieldName, field) =
+        field info >>= \a -> return (th << fieldName <-> td << a)
+
+      entries :: [HtmlTable]
+      entries = maybeToList copyrightsTable ++ mapMaybe doOneEntry [
+          ("License",hmi_license),
+          ("Maintainer",hmi_maintainer),
+          ("Stability",hmi_stability),
+          ("Portability",hmi_portability),
+          ("Safe Haskell",hmi_safety),
+          ("Language", lg)
+          ] ++ extsForm
+        where
+          lg inf = fmap show (hmi_language inf)
+
+          multilineRow :: String -> [String] -> HtmlTable
+          multilineRow title xs = (th ! [valign "top"]) << title <-> td << (toLines xs)
+            where toLines = mconcat . intersperse br . map toHtml
+
+          copyrightsTable :: Maybe HtmlTable
+          copyrightsTable = fmap (multilineRow "Copyright" . split) (hmi_copyright info)
+            where split = map (trim . filter (/= ',')) . lines
+
+          extsForm
+            | OptShowExtensions `elem` ifaceOptions iface =
+              let fs = map (dropOpt . show) (hmi_extensions info)
+              in case map stringToHtml fs of
+                [] -> []
+                [x] -> extField x -- don't use a list for a single extension
+                xs -> extField $ unordList xs ! [theclass "extension-list"]
+            | otherwise = []
+            where
+              extField x = return $ th << "Extensions" <-> td << x
+              dropOpt x = if "Opt_" `isPrefixOf` x then drop 4 x else x
+   in
+      case entries of
+         [] -> noHtml
+         _ -> table ! [theclass "info"] << aboves entries
+
+
+--------------------------------------------------------------------------------
+-- * Generate the module contents
+--------------------------------------------------------------------------------
+
+
+ppHtmlContents
+   :: UnitState
+   -> FilePath
+   -> String
+   -> Maybe String
+   -> Themes
+   -> Maybe String
+   -> Maybe String
+   -> SourceURLs
+   -> WikiURLs
+   -> Bool  -- ^ With Quick Jump?
+   -> [PackageInterfaces] -> Bool -> Maybe (MDoc GHC.RdrName)
+   -> Bool
+   -> Maybe Package  -- ^ Current package
+   -> Qualification  -- ^ How to qualify names
+   -> IO ()
+ppHtmlContents state odir doctitle _maybe_package
+  themes mathjax_url maybe_index_url
+  maybe_source_url maybe_wiki_url withQuickjump
+  packages showPkgs prologue debug pkg qual = do
+  let trees =
+        [ ( piPackageInfo pinfo
+          , mkModuleTree state showPkgs
+            [(instMod iface, toInstalledDescription iface)
+            | iface <- piInstalledInterfaces pinfo
+            , not (instIsSig iface)
+            ]
+          )
+        | pinfo <- packages
+        ]
+      sig_trees =
+        [ ( piPackageInfo pinfo
+          , mkModuleTree state showPkgs
+            [(instMod iface, toInstalledDescription iface)
+            | iface <- piInstalledInterfaces pinfo
+            , instIsSig iface
+            ]
+          )
+        | pinfo <- packages
+        ]
+      html =
+        headHtml doctitle themes mathjax_url Nothing +++
+        bodyHtml doctitle Nothing
+          maybe_source_url maybe_wiki_url
+          Nothing maybe_index_url withQuickjump << [
+            ppPrologue pkg qual doctitle prologue,
+            ppSignatureTrees pkg qual sig_trees,
+            ppModuleTrees pkg qual trees
+          ]
+  createDirectoryIfMissing True odir
+  writeUtf8File (joinPath [odir, contentsHtmlFile]) (renderToString debug html)
+  where
+    -- Extract a module's short description.
+    toInstalledDescription :: InstalledInterface -> Maybe (MDoc Name)
+    toInstalledDescription = fmap mkMeta . hmi_description . instInfo
+
+
+ppPrologue :: Maybe Package -> Qualification -> String -> Maybe (MDoc GHC.RdrName) -> Html
+ppPrologue _ _ _ Nothing = noHtml
+ppPrologue pkg qual title (Just doc) =
+  divDescription << (h1 << title +++ docElement thediv (rdrDocToHtml pkg qual doc))
+
+ppSignatureTrees :: Maybe Package -> Qualification -> [(PackageInfo, [ModuleTree])] -> Html
+ppSignatureTrees _ _ tss | all (null . snd) tss = mempty
+ppSignatureTrees pkg qual [(info, ts)] =
+  divPackageList << (sectionName << "Signatures" +++ ppSignatureTree pkg qual "n" info ts)
+ppSignatureTrees pkg qual tss =
+  divModuleList <<
+    (sectionName << "Signatures"
+     +++ concatHtml [ ppSignatureTree pkg qual("n."++show i++".") info ts
+                    | (i, (info, ts)) <- zip [(1::Int)..] tss
+                    ])
+
+ppSignatureTree :: Maybe Package -> Qualification -> String -> PackageInfo -> [ModuleTree] -> Html
+ppSignatureTree _ _ _ _ [] = mempty
+ppSignatureTree pkg qual p info ts =
+  divModuleList << (sectionName << ppPackageInfo info +++ mkNodeList pkg qual [] p ts)
+
+ppModuleTrees :: Maybe Package -> Qualification -> [(PackageInfo, [ModuleTree])] -> Html
+ppModuleTrees _ _ tss | all (null . snd) tss = mempty
+ppModuleTrees pkg qual [(info, ts)] =
+  divModuleList << (sectionName << "Modules" +++ ppModuleTree pkg qual "n" info ts)
+ppModuleTrees pkg qual tss =
+  divPackageList <<
+    (sectionName << "Packages"
+     +++ concatHtml [ppModuleTree pkg qual ("n."++show i++".") info ts
+                    | (i, (info, ts)) <- zip [(1::Int)..] tss
+                    ])
+
+ppModuleTree :: Maybe Package -> Qualification -> String -> PackageInfo -> [ModuleTree] -> Html
+ppModuleTree _ _ _ _ [] = mempty
+ppModuleTree pkg qual p info ts =
+  divModuleList << (sectionName << ppPackageInfo info +++ mkNodeList pkg qual [] p ts)
+
+
+mkNodeList :: Maybe Package -> Qualification -> [String] -> String -> [ModuleTree] -> Html
+mkNodeList pkg qual ss p ts = case ts of
+  [] -> noHtml
+  _ -> unordList (zipWith (mkNode pkg qual ss) ps ts)
+  where
+    ps = [ p ++ '.' : show i | i <- [(1::Int)..]]
+
+
+mkNode :: Maybe Package -> Qualification -> [String] -> String -> ModuleTree -> Html
+mkNode pkg qual ss p (Node s leaf _pkg srcPkg short ts) =
+  htmlModule <+> shortDescr +++ htmlPkg +++ subtree
+  where
+    modAttrs = case (ts, leaf) of
+      (_:_, Nothing) -> collapseControl p "module"
+      (_,   _    ) -> [theclass "module"]
+
+    cBtn = case (ts, leaf) of
+      (_:_, Just _) -> thespan ! collapseControl p "" << spaceHtml
+      ([] , Just _) -> thespan ! [theclass "noexpander"] << spaceHtml
+      (_,   _   ) -> noHtml
+      -- We only need an explicit collapser button when the module name
+      -- is also a leaf, and so is a link to a module page. Indeed, the
+      -- spaceHtml is a minor hack and does upset the layout a fraction.
+
+    htmlModule = thespan ! modAttrs << (cBtn +++
+      case leaf of
+        Just m -> ppModule m
+        Nothing -> toHtml s
+      )
+
+    shortDescr = maybe noHtml (origDocToHtml pkg qual) short
+    htmlPkg = maybe noHtml (thespan ! [theclass "package"] <<) srcPkg
+
+    subtree =
+      if null ts then noHtml else
+      collapseDetails p DetailsOpen (
+        thesummary ! [ theclass "hide-when-js-enabled" ] << "Submodules" +++
+        mkNodeList pkg qual (s:ss) p ts
+      )
+
+--------------------------------------------------------------------------------
+-- * Generate the index
+--------------------------------------------------------------------------------
+
+data JsonIndexEntry = JsonIndexEntry {
+      jieHtmlFragment :: String,
+      jieName         :: String,
+      jieModule       :: String,
+      jieLink         :: String
+    }
+  deriving Show
+
+instance ToJSON JsonIndexEntry where
+    toJSON JsonIndexEntry
+        { jieHtmlFragment
+        , jieName
+        , jieModule
+        , jieLink } =
+      Object
+        [ "display_html" .= String jieHtmlFragment
+        , "name"         .= String jieName
+        , "module"       .= String jieModule
+        , "link"         .= String jieLink
+        ]
+
+instance FromJSON JsonIndexEntry where
+    parseJSON = withObject "JsonIndexEntry" $ \v ->
+      JsonIndexEntry
+        <$> v .: "display_html"
+        <*> v .: "name"
+        <*> v .: "module"
+        <*> v .: "link"
+
+ppJsonIndex :: FilePath
+           -> SourceURLs                   -- ^ The source URL (--source)
+           -> WikiURLs                     -- ^ The wiki URL (--wiki)
+           -> Bool
+           -> Maybe Package
+           -> QualOption
+           -> [Interface]
+           -> [FilePath]                   -- ^ file paths to interface files
+                                           -- (--read-interface)
+           -> IO ()
+ppJsonIndex odir maybe_source_url maybe_wiki_url unicode pkg qual_opt ifaces installedIfacesPaths = do
+  createDirectoryIfMissing True odir
+  (errors, installedIndexes) <-
+    partitionEithers
+      <$> traverse
+            (\ifaceFile -> do
+              let indexFile = takeDirectory ifaceFile
+                    FilePath.</> "doc-index.json"
+              a <- doesFileExist indexFile
+              if a then
+                    bimap (indexFile,) (map (fixLink ifaceFile))
+                <$> eitherDecodeFile @[JsonIndexEntry] indexFile
+                   else
+                    return (Right [])
+            )
+            installedIfacesPaths
+  traverse_ (\(indexFile, err) -> putStrLn $ "haddock: Coudn't parse " ++ indexFile ++ ": " ++ err)
+            errors
+  IO.withBinaryFile (joinPath [odir, indexJsonFile]) IO.WriteMode $ \h ->
+      Builder.hPutBuilder
+        h (encodeToBuilder (encodeIndexes (concat installedIndexes)))
+  where
+    encodeIndexes :: [JsonIndexEntry] -> Value
+    encodeIndexes installedIndexes =
+      toJSON
+        (concatMap fromInterface ifaces
+         ++ installedIndexes)
+
+    fromInterface :: Interface -> [JsonIndexEntry]
+    fromInterface iface =
+        mkIndex mdl qual `mapMaybe` ifaceRnExportItems iface
+      where
+        aliases = ifaceModuleAliases iface
+        qual    = makeModuleQual qual_opt aliases mdl
+        mdl     = ifaceMod iface
+
+    mkIndex :: Module -> Qualification -> ExportItem DocNameI -> Maybe JsonIndexEntry
+    mkIndex mdl qual item
+      | Just item_html <- processExport True links_info unicode pkg qual item
+      = Just JsonIndexEntry
+          { jieHtmlFragment = showHtmlFragment item_html
+          , jieName         = unwords (map getOccString names)
+          , jieModule       = moduleString mdl
+          , jieLink         = fromMaybe "" (listToMaybe (map (nameLink mdl) names))
+          }
+      | otherwise = Nothing
+      where
+        names = exportName item ++ exportSubs item
+
+    exportSubs :: ExportItem DocNameI -> [IdP DocNameI]
+    exportSubs (ExportDecl (RnExportD { rnExpDExpD = ExportD { expDSubDocs } })) = map fst expDSubDocs
+    exportSubs _ = []
+
+    exportName :: ExportItem DocNameI -> [IdP DocNameI]
+    exportName (ExportDecl (RnExportD { rnExpDExpD = ExportD { expDDecl } })) = getMainDeclBinderI (unLoc expDDecl)
+    exportName ExportNoDecl { expItemName } = [expItemName]
+    exportName _ = []
+
+    nameLink :: NamedThing name => Module -> name -> String
+    nameLink mdl = moduleNameUrl' (moduleName mdl) . nameOccName . getName
+
+    links_info = (maybe_source_url, maybe_wiki_url)
+
+    -- update link using relative path to output directory
+    fixLink :: FilePath
+            -> JsonIndexEntry -> JsonIndexEntry
+    fixLink ifaceFile jie =
+      jie { jieLink = makeRelative odir (takeDirectory ifaceFile)
+                        FilePath.</> jieLink jie }
+
+ppHtmlIndex :: FilePath
+            -> String
+            -> Maybe String
+            -> Themes
+            -> Maybe String
+            -> Maybe String
+            -> SourceURLs
+            -> WikiURLs
+            -> Bool  -- ^ With Quick Jump?
+            -> [InstalledInterface]
+            -> Bool
+            -> IO ()
+ppHtmlIndex odir doctitle _maybe_package themes
+  maybe_mathjax_url maybe_contents_url maybe_source_url maybe_wiki_url withQuickjump ifaces debug = do
+  let html = indexPage split_indices Nothing
+              (if split_indices then [] else index)
+
+  createDirectoryIfMissing True odir
+
+  when split_indices $ do
+    mapM_ (do_sub_index index) initialChars
+    -- Let's add a single large index as well for those who don't know exactly what they're looking for:
+    let mergedhtml = indexPage False Nothing index
+    writeUtf8File (joinPath [odir, subIndexHtmlFile merged_name]) (renderToString debug mergedhtml)
+
+  writeUtf8File (joinPath [odir, indexHtmlFile]) (renderToString debug html)
+
+  where
+    indexPage showLetters ch items =
+      headHtml (doctitle ++ " (" ++ indexName ch ++ ")") themes maybe_mathjax_url Nothing +++
+      bodyHtml doctitle Nothing
+        maybe_source_url maybe_wiki_url
+        maybe_contents_url Nothing withQuickjump << [
+          if showLetters then indexInitialLetterLinks else noHtml,
+          if null items then noHtml else
+            divIndex << [sectionName << indexName ch, buildIndex items]
+          ]
+
+    indexName ch = "Index" ++ maybe "" (\c -> " - " ++ [c]) ch
+    merged_name = "All"
+
+    buildIndex items = table << aboves (map indexElt items)
+
+    -- an arbitrary heuristic:
+    -- too large, and a single-page will be slow to load
+    -- too small, and we'll have lots of letter-indexes with only one
+    --   or two members in them, which seems inefficient or
+    --   unnecessarily hard to use.
+    split_indices = length index > 150
+
+    indexInitialLetterLinks =
+      divAlphabet <<
+         unordList (map (\str -> anchor ! [href (subIndexHtmlFile str)] << str) $
+                        [ [c] | c <- initialChars
+                              , any ((==c) . toUpper . head . fst) index ] ++
+                        [merged_name])
+
+    -- todo: what about names/operators that start with Unicode
+    -- characters?
+    -- Exports beginning with '_' can be listed near the end,
+    -- presumably they're not as important... but would be listed
+    -- with non-split index!
+    initialChars = [ 'A'..'Z' ] ++ ":!#$%&*+./<=>?@\\^|-~" ++ "_"
+
+    do_sub_index this_ix c
+      = unless (null index_part) $
+          writeUtf8File (joinPath [odir, subIndexHtmlFile [c]]) (renderToString debug html)
+      where
+        html = indexPage True (Just c) index_part
+        index_part = [(n,stuff) | (n,stuff) <- this_ix, toUpper (head n) == c]
+
+
+    index :: [(String, Map GHC.Name [(Module,Bool)])]
+    index = sortBy cmp (Map.toAscList full_index)
+      where cmp (n1,_) (n2,_) = comparing (map toUpper) n1 n2
+
+    -- for each name (a plain string), we have a number of original HsNames that
+    -- it can refer to, and for each of those we have a list of modules
+    -- that export that entity.  Each of the modules exports the entity
+    -- in a visible or invisible way (hence the Bool).
+    full_index :: Map String (Map GHC.Name [(Module,Bool)])
+    full_index = foldl' f Map.empty ifaces
+      where
+        f :: Map String (Map Name [(Module, Bool)])
+          -> InstalledInterface
+          -> Map String (Map Name [(Module, Bool)])
+        f !idx iface =
+          Map.unionWith
+            (Map.unionWith (\a b -> let !x = force $ a ++ b in x))
+            idx
+            (getIfaceIndex iface)
+
+
+    getIfaceIndex :: InstalledInterface -> Map String (Map Name [(Module, Bool)])
+    getIfaceIndex iface =
+        foldl' f Map.empty (instExports iface)
+      where
+        f :: Map String (Map Name [(Module, Bool)])
+          -> Name
+          -> Map String (Map Name [(Module, Bool)])
+        f !idx name =
+          let !vis =  name `Set.member` visible
+          in
+            Map.insertWith
+              (Map.unionWith (++))
+              (getOccString name)
+              (Map.singleton name [(mdl, vis)])
+              idx
+
+        mdl = instMod iface
+        visible = Set.fromList (instVisibleExports iface)
+
+    indexElt :: (String, Map GHC.Name [(Module,Bool)]) -> HtmlTable
+    indexElt (str, entities) =
+       case Map.toAscList entities of
+          [(nm,entries)] ->
+              td ! [ theclass "src" ] << toHtml str <->
+                          indexLinks nm entries
+          many_entities ->
+              td ! [ theclass "src" ] << toHtml str <-> td << spaceHtml </>
+                  aboves (zipWith (curry doAnnotatedEntity) [1..] many_entities)
+
+    doAnnotatedEntity :: (Integer, (Name, [(Module, Bool)])) -> HtmlTable
+    doAnnotatedEntity (j,(nm,entries))
+          = td ! [ theclass "alt" ] <<
+                  toHtml (show j) <+> parens (ppAnnot (nameOccName nm)) <->
+                   indexLinks nm entries
+
+    ppAnnot n | not (isValOcc n) = toHtml "Type/Class"
+              | isDataOcc n      = toHtml "Data Constructor"
+              | otherwise        = toHtml "Function"
+
+    indexLinks nm entries =
+       td ! [ theclass "module" ] <<
+          hsep (punctuate comma
+          [ if visible then
+               linkId mdl (Just nm) << toHtml (moduleString mdl)
+            else
+               toHtml (moduleString mdl)
+          | (mdl, visible) <- entries ])
+
+
+--------------------------------------------------------------------------------
+-- * Generate the HTML page for a module
+--------------------------------------------------------------------------------
+
+
+ppHtmlModule
+        :: FilePath -> String -> Themes
+        -> Maybe String -> SourceURLs -> WikiURLs -> BaseURL
+        -> Maybe String -> Maybe String
+        -> Bool  -- ^ With Quick Jump?
+        -> Bool -> Maybe Package -> QualOption
+        -> Bool -> Interface -> IO ()
+ppHtmlModule odir doctitle themes
+  maybe_mathjax_url maybe_source_url maybe_wiki_url maybe_base_url
+  maybe_contents_url maybe_index_url withQuickjump
+  unicode pkg qual debug iface = do
+  let
+      mdl = ifaceMod iface
+      aliases = ifaceModuleAliases iface
+      mdl_str = moduleString mdl
+      mdl_str_annot = mdl_str ++ if ifaceIsSig iface
+                                    then " (signature)"
+                                    else ""
+      mdl_str_linked
+        | ifaceIsSig iface
+        = mdl_str +++ " (signature" +++
+                       sup << ("[" +++ anchor ! [href signatureDocURL] << "?" +++ "]" ) +++
+                       ")"
+        | otherwise
+        = toHtml mdl_str
+      real_qual = makeModuleQual qual aliases mdl
+      html =
+        headHtml mdl_str_annot themes maybe_mathjax_url maybe_base_url +++
+        bodyHtml doctitle (Just iface)
+          maybe_source_url maybe_wiki_url
+          maybe_contents_url maybe_index_url withQuickjump << [
+            divModuleHeader << (moduleInfo iface +++ (sectionName << mdl_str_linked)),
+            ifaceToHtml maybe_source_url maybe_wiki_url iface unicode pkg real_qual
+          ]
+
+  createDirectoryIfMissing True odir
+  writeUtf8File (joinPath [odir, moduleHtmlFile mdl]) (renderToString debug html)
+
+signatureDocURL :: String
+signatureDocURL = "https://wiki.haskell.org/Module_signature"
+
+
+ifaceToHtml :: SourceURLs -> WikiURLs -> Interface -> Bool -> Maybe Package -> Qualification -> Html
+ifaceToHtml maybe_source_url maybe_wiki_url iface unicode pkg qual
+  = ppModuleContents pkg qual exports (not . null $ ifaceRnOrphanInstances iface) +++
+    description +++
+    synopsis +++
+    divInterface (maybe_doc_hdr +++ bdy +++ orphans)
+  where
+    exports = numberSectionHeadings (ifaceRnExportItems iface)
+
+    -- todo: if something has only sub-docs, or fn-args-docs, should
+    -- it be measured here and thus prevent omitting the synopsis?
+    has_doc
+      ( ExportDecl
+        ( RnExportD
+          { rnExpDExpD =
+            ExportD
+            { expDMbDoc =
+              ( Documentation mDoc mWarn, _ )
+            }
+          }
+        )
+      ) = isJust mDoc || isJust mWarn
+    has_doc (ExportNoDecl _ _) = False
+    has_doc (ExportModule _) = False
+    has_doc _ = True
+
+    no_doc_at_all = not (any has_doc exports)
+
+    description | isNoHtml doc = doc
+                | otherwise    = divDescription $ sectionName << "Description" +++ doc
+                where doc = docSection Nothing pkg qual (ifaceRnDoc iface)
+
+        -- omit the synopsis if there are no documentation annotations at all
+    synopsis
+      | no_doc_at_all = noHtml
+      | otherwise
+      = divSynopsis $
+            collapseDetails "syn" DetailsClosed (
+              thesummary << "Synopsis" +++
+              shortDeclList (
+                  mapMaybe (processExport True linksInfo unicode pkg qual) exports
+              ) ! collapseToggle "syn" ""
+            )
+
+        -- if the documentation doesn't begin with a section header, then
+        -- add one ("Documentation").
+    maybe_doc_hdr
+      = case exports of
+          [] -> noHtml
+          ExportGroup {} : _ -> noHtml
+          _ -> h1 << "Documentation"
+
+    bdy =
+      foldr (+++) noHtml $
+        mapMaybe (processExport False linksInfo unicode pkg qual) exports
+
+    orphans =
+      ppOrphanInstances linksInfo (ifaceRnOrphanInstances iface) False unicode pkg qual
+
+    linksInfo = (maybe_source_url, maybe_wiki_url)
+
+
+ppModuleContents :: Maybe Package -- ^ This package
+                 -> Qualification
+                 -> [ExportItem DocNameI]
+                 -> Bool          -- ^ Orphans sections
+                 -> Html
+ppModuleContents pkg qual exports orphan
+  | null sections && not orphan  = noHtml
+  | otherwise                    = contentsDiv
+ where
+  contentsDiv = divTableOfContents << (divContentsList << (
+    (sectionName << "Contents") ! [ strAttr "onclick" "window.scrollTo(0,0)" ] +++
+    unordList (sections ++ orphanSection)))
+
+  (sections, _leftovers{-should be []-}) = process 0 exports
+  orphanSection
+    | orphan =  [ linkedAnchor "section.orphans" << "Orphan instances" ]
+    | otherwise = []
+
+  process :: Int -> [ExportItem DocNameI] -> ([Html],[ExportItem DocNameI])
+  process _ [] = ([], [])
+  process n items@(ExportGroup lev id0 doc : rest)
+    | lev <= n  = ( [], items )
+    | otherwise = ( html:secs, rest2 )
+    where
+      html = linkedAnchor (groupId id0)
+             << docToHtmlNoAnchors (Just id0) pkg qual (mkMeta doc) +++ mk_subsections ssecs
+      (ssecs, rest1) = process lev rest
+      (secs,  rest2) = process n   rest1
+  process n (_ : rest) = process n rest
+
+  mk_subsections [] = noHtml
+  mk_subsections ss = unordList ss
+
+-- we need to assign a unique id to each section heading so we can hyperlink
+-- them from the contents:
+numberSectionHeadings :: [ExportItem DocNameI] -> [ExportItem DocNameI]
+numberSectionHeadings = go 1
+  where go :: Int -> [ExportItem DocNameI] -> [ExportItem DocNameI]
+        go _ [] = []
+        go n (ExportGroup lev _ doc : es)
+          = case collectAnchors doc of
+              [] -> ExportGroup lev (show n) doc : go (n+1) es
+              (a:_) -> ExportGroup lev a doc : go (n+1) es
+        go n (other:es)
+          = other : go n es
+
+        collectAnchors :: DocH (Wrap (ModuleName, OccName)) (Wrap DocName) -> [String]
+        collectAnchors (DocAppend a b) = collectAnchors a ++ collectAnchors b
+        collectAnchors (DocAName a) = [a]
+        collectAnchors _ = []
+
+processExport :: Bool -> LinksInfo -> Bool -> Maybe Package -> Qualification
+              -> ExportItem DocNameI -> Maybe Html
+processExport _ _ _ _ _
+    ( ExportDecl
+      ( RnExportD
+        { rnExpDExpD =
+            ExportD
+            { expDDecl = L _ (InstD {})
+            }
+        }
+      )
+    )
+  = Nothing -- Hide empty instances
+processExport summary links unicode pkg qual
+    ( ExportDecl
+      ( RnExportD
+        { rnExpDExpD =
+            ExportD decl pats doc subdocs insts fixities splice
+        }
+      )
+    )
+  = processDecl summary $ ppDecl summary links decl pats doc insts fixities subdocs splice unicode pkg qual
+processExport summary _ _ pkg qual (ExportGroup lev id0 doc)
+  = nothingIf summary $ groupHeading lev id0 << docToHtmlNoAnchors (Just id0) pkg qual (mkMeta doc)
+processExport summary _ _ _ qual (ExportNoDecl y [])
+  = processDeclOneLiner summary $ ppDocName qual Prefix True y
+processExport summary _ _ _ qual (ExportNoDecl y subs)
+  = processDeclOneLiner summary $
+      ppDocName qual Prefix True y
+      +++ parenList (map (ppDocName qual Prefix True) subs)
+processExport summary _ _ pkg qual (ExportDoc doc)
+  = nothingIf summary $ docSection_ Nothing pkg qual doc
+processExport summary _ _ _ _ (ExportModule mdl)
+  = processDeclOneLiner summary $ toHtml "module" <+> ppModule mdl
+
+
+nothingIf :: Bool -> a -> Maybe a
+nothingIf True _ = Nothing
+nothingIf False a = Just a
+
+
+processDecl :: Bool -> Html -> Maybe Html
+processDecl True = Just
+processDecl False = Just . divTopDecl
+
+trim :: String -> String
+trim = f . f
+  where f = reverse . dropWhile isSpace
+
+processDeclOneLiner :: Bool -> Html -> Maybe Html
+processDeclOneLiner True = Just
+processDeclOneLiner False = Just . divTopDecl . declElem
+
+groupHeading :: Int -> String -> Html -> Html
+groupHeading lev id0 = linkedAnchor grpId . groupTag lev ! [identifier grpId]
+  where grpId = groupId id0
+
+groupTag :: Int -> Html -> Html
+groupTag lev
+  | lev == 1  = h1
+  | lev == 2  = h2
+  | lev == 3  = h3
+  | otherwise = h4
diff --git a/haddock-api/src/Haddock/Backends/Xhtml/Decl.hs b/haddock-api/src/Haddock/Backends/Xhtml/Decl.hs
new file mode 100644
--- /dev/null
+++ b/haddock-api/src/Haddock/Backends/Xhtml/Decl.hs
@@ -0,0 +1,1312 @@
+{-# LANGUAGE TransformListComp #-}
+{-# LANGUAGE RecordWildCards #-}
+{-# LANGUAGE Rank2Types #-}
+{-# LANGUAGE TypeFamilies #-}
+{-# LANGUAGE LambdaCase #-}
+
+-----------------------------------------------------------------------------
+-- |
+-- Module      :  Haddock.Backends.Html.Decl
+-- Copyright   :  (c) Simon Marlow   2003-2006,
+--                    David Waern    2006-2009,
+--                    Mark Lentczner 2010
+-- License     :  BSD-like
+--
+-- Maintainer  :  haddock@projects.haskell.org
+-- Stability   :  experimental
+-- Portability :  portable
+-----------------------------------------------------------------------------
+module Haddock.Backends.Xhtml.Decl (
+  ppDecl,
+  ppOrphanInstances,
+) where
+
+import Haddock.Backends.Xhtml.DocMarkup
+import Haddock.Backends.Xhtml.Layout
+import Haddock.Backends.Xhtml.Names
+import Haddock.Backends.Xhtml.Types
+import Haddock.Backends.Xhtml.Utils
+import Haddock.GhcUtils
+import Haddock.Types
+import Haddock.Doc (combineDocumentation)
+
+import           Data.Foldable         ( toList )
+import           Data.List             ( intersperse, sort )
+import           Data.List.NonEmpty    ( NonEmpty (..) )
+import qualified Data.Map as Map
+import           Data.Maybe
+import           Text.XHtml hiding     ( name, title, p, quote )
+
+import GHC.Core.Type ( Specificity(..) )
+import GHC hiding (LexicalFixity(..), fromMaybeContext)
+import GHC.Exts hiding (toList)
+import GHC.Types.Name
+import GHC.Data.BooleanFormula
+import GHC.Types.Name.Reader ( rdrNameOcc )
+
+-- | Pretty print a declaration
+ppDecl :: Bool                                     -- ^ print summary info only
+       -> LinksInfo                                -- ^ link information
+       -> LHsDecl DocNameI                         -- ^ declaration to print
+       -> [(HsDecl DocNameI, DocForDecl DocName)]  -- ^ relevant pattern synonyms
+       -> DocForDecl DocName                       -- ^ documentation for this decl
+       -> [DocInstance DocNameI]                   -- ^ relevant instances
+       -> [(DocName, Fixity)]                      -- ^ relevant fixities
+       -> [(DocName, DocForDecl DocName)]          -- ^ documentation for all decls
+       -> Splice
+       -> Unicode                                  -- ^ unicode output
+       -> Maybe Package
+       -> Qualification
+       -> Html
+ppDecl summ links (L loc decl) pats (mbDoc, fnArgsDoc) instances fixities subdocs splice unicode pkg qual = case decl of
+  TyClD _ (FamDecl _ d)          -> ppFamDecl summ False links instances fixities (locA loc) mbDoc d splice unicode pkg qual
+  TyClD _ d@(DataDecl {})        -> ppDataDecl summ links instances fixities subdocs (locA loc) mbDoc d pats splice unicode pkg qual
+  TyClD _ d@(SynDecl {})         -> ppTySyn summ links fixities (locA loc) (mbDoc, fnArgsDoc) d splice unicode pkg qual
+  TyClD _ d@(ClassDecl {})       -> ppClassDecl summ links instances fixities (locA loc) mbDoc subdocs d splice unicode pkg qual
+  SigD _ (TypeSig _ lnames lty)  -> ppLFunSig summ links (locA loc) (mbDoc, fnArgsDoc) lnames
+                                         (dropWildCards lty) fixities splice unicode pkg qual
+  SigD _ (PatSynSig _ lnames lty) -> ppLPatSig summ links (locA loc) (mbDoc, fnArgsDoc) lnames
+                                         lty fixities splice unicode pkg qual
+  ForD _ d                       -> ppFor summ links (locA loc) (mbDoc, fnArgsDoc) d fixities splice unicode pkg qual
+  InstD _ _                      -> noHtml
+  DerivD _ _                     -> noHtml
+  _                              -> error "declaration not supported by ppDecl"
+
+
+ppLFunSig :: Bool -> LinksInfo -> SrcSpan -> DocForDecl DocName ->
+             [LocatedN DocName] -> LHsSigType DocNameI -> [(DocName, Fixity)] ->
+             Splice -> Unicode -> Maybe Package -> Qualification -> Html
+ppLFunSig summary links loc doc lnames lty fixities splice unicode pkg qual =
+  ppFunSig summary links loc noHtml doc (map unLoc lnames) lty fixities
+           splice unicode pkg qual
+
+ppFunSig :: Bool -> LinksInfo -> SrcSpan -> Html -> DocForDecl DocName ->
+            [DocName] -> LHsSigType DocNameI -> [(DocName, Fixity)] ->
+            Splice -> Unicode -> Maybe Package -> Qualification -> Html
+ppFunSig summary links loc leader doc docnames typ fixities splice unicode pkg qual =
+  ppSigLike summary links loc leader doc docnames fixities (unLoc typ, pp_typ)
+            splice unicode pkg qual HideEmptyContexts
+  where
+    pp_typ = ppLSigType unicode qual HideEmptyContexts typ
+
+-- | Pretty print a pattern synonym
+ppLPatSig :: Bool -> LinksInfo -> SrcSpan -> DocForDecl DocName
+          -> [LocatedN DocName]     -- ^ names of patterns in declaration
+          -> LHsSigType DocNameI   -- ^ type of patterns in declaration
+          -> [(DocName, Fixity)]
+          -> Splice -> Unicode -> Maybe Package -> Qualification -> Html
+ppLPatSig summary links loc doc lnames typ fixities splice unicode pkg qual =
+  ppSigLike summary links loc (keyword "pattern") doc (map unLoc lnames) fixities
+            (unLoc typ, pp_typ) splice unicode pkg qual (patSigContext typ)
+  where
+    pp_typ = ppPatSigType unicode qual typ
+
+
+ppSigLike :: Bool -> LinksInfo -> SrcSpan -> Html -> DocForDecl DocName ->
+             [DocName] -> [(DocName, Fixity)] -> (HsSigType DocNameI, Html) ->
+             Splice -> Unicode -> Maybe Package -> Qualification -> HideEmptyContexts -> Html
+ppSigLike summary links loc leader doc docnames fixities (typ, pp_typ)
+          splice unicode pkg qual emptyCtxts =
+  ppTypeOrFunSig summary links loc docnames typ doc
+    ( addFixities $ leader <+> ppTypeSig summary occnames pp_typ unicode
+    , (leader <+>) . addFixities . concatHtml . punctuate comma $ map (ppBinder False) occnames
+    , dcolon unicode
+    )
+    splice unicode pkg qual emptyCtxts
+  where
+    occnames = map (nameOccName . getName) docnames
+    addFixities html
+      | summary   = html
+      | otherwise = html <+> ppFixities fixities qual
+
+
+ppTypeOrFunSig :: Bool -> LinksInfo -> SrcSpan -> [DocName] -> HsSigType DocNameI
+               -> DocForDecl DocName -> (Html, Html, Html)
+               -> Splice -> Unicode -> Maybe Package -> Qualification
+               -> HideEmptyContexts -> Html
+ppTypeOrFunSig summary links loc docnames typ (doc, argDocs) (pref1, pref2, sep)
+               splice unicode pkg qual emptyCtxts
+  | summary = pref1
+  | Map.null argDocs = topDeclElem links loc splice docnames pref1 +++ docSection curname pkg qual doc
+  | otherwise = topDeclElem links loc splice docnames pref2
+                  +++ subArguments pkg qual (ppSubSigLike unicode qual typ argDocs [] sep emptyCtxts)
+                  +++ docSection curname pkg qual doc
+  where
+    curname = getName <$> listToMaybe docnames
+
+
+-- | This splits up a type signature along @->@ and adds docs (when they exist)
+-- to the arguments.
+--
+-- If one passes in a list of the available subdocs, any top-level `HsRecTy`
+-- found will be expanded out into their fields.
+ppSubSigLike :: Unicode -> Qualification
+             -> HsSigType DocNameI               -- ^ type signature
+             -> FnArgsDoc DocName                -- ^ docs to add
+             -> [(DocName, DocForDecl DocName)]  -- ^ all subdocs (useful when
+                                                 -- we expand an `HsRecTy`)
+             -> Html -> HideEmptyContexts -> [SubDecl]
+ppSubSigLike unicode qual typ argDocs subdocs sep emptyCtxts = do_sig_args 0 sep typ
+  where
+    do_sig_args :: Int -> Html -> HsSigType DocNameI -> [SubDecl]
+    do_sig_args n leader (HsSig { sig_bndrs = outer_bndrs, sig_body = ltype }) =
+      case outer_bndrs of
+        HsOuterExplicit{hso_bndrs = bndrs} -> do_largs n (leader' bndrs) ltype
+        HsOuterImplicit{}                  -> do_largs n leader          ltype
+      where
+        leader' bndrs = leader <+> ppForAllPart unicode qual (mkHsForAllInvisTeleI bndrs)
+
+    argDoc n = Map.lookup n argDocs
+
+    do_largs :: Int -> Html -> LHsType DocNameI -> [SubDecl]
+    do_largs n leader (L _ t) = do_args n leader t
+
+    do_args :: Int -> Html -> HsType DocNameI -> [SubDecl]
+    do_args n leader (HsForAllTy _ tele ltype)
+      = do_largs n leader' ltype
+      where
+        leader' = leader <+> ppForAllPart unicode qual tele
+
+    do_args n leader (HsQualTy _ lctxt ltype)
+      | null (unLoc lctxt)
+      = do_largs n leader ltype
+      | otherwise
+      = (leader <+> ppLContextNoArrow lctxt unicode qual emptyCtxts, Nothing, [])
+        : do_largs n (darrow unicode) ltype
+
+    do_args n leader (HsFunTy _ _w (L _ (HsRecTy _ fields)) r)
+      = [ (ldr <+> html, mdoc, subs)
+        | (L _ field, ldr) <- zip fields (leader <+> gadtOpen : repeat gadtComma)
+        , let (html, mdoc, subs) = ppSideBySideField subdocs unicode qual field
+        ]
+        ++ do_largs (n+1) (gadtEnd <+> arrow unicode) r
+
+    do_args n leader (HsFunTy _ _w lt r)
+      = (leader <+> ppLFunLhType unicode qual emptyCtxts lt, argDoc n, [])
+        : do_largs (n+1) (arrow unicode) r
+
+    do_args n leader t
+      = [(leader <+> ppType unicode qual emptyCtxts t, argDoc n, [])]
+
+
+    -- FIXME: this should be done more elegantly
+    --
+    -- We need 'gadtComma' and 'gadtEnd' to line up with the `{` from
+    -- 'gadtOpen', so we add 3 spaces to cover for `-> `/`:: ` (3 in unicode
+    -- mode since `->` and `::` are rendered as single characters.
+    gadtComma = concatHtml (replicate (if unicode then 2 else 3) spaceHtml) <> toHtml ","
+    gadtEnd = concatHtml (replicate (if unicode then 2 else 3) spaceHtml) <> toHtml "}"
+    gadtOpen = toHtml "{"
+
+
+ppFixities :: [(DocName, Fixity)] -> Qualification -> Html
+ppFixities [] _ = noHtml
+ppFixities fs qual = foldr1 (+++) (map ppFix uniq_fs) +++ rightEdge
+  where
+    ppFix (ns, p, d) = thespan ! [theclass "fixity"] <<
+                         (toHtml d <+> toHtml (show p) <+> ppNames ns)
+
+    ppDir InfixR = "infixr"
+    ppDir InfixL = "infixl"
+    ppDir InfixN = "infix"
+
+    ppNames = case fs of
+      _:[] -> const noHtml -- Don't display names for fixities on single names
+      _    -> concatHtml . intersperse (stringToHtml ", ") . map (ppDocName qual Infix False)
+
+    uniq_fs = [ (n, the p, the d') | (n, Fixity _ p d) <- fs
+                                   , let d' = ppDir d
+                                   , then group by Down (p,d') using groupWith ]
+
+    rightEdge = thespan ! [theclass "rightedge"] << noHtml
+
+
+-- | Pretty-print type variables.
+ppTyVars :: RenderableBndrFlag flag =>
+  Unicode -> Qualification -> [LHsTyVarBndr flag DocNameI] -> [Html]
+ppTyVars unicode qual tvs = map (ppHsTyVarBndr unicode qual . unLoc) tvs
+
+
+ppFor :: Bool -> LinksInfo -> SrcSpan -> DocForDecl DocName
+      -> ForeignDecl DocNameI -> [(DocName, Fixity)]
+      -> Splice -> Unicode -> Maybe Package -> Qualification -> Html
+ppFor summary links loc doc (ForeignImport _ (L _ name) typ _) fixities
+      splice unicode pkg qual
+  = ppFunSig summary links loc noHtml doc [name] typ fixities splice unicode pkg qual
+ppFor _ _ _ _ _ _ _ _ _ _ = error "ppFor"
+
+
+-- we skip type patterns for now
+ppTySyn :: Bool -> LinksInfo -> [(DocName, Fixity)] -> SrcSpan
+        -> DocForDecl DocName -> TyClDecl DocNameI
+        -> Splice -> Unicode -> Maybe Package -> Qualification -> Html
+ppTySyn summary links fixities loc doc (SynDecl { tcdLName = L _ name, tcdTyVars = ltyvars
+                                                , tcdRhs = ltype })
+        splice unicode pkg qual
+  = ppTypeOrFunSig summary links loc [name] sig_type doc
+                   (full <+> fixs, hdr <+> fixs, spaceHtml +++ equals)
+                   splice unicode pkg qual ShowEmptyToplevelContexts
+  where
+    sig_type = mkHsImplicitSigTypeI ltype
+    hdr  = hsep ([keyword "type", ppBinder summary occ]
+                 ++ ppTyVars unicode qual (hsQTvExplicit ltyvars))
+    full = hdr <+> equals <+> ppPatSigType unicode qual (noLocA sig_type)
+    occ  = nameOccName . getName $ name
+    fixs
+      | summary   = noHtml
+      | otherwise = ppFixities fixities qual
+ppTySyn _ _ _ _ _ _ _ _ _ _ = error "declaration not supported by ppTySyn"
+
+
+ppTypeSig :: Bool -> [OccName] -> Html -> Unicode -> Html
+ppTypeSig summary nms pp_ty unicode =
+  concatHtml htmlNames <+> dcolon unicode <+> pp_ty
+  where
+    htmlNames = intersperse (stringToHtml ", ") $ map (ppBinder summary) nms
+
+ppSimpleSig :: LinksInfo -> Splice -> Unicode -> Qualification -> HideEmptyContexts -> SrcSpan
+            -> [DocName] -> HsSigType DocNameI
+            -> Html
+ppSimpleSig links splice unicode qual emptyCtxts loc names typ =
+    topDeclElem' names $ ppTypeSig True occNames ppTyp unicode
+  where
+    topDeclElem' = topDeclElem links loc splice
+    ppTyp = ppSigType unicode qual emptyCtxts typ
+    occNames = map getOccName names
+
+
+--------------------------------------------------------------------------------
+-- * Type families
+--------------------------------------------------------------------------------
+
+
+-- | Print a data\/type family declaration
+ppFamDecl :: Bool                     -- ^ is a summary
+          -> Bool                     -- ^ is an associated type
+          -> LinksInfo
+          -> [DocInstance DocNameI]   -- ^ relevant instances
+          -> [(DocName, Fixity)]      -- ^ relevant fixities
+          -> SrcSpan
+          -> Documentation DocName    -- ^ this decl's documentation
+          -> FamilyDecl DocNameI      -- ^ this decl
+          -> Splice -> Unicode -> Maybe Package -> Qualification -> Html
+ppFamDecl summary associated links instances fixities loc doc decl splice unicode pkg qual
+  | summary   = ppFamHeader True associated decl unicode qual
+  | otherwise = header_ +++ docSection curname pkg qual doc +++ instancesBit
+
+  where
+    docname = unLoc $ fdLName decl
+    curname = Just $ getName docname
+
+    header_ = topDeclElem links loc splice [docname] $
+       ppFamHeader summary associated decl unicode qual <+> ppFixities fixities qual
+
+    instancesBit
+      | FamilyDecl { fdInfo = ClosedTypeFamily mb_eqns } <- decl
+      , not summary
+      = subEquations pkg qual $ map (ppFamDeclEqn . unLoc) $ fromMaybe [] mb_eqns
+
+      | otherwise
+      = ppInstances links (OriginFamily docname) instances splice unicode pkg qual
+
+    -- Individual equation of a closed type family
+    ppFamDeclEqn :: TyFamInstEqn DocNameI -> SubDecl
+    ppFamDeclEqn (FamEqn { feqn_tycon = L _ n
+                         , feqn_rhs = rhs
+                         , feqn_pats = ts })
+      = ( ppAppNameTypeArgs n ts unicode qual
+          <+> equals <+> ppType unicode qual HideEmptyContexts (unLoc rhs)
+        , Nothing
+        , []
+        )
+
+
+-- | Print a pseudo family declaration
+ppPseudoFamDecl :: LinksInfo -> Splice
+                -> PseudoFamilyDecl DocNameI   -- ^ this decl
+                -> Unicode -> Qualification -> Html
+ppPseudoFamDecl links splice
+                (PseudoFamilyDecl { pfdInfo = info
+                                  , pfdKindSig = L _ kindSig
+                                  , pfdTyVars = tvs
+                                  , pfdLName = L loc name })
+                unicode qual =
+    topDeclElem links (locA loc) splice [name] leader
+  where
+    leader = hsep [ ppFamilyLeader True info
+                  , ppAppNameTypes name (map unLoc tvs) unicode qual
+                  , ppResultSig kindSig unicode qual
+                  ]
+
+-- | Print the LHS of a type\/data family declaration
+ppFamHeader :: Bool                 -- ^ is a summary
+            -> Bool                 -- ^ is an associated type
+            -> FamilyDecl DocNameI  -- ^ family declaration
+            -> Unicode -> Qualification -> Html
+ppFamHeader summary associated (FamilyDecl { fdInfo = info
+                                           , fdResultSig = L _ result
+                                           , fdInjectivityAnn = injectivity
+                                           , fdLName = L _ name
+                                           , fdTyVars = tvs })
+              unicode qual =
+  hsep [ ppFamilyLeader associated info
+       , ppAppDocNameTyVarBndrs summary unicode qual name (hsq_explicit tvs)
+       , ppResultSig result unicode qual
+       , injAnn
+       , whereBit
+       ]
+  where
+    whereBit = case info of
+      ClosedTypeFamily _ -> keyword "where ..."
+      _                  -> noHtml
+
+    injAnn = case injectivity of
+      Nothing -> noHtml
+      Just (L _ (InjectivityAnn _ lhs rhs)) -> hsep ( keyword "|"
+                                                    : ppLDocName qual Raw lhs
+                                                    : arrow unicode
+                                                    : map (ppLDocName qual Raw) rhs)
+      Just _ -> error "ppFamHeader:XInjectivityAnn"
+
+-- | Print the keywords that begin the family declaration
+ppFamilyLeader :: Bool -> FamilyInfo DocNameI -> Html
+ppFamilyLeader assoc info = keyword (typ ++ if assoc then "" else " family")
+  where
+    typ = case info of
+       OpenTypeFamily     -> "type"
+       ClosedTypeFamily _ -> "type"
+       DataFamily         -> "data"
+
+-- | Print the signature attached to a family
+ppResultSig :: FamilyResultSig DocNameI -> Unicode -> Qualification -> Html
+ppResultSig result unicode qual = case result of
+    NoSig _               -> noHtml
+    KindSig _ kind        -> dcolon unicode  <+> ppLKind unicode qual kind
+    TyVarSig _ (L _ bndr) -> equals <+> ppHsTyVarBndr unicode qual bndr
+
+
+--------------------------------------------------------------------------------
+-- * Associated Types
+--------------------------------------------------------------------------------
+
+
+ppAssocType :: Bool -> LinksInfo -> DocForDecl DocName -> LFamilyDecl DocNameI
+            -> [(DocName, Fixity)] -> Splice -> Unicode -> Maybe Package
+            -> Qualification -> Html
+ppAssocType summ links doc (L loc decl) fixities splice unicode pkg qual =
+   ppFamDecl summ True links [] fixities loc (fst doc) decl splice unicode pkg qual
+
+
+--------------------------------------------------------------------------------
+-- * Type applications
+--------------------------------------------------------------------------------
+
+ppAppDocNameTyVarBndrs :: RenderableBndrFlag flag =>
+  Bool -> Unicode -> Qualification -> DocName -> [LHsTyVarBndr flag DocNameI] -> Html
+ppAppDocNameTyVarBndrs summ unicode qual n vs =
+    ppTypeApp n vs ppDN (ppHsTyVarBndr unicode qual . unLoc)
+  where
+    ppDN notation = ppBinderFixity notation summ . nameOccName . getName
+    ppBinderFixity Infix = ppBinderInfix
+    ppBinderFixity _ = ppBinder
+
+-- | Print an application of a 'DocName' to its list of 'HsType's
+ppAppNameTypes :: DocName -> [HsType DocNameI] -> Unicode -> Qualification -> Html
+ppAppNameTypes n ts unicode qual =
+    ppTypeApp n ts (\p -> ppDocName qual p True) (ppParendType unicode qual HideEmptyContexts)
+
+ppAppNameTypeArgs :: DocName -> [LHsTypeArg DocNameI] -> Unicode -> Qualification -> Html
+ppAppNameTypeArgs n args@(HsValArg _:HsValArg _:_) u q
+  = ppTypeApp n args (\p -> ppDocName q p True) (ppLHsTypeArg u q HideEmptyContexts)
+ppAppNameTypeArgs n args u q
+  = (ppDocName q Prefix True n) <+> hsep (map (ppLHsTypeArg u q HideEmptyContexts) args)
+
+-- | General printing of type applications
+ppTypeApp :: DocName -> [a] -> (Notation -> DocName -> Html) -> (a -> Html) -> Html
+ppTypeApp n (t1:t2:rest) ppDN ppT
+  | operator, not . null $ rest = parens opApp <+> hsep (map ppT rest)
+  | operator                    = opApp
+  where
+    operator = isNameSym . getName $ n
+    opApp = ppT t1 <+> ppDN Infix n <+> ppT t2
+
+ppTypeApp n ts ppDN ppT = ppDN Prefix n <+> hsep (map ppT ts)
+
+-------------------------------------------------------------------------------
+-- * Contexts
+-------------------------------------------------------------------------------
+
+
+ppLContext :: Maybe (LHsContext DocNameI) -> Unicode
+                              -> Qualification -> HideEmptyContexts -> Html
+ppLContext        Nothing  u q h = ppContext        []        u q h
+ppLContext        (Just c) u q h = ppContext        (unLoc c) u q h
+
+ppLContextNoArrow :: LHsContext DocNameI -> Unicode
+                              -> Qualification -> HideEmptyContexts -> Html
+ppLContextNoArrow c u q h = ppContextNoArrow (unLoc c) u q h
+
+ppContextNoArrow :: HsContext DocNameI -> Unicode -> Qualification -> HideEmptyContexts -> Html
+ppContextNoArrow cxt unicode qual emptyCtxts = fromMaybe noHtml $
+                                               ppContextNoLocsMaybe (map unLoc cxt) unicode qual emptyCtxts
+
+
+ppContextNoLocs :: [HsType DocNameI] -> Unicode -> Qualification -> HideEmptyContexts -> Html
+ppContextNoLocs cxt unicode qual emptyCtxts = maybe noHtml (<+> darrow unicode) $
+                                              ppContextNoLocsMaybe cxt unicode qual emptyCtxts
+
+
+ppContextNoLocsMaybe :: [HsType DocNameI] -> Unicode -> Qualification -> HideEmptyContexts -> Maybe Html
+ppContextNoLocsMaybe [] _ _ emptyCtxts =
+  case emptyCtxts of
+    HideEmptyContexts -> Nothing
+    ShowEmptyToplevelContexts -> Just (toHtml "()")
+ppContextNoLocsMaybe cxt unicode qual _ = Just $ ppHsContext cxt unicode qual
+
+ppContext :: HsContext DocNameI -> Unicode -> Qualification -> HideEmptyContexts -> Html
+ppContext cxt unicode qual emptyCtxts = ppContextNoLocs (map unLoc cxt) unicode qual emptyCtxts
+
+
+ppHsContext :: [HsType DocNameI] -> Unicode -> Qualification -> Html
+ppHsContext []  _       _    = noHtml
+ppHsContext [p] unicode qual = ppCtxType unicode qual p
+ppHsContext cxt unicode qual = parenList (map (ppType unicode qual HideEmptyContexts) cxt)
+
+
+-------------------------------------------------------------------------------
+-- * Class declarations
+-------------------------------------------------------------------------------
+
+
+ppClassHdr :: Bool -> Maybe (LocatedC [LHsType DocNameI]) -> DocName
+           -> LHsQTyVars DocNameI -> [LHsFunDep DocNameI]
+           -> Unicode -> Qualification -> Html
+ppClassHdr summ lctxt n tvs fds unicode qual =
+  keyword "class"
+  <+> (if not (null $ fromMaybeContext lctxt) then ppLContext lctxt unicode qual HideEmptyContexts else noHtml)
+  <+> ppAppDocNameTyVarBndrs summ unicode qual n (hsQTvExplicit tvs)
+  <+> ppFds fds unicode qual
+
+
+ppFds :: [LHsFunDep DocNameI] -> Unicode -> Qualification -> Html
+ppFds fds unicode qual =
+  if null fds then noHtml else
+        char '|' <+> hsep (punctuate comma (map (fundep . unLoc) fds))
+  where
+        fundep (FunDep _ vars1 vars2) = ppVars vars1 <+> arrow unicode <+> ppVars vars2
+        fundep (XFunDep _) = error "ppFds"
+        ppVars = hsep . map ((ppDocName qual Prefix True) . unLoc)
+
+ppShortClassDecl :: Bool -> LinksInfo -> TyClDecl DocNameI -> SrcSpan
+                 -> [(DocName, DocForDecl DocName)]
+                 -> Splice -> Unicode -> Maybe Package -> Qualification -> Html
+ppShortClassDecl summary links (ClassDecl { tcdCtxt = lctxt, tcdLName = lname, tcdTyVars = tvs
+                                          , tcdFDs = fds, tcdSigs = sigs, tcdATs = ats }) loc
+    subdocs splice unicode pkg qual =
+  if not (any isUserLSig sigs) && null ats
+    then (if summary then id else topDeclElem links loc splice [nm]) hdr
+    else (if summary then id else topDeclElem links loc splice [nm]) (hdr <+> keyword "where")
+      +++ shortSubDecls False
+          (
+            [ ppAssocType summary links doc at [] splice unicode pkg qual | at <- ats
+              , let doc = lookupAnySubdoc (unL $ fdLName $ unL at) subdocs ]  ++
+
+                -- ToDo: add associated type defaults
+
+            [ ppFunSig summary links loc noHtml doc names typ
+                       [] splice unicode pkg qual
+              | L _ (ClassOpSig _ False lnames typ) <- sigs
+              , let doc = lookupAnySubdoc (head names) subdocs
+                    names = map unLoc lnames ]
+              -- FIXME: is taking just the first name ok? Is it possible that
+              -- there are different subdocs for different names in a single
+              -- type signature?
+          )
+  where
+    hdr = ppClassHdr summary lctxt (unLoc lname) tvs fds unicode qual
+    nm  = unLoc lname
+ppShortClassDecl _ _ _ _ _ _ _ _ _ = error "declaration type not supported by ppShortClassDecl"
+
+
+
+ppClassDecl :: Bool -> LinksInfo -> [DocInstance DocNameI] -> [(DocName, Fixity)]
+            -> SrcSpan -> Documentation DocName
+            -> [(DocName, DocForDecl DocName)] -> TyClDecl DocNameI
+            -> Splice -> Unicode -> Maybe Package -> Qualification -> Html
+ppClassDecl summary links instances fixities loc d subdocs
+        decl@(ClassDecl { tcdCtxt = lctxt, tcdLName = lname, tcdTyVars = ltyvars
+                        , tcdFDs = lfds, tcdSigs = lsigs, tcdATs = ats, tcdATDefs = atsDefs })
+            splice unicode pkg qual
+  | summary = ppShortClassDecl summary links decl loc subdocs splice unicode pkg qual
+  | otherwise = classheader +++ docSection curname pkg qual d
+                  +++ minimalBit +++ atBit +++ methodBit +++ instancesBit
+  where
+    curname = Just $ getName nm
+
+    sigs = map unLoc lsigs
+
+    classheader
+      | any isUserLSig lsigs = topDeclElem links loc splice [nm] (hdr unicode qual <+> keyword "where" <+> fixs)
+      | otherwise = topDeclElem links loc splice [nm] (hdr unicode qual <+> fixs)
+
+    -- Only the fixity relevant to the class header
+    fixs = ppFixities [ f | f@(n,_) <- fixities, n == unLoc lname ] qual
+
+    nm   = tcdNameI decl
+
+    hdr = ppClassHdr summary lctxt (unLoc lname) ltyvars lfds
+
+    -- Associated types
+    atBit = subAssociatedTypes
+      [ ppAssocType summary links doc at subfixs splice unicode pkg qual
+          <+>
+        subDefaults (maybeToList defTys)
+      | at <- ats
+      , let name = unLoc . fdLName $ unLoc at
+            doc = lookupAnySubdoc name subdocs
+            subfixs = filter ((== name) . fst) fixities
+            defTys = (declElem . ppDefaultAssocTy name) <$> lookupDAT name
+      ]
+
+    -- Default associated types
+    ppDefaultAssocTy n (vs,rhs) = hsep
+      [ keyword "type", ppAppNameTypeArgs n vs unicode qual, equals
+      , ppType unicode qual HideEmptyContexts (unLoc rhs)
+      ]
+
+    lookupDAT name = Map.lookup (getName name) defaultAssocTys
+    defaultAssocTys = Map.fromList
+      [ (getName name, (vs, typ))
+      | L _ (TyFamInstDecl _ (FamEqn { feqn_rhs = typ
+                                     , feqn_tycon = L _ name
+                                     , feqn_pats = vs })) <- atsDefs
+      ]
+
+    -- Methods
+    methodBit = subMethods
+      [ ppFunSig summary links loc noHtml doc [name] typ
+                 subfixs splice unicode pkg qual
+          <+>
+        subDefaults (maybeToList defSigs)
+      | ClassOpSig _ False lnames typ <- sigs
+      , name <- map unLoc lnames
+      , let doc = lookupAnySubdoc name subdocs
+            subfixs = filter ((== name)  . fst) fixities
+            defSigs = ppDefaultFunSig name <$> lookupDM name
+      ]
+      -- N.B. taking just the first name is ok. Signatures with multiple names
+      -- are expanded so that each name gets its own signature.
+
+    -- Default methods
+    ppDefaultFunSig n (t, d') = ppFunSig summary links loc (keyword "default")
+      d' [n] t [] splice unicode pkg qual
+
+    lookupDM name = Map.lookup (getOccString name) defaultMethods
+    defaultMethods = Map.fromList
+      [ (nameStr, (typ, doc))
+      | ClassOpSig _ True lnames typ <- sigs
+      , name <- map unLoc lnames
+      , let doc = noDocForDecl -- TODO: get docs for method defaults
+            nameStr = getOccString name
+      ]
+
+    -- Minimal complete definition
+    minimalBit = case [ s | MinimalSig _ (L _ s) <- sigs ] of
+      -- Miminal complete definition = every shown method
+      And xs : _ | sort [getName n | L _ (Var (L _ n)) <- xs] ==
+                   sort [getName n | ClassOpSig _ _ ns _ <- sigs, L _ n <- ns]
+        -> noHtml
+
+      -- Minimal complete definition = the only shown method
+      Var (L _ n) : _ | [getName n] ==
+                        [getName n' | L _ (ClassOpSig _ _ ns _) <- lsigs, L _ n' <- ns]
+        -> noHtml
+
+      -- Minimal complete definition = nothing
+      And [] : _ -> subMinimal $ toHtml "Nothing"
+
+      m : _  -> subMinimal $ ppMinimal False m
+      _ -> noHtml
+
+    ppMinimal _ (Var (L _ n)) = ppDocName qual Prefix True n
+    ppMinimal _ (And fs) = foldr1 (\a b -> a+++", "+++b) $ map (ppMinimal True . unLoc) fs
+    ppMinimal p (Or fs) = wrap $ foldr1 (\a b -> a+++" | "+++b) $ map (ppMinimal False . unLoc) fs
+      where wrap | p = parens | otherwise = id
+    ppMinimal p (Parens x) = ppMinimal p (unLoc x)
+
+    -- Instances
+    instancesBit = ppInstances links (OriginClass nm) instances
+        splice unicode pkg qual
+
+ppClassDecl _ _ _ _ _ _ _ _ _ _ _ _ = error "declaration type not supported by ppShortClassDecl"
+
+
+ppInstances :: LinksInfo
+            -> InstOrigin DocName -> [DocInstance DocNameI]
+            -> Splice -> Unicode -> Maybe Package -> Qualification
+            -> Html
+ppInstances links origin instances splice unicode pkg qual
+  = subInstances pkg qual instName links True (zipWith instDecl [1..] instances)
+  -- force Splice = True to use line URLs
+  where
+    instName = getOccString origin
+    instDecl :: Int -> DocInstance DocNameI -> (SubDecl, Maybe Module, Located DocName)
+    instDecl no (inst, mdoc, loc, mdl) =
+        ((ppInstHead links splice unicode qual mdoc origin False no inst mdl), mdl, loc)
+
+
+ppOrphanInstances :: LinksInfo
+                  -> [DocInstance DocNameI]
+                  -> Splice -> Unicode -> Maybe Package -> Qualification
+                  -> Html
+ppOrphanInstances links instances splice unicode pkg qual
+  = subOrphanInstances pkg qual links True (zipWith instDecl [1..] instances)
+  where
+    instOrigin :: InstHead name -> InstOrigin (IdP name)
+    instOrigin inst = OriginClass (ihdClsName inst)
+
+    instDecl :: Int -> DocInstance DocNameI -> (SubDecl, Maybe Module, Located DocName)
+    instDecl no (inst, mdoc, loc, mdl) =
+        ((ppInstHead links splice unicode qual mdoc (instOrigin inst) True no inst Nothing), mdl, loc)
+
+
+ppInstHead :: LinksInfo -> Splice -> Unicode -> Qualification
+           -> Maybe (MDoc DocName)
+           -> InstOrigin DocName
+           -> Bool -- ^ Is instance orphan
+           -> Int  -- ^ Normal
+           -> InstHead DocNameI
+           -> Maybe Module
+           -> SubDecl
+ppInstHead links splice unicode qual mdoc origin orphan no ihd@(InstHead {..}) mdl =
+    case ihdInstType of
+        ClassInst { .. } ->
+            ( subInstHead iid $ ppContextNoLocs clsiCtx unicode qual HideEmptyContexts <+> typ
+            , mdoc
+            , [subInstDetails iid ats sigs mname]
+            )
+          where
+            sigs = ppInstanceSigs links splice unicode qual clsiSigs
+            ats = ppInstanceAssocTys links splice unicode qual clsiAssocTys
+        TypeInst rhs ->
+            ( subInstHead iid ptype
+            , mdoc
+            , [subFamInstDetails iid prhs mname]
+            )
+          where
+            ptype = keyword "type" <+> typ
+            prhs = ptype <+> maybe noHtml
+                                   (\t -> equals <+> ppType unicode qual HideEmptyContexts t) rhs
+        DataInst dd ->
+            ( subInstHead iid pdata
+            , mdoc
+            , [subFamInstDetails iid pdecl mname])
+          where
+            cons = dd_cons (tcdDataDefn dd)
+            pref = case cons of { NewTypeCon _ -> keyword "newtype"; DataTypeCons _ _ -> keyword "data" }
+            pdata = pref <+> typ
+            pdecl = pdata <+> ppShortDataDecl False True dd [] unicode qual
+  where
+    mname = maybe noHtml (\m -> toHtml "Defined in" <+> ppModule m) mdl
+    iid = instanceId origin no orphan ihd
+    typ = ppAppNameTypes ihdClsName ihdTypes unicode qual
+
+
+ppInstanceAssocTys :: LinksInfo -> Splice -> Unicode -> Qualification
+                   -> [PseudoFamilyDecl DocNameI]
+                   -> [Html]
+ppInstanceAssocTys links splice unicode qual =
+    map (\pseudo -> ppPseudoFamDecl links splice pseudo unicode qual)
+
+
+ppInstanceSigs :: LinksInfo -> Splice -> Unicode -> Qualification
+              -> [Sig DocNameI]
+              -> [Html]
+ppInstanceSigs links splice unicode qual sigs = do
+    TypeSig _ lnames typ <- sigs
+    let names = map unLoc lnames
+        L _ rtyp = dropWildCards typ
+    -- Instance methods signatures are synified and thus don't have a useful
+    -- SrcSpan value. Use the methods name location instead.
+    return $ ppSimpleSig links splice unicode qual HideEmptyContexts (getLocA $ head lnames) names rtyp
+
+
+lookupAnySubdoc :: Eq id1 => id1 -> [(id1, DocForDecl id2)] -> DocForDecl id2
+lookupAnySubdoc n = fromMaybe noDocForDecl . lookup n
+
+
+instanceId :: InstOrigin DocName -> Int -> Bool -> InstHead DocNameI -> String
+instanceId origin no orphan ihd = concat $
+    [ "o:" | orphan ] ++
+    [ qual origin
+    , ":" ++ getOccString origin
+    , ":" ++ getOccString (ihdClsName ihd)
+    , ":" ++ show no
+    ]
+  where
+    qual (OriginClass _) = "ic"
+    qual (OriginData _) = "id"
+    qual (OriginFamily _) = "if"
+
+
+-------------------------------------------------------------------------------
+-- * Data & newtype declarations
+-------------------------------------------------------------------------------
+
+
+-- TODO: print contexts
+ppShortDataDecl :: Bool -> Bool -> TyClDecl DocNameI
+                -> [(HsDecl DocNameI, DocForDecl DocName)]
+                -> Unicode -> Qualification -> Html
+ppShortDataDecl summary dataInst dataDecl pats unicode qual
+
+  | [] <- toList cons
+  , [] <- pats = dataHeader
+
+  | [lcon] <- toList cons, [] <- pats, isH98,
+    (cHead,cBody,cFoot) <- ppShortConstrParts summary dataInst (unLoc lcon) unicode qual
+       = (dataHeader <+> equals <+> cHead) +++ cBody +++ cFoot
+
+  | [] <- pats, isH98 = dataHeader
+      +++ shortSubDecls dataInst (zipWith doConstr ('=':repeat '|') (toList cons) ++ pats1)
+
+  | otherwise = (dataHeader <+> keyword "where")
+      +++ shortSubDecls dataInst (map doGADTConstr (toList cons) ++ pats1)
+
+  where
+    dataHeader
+      | dataInst  = noHtml
+      | otherwise = ppDataHeader summary dataDecl unicode qual
+    doConstr c con = toHtml [c] <+> ppShortConstr summary (unLoc con) unicode qual
+    doGADTConstr con = ppShortConstr summary (unLoc con) unicode qual
+
+    cons      = dd_cons (tcdDataDefn dataDecl)
+    isH98     = flip any (unLoc <$> cons) $ \ case
+                  ConDeclH98 {} -> True
+                  ConDeclGADT{} -> False
+
+    pats1 = [ hsep [ keyword "pattern"
+                   , hsep $ punctuate comma $ map (ppBinder summary . getOccName) lnames
+                   , dcolon unicode
+                   , ppPatSigType unicode qual typ
+                   ]
+            | (SigD _ (PatSynSig _ lnames typ),_) <- pats
+            ]
+
+
+-- | Pretty-print a data declaration
+ppDataDecl :: Bool -> LinksInfo
+           -> [DocInstance DocNameI]                  -- ^ relevant instances
+           -> [(DocName, Fixity)]                     -- ^ relevant fixities
+           -> [(DocName, DocForDecl DocName)]         -- ^ all decl documentation
+           -> SrcSpan
+           -> Documentation DocName                   -- ^ this decl's documentation
+           -> TyClDecl DocNameI                       -- ^ this decl
+           -> [(HsDecl DocNameI, DocForDecl DocName)] -- ^ relevant patterns
+           -> Splice -> Unicode -> Maybe Package -> Qualification -> Html
+ppDataDecl summary links instances fixities subdocs loc doc dataDecl pats
+           splice unicode pkg qual
+
+  | summary   = ppShortDataDecl summary False dataDecl pats unicode qual
+  | otherwise = header_ +++ docSection curname pkg qual doc +++ constrBit +++ patternBit +++ instancesBit
+
+  where
+    docname   = tcdNameI dataDecl
+    curname   = Just $ getName docname
+    cons      = dd_cons (tcdDataDefn dataDecl)
+    isH98     = flip any (unLoc <$> cons) $ \ case
+                  ConDeclH98 {} -> True
+                  ConDeclGADT{} -> False
+
+    header_ = topDeclElem links loc splice [docname] $
+             ppDataHeader summary dataDecl unicode qual <+> whereBit <+> fix
+
+    fix = ppFixities (filter (\(n,_) -> n == docname) fixities) qual
+
+    whereBit
+      | null cons
+      , null pats = noHtml
+      | isH98 = noHtml
+      | otherwise = keyword "where"
+
+    constrBit = subConstructors pkg qual
+      [ ppSideBySideConstr subdocs subfixs unicode pkg qual c
+      | c <- toList cons
+      , let subfixs = filter (\(n,_) -> any (\cn -> cn == n)
+                                            (unL <$> getConNamesI (unLoc c))) fixities
+      ]
+
+    patternBit = subPatterns pkg qual
+      [ ppSideBySidePat subfixs unicode qual lnames typ d
+      | (SigD _ (PatSynSig _ lnames typ), d) <- pats
+      , let subfixs = filter (\(n,_) -> any (\cn -> cn == n)
+                                            (map unLoc lnames)) fixities
+      ]
+
+    instancesBit = ppInstances links (OriginData docname) instances
+        splice unicode pkg qual
+
+
+ppShortConstr :: Bool -> ConDecl DocNameI -> Unicode -> Qualification -> Html
+ppShortConstr summary con unicode qual = cHead <+> cBody <+> cFoot
+  where
+    (cHead,cBody,cFoot) = ppShortConstrParts summary False con unicode qual
+
+
+-- returns three pieces: header, body, footer so that header & footer can be
+-- incorporated into the declaration
+ppShortConstrParts :: Bool -> Bool -> ConDecl DocNameI -> Unicode -> Qualification -> (Html, Html, Html)
+ppShortConstrParts summary dataInst con unicode qual
+  = case con of
+      ConDeclH98{ con_args = det
+                , con_ex_tvs = tyVars
+                , con_forall = forall_
+                , con_mb_cxt = cxt
+                } -> let context = fromMaybeContext cxt
+                         header_ = ppConstrHdr forall_ tyVars context unicode qual
+                     in case det of
+
+        -- Prefix constructor, e.g. 'Just a'
+        PrefixCon _ args ->
+          ( header_ <+> hsep (ppOcc : map (ppLParendType unicode qual HideEmptyContexts . hsScaledThing) args)
+          , noHtml
+          , noHtml
+          )
+
+        -- Record constructor, e.g. 'Identity { runIdentity :: a }'
+        RecCon (L _ fields) ->
+          ( header_ +++ ppOcc <+> char '{'
+          , shortSubDecls dataInst [ ppShortField summary unicode qual field
+                                   | L _ field <- fields
+                                   ]
+          , char '}'
+          )
+
+        -- Infix constructor, e.g. 'a :| [a]'
+        InfixCon arg1 arg2 ->
+          ( header_ <+> hsep [ ppLParendType unicode qual HideEmptyContexts (hsScaledThing arg1)
+                             , ppOccInfix
+                             , ppLParendType unicode qual HideEmptyContexts (hsScaledThing arg2)
+                             ]
+          , noHtml
+          , noHtml
+          )
+
+      -- GADT constructor, e.g. 'Foo :: Int -> Foo'
+      ConDeclGADT {} ->
+          ( hsep [ ppOcc, dcolon unicode, ppLSigType unicode qual HideEmptyContexts (getGADTConType con) ]
+          , noHtml
+          , noHtml
+          )
+
+  where
+    occ        = toList $ nameOccName . getName . unL <$> getConNamesI con
+    ppOcc      = hsep (punctuate comma (map (ppBinder summary) occ))
+    ppOccInfix = hsep (punctuate comma (map (ppBinderInfix summary) occ))
+
+
+-- | Pretty print an expanded constructor
+ppSideBySideConstr :: [(DocName, DocForDecl DocName)] -> [(DocName, Fixity)]
+                   -> Unicode -> Maybe Package -> Qualification
+                   -> LConDecl DocNameI -- ^ constructor declaration to print
+                   -> SubDecl
+ppSideBySideConstr subdocs fixities unicode pkg qual (L _ con)
+ = ( decl       -- Constructor header (name, fixity)
+   , mbDoc      -- Docs on the whole constructor
+   , fieldPart  -- Information on the fields (or arguments, if they have docs)
+   )
+ where
+    -- Find the name of a constructors in the decl (`getConName` always returns a non-empty list)
+    L _ aConName :| _ = getConNamesI con
+
+    fixity   = ppFixities fixities qual
+    occ      = toList $ nameOccName . getName . unL <$> getConNamesI con
+
+    ppOcc      = hsep (punctuate comma (map (ppBinder False) occ))
+    ppOccInfix = hsep (punctuate comma (map (ppBinderInfix False) occ))
+
+    -- Extract out the map of of docs corresponding to the constructors arguments
+    argDocs = maybe Map.empty snd (lookup aConName subdocs)
+    hasArgDocs = not $ Map.null argDocs
+
+    decl = case con of
+      ConDeclH98{ con_args = det
+                , con_ex_tvs = tyVars
+                , con_forall = forall_
+                , con_mb_cxt = cxt
+                } -> let context = fromMaybeContext cxt
+                         header_ = ppConstrHdr forall_ tyVars context unicode qual
+                     in case det of
+        -- Prefix constructor, e.g. 'Just a'
+        PrefixCon _ args
+          | hasArgDocs -> header_ <+> ppOcc <+> fixity
+          | otherwise -> hsep [ header_ <+> ppOcc
+                              , hsep (map (ppLParendType unicode qual HideEmptyContexts . hsScaledThing) args)
+                              , fixity
+                              ]
+
+        -- Record constructor, e.g. 'Identity { runIdentity :: a }'
+        RecCon _ -> header_ <+> ppOcc <+> fixity
+
+        -- Infix constructor, e.g. 'a :| [a]'
+        InfixCon arg1 arg2
+          | hasArgDocs -> header_ <+> ppOcc <+> fixity
+          | otherwise -> hsep [ header_ <+> ppLParendType unicode qual HideEmptyContexts (hsScaledThing arg1)
+                              , ppOccInfix
+                              , ppLParendType unicode qual HideEmptyContexts (hsScaledThing arg2)
+                              , fixity
+                              ]
+
+      -- GADT constructor, e.g. 'Foo :: Int -> Foo'
+      ConDeclGADT{}
+          | hasArgDocs || not (null fieldPart) -> ppOcc <+> fixity
+          | otherwise -> hsep [ ppOcc
+                              , dcolon unicode
+                              -- ++AZ++ make this prepend "{..}" when it is a record style GADT
+                              , ppLSigType unicode qual HideEmptyContexts (getGADTConType con)
+                              , fixity
+                              ]
+
+    fieldPart = case con of
+        ConDeclGADT{con_g_args = con_args'} -> case con_args' of
+          -- GADT record declarations
+          RecConGADT _ _                  -> [ doConstrArgsWithDocs [] ]
+          -- GADT prefix data constructors
+          PrefixConGADT args | hasArgDocs -> [ doConstrArgsWithDocs args ]
+          _                               -> []
+
+        ConDeclH98{con_args = con_args'} -> case con_args' of
+          -- H98 record declarations
+          RecCon (L _ fields)             -> [ doRecordFields fields ]
+          -- H98 prefix data constructors
+          PrefixCon _ args | hasArgDocs   -> [ doConstrArgsWithDocs args ]
+          -- H98 infix data constructor
+          InfixCon arg1 arg2 | hasArgDocs -> [ doConstrArgsWithDocs [arg1,arg2] ]
+          _                               -> []
+
+    doRecordFields fields = subFields pkg qual
+      (map (ppSideBySideField subdocs unicode qual) (map unLoc fields))
+
+    doConstrArgsWithDocs args = subFields pkg qual $ case con of
+      ConDeclH98{} ->
+        [ (ppLParendType unicode qual HideEmptyContexts arg, mdoc, [])
+        | (i, arg) <- zip [0..] (map hsScaledThing args)
+        , let mdoc = Map.lookup i argDocs
+        ]
+      ConDeclGADT{} ->
+        ppSubSigLike unicode qual (unLoc (getGADTConType con))
+                     argDocs subdocs (dcolon unicode) HideEmptyContexts
+
+    -- don't use "con_doc con", in case it's reconstructed from a .hi file,
+    -- or also because we want Haddock to do the doc-parsing, not GHC.
+    mbDoc = lookup aConName subdocs >>=
+            combineDocumentation . fst
+
+
+-- ppConstrHdr is for (non-GADT) existentials constructors' syntax
+ppConstrHdr
+  :: Bool                    -- ^ print explicit foralls
+  -> [LHsTyVarBndr Specificity DocNameI] -- ^ type variables
+  -> HsContext DocNameI      -- ^ context
+  -> Unicode -> Qualification
+  -> Html
+ppConstrHdr forall_ tvs ctxt unicode qual = ppForall +++ ppCtxt
+  where
+    ppForall
+      | null tvs || not forall_ = noHtml
+      | otherwise = ppForAllPart unicode qual (HsForAllInvis noExtField tvs)
+
+    ppCtxt
+      | null ctxt = noHtml
+      | otherwise = ppContextNoArrow ctxt unicode qual HideEmptyContexts
+                      <+> darrow unicode +++ toHtml " "
+
+
+-- | Pretty-print a record field
+ppSideBySideField :: [(DocName, DocForDecl DocName)] -> Unicode -> Qualification
+                  -> ConDeclField DocNameI -> SubDecl
+ppSideBySideField subdocs unicode qual (ConDeclField _ names ltype _) =
+  ( hsep (punctuate comma [ ppBinder False (rdrNameOcc field)
+                          | L _ name <- names
+                          , let field = (unLoc . foLabel) name
+                          ])
+      <+> dcolon unicode
+      <+> ppLType unicode qual HideEmptyContexts ltype
+  , mbDoc
+  , []
+  )
+  where
+    -- don't use cd_fld_doc for same reason we don't use con_doc above
+    -- Where there is more than one name, they all have the same documentation
+    mbDoc = lookup (foExt $ unLoc $ head names) subdocs >>= combineDocumentation . fst
+
+
+ppShortField :: Bool -> Unicode -> Qualification -> ConDeclField DocNameI -> Html
+ppShortField summary unicode qual (ConDeclField _ names ltype _)
+  = hsep (punctuate comma (map ((ppBinder summary) . rdrNameOcc . unLoc . foLabel . unLoc) names))
+    <+> dcolon unicode <+> ppLType unicode qual HideEmptyContexts ltype
+
+
+-- | Pretty print an expanded pattern (for bundled patterns)
+ppSideBySidePat :: [(DocName, Fixity)] -> Unicode -> Qualification
+                   -> [LocatedN DocName]   -- ^ pattern name(s)
+                   -> LHsSigType DocNameI  -- ^ type of pattern(s)
+                   -> DocForDecl DocName   -- ^ doc map
+                   -> SubDecl
+ppSideBySidePat fixities unicode qual lnames typ (doc, argDocs) =
+  ( decl
+  , combineDocumentation doc
+  , fieldPart
+  )
+  where
+    hasArgDocs = not $ Map.null argDocs
+    fixity = ppFixities fixities qual
+    ppOcc = hsep (punctuate comma (map (ppBinder False . getOccName) lnames))
+
+    decl | hasArgDocs = keyword "pattern" <+> ppOcc <+> fixity
+         | otherwise = hsep [ keyword "pattern"
+                            , ppOcc
+                            , dcolon unicode
+                            , ppPatSigType unicode qual typ
+                            , fixity
+                            ]
+
+    fieldPart
+      | not hasArgDocs = []
+      | otherwise = [ subFields Nothing qual (ppSubSigLike unicode qual (unLoc typ)
+                                                        argDocs [] (dcolon unicode)
+                                                        emptyCtxt) ]
+
+    emptyCtxt = patSigContext typ
+
+
+-- | Print the LHS of a data\/newtype declaration.
+-- Currently doesn't handle 'data instance' decls or kind signatures
+ppDataHeader :: Bool -> TyClDecl DocNameI -> Unicode -> Qualification -> Html
+ppDataHeader summary (DataDecl { tcdDataDefn =
+                                    HsDataDefn { dd_cons = cons
+                                               , dd_ctxt = ctxt
+                                               , dd_kindSig = ks }
+                               , tcdLName = L _ name
+                               , tcdTyVars = tvs })
+             unicode qual
+  = -- newtype or data
+    (case cons of
+       { NewTypeCon _ -> keyword "newtype"
+       ; DataTypeCons False _ -> keyword "data"
+       ; DataTypeCons True _ -> keyword "type" <+> keyword "data"
+       })
+    <+>
+    -- context
+    ppLContext ctxt unicode qual HideEmptyContexts <+>
+    -- T a b c ..., or a :+: b
+    ppAppDocNameTyVarBndrs summary unicode qual name (hsQTvExplicit tvs)
+    <+> case ks of
+      Nothing -> mempty
+      Just (L _ x) -> dcolon unicode <+> ppKind unicode qual x
+
+ppDataHeader _ _ _ _ = error "ppDataHeader: illegal argument"
+
+--------------------------------------------------------------------------------
+-- * Types and contexts
+--------------------------------------------------------------------------------
+
+
+ppBang :: HsSrcBang -> Html
+ppBang (HsSrcBang _ _ SrcStrict) = toHtml "!"
+ppBang (HsSrcBang _ _ SrcLazy)   = toHtml "~"
+ppBang _                         = noHtml
+
+
+tupleParens :: HsTupleSort -> [Html] -> Html
+tupleParens HsUnboxedTuple = ubxParenList
+tupleParens _              = parenList
+
+
+sumParens :: [Html] -> Html
+sumParens = ubxSumList
+
+--------------------------------------------------------------------------------
+-- * Rendering of HsType
+--------------------------------------------------------------------------------
+
+ppLType, ppLParendType, ppLFunLhType :: Unicode -> Qualification -> HideEmptyContexts -> LHsType DocNameI -> Html
+ppLType       unicode qual emptyCtxts y = ppType unicode qual emptyCtxts (unLoc y)
+ppLParendType unicode qual emptyCtxts y = ppParendType unicode qual emptyCtxts (unLoc y)
+ppLFunLhType  unicode qual emptyCtxts y = ppFunLhType unicode qual emptyCtxts (unLoc y)
+
+ppLSigType ::  Unicode -> Qualification -> HideEmptyContexts -> LHsSigType DocNameI -> Html
+ppLSigType unicode qual emptyCtxts y = ppSigType unicode qual emptyCtxts (unLoc y)
+
+ppCtxType :: Unicode -> Qualification -> HsType DocNameI -> Html
+ppCtxType unicode qual ty = ppr_mono_ty (reparenTypePrec PREC_CTX ty) unicode qual HideEmptyContexts
+
+ppType, ppParendType, ppFunLhType :: Unicode -> Qualification -> HideEmptyContexts -> HsType DocNameI -> Html
+ppType       unicode qual emptyCtxts ty = ppr_mono_ty (reparenTypePrec PREC_TOP ty) unicode qual emptyCtxts
+ppParendType unicode qual emptyCtxts ty = ppr_mono_ty (reparenTypePrec PREC_CON ty) unicode qual emptyCtxts
+ppFunLhType  unicode qual emptyCtxts ty = ppr_mono_ty (reparenTypePrec PREC_FUN ty) unicode qual emptyCtxts
+
+ppSigType ::  Unicode -> Qualification -> HideEmptyContexts -> HsSigType DocNameI -> Html
+ppSigType unicode qual emptyCtxts sig_ty = ppr_sig_ty (reparenSigType sig_ty) unicode qual emptyCtxts
+
+ppLHsTypeArg :: Unicode -> Qualification -> HideEmptyContexts -> LHsTypeArg DocNameI -> Html
+ppLHsTypeArg unicode qual emptyCtxts (HsValArg ty) = ppLParendType unicode qual emptyCtxts ty
+ppLHsTypeArg unicode qual emptyCtxts (HsTypeArg _ ki) = atSign unicode <>
+                                                       ppLParendType unicode qual emptyCtxts ki
+ppLHsTypeArg _ _ _ (HsArgPar _) = toHtml ""
+
+class RenderableBndrFlag flag where
+  ppHsTyVarBndr :: Unicode -> Qualification -> HsTyVarBndr flag DocNameI -> Html
+
+instance RenderableBndrFlag () where
+  ppHsTyVarBndr _       qual (UserTyVar _ _ (L _ name)) =
+      ppDocName qual Raw False name
+  ppHsTyVarBndr unicode qual (KindedTyVar _ _ name kind) =
+      parens (ppDocName qual Raw False (unL name) <+> dcolon unicode <+>
+              ppLKind unicode qual kind)
+
+instance RenderableBndrFlag Specificity where
+  ppHsTyVarBndr _       qual (UserTyVar _ SpecifiedSpec (L _ name)) =
+      ppDocName qual Raw False name
+  ppHsTyVarBndr _       qual (UserTyVar _ InferredSpec (L _ name)) =
+      braces $ ppDocName qual Raw False name
+  ppHsTyVarBndr unicode qual (KindedTyVar _ SpecifiedSpec name kind) =
+      parens (ppDocName qual Raw False (unL name) <+> dcolon unicode <+>
+              ppLKind unicode qual kind)
+  ppHsTyVarBndr unicode qual (KindedTyVar _ InferredSpec name kind) =
+      braces (ppDocName qual Raw False (unL name) <+> dcolon unicode <+>
+              ppLKind unicode qual kind)
+
+ppLKind :: Unicode -> Qualification -> LHsKind DocNameI -> Html
+ppLKind unicode qual y = ppKind unicode qual (unLoc y)
+
+ppKind :: Unicode -> Qualification -> HsKind DocNameI -> Html
+ppKind unicode qual ki = ppr_mono_ty (reparenTypePrec PREC_TOP ki) unicode qual HideEmptyContexts
+
+patSigContext :: LHsSigType DocNameI -> HideEmptyContexts
+patSigContext sig_typ | hasNonEmptyContext typ && isFirstContextEmpty typ =  ShowEmptyToplevelContexts
+                      | otherwise = HideEmptyContexts
+  where
+    typ = sig_body (unLoc sig_typ)
+
+    hasNonEmptyContext t =
+      case unLoc t of
+        HsForAllTy _ _ s -> hasNonEmptyContext s
+        HsQualTy _ cxt s -> if null (unLoc cxt) then hasNonEmptyContext s else True
+        HsFunTy _ _ _ s    -> hasNonEmptyContext s
+        _ -> False
+    isFirstContextEmpty t =
+      case unLoc t of
+        HsForAllTy _ _ s -> isFirstContextEmpty s
+        HsQualTy _ cxt _ -> null (unLoc cxt)
+        HsFunTy _ _ _ s    -> isFirstContextEmpty s
+        _ -> False
+
+
+-- | Pretty-print a pattern signature (all this does over 'ppLType' is slot in
+-- the right 'HideEmptyContext' value)
+ppPatSigType :: Unicode -> Qualification -> LHsSigType DocNameI -> Html
+ppPatSigType unicode qual typ =
+  let emptyCtxts = patSigContext typ in ppLSigType unicode qual emptyCtxts typ
+
+ppHsOuterTyVarBndrs :: RenderableBndrFlag flag
+                    => Unicode -> Qualification -> HsOuterTyVarBndrs flag DocNameI -> Html
+ppHsOuterTyVarBndrs unicode qual outer_bndrs = case outer_bndrs of
+  HsOuterImplicit{} -> noHtml
+  HsOuterExplicit{hso_bndrs = bndrs} ->
+    hsep (forallSymbol unicode : ppTyVars unicode qual bndrs) +++ dot
+
+ppForAllPart :: Unicode -> Qualification -> HsForAllTelescope DocNameI -> Html
+ppForAllPart unicode qual tele = case tele of
+  HsForAllVis { hsf_vis_bndrs = bndrs } ->
+    hsep (forallSymbol unicode : ppTyVars unicode qual bndrs) +++
+    spaceHtml +++  arrow unicode
+  HsForAllInvis { hsf_invis_bndrs = bndrs } ->
+    hsep (forallSymbol unicode : ppTyVars unicode qual bndrs) +++ dot
+
+ppr_sig_ty :: HsSigType DocNameI -> Unicode -> Qualification -> HideEmptyContexts -> Html
+ppr_sig_ty (HsSig { sig_bndrs = outer_bndrs, sig_body = ltype }) unicode qual emptyCtxts
+  = ppHsOuterTyVarBndrs unicode qual outer_bndrs <+> ppr_mono_lty ltype unicode qual emptyCtxts
+
+ppr_mono_lty :: LHsType DocNameI -> Unicode -> Qualification -> HideEmptyContexts -> Html
+ppr_mono_lty ty = ppr_mono_ty (unLoc ty)
+
+
+ppr_mono_ty :: HsType DocNameI -> Unicode -> Qualification -> HideEmptyContexts -> Html
+ppr_mono_ty (HsForAllTy _ tele ty) unicode qual emptyCtxts
+  = ppForAllPart unicode qual tele <+> ppr_mono_lty ty unicode qual emptyCtxts
+
+ppr_mono_ty (HsQualTy _ ctxt ty) unicode qual emptyCtxts
+  = ppLContext (Just ctxt) unicode qual emptyCtxts <+> ppr_mono_lty ty unicode qual emptyCtxts
+
+-- UnicodeSyntax alternatives
+ppr_mono_ty (HsTyVar _ _ (L _ name)) True _ _
+  | getOccString (getName name) == "(->)" = toHtml "(→)"
+
+ppr_mono_ty (HsBangTy _ b ty) u q _ =
+  ppBang b +++ ppLParendType u q HideEmptyContexts ty
+ppr_mono_ty (HsTyVar _ prom (L _ name)) _ q _
+  | isPromoted prom = promoQuote (ppDocName q Prefix True name)
+  | otherwise = ppDocName q Prefix True name
+ppr_mono_ty (HsStarTy _ isUni) u _ _ =
+  toHtml (if u || isUni then "★" else "*")
+ppr_mono_ty (HsFunTy _ mult ty1 ty2) u q e =
+  hsep [ ppr_mono_lty ty1 u q HideEmptyContexts
+       , arr <+> ppr_mono_lty ty2 u q e
+       ]
+   where arr = case mult of
+                 HsLinearArrow _ -> lollipop u
+                 HsUnrestrictedArrow _ -> arrow u
+                 HsExplicitMult _ m _ -> multAnnotation <> ppr_mono_lty m u q e <+> arrow u
+
+ppr_mono_ty (HsTupleTy _ con tys) u q _ =
+  tupleParens con (map (ppLType u q HideEmptyContexts) tys)
+ppr_mono_ty (HsSumTy _ tys) u q _ =
+  sumParens (map (ppLType u q HideEmptyContexts) tys)
+ppr_mono_ty (HsKindSig _ ty kind) u q e =
+  ppr_mono_lty ty u q e <+> dcolon u <+> ppLKind u q kind
+ppr_mono_ty (HsListTy _ ty)       u q _ = brackets (ppr_mono_lty ty u q HideEmptyContexts)
+ppr_mono_ty (HsIParamTy _ (L _ n) ty) u q _ =
+  ppIPName n <+> dcolon u <+> ppr_mono_lty ty u q HideEmptyContexts
+ppr_mono_ty (HsSpliceTy v _) _ _ _ = dataConCantHappen v
+ppr_mono_ty (HsRecTy {})        _ _ _ = toHtml "{..}"
+       -- Can now legally occur in ConDeclGADT, the output here is to provide a
+       -- placeholder in the signature, which is followed by the field
+       -- declarations.
+ppr_mono_ty (XHsType {})        _ _ _ = error "ppr_mono_ty HsCoreTy"
+ppr_mono_ty (HsExplicitListTy _ IsPromoted tys) u q _ = promoQuote $ brackets $ hsep $ punctuate comma $ map (ppLType u q HideEmptyContexts) tys
+ppr_mono_ty (HsExplicitListTy _ NotPromoted tys) u q _ = brackets $ hsep $ punctuate comma $ map (ppLType u q HideEmptyContexts) tys
+ppr_mono_ty (HsExplicitTupleTy _ tys) u q _ = promoQuote $ parenList $ map (ppLType u q HideEmptyContexts) tys
+
+ppr_mono_ty (HsAppTy _ fun_ty arg_ty) unicode qual _
+  = hsep [ ppr_mono_lty fun_ty unicode qual HideEmptyContexts
+         , ppr_mono_lty arg_ty unicode qual HideEmptyContexts ]
+
+ppr_mono_ty (HsAppKindTy _ fun_ty arg_ki) unicode qual _
+  = hsep [ppr_mono_lty fun_ty unicode qual HideEmptyContexts
+         , atSign unicode <> ppr_mono_lty arg_ki unicode qual HideEmptyContexts]
+
+ppr_mono_ty (HsOpTy _ prom ty1 op ty2) unicode qual _
+  = ppr_mono_lty ty1 unicode qual HideEmptyContexts <+> ppr_op_prom <+> ppr_mono_lty ty2 unicode qual HideEmptyContexts
+  where
+    ppr_op_prom
+        | isPromoted prom
+        = promoQuote ppr_op
+        | otherwise
+        = ppr_op
+    ppr_op = ppLDocName qual Infix op
+
+ppr_mono_ty (HsParTy _ ty) unicode qual emptyCtxts
+  = parens (ppr_mono_lty ty unicode qual emptyCtxts)
+--  = parens (ppr_mono_lty ctxt_prec ty unicode qual emptyCtxts)
+
+ppr_mono_ty (HsDocTy _ ty _) unicode qual emptyCtxts
+  = ppr_mono_lty ty unicode qual emptyCtxts
+
+ppr_mono_ty (HsWildCardTy _) _ _ _ = char '_'
+ppr_mono_ty (HsTyLit _ n) _ _ _ = ppr_tylit n
+
+ppr_tylit :: HsTyLit DocNameI -> Html
+ppr_tylit (HsNumTy _ n) = toHtml (show n)
+ppr_tylit (HsStrTy _ s) = toHtml (show s)
+ppr_tylit (HsCharTy _ c) = toHtml (show c)
diff --git a/haddock-api/src/Haddock/Backends/Xhtml/DocMarkup.hs b/haddock-api/src/Haddock/Backends/Xhtml/DocMarkup.hs
new file mode 100644
--- /dev/null
+++ b/haddock-api/src/Haddock/Backends/Xhtml/DocMarkup.hs
@@ -0,0 +1,284 @@
+-----------------------------------------------------------------------------
+-- |
+-- Module      :  Haddock.Backends.Html.DocMarkup
+-- Copyright   :  (c) Simon Marlow   2003-2006,
+--                    David Waern    2006-2009,
+--                    Mark Lentczner 2010
+-- License     :  BSD-like
+--
+-- Maintainer  :  haddock@projects.haskell.org
+-- Stability   :  experimental
+-- Portability :  portable
+-----------------------------------------------------------------------------
+module Haddock.Backends.Xhtml.DocMarkup (
+  docToHtml,
+  rdrDocToHtml,
+  origDocToHtml,
+  docToHtmlNoAnchors,
+
+  docElement, docSection, docSection_,
+) where
+
+import Data.List (intersperse)
+import Documentation.Haddock.Markup
+import Haddock.Backends.Xhtml.Names
+import Haddock.Backends.Xhtml.Utils
+import Haddock.Types
+import Haddock.Utils
+import Haddock.Doc (combineDocumentation, emptyMetaDoc,
+                    metaDocAppend, metaConcat)
+
+import Text.XHtml hiding ( name, p, quote )
+import Data.Maybe (fromMaybe)
+
+import GHC hiding (anchor)
+import GHC.Types.Name
+
+
+parHtmlMarkup :: Qualification -> Bool
+              -> (Bool -> a -> Html) -> DocMarkup a Html
+parHtmlMarkup qual insertAnchors ppId = Markup {
+  markupEmpty                = noHtml,
+  markupString               = toHtml,
+  markupParagraph            = paragraph,
+  markupAppend               = (+++),
+  markupIdentifier           = thecode . ppId insertAnchors,
+  markupIdentifierUnchecked  = thecode . ppUncheckedLink qual,
+  markupModule               = \(ModLink m lbl) ->
+                                 let (mdl,ref) = break (=='#') m
+                                       -- Accommodate for old style
+                                       -- foo\#bar anchors
+                                     mdl' = case reverse mdl of
+                                              '\\':_ -> init mdl
+                                              _ -> mdl
+                                 in ppModuleRef lbl (mkModuleName mdl') ref,
+  markupWarning              = thediv ! [theclass "warning"],
+  markupEmphasis             = emphasize,
+  markupBold                 = strong,
+  markupMonospaced           = thecode,
+  markupUnorderedList        = unordList,
+  markupOrderedList          = makeOrdList,
+  markupDefList              = defList,
+  markupCodeBlock            = pre,
+  markupHyperlink            = \(Hyperlink url mLabel)
+                               -> if insertAnchors
+                                  then anchor ! [href url]
+                                       << fromMaybe (toHtml url) mLabel
+                                  else fromMaybe (toHtml url) mLabel,
+  markupAName                = \aname
+                               -> if insertAnchors
+                                  then namedAnchor aname << ""
+                                  else noHtml,
+  markupPic                  = \(Picture uri t) -> image ! ([src uri] ++ fromMaybe [] (return . title <$> t)),
+  markupMathInline           = \mathjax -> thespan ! [theclass "mathjax"] << toHtml ("\\(" ++ mathjax ++ "\\)"),
+  markupMathDisplay          = \mathjax -> thespan ! [theclass "mathjax"] << toHtml ("\\[" ++ mathjax ++ "\\]"),
+  markupProperty             = pre . toHtml,
+  markupExample              = examplesToHtml,
+  markupHeader               = \(Header l t) -> makeHeader l t,
+  markupTable                = \(Table h r) -> makeTable h r
+  }
+  where
+    makeHeader :: Int -> Html -> Html
+    makeHeader 1 mkup = h1 mkup
+    makeHeader 2 mkup = h2 mkup
+    makeHeader 3 mkup = h3 mkup
+    makeHeader 4 mkup = h4 mkup
+    makeHeader 5 mkup = h5 mkup
+    makeHeader 6 mkup = h6 mkup
+    makeHeader l _ = error $ "Somehow got a header level `" ++ show l ++ "' in DocMarkup!"
+
+    makeTable :: [TableRow Html] -> [TableRow Html] -> Html
+    makeTable hs bs = table (concatHtml (hs' ++ bs'))
+      where
+        hs' | null hs   = []
+            | otherwise = [thead (concatHtml (map (makeTableRow th) hs))]
+
+        bs' = [tbody (concatHtml (map (makeTableRow td) bs))]
+
+    makeTableRow :: (Html -> Html) -> TableRow Html -> Html
+    makeTableRow thr (TableRow cs) = tr (concatHtml (map (makeTableCell thr) cs))
+
+    makeTableCell :: (Html -> Html) -> TableCell Html -> Html
+    makeTableCell thr (TableCell i j c) = thr c ! (i' ++ j')
+      where
+        i' = if i == 1 then [] else [ colspan i ]
+        j' = if j == 1 then [] else [ rowspan j ]
+
+    examplesToHtml l = pre (concatHtml $ map exampleToHtml l) ! [theclass "screen"]
+
+    exampleToHtml (Example expression result) = htmlExample
+      where
+        htmlExample = htmlPrompt +++ htmlExpression +++ toHtml (unlines result)
+        htmlPrompt = (thecode . toHtml $ ">>> ") ! [theclass "prompt"]
+        htmlExpression = (strong . thecode . toHtml $ expression ++ "\n") ! [theclass "userinput"]
+
+    makeOrdList :: HTML a => [(Int, a)] -> Html
+    makeOrdList items = olist << map (\(index, a) -> li ! [intAttr "value" index] << a) items
+
+-- | We use this intermediate type to transform the input 'Doc' tree
+-- in an arbitrary way before rendering, such as grouping some
+-- elements. This is effectively a hack to prevent the 'Doc' type
+-- from changing if it is possible to recover the layout information
+-- we won't need after the fact.
+data Hack a id =
+  UntouchedDoc (MetaDoc a id)
+  | CollapsingHeader (Header (DocH a id)) (MetaDoc a id) Int (Maybe String)
+  | HackAppend (Hack a id) (Hack a id)
+  deriving Eq
+
+-- | Group things under bold 'DocHeader's together.
+toHack :: Int -- ^ Counter for header IDs which serves to assign
+              -- unique identifiers within the comment scope
+       -> Maybe String
+       -- ^ It is not enough to have unique identifier within the
+       -- scope of the comment: if two different comments have the
+       -- same ID for headers, the collapse/expand behaviour will act
+       -- on them both. This serves to make each header a little bit
+       -- more unique. As we can't export things with the same names,
+       -- this should work more or less fine: it is in fact the
+       -- implicit assumption the collapse/expand mechanism makes for
+       -- things like ‘Instances’ boxes.
+       -> [MetaDoc a id] -> Hack a id
+toHack _ _ [] = UntouchedDoc emptyMetaDoc
+toHack _ _ [x] = UntouchedDoc x
+toHack n nm (MetaDoc { _doc = DocHeader (Header l (DocBold x)) }:xs) =
+  let -- Header with dropped bold
+      h = Header l x
+      -- Predicate for takeWhile, grab everything including ‘smaller’
+      -- headers
+      p (MetaDoc { _doc = DocHeader (Header l' _) }) = l' > l
+      p _ = True
+      -- Stuff ‘under’ this header
+      r = takeWhile p xs
+      -- Everything else that didn't make it under
+      r' = drop (length r) xs
+      app y [] = y
+      app y ys = HackAppend y (toHack (n + 1) nm ys)
+  in case r of
+      -- No content under this header
+      [] -> CollapsingHeader h emptyMetaDoc n nm `app` r'
+      -- We got something out, stitch it back together into one chunk
+      y:ys -> CollapsingHeader h (foldl metaDocAppend y ys) n nm `app` r'
+toHack n nm (x:xs) = HackAppend (UntouchedDoc x) (toHack n nm xs)
+
+-- | Remove ‘top-level’ 'DocAppend's turning them into a flat list.
+-- This lends itself much better to processing things in order user
+-- might look at them, such as in 'toHack'.
+flatten :: MetaDoc a id -> [MetaDoc a id]
+flatten MetaDoc { _meta = m, _doc = DocAppend x y } =
+  let f z = MetaDoc { _meta = m, _doc = z }
+  in flatten (f x) ++ flatten (f y)
+flatten x = [x]
+
+-- | Generate the markup needed for collapse to happen. For
+-- 'UntouchedDoc' and 'HackAppend' we do nothing more but
+-- extract/append the underlying 'Doc' and convert it to 'Html'. For
+-- 'CollapsingHeader', we attach extra info to the generated 'Html'
+-- that allows us to expand/collapse the content.
+hackMarkup :: DocMarkup id Html -> Maybe Package -> Hack (Wrap (ModuleName, OccName)) id -> Html
+hackMarkup fmt' currPkg h' =
+  let (html, ms) = hackMarkup' fmt' h'
+  in html +++ renderMeta fmt' currPkg (metaConcat ms)
+  where
+    hackMarkup' :: DocMarkup id Html -> Hack (Wrap (ModuleName, OccName)) id
+                -> (Html, [Meta])
+    hackMarkup' fmt h = case h of
+      UntouchedDoc d -> (markup fmt $ _doc d, [_meta d])
+      CollapsingHeader (Header lvl titl) par n nm ->
+        let id_ = makeAnchorId $ "ch:" ++ fromMaybe "noid:" nm ++ show n
+            col' = collapseControl id_ "subheading"
+            summary = thesummary ! [ theclass "hide-when-js-enabled" ] << "Expand"
+            instTable contents = collapseDetails id_ DetailsClosed (summary +++ contents)
+            lvs = zip [1 .. ] [h1, h2, h3, h4, h5, h6]
+            getHeader = fromMaybe caption (lookup lvl lvs)
+            subCaption = getHeader ! col' << markup fmt titl
+        in ((subCaption +++) . instTable $ markup fmt (_doc par), [_meta par])
+      HackAppend d d' -> let (x, m) = hackMarkup' fmt d
+                             (y, m') = hackMarkup' fmt d'
+                         in (markupAppend fmt x y, m ++ m')
+
+renderMeta :: DocMarkup id Html -> Maybe Package -> Meta -> Html
+renderMeta fmt currPkg (Meta { _version = Just x, _package = pkg }) =
+  markupParagraph fmt . markupEmphasis fmt . toHtml $
+    "Since: " ++ formatPkgMaybe pkg ++ formatVersion x
+  where
+    formatVersion v = concat . intersperse "." $ map show v
+    formatPkgMaybe (Just p) | Just p /= currPkg = p ++ "-"
+    formatPkgMaybe _ = ""
+renderMeta _ _ _ = noHtml
+
+-- | Goes through 'hackMarkup' to generate the 'Html' rather than
+-- skipping straight to 'markup': this allows us to employ XHtml
+-- specific hacks to the tree first.
+markupHacked :: DocMarkup (Wrap id) Html
+             -> Maybe Package      -- this package
+             -> Maybe String
+             -> MDoc id
+             -> Html
+markupHacked fmt currPkg n = hackMarkup fmt currPkg . toHack 0 n . flatten
+
+-- If the doc is a single paragraph, don't surround it with <P> (this causes
+-- ugly extra whitespace with some browsers).  FIXME: Does this still apply?
+docToHtml :: Maybe String  -- ^ Name of the thing this doc is for. See
+                           -- comments on 'toHack' for details.
+          -> Maybe Package -- ^ Current package
+          -> Qualification -> MDoc DocName -> Html
+docToHtml n pkg qual = markupHacked fmt pkg n . cleanup
+  where fmt = parHtmlMarkup qual True (ppWrappedDocName qual Raw)
+
+-- | Same as 'docToHtml' but it doesn't insert the 'anchor' element
+-- in links. This is used to generate the Contents box elements.
+docToHtmlNoAnchors :: Maybe String  -- ^ See 'toHack'
+                   -> Maybe Package -- ^ Current package
+                   -> Qualification -> MDoc DocName -> Html
+docToHtmlNoAnchors n pkg qual = markupHacked fmt pkg n . cleanup
+  where fmt = parHtmlMarkup qual False (ppWrappedDocName qual Raw)
+
+origDocToHtml :: Maybe Package -> Qualification -> MDoc Name -> Html
+origDocToHtml pkg qual = markupHacked fmt pkg Nothing . cleanup
+  where fmt = parHtmlMarkup qual True (const (ppWrappedName Raw))
+
+
+rdrDocToHtml :: Maybe Package -> Qualification -> MDoc RdrName -> Html
+rdrDocToHtml pkg qual = markupHacked fmt pkg Nothing . cleanup
+  where fmt = parHtmlMarkup qual True (const (ppRdrName . unwrap))
+
+
+docElement :: (Html -> Html) -> Html -> Html
+docElement el content_ =
+  if isNoHtml content_
+    then el ! [theclass "doc empty"] << spaceHtml
+    else el ! [theclass "doc"] << content_
+
+
+docSection :: Maybe Name -- ^ Name of the thing this doc is for
+           -> Maybe Package -- ^ Current package
+           -> Qualification -> Documentation DocName -> Html
+docSection n pkg qual =
+  maybe noHtml (docSection_ n pkg qual) . combineDocumentation
+
+
+docSection_ :: Maybe Name    -- ^ Name of the thing this doc is for
+            -> Maybe Package -- ^ Current package
+            -> Qualification -> MDoc DocName -> Html
+docSection_ n pkg qual =
+  (docElement thediv <<) . docToHtml (getOccString <$> n) pkg qual
+
+
+cleanup :: MDoc a -> MDoc a
+cleanup = overDoc (markup fmtUnParagraphLists)
+  where
+    -- If there is a single paragraph, then surrounding it with <P>..</P>
+    -- can add too much whitespace in some browsers (eg. IE).  However if
+    -- we have multiple paragraphs, then we want the extra whitespace to
+    -- separate them.  So we catch the single paragraph case and transform it
+    -- here. We don't do this in code blocks as it eliminates line breaks.
+    unParagraph :: Doc a -> Doc a
+    unParagraph (DocParagraph d) = d
+    unParagraph doc              = doc
+
+    fmtUnParagraphLists :: DocMarkup (Wrap a) (Doc a)
+    fmtUnParagraphLists = idMarkup {
+      markupUnorderedList = DocUnorderedList . map unParagraph,
+      markupOrderedList   = DocOrderedList   . map (\(index, a) -> (index, unParagraph a))
+      }
diff --git a/haddock-api/src/Haddock/Backends/Xhtml/Layout.hs b/haddock-api/src/Haddock/Backends/Xhtml/Layout.hs
new file mode 100644
--- /dev/null
+++ b/haddock-api/src/Haddock/Backends/Xhtml/Layout.hs
@@ -0,0 +1,319 @@
+-----------------------------------------------------------------------------
+-- |
+-- Module      :  Haddock.Backends.Html.Layout
+-- Copyright   :  (c) Simon Marlow   2003-2006,
+--                    David Waern    2006-2009,
+--                    Mark Lentczner 2010
+-- License     :  BSD-like
+--
+-- Maintainer  :  haddock@projects.haskell.org
+-- Stability   :  experimental
+-- Portability :  portable
+-----------------------------------------------------------------------------
+module Haddock.Backends.Xhtml.Layout (
+  miniBody,
+
+  divPackageHeader, divContent, divModuleHeader, divFooter,
+  divTableOfContents, divDescription, divSynopsis, divInterface,
+  divIndex, divAlphabet, divPackageList, divModuleList,  divContentsList,
+
+  sectionName,
+  nonEmptySectionName,
+
+  shortDeclList,
+  shortSubDecls,
+
+  divTopDecl,
+
+  SubDecl,
+  subArguments,
+  subAssociatedTypes,
+  subConstructors,
+  subPatterns,
+  subEquations,
+  subFields,
+  subInstances, subOrphanInstances,
+  subInstHead, subInstDetails, subFamInstDetails,
+  subMethods,
+  subDefaults,
+  subMinimal,
+
+  topDeclElem, declElem,
+) where
+
+import Haddock.Backends.Xhtml.DocMarkup
+import Haddock.Backends.Xhtml.Types
+import Haddock.Backends.Xhtml.Utils
+import Haddock.Types
+import Haddock.Utils (makeAnchorId, nameAnchorId)
+import qualified Data.Map as Map
+import Text.XHtml hiding ( name, title, quote )
+import Data.Maybe (fromMaybe)
+
+import GHC.Data.FastString ( unpackFS )
+import GHC hiding (anchor)
+import GHC.Types.Name (nameOccName)
+
+--------------------------------------------------------------------------------
+-- * Sections of the document
+--------------------------------------------------------------------------------
+
+
+miniBody :: Html -> Html
+miniBody = body ! [identifier "mini"]
+
+
+sectionDiv :: String -> Html -> Html
+sectionDiv i = thediv ! [identifier i]
+
+
+sectionName :: Html -> Html
+sectionName = paragraph ! [theclass "caption"]
+
+
+-- | Make an element that always has at least something (a non-breaking space).
+-- If it would have otherwise been empty, then give it the class ".empty".
+nonEmptySectionName :: Html -> Html
+nonEmptySectionName c
+  | isNoHtml c = thespan ! [theclass "caption empty"] $ spaceHtml
+  | otherwise  = thespan ! [theclass "caption"]       $ c
+
+
+divPackageHeader, divContent, divModuleHeader, divFooter,
+  divTableOfContents, divDescription, divSynopsis, divInterface,
+  divIndex, divAlphabet, divPackageList, divModuleList, divContentsList
+    :: Html -> Html
+
+divPackageHeader    = sectionDiv "package-header"
+divContent          = sectionDiv "content"
+divModuleHeader     = sectionDiv "module-header"
+divFooter           = sectionDiv "footer"
+divTableOfContents  = sectionDiv "table-of-contents"
+divContentsList     = sectionDiv "contents-list"
+divDescription      = sectionDiv "description"
+divSynopsis         = sectionDiv "synopsis"
+divInterface        = sectionDiv "interface"
+divIndex            = sectionDiv "index"
+divAlphabet         = sectionDiv "alphabet"
+divModuleList       = sectionDiv "module-list"
+divPackageList      = sectionDiv "module-list"
+
+
+--------------------------------------------------------------------------------
+-- * Declaration containers
+--------------------------------------------------------------------------------
+
+
+shortDeclList :: [Html] -> Html
+shortDeclList items = ulist << map (li ! [theclass "src short"] <<) items
+
+
+shortSubDecls :: Bool -> [Html] -> Html
+shortSubDecls inst items = ulist ! [theclass c] << map (i <<) items
+  where i | inst      = li ! [theclass "inst"]
+          | otherwise = li
+        c | inst      = "inst"
+          | otherwise = "subs"
+
+
+divTopDecl :: Html -> Html
+divTopDecl = thediv ! [theclass "top"]
+
+
+type SubDecl = (Html, Maybe (MDoc DocName), [Html])
+
+
+divSubDecls :: (HTML a) => String -> a -> Maybe Html -> Html
+divSubDecls cssClass captionName = maybe noHtml wrap
+  where
+    wrap = (subSection <<) . (subCaption +++)
+    subSection = thediv ! [theclass $ unwords ["subs", cssClass]]
+    subCaption = paragraph ! [theclass "caption"] << captionName
+
+
+subDlist :: Maybe Package -> Qualification -> [SubDecl] -> Maybe Html
+subDlist _ _ [] = Nothing
+subDlist pkg qual decls = Just $ ulist << map subEntry decls
+  where
+    subEntry (decl, mdoc, subs) =
+      li <<
+        (define ! [theclass "src"] << decl +++
+         docElement thediv << (fmap (docToHtml Nothing pkg qual) mdoc +++ subs))
+
+
+subTable :: Maybe Package -> Qualification -> [SubDecl] -> Maybe Html
+subTable _ _ [] = Nothing
+subTable pkg qual decls = Just $ table << aboves (concatMap subRow decls)
+  where
+    subRow (decl, mdoc, subs) =
+      (td ! [theclass "src"] << decl
+       <->
+       docElement td << fmap (docToHtml Nothing pkg qual) mdoc)
+      : map (cell . (td <<)) subs
+
+
+-- | Sub table with source information (optional).
+subTableSrc :: Maybe Package -> Qualification -> LinksInfo -> Bool
+            -> [(SubDecl, Maybe Module, Located DocName)] -> Maybe Html
+subTableSrc _ _ _ _ [] = Nothing
+subTableSrc pkg qual lnks splice decls = Just $ table << aboves (concatMap subRow decls)
+  where
+    subRow ((decl, mdoc, subs), mdl, L loc dn) =
+      (td ! [theclass "src clearfix"] <<
+        (thespan ! [theclass "inst-left"] << decl)
+        <+> linkHtml loc mdl dn
+      <->
+      docElement td << fmap (docToHtml Nothing pkg qual) mdoc
+      )
+      : map (cell . (td <<)) subs
+
+    linkHtml :: SrcSpan -> Maybe Module -> DocName -> Html
+    linkHtml loc@(RealSrcSpan _ _) mdl dn = links lnks loc splice mdl dn
+    linkHtml _ _ _ = noHtml
+
+subBlock :: [Html] -> Maybe Html
+subBlock [] = Nothing
+subBlock hs = Just $ toHtml hs
+
+
+subArguments :: Maybe Package -> Qualification -> [SubDecl] -> Html
+subArguments pkg qual = divSubDecls "arguments" "Arguments" . subTable pkg qual
+
+
+subAssociatedTypes :: [Html] -> Html
+subAssociatedTypes = divSubDecls "associated-types" "Associated Types" . subBlock
+
+
+subConstructors :: Maybe Package -> Qualification -> [SubDecl] -> Html
+subConstructors pkg qual = divSubDecls "constructors" "Constructors" . subTable pkg qual
+
+subPatterns :: Maybe Package -> Qualification -> [SubDecl] -> Html
+subPatterns pkg qual = divSubDecls "bundled-patterns" "Bundled Patterns" . subTable pkg qual
+
+subFields :: Maybe Package -> Qualification -> [SubDecl] -> Html
+subFields pkg qual = divSubDecls "fields" "Fields" . subDlist pkg qual
+
+
+subEquations :: Maybe Package -> Qualification -> [SubDecl] -> Html
+subEquations pkg qual = divSubDecls "equations" "Equations" . subTable pkg qual
+
+
+-- | Generate collapsible sub table for instance declarations, with source
+subInstances :: Maybe Package -> Qualification
+             -> String -- ^ Class name, used for anchor generation
+             -> LinksInfo -> Bool
+             -> [(SubDecl, Maybe Module, Located DocName)] -> Html
+subInstances pkg qual nm lnks splice = maybe noHtml wrap . instTable
+  where
+    wrap contents = subSection (hdr +++ collapseDetails id_ DetailsOpen (summary +++ contents))
+    instTable = subTableSrc pkg qual lnks splice
+    subSection = thediv ! [theclass "subs instances"]
+    hdr = h4 ! collapseControl id_ "instances" << "Instances"
+    summary = thesummary ! [ theclass "hide-when-js-enabled" ] << "Instances details"
+    id_ = makeAnchorId $ "i:" ++ nm
+
+
+subOrphanInstances :: Maybe Package -> Qualification
+                   -> LinksInfo -> Bool
+                   -> [(SubDecl, Maybe Module, Located DocName)] -> Html
+subOrphanInstances pkg qual lnks splice  = maybe noHtml wrap . instTable
+  where
+    wrap = ((h1 << "Orphan instances") +++)
+    instTable = fmap (thediv ! [ identifier ("section." ++ id_) ] <<) . subTableSrc pkg qual lnks splice
+    id_ = makeAnchorId "orphans"
+
+
+subInstHead :: String -- ^ Instance unique id (for anchor generation)
+            -> Html -- ^ Header content (instance name and type)
+            -> Html
+subInstHead iid hdr =
+    expander noHtml <+> hdr
+  where
+    expander = thespan ! collapseControl (instAnchorId iid) "instance"
+
+
+subInstDetails :: String -- ^ Instance unique id (for anchor generation)
+               -> [Html] -- ^ Associated type contents
+               -> [Html] -- ^ Method contents (pretty-printed signatures)
+               -> Html   -- ^ Source module
+               -> Html
+subInstDetails iid ats mets mdl =
+    subInstSection iid << (p mdl <+> subAssociatedTypes ats <+> subMethods mets)
+
+subFamInstDetails :: String -- ^ Instance unique id (for anchor generation)
+                  -> Html   -- ^ Type or data family instance
+                  -> Html   -- ^ Source module TODO: use this
+                  -> Html
+subFamInstDetails iid fi mdl =
+    subInstSection iid << (p mdl <+> (thediv ! [theclass "src"] << fi))
+
+subInstSection :: String -- ^ Instance unique id (for anchor generation)
+               -> Html
+               -> Html
+subInstSection iid contents = collapseDetails (instAnchorId iid) DetailsClosed (summary +++ contents)
+  where
+    summary = thesummary ! [ theclass "hide-when-js-enabled" ] << "Instance details"
+
+instAnchorId :: String -> String
+instAnchorId iid = makeAnchorId $ "i:" ++ iid
+
+
+subMethods :: [Html] -> Html
+subMethods = divSubDecls "methods" "Methods" . subBlock
+
+subDefaults :: [Html] -> Html
+subDefaults = divSubDecls "default" "" . subBlock
+
+subMinimal :: Html -> Html
+subMinimal = divSubDecls "minimal" "Minimal complete definition" . Just . declElem
+
+
+-- a box for displaying code
+declElem :: Html -> Html
+declElem = paragraph ! [theclass "src"]
+
+
+-- a box for top level documented names
+-- it adds a source and wiki link at the right hand side of the box
+topDeclElem :: LinksInfo -> SrcSpan -> Bool -> [DocName] -> Html -> Html
+topDeclElem lnks loc splice names html =
+    declElem << (html <+> (links lnks loc splice Nothing $ head names))
+        -- FIXME: is it ok to simply take the first name?
+
+-- | Adds a source and wiki link at the right hand side of the box.
+-- Name must be documented, otherwise we wouldn't get here.
+links :: LinksInfo -> SrcSpan -> Bool -> Maybe Module -> DocName -> Html
+links ((_,_,sourceMap,lineMap), (_,_,maybe_wiki_url)) loc splice mdl' docName@(Documented n mdl) =
+  srcLink <+> wikiLink <+> (selfLink ! [theclass "selflink"] << "#")
+  where selfLink = linkedAnchor (nameAnchorId (nameOccName (getName docName)))
+
+        srcLink = let nameUrl = Map.lookup origPkg sourceMap
+                      lineUrl = Map.lookup origPkg lineMap
+                      mUrl | splice    = lineUrl
+                                        -- Use the lineUrl as a backup
+                           | otherwise = maybe lineUrl Just nameUrl in
+          case mUrl of
+            Nothing  -> noHtml
+            Just url -> let url' = spliceURL (Just fname) (Just origMod)
+                                               (Just n) (Just loc) url
+                          in anchor ! [href url', theclass "link"] << "Source"
+
+        wikiLink =
+          case maybe_wiki_url of
+            Nothing  -> noHtml
+            Just url -> let url' = spliceURL (Just fname) (Just mdl)
+                                               (Just n) (Just loc) url
+                          in anchor ! [href url', theclass "link"] << "Comments"
+
+        -- For source links, we want to point to the original module,
+        -- because only that will have the source.
+        --
+        -- 'mdl'' is a way of "overriding" the module. Without it, instances
+        -- will point to the module defining the class/family, which is wrong.
+        origMod = fromMaybe (nameModule n) mdl'
+        origPkg = moduleUnit origMod
+
+        fname = case loc of
+          RealSrcSpan l _ -> unpackFS (srcSpanFile l)
+          UnhelpfulSpan _ -> error "links: UnhelpfulSpan"
+links _ _ _ _ _ = noHtml
diff --git a/haddock-api/src/Haddock/Backends/Xhtml/Meta.hs b/haddock-api/src/Haddock/Backends/Xhtml/Meta.hs
new file mode 100644
--- /dev/null
+++ b/haddock-api/src/Haddock/Backends/Xhtml/Meta.hs
@@ -0,0 +1,28 @@
+module Haddock.Backends.Xhtml.Meta where
+
+import Haddock.Utils.Json
+import Haddock.Version
+
+import Data.ByteString.Builder (hPutBuilder)
+import System.FilePath ((</>))
+import System.IO (withFile, IOMode (WriteMode))
+
+-- | Everytime breaking changes to the Quckjump api
+-- happen this needs to be modified.
+quickjumpVersion :: Int
+quickjumpVersion = 1
+
+-- | Writes a json encoded file containing additional
+-- information about the generated documentation. This
+-- is useful for external tools (e.g., Hackage).
+writeHaddockMeta :: FilePath -> Bool -> IO ()
+writeHaddockMeta odir withQuickjump = do
+  let
+    meta_json :: Value
+    meta_json = object (concat [
+        [ "haddock_version"   .= String projectVersion ]
+      , [ "quickjump_version" .= quickjumpVersion | withQuickjump ]
+      ])
+
+  withFile (odir </> "meta.json") WriteMode $ \h ->
+    hPutBuilder h (encodeToBuilder meta_json)
diff --git a/haddock-api/src/Haddock/Backends/Xhtml/Names.hs b/haddock-api/src/Haddock/Backends/Xhtml/Names.hs
new file mode 100644
--- /dev/null
+++ b/haddock-api/src/Haddock/Backends/Xhtml/Names.hs
@@ -0,0 +1,198 @@
+-----------------------------------------------------------------------------
+-- |
+-- Module      :  Haddock.Backends.Html.Names
+-- Copyright   :  (c) Simon Marlow   2003-2006,
+--                    David Waern    2006-2009,
+--                    Mark Lentczner 2010
+-- License     :  BSD-like
+--
+-- Maintainer  :  haddock@projects.haskell.org
+-- Stability   :  experimental
+-- Portability :  portable
+-----------------------------------------------------------------------------
+module Haddock.Backends.Xhtml.Names (
+  ppName, ppDocName, ppLDocName, ppRdrName, ppUncheckedLink,
+  ppBinder, ppBinderInfix, ppBinder',
+  ppModule, ppModuleRef, ppIPName, linkId, Notation(..),
+  ppWrappedDocName, ppWrappedName,
+) where
+
+
+import Haddock.Backends.Xhtml.Utils
+import Haddock.GhcUtils
+import Haddock.Types
+import Haddock.Utils
+
+import Text.XHtml hiding ( name, p, quote )
+import qualified Data.Map as M
+import Data.List ( stripPrefix )
+
+import GHC hiding (LexicalFixity(..), anchor)
+import GHC.Types.Name
+import GHC.Types.Name.Reader
+import GHC.Data.FastString (unpackFS)
+
+
+-- | Indicator of how to render a 'DocName' into 'Html'
+data Notation = Raw -- ^ Render as-is.
+              | Infix -- ^ Render using infix notation.
+              | Prefix -- ^ Render using prefix notation.
+                deriving (Eq, Show)
+
+ppOccName :: OccName -> Html
+ppOccName = toHtml . occNameString
+
+
+ppRdrName :: RdrName -> Html
+ppRdrName = ppOccName . rdrNameOcc
+
+ppIPName :: HsIPName -> Html
+ppIPName = toHtml . ('?':) . unpackFS . hsIPNameFS
+
+
+ppUncheckedLink :: Qualification -> Wrap (ModuleName, OccName) -> Html
+ppUncheckedLink _ x = linkIdOcc' mdl (Just occ) << occHtml
+  where
+    (mdl, occ) = unwrap x
+    occHtml = toHtml (showWrapped (occNameString . snd) x) -- TODO: apply ppQualifyName
+
+-- The Bool indicates if it is to be rendered in infix notation
+ppLDocName :: Qualification -> Notation -> GenLocated l DocName -> Html
+ppLDocName qual notation (L _ d) = ppDocName qual notation True d
+
+
+ppDocName :: Qualification -> Notation -> Bool -> DocName -> Html
+ppDocName qual notation insertAnchors docName =
+  case docName of
+    Documented name mdl ->
+      linkIdOcc mdl (Just (nameOccName name)) insertAnchors
+      << ppQualifyName qual notation name mdl
+    Undocumented name
+      | isExternalName name || isWiredInName name ->
+          ppQualifyName qual notation name (nameModule name)
+      | otherwise -> ppName notation name
+
+
+ppWrappedDocName :: Qualification -> Notation -> Bool -> Wrap DocName -> Html
+ppWrappedDocName qual notation insertAnchors docName = case docName of
+  Unadorned n -> ppDocName qual notation insertAnchors n
+  Parenthesized n -> ppDocName qual Prefix insertAnchors n
+  Backticked n -> ppDocName qual Infix insertAnchors n
+
+ppWrappedName :: Notation -> Wrap Name -> Html
+ppWrappedName notation docName = case docName of
+  Unadorned n -> ppName notation n
+  Parenthesized n -> ppName Prefix n
+  Backticked n -> ppName Infix n
+
+-- | Render a name depending on the selected qualification mode
+ppQualifyName :: Qualification -> Notation -> Name -> Module -> Html
+ppQualifyName qual notation name mdl =
+  case qual of
+    NoQual   -> ppName notation name
+    FullQual -> ppFullQualName notation mdl name
+    LocalQual localmdl ->
+      if moduleString mdl == moduleString localmdl
+        then ppName notation name
+        else ppFullQualName notation mdl name
+    RelativeQual localmdl ->
+      case stripPrefix (moduleString localmdl) (moduleString mdl) of
+        -- local, A.x -> x
+        Just []      -> ppName notation name
+        -- sub-module, A.B.x -> B.x
+        Just ('.':m) -> toHtml $ m ++ '.' : getOccString name
+        -- some module with same prefix, ABC.x -> ABC.x
+        Just _       -> ppFullQualName notation mdl name
+        -- some other module, D.x -> D.x
+        Nothing      -> ppFullQualName notation mdl name
+    AliasedQual aliases localmdl ->
+      case (moduleString mdl == moduleString localmdl,
+            M.lookup mdl aliases) of
+        (False, Just alias) -> ppQualName notation alias name
+        _ -> ppName notation name
+
+
+ppFullQualName :: Notation -> Module -> Name -> Html
+ppFullQualName notation mdl name = wrapInfix notation (getOccName name) qname
+  where
+    qname = toHtml $ moduleString mdl ++ '.' : getOccString name
+
+ppQualName :: Notation -> ModuleName -> Name -> Html
+ppQualName notation mdlName name = wrapInfix notation (getOccName name) qname
+  where
+    qname = toHtml $ moduleNameString mdlName ++ '.' : getOccString name
+
+ppName :: Notation -> Name -> Html
+ppName notation name = wrapInfix notation (getOccName name) $ toHtml (getOccString name)
+
+
+ppBinder :: Bool -> OccName -> Html
+ppBinder = ppBinderWith Prefix
+
+ppBinderInfix :: Bool -> OccName -> Html
+ppBinderInfix = ppBinderWith Infix
+
+ppBinderWith :: Notation -> Bool -> OccName -> Html
+-- 'isRef' indicates whether this is merely a reference from another part of
+-- the documentation or is the actual definition; in the latter case, we also
+-- set the 'id' and 'class' attributes.
+ppBinderWith notation isRef n =
+  makeAnchor << ppBinder' notation n
+  where
+    name = nameAnchorId n
+    makeAnchor | isRef     = linkedAnchor name
+               | otherwise = namedAnchor name ! [theclass "def"]
+
+ppBinder' :: Notation -> OccName -> Html
+ppBinder' notation n = wrapInfix notation n $ ppOccName n
+
+wrapInfix :: Notation -> OccName -> Html -> Html
+wrapInfix notation n = case notation of
+  Infix | is_star_kind -> id
+        | not is_sym -> quote
+  Prefix | is_star_kind -> id
+         | is_sym -> parens
+  _ -> id
+  where
+    is_sym = isSymOcc n
+    is_star_kind = isTcOcc n && occNameString n == "*"
+
+linkId :: Module -> Maybe Name -> Html -> Html
+linkId mdl mbName = linkIdOcc mdl (fmap nameOccName mbName) True
+
+
+linkIdOcc :: Module -> Maybe OccName -> Bool -> Html -> Html
+linkIdOcc mdl mbName insertAnchors =
+  if insertAnchors
+  then anchor ! [href url, title ttl]
+  else id
+  where
+    ttl = moduleNameString (moduleName mdl)
+    url = case mbName of
+      Nothing   -> moduleUrl mdl
+      Just name -> moduleNameUrl mdl name
+
+
+linkIdOcc' :: ModuleName -> Maybe OccName -> Html -> Html
+linkIdOcc' mdl mbName = anchor ! [href url, title ttl]
+  where
+    ttl = moduleNameString mdl
+    url = case mbName of
+      Nothing   -> moduleHtmlFile' mdl
+      Just name -> moduleNameUrl' mdl name
+
+
+ppModule :: Module -> Html
+ppModule mdl = anchor ! [href (moduleUrl mdl)]
+               << toHtml (moduleString mdl)
+
+
+ppModuleRef :: Maybe Html -> ModuleName -> String -> Html
+ppModuleRef Nothing mdl ref = anchor ! [href (moduleHtmlFile' mdl ++ ref)]
+                              << toHtml (moduleNameString mdl)
+ppModuleRef (Just lbl) mdl ref = anchor ! [href (moduleHtmlFile' mdl ++ ref)]
+                                 << lbl
+
+    -- NB: The ref parameter already includes the '#'.
+    -- This function is only called from markupModule expanding a
+    -- DocModule, which doesn't seem to be ever be used.
diff --git a/haddock-api/src/Haddock/Backends/Xhtml/Themes.hs b/haddock-api/src/Haddock/Backends/Xhtml/Themes.hs
new file mode 100644
--- /dev/null
+++ b/haddock-api/src/Haddock/Backends/Xhtml/Themes.hs
@@ -0,0 +1,208 @@
+-----------------------------------------------------------------------------
+-- |
+-- Module      :  Haddock.Backends.Html.Themes
+-- Copyright   :  (c) Mark Lentczner 2010
+-- License     :  BSD-like
+--
+-- Maintainer  :  haddock@projects.haskell.org
+-- Stability   :  experimental
+-- Portability :  portable
+-----------------------------------------------------------------------------
+module Haddock.Backends.Xhtml.Themes (
+    Themes,
+    getThemes,
+
+    cssFiles, styleSheet
+    )
+    where
+
+import Haddock.Options
+import Haddock.Backends.Xhtml.Types ( BaseURL, withBaseURL )
+
+import Control.Monad (liftM)
+import Data.Char (toLower)
+import Data.Either (lefts, rights)
+import Data.List (nub)
+import Data.Maybe (isJust, listToMaybe)
+
+import System.Directory
+import System.FilePath
+import Text.XHtml hiding ( name, title, p, quote, (</>) )
+import qualified Text.XHtml as XHtml
+
+
+--------------------------------------------------------------------------------
+-- * CSS Themes
+--------------------------------------------------------------------------------
+
+data Theme = Theme {
+  themeName :: String,
+  themeHref :: String,
+  themeFiles :: [FilePath]
+  }
+
+type Themes = [Theme]
+
+type PossibleTheme = Either String Theme
+type PossibleThemes = Either String Themes
+
+
+-- | Find a theme by name (case insensitive match)
+findTheme :: String -> Themes -> Maybe Theme
+findTheme s = listToMaybe . filter ((== ls).lower.themeName)
+  where lower = map toLower
+        ls = lower s
+
+
+-- | Standard theme used by default
+standardTheme :: FilePath -> IO PossibleThemes
+standardTheme libDir = liftM (liftEither (take 1)) (defaultThemes libDir)
+
+
+-- | Default themes that are part of Haddock; added with @--built-in-themes@
+-- The first theme in this list is considered the standard theme.
+-- Themes are "discovered" by scanning the html sub-dir of the libDir,
+-- and looking for directories with the extension .theme or .std-theme.
+-- The later is, obviously, the standard theme.
+defaultThemes :: FilePath -> IO PossibleThemes
+defaultThemes libDir = do
+  themeDirs <- getDirectoryItems (libDir </> "html")
+  themes <- mapM directoryTheme $ discoverThemes themeDirs
+  return $ sequenceEither themes
+  where
+    discoverThemes paths =
+      filterExt ".std-theme" paths ++ filterExt ".theme" paths
+    filterExt ext = filter ((== ext).takeExtension)
+
+
+-- | Build a theme from a single .css file
+singleFileTheme :: FilePath -> IO PossibleTheme
+singleFileTheme path =
+  if isCssFilePath path
+      then retRight $ Theme name file [path]
+      else errMessage "File extension isn't .css" path
+  where
+    name = takeBaseName path
+    file = takeFileName path
+
+
+-- | Build a theme from a directory
+directoryTheme :: FilePath -> IO PossibleTheme
+directoryTheme path = do
+  items <- getDirectoryItems path
+  case filter isCssFilePath items of
+    [cf] -> retRight $ Theme (takeBaseName path) (takeFileName cf) items
+    [] -> errMessage "No .css file in theme directory" path
+    _ -> errMessage "More than one .css file in theme directory" path
+
+
+-- | Check if we have a built in theme
+doesBuiltInExist :: IO PossibleThemes -> String -> IO Bool
+doesBuiltInExist pts s = fmap (either (const False) test) pts
+  where test = isJust . findTheme s
+
+
+-- | Find a built in theme
+builtInTheme :: IO PossibleThemes -> String -> IO PossibleTheme
+builtInTheme pts s = either Left fetch <$> pts
+  where fetch = maybe (Left ("Unknown theme: " ++ s)) Right . findTheme s
+
+
+--------------------------------------------------------------------------------
+-- * CSS Theme Arguments
+--------------------------------------------------------------------------------
+
+-- | Process input flags for CSS Theme arguments
+getThemes :: FilePath -> [Flag] -> IO PossibleThemes
+getThemes libDir flags =
+  liftM concatEither (mapM themeFlag flags) >>= someTheme
+  where
+    themeFlag :: Flag -> IO (Either String Themes)
+    themeFlag (Flag_CSS path) = (liftM . liftEither) (:[]) (theme path)
+    themeFlag (Flag_BuiltInThemes) = builtIns
+    themeFlag _ = retRight []
+
+    theme :: FilePath -> IO PossibleTheme
+    theme path = pick path
+      [(doesFileExist,              singleFileTheme),
+       (doesDirectoryExist,         directoryTheme),
+       (doesBuiltInExist builtIns,  builtInTheme builtIns)]
+      "Theme not found"
+
+    pick :: FilePath
+      -> [(FilePath -> IO Bool, FilePath -> IO PossibleTheme)] -> String
+      -> IO PossibleTheme
+    pick path [] msg = errMessage msg path
+    pick path ((test,build):opts) msg = do
+      pass <- test path
+      if pass then build path else pick path opts msg
+
+
+    someTheme :: Either String Themes -> IO (Either String Themes)
+    someTheme (Right []) = standardTheme libDir
+    someTheme est = return est
+
+    builtIns = defaultThemes libDir
+
+
+errMessage :: String -> FilePath -> IO (Either String a)
+errMessage msg path = return (Left msg')
+  where msg' = "Error: " ++ msg ++ ": \"" ++ path ++ "\"\n"
+
+
+retRight :: a -> IO (Either String a)
+retRight = return . Right
+
+
+--------------------------------------------------------------------------------
+-- * File Utilities
+--------------------------------------------------------------------------------
+
+
+getDirectoryItems :: FilePath -> IO [FilePath]
+getDirectoryItems path =
+  map (combine path) . filter notDot <$> getDirectoryContents path
+  where notDot s = s /= "." && s /= ".."
+
+
+isCssFilePath :: FilePath -> Bool
+isCssFilePath path = takeExtension path == ".css"
+
+
+--------------------------------------------------------------------------------
+-- * Style Sheet Utilities
+--------------------------------------------------------------------------------
+
+cssFiles :: Themes -> [String]
+cssFiles ts = nub $ concatMap themeFiles ts
+
+
+styleSheet :: BaseURL -> Themes -> Html
+styleSheet base_url ts = toHtml $ zipWith mkLink rels ts
+  where
+    rels = "stylesheet" : repeat "alternate stylesheet"
+    mkLink aRel t =
+      thelink
+        ! [ href (withBaseURL base_url (themeHref t)),  rel aRel, thetype "text/css",
+            XHtml.title (themeName t)
+          ]
+        << noHtml
+
+--------------------------------------------------------------------------------
+-- * Either Utilities
+--------------------------------------------------------------------------------
+
+-- These three routines are here because Haddock does not have access to the
+-- Control.Monad.Error module which supplies the Functor and Monad instances
+-- for Either String.
+
+sequenceEither :: [Either a b] -> Either a [b]
+sequenceEither es = maybe (Right $ rights es) Left (listToMaybe (lefts es))
+
+
+liftEither :: (b -> c) -> Either a b -> Either a c
+liftEither f = either Left (Right . f)
+
+
+concatEither :: [Either a [b]] -> Either a [b]
+concatEither = liftEither concat . sequenceEither
diff --git a/haddock-api/src/Haddock/Backends/Xhtml/Types.hs b/haddock-api/src/Haddock/Backends/Xhtml/Types.hs
new file mode 100644
--- /dev/null
+++ b/haddock-api/src/Haddock/Backends/Xhtml/Types.hs
@@ -0,0 +1,48 @@
+-----------------------------------------------------------------------------
+-- |
+-- Module      :  Haddock.Backends.Html.Types
+-- Copyright   :  (c) Simon Marlow   2003-2006,
+--                    David Waern    2006-2009,
+--                    Mark Lentczner 2010
+-- License     :  BSD-like
+--
+-- Maintainer  :  haddock@projects.haskell.org
+-- Stability   :  experimental
+-- Portability :  portable
+-----------------------------------------------------------------------------
+module Haddock.Backends.Xhtml.Types (
+  SourceURLs, WikiURLs,
+  BaseURL,
+  withBaseURL,
+  LinksInfo,
+  Splice,
+  Unicode,
+) where
+
+
+import Data.Map
+import GHC
+import qualified System.FilePath as FilePath
+
+
+-- the base, module and entity URLs for the source code and wiki links.
+type SourceURLs = (Maybe FilePath, Maybe FilePath, Map Unit FilePath, Map Unit FilePath)
+type WikiURLs = (Maybe FilePath, Maybe FilePath, Maybe FilePath)
+
+-- | base url for loading js, json, css resources.  The default is "."
+--
+type BaseURL = Maybe String
+
+-- TODO: we shouldn't use 'FilePath.</>'
+withBaseURL :: BaseURL -> String -> String
+withBaseURL Nothing        uri = uri
+withBaseURL (Just baseUrl) uri = baseUrl FilePath.</> uri
+
+-- The URL for source and wiki links
+type LinksInfo = (SourceURLs, WikiURLs)
+
+-- Whether something is a splice or not
+type Splice = Bool
+
+-- Whether unicode syntax is to be used
+type Unicode = Bool
diff --git a/haddock-api/src/Haddock/Backends/Xhtml/Utils.hs b/haddock-api/src/Haddock/Backends/Xhtml/Utils.hs
new file mode 100644
--- /dev/null
+++ b/haddock-api/src/Haddock/Backends/Xhtml/Utils.hs
@@ -0,0 +1,241 @@
+-----------------------------------------------------------------------------
+-- |
+-- Module      :  Haddock.Backends.Html.Util
+-- Copyright   :  (c) Simon Marlow   2003-2006,
+--                    David Waern    2006-2009,
+--                    Mark Lentczner 2010
+-- License     :  BSD-like
+--
+-- Maintainer  :  haddock@projects.haskell.org
+-- Stability   :  experimental
+-- Portability :  portable
+-----------------------------------------------------------------------------
+module Haddock.Backends.Xhtml.Utils (
+  renderToString,
+
+  namedAnchor, linkedAnchor,
+  spliceURL, spliceURL',
+  groupId,
+
+  (<+>), (<=>), char,
+  keyword, punctuate,
+
+  braces, brackets, pabrackets, parens, parenList, ubxParenList, ubxSumList,
+  arrow, lollipop, comma, dcolon, dot, darrow, equals, forallSymbol, quote, promoQuote,
+  multAnnotation,
+  atSign,
+
+  hsep, vcat,
+
+  DetailsState(..), collapseDetails, thesummary,
+  collapseToggle, collapseControl,
+) where
+
+
+import Haddock.Utils
+
+import Data.Maybe
+
+import Text.XHtml hiding ( name, title, p, quote )
+import qualified Text.XHtml as XHtml
+
+import GHC              ( SrcSpan(..), srcSpanStartLine, Name )
+import GHC.Unit.Module ( Module, ModuleName, moduleName, moduleNameString )
+import GHC.Types.Name   ( getOccString, nameOccName, isValOcc )
+
+
+-- | Replace placeholder string elements with provided values.
+--
+-- Used to generate URL for customized external paths, usually provided with
+-- @--source-module@, @--source-entity@ and related command-line arguments.
+--
+-- >>> spliceURL Nothing mmod mname Nothing "output/%{MODULE}.hs#%{NAME}"
+-- "output/Foo.hs#foo"
+spliceURL :: Maybe FilePath -> Maybe Module -> Maybe GHC.Name ->
+             Maybe SrcSpan -> String -> String
+spliceURL mfile mmod = spliceURL' mfile (moduleName <$> mmod)
+
+
+-- | Same as 'spliceURL' but takes 'ModuleName' instead of 'Module'.
+spliceURL' :: Maybe FilePath -> Maybe ModuleName -> Maybe GHC.Name ->
+              Maybe SrcSpan -> String -> String
+spliceURL' maybe_file maybe_mod maybe_name maybe_loc = run
+ where
+  file = fromMaybe "" maybe_file
+  mdl = case maybe_mod of
+          Nothing           -> ""
+          Just m -> moduleNameString m
+
+  (name, kind) =
+    case maybe_name of
+      Nothing             -> ("","")
+      Just n | isValOcc (nameOccName n) -> (escapeStr (getOccString n), "v")
+             | otherwise -> (escapeStr (getOccString n), "t")
+
+  line = case maybe_loc of
+    Nothing -> ""
+    Just span_ ->
+      case span_ of
+      RealSrcSpan span__ _ ->
+        show $ srcSpanStartLine span__
+      UnhelpfulSpan _ -> ""
+
+  run "" = ""
+  run ('%':'M':rest) = mdl  ++ run rest
+  run ('%':'F':rest) = file ++ run rest
+  run ('%':'N':rest) = name ++ run rest
+  run ('%':'K':rest) = kind ++ run rest
+  run ('%':'L':rest) = line ++ run rest
+  run ('%':'%':rest) = '%'   : run rest
+
+  run ('%':'{':'M':'O':'D':'U':'L':'E':'}':rest) = mdl  ++ run rest
+  run ('%':'{':'F':'I':'L':'E':'}':rest)         = file ++ run rest
+  run ('%':'{':'N':'A':'M':'E':'}':rest)         = name ++ run rest
+  run ('%':'{':'K':'I':'N':'D':'}':rest)         = kind ++ run rest
+
+  run ('%':'{':'M':'O':'D':'U':'L':'E':'/':'.':'/':c:'}':rest) =
+    map (\x -> if x == '.' then c else x) mdl ++ run rest
+
+  run ('%':'{':'F':'I':'L':'E':'/':'/':'/':c:'}':rest) =
+    map (\x -> if x == '/' then c else x) file ++ run rest
+
+  run ('%':'{':'L':'I':'N':'E':'}':rest)         = line ++ run rest
+
+  run (c:rest) = c : run rest
+
+
+renderToString :: Bool -> Html -> String
+renderToString debug html
+  | debug = renderHtml html
+  | otherwise = showHtml html
+
+
+hsep :: [Html] -> Html
+hsep [] = noHtml
+hsep htmls = foldr1 (<+>) htmls
+
+-- | Concatenate a series of 'Html' values vertically, with linebreaks in between.
+vcat :: [Html] -> Html
+vcat [] = noHtml
+vcat htmls = foldr1 (\a b -> a+++br+++b) htmls
+
+
+infixr 8 <+>
+(<+>) :: Html -> Html -> Html
+a <+> b = a +++ sep +++ b
+  where
+    sep = if isNoHtml a || isNoHtml b then noHtml else toHtml " "
+
+-- | Join two 'Html' values together with a linebreak in between.
+--   Has 'noHtml' as left identity.
+infixr 8 <=>
+(<=>) :: Html -> Html -> Html
+a <=> b = a +++ sep +++ b
+  where
+    sep = if isNoHtml a then noHtml else br
+
+
+keyword :: String -> Html
+keyword s = thespan ! [theclass "keyword"] << toHtml s
+
+
+equals, comma :: Html
+equals = char '='
+comma  = char ','
+
+
+char :: Char -> Html
+char c = toHtml [c]
+
+
+quote :: Html -> Html
+quote h = char '`' +++ h +++ '`'
+
+
+-- | Promoted type quote (e.g. @'[a, b]@, @'(a, b, c)@).
+promoQuote :: Html -> Html
+promoQuote h = char '\'' +++ h
+
+
+parens, brackets, pabrackets, braces :: Html -> Html
+parens h        = char '(' +++ h +++ char ')'
+brackets h      = char '[' +++ h +++ char ']'
+pabrackets h    = toHtml "[:" +++ h +++ toHtml ":]"
+braces h        = char '{' +++ h +++ char '}'
+
+
+punctuate :: Html -> [Html] -> [Html]
+punctuate _ []     = []
+punctuate h (d0:ds) = go d0 ds
+                   where
+                     go d [] = [d]
+                     go d (e:es) = (d +++ h) : go e es
+
+
+parenList :: [Html] -> Html
+parenList = parens . hsep . punctuate comma
+
+
+ubxParenList :: [Html] -> Html
+ubxParenList = ubxparens . hsep . punctuate comma
+
+
+ubxSumList :: [Html]  -> Html
+ubxSumList = ubxparens . hsep . punctuate (toHtml " | ")
+
+
+ubxparens :: Html -> Html
+ubxparens h = toHtml "(#" <+> h <+> toHtml "#)"
+
+
+dcolon, arrow, lollipop, darrow, forallSymbol, atSign :: Bool -> Html
+dcolon unicode = toHtml (if unicode then "∷" else "::")
+arrow  unicode = toHtml (if unicode then "→" else "->")
+lollipop unicode = toHtml (if unicode then "⊸" else "%1 ->")
+darrow unicode = toHtml (if unicode then "⇒" else "=>")
+forallSymbol unicode = if unicode then toHtml "∀" else keyword "forall"
+atSign unicode = toHtml (if unicode then "@" else "@")
+
+multAnnotation :: Html
+multAnnotation = toHtml "%"
+
+dot :: Html
+dot = toHtml "."
+
+
+-- | Generate a named anchor
+namedAnchor :: String -> Html -> Html
+namedAnchor n = anchor ! [XHtml.identifier n]
+
+
+linkedAnchor :: String -> Html -> Html
+linkedAnchor n = anchor ! [href ('#':n)]
+
+
+-- | generate an anchor identifier for a group
+groupId :: String -> String
+groupId g = makeAnchorId ("g:" ++ g)
+
+--
+-- A section of HTML which is collapsible.
+--
+
+data DetailsState = DetailsOpen | DetailsClosed
+
+collapseDetails :: String -> DetailsState -> Html -> Html
+collapseDetails id_ state = tag "details" ! (identifier id_ : openAttrs)
+  where openAttrs = case state of { DetailsOpen -> [emptyAttr "open"]; DetailsClosed -> [] }
+
+thesummary :: Html -> Html
+thesummary = tag "summary"
+
+-- | Attributes for an area that toggles a collapsed area
+collapseToggle :: String -> String -> [HtmlAttr]
+collapseToggle id_ classes = [ theclass cs, strAttr "data-details-id" id_ ]
+  where cs = unwords (words classes ++ ["details-toggle"])
+
+-- | Attributes for an area that toggles a collapsed area,
+-- and displays a control.
+collapseControl :: String -> String -> [HtmlAttr]
+collapseControl id_ classes = collapseToggle id_ cs
+  where cs = unwords (words classes ++ ["details-toggle-control"])
diff --git a/haddock-api/src/Haddock/Convert.hs b/haddock-api/src/Haddock/Convert.hs
new file mode 100644
--- /dev/null
+++ b/haddock-api/src/Haddock/Convert.hs
@@ -0,0 +1,986 @@
+{-# LANGUAGE CPP           #-}
+{-# LANGUAGE PatternGuards #-}
+{-# LANGUAGE TypeFamilies  #-}
+{-# LANGUAGE BangPatterns  #-}
+
+-----------------------------------------------------------------------------
+-- |
+-- Module      :  Haddock.Convert
+-- Copyright   :  (c) Isaac Dupree 2009,
+-- License     :  BSD-like
+--
+-- Maintainer  :  haddock@projects.haskell.org
+-- Stability   :  experimental
+-- Portability :  portable
+--
+-- Conversion between TyThing and HsDecl. This functionality may be moved into
+-- GHC at some point.
+-----------------------------------------------------------------------------
+module Haddock.Convert (
+  tyThingToLHsDecl,
+  synifyInstHead,
+  synifyFamInst,
+  PrintRuntimeReps(..),
+) where
+
+import Control.DeepSeq (force)
+import GHC.Data.Bag ( emptyBag )
+import GHC.Types.Basic ( TupleSort(..), DefMethSpec(..), TopLevelFlag(..) )
+import GHC.Types.SourceText (SourceText(..))
+import GHC.Types.Fixity (LexicalFixity(..))
+import GHC.Core.Class
+import GHC.Core.Coercion.Axiom
+import GHC.Core.ConLike
+import GHC.Core.DataCon
+import GHC.Core.FamInstEnv
+import GHC.Core.PatSyn
+import GHC.Core.TyCon
+import GHC.Core.Type
+import GHC.Core.TyCo.Rep
+import GHC.Core.TyCo.Compare( eqTypes )
+
+import GHC.Hs
+import GHC.Types.TyThing
+import GHC.Types.Name
+import GHC.Types.Name.Set    ( emptyNameSet )
+import GHC.Types.Name.Reader ( mkVarUnqual )
+import GHC.Builtin.Types.Prim ( alphaTyVars )
+import GHC.Builtin.Types ( eqTyConName, listTyConName, liftedTypeKindTyConName
+                  , unitTy, promotedNilDataCon, promotedConsDataCon )
+import GHC.Builtin.Names ( hasKey, eqTyConKey, ipClassKey, tYPETyConKey
+                 , liftedDataConKey, boxedRepDataConKey )
+import GHC.Types.Unique ( getUnique )
+import GHC.Utils.Misc ( chkAppend, dropList, equalLength
+                      , filterByList, filterOut )
+import GHC.Utils.Panic.Plain ( assert )
+import GHC.Types.Var
+import GHC.Types.Var.Set
+import GHC.Types.SrcLoc
+
+import Language.Haskell.Syntax.Basic (FieldLabelString(..))
+
+import Haddock.Types
+import Haddock.Interface.Specialize
+import Haddock.GhcUtils                      ( orderedFVs, defaultRuntimeRepVars, mkEmptySigType )
+
+import Data.Either (lefts, rights)
+import Data.Maybe                            ( catMaybes, mapMaybe, maybeToList )
+import Data.Either                           ( partitionEithers )
+
+
+-- | Whether or not to default 'RuntimeRep' variables to 'LiftedRep'. Check
+-- out Note [Defaulting RuntimeRep variables] in GHC.Iface.Type for the
+-- motivation.
+data PrintRuntimeReps = ShowRuntimeRep | HideRuntimeRep deriving Show
+
+-- the main function here! yay!
+tyThingToLHsDecl
+  :: PrintRuntimeReps
+  -> TyThing
+  -> Either String ([String], (HsDecl GhcRn))
+tyThingToLHsDecl prr t = case t of
+  -- ids (functions and zero-argument a.k.a. CAFs) get a type signature.
+  -- Including built-in functions like seq.
+  -- foreign-imported functions could be represented with ForD
+  -- instead of SigD if we wanted...
+  --
+  -- in a future code version we could turn idVarDetails = foreign-call
+  -- into a ForD instead of a SigD if we wanted.  Haddock doesn't
+  -- need to care.
+  AnId i -> allOK $ SigD noExtField (synifyIdSig prr ImplicitizeForAll [] i)
+
+  -- type-constructors (e.g. Maybe) are complicated, put the definition
+  -- later in the file (also it's used for class associated-types too.)
+  ATyCon tc
+    | Just cl <- tyConClass_maybe tc -- classes are just a little tedious
+    -> let extractFamilyDecl :: TyClDecl a -> Either String (FamilyDecl a)
+           extractFamilyDecl (FamDecl _ d) = return d
+           extractFamilyDecl _           =
+             Left "tyThingToLHsDecl: impossible associated tycon"
+
+           cvt :: HsTyVarBndr flag GhcRn -> HsType GhcRn
+             -- Without this signature, we trigger GHC#18932
+           cvt (UserTyVar _ _ n) = HsTyVar noAnn NotPromoted n
+           cvt (KindedTyVar _ _ (L name_loc n) kind) = HsKindSig noAnn
+              (L (na2la name_loc) (HsTyVar noAnn NotPromoted (L name_loc n))) kind
+
+           -- | Convert a LHsTyVarBndr to an equivalent LHsType.
+           hsLTyVarBndrToType :: LHsTyVarBndr flag GhcRn -> LHsType GhcRn
+           hsLTyVarBndrToType = fmap cvt
+
+           extractFamDefDecl :: FamilyDecl GhcRn -> Type -> TyFamDefltDecl GhcRn
+           extractFamDefDecl fd rhs =
+             TyFamInstDecl noAnn $ FamEqn
+             { feqn_ext = noAnn
+             , feqn_tycon = fdLName fd
+             , feqn_bndrs = HsOuterImplicit{hso_ximplicit = hsq_ext (fdTyVars fd)}
+             , feqn_pats = map (HsValArg . hsLTyVarBndrToType) $
+                           hsq_explicit $ fdTyVars fd
+             , feqn_fixity = fdFixity fd
+             , feqn_rhs = synifyType WithinType [] rhs }
+
+           extractAtItem
+             :: ClassATItem
+             -> Either String (LFamilyDecl GhcRn, Maybe (LTyFamDefltDecl GhcRn))
+           extractAtItem (ATI at_tc def) = do
+             tyDecl <- synifyTyCon prr Nothing at_tc
+             famDecl <- extractFamilyDecl tyDecl
+             let defEqnTy = fmap (noLocA . extractFamDefDecl famDecl . fst) def
+             pure (noLocA famDecl, defEqnTy)
+
+           atTyClDecls = map extractAtItem (classATItems cl)
+           (atFamDecls, atDefFamDecls) = unzip (rights atTyClDecls)
+           vs = tyConVisibleTyVars (classTyCon cl)
+
+       in withErrs (lefts atTyClDecls) . TyClD noExtField $ ClassDecl
+         { tcdCtxt = Just $ synifyCtx (classSCTheta cl)
+         , tcdLayout = NoLayoutInfo
+         , tcdLName = synifyNameN cl
+         , tcdTyVars = synifyTyVars vs
+         , tcdFixity = synifyFixity cl
+         , tcdFDs = map (\ (l,r) -> noLocA
+                        (FunDep noAnn (map (noLocA . getName) l) (map (noLocA . getName) r)) ) $
+                         snd $ classTvsFds cl
+         , tcdSigs = noLocA (MinimalSig (noAnn, NoSourceText) . noLocA . fmap noLocA $ classMinimalDef cl) :
+                      [ noLocA tcdSig
+                      | clsOp <- classOpItems cl
+                      , tcdSig <- synifyTcIdSig vs clsOp ]
+         , tcdMeths = emptyBag --ignore default method definitions, they don't affect signature
+         -- class associated-types are a subset of TyCon:
+         , tcdATs = atFamDecls
+         , tcdATDefs = catMaybes atDefFamDecls
+         , tcdDocs = [] --we don't have any docs at this point
+         , tcdCExt = emptyNameSet }
+    | otherwise
+    -> synifyTyCon prr Nothing tc >>= allOK . TyClD noExtField
+
+  -- type-constructors (e.g. Maybe) are complicated, put the definition
+  -- later in the file (also it's used for class associated-types too.)
+  ACoAxiom ax -> synifyAxiom ax >>= allOK
+
+  -- a data-constructor alone just gets rendered as a function:
+  AConLike (RealDataCon dc) -> allOK $ SigD noExtField (TypeSig noAnn [synifyNameN dc]
+    (synifySigWcType ImplicitizeForAll [] (dataConWrapperType dc)))
+
+  AConLike (PatSynCon ps) ->
+    allOK . SigD noExtField $ PatSynSig noAnn [synifyNameN ps] (synifyPatSynSigType ps)
+  where
+    withErrs e x = return (e, x)
+    allOK x = return (mempty, x)
+
+synifyAxBranch :: TyCon -> CoAxBranch -> TyFamInstEqn GhcRn
+synifyAxBranch tc (CoAxBranch { cab_tvs = tkvs, cab_lhs = args, cab_rhs = rhs })
+  = let name            = synifyNameN tc
+        args_types_only = filterOutInvisibleTypes tc args
+        typats          = map (synifyType WithinType []) args_types_only
+        annot_typats    = zipWith3 annotHsType args_poly args_types_only typats
+        hs_rhs          = synifyType WithinType [] rhs
+        outer_bndrs     = HsOuterImplicit{hso_ximplicit = map tyVarName tkvs}
+                                       -- TODO: this must change eventually
+    in FamEqn { feqn_ext    = noAnn
+              , feqn_tycon  = name
+              , feqn_bndrs  = outer_bndrs
+              , feqn_pats   = map HsValArg annot_typats
+              , feqn_fixity = synifyFixity name
+              , feqn_rhs    = hs_rhs }
+  where
+    args_poly = tyConArgsPolyKinded tc
+
+synifyAxiom :: CoAxiom br -> Either String (HsDecl GhcRn)
+synifyAxiom ax@(CoAxiom { co_ax_tc = tc })
+  | isOpenTypeFamilyTyCon tc
+  , Just branch <- coAxiomSingleBranch_maybe ax
+  = return $ InstD noExtField
+           $ TyFamInstD noExtField
+           $ TyFamInstDecl { tfid_xtn = noAnn, tfid_eqn = synifyAxBranch tc branch }
+
+  | Just ax' <- isClosedSynFamilyTyConWithAxiom_maybe tc
+  , getUnique ax' == getUnique ax   -- without the getUniques, type error
+  = synifyTyCon ShowRuntimeRep (Just ax) tc >>= return . TyClD noExtField
+
+  | otherwise
+  = Left "synifyAxiom: closed/open family confusion"
+
+-- | Turn type constructors into data declarations, type families, or type synonyms
+synifyTyCon
+  :: PrintRuntimeReps
+  -> Maybe (CoAxiom br)  -- ^ RHS of type synonym
+  -> TyCon               -- ^ type constructor to convert
+  -> Either String (TyClDecl GhcRn)
+synifyTyCon prr _coax tc
+  | isPrimTyCon tc
+  = return $
+    DataDecl { tcdLName = synifyNameN tc
+             , tcdTyVars = HsQTvs  { hsq_ext = []   -- No kind polymorphism
+                                   , hsq_explicit = zipWith mk_hs_tv
+                                                            (map scaledThing tyVarKinds)
+                                                            alphaTyVars --a, b, c... which are unfortunately all kind *
+                                   }
+
+           , tcdFixity = synifyFixity tc
+
+           , tcdDataDefn = HsDataDefn { dd_ext = noExtField
+                                      , dd_cons = DataTypeCons False []  -- No constructors; arbitrary lie, they are neither
+                                                    -- algebraic data nor newtype:
+                                      , dd_ctxt = Nothing
+                                      , dd_cType = Nothing
+                                      , dd_kindSig = synifyDataTyConReturnKind tc
+                                               -- we have their kind accurately:
+                                      , dd_derivs = [] }
+           , tcdDExt = DataDeclRn False emptyNameSet }
+  where
+    -- tyConTyVars doesn't work on fun/prim, but we can make them up:
+    mk_hs_tv realKind fakeTyVar
+      | isLiftedTypeKind realKind = noLocA $ UserTyVar noAnn () (noLocA (getName fakeTyVar))
+      | otherwise = noLocA $ KindedTyVar noAnn () (noLocA (getName fakeTyVar)) (synifyKindSig realKind)
+
+    conKind = defaultType prr (tyConKind tc)
+    tyVarKinds = fst . splitFunTys . snd . splitInvisPiTys $ conKind
+
+synifyTyCon _prr _coax tc
+  | Just flav <- famTyConFlav_maybe tc
+  = case flav of
+      -- Type families
+      OpenSynFamilyTyCon -> mkFamDecl OpenTypeFamily
+      ClosedSynFamilyTyCon mb
+        | Just (CoAxiom { co_ax_branches = branches }) <- mb
+          -> mkFamDecl $ ClosedTypeFamily $ Just
+            $ map (noLocA . synifyAxBranch tc) (fromBranches branches)
+        | otherwise
+          -> mkFamDecl $ ClosedTypeFamily $ Just []
+      BuiltInSynFamTyCon {}
+        -> mkFamDecl $ ClosedTypeFamily $ Just []
+      AbstractClosedSynFamilyTyCon {}
+        -> mkFamDecl $ ClosedTypeFamily Nothing
+      DataFamilyTyCon {}
+        -> mkFamDecl DataFamily
+  where
+    resultVar = tyConFamilyResVar_maybe tc
+    mkFamDecl i = return $ FamDecl noExtField $
+      FamilyDecl { fdExt = noAnn
+                 , fdInfo = i
+                 , fdTopLevel = TopLevel
+                 , fdLName = synifyNameN tc
+                 , fdTyVars = synifyTyVars (tyConVisibleTyVars tc)
+                 , fdFixity = synifyFixity tc
+                 , fdResultSig =
+                       synifyFamilyResultSig resultVar (tyConResKind tc)
+                 , fdInjectivityAnn =
+                       synifyInjectivityAnn  resultVar (tyConTyVars tc)
+                                       (tyConInjectivityInfo tc)
+                 }
+
+synifyTyCon _prr coax tc
+  | Just ty <- synTyConRhs_maybe tc
+  = return $ SynDecl { tcdSExt   = emptyNameSet
+                     , tcdLName  = synifyNameN tc
+                     , tcdTyVars = synifyTyVars (tyConVisibleTyVars tc)
+                     , tcdFixity = synifyFixity tc
+                     , tcdRhs = synifyType WithinType [] ty }
+  | otherwise = do
+  -- (closed) newtype and data
+  let alg_ctx = synifyCtx (tyConStupidTheta tc)
+      name = case coax of
+        Just a -> synifyNameN a -- Data families are named according to their
+                           -- CoAxioms, not their TyCons
+        _ -> synifyNameN tc
+      tyvars = synifyTyVars (tyConVisibleTyVars tc)
+      kindSig = synifyDataTyConReturnKind tc
+      -- The data constructors.
+      --
+      -- Any data-constructors not exported from the module that *defines* the
+      -- type will not (cannot) be included.
+      --
+      -- Very simple constructors, Haskell98 with no existentials or anything,
+      -- probably look nicer in non-GADT syntax.  In source code, all constructors
+      -- must be declared with the same (GADT vs. not) syntax, and it probably
+      -- is less confusing to follow that principle for the documentation as well.
+      --
+      -- There is no sensible infix-representation for GADT-syntax constructor
+      -- declarations.  They cannot be made in source code, but we could end up
+      -- with some here in the case where some constructors use existentials.
+      -- That seems like an acceptable compromise (they'll just be documented
+      -- in prefix position), since, otherwise, the logic (at best) gets much more
+      -- complicated. (would use dataConIsInfix.)
+      use_gadt_syntax = isGadtSyntaxTyCon tc
+  consRaw <- case partitionEithers $ synifyDataCon use_gadt_syntax <$> tyConDataCons tc of
+      ([], consRaw) -> Right consRaw
+      (errs, _) -> Left (unlines errs)
+  cons <- case (isNewTyCon tc, consRaw) of
+      (False, cons) -> Right (DataTypeCons False cons)
+      (True, [con]) -> Right (NewTypeCon con)
+      (True, _) -> Left "Newtype hasn't 1 constructor"
+
+  let -- "deriving" doesn't affect the signature, no need to specify any.
+      alg_deriv = []
+      defn = HsDataDefn { dd_ext     = noExtField
+                    , dd_ctxt    = Just alg_ctx
+                    , dd_cType   = Nothing
+                    , dd_kindSig = kindSig
+                    , dd_cons    = cons
+                    , dd_derivs  = alg_deriv }
+  pure  DataDecl { tcdLName = name, tcdTyVars = tyvars
+                 , tcdFixity = synifyFixity name
+                 , tcdDataDefn = defn
+                 , tcdDExt = DataDeclRn False emptyNameSet }
+
+-- | In this module, every TyCon being considered has come from an interface
+-- file. This means that when considering a data type constructor such as:
+--
+-- > data Foo (w :: *) (m :: * -> *) (a :: *)
+--
+-- Then its tyConKind will be (* -> (* -> *) -> * -> *). But beware! We are
+-- also rendering the type variables of Foo, so if we synify the tyConKind of
+-- Foo in full, we will end up displaying this in Haddock:
+--
+-- > data Foo (w :: *) (m :: * -> *) (a :: *)
+-- >   :: * -> (* -> *) -> * -> *
+--
+-- Which is entirely wrong (#548). We only want to display the /return/ kind,
+-- which this function obtains.
+synifyDataTyConReturnKind :: TyCon -> Maybe (LHsKind GhcRn)
+synifyDataTyConReturnKind tc
+  | isLiftedTypeKind ret_kind = Nothing -- Don't bother displaying :: *
+  | otherwise                 = Just (synifyKindSig ret_kind)
+  where ret_kind = tyConResKind tc
+
+synifyInjectivityAnn :: Maybe Name -> [TyVar] -> Injectivity
+                     -> Maybe (LInjectivityAnn GhcRn)
+synifyInjectivityAnn Nothing _ _            = Nothing
+synifyInjectivityAnn _       _ NotInjective = Nothing
+synifyInjectivityAnn (Just lhs) tvs (Injective inj) =
+    let rhs = map (noLocA . tyVarName) (filterByList inj tvs)
+    in Just $ noLocA $ InjectivityAnn noAnn (noLocA lhs) rhs
+
+synifyFamilyResultSig :: Maybe Name -> Kind -> LFamilyResultSig GhcRn
+synifyFamilyResultSig  Nothing    kind
+   | isLiftedTypeKind kind = noLocA $ NoSig noExtField
+   | otherwise = noLocA $ KindSig  noExtField (synifyKindSig kind)
+synifyFamilyResultSig (Just name) kind =
+   noLocA $ TyVarSig noExtField (noLocA $ KindedTyVar noAnn () (noLocA name) (synifyKindSig kind))
+
+-- User beware: it is your responsibility to pass True (use_gadt_syntax)
+-- for any constructor that would be misrepresented by omitting its
+-- result-type.
+-- But you might want pass False in simple enough cases,
+-- if you think it looks better.
+synifyDataCon :: Bool -> DataCon -> Either String (LConDecl GhcRn)
+synifyDataCon use_gadt_syntax dc =
+ let
+  -- dataConIsInfix allegedly tells us whether it was declared with
+  -- infix *syntax*.
+  use_infix_syntax = dataConIsInfix dc
+  use_named_field_syntax = not (null field_tys)
+  name = synifyNameN dc
+  -- con_qvars means a different thing depending on gadt-syntax
+  (_univ_tvs, ex_tvs, _eq_spec, theta, arg_tys, res_ty) = dataConFullSig dc
+  user_tvbndrs = dataConUserTyVarBinders dc -- Used for GADT data constructors
+
+  outer_bndrs | null user_tvbndrs
+              = HsOuterImplicit { hso_ximplicit = [] }
+              | otherwise
+              = HsOuterExplicit { hso_xexplicit = noExtField
+                                , hso_bndrs = map synifyTyVarBndr user_tvbndrs }
+
+  -- skip any EqTheta, use 'orig'inal syntax
+  ctx | null theta = Nothing
+      | otherwise = Just $ synifyCtx theta
+
+  linear_tys =
+    zipWith (\ty bang ->
+               let tySyn = synifyType WithinType [] (scaledThing ty)
+               in case bang of
+                    (HsSrcBang _ NoSrcUnpack NoSrcStrict) -> tySyn
+                    bang' -> noLocA $ HsBangTy noAnn bang' tySyn)
+            arg_tys (dataConSrcBangs dc)
+
+  field_tys = zipWith con_decl_field (dataConFieldLabels dc) linear_tys
+  con_decl_field fl synTy = noLocA $
+    ConDeclField noAnn [noLocA $ FieldOcc (flSelector fl) (noLocA $ mkVarUnqual $ field_label $ flLabel fl)] synTy
+                 Nothing
+
+  mk_h98_arg_tys :: Either String (HsConDeclH98Details GhcRn)
+  mk_h98_arg_tys = case (use_named_field_syntax, use_infix_syntax) of
+    (True,True) -> Left "synifyDataCon: contradiction!"
+    (True,False) -> return $ RecCon (noLocA field_tys)
+    (False,False) -> return $ PrefixCon noTypeArgs (map hsUnrestricted linear_tys)
+    (False,True) -> case linear_tys of
+                     [a,b] -> return $ InfixCon (hsUnrestricted a) (hsUnrestricted b)
+                     _ -> Left "synifyDataCon: infix with non-2 args?"
+
+  mk_gadt_arg_tys :: HsConDeclGADTDetails GhcRn
+  mk_gadt_arg_tys
+    | use_named_field_syntax = RecConGADT (noLocA field_tys) noHsUniTok
+    | otherwise              = PrefixConGADT (map hsUnrestricted linear_tys)
+
+ -- finally we get synifyDataCon's result!
+ in if use_gadt_syntax
+       then do
+         let hat = mk_gadt_arg_tys
+         return $ noLocA $ ConDeclGADT
+           { con_g_ext  = noAnn
+           , con_names  = pure name
+           , con_dcolon = noHsUniTok
+           , con_bndrs  = noLocA outer_bndrs
+           , con_mb_cxt = ctx
+           , con_g_args = hat
+           , con_res_ty = synifyType WithinType [] res_ty
+           , con_doc    = Nothing }
+       else do
+         hat <- mk_h98_arg_tys
+         return $ noLocA $ ConDeclH98
+           { con_ext    = noAnn
+           , con_name   = name
+           , con_forall = False
+           , con_ex_tvs = map (synifyTyVarBndr . (mkForAllTyBinder InferredSpec)) ex_tvs
+           , con_mb_cxt = ctx
+           , con_args   = hat
+           , con_doc    = Nothing }
+
+synifyNameN :: NamedThing n => n -> LocatedN Name
+synifyNameN n = L (noAnnSrcSpan $ srcLocSpan (getSrcLoc n)) (getName n)
+
+-- synifyName :: NamedThing n => n -> LocatedA Name
+-- synifyName n = L (noAnnSrcSpan $ srcLocSpan (getSrcLoc n)) (getName n)
+
+-- | Guess the fixity of a something with a name. This isn't quite right, since
+-- a user can always declare an infix name in prefix form or a prefix name in
+-- infix form. Unfortunately, that is not something we can usually reconstruct.
+synifyFixity :: NamedThing n => n -> LexicalFixity
+synifyFixity n | isSymOcc (getOccName n) = Infix
+               | otherwise = Prefix
+
+synifyIdSig
+  :: PrintRuntimeReps -- ^ are we printing tyvars of kind 'RuntimeRep'?
+  -> SynifyTypeState  -- ^ what to do with a 'forall'
+  -> [TyVar]          -- ^ free variables in the type to convert
+  -> Id               -- ^ the 'Id' from which to get the type signature
+  -> Sig GhcRn
+synifyIdSig prr s vs i = TypeSig noAnn [n] (synifySigWcType s vs t)
+  where
+    !n = force $ synifyNameN i
+    t = defaultType prr (varType i)
+
+-- | Turn a 'ClassOpItem' into a list of signatures. The list returned is going
+-- to contain the synified 'ClassOpSig' as well (when appropriate) a default
+-- 'ClassOpSig'.
+synifyTcIdSig :: [TyVar] -> ClassOpItem -> [Sig GhcRn]
+synifyTcIdSig vs (i, dm) =
+  [ ClassOpSig noAnn False [synifyNameN i] (mainSig (varType i)) ] ++
+  [ ClassOpSig noAnn True [noLocA dn] (defSig dt)
+  | Just (dn, GenericDM dt) <- [dm] ]
+  where
+    mainSig t = synifySigType DeleteTopLevelQuantification vs t
+    defSig t = synifySigType ImplicitizeForAll vs t
+
+synifyCtx :: [PredType] -> LHsContext GhcRn
+synifyCtx ts = noLocA ( map (synifyType WithinType []) ts)
+
+
+synifyTyVars :: [TyVar] -> LHsQTyVars GhcRn
+synifyTyVars ktvs = HsQTvs { hsq_ext = []
+                           , hsq_explicit = map synifyTyVar ktvs }
+
+synifyTyVar :: TyVar -> LHsTyVarBndr () GhcRn
+synifyTyVar = synify_ty_var emptyVarSet ()
+
+synifyTyVarBndr :: VarBndr TyVar flag -> LHsTyVarBndr flag GhcRn
+synifyTyVarBndr = synifyTyVarBndr' emptyVarSet
+
+synifyTyVarBndr' :: VarSet -> VarBndr TyVar flag -> LHsTyVarBndr flag GhcRn
+synifyTyVarBndr' no_kinds (Bndr tv spec) = synify_ty_var no_kinds spec tv
+
+-- | Like 'synifyTyVarBndr', but accepts a set of variables for which to omit kind
+-- signatures (even if they don't have the lifted type kind).
+synify_ty_var :: VarSet -> flag -> TyVar -> LHsTyVarBndr flag GhcRn
+synify_ty_var no_kinds flag tv
+  | isLiftedTypeKind kind || tv `elemVarSet` no_kinds
+  = noLocA (UserTyVar noAnn flag (noLocA name))
+  | otherwise = noLocA (KindedTyVar noAnn flag (noLocA name) (synifyKindSig kind))
+  where
+    kind = tyVarKind tv
+    name = getName tv
+
+-- | Annotate (with HsKingSig) a type if the first parameter is True
+-- and if the type contains a free variable.
+-- This is used to synify type patterns for poly-kinded tyvars in
+-- synifying class and type instances.
+annotHsType :: Bool   -- True <=> annotate
+            -> Type -> LHsType GhcRn -> LHsType GhcRn
+  -- tiny optimization: if the type is annotated, don't annotate again.
+annotHsType _    _  hs_ty@(L _ (HsKindSig {})) = hs_ty
+annotHsType True ty hs_ty
+  | not $ isEmptyVarSet $ filterVarSet isTyVar $ tyCoVarsOfType ty
+  = let ki    = typeKind ty
+        hs_ki = synifyType WithinType [] ki
+    in noLocA (HsKindSig noAnn hs_ty hs_ki)
+annotHsType _    _ hs_ty = hs_ty
+
+-- | For every argument type that a type constructor accepts,
+-- report whether or not the argument is poly-kinded. This is used to
+-- eventually feed into 'annotThType'.
+tyConArgsPolyKinded :: TyCon -> [Bool]
+tyConArgsPolyKinded tc =
+     map (is_poly_ty . tyVarKind)      tc_vis_tvs
+  ++ map (is_poly_ty . piTyBinderType) tc_res_kind_vis_bndrs
+  ++ repeat True
+  where
+    is_poly_ty :: Type -> Bool
+    is_poly_ty ty = not $
+                    isEmptyVarSet $
+                    filterVarSet isTyVar $
+                    tyCoVarsOfType ty
+
+    tc_vis_tvs :: [TyVar]
+    tc_vis_tvs = tyConVisibleTyVars tc
+
+    tc_res_kind_vis_bndrs :: [PiTyBinder]
+    tc_res_kind_vis_bndrs = filter isVisiblePiTyBinder $ fst $ splitPiTys $ tyConResKind tc
+
+--states of what to do with foralls:
+data SynifyTypeState
+  = WithinType
+  -- ^ normal situation.  This is the safe one to use if you don't
+  -- quite understand what's going on.
+  | ImplicitizeForAll
+  -- ^ beginning of a function definition, in which, to make it look
+  --   less ugly, those rank-1 foralls (without kind annotations) are made
+  --   implicit.
+  | DeleteTopLevelQuantification
+  -- ^ because in class methods the context is added to the type
+  --   (e.g. adding @forall a. Num a =>@ to @(+) :: a -> a -> a@)
+  --   which is rather sensible,
+  --   but we want to restore things to the source-syntax situation where
+  --   the defining class gets to quantify all its functions for free!
+
+
+synifySigType :: SynifyTypeState -> [TyVar] -> Type -> LHsSigType GhcRn
+-- The use of mkEmptySigType (which uses empty binders in OuterImplicit)
+-- is a bit suspicious; what if the type has free variables?
+synifySigType s vs ty = mkEmptySigType (synifyType s vs ty)
+
+synifySigWcType :: SynifyTypeState -> [TyVar] -> Type -> LHsSigWcType GhcRn
+-- Ditto (see synifySigType)
+synifySigWcType s vs ty = mkEmptyWildCardBndrs (mkEmptySigType (synifyType s vs ty))
+
+synifyPatSynSigType :: PatSyn -> LHsSigType GhcRn
+-- Ditto (see synifySigType)
+synifyPatSynSigType ps = mkEmptySigType (synifyPatSynType ps)
+
+-- | Depending on the first argument, try to default all type variables of kind
+-- 'RuntimeRep' to 'LiftedType'.
+defaultType :: PrintRuntimeReps -> Type -> Type
+defaultType ShowRuntimeRep = id
+defaultType HideRuntimeRep = defaultRuntimeRepVars
+
+-- | Convert a core type into an 'HsType'.
+synifyType
+  :: SynifyTypeState  -- ^ what to do with a 'forall'
+  -> [TyVar]          -- ^ free variables in the type to convert
+  -> Type             -- ^ the type to convert
+  -> LHsType GhcRn
+synifyType _ _ (TyVarTy tv) = noLocA $ HsTyVar noAnn NotPromoted $ noLocA (getName tv)
+synifyType _ vs (TyConApp tc tys)
+  = maybe_sig res_ty
+  where
+    res_ty :: LHsType GhcRn
+    res_ty
+      -- Use */# instead of TYPE 'Lifted/TYPE 'Unlifted (#473)
+      | tc `hasKey` tYPETyConKey
+      , [TyConApp rep [TyConApp lev []]] <- tys
+      , rep `hasKey` boxedRepDataConKey
+      , lev `hasKey` liftedDataConKey
+      = noLocA (HsTyVar noAnn NotPromoted (noLocA liftedTypeKindTyConName))
+      -- Use non-prefix tuple syntax where possible, because it looks nicer.
+      | Just sort <- tyConTuple_maybe tc
+      , tyConArity tc == tys_len
+      = noLocA $ HsTupleTy noAnn
+                          (case sort of
+                              BoxedTuple      -> HsBoxedOrConstraintTuple
+                              ConstraintTuple -> HsBoxedOrConstraintTuple
+                              UnboxedTuple    -> HsUnboxedTuple)
+                           (map (synifyType WithinType vs) vis_tys)
+      | isUnboxedSumTyCon tc = noLocA $ HsSumTy noAnn (map (synifyType WithinType vs) vis_tys)
+      | Just dc <- isPromotedDataCon_maybe tc
+      , isTupleDataCon dc
+      , dataConSourceArity dc == length vis_tys
+      = noLocA $ HsExplicitTupleTy noExtField (map (synifyType WithinType vs) vis_tys)
+      -- ditto for lists
+      | getName tc == listTyConName, [ty] <- vis_tys =
+         noLocA $ HsListTy noAnn (synifyType WithinType vs ty)
+      | tc == promotedNilDataCon, [] <- vis_tys
+      = noLocA $ HsExplicitListTy noExtField IsPromoted []
+      | tc == promotedConsDataCon
+      , [ty1, ty2] <- vis_tys
+      = let hTy = synifyType WithinType vs ty1
+        in case synifyType WithinType vs ty2 of
+             tTy | L _ (HsExplicitListTy _ IsPromoted tTy') <- stripKindSig tTy
+                 -> noLocA $ HsExplicitListTy noExtField IsPromoted (hTy : tTy')
+                 | otherwise
+                 -> noLocA $ HsOpTy noAnn IsPromoted hTy (noLocA $ getName tc) tTy
+      -- ditto for implicit parameter tycons
+      | tc `hasKey` ipClassKey
+      , [name, ty] <- tys
+      , Just x <- isStrLitTy name
+      = noLocA $ HsIParamTy noAnn (noLocA $ HsIPName x) (synifyType WithinType vs ty)
+      -- and equalities
+      | tc `hasKey` eqTyConKey
+      , [ty1, ty2] <- tys
+      = noLocA $ HsOpTy noAnn
+                       NotPromoted
+                       (synifyType WithinType vs ty1)
+                       (noLocA eqTyConName)
+                       (synifyType WithinType vs ty2)
+      -- and infix type operators
+      | isSymOcc (nameOccName (getName tc))
+      , ty1:ty2:tys_rest <- vis_tys
+      = mk_app_tys (HsOpTy noAnn
+                           prom
+                           (synifyType WithinType vs ty1)
+                           (noLocA $ getName tc)
+                           (synifyType WithinType vs ty2))
+                   tys_rest
+      -- Most TyCons:
+      | otherwise
+      = mk_app_tys (HsTyVar noAnn prom $ noLocA (getName tc))
+                   vis_tys
+      where
+        !prom = if isPromotedDataCon tc then IsPromoted else NotPromoted
+        mk_app_tys ty_app ty_args =
+          foldl (\t1 t2 -> noLocA $ HsAppTy noExtField t1 t2)
+                (noLocA ty_app)
+                (map (synifyType WithinType vs) $
+                 filterOut isCoercionTy ty_args)
+
+    tys_len = length tys
+    vis_tys = filterOutInvisibleTypes tc tys
+
+    maybe_sig :: LHsType GhcRn -> LHsType GhcRn
+    maybe_sig ty'
+      | tyConAppNeedsKindSig False tc tys_len
+      = let full_kind  = typeKind (mkTyConApp tc tys)
+            full_kind' = synifyType WithinType vs full_kind
+        in noLocA $ HsKindSig noAnn ty' full_kind'
+      | otherwise = ty'
+
+synifyType _ vs ty@(AppTy {}) = let
+  (ty_head, ty_args) = splitAppTys ty
+  ty_head' = synifyType WithinType vs ty_head
+  ty_args' = map (synifyType WithinType vs) $
+             filterOut isCoercionTy $
+             filterByList (map isVisibleForAllTyFlag $ appTyForAllTyFlags ty_head ty_args)
+                          ty_args
+  in foldl (\t1 t2 -> noLocA $ HsAppTy noExtField t1 t2) ty_head' ty_args'
+
+synifyType s vs funty@(FunTy af w t1 t2)
+  | isInvisibleFunArg af = synifySigmaType s vs funty
+  | otherwise            = noLocA $ HsFunTy noAnn w' s1 s2
+  where
+    s1 = synifyType WithinType vs t1
+    s2 = synifyType WithinType vs t2
+    w' = synifyMult vs w
+
+synifyType s vs forallty@(ForAllTy (Bndr _ argf) _ty) =
+  case argf of
+    Required    -> synifyVisForAllType vs forallty
+    Invisible _ -> synifySigmaType s vs forallty
+
+synifyType _ _ (LitTy t) = noLocA $ HsTyLit noExtField $ synifyTyLit t
+synifyType s vs (CastTy t _) = synifyType s vs t
+synifyType _ _ (CoercionTy {}) = error "synifyType:Coercion"
+
+-- | Process a 'Type' which starts with a visible @forall@ into an 'HsType'
+synifyVisForAllType
+  :: [TyVar]          -- ^ free variables in the type to convert
+  -> Type             -- ^ the forall type to convert
+  -> LHsType GhcRn
+synifyVisForAllType vs ty =
+  let (tvs, rho) = tcSplitForAllTysReqPreserveSynonyms ty
+
+      sTvs = map synifyTyVarBndr tvs
+
+      -- Figure out what the type variable order would be inferred in the
+      -- absence of an explicit forall
+      tvs' = orderedFVs (mkVarSet vs) [rho]
+
+  in noLocA $ HsForAllTy { hst_tele    = mkHsForAllVisTele noAnn sTvs
+                         , hst_xforall = noExtField
+                         , hst_body    = synifyType WithinType (tvs' ++ vs) rho }
+
+-- | Process a 'Type' which starts with an invisible @forall@ or a constraint
+-- into an 'HsType'
+synifySigmaType
+  :: SynifyTypeState  -- ^ what to do with the 'forall'
+  -> [TyVar]          -- ^ free variables in the type to convert
+  -> Type             -- ^ the forall type to convert
+  -> LHsType GhcRn
+synifySigmaType s vs ty =
+  let (tvs, ctx, tau) = tcSplitSigmaTyPreserveSynonyms ty
+      sPhi = HsQualTy { hst_ctxt = synifyCtx ctx
+                      , hst_xqual = noExtField
+                      , hst_body = synifyType WithinType (tvs' ++ vs) tau }
+
+      sTy = HsForAllTy { hst_tele = mkHsForAllInvisTele noAnn sTvs
+                       , hst_xforall = noExtField
+                       , hst_body  = noLocA sPhi }
+
+      sTvs = map synifyTyVarBndr tvs
+
+      -- Figure out what the type variable order would be inferred in the
+      -- absence of an explicit forall
+      tvs' = orderedFVs (mkVarSet vs) (ctx ++ [tau])
+
+  in case s of
+    DeleteTopLevelQuantification -> synifyType ImplicitizeForAll (tvs' ++ vs) tau
+
+    -- Put a forall in if there are any type variables
+    WithinType
+      | not (null tvs) -> noLocA sTy
+      | otherwise -> noLocA sPhi
+
+    ImplicitizeForAll -> implicitForAll [] vs tvs ctx (synifyType WithinType) tau
+
+-- | Put a forall in if there are any type variables which require
+-- explicit kind annotations or if the inferred type variable order
+-- would be different.
+implicitForAll
+  :: [TyCon]          -- ^ type constructors that determine their args kinds
+  -> [TyVar]          -- ^ free variables in the type to convert
+  -> [InvisTVBinder]  -- ^ type variable binders in the forall
+  -> ThetaType        -- ^ constraints right after the forall
+  -> ([TyVar] -> Type -> LHsType GhcRn) -- ^ how to convert the inner type
+  -> Type             -- ^ inner type
+  -> LHsType GhcRn
+implicitForAll tycons vs tvs ctx synInner tau
+  | any (isHsKindedTyVar . unLoc) sTvs = noLocA sTy
+  | tvs' /= (binderVars tvs)           = noLocA sTy
+  | otherwise                          = noLocA sPhi
+  where
+  sRho = synInner (tvs' ++ vs) tau
+  sPhi | null ctx = unLoc sRho
+       | otherwise
+       = HsQualTy { hst_ctxt = synifyCtx ctx
+                  , hst_xqual = noExtField
+                  , hst_body = synInner (tvs' ++ vs) tau }
+  sTy = HsForAllTy { hst_tele = mkHsForAllInvisTele noAnn sTvs
+                   , hst_xforall = noExtField
+                   , hst_body = noLocA sPhi }
+
+  no_kinds_needed = noKindTyVars tycons tau
+  sTvs = map (synifyTyVarBndr' no_kinds_needed) tvs
+
+  -- Figure out what the type variable order would be inferred in the
+  -- absence of an explicit forall
+  tvs' = orderedFVs (mkVarSet vs) (ctx ++ [tau])
+
+
+
+-- | Find the set of type variables whose kind signatures can be properly
+-- inferred just from their uses in the type signature. This means the type
+-- variable to has at least one fully applied use @f x1 x2 ... xn@ where:
+--
+--   * @f@ has a function kind where the arguments have the same kinds
+--     as @x1 x2 ... xn@.
+--
+--   * @f@ has a function kind whose final return has lifted type kind
+--
+noKindTyVars
+  :: [TyCon]  -- ^ type constructors that determine their args kinds
+  -> Type     -- ^ type to inspect
+  -> VarSet   -- ^ set of variables whose kinds can be inferred from uses in the type
+noKindTyVars _ (TyVarTy var)
+  | isLiftedTypeKind (tyVarKind var) = unitVarSet var
+noKindTyVars ts ty
+  | (f, xs) <- splitAppTys ty
+  , not (null xs)
+  = let args = map (noKindTyVars ts) xs
+        func = case f of
+                 TyVarTy var | (xsKinds, outKind) <- splitFunTys (tyVarKind var)
+                             , map scaledThing xsKinds `eqTypes` map typeKind xs
+                             , isLiftedTypeKind outKind
+                             -> unitVarSet var
+                 TyConApp t ks | t `elem` ts
+                               , all noFreeVarsOfType ks
+                               -> mkVarSet [ v | TyVarTy v <- xs ]
+                 _ -> noKindTyVars ts f
+    in unionVarSets (func : args)
+noKindTyVars ts (ForAllTy _ t) = noKindTyVars ts t
+noKindTyVars ts (FunTy _ w t1 t2) = noKindTyVars ts w `unionVarSet`
+                                    noKindTyVars ts t1 `unionVarSet`
+                                    noKindTyVars ts t2
+noKindTyVars ts (CastTy t _) = noKindTyVars ts t
+noKindTyVars _ _ = emptyVarSet
+
+synifyMult :: [TyVar] -> Mult -> HsArrow GhcRn
+synifyMult vs t = case t of
+                    OneTy  -> HsLinearArrow (HsPct1 noHsTok noHsUniTok)
+                    ManyTy -> HsUnrestrictedArrow noHsUniTok
+                    ty -> HsExplicitMult noHsTok (synifyType WithinType vs ty) noHsUniTok
+
+
+
+synifyPatSynType :: PatSyn -> LHsType GhcRn
+synifyPatSynType ps =
+  let (univ_tvs, req_theta, ex_tvs, prov_theta, arg_tys, res_ty) = patSynSigBndr ps
+      ts = maybeToList (tyConAppTyCon_maybe res_ty)
+
+      -- HACK: a HsQualTy with theta = [unitTy] will be printed as "() =>",
+      -- i.e., an explicit empty context, which is what we need. This is not
+      -- possible by taking theta = [], as that will print no context at all
+      req_theta' | null req_theta
+                 , not (null prov_theta && null ex_tvs)
+                 = [unitTy]
+                 | otherwise = req_theta
+
+  in implicitForAll ts [] (univ_tvs ++ ex_tvs) req_theta'
+       (\vs -> implicitForAll ts vs [] prov_theta (synifyType WithinType))
+       (mkScaledFunTys arg_tys res_ty)
+
+synifyTyLit :: TyLit -> HsTyLit GhcRn
+synifyTyLit (NumTyLit n) = HsNumTy NoSourceText n
+synifyTyLit (StrTyLit s) = HsStrTy NoSourceText s
+synifyTyLit (CharTyLit c) = HsCharTy NoSourceText c
+
+synifyKindSig :: Kind -> LHsKind GhcRn
+synifyKindSig k = synifyType WithinType [] k
+
+stripKindSig :: LHsType GhcRn -> LHsType GhcRn
+stripKindSig (L _ (HsKindSig _ t _)) = t
+stripKindSig t = t
+
+synifyInstHead :: ([TyVar], [PredType], Class, [Type]) -> InstHead GhcRn
+synifyInstHead (vs, preds, cls, types) = specializeInstHead $ InstHead
+    { ihdClsName = getName cls
+    , ihdTypes = map unLoc annot_ts
+    , ihdInstType = ClassInst
+        { clsiCtx = map (unLoc . synifyType WithinType []) preds
+        , clsiTyVars = synifyTyVars (tyConVisibleTyVars cls_tycon)
+        , clsiSigs = map synifyClsIdSig $ classMethods cls
+        , clsiAssocTys = do
+            (Right (FamDecl _ fam)) <- map (synifyTyCon HideRuntimeRep Nothing)
+                                           (classATs cls)
+            pure $ mkPseudoFamilyDecl fam
+        }
+    }
+  where
+    cls_tycon = classTyCon cls
+    ts  = filterOutInvisibleTypes cls_tycon types
+    ts' = map (synifyType WithinType vs) ts
+    annot_ts = zipWith3 annotHsType args_poly ts ts'
+    args_poly = tyConArgsPolyKinded cls_tycon
+    synifyClsIdSig = synifyIdSig ShowRuntimeRep DeleteTopLevelQuantification vs
+
+-- Convert a family instance, this could be a type family or data family
+synifyFamInst :: FamInst -> Bool -> Either String (InstHead GhcRn)
+synifyFamInst fi opaque = do
+    ityp' <- ityp fam_flavor
+    return InstHead
+        { ihdClsName = fi_fam fi
+        , ihdTypes = map unLoc annot_ts
+        , ihdInstType = ityp'
+        }
+  where
+    ityp SynFamilyInst | opaque = return $ TypeInst Nothing
+    ityp SynFamilyInst =
+        return . TypeInst . Just . unLoc $ synifyType WithinType [] fam_rhs
+    ityp (DataFamilyInst c) =
+        DataInst <$> synifyTyCon HideRuntimeRep (Just $ famInstAxiom fi) c
+    fam_tc     = famInstTyCon fi
+    fam_flavor = fi_flavor fi
+    fam_lhs    = fi_tys fi
+    fam_rhs    = fi_rhs fi
+
+    eta_expanded_lhs
+      -- eta-expand lhs types, because sometimes data/newtype
+      -- instances are eta-reduced; See Trac #9692
+      -- See Note [Eta reduction for data family axioms] in GHC.Tc.TyCl.Instance in GHC
+      | DataFamilyInst rep_tc <- fam_flavor
+      = let (_, rep_tc_args) = splitTyConApp fam_rhs
+            etad_tyvars      = dropList rep_tc_args $ tyConTyVars rep_tc
+            etad_tys         = mkTyVarTys etad_tyvars
+            eta_exp_lhs      = fam_lhs `chkAppend` etad_tys
+        in eta_exp_lhs
+      | otherwise
+      = fam_lhs
+
+    ts = filterOutInvisibleTypes fam_tc eta_expanded_lhs
+    synifyTypes = map (synifyType WithinType [])
+    ts' = synifyTypes ts
+    annot_ts = zipWith3 annotHsType args_poly ts ts'
+    args_poly = tyConArgsPolyKinded fam_tc
+
+{-
+Note [Invariant: Never expand type synonyms]
+
+In haddock, we never want to expand a type synonym that may be presented to the
+user, as we want to keep the link to the abstraction captured in the synonym.
+
+All code in Haddock.Convert must make sure that this invariant holds.
+
+See https://github.com/haskell/haddock/issues/879 for a bug where this
+invariant didn't hold.
+-}
+
+-- | A version of 'TcType.tcSplitSigmaTy' that:
+--
+-- 1. Preserves type synonyms.
+-- 2. Returns 'InvisTVBinder's instead of 'TyVar's.
+--
+-- See Note [Invariant: Never expand type synonyms]
+tcSplitSigmaTyPreserveSynonyms :: Type -> ([InvisTVBinder], ThetaType, Type)
+tcSplitSigmaTyPreserveSynonyms ty =
+    case tcSplitForAllTysInvisPreserveSynonyms ty of
+      (tvs, rho) -> case tcSplitPhiTyPreserveSynonyms rho of
+        (theta, tau) -> (tvs, theta, tau)
+
+-- | See Note [Invariant: Never expand type synonyms]
+tcSplitSomeForAllTysPreserveSynonyms ::
+  (ForAllTyFlag -> Bool) -> Type -> ([ForAllTyBinder], Type)
+tcSplitSomeForAllTysPreserveSynonyms argf_pred ty = split ty ty []
+  where
+    split _ (ForAllTy tvb@(Bndr _ argf) ty') tvs
+      | argf_pred argf  = split ty' ty' (tvb:tvs)
+    split orig_ty _ tvs = (reverse tvs, orig_ty)
+
+-- | See Note [Invariant: Never expand type synonyms]
+tcSplitForAllTysReqPreserveSynonyms :: Type -> ([ReqTVBinder], Type)
+tcSplitForAllTysReqPreserveSynonyms ty =
+  let (all_bndrs, body) = tcSplitSomeForAllTysPreserveSynonyms isVisibleForAllTyFlag ty
+      req_bndrs         = mapMaybe mk_req_bndr_maybe all_bndrs in
+  assert ( req_bndrs `equalLength` all_bndrs)
+    (req_bndrs, body)
+  where
+    mk_req_bndr_maybe :: ForAllTyBinder -> Maybe ReqTVBinder
+    mk_req_bndr_maybe (Bndr tv argf) = case argf of
+      Required    -> Just $ Bndr tv ()
+      Invisible _ -> Nothing
+
+-- | See Note [Invariant: Never expand type synonyms]
+tcSplitForAllTysInvisPreserveSynonyms :: Type -> ([InvisTVBinder], Type)
+tcSplitForAllTysInvisPreserveSynonyms ty =
+  let (all_bndrs, body) = tcSplitSomeForAllTysPreserveSynonyms isInvisibleForAllTyFlag ty
+      inv_bndrs         = mapMaybe mk_inv_bndr_maybe all_bndrs in
+  assert ( inv_bndrs `equalLength` all_bndrs)
+    (inv_bndrs, body)
+  where
+    mk_inv_bndr_maybe :: ForAllTyBinder -> Maybe InvisTVBinder
+    mk_inv_bndr_maybe (Bndr tv argf) = case argf of
+      Invisible s -> Just $ Bndr tv s
+      Required    -> Nothing
+
+-- | See Note [Invariant: Never expand type synonyms]
+
+-- | See Note [Invariant: Never expand type synonyms]
+tcSplitPhiTyPreserveSynonyms :: Type -> (ThetaType, Type)
+tcSplitPhiTyPreserveSynonyms ty0 = split ty0 []
+  where
+    split ty ts
+      = case tcSplitPredFunTyPreserveSynonyms_maybe ty of
+          Just (pred_, ty') -> split ty' (pred_:ts)
+          Nothing           -> (reverse ts, ty)
+
+-- | See Note [Invariant: Never expand type synonyms]
+tcSplitPredFunTyPreserveSynonyms_maybe :: Type -> Maybe (PredType, Type)
+tcSplitPredFunTyPreserveSynonyms_maybe (FunTy af _ arg res)
+  | isInvisibleFunArg af = Just (arg, res)
+tcSplitPredFunTyPreserveSynonyms_maybe _ = Nothing
diff --git a/haddock-api/src/Haddock/Doc.hs b/haddock-api/src/Haddock/Doc.hs
new file mode 100644
--- /dev/null
+++ b/haddock-api/src/Haddock/Doc.hs
@@ -0,0 +1,34 @@
+{-# OPTIONS_GHC -fno-warn-orphans #-}
+module Haddock.Doc ( module Documentation.Haddock.Doc
+                   , docCodeBlock
+                   , combineDocumentation
+                   ) where
+
+import Data.Maybe
+import Documentation.Haddock.Doc
+import Haddock.Types
+import Haddock.Utils (mkMeta)
+
+combineDocumentation :: Documentation name -> Maybe (MDoc name)
+combineDocumentation (Documentation Nothing Nothing) = Nothing
+combineDocumentation (Documentation mDoc mWarning)   =
+  Just (maybe emptyMetaDoc mkMeta mWarning
+        `metaDocAppend`
+        fromMaybe emptyMetaDoc mDoc)
+
+-- Drop trailing whitespace from @..@ code blocks.  Otherwise this:
+--
+--    -- @
+--    -- foo
+--    -- @
+--
+-- turns into (DocCodeBlock "\nfoo\n ") which when rendered in HTML
+-- gives an extra vertical space after the code block.  The single space
+-- on the final line seems to trigger the extra vertical space.
+--
+docCodeBlock :: DocH mod id -> DocH mod id
+docCodeBlock (DocString s)
+  = DocString (reverse $ dropWhile (`elem` " \t") $ reverse s)
+docCodeBlock (DocAppend l r)
+  = DocAppend l (docCodeBlock r)
+docCodeBlock d = d
diff --git a/haddock-api/src/Haddock/GhcUtils.hs b/haddock-api/src/Haddock/GhcUtils.hs
new file mode 100644
--- /dev/null
+++ b/haddock-api/src/Haddock/GhcUtils.hs
@@ -0,0 +1,777 @@
+{-# LANGUAGE BangPatterns, FlexibleInstances #-}
+{-# LANGUAGE TypeFamilies #-}
+{-# LANGUAGE TypeOperators #-}
+{-# LANGUAGE RankNTypes #-}
+{-# LANGUAGE TypeApplications #-}
+{-# LANGUAGE ScopedTypeVariables #-}
+{-# LANGUAGE FlexibleContexts #-}
+{-# LANGUAGE LambdaCase #-}
+{-# LANGUAGE MonadComprehensions #-}
+{-# OPTIONS_GHC -fno-warn-orphans #-}
+{-# OPTIONS_GHC -Wno-incomplete-record-updates #-}
+{-# OPTIONS_HADDOCK hide #-}
+-----------------------------------------------------------------------------
+-- |
+-- Module      :  Haddock.GhcUtils
+-- Copyright   :  (c) David Waern 2006-2009
+-- License     :  BSD-like
+--
+-- Maintainer  :  haddock@projects.haskell.org
+-- Stability   :  experimental
+-- Portability :  portable
+--
+-- Utils for dealing with types from the GHC API
+-----------------------------------------------------------------------------
+module Haddock.GhcUtils where
+
+
+import Control.Arrow
+import Data.Char ( isSpace )
+import Data.Foldable ( toList, foldl' )
+import Data.List.NonEmpty ( NonEmpty )
+import Data.Maybe ( mapMaybe, fromMaybe )
+import qualified Data.Set as Set
+
+import Haddock.Types( DocName, DocNameI, XRecCond )
+
+import GHC.Utils.FV as FV
+import GHC.Utils.Outputable ( Outputable )
+import GHC.Utils.Panic ( panic )
+import GHC.Driver.Ppr (showPpr )
+import GHC.Types.Name
+import GHC.Unit.Module
+import GHC
+import GHC.Driver.Session
+import GHC.Types.SrcLoc  ( advanceSrcLoc )
+import GHC.Types.Var     ( Specificity, VarBndr(..), TyVarBinder
+                         , tyVarKind, updateTyVarKind, isInvisibleForAllTyFlag )
+import GHC.Types.Var.Set ( VarSet, emptyVarSet )
+import GHC.Types.Var.Env ( TyVarEnv, extendVarEnv, elemVarEnv, emptyVarEnv )
+import GHC.Core.TyCo.Rep ( Type(..) )
+import GHC.Core.Type     ( isRuntimeRepVar, binderVar )
+import GHC.Builtin.Types( liftedRepTy )
+
+import           GHC.Data.StringBuffer ( StringBuffer )
+import qualified GHC.Data.StringBuffer             as S
+
+import           Data.ByteString ( ByteString )
+import qualified Data.ByteString          as BS
+import qualified Data.ByteString.Internal as BS
+
+import GHC.HsToCore.Docs
+
+moduleString :: Module -> String
+moduleString = moduleNameString . moduleName
+
+isNameSym :: Name -> Bool
+isNameSym = isSymOcc . nameOccName
+
+-- Useful when there is a signature with multiple names, e.g.
+--   foo, bar :: Types..
+-- but only one of the names is exported and we have to change the
+-- type signature to only include the exported names.
+filterLSigNames :: (IdP (GhcPass p) -> Bool) -> LSig (GhcPass p) -> Maybe (LSig (GhcPass p))
+filterLSigNames p (L loc sig) = L loc <$> (filterSigNames p sig)
+
+filterSigNames :: (IdP (GhcPass p) -> Bool) -> Sig (GhcPass p) -> Maybe (Sig (GhcPass p))
+filterSigNames p orig@(SpecSig _ n _ _)          = ifTrueJust (p $ unLoc n) orig
+filterSigNames p orig@(InlineSig _ n _)          = ifTrueJust (p $ unLoc n) orig
+filterSigNames p (FixSig _ (FixitySig _ ns ty)) =
+  case filter (p . unLoc) ns of
+    []       -> Nothing
+    filtered -> Just (FixSig noAnn (FixitySig noExtField filtered ty))
+filterSigNames _ orig@(MinimalSig _ _)      = Just orig
+filterSigNames p (TypeSig _ ns ty) =
+  case filter (p . unLoc) ns of
+    []       -> Nothing
+    filtered -> Just (TypeSig noAnn filtered ty)
+filterSigNames p (ClassOpSig _ is_default ns ty) =
+  case filter (p . unLoc) ns of
+    []       -> Nothing
+    filtered -> Just (ClassOpSig noAnn is_default filtered ty)
+filterSigNames p (PatSynSig _ ns ty) =
+  case filter (p . unLoc) ns of
+    []       -> Nothing
+    filtered -> Just (PatSynSig noAnn filtered ty)
+filterSigNames _ _                             = Nothing
+
+ifTrueJust :: Bool -> name -> Maybe name
+ifTrueJust True  = Just
+ifTrueJust False = const Nothing
+
+sigName :: LSig GhcRn -> [IdP GhcRn]
+sigName (L _ sig) = sigNameNoLoc emptyOccEnv sig
+
+-- | Was this signature given by the user?
+isUserLSig :: forall p. UnXRec p => LSig p -> Bool
+isUserLSig = isUserSig . unXRec @p
+
+isClassD :: HsDecl a -> Bool
+isClassD (TyClD _ d) = isClassDecl d
+isClassD _ = False
+
+pretty :: Outputable a => DynFlags -> a -> String
+pretty = showPpr
+
+-- ---------------------------------------------------------------------
+
+-- These functions are duplicated from the GHC API, as they must be
+-- instantiated at DocNameI instead of (GhcPass _).
+
+-- | Like 'hsTyVarName' from GHC API, but not instantiated at (GhcPass _)
+hsTyVarBndrName :: forall flag n. (XXTyVarBndr n ~ DataConCantHappen, UnXRec n)
+                => HsTyVarBndr flag n -> IdP n
+hsTyVarBndrName (UserTyVar _ _ name) = unXRec @n name
+hsTyVarBndrName (KindedTyVar _ _ name _) = unXRec @n name
+
+hsTyVarNameI :: HsTyVarBndr flag DocNameI -> DocName
+hsTyVarNameI (UserTyVar _ _ (L _ n))     = n
+hsTyVarNameI (KindedTyVar _ _ (L _ n) _) = n
+
+hsLTyVarNameI :: LHsTyVarBndr flag DocNameI -> DocName
+hsLTyVarNameI = hsTyVarNameI . unLoc
+
+getConNamesI :: ConDecl DocNameI -> NonEmpty (LocatedN DocName)
+getConNamesI ConDeclH98  {con_name  = name}  = pure name
+getConNamesI ConDeclGADT {con_names = names} = names
+
+hsSigTypeI :: LHsSigType DocNameI -> LHsType DocNameI
+hsSigTypeI = sig_body . unLoc
+
+mkEmptySigType :: LHsType GhcRn -> LHsSigType GhcRn
+-- Dubious, because the implicit binders are empty even
+-- though the type might have free variables
+mkEmptySigType lty@(L loc ty) = L loc $ case ty of
+  HsForAllTy { hst_tele = HsForAllInvis { hsf_invis_bndrs = bndrs }
+             , hst_body = body }
+    -> HsSig { sig_ext = noExtField
+             , sig_bndrs = HsOuterExplicit { hso_xexplicit = noExtField
+                                           , hso_bndrs     = bndrs }
+             , sig_body = body }
+  _ -> HsSig { sig_ext   = noExtField
+             , sig_bndrs = HsOuterImplicit{hso_ximplicit = []}
+             , sig_body = lty }
+
+mkHsForAllInvisTeleI ::
+  [LHsTyVarBndr Specificity DocNameI] -> HsForAllTelescope DocNameI
+mkHsForAllInvisTeleI invis_bndrs =
+  HsForAllInvis { hsf_xinvis = noExtField, hsf_invis_bndrs = invis_bndrs }
+
+mkHsImplicitSigTypeI :: LHsType DocNameI -> HsSigType DocNameI
+mkHsImplicitSigTypeI body =
+  HsSig { sig_ext   = noExtField
+        , sig_bndrs = HsOuterImplicit{hso_ximplicit = noExtField}
+        , sig_body  = body }
+
+getGADTConType :: ConDecl DocNameI -> LHsSigType DocNameI
+-- The full type of a GADT data constructor We really only get this in
+-- order to pretty-print it, and currently only in Haddock's code.  So
+-- we are cavalier about locations and extensions, hence the
+-- 'undefined's
+getGADTConType (ConDeclGADT { con_bndrs = L _ outer_bndrs
+                            , con_mb_cxt = mcxt, con_g_args = args
+                            , con_res_ty = res_ty })
+ = noLocA (HsSig { sig_ext   = noExtField
+                 , sig_bndrs = outer_bndrs
+                 , sig_body  = theta_ty })
+ where
+   theta_ty | Just theta <- mcxt
+            = noLocA (HsQualTy { hst_xqual = noAnn, hst_ctxt = theta, hst_body = tau_ty })
+            | otherwise
+            = tau_ty
+
+--  tau_ty :: LHsType DocNameI
+   tau_ty = case args of
+              RecConGADT flds _ -> mkFunTy (noLocA (HsRecTy noAnn (unLoc flds))) res_ty
+              PrefixConGADT pos_args -> foldr mkFunTy res_ty (map hsScaledThing pos_args)
+
+   mkFunTy :: LHsType DocNameI -> LHsType DocNameI -> LHsType DocNameI
+   mkFunTy a b = noLocA (HsFunTy noAnn (HsUnrestrictedArrow noHsUniTok) a b)
+
+getGADTConType (ConDeclH98 {}) = panic "getGADTConType"
+  -- Should only be called on ConDeclGADT
+
+getMainDeclBinderI :: HsDecl DocNameI -> [IdP DocNameI]
+getMainDeclBinderI (TyClD _ d) = [tcdNameI d]
+getMainDeclBinderI (ValD _ d) =
+  case collectHsBindBinders CollNoDictBinders d of
+    []       -> []
+    (name:_) -> [name]
+getMainDeclBinderI (SigD _ d) = sigNameNoLoc emptyOccEnv d
+getMainDeclBinderI (ForD _ (ForeignImport _ name _ _)) = [unLoc name]
+getMainDeclBinderI (ForD _ (ForeignExport _ _ _ _)) = []
+getMainDeclBinderI _ = []
+
+familyDeclLNameI :: FamilyDecl DocNameI -> LocatedN DocName
+familyDeclLNameI (FamilyDecl { fdLName = n }) = n
+
+tyClDeclLNameI :: TyClDecl DocNameI -> LocatedN DocName
+tyClDeclLNameI (FamDecl { tcdFam = fd })     = familyDeclLNameI fd
+tyClDeclLNameI (SynDecl { tcdLName = ln })   = ln
+tyClDeclLNameI (DataDecl { tcdLName = ln })  = ln
+tyClDeclLNameI (ClassDecl { tcdLName = ln }) = ln
+
+tcdNameI :: TyClDecl DocNameI -> DocName
+tcdNameI = unLoc . tyClDeclLNameI
+
+addClassContext :: Name -> LHsQTyVars GhcRn -> LSig GhcRn -> LSig GhcRn
+-- Add the class context to a class-op signature
+addClassContext cls tvs0 (L pos (ClassOpSig _ _ lname ltype))
+  = L pos (TypeSig noAnn lname (mkEmptyWildCardBndrs (go_sig_ty ltype)))
+  where
+    go_sig_ty (L loc (HsSig { sig_bndrs = bndrs, sig_body = ty }))
+       = L loc (HsSig { sig_ext = noExtField
+                      , sig_bndrs = bndrs, sig_body = go_ty ty })
+
+    go_ty (L loc (HsForAllTy { hst_tele = tele, hst_body = ty }))
+       = L loc (HsForAllTy { hst_xforall = noExtField
+                           , hst_tele = tele, hst_body = go_ty ty })
+    go_ty (L loc (HsQualTy { hst_ctxt = ctxt, hst_body = ty }))
+       = L loc (HsQualTy { hst_xqual = noExtField
+                         , hst_ctxt = add_ctxt ctxt, hst_body = ty })
+    go_ty (L loc ty)
+       = L loc (HsQualTy { hst_xqual = noExtField
+                         , hst_ctxt = add_ctxt (noLocA []), hst_body = L loc ty })
+
+    extra_pred = nlHsTyConApp NotPromoted Prefix cls (lHsQTyVarsToTypes tvs0)
+
+    add_ctxt (L loc preds) = L loc (extra_pred : preds)
+
+addClassContext _ _ sig = sig   -- E.g. a MinimalSig is fine
+
+lHsQTyVarsToTypes :: LHsQTyVars GhcRn -> [LHsTypeArg GhcRn]
+lHsQTyVarsToTypes tvs
+  = [ HsValArg $ noLocA (HsTyVar noAnn NotPromoted (noLocA (hsLTyVarName tv)))
+    | tv <- hsQTvExplicit tvs ]
+
+
+--------------------------------------------------------------------------------
+-- * Making abstract declarations
+--------------------------------------------------------------------------------
+
+restrictTo :: [Name] -> LHsDecl GhcRn -> LHsDecl GhcRn
+restrictTo names (L loc decl) = L loc $ case decl of
+  TyClD x d | isDataDecl d  ->
+    TyClD x (d { tcdDataDefn = restrictDataDefn names (tcdDataDefn d) })
+  TyClD x d | isClassDecl d ->
+    TyClD x (d { tcdSigs = restrictDecls names (tcdSigs d),
+               tcdATs = restrictATs names (tcdATs d) })
+  _ -> decl
+
+restrictDataDefn :: [Name] -> HsDataDefn GhcRn -> HsDataDefn GhcRn
+restrictDataDefn names d = d { dd_cons = restrictDataDefnCons names (dd_cons d) }
+
+restrictDataDefnCons :: [Name] -> DataDefnCons (LConDecl GhcRn) -> DataDefnCons (LConDecl GhcRn)
+restrictDataDefnCons names = \ case
+    DataTypeCons is_type_data cons -> DataTypeCons is_type_data (restrictCons names cons)
+    NewTypeCon con -> maybe (DataTypeCons False []) NewTypeCon $ restrictCons names (Just con)
+
+restrictCons :: MonadFail m => [Name] -> m (LConDecl GhcRn) -> m (LConDecl GhcRn)
+restrictCons names decls = [ L p d | L p (Just d) <- fmap keep <$> decls ]
+  where
+    keep :: ConDecl GhcRn -> Maybe (ConDecl GhcRn)
+    keep d
+      | any (`elem` names) (unLoc <$> getConNames d) =
+        case d of
+          ConDeclH98 { con_args = con_args' } -> case con_args' of
+            PrefixCon {} -> Just d
+            RecCon fields
+              | all field_avail (unLoc fields) -> Just d
+              | otherwise -> Just (d { con_args = PrefixCon [] (field_types $ unLoc fields) })
+              -- if we have *all* the field names available, then
+              -- keep the record declaration.  Otherwise degrade to
+              -- a constructor declaration.  This isn't quite right, but
+              -- it's the best we can do.
+            InfixCon _ _ -> Just d
+
+          ConDeclGADT { con_g_args = con_args' } -> case con_args' of
+            PrefixConGADT {} -> Just d
+            RecConGADT fields _
+              | all field_avail (unLoc fields) -> Just d
+              | otherwise -> Just (d { con_g_args = PrefixConGADT (field_types $ unLoc fields) })
+              -- see above
+      where
+        field_avail :: LConDeclField GhcRn -> Bool
+        field_avail (L _ (ConDeclField _ fs _ _))
+            = all (\f -> foExt (unLoc f) `elem` names) fs
+
+        field_types flds = [ hsUnrestricted t | L _ (ConDeclField _ _ t _) <- flds ]
+
+    keep _ = Nothing
+
+restrictDecls :: [Name] -> [LSig GhcRn] -> [LSig GhcRn]
+restrictDecls names = mapMaybe (filterLSigNames (`elem` names))
+
+
+restrictATs :: [Name] -> [LFamilyDecl GhcRn] -> [LFamilyDecl GhcRn]
+restrictATs names ats = [ at | at <- ats , unLoc (fdLName (unLoc at)) `elem` names ]
+
+
+-------------------------------------------------------------------------------
+-- * Parenthesization
+-------------------------------------------------------------------------------
+
+-- | Precedence level (inside the 'HsType' AST).
+data Precedence
+  = PREC_TOP  -- ^ precedence of 'type' production in GHC's parser
+
+  | PREC_SIG  -- ^ explicit type signature
+
+  | PREC_CTX  -- ^ Used for single contexts, eg. ctx => type
+              -- (as opposed to (ctx1, ctx2) => type)
+
+  | PREC_FUN  -- ^ precedence of 'btype' production in GHC's parser
+              -- (used for LH arg of (->))
+
+  | PREC_OP   -- ^ arg of any infix operator
+              -- (we don't keep have fixity info)
+
+  | PREC_CON  -- ^ arg of type application: always parenthesize unless atomic
+  deriving (Eq, Ord)
+
+-- | Add in extra 'HsParTy' where needed to ensure that what would be printed
+-- out using 'ppr' has enough parentheses to be re-parsed properly.
+--
+-- We cannot add parens that may be required by fixities because we do not have
+-- any fixity information to work with in the first place :(.
+reparenTypePrec :: forall a. (XRecCond a)
+                => Precedence -> HsType a -> HsType a
+reparenTypePrec = go
+  where
+
+  -- Shorter name for 'reparenType'
+  go :: Precedence -> HsType a -> HsType a
+  go _ (HsBangTy x b ty)     = HsBangTy x b (reparenLType ty)
+  go _ (HsTupleTy x con tys) = HsTupleTy x con (map reparenLType tys)
+  go _ (HsSumTy x tys)       = HsSumTy x (map reparenLType tys)
+  go _ (HsListTy x ty)       = HsListTy x (reparenLType ty)
+  go _ (HsRecTy x flds)      = HsRecTy x (map (mapXRec @a reparenConDeclField) flds)
+  go p (HsDocTy x ty d)      = HsDocTy x (goL p ty) d
+  go _ (HsExplicitListTy x p tys) = HsExplicitListTy x p (map reparenLType tys)
+  go _ (HsExplicitTupleTy x tys) = HsExplicitTupleTy x (map reparenLType tys)
+  go p (HsKindSig x ty kind)
+    = paren p PREC_SIG $ HsKindSig x (goL PREC_SIG ty) (goL PREC_SIG kind)
+  go p (HsIParamTy x n ty)
+    = paren p PREC_SIG $ HsIParamTy x n (reparenLType ty)
+  go p (HsForAllTy x tele ty)
+    = paren p PREC_CTX $ HsForAllTy x (reparenHsForAllTelescope tele) (reparenLType ty)
+  go p (HsQualTy x ctxt ty)
+    = let p' [_] = PREC_CTX
+          p' _   = PREC_TOP -- parens will get added anyways later...
+          ctxt' = mapXRec @a (\xs -> map (goL (p' xs)) xs) ctxt
+      in paren p PREC_CTX $ HsQualTy x ctxt' (goL PREC_TOP ty)
+  go p (HsFunTy x w ty1 ty2)
+    = paren p PREC_FUN $ HsFunTy x w (goL PREC_FUN ty1) (goL PREC_TOP ty2)
+  go p (HsAppTy x fun_ty arg_ty)
+    = paren p PREC_CON $ HsAppTy x (goL PREC_FUN fun_ty) (goL PREC_CON arg_ty)
+  go p (HsAppKindTy x fun_ty arg_ki)
+    = paren p PREC_CON $ HsAppKindTy x (goL PREC_FUN fun_ty) (goL PREC_CON arg_ki)
+  go p (HsOpTy x prom ty1 op ty2)
+    = paren p PREC_FUN $ HsOpTy x prom (goL PREC_OP ty1) op (goL PREC_OP ty2)
+  go p (HsParTy _ t) = unXRec @a $ goL p t -- pretend the paren doesn't exist - it will be added back if needed
+  go _ t@HsTyVar{} = t
+  go _ t@HsStarTy{} = t
+  go _ t@HsSpliceTy{} = t
+  go _ t@HsTyLit{} = t
+  go _ t@HsWildCardTy{} = t
+  go _ t@XHsType{} = t
+
+  -- Located variant of 'go'
+  goL :: Precedence -> LHsType a -> LHsType a
+  goL ctxt_prec = mapXRec @a (go ctxt_prec)
+
+  -- Optionally wrap a type in parens
+  paren :: Precedence            -- Precedence of context
+        -> Precedence            -- Precedence of top-level operator
+        -> HsType a -> HsType a  -- Wrap in parens if (ctxt >= op)
+  paren ctxt_prec op_prec | ctxt_prec >= op_prec = HsParTy noAnn . wrapXRec @a
+                          | otherwise            = id
+
+
+-- | Add parenthesis around the types in a 'HsType' (see 'reparenTypePrec')
+reparenType :: XRecCond a => HsType a -> HsType a
+reparenType = reparenTypePrec PREC_TOP
+
+-- | Add parenthesis around the types in a 'LHsType' (see 'reparenTypePrec')
+reparenLType :: forall a. (XRecCond a) => LHsType a -> LHsType a
+reparenLType = mapXRec @a reparenType
+
+-- | Add parentheses around the types in an 'HsSigType' (see 'reparenTypePrec')
+reparenSigType :: forall a. ( XRecCond a )
+               => HsSigType a -> HsSigType a
+reparenSigType (HsSig x bndrs body) =
+  HsSig x (reparenOuterTyVarBndrs bndrs) (reparenLType body)
+reparenSigType v@XHsSigType{} = v
+
+-- | Add parentheses around the types in an 'HsOuterTyVarBndrs' (see 'reparenTypePrec')
+reparenOuterTyVarBndrs :: forall flag a. ( XRecCond a )
+                       => HsOuterTyVarBndrs flag a -> HsOuterTyVarBndrs flag a
+reparenOuterTyVarBndrs imp@HsOuterImplicit{} = imp
+reparenOuterTyVarBndrs (HsOuterExplicit x exp_bndrs) =
+  HsOuterExplicit x (map (mapXRec @(NoGhcTc a) reparenTyVar) exp_bndrs)
+reparenOuterTyVarBndrs v@XHsOuterTyVarBndrs{} = v
+
+-- | Add parentheses around the types in an 'HsForAllTelescope' (see 'reparenTypePrec')
+reparenHsForAllTelescope :: forall a. (XRecCond a )
+                         => HsForAllTelescope a -> HsForAllTelescope a
+reparenHsForAllTelescope (HsForAllVis x bndrs) =
+  HsForAllVis x (map (mapXRec @a reparenTyVar) bndrs)
+reparenHsForAllTelescope (HsForAllInvis x bndrs) =
+  HsForAllInvis x (map (mapXRec @a reparenTyVar) bndrs)
+reparenHsForAllTelescope v@XHsForAllTelescope{} = v
+
+-- | Add parenthesis around the types in a 'HsTyVarBndr' (see 'reparenTypePrec')
+reparenTyVar :: (XRecCond a) => HsTyVarBndr flag a -> HsTyVarBndr flag a
+reparenTyVar (UserTyVar x flag n) = UserTyVar x flag n
+reparenTyVar (KindedTyVar x flag n kind) = KindedTyVar x flag n (reparenLType kind)
+reparenTyVar v@XTyVarBndr{} = v
+
+-- | Add parenthesis around the types in a 'ConDeclField' (see 'reparenTypePrec')
+reparenConDeclField :: (XRecCond a) => ConDeclField a -> ConDeclField a
+reparenConDeclField (ConDeclField x n t d) = ConDeclField x n (reparenLType t) d
+reparenConDeclField c@XConDeclField{} = c
+
+
+-------------------------------------------------------------------------------
+-- * Located
+-------------------------------------------------------------------------------
+
+
+unL :: GenLocated l a -> a
+unL (L _ x) = x
+
+reL :: a -> GenLocated l a
+reL = L undefined
+
+mapMA :: Monad m => (a -> m b) -> LocatedAn an a -> m (Located b)
+mapMA f (L al a) = L (locA al) <$> f a
+
+-------------------------------------------------------------------------------
+-- * NamedThing instances
+-------------------------------------------------------------------------------
+
+
+instance NamedThing (TyClDecl GhcRn) where
+  getName = tcdName
+
+-------------------------------------------------------------------------------
+-- * Subordinates
+-------------------------------------------------------------------------------
+
+
+class Parent a where
+  children :: a -> [Name]
+
+
+instance Parent (ConDecl GhcRn) where
+  children con =
+    case getRecConArgs_maybe con of
+      Nothing -> []
+      Just flds -> map (foExt . unLoc) $ concatMap (cd_fld_names . unLoc) (unLoc flds)
+
+instance Parent (TyClDecl GhcRn) where
+  children d
+    | isDataDecl  d = map unLoc $ concatMap (toList . getConNames . unLoc)
+                                $ (dd_cons . tcdDataDefn) d
+    | isClassDecl d =
+        map (unLoc . fdLName . unLoc) (tcdATs d) ++
+        [ unLoc n | L _ (TypeSig _ ns _) <- tcdSigs d, n <- ns ]
+    | otherwise = []
+
+
+-- | A parent and its children
+family :: (NamedThing a, Parent a) => a -> (Name, [Name])
+family = getName &&& children
+
+
+familyConDecl :: ConDecl GHC.GhcRn -> [(Name, [Name])]
+familyConDecl d = zip (toList $ unLoc <$> getConNames d) (repeat $ children d)
+
+-- | A mapping from the parent (main-binder) to its children and from each
+-- child to its grand-children, recursively.
+families :: TyClDecl GhcRn -> [(Name, [Name])]
+families d
+  | isDataDecl  d = family d : concatMap (familyConDecl . unLoc) (dd_cons (tcdDataDefn d))
+  | isClassDecl d = [family d]
+  | otherwise     = []
+
+
+-- | A mapping from child to parent
+parentMap :: TyClDecl GhcRn -> [(Name, Name)]
+parentMap d = [ (c, p) | (p, cs) <- families d, c <- cs ]
+
+
+-- | The parents of a subordinate in a declaration
+parents :: Name -> HsDecl GhcRn -> [Name]
+parents n (TyClD _ d) = [ p | (c, p) <- parentMap d, c == n ]
+parents _ _ = []
+
+
+-------------------------------------------------------------------------------
+-- * Utils that work in monads defined by GHC
+-------------------------------------------------------------------------------
+
+
+modifySessionDynFlags :: (DynFlags -> DynFlags) -> Ghc ()
+modifySessionDynFlags f = do
+  dflags <- getSessionDynFlags
+  _ <- setSessionDynFlags (f dflags)
+  return ()
+
+
+-------------------------------------------------------------------------------
+-- * DynFlags
+-------------------------------------------------------------------------------
+
+-- TODO: use `setOutputDir` from GHC
+setOutputDir :: FilePath -> DynFlags -> DynFlags
+setOutputDir dir dynFlags =
+  dynFlags { objectDir    = Just dir
+           , hiDir        = Just dir
+           , hieDir       = Just dir
+           , stubDir      = Just dir
+           , includePaths = addGlobalInclude (includePaths dynFlags) [dir]
+           , dumpDir      = Just dir
+           }
+
+-------------------------------------------------------------------------------
+-- * 'StringBuffer' and 'ByteString'
+-------------------------------------------------------------------------------
+-- We get away with a bunch of these functions because 'StringBuffer' and
+-- 'ByteString' have almost exactly the same structure.
+
+-- | Convert a UTF-8 encoded 'ByteString' into a 'StringBuffer. This really
+-- relies on the internals of both 'ByteString' and 'StringBuffer'.
+--
+-- /O(n)/ (but optimized into a @memcpy@ by @bytestring@ under the hood)
+stringBufferFromByteString :: ByteString -> StringBuffer
+stringBufferFromByteString bs =
+  let BS.PS fp off len = bs <> BS.pack [0,0,0]
+  in S.StringBuffer { S.buf = fp, S.len = len - 3, S.cur = off }
+
+-- | Take the first @n@ /bytes/ of the 'StringBuffer' and put them in a
+-- 'ByteString'.
+--
+-- /O(1)/
+takeStringBuffer :: Int -> StringBuffer -> ByteString
+takeStringBuffer !n (S.StringBuffer fp _ cur) = BS.PS fp cur n
+
+-- | Return the prefix of the first 'StringBuffer' that /isn't/ in the second
+-- 'StringBuffer'. **The behavior is undefined if the 'StringBuffers' use
+-- separate buffers.**
+--
+-- /O(1)/
+splitStringBuffer :: StringBuffer -> StringBuffer -> ByteString
+splitStringBuffer buf1 buf2 = takeStringBuffer n buf1
+  where n = S.byteDiff buf1 buf2
+
+-- | Split the 'StringBuffer' at the next newline (or the end of the buffer).
+-- Also: initial position is passed in and the updated position is returned.
+--
+-- /O(n)/ (but /O(1)/ space)
+spanLine :: RealSrcLoc -> StringBuffer -> (ByteString, RealSrcLoc, StringBuffer)
+spanLine !loc !buf = go loc buf
+  where
+
+  go !l !b
+    | not (S.atEnd b)
+    = case S.nextChar b of
+        ('\n', b') -> (splitStringBuffer buf b', advanceSrcLoc l '\n', b')
+        (c,    b') -> go (advanceSrcLoc l c) b'
+    | otherwise
+    = (splitStringBuffer buf b, advanceSrcLoc l '\n', b)
+
+-- | Given a start position and a buffer with that start position, split the
+-- buffer at an end position.
+--
+-- /O(n)/ (but /O(1)/ space)
+spanPosition :: RealSrcLoc   -- ^ start of buffeer
+             -> RealSrcLoc   -- ^ position until which to take
+             -> StringBuffer -- ^ buffer from which to take
+             -> (ByteString, StringBuffer)
+spanPosition !start !end !buf = go start buf
+  where
+
+  go !l !b
+    | l < end
+    , not (S.atEnd b)
+    , (c, b') <- S.nextChar b
+    = go (advanceSrcLoc l c) b'
+    | otherwise
+    = (splitStringBuffer buf b, b)
+
+-- | Try to parse a line of CPP from the from of the buffer. A \"line\" of CPP
+-- consists of
+--
+--   * at most 10 whitespace characters, including at least one newline
+--   * a @#@ character
+--   * keep parsing lines until you find a line not ending in @\\@.
+--
+-- This is chock full of heuristics about what a line of CPP is.
+--
+-- /O(n)/ (but /O(1)/ space)
+tryCppLine :: RealSrcLoc -> StringBuffer -> Maybe (ByteString, RealSrcLoc, StringBuffer)
+tryCppLine !loc !buf = spanSpace (S.prevChar buf '\n' == '\n') loc buf
+  where
+
+  -- Keep consuming space characters until we hit either a @#@ or something
+  -- else. If we hit a @#@, start parsing CPP
+  spanSpace !seenNl !l !b
+    | S.atEnd b
+    = Nothing
+    | otherwise
+    = case S.nextChar b of
+        ('#' , b') | not (S.atEnd b')
+                   , ('-', b'') <- S.nextChar b'
+                   , ('}', _) <- S.nextChar b''
+                   -> Nothing -- Edge case exception for @#-}@
+                   | seenNl
+                   -> Just (spanCppLine (advanceSrcLoc l '#') b') -- parse CPP
+                   | otherwise
+                   -> Nothing -- We didn't see a newline, so this can't be CPP!
+
+        (c   , b') | isSpace c -> spanSpace (seenNl || c == '\n')
+                                            (advanceSrcLoc l c) b'
+                   | otherwise -> Nothing
+
+  -- Consume a CPP line to its "end" (basically the first line that ends not
+  -- with a @\@ character)
+  spanCppLine !l !b
+    | S.atEnd b
+    = (splitStringBuffer buf b, l, b)
+    | otherwise
+    = case S.nextChar b of
+        ('\\', b') | not (S.atEnd b')
+                   , ('\n', b'') <- S.nextChar b'
+                   -> spanCppLine (advanceSrcLoc (advanceSrcLoc l '\\') '\n') b''
+
+        ('\n', b') -> (splitStringBuffer buf b', advanceSrcLoc l '\n', b')
+
+        (c   , b') -> spanCppLine (advanceSrcLoc l c) b'
+
+-------------------------------------------------------------------------------
+-- * Names in a 'Type'
+-------------------------------------------------------------------------------
+
+-- | Given a 'Type', return a set of 'Name's coming from the 'TyCon's within
+-- the type.
+typeNames :: Type -> Set.Set Name
+typeNames ty = go ty Set.empty
+  where
+    go :: Type -> Set.Set Name -> Set.Set Name
+    go t acc =
+      case t of
+        TyVarTy {} -> acc
+        AppTy t1 t2 ->  go t2 $ go t1 acc
+        FunTy _ _ t1 t2 -> go t2 $ go t1 acc
+        TyConApp tcon args -> foldl' (\s t' -> go t' s) (Set.insert (getName tcon) acc) args
+        ForAllTy bndr t' -> go t' $ go (tyVarKind (binderVar bndr)) acc
+        LitTy _ -> acc
+        CastTy t' _ -> go t' acc
+        CoercionTy {} -> acc
+
+-------------------------------------------------------------------------------
+-- * Free variables of a 'Type'
+-------------------------------------------------------------------------------
+
+-- | Get free type variables in a 'Type' in their order of appearance.
+-- See [Ordering of implicit variables].
+orderedFVs
+  :: VarSet  -- ^ free variables to ignore
+  -> [Type]  -- ^ types to traverse (in order) looking for free variables
+  -> [TyVar] -- ^ free type variables, in the order they appear in
+orderedFVs vs tys =
+  reverse . fst $ tyCoFVsOfTypes' tys (const True) vs ([], emptyVarSet)
+
+
+-- See the "Free variables of types and coercions" section in 'TyCoRep', or
+-- check out Note [Free variables of types]. The functions in this section
+-- don't output type variables in the order they first appear in in the 'Type'.
+--
+-- For example, 'tyCoVarsOfTypeList' reports an incorrect order for the type
+-- of 'const :: a -> b -> a':
+--
+-- >>> import GHC.Types.Name
+-- >>> import TyCoRep
+-- >>> import GHC.Builtin.Types.Prim
+-- >>> import GHC.Types.Var
+-- >>> a = TyVarTy alphaTyVar
+-- >>> b = TyVarTy betaTyVar
+-- >>> constTy = mkFunTys [a, b] a
+-- >>> map (getOccString . tyVarName) (tyCoVarsOfTypeList constTy)
+-- ["b","a"]
+--
+-- However, we want to reuse the very optimized traversal machinery there, so
+-- so we make our own `tyCoFVsOfType'`, `tyCoFVsBndr'`, and `tyCoVarsOfTypes'`.
+-- All these do differently is traverse in a different order and ignore
+-- coercion variables.
+
+-- | Just like 'tyCoFVsOfType', but traverses type variables in reverse order
+-- of  appearance.
+tyCoFVsOfType' :: Type -> FV
+tyCoFVsOfType' (TyVarTy v)        a b c = (FV.unitFV v `unionFV` tyCoFVsOfType' (tyVarKind v)) a b c
+tyCoFVsOfType' (TyConApp _ tys)   a b c = tyCoFVsOfTypes' tys a b c
+tyCoFVsOfType' (LitTy {})         a b c = emptyFV a b c
+tyCoFVsOfType' (AppTy fun arg)    a b c = (tyCoFVsOfType' arg `unionFV` tyCoFVsOfType' fun) a b c
+tyCoFVsOfType' (FunTy _ w arg res)  a b c = (tyCoFVsOfType' w `unionFV`
+                                           tyCoFVsOfType' res `unionFV`
+                                           tyCoFVsOfType' arg) a b c
+tyCoFVsOfType' (ForAllTy bndr ty) a b c = tyCoFVsBndr' bndr (tyCoFVsOfType' ty)  a b c
+tyCoFVsOfType' (CastTy ty _)      a b c = (tyCoFVsOfType' ty) a b c
+tyCoFVsOfType' (CoercionTy _ )    a b c = emptyFV a b c
+
+-- | Just like 'tyCoFVsOfTypes', but traverses type variables in reverse order
+-- of appearance.
+tyCoFVsOfTypes' :: [Type] -> FV
+tyCoFVsOfTypes' (ty:tys) fv_cand in_scope acc = (tyCoFVsOfTypes' tys `unionFV` tyCoFVsOfType' ty) fv_cand in_scope acc
+tyCoFVsOfTypes' []       fv_cand in_scope acc = emptyFV fv_cand in_scope acc
+
+-- | Just like 'tyCoFVsBndr', but traverses type variables in reverse order of
+-- appearance.
+tyCoFVsBndr' :: TyVarBinder -> FV -> FV
+tyCoFVsBndr' (Bndr tv _) fvs = FV.delFV tv fvs `unionFV` tyCoFVsOfType' (tyVarKind tv)
+
+
+-------------------------------------------------------------------------------
+-- * Defaulting RuntimeRep variables
+-------------------------------------------------------------------------------
+
+-- | Traverses the type, defaulting type variables of kind 'RuntimeRep' to
+-- 'LiftedType'. See 'defaultRuntimeRepVars' in GHC.Iface.Type the original such
+-- function working over `IfaceType`'s.
+defaultRuntimeRepVars :: Type -> Type
+defaultRuntimeRepVars = go emptyVarEnv
+  where
+    go :: TyVarEnv () -> Type -> Type
+    go subs (ForAllTy (Bndr var flg) ty)
+      | isRuntimeRepVar var
+      , isInvisibleForAllTyFlag flg
+      = let subs' = extendVarEnv subs var ()
+        in go subs' ty
+      | otherwise
+      = ForAllTy (Bndr (updateTyVarKind (go subs) var) flg)
+                 (go subs ty)
+
+    go subs (TyVarTy tv)
+      | tv `elemVarEnv` subs
+      = liftedRepTy
+      | otherwise
+      = TyVarTy (updateTyVarKind (go subs) tv)
+
+    go subs (TyConApp tc tc_args)
+      = TyConApp tc (map (go subs) tc_args)
+
+    go subs (FunTy af w arg res)
+      = FunTy af (go subs w) (go subs arg) (go subs res)
+
+    go subs (AppTy t u)
+      = AppTy (go subs t) (go subs u)
+
+    go subs (CastTy x co)
+      = CastTy (go subs x) co
+
+    go _ ty@(LitTy {}) = ty
+    go _ ty@(CoercionTy {}) = ty
+
+fromMaybeContext :: Maybe (LHsContext DocNameI) -> HsContext DocNameI
+fromMaybeContext mctxt = unLoc $ fromMaybe (noLocA []) mctxt
diff --git a/haddock-api/src/Haddock/Interface.hs b/haddock-api/src/Haddock/Interface.hs
new file mode 100644
--- /dev/null
+++ b/haddock-api/src/Haddock/Interface.hs
@@ -0,0 +1,434 @@
+{-# LANGUAGE CPP               #-}
+{-# LANGUAGE OverloadedStrings #-}
+{-# LANGUAGE BangPatterns      #-}
+{-# LANGUAGE NamedFieldPuns    #-}
+{-# LANGUAGE TupleSections     #-}
+-----------------------------------------------------------------------------
+-- |
+-- Module      :  Haddock.Interface
+-- Copyright   :  (c) Simon Marlow      2003-2006,
+--                    David Waern       2006-2010,
+--                    Mateusz Kowalczyk 2013
+-- License     :  BSD-like
+--
+-- Maintainer  :  haddock@projects.haskell.org
+-- Stability   :  experimental
+-- Portability :  portable
+--
+-- This module typechecks Haskell modules using the GHC API and processes
+-- the result to create 'Interface's. The typechecking and the 'Interface'
+-- creation is interleaved, so that when a module is processed, the
+-- 'Interface's of all previously processed modules are available. The
+-- creation of an 'Interface' from a typechecked module is delegated to
+-- "Haddock.Interface.Create".
+--
+-- When all modules have been typechecked and processed, information about
+-- instances are attached to each 'Interface'. This task is delegated to
+-- "Haddock.Interface.AttachInstances". Note that this is done as a separate
+-- step because GHC can't know about all instances until all modules have been
+-- typechecked.
+--
+-- As a last step a link environment is built which maps names to the \"best\"
+-- places to link to in the documentation, and all 'Interface's are \"renamed\"
+-- using this environment.
+-----------------------------------------------------------------------------
+module Haddock.Interface (
+    plugin
+  , processModules
+) where
+
+
+import Haddock.GhcUtils (moduleString, pretty)
+import Haddock.Interface.AttachInstances (attachInstances)
+import Haddock.Interface.Create (createInterface1)
+import Haddock.Interface.Rename (renameInterface)
+import Haddock.InterfaceFile (InterfaceFile, ifInstalledIfaces, ifLinkEnv)
+import Haddock.Options hiding (verbosity)
+import Haddock.Types
+import Haddock.Utils (Verbosity (..), normal, out, verbose)
+
+import Control.Monad (unless, when)
+import Data.IORef (atomicModifyIORef', newIORef, readIORef, IORef)
+import Data.List (foldl', isPrefixOf)
+import Data.Maybe (mapMaybe)
+import Data.Traversable (for)
+import Text.Printf (printf)
+import qualified Data.Map.Strict as Map
+import qualified Data.Set as Set
+
+import GHC hiding (verbosity)
+import GHC.Data.Graph.Directed
+import GHC.Driver.Env
+import GHC.Driver.Monad (modifySession, withTimingM)
+import GHC.Driver.Session hiding (verbosity)
+import GHC.HsToCore.Docs (getMainDeclBinder)
+import GHC.Plugins
+import GHC.Tc.Types (TcGblEnv (..), TcM)
+import GHC.Tc.Utils.Env (tcLookupGlobal)
+import GHC.Tc.Utils.Monad (getTopEnv)
+import GHC.Unit.Module.Graph
+import GHC.Utils.Error (withTiming)
+
+#if defined(mingw32_HOST_OS)
+import System.IO
+import GHC.IO.Encoding.CodePage (mkLocaleEncoding)
+import GHC.IO.Encoding.Failure (CodingFailureMode(TransliterateCodingFailure))
+#endif
+
+-- | Create 'Interface's and a link environment by typechecking the list of
+-- modules using the GHC API and processing the resulting syntax trees.
+processModules
+  :: Verbosity                  -- ^ Verbosity of logging to 'stdout'
+  -> [String]                   -- ^ A list of file or module names sorted by
+                                -- module topology
+  -> [Flag]                     -- ^ Command-line flags
+  -> [InterfaceFile]            -- ^ Interface files of package dependencies
+  -> Ghc ([Interface], LinkEnv) -- ^ Resulting list of interfaces and renaming
+                                -- environment
+processModules verbosity modules flags extIfaces = do
+#if defined(mingw32_HOST_OS)
+  -- Avoid internal error: <stderr>: hPutChar: invalid argument (invalid character)' non UTF-8 Windows
+  liftIO $ hSetEncoding stdout $ mkLocaleEncoding TransliterateCodingFailure
+  liftIO $ hSetEncoding stderr $ mkLocaleEncoding TransliterateCodingFailure
+#endif
+
+  dflags <- getDynFlags
+
+  out verbosity verbose "Creating interfaces..."
+
+
+  -- Map from a module to a corresponding installed interface
+  let instIfaceMap :: InstIfaceMap
+      instIfaceMap = Map.fromList
+        [ (instMod iface, iface)
+        | ext <- extIfaces
+        , iface <- ifInstalledIfaces ext
+        ]
+
+  (interfaces, ms) <- createIfaces verbosity modules flags instIfaceMap
+
+  let exportedNames =
+        Set.unions $ map (Set.fromList . ifaceExports) $
+        filter (\i -> not $ OptHide `elem` ifaceOptions i) interfaces
+      mods = Set.fromList $ map ifaceMod interfaces
+
+  out verbosity verbose "Attaching instances..."
+  interfaces' <- {-# SCC attachInstances #-}
+                 withTimingM "attachInstances" (const ()) $ do
+                   attachInstances (exportedNames, mods) interfaces instIfaceMap ms
+
+  out verbosity verbose "Building cross-linking environment..."
+  -- Combine the link envs of the external packages into one
+  let extLinks  = Map.unions (map ifLinkEnv extIfaces)
+      homeLinks = buildHomeLinks interfaces' -- Build the environment for the home
+                                             -- package
+      links     = homeLinks `Map.union` extLinks
+
+  out verbosity verbose "Renaming interfaces..."
+
+  let warnings = Flag_NoWarnings `notElem` flags
+      ignoredSymbolSet = ignoredSymbols flags
+
+  interfaces'' <-
+    withTimingM "renameAllInterfaces" (const ()) $
+      for interfaces' $ \i -> do
+        withTimingM ("renameInterface: " <+> pprModuleName (moduleName (ifaceMod i))) (const ()) $
+          renameInterface dflags ignoredSymbolSet links warnings (Flag_Hoogle `elem` flags) i
+
+  return (interfaces'', homeLinks)
+
+--------------------------------------------------------------------------------
+-- * Module typechecking and Interface creation
+--------------------------------------------------------------------------------
+
+createIfaces
+    :: Verbosity
+    -- ^ Verbosity requested by the caller
+    -> [String]
+    -- ^ List of modules provided as arguments to Haddock (still in FilePath
+    -- format)
+    -> [Flag]
+    -- ^ Command line flags which Hadddock was invoked with
+    -> InstIfaceMap
+    -- ^ Map from module to corresponding installed interface file
+    -> Ghc ([Interface], ModuleSet)
+    -- ^ Resulting interfaces
+createIfaces verbosity modules flags instIfaceMap = do
+  -- Initialize the IORefs for the interface map and the module set
+  (ifaceMapRef, moduleSetRef) <- liftIO $ do
+    m <- newIORef Map.empty
+    s <- newIORef emptyModuleSet
+    return (m, s)
+
+  let
+    haddockPlugin = plugin verbosity flags instIfaceMap ifaceMapRef moduleSetRef
+
+    installHaddockPlugin :: HscEnv -> HscEnv
+    installHaddockPlugin hsc_env =
+      let
+        old_plugins = hsc_plugins hsc_env
+        new_plugins = old_plugins { staticPlugins = haddockPlugin : staticPlugins old_plugins }
+        hsc_env'    = hsc_env { hsc_plugins = new_plugins }
+      in hscUpdateFlags (flip gopt_set Opt_PluginTrustworthy) hsc_env'
+
+  -- Note that we would rather use withTempSession but as long as we
+  -- have the separate attachInstances step we need to keep the session
+  -- alive to be able to find all the instances.
+  modifySession installHaddockPlugin
+
+  targets <- mapM (\filePath -> guessTarget filePath Nothing Nothing) modules
+  setTargets targets
+
+  loadOk <- withTimingM "load" (const ()) $
+    {-# SCC load #-} GHC.load LoadAllTargets
+
+  case loadOk of
+    Failed ->
+      throwE "Cannot typecheck modules"
+    Succeeded -> do
+      modGraph <- GHC.getModuleGraph
+
+      (ifaceMap, moduleSet) <- liftIO $ do
+        m <- atomicModifyIORef' ifaceMapRef (Map.empty,)
+        s <- atomicModifyIORef' moduleSetRef (Set.empty,)
+        return (m, s)
+
+      let
+        -- We topologically sort the module graph including boot files,
+        -- so it should be acylic (hopefully we failed much earlier if this is not the case)
+        -- We then filter out boot modules from the resultant topological sort
+        --
+        -- We do it this way to make 'buildHomeLinks' a bit more stable
+        -- 'buildHomeLinks' depends on the topological order of its input in order
+        -- to construct its result. In particular, modules closer to the bottom of
+        -- the dependency chain are to be prefered for link destinations.
+        --
+        -- If there are cycles in the graph, then this order is indeterminate
+        -- (the nodes in the cycle can be ordered in any way).
+        -- While 'topSortModuleGraph' does guarantee stability for equivalent
+        -- module graphs, seemingly small changes in the ModuleGraph can have
+        -- big impacts on the `LinkEnv` constructed.
+        --
+        -- For example, suppose
+        --  G1 = A.hs -> B.hs -> C.hs (where '->' denotes an import).
+        --
+        -- Then suppose C.hs is changed to have a cyclic dependency on A
+        --
+        --  G2 = A.hs -> B.hs -> C.hs -> A.hs-boot
+        --
+        -- For G1, `C.hs` is preferred for link destinations. However, for G2,
+        -- the topologically sorted order not taking into account boot files (so
+        -- C -> A) is completely indeterminate.
+        -- Using boot files to resolve cycles, we end up with the original order
+        -- [C, B, A] (in decreasing order of preference for links)
+        --
+        -- This exact case came up in testing for the 'base' package, where there
+        -- is a big module cycle involving 'Prelude' on windows, but the cycle doesn't
+        -- include 'Prelude' on non-windows platforms. This lead to drastically different
+        -- LinkEnv's (and failing haddockHtmlTests) across the platforms
+        --
+        -- In effect, for haddock users this behaviour (using boot files to eliminate cycles)
+        -- means that {-# SOURCE #-} imports no longer count towards re-ordering
+        -- the preference of modules for linking.
+        --
+        -- i.e. if module A imports B, then B is preferred over A,
+        -- but if module A {-# SOURCE #-} imports B, then we can't say the same.
+        --
+        go :: SCC ModuleGraphNode -> Maybe Module
+        go (AcyclicSCC (ModuleNode _ ms))
+          | NotBoot <- isBootSummary ms = Just $ ms_mod ms
+          | otherwise = Nothing
+        go (AcyclicSCC _) = Nothing
+        go (CyclicSCC _) = error "haddock: module graph cyclic even with boot files"
+
+        ifaces :: [Interface]
+        ifaces =
+          [ Map.findWithDefault
+              (error "haddock:iface")
+              m
+              ifaceMap
+          | m <- mapMaybe go $ topSortModuleGraph False modGraph Nothing
+          ]
+
+      return (ifaces, moduleSet)
+
+
+-- | A `Plugin` that hooks into GHC's compilation pipeline to generate Haddock
+-- interfaces. Due to the plugin nature we benefit from GHC's capabilities to
+-- parallelize the compilation process.
+plugin
+  :: Verbosity
+  -- ^ Verbosity requested by the Haddock caller
+  -> [Flag]
+  -- ^ Command line flags which Hadddock was invoked with
+  -> InstIfaceMap
+  -- ^ Map from module to corresponding installed interface file
+  -> IORef IfaceMap
+  -- ^ The 'IORef' to write the interface map to
+  -> IORef ModuleSet
+  -- ^ The 'IORef' to write the module set to
+  -> StaticPlugin -- the plugin to install with GHC
+plugin verbosity flags instIfaceMap ifaceMapRef moduleSetRef =
+  let
+    processTypeCheckedResult :: ModSummary -> TcGblEnv -> TcM ()
+    processTypeCheckedResult mod_summary tc_gbl_env
+      -- Don't do anything for hs-boot modules
+      | IsBoot <- isBootSummary mod_summary =
+          pure ()
+      | otherwise = do
+          hsc_env <- getTopEnv
+          ifaces <- liftIO $ readIORef ifaceMapRef
+
+          (iface, modules) <-
+            withTiming (hsc_logger hsc_env) "processModule1" (const ()) $
+              processModule1 verbosity flags ifaces instIfaceMap hsc_env mod_summary tc_gbl_env
+
+          liftIO $ do
+            atomicModifyIORef' ifaceMapRef $ \xs ->
+              (Map.insert (ms_mod mod_summary) iface xs, ())
+
+            atomicModifyIORef' moduleSetRef $ \xs ->
+              (modules `unionModuleSet` xs, ())
+  in
+    StaticPlugin
+      {
+        spPlugin = PluginWithArgs
+        {
+          paPlugin = defaultPlugin
+          {
+            renamedResultAction = keepRenamedSource
+          , typeCheckResultAction = \_ mod_summary tc_gbl_env -> do
+              processTypeCheckedResult mod_summary tc_gbl_env
+              pure tc_gbl_env
+          }
+        , paArguments = []
+        }
+      }
+
+processModule1
+  :: Verbosity
+  -- ^ Verbosity requested by the Haddock caller
+  -> [Flag]
+  -- ^ Command line flags which Hadddock was invoked with
+  -> IfaceMap
+  -- ^ Map from module to corresponding interface, for the modules we have
+  -- already processed
+  -> InstIfaceMap
+  -- ^ Map from module to corresponding installed interface file
+  -> HscEnv
+  -> ModSummary
+  -> TcGblEnv
+  -> TcM (Interface, ModuleSet)
+processModule1 verbosity flags ifaces inst_ifaces hsc_env mod_summary tc_gbl_env = do
+  out verbosity verbose "Creating interface..."
+
+  let
+    TcGblEnv { tcg_rdr_env } = tc_gbl_env
+
+    unit_state = hsc_units hsc_env
+
+  !interface <- do
+    logger <- getLogger
+    {-# SCC createInterface #-}
+      withTiming logger "createInterface" (const ()) $
+        runIfM (fmap Just . tcLookupGlobal) $
+          createInterface1 flags unit_state mod_summary tc_gbl_env ifaces inst_ifaces
+
+  -- We need to keep track of which modules were somehow in scope so that when
+  -- Haddock later looks for instances, it also looks in these modules too.
+  --
+  -- See https://github.com/haskell/haddock/issues/469.
+  let
+    mods :: ModuleSet
+    !mods = mkModuleSet
+      [ nameModule name
+      | gre <- globalRdrEnvElts tcg_rdr_env
+      , let name = greMangledName gre
+      , nameIsFromExternalPackage (hsc_home_unit hsc_env) name
+      , isTcOcc (nameOccName name)   -- Types and classes only
+      , unQualOK gre -- In scope unqualified
+      ]
+
+  dflags <- getDynFlags
+
+  let
+    (haddockable, haddocked) =
+      ifaceHaddockCoverage interface
+
+    percentage :: Int
+    percentage = div (haddocked * 100) haddockable
+
+    modString :: String
+    modString = moduleString (ifaceMod interface)
+
+    coverageMsg :: String
+    coverageMsg =
+      printf " %3d%% (%3d /%3d) in '%s'" percentage haddocked haddockable modString
+
+    header :: Bool
+    header = case ifaceDoc interface of
+      Documentation Nothing _ -> False
+      _ -> True
+
+    undocumentedExports :: [String]
+    undocumentedExports =
+      [ formatName (locA s) n
+      | ExportDecl ExportD
+          { expDDecl = L s n
+          , expDMbDoc = (Documentation Nothing _, _)
+          } <- ifaceExportItems interface
+      ]
+        where
+          formatName :: SrcSpan -> HsDecl GhcRn -> String
+          formatName loc n = p (getMainDeclBinder emptyOccEnv n) ++ case loc of
+            RealSrcSpan rss _ -> " (" ++ unpackFS (srcSpanFile rss) ++ ":" ++
+              show (srcSpanStartLine rss) ++ ")"
+            _ -> ""
+
+          p :: Outputable a => [a] -> String
+          p [] = ""
+          p (x:_) = let n = pretty dflags x
+                        ms = modString ++ "."
+                    in if ms `isPrefixOf` n
+                       then drop (length ms) n
+                       else n
+
+  when (OptHide `notElem` ifaceOptions interface) $ do
+    out verbosity normal coverageMsg
+    when (Flag_NoPrintMissingDocs `notElem` flags
+          && not (null undocumentedExports && header)) $ do
+      out verbosity normal "  Missing documentation for:"
+      unless header $ out verbosity normal "    Module header"
+      mapM_ (out verbosity normal . ("    " ++)) undocumentedExports
+
+  pure (interface, mods)
+
+
+--------------------------------------------------------------------------------
+-- * Building of cross-linking environment
+--------------------------------------------------------------------------------
+
+
+-- | Build a mapping which for each original name, points to the "best"
+-- place to link to in the documentation.  For the definition of
+-- "best", we use "the module nearest the bottom of the dependency
+-- graph which exports this name", not including hidden modules.  When
+-- there are multiple choices, we pick a random one.
+--
+-- The interfaces are passed in in topologically sorted order, but we start
+-- by reversing the list so we can do a foldl.
+buildHomeLinks :: [Interface] -> LinkEnv
+buildHomeLinks ifaces = foldl' upd Map.empty (reverse ifaces)
+  where
+    upd old_env iface
+      | OptHide `elem` ifaceOptions iface =
+          old_env
+      | OptNotHome `elem` ifaceOptions iface =
+          foldl' keep_old old_env exported_names
+      | otherwise =
+          foldl' keep_new old_env exported_names
+      where
+        exported_names = ifaceVisibleExports iface ++ map haddockClsInstName (ifaceInstances iface)
+        mdl            = ifaceMod iface
+        keep_old env n = Map.insertWith (\_ old -> old) n mdl env
+        keep_new env n = Map.insert n mdl env
diff --git a/haddock-api/src/Haddock/Interface/AttachInstances.hs b/haddock-api/src/Haddock/Interface/AttachInstances.hs
new file mode 100644
--- /dev/null
+++ b/haddock-api/src/Haddock/Interface/AttachInstances.hs
@@ -0,0 +1,280 @@
+{-# LANGUAGE TypeFamilies #-}
+{-# LANGUAGE BangPatterns #-}
+{-# OPTIONS_GHC -Wno-incomplete-record-updates #-}
+{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}
+-----------------------------------------------------------------------------
+-- |
+-- Module      :  Haddock.Interface.AttachInstances
+-- Copyright   :  (c) Simon Marlow 2006,
+--                    David Waern  2006-2009,
+--                    Isaac Dupree 2009
+-- License     :  BSD-like
+--
+-- Maintainer  :  haddock@projects.haskell.org
+-- Stability   :  experimental
+-- Portability :  portable
+-----------------------------------------------------------------------------
+module Haddock.Interface.AttachInstances (attachInstances, instHead) where
+
+
+import Haddock.Convert
+import Haddock.GhcUtils (typeNames)
+import Haddock.Types
+
+import Control.Applicative ((<|>))
+import Control.Arrow hiding ((<+>))
+import Control.DeepSeq (force)
+import Data.Foldable (foldl')
+import Data.List (sortBy)
+import Data.Ord (comparing)
+import Data.Maybe ( maybeToList, mapMaybe, fromMaybe )
+import qualified Data.Map.Strict as Map
+import qualified Data.Set as Set
+
+import GHC.Data.FastString (unpackFS)
+import GHC.Core.Class
+import GHC.Core.FamInstEnv
+import GHC
+import GHC.Core.InstEnv
+import GHC.Unit.Module.Env ( ModuleSet, moduleSetElts )
+import GHC.Types.Name
+import GHC.Types.Name.Env
+import GHC.Utils.Outputable (text, sep, (<+>))
+import GHC.Types.SrcLoc
+import GHC.Core.TyCon
+import GHC.Core.TyCo.Rep
+import GHC.Builtin.Types( unrestrictedFunTyConName )
+import GHC.Types.Var hiding (varName)
+import GHC.HsToCore.Docs
+
+type ExportedNames = Set.Set Name
+type Modules = Set.Set Module
+type ExportInfo = (ExportedNames, Modules)
+
+-- Also attaches fixities
+attachInstances :: ExportInfo -> [Interface] -> InstIfaceMap -> ModuleSet -> Ghc [Interface]
+attachInstances expInfo ifaces instIfaceMap mods = do
+  (_msgs, mb_index) <- getNameToInstancesIndex (map ifaceMod ifaces) mods'
+  mapM (attach $ fromMaybe emptyNameEnv mb_index) ifaces
+  where
+    mods' = Just (moduleSetElts mods)
+
+    -- TODO: take an IfaceMap as input
+    ifaceMap = Map.fromList [ (ifaceMod i, i) | i <- ifaces ]
+
+    attach index iface = do
+
+      let getInstDoc = findInstDoc iface ifaceMap instIfaceMap
+          getFixity = findFixity iface ifaceMap instIfaceMap
+
+      newItems <- mapM (attachToExportItem index expInfo getInstDoc getFixity)
+                       (ifaceExportItems iface)
+      let orphanInstances = attachOrphanInstances expInfo getInstDoc (ifaceInstances iface)
+      return $ iface { ifaceExportItems = newItems
+                     , ifaceOrphanInstances = orphanInstances
+                     }
+
+attachOrphanInstances
+  :: ExportInfo
+  -> (Name -> Maybe (MDoc Name))      -- ^ how to lookup the doc of an instance
+  -> [HaddockClsInst]                 -- ^ a list of instances
+  -> [DocInstance GhcRn]
+attachOrphanInstances expInfo getInstDoc cls_instances =
+  [ (synified, getInstDoc instName, (L (getSrcSpan instName) instName), Nothing)
+  | let is =
+          [ ( haddockClsInstHead i
+            , haddockClsInstSynified i
+            , haddockClsInstName i
+            , haddockClsInstClsName i
+            , haddockClsInstTyNames i
+            )
+          | i <- cls_instances, haddockClsInstIsOrphan i
+          ]
+  , (_, synified, instName, cls, tyNames) <- sortBy (comparing $ (\(ih,_,_,_,_) -> ih)) is
+  , not $ isInstanceHidden expInfo cls tyNames
+  ]
+
+
+attachToExportItem
+  :: NameEnv ([ClsInst], [FamInst])   -- ^ all instances (that we know of)
+  -> ExportInfo
+  -> (Name -> Maybe (MDoc Name))      -- ^ how to lookup the doc of an instance
+  -> (Name -> Maybe Fixity)           -- ^ how to lookup a fixity
+  -> ExportItem GhcRn
+  -> Ghc (ExportItem GhcRn)
+attachToExportItem index expInfo getInstDoc getFixity export =
+  case attachFixities export of
+    ExportDecl e@(ExportD { expDDecl = L eSpan (TyClD _ d) }) -> do
+      insts <-
+        let mb_instances  = lookupNameEnv index (tcdName d)
+            cls_instances = maybeToList mb_instances >>= fst
+            fam_instances = maybeToList mb_instances >>= snd
+            fam_insts = [ ( synFamInst
+                          , getInstDoc n
+                          , spanNameE n synFamInst (L (locA eSpan) (tcdName d))
+                          , mb_mdl
+                          )
+                        | i <- sortBy (comparing instFam) fam_instances
+                        , let n = getName i
+                        , not $ isNameHidden expInfo (fi_fam i)
+                        , not $ any (isTypeHidden expInfo) (fi_tys i)
+                        , let opaque = isTypeHidden expInfo (fi_rhs i)
+                        , let synFamInst = synifyFamInst i opaque
+                        , let !mb_mdl = force $ nameModule_maybe n
+                        ]
+            cls_insts = [ ( synClsInst
+                          , getInstDoc n
+                          , spanName n synClsInst (L (locA eSpan) (tcdName d))
+                          , mb_mdl
+                          )
+                        | let is = [ (instanceSig i, getName i) | i <- cls_instances ]
+                        , (i@(_,_,cls,tys), n) <- sortBy (comparing $ first instHead) is
+                        , not $ isInstanceHidden
+                                  expInfo
+                                  (getName cls)
+                                  (foldl' (\acc t -> acc `Set.union` typeNames t) Set.empty tys)
+                        , let synClsInst = synifyInstHead i
+                        , let !mb_mdl = force $ nameModule_maybe n
+                        ]
+              -- fam_insts but with failing type fams filtered out
+            cleanFamInsts = [ (fi, n, L l r, m) | (Right fi, n, L l (Right r), m) <- fam_insts ]
+            famInstErrs = [ errm | (Left errm, _, _, _) <- fam_insts ]
+        in do
+          let mkBug = (text "haddock-bug:" <+>) . text
+          putMsgM (sep $ map mkBug famInstErrs)
+          return $ cls_insts ++ cleanFamInsts
+      return $ ExportDecl e { expDInstances = insts }
+    e -> return e
+  where
+    attachFixities
+        ( ExportDecl
+          ( e@ExportD
+              { expDDecl = L _ d
+              , expDPats = patsyns
+              , expDSubDocs = subDocs
+              }
+          )
+        )
+      = ExportDecl e
+          { expDFixities = fixities
+          }
+      where
+        fixities :: [(Name, Fixity)]
+        !fixities = force . Map.toList $ foldl' f Map.empty all_names
+
+        f :: Map.Map Name Fixity -> Name -> Map.Map Name Fixity
+        f !fs n = Map.alter (<|> getFixity n) n fs
+
+        patsyn_names :: [Name]
+        patsyn_names = concatMap (getMainDeclBinder emptyOccEnv . fst) patsyns
+
+        all_names :: [Name]
+        all_names =
+             getMainDeclBinder emptyOccEnv d
+          ++ map fst subDocs
+          ++ patsyn_names
+
+    attachFixities e = e
+
+    -- spanName: attach the location to the name that is the same file as the instance location
+    spanName s (InstHead { ihdClsName = clsn }) (L instL instn) =
+        let s1 = getSrcSpan s
+            sn = if srcSpanFileName_maybe s1 == srcSpanFileName_maybe instL
+                    then instn
+                    else clsn
+        in L (getSrcSpan s) sn
+    -- spanName on Either
+    spanNameE s (Left e) _ =  L (getSrcSpan s) (Left e)
+    spanNameE s (Right ok) linst =
+      let L l r = spanName s ok linst
+      in L l (Right r)
+
+-- | Lookup the doc associated with a certain instance
+findInstDoc :: Interface -> IfaceMap -> InstIfaceMap -> Name -> Maybe (MDoc Name)
+findInstDoc iface ifaceMap instIfaceMap = \name ->
+  (Map.lookup name . ifaceDocMap $ iface) <|>
+  (Map.lookup name . ifaceDocMap =<< Map.lookup (nameModule name) ifaceMap) <|>
+  (Map.lookup name . instDocMap =<< Map.lookup (nameModule name) instIfaceMap)
+
+-- | Lookup the fixity associated with a certain name
+findFixity :: Interface -> IfaceMap -> InstIfaceMap -> Name -> Maybe Fixity
+findFixity iface ifaceMap instIfaceMap = \name ->
+  (Map.lookup name . ifaceFixMap $ iface) <|>
+  (Map.lookup name . ifaceFixMap =<< Map.lookup (nameModule name) ifaceMap) <|>
+  (Map.lookup name . instFixMap =<< Map.lookup (nameModule name) instIfaceMap)
+
+
+--------------------------------------------------------------------------------
+-- Collecting and sorting instances
+--------------------------------------------------------------------------------
+
+instHead :: ([TyVar], [PredType], Class, [Type]) -> ([Int], SName, [SimpleType])
+instHead (_, _, cls, args)
+  = (map argCount args, SName (className cls), map simplify args)
+
+argCount :: Type -> Int
+argCount (AppTy t _)     = argCount t + 1
+argCount (TyConApp _ ts) = length ts
+argCount (FunTy _ _ _ _) = 2
+argCount (ForAllTy _ t)  = argCount t
+argCount (CastTy t _)    = argCount t
+argCount _ = 0
+
+simplify :: Type -> SimpleType
+simplify (FunTy _ _ t1 t2)  = SimpleType (SName unrestrictedFunTyConName) [simplify t1, simplify t2]
+simplify (ForAllTy _ t) = simplify t
+simplify (AppTy t1 t2) = SimpleType s (ts ++ maybeToList (simplify_maybe t2))
+  where (SimpleType s ts) = simplify t1
+simplify (TyVarTy v) = SimpleType (SName (tyVarName v)) []
+simplify (TyConApp tc ts) = SimpleType (SName (tyConName tc))
+                                       (mapMaybe simplify_maybe ts)
+simplify (LitTy (NumTyLit n)) = SimpleIntTyLit n
+simplify (LitTy (StrTyLit s)) = SimpleStringTyLit (unpackFS s)
+simplify (LitTy (CharTyLit c)) = SimpleCharTyLit c
+simplify (CastTy ty _) = simplify ty
+simplify (CoercionTy _) = error "simplify:Coercion"
+
+simplify_maybe :: Type -> Maybe SimpleType
+simplify_maybe (CoercionTy {}) = Nothing
+simplify_maybe ty              = Just (simplify ty)
+
+-- Used for sorting
+instFam :: FamInst -> ([Int], SName, [SimpleType], Int, SimpleType)
+instFam FamInst { fi_fam = n, fi_tys = ts, fi_rhs = t }
+  = (map argCount ts, SName n, map simplify ts, argCount t, simplify t)
+
+
+--------------------------------------------------------------------------------
+-- Filtering hidden instances
+--------------------------------------------------------------------------------
+
+-- | A class or data type is hidden iff
+--
+-- * it is defined in one of the modules that are being processed
+--
+-- * and it is not exported by any non-hidden module
+isNameHidden :: ExportInfo -> Name -> Bool
+isNameHidden (names, modules) name =
+  nameModule name `Set.member` modules &&
+  not (name `Set.member` names)
+
+-- | We say that an instance is «hidden» iff its class or any (part)
+-- of its type(s) is hidden.
+isInstanceHidden :: ExportInfo -> Name -> Set.Set Name -> Bool
+isInstanceHidden expInfo cls tyNames =
+    instClassHidden || instTypeHidden
+  where
+    instClassHidden :: Bool
+    instClassHidden = isNameHidden expInfo cls
+
+    instTypeHidden :: Bool
+    instTypeHidden = any (isNameHidden expInfo) tyNames
+
+isTypeHidden :: ExportInfo -> Type -> Bool
+isTypeHidden expInfo = typeHidden
+  where
+    typeHidden :: Type -> Bool
+    typeHidden t = any nameHidden $ typeNames t
+
+    nameHidden :: Name -> Bool
+    nameHidden = isNameHidden expInfo
diff --git a/haddock-api/src/Haddock/Interface/Create.hs b/haddock-api/src/Haddock/Interface/Create.hs
new file mode 100644
--- /dev/null
+++ b/haddock-api/src/Haddock/Interface/Create.hs
@@ -0,0 +1,1276 @@
+{-# LANGUAGE BangPatterns #-}
+{-# LANGUAGE CPP #-}
+{-# LANGUAGE DerivingStrategies #-}
+{-# LANGUAGE FlexibleInstances #-}
+{-# LANGUAGE GeneralizedNewtypeDeriving #-}
+{-# LANGUAGE LambdaCase #-}
+{-# LANGUAGE MultiParamTypeClasses #-}
+{-# LANGUAGE NamedFieldPuns #-}
+{-# LANGUAGE RecordWildCards #-}
+{-# LANGUAGE ScopedTypeVariables #-}
+{-# LANGUAGE StandaloneDeriving #-}
+{-# LANGUAGE TypeFamilies #-}
+{-# LANGUAGE ViewPatterns #-}
+{-# OPTIONS_GHC -Wwarn #-}
+-----------------------------------------------------------------------------
+-- |
+-- Module      :  Haddock.Interface.Create
+-- Copyright   :  (c) Simon Marlow      2003-2006,
+--                    David Waern       2006-2009,
+--                    Mateusz Kowalczyk 2013
+-- License     :  BSD-like
+--
+-- Maintainer  :  haddock@projects.haskell.org
+-- Stability   :  experimental
+-- Portability :  portable
+--
+-- This module provides a single function 'createInterface',
+-- which creates a Haddock 'Interface' from the typechecking
+-- results 'TypecheckedModule' from GHC.
+-----------------------------------------------------------------------------
+module Haddock.Interface.Create (IfM, runIfM, createInterface1) where
+
+import Documentation.Haddock.Doc (metaDocAppend)
+import Haddock.Backends.Hoogle (outWith)
+import Haddock.Convert (PrintRuntimeReps (..), tyThingToLHsDecl, synifyInstHead)
+import Haddock.GhcUtils (addClassContext, filterSigNames, lHsQTyVarsToTypes, mkEmptySigType, moduleString, parents,
+                         pretty, restrictTo, sigName, unL, typeNames)
+import Haddock.Interface.AttachInstances (instHead)
+import Haddock.Interface.LexParseRn
+import Haddock.Options (Flag (..), modulePackageInfo)
+import Haddock.Types
+import Haddock.Utils (replace)
+
+import Control.Applicative ((<|>))
+import Control.DeepSeq
+import Control.Monad.State.Strict
+import Data.Bitraversable (bitraverse)
+import Data.Foldable (toList)
+import Data.List (find, foldl')
+import qualified Data.IntMap as IM
+import Data.IntMap (IntMap)
+import Data.Map.Strict (Map)
+import qualified Data.Map.Strict as M
+import Data.Maybe (catMaybes, fromJust, isJust, mapMaybe, maybeToList)
+import qualified Data.Set as Set
+import Data.Traversable (for)
+
+import GHC hiding (lookupName)
+import GHC.Core (isOrphan)
+import GHC.Core.Class (ClassMinimalDef, classMinimalDef)
+import GHC.Core.ConLike (ConLike (..))
+import GHC.Core.InstEnv
+import GHC.Data.FastString (unpackFS)
+import GHC.Driver.Ppr (showSDoc, showSDocForUser)
+import GHC.HsToCore.Docs hiding (mkMaps, unionArgMaps)
+import GHC.IORef (readIORef)
+import GHC.Stack (HasCallStack)
+import GHC.Tc.Types hiding (IfM)
+import GHC.Tc.Utils.Monad (finalSafeMode)
+import GHC.Types.Avail hiding (avail)
+import qualified GHC.Types.Avail as Avail
+import GHC.Types.Name (getOccString, getSrcSpan, isDataConName, isValName, nameIsLocalOrFrom, nameOccName, emptyOccEnv)
+import GHC.Types.Name.Env (lookupNameEnv)
+import GHC.Types.Name.Reader (GlobalRdrEnv, greMangledName, lookupGlobalRdrEnv)
+import GHC.Types.Name.Set (elemNameSet, mkNameSet)
+import GHC.Types.SourceFile (HscSource (..))
+import GHC.Types.SourceText (SourceText (..), sl_fs)
+import GHC.Unit.Types
+import qualified GHC.Types.SrcLoc as SrcLoc
+import qualified GHC.Unit.Module as Module
+import GHC.Unit.Module.ModSummary (msHsFilePath)
+import GHC.Unit.State (PackageName (..), UnitState, lookupModuleInAllUnits)
+import qualified GHC.Utils.Outputable as O
+import GHC.Utils.Panic (pprPanic)
+import GHC.Unit.Module.Warnings
+import GHC.Types.Unique.Map
+
+createInterface1
+  :: MonadIO m
+  => [Flag]
+  -> UnitState
+  -> ModSummary
+  -> TcGblEnv
+  -> IfaceMap
+  -> InstIfaceMap
+  -> IfM m Interface
+createInterface1 flags unit_state mod_sum tc_gbl_env ifaces inst_ifaces = do
+
+  let
+    ModSummary
+      {
+        -- Cached flags from OPTIONS, INCLUDE and LANGUAGE
+        -- pragmas in the modules source code. Used to infer
+        -- safety of module.
+        ms_hspp_opts
+      , ms_location = ModLocation
+        {
+          ml_hie_file
+        }
+      } = mod_sum
+
+    !ml_hie_file' = force ml_hie_file
+
+    TcGblEnv
+      {
+        tcg_mod
+      , tcg_src
+      , tcg_semantic_mod
+      , tcg_rdr_env
+      , tcg_exports
+      , tcg_insts
+      , tcg_fam_insts
+      , tcg_warns
+
+      -- Renamed source
+      , tcg_rn_imports
+      , tcg_rn_exports
+      , tcg_rn_decls
+
+      , tcg_th_docs
+      , tcg_doc_hdr
+      } = tc_gbl_env
+
+    dflags = ms_hspp_opts
+
+    is_sig = tcg_src == HsigFile
+
+    (pkg_name_fs, _) =
+      modulePackageInfo unit_state flags (Just tcg_mod)
+
+    pkg_name :: Maybe Package
+    pkg_name =
+      let
+        unpack (PackageName name) = unpackFS name
+      in
+        fmap unpack pkg_name_fs
+
+    fixities :: FixMap
+    fixities = case tcg_rn_decls of
+      Nothing -> mempty
+      Just dx -> mkFixMap dx
+
+    -- Locations of all the TH splices
+    loc_splices :: [SrcSpan]
+    loc_splices = case tcg_rn_decls of
+      Nothing -> []
+      Just HsGroup { hs_splcds } -> [ locA loc | L loc _ <- hs_splcds ]
+
+  decls <- case tcg_rn_decls of
+    Nothing -> do
+      warn "Warning: Renamed source is not available"
+      pure []
+    Just dx -> pure (topDecls dx)
+
+  -- Derive final options to use for haddocking this module
+  doc_opts <- mkDocOpts (haddockOptions ms_hspp_opts) flags tcg_mod
+
+  let
+    -- All elements of an explicit export list, if present
+    export_list :: Maybe [(IE GhcRn, Avails)]
+    export_list
+      | OptIgnoreExports `elem` doc_opts  =
+          Nothing
+      | Just rn_exports <- tcg_rn_exports =
+          Just [ (ie, avail) | (L _ ie, avail) <- rn_exports ]
+      | otherwise =
+          Nothing
+
+    -- All the exported Names of this module.
+    exported_names :: [Name]
+    !exported_names = force $
+      concatMap availNamesWithSelectors tcg_exports
+
+    -- Module imports of the form `import X`. Note that there is
+    -- a) no qualification and
+    -- b) no import list
+    imported_modules :: Map ModuleName [ModuleName]
+    imported_modules
+      | Just{} <- export_list =
+          unrestrictedModuleImports (map unLoc tcg_rn_imports)
+      | otherwise =
+          M.empty
+
+    -- TyThings that have instances defined in this module
+    local_instances :: [Name]
+    local_instances =
+      [ name
+      | name <- map getName tcg_insts ++ map getName tcg_fam_insts
+      , nameIsLocalOrFrom tcg_semantic_mod name
+      ]
+
+  -- Infer module safety
+  safety   <- liftIO (finalSafeMode ms_hspp_opts tc_gbl_env)
+
+  -- The docs added via Template Haskell's putDoc
+  thDocs@ExtractedTHDocs { ethd_mod_header = thMbDocStr } <-
+    liftIO $ extractTHDocs <$> readIORef tcg_th_docs
+
+  -- Process the top-level module header documentation.
+  (!info, !header_doc) <- force <$> processModuleHeader dflags pkg_name
+    tcg_rdr_env safety (fmap hsDocString thMbDocStr <|> (hsDocString . unLoc <$> tcg_doc_hdr))
+
+  -- Warnings on declarations in this module
+  decl_warnings <- mkWarningMap dflags tcg_warns tcg_rdr_env exported_names
+
+  -- Warning on the module header
+  mod_warning <- moduleWarning dflags tcg_rdr_env tcg_warns
+
+  let
+    -- Warnings in this module and transitive warnings from dependent modules
+    warnings :: Map Name (Doc Name)
+    warnings = M.unions (decl_warnings : map ifaceWarningMap (M.elems ifaces))
+
+  maps@(!docs, !arg_docs, !decl_map, _) <-
+    mkMaps dflags pkg_name tcg_rdr_env local_instances decls thDocs
+
+  export_items <- mkExportItems is_sig ifaces pkg_name tcg_mod tcg_semantic_mod
+    warnings tcg_rdr_env exported_names (map fst decls) maps fixities
+    imported_modules loc_splices export_list tcg_exports inst_ifaces dflags
+
+  let
+    visible_names :: [Name]
+    !visible_names = force $ mkVisibleNames maps export_items doc_opts
+
+    -- Measure haddock documentation coverage.
+    pruned_export_items :: [ExportItem GhcRn]
+    pruned_export_items = pruneExportItems export_items
+
+    !haddockable = 1 + length export_items -- module + exports
+    !haddocked = (if isJust tcg_doc_hdr then 1 else 0) + length pruned_export_items
+
+    coverage :: (Int, Int)
+    !coverage = (haddockable, haddocked)
+
+    aliases :: Map Module ModuleName
+    aliases = mkAliasMap unit_state tcg_rn_imports
+
+    insts :: [HaddockClsInst]
+    !insts = force $ map (fromClsInst (Flag_Hoogle `elem` flags) dflags unit_state) tcg_insts
+
+  return $! Interface
+    {
+      ifaceMod               = tcg_mod
+    , ifaceIsSig             = is_sig
+    , ifaceOrigFilename      = msHsFilePath mod_sum
+    , ifaceHieFile           = Just ml_hie_file'
+    , ifaceInfo              = info
+    , ifaceDoc               = Documentation header_doc mod_warning
+    , ifaceRnDoc             = Documentation Nothing Nothing
+    , ifaceOptions           = doc_opts
+    , ifaceDocMap            = docs
+    , ifaceArgMap            = arg_docs
+    , ifaceExportItems       = if OptPrune `elem` doc_opts then
+                                 pruned_export_items else export_items
+    , ifaceRnExportItems     = [] -- Filled in renameInterfaceRn
+    , ifaceExports           = exported_names
+    , ifaceVisibleExports    = visible_names
+    , ifaceDeclMap           = decl_map
+    , ifaceFixMap            = fixities
+    , ifaceModuleAliases     = aliases
+    , ifaceInstances         = insts
+    , ifaceOrphanInstances   = [] -- Filled in attachInstances
+    , ifaceRnOrphanInstances = [] -- Filled in renameInterfaceRn
+    , ifaceHaddockCoverage   = coverage
+    , ifaceWarningMap        = warnings
+    , ifaceDynFlags          = dflags
+    }
+
+
+-- | Given all of the @import M as N@ declarations in a package,
+-- create a mapping from the module identity of M, to an alias N
+-- (if there are multiple aliases, we pick the last one.)  This
+-- will go in 'ifaceModuleAliases'.
+mkAliasMap :: UnitState -> [LImportDecl GhcRn] -> M.Map Module ModuleName
+mkAliasMap st impDecls =
+  M.fromList $
+  mapMaybe (\(SrcLoc.L _ impDecl) -> do
+    SrcLoc.L _ alias <- ideclAs impDecl
+    return
+      (lookupModuleDyn st
+         -- TODO: This is supremely dodgy, because in general the
+         -- UnitId isn't going to look anything like the package
+         -- qualifier (even with old versions of GHC, the
+         -- IPID would be p-0.1, but a package qualifier never
+         -- has a version number it.  (Is it possible that in
+         -- Haddock-land, the UnitIds never have version numbers?
+         -- I, ezyang, have not quite understand Haddock's package
+         -- identifier model.)
+         --
+         -- Additionally, this is simulating some logic GHC already
+         -- has for deciding how to qualify names when it outputs
+         -- them to the user.  We should reuse that information;
+         -- or at least reuse the renamed imports, which know what
+         -- they import!
+         (ideclPkgQual impDecl)
+         (case ideclName impDecl of SrcLoc.L _ name -> name),
+       alias))
+    impDecls
+
+-- We want to know which modules are imported without any qualification. This
+-- way we can display module reexports more compactly. This mapping also looks
+-- through aliases:
+--
+-- module M (module X) where
+--   import M1 as X
+--   import M2 as X
+--
+-- With our mapping we know that we can display exported modules M1 and M2.
+--
+unrestrictedModuleImports :: [ImportDecl GhcRn] -> M.Map ModuleName [ModuleName]
+unrestrictedModuleImports idecls =
+  M.map (map (unLoc . ideclName))
+  $ M.filter (all isInteresting) impModMap
+  where
+    impModMap =
+      M.fromListWith (++) (concatMap moduleMapping idecls)
+
+    moduleMapping idecl =
+      concat [ [ (unLoc (ideclName idecl), [idecl]) ]
+             , [ (unLoc mod_name, [idecl])
+               | Just mod_name <- [ideclAs idecl]
+               ]
+             ]
+
+    isInteresting idecl =
+      case ideclImportList idecl of
+        -- i) no subset selected
+        Nothing             -> True
+        -- ii) an import with a hiding clause
+        -- without any names
+        Just (EverythingBut, L _ []) -> True
+        -- iii) any other case of qualification
+        _                   -> False
+
+-- Similar to GHC.lookupModule
+-- ezyang: Not really...
+lookupModuleDyn ::
+  UnitState -> PkgQual -> ModuleName -> Module
+lookupModuleDyn st pkg_qual mdlName = case pkg_qual of
+  OtherPkg uid -> Module.mkModule (RealUnit (Definite uid)) mdlName
+  ThisPkg uid  -> Module.mkModule (RealUnit (Definite uid)) mdlName
+  NoPkgQual    -> case lookupModuleInAllUnits st mdlName of
+    (m,_):_ -> m
+    [] -> Module.mkModule Module.mainUnit mdlName
+
+-- | Prune a 'ClsInst' down to a 'HaddockClsInst'. The goal is to remove as much
+-- unnecessary information from the 'ClsInst' as possible by precomputing the
+-- information we eventually want from it.
+fromClsInst
+  :: Bool
+  -- ^ Was Hoogle output requested?
+  -> DynFlags
+  -- ^ GHC session dynflags
+  -> UnitState
+  -- ^ GHC session dynflags
+  -> ClsInst
+  -- ^ Class instance to convert
+  -> HaddockClsInst
+  -- ^ Resulting Haddock class instance
+fromClsInst doHoogle dflags unitState inst =
+    HaddockClsInst
+      { haddockClsInstPprHoogle =
+          if doHoogle then Just (ppInstance inst) else Nothing
+      , haddockClsInstName = getName inst
+      , haddockClsInstClsName = getName cls
+      , haddockClsInstIsOrphan = isOrphan $ is_orphan inst
+      , haddockClsInstSynified = synifyInstHead instSig
+      , haddockClsInstHead = instHead instSig
+      , haddockClsInstTyNames =
+          foldl' (\ns t -> ns `Set.union` typeNames t) Set.empty tys
+      }
+  where
+    instSig :: ([TyVar], [Type], Class, [Type])
+    instSig@(_,_,cls,tys) = instanceSig inst
+
+    ppInstance :: ClsInst -> String
+    ppInstance i =
+        dropComment $ outWith (showSDocForUser dflags unitState alwaysQualify) i'
+      where
+        -- As per #168, we don't want safety information about the class
+        -- in Hoogle output. The easiest way to achieve this is to set the
+        -- safety information to a state where the Outputable instance
+        -- produces no output which means no overlap and unsafe (or [safe]
+        -- is generated).
+        i' = i { is_flag = OverlapFlag { overlapMode = NoOverlap NoSourceText
+                                        , isSafeOverlap = False } }
+
+        dropComment :: String -> String
+        dropComment (' ':'-':'-':' ':_) = []
+        dropComment (x:xs) = x : dropComment xs
+        dropComment [] = []
+
+
+-------------------------------------------------------------------------------
+-- Warnings
+-------------------------------------------------------------------------------
+
+mkWarningMap
+  :: MonadIO m
+  => DynFlags
+  -> Warnings a
+  -> GlobalRdrEnv
+  -> [Name]
+  -> IfM m WarningMap
+mkWarningMap dflags warnings gre exps = case warnings of
+  NoWarnings  -> pure M.empty
+  WarnAll _   -> pure M.empty
+  WarnSome ws ->
+    let ws' = [ (n, w)
+              | (occ, w) <- ws
+              , elt <- lookupGlobalRdrEnv gre occ
+              , let n = greMangledName elt, n `elem` exps ]
+    in M.fromList <$> traverse (bitraverse pure (parseWarning dflags gre)) ws'
+
+moduleWarning
+  :: MonadIO m
+  => DynFlags
+  -> GlobalRdrEnv
+  -> Warnings a
+  -> IfM m (Maybe (Doc Name))
+moduleWarning _ _ NoWarnings = pure Nothing
+moduleWarning _ _ (WarnSome _) = pure Nothing
+moduleWarning dflags gre (WarnAll w) = Just <$> parseWarning dflags gre w
+
+parseWarning
+  :: MonadIO m
+  => DynFlags
+  -> GlobalRdrEnv
+  -> WarningTxt a
+  -> IfM m (Doc Name)
+parseWarning dflags gre w = case w of
+  DeprecatedTxt _ msg -> format "Deprecated: " (foldMap (unpackFS . sl_fs . hsDocString . unLoc) msg)
+  WarningTxt    _ msg -> format "Warning: "    (foldMap (unpackFS . sl_fs . hsDocString . unLoc) msg)
+  where
+    format x bs = DocWarning . DocParagraph . DocAppend (DocString x)
+                  <$> processDocStringFromString dflags gre bs
+
+
+-------------------------------------------------------------------------------
+-- Doc options
+--
+-- Haddock options that are embedded in the source file
+-------------------------------------------------------------------------------
+
+mkDocOpts :: MonadIO m => Maybe String -> [Flag] -> Module -> IfM m [DocOption]
+mkDocOpts mbOpts flags mdl = do
+  opts <- case mbOpts of
+    Just opts -> case words $ replace ',' ' ' opts of
+      [] -> warn "No option supplied to DOC_OPTION/doc_option" >> return []
+      xs -> fmap catMaybes (mapM parseOption xs)
+    Nothing -> return []
+  pure (foldl go opts flags)
+  where
+    mdlStr = moduleString mdl
+
+    -- Later flags override earlier ones
+    go os m | m == Flag_HideModule mdlStr     = OptHide : os
+            | m == Flag_ShowModule mdlStr     = filter (/= OptHide) os
+            | m == Flag_ShowAllModules        = filter (/= OptHide) os
+            | m == Flag_IgnoreAllExports      = OptIgnoreExports : os
+            | m == Flag_ShowExtensions mdlStr = OptIgnoreExports : os
+            | otherwise                       = os
+
+parseOption :: MonadIO m => String -> IfM m (Maybe DocOption)
+parseOption "hide"            = return (Just OptHide)
+parseOption "prune"           = return (Just OptPrune)
+parseOption "ignore-exports"  = return (Just OptIgnoreExports)
+parseOption "not-home"        = return (Just OptNotHome)
+parseOption "show-extensions" = return (Just OptShowExtensions)
+parseOption other = warn ("Unrecognised option: " ++ other) >> return Nothing
+
+--------------------------------------------------------------------------------
+-- Maps
+--------------------------------------------------------------------------------
+
+
+type Maps = (DocMap Name, ArgMap Name, DeclMap, InstMap)
+
+-- | Create 'Maps' by looping through the declarations. For each declaration,
+-- find its names, its subordinates, and its doc strings. Process doc strings
+-- into 'Doc's.
+mkMaps
+  :: MonadIO m
+  => DynFlags
+  -> Maybe Package  -- this package
+  -> GlobalRdrEnv
+  -> [Name]
+  -> [(LHsDecl GhcRn, [HsDoc GhcRn])]
+  -> ExtractedTHDocs -- ^ Template Haskell putDoc docs
+  -> IfM m Maps
+mkMaps dflags pkgName gre instances decls thDocs = do
+  (a, b, c) <- unzip3 <$> traverse mappings decls
+  (th_a, th_b) <- thMappings
+  pure ( force $
+           th_a `M.union` f' (map (nubByName fst) a)
+       , force $
+           fmap intmap2mapint $
+             th_b `unionArgMaps` (f (filterMapping (not . IM.null) b))
+       , f c
+       , instanceMap
+       )
+  where
+    f :: (Ord a, Semigroup b) => [[(a, b)]] -> Map a b
+    f = M.fromListWith (<>) . concat
+
+    f' :: [[(Name, MDoc Name)]] -> Map Name (MDoc Name)
+    f' = M.fromListWith metaDocAppend . concat
+
+    filterMapping :: (b -> Bool) ->  [[(a, b)]] -> [[(a, b)]]
+    filterMapping p = map (filter (p . snd))
+
+    -- Convert IntMap -> IntMap
+    -- TODO: should ArgMap eventually be switched over to IntMap?
+    intmap2mapint = M.fromList . IM.toList
+
+    -- | Extract the mappings from template haskell.
+    -- No DeclMap/InstMap is needed since we already have access to the
+    -- doc strings
+    thMappings
+      :: MonadIO m
+      => IfM m (Map Name (MDoc Name), Map Name (IntMap (MDoc Name)))
+    thMappings = do
+      let ExtractedTHDocs
+            _
+            declDocs
+            argDocs
+            instDocs = thDocs
+          ds2mdoc :: MonadIO m => (HsDoc GhcRn) -> IfM m (MDoc Name)
+          ds2mdoc = processDocStringParas dflags pkgName gre . hsDocString
+
+      let cvt = M.fromList . nonDetEltsUniqMap
+
+      declDocs' <- mapM ds2mdoc (cvt declDocs)
+      argDocs'  <- mapM (mapM ds2mdoc) (cvt argDocs)
+      instDocs' <- mapM ds2mdoc (cvt instDocs)
+      return (declDocs' <> instDocs', argDocs')
+
+
+    mappings
+      :: MonadIO m
+      => (LHsDecl GhcRn, [HsDoc GhcRn])
+      -> IfM m
+         ( [(Name, MDoc Name)]
+         , [(Name, IntMap (MDoc Name))]
+         , [(Name, DeclMapEntry)]
+         )
+    mappings (ldecl@(L (SrcSpanAnn _ (RealSrcSpan l _)) decl), hs_docStrs) = do
+      let docStrs = map hsDocString hs_docStrs
+          declDoc
+            :: MonadIO m
+            => [HsDocString]
+            -> IntMap HsDocString
+            -> IfM m (Maybe (MDoc Name), IntMap (MDoc Name))
+          declDoc strs m = do
+            doc' <- processDocStrings dflags pkgName gre strs
+            m'   <- traverse (processDocStringParas dflags pkgName gre) m
+            pure (doc', m')
+
+      (!doc, !args) <- force <$> declDoc docStrs (fmap hsDocString (declTypeDocs decl))
+
+      let
+          subs :: [(Name, [HsDocString], IntMap HsDocString)]
+          subs = map (\(n, ds, im) -> (n, map hsDocString ds, fmap hsDocString im))
+                  $ subordinates emptyOccEnv instanceMap decl
+
+      (subDocs, subArgs) <- unzip <$> traverse (\(_, strs, m) -> declDoc strs m) subs
+
+      let
+          ns = names l decl
+          subNs = [ n | (n, _, _) <- subs ]
+          dm = [ (n, d) | (n, Just d) <- zip ns (repeat doc) ++ zip subNs subDocs ]
+          am = [ (n, args) | n <- ns ] ++ zip subNs subArgs
+          cm = [ (n, toDeclMapEntry ldecl) | n <- ns ++ subNs ]
+
+      seqList ns `seq`
+        seqList subNs `seq`
+        doc `seq`
+        seqList subDocs `seq`
+        seqList subArgs `seq`
+        pure (dm, am, cm)
+    mappings (L (SrcSpanAnn _ (UnhelpfulSpan _)) _, _) = pure ([], [], [])
+
+    instanceMap :: Map RealSrcSpan Name
+    instanceMap = M.fromList [(l, n) | n <- instances, RealSrcSpan l _ <- [getSrcSpan n] ]
+
+    names :: RealSrcSpan -> HsDecl GhcRn -> [Name]
+    names _ (InstD _ d) = maybeToList (SrcLoc.lookupSrcSpan loc instanceMap) -- See note [2].
+      where loc = case d of
+              -- The CoAx's loc is the whole line, but only for TFs. The
+              -- workaround is to dig into the family instance declaration and
+              -- get the identifier with the right location.
+              TyFamInstD _ (TyFamInstDecl _ d') -> getLocA (feqn_tycon d')
+              _ -> getInstLoc d
+    names l (DerivD {}) = maybeToList (M.lookup l instanceMap) -- See note [2].
+    names _ decl = getMainDeclBinder emptyOccEnv decl
+
+-- | Unions together two 'ArgDocMaps' (or ArgMaps in haddock-api), such that two
+-- maps with values for the same key merge the inner map as well.
+-- Left biased so @unionArgMaps a b@ prefers @a@ over @b@.
+
+unionArgMaps :: forall b . Map Name (IntMap b)
+             -> Map Name (IntMap b)
+             -> Map Name (IntMap b)
+unionArgMaps a b = M.foldrWithKey go b a
+  where
+    go :: Name -> IntMap b
+            -> Map Name (IntMap b) -> Map Name (IntMap b)
+    go n newArgMap acc
+      | Just oldArgMap <- M.lookup n acc =
+          M.insert n (newArgMap `IM.union` oldArgMap) acc
+      | otherwise = M.insert n newArgMap acc
+
+-- Note [2]:
+------------
+-- We relate ClsInsts to InstDecls and DerivDecls using the SrcSpans buried
+-- inside them. That should work for normal user-written instances (from
+-- looking at GHC sources). We can assume that commented instances are
+-- user-written. This lets us relate Names (from ClsInsts) to comments
+-- (associated with InstDecls and DerivDecls).
+
+--------------------------------------------------------------------------------
+-- Declarations
+--------------------------------------------------------------------------------
+
+-- | Extract a map of fixity declarations only
+mkFixMap :: HsGroup GhcRn -> FixMap
+mkFixMap group_ =
+  M.fromList [ (n,f)
+             | L _ (FixitySig _ ns f) <- hsGroupTopLevelFixitySigs group_,
+               L _ n <- ns ]
+
+
+-- | Build the list of items that will become the documentation, from the
+-- export list.  At this point, the list of ExportItems is in terms of
+-- original names.
+--
+-- We create the export items even if the module is hidden, since they
+-- might be useful when creating the export items for other modules.
+mkExportItems
+  :: MonadIO m
+  => Bool               -- is it a signature
+  -> IfaceMap
+  -> Maybe Package      -- this package
+  -> Module             -- this module
+  -> Module             -- semantic module
+  -> WarningMap
+  -> GlobalRdrEnv
+  -> [Name]             -- exported names (orig)
+  -> [LHsDecl GhcRn]    -- renamed source declarations
+  -> Maps
+  -> FixMap
+  -> M.Map ModuleName [ModuleName]
+  -> [SrcSpan]          -- splice locations
+  -> Maybe [(IE GhcRn, Avails)]
+  -> Avails             -- exported stuff from this module
+  -> InstIfaceMap
+  -> DynFlags
+  -> IfM m [ExportItem GhcRn]
+mkExportItems
+  is_sig modMap pkgName thisMod semMod warnings gre exportedNames decls
+  maps fixMap unrestricted_imp_mods splices exportList allExports
+  instIfaceMap dflags =
+  case exportList of
+    Nothing      -> do
+      fullModuleContents is_sig modMap pkgName thisMod semMod warnings gre
+        exportedNames decls maps fixMap splices instIfaceMap dflags
+        allExports
+    Just exports -> fmap concat $ mapM lookupExport exports
+  where
+    lookupExport (IEGroup _ lev docStr, _) = do
+      !doc <- force <$> processDocString dflags gre (hsDocString . unLoc $ docStr)
+      return [ExportGroup lev "" doc]
+
+    lookupExport (IEDoc _ docStr, _) = do
+      !doc <- force <$> processDocStringParas dflags pkgName gre (hsDocString . unLoc $ docStr)
+      return [ExportDoc doc]
+
+    lookupExport (IEDocNamed _ str, _) =
+      findNamedDoc str [ unL d | d <- decls ] >>= \case
+        Nothing -> return  []
+        Just docStr -> do
+          !doc <- force <$> processDocStringParas dflags pkgName gre docStr
+          return [ExportDoc doc]
+
+    lookupExport (IEModuleContents _ (L _ mod_name), _)
+      -- only consider exporting a module if we are sure we
+      -- are really exporting the whole module and not some
+      -- subset. We also look through module aliases here.
+      | Just mods <- M.lookup mod_name unrestricted_imp_mods
+      , not (null mods)
+      = concat <$> traverse (moduleExport thisMod dflags modMap instIfaceMap) mods
+
+    lookupExport (_, avails) = concat <$> traverse availExport (nubAvails avails)
+
+    availExport avail =
+      availExportItem is_sig modMap thisMod semMod warnings exportedNames
+        maps fixMap splices instIfaceMap dflags avail
+
+
+-- Extract the minimal complete definition of a Name, if one exists
+minimalDef :: Monad m => Name -> IfM m (Maybe ClassMinimalDef)
+minimalDef n = do
+  mty <- lookupName n
+  case mty of
+    Just (ATyCon (tyConClass_maybe -> Just c)) ->
+      return . Just $ classMinimalDef c
+    _ ->
+      return Nothing
+
+
+availExportItem
+  :: forall m
+  .  MonadIO m
+  => Bool               -- is it a signature
+  -> IfaceMap
+  -> Module             -- this module
+  -> Module             -- semantic module
+  -> WarningMap
+  -> [Name]             -- exported names (orig)
+  -> Maps
+  -> FixMap
+  -> [SrcSpan]          -- splice locations
+  -> InstIfaceMap
+  -> DynFlags
+  -> AvailInfo
+  -> IfM m [ExportItem GhcRn]
+availExportItem is_sig modMap thisMod semMod warnings exportedNames
+  (docMap, argMap, declMap, _) fixMap splices instIfaceMap
+  dflags availInfo = declWith availInfo
+  where
+    declWith :: AvailInfo -> IfM m [ ExportItem GhcRn ]
+    declWith avail = do
+      let t = availName avail
+      r    <- findDecl avail
+      case r of
+        (Just (EValD srcSpan), (doc, _)) -> do
+          -- Since the DeclMapEntry is an 'EValD', we know the declaration is a
+          -- top-level binding without a type signature. We get type information
+          -- for the binding from the GHC interface file using the
+          -- 'hiValExportItem' function
+          export <- hiValExportItem dflags t srcSpan doc (srcSpan `elem` splices) $ M.lookup t fixMap
+          return [export]
+
+        (Just (EOther d), docs_) ->
+          let declNames = getMainDeclBinder emptyOccEnv (unL d)
+          in case () of
+            _
+              -- If 't' is not the main declaration binder, then it is a
+              -- subordinate name in the declaration. If any of its parents are
+              -- also exported, we do not want to show its documentation by
+              -- itself. See note [1].
+              | t `notElem` declNames,
+                Just p <- find isExported (parents t $ unL d) -> do
+                  warn $
+                     "Warning: " ++ moduleString thisMod ++ ": " ++
+                     pretty dflags (nameOccName t) ++ " is exported separately but " ++
+                     "will be documented under " ++ pretty dflags (nameOccName p) ++
+                     ". Consider exporting it together with its parent(s)" ++
+                     " for code clarity."
+                  return []
+
+              -- normal case
+              | otherwise -> case d of
+                  -- A single signature might refer to many names, but we
+                  -- create an export item for a single name only.  So we
+                  -- modify the signature to contain only that single name.
+                  L loc (SigD _ sig) ->
+                    -- fromJust is safe since we already checked in guards
+                    -- that 't' is a name declared in this declaration.
+                    let newDecl = L loc . SigD noExtField . fromJust $ filterSigNames (== t) sig
+                    in availExportDecl avail newDecl docs_
+
+                  L loc (TyClD _ ClassDecl {..}) -> do
+                    mdef <- minimalDef t
+                    let sig = maybeToList $ fmap (noLocA . MinimalSig (noAnn, NoSourceText) . noLocA . fmap noLocA) mdef
+                    availExportDecl avail
+                      (L loc $ TyClD noExtField ClassDecl { tcdSigs = sig ++ tcdSigs, .. }) docs_
+
+                  _ -> availExportDecl avail d docs_
+
+        -- Declaration from another package
+        (Nothing, _) -> do
+          mayDecl <- hiDecl dflags t
+          case mayDecl of
+            Nothing -> return [ ExportNoDecl t [] ]
+            Just decl ->
+              -- We try to get the subs and docs
+              -- from the installed .haddock file for that package.
+              -- TODO: This needs to be more sophisticated to deal
+              -- with signature inheritance
+              case M.lookup (nameModule t) instIfaceMap of
+                Nothing -> do
+                  warn $ "Warning: Couldn't find .haddock for export " ++ pretty dflags t
+                  let subs_ = availNoDocs avail
+                  availExportDecl avail decl (noDocForDecl, subs_)
+                Just iface ->
+                  availExportDecl avail decl (lookupDocs avail warnings (instDocMap iface) (instArgMap iface))
+
+    -- Tries 'extractDecl' first then falls back to 'hiDecl' if that fails
+    availDecl :: Name -> LHsDecl GhcRn -> IfM m (LHsDecl GhcRn)
+    availDecl declName parentDecl =
+      case extractDecl declMap declName parentDecl of
+        Right d -> pure d
+        Left err -> do
+          synifiedDeclOpt <- hiDecl dflags declName
+          case synifiedDeclOpt of
+            Just synifiedDecl -> pure synifiedDecl
+            Nothing -> pprPanic "availExportItem" (O.text err)
+
+    availExportDecl :: AvailInfo -> LHsDecl GhcRn
+                    -> (DocForDecl Name, [(Name, DocForDecl Name)])
+                    -> IfM m [ ExportItem GhcRn ]
+    availExportDecl avail decl (doc, subs)
+      | availExportsDecl avail = do
+          extractedDecl <- availDecl (availName avail) decl
+
+          -- bundled pattern synonyms only make sense if the declaration is
+          -- exported (otherwise there would be nothing to bundle to)
+          bundledPatSyns <- findBundledPatterns avail
+
+          let
+            !patSynNames = force $
+              concatMap (getMainDeclBinder emptyOccEnv . fst) bundledPatSyns
+
+            !doc'  = force doc
+            !subs' = force subs
+
+            !restrictToNames = force $ fmap fst subs'
+
+            !fixities = force
+                [ (n, f)
+                | n <- availName avail : fmap fst subs' ++ patSynNames
+                , Just f <- [M.lookup n fixMap]
+                ]
+
+          return
+            [ ExportDecl ExportD
+                { expDDecl      = restrictTo restrictToNames extractedDecl
+                , expDPats      = bundledPatSyns
+                , expDMbDoc     = doc'
+                , expDSubDocs   = subs'
+                , expDInstances = []
+                , expDFixities  = fixities
+                , expDSpliced   = False
+                }
+            ]
+
+      | otherwise = for subs $ \(sub, sub_doc) -> do
+          extractedDecl <- availDecl sub decl
+
+          let
+            !fixities = force [ (sub, f) | Just f <- [M.lookup sub fixMap] ]
+            !subDoc   = force sub_doc
+
+          return $
+            ExportDecl ExportD
+              { expDDecl      = extractedDecl
+              , expDPats      = []
+              , expDMbDoc     = subDoc
+              , expDSubDocs   = []
+              , expDInstances = []
+              , expDFixities  = fixities
+              , expDSpliced   = False
+              }
+
+    exportedNameSet = mkNameSet exportedNames
+    isExported n = elemNameSet n exportedNameSet
+
+    findDecl :: AvailInfo -> IfM m (Maybe DeclMapEntry, (DocForDecl Name, [(Name, DocForDecl Name)]))
+    findDecl avail
+      | m == semMod =
+          case M.lookup n declMap of
+            Just d -> return (Just d, lookupDocs avail warnings docMap argMap)
+            Nothing
+              | is_sig -> do
+                -- OK, so it wasn't in the local declaration map.  It could
+                -- have been inherited from a signature.  Reconstitute it
+                -- from the type.
+                mb_r <- hiDecl dflags n
+                case mb_r of
+                    Nothing -> return (Nothing, (noDocForDecl, availNoDocs avail))
+                    -- TODO: If we try harder, we might be able to find
+                    -- a Haddock!  Look in the Haddocks for each thing in
+                    -- requirementContext (unitState)
+                    Just decl -> return (Just $ toDeclMapEntry decl, (noDocForDecl, availNoDocs avail))
+              | otherwise ->
+                return (Nothing, (noDocForDecl, availNoDocs avail))
+      | Just iface <- M.lookup (semToIdMod (moduleUnit thisMod) m) modMap
+      , Just d <- M.lookup n (ifaceDeclMap iface) =
+          return (Just d, lookupDocs avail warnings
+                            (ifaceDocMap iface)
+                            (ifaceArgMap iface))
+      | otherwise = return (Nothing, (noDocForDecl, availNoDocs avail))
+      where
+        n = availName avail
+        m = nameModule n
+
+    findBundledPatterns :: AvailInfo -> IfM m [(HsDecl GhcRn, DocForDecl Name)]
+    findBundledPatterns avail = do
+      patsyns <- for constructor_names $ \name -> do
+        mtyThing <- lookupName name
+        case mtyThing of
+          Just (AConLike PatSynCon{}) -> do
+            export_items <- declWith (Avail.avail name)
+            pure [ (unLoc patsyn_decl, patsyn_doc)
+                 | ExportDecl ExportD
+                     { expDDecl  = patsyn_decl
+                     , expDMbDoc = patsyn_doc
+                     } <- export_items
+                 ]
+          _ -> pure []
+      pure (concat patsyns)
+      where
+        constructor_names =
+          filter isDataConName (availSubordinates avail)
+
+availSubordinates :: AvailInfo -> [Name]
+availSubordinates = map greNameMangledName . availSubordinateGreNames
+
+availNoDocs :: AvailInfo -> [(Name, DocForDecl Name)]
+availNoDocs avail =
+  zip (availSubordinates avail) (repeat noDocForDecl)
+
+-- | Given a 'Module' from a 'Name', convert it into a 'Module' that
+-- we can actually find in the 'IfaceMap'.
+semToIdMod :: Unit -> Module -> Module
+semToIdMod this_uid m
+    | Module.isHoleModule m = mkModule this_uid (moduleName m)
+    | otherwise             = m
+
+hiDecl :: MonadIO m => DynFlags -> Name -> IfM m (Maybe (LHsDecl GhcRn))
+hiDecl dflags t = do
+  mayTyThing <- lookupName t
+  case mayTyThing of
+    Nothing -> do
+      warn $ "Warning: Not found in environment: " ++ pretty dflags t
+      return Nothing
+    Just x -> case tyThingToLHsDecl ShowRuntimeRep x of
+      Left m -> (warn $ bugWarn m) >> return Nothing
+      Right (m, t') -> mapM (warn . bugWarn) m >> return (Just $ noLocA t')
+    where
+      warnLine x = O.text "haddock-bug:" O.<+> O.text x O.<>
+                   O.comma O.<+> O.quotes (O.ppr t) O.<+>
+                   O.text "-- Please report this on Haddock issue tracker!"
+      bugWarn = showSDoc dflags . warnLine
+
+-- | This function is called for top-level bindings without type signatures.
+-- It gets the type signature from GHC and that means it's not going to
+-- have a meaningful 'SrcSpan'. So we pass down 'SrcSpan' for the
+-- declaration and use it instead - 'nLoc' here.
+hiValExportItem
+  :: MonadIO m => DynFlags -> Name -> SrcSpan -> DocForDecl Name -> Bool
+  -> Maybe Fixity -> IfM m (ExportItem GhcRn)
+hiValExportItem dflags name nLoc doc splice fixity = do
+  mayDecl <- hiDecl dflags name
+  case mayDecl of
+    Nothing -> return (ExportNoDecl name [])
+    Just decl -> return (ExportDecl $ ExportD (fixSpan decl) [] doc [] [] fixities splice)
+  where
+    fixSpan (L (SrcSpanAnn a l) t) = L (SrcSpanAnn a (SrcLoc.combineSrcSpans l nLoc)) t
+    fixities = case fixity of
+      Just f  -> [(name, f)]
+      Nothing -> []
+
+
+-- | Lookup docs for a declaration from maps.
+lookupDocs :: AvailInfo -> WarningMap -> DocMap Name -> ArgMap Name
+           -> (DocForDecl Name, [(Name, DocForDecl Name)])
+lookupDocs avail warningMap docMap argMap =
+  let n = availName avail in
+  let lookupArgDoc x = M.findWithDefault M.empty x argMap in
+  let doc = (lookupDoc n, lookupArgDoc n) in
+  let subDocs = [ (s, (lookupDoc s, lookupArgDoc s))
+                | s <- availSubordinates avail
+                ] in
+  (doc, subDocs)
+  where
+    lookupDoc name = Documentation (M.lookup name docMap) (M.lookup name warningMap)
+
+
+-- | Export the given module as `ExportModule`. We are not concerned with the
+-- single export items of the given module.
+moduleExport
+  :: MonadIO m
+  => Module           -- ^ Module A (identity, NOT semantic)
+  -> DynFlags         -- ^ The flags used when typechecking A
+  -> IfaceMap         -- ^ Already created interfaces
+  -> InstIfaceMap     -- ^ Interfaces in other packages
+  -> ModuleName       -- ^ The exported module
+  -> IfM m [ExportItem GhcRn] -- ^ Resulting export items
+moduleExport thisMod dflags ifaceMap instIfaceMap expMod =
+    -- NB: we constructed the identity module when looking up in
+    -- the IfaceMap.
+    case M.lookup m ifaceMap of
+      Just iface
+        | OptHide `elem` ifaceOptions iface -> return (ifaceExportItems iface)
+        | otherwise -> return [ ExportModule m ]
+
+      Nothing -> -- We have to try to find it in the installed interfaces
+                 -- (external packages).
+        case M.lookup expMod (M.mapKeys moduleName instIfaceMap) of
+          Just iface -> return [ ExportModule (instMod iface) ]
+          Nothing -> do
+            warn $
+              "Warning: " ++ pretty dflags thisMod ++ ": Could not find " ++
+              "documentation for exported module: " ++ pretty dflags expMod
+            return []
+  where
+    m = mkModule (moduleUnit thisMod) expMod -- Identity module!
+
+-- Note [1]:
+------------
+-- It is unnecessary to document a subordinate by itself at the top level if
+-- any of its parents is also documented. Furthermore, if the subordinate is a
+-- record field or a class method, documenting it under its parent
+-- indicates its special status.
+--
+-- A user might expect that it should show up separately, so we issue a
+-- warning. It's a fine opportunity to also tell the user she might want to
+-- export the subordinate through the parent export item for clarity.
+--
+-- The code removes top-level subordinates also when the parent is exported
+-- through a 'module' export. I think that is fine.
+--
+-- (For more information, see Trac #69)
+
+
+-- | Simplified variant of 'mkExportItems', where we can assume that
+-- every locally defined declaration is exported; thus, we just
+-- zip through the renamed declarations.
+
+fullModuleContents
+  :: MonadIO m
+  => Bool               -- is it a signature
+  -> IfaceMap
+  -> Maybe Package      -- this package
+  -> Module             -- this module
+  -> Module             -- semantic module
+  -> WarningMap
+  -> GlobalRdrEnv      -- ^ The renaming environment
+  -> [Name]             -- exported names (orig)
+  -> [LHsDecl GhcRn]    -- renamed source declarations
+  -> Maps
+  -> FixMap
+  -> [SrcSpan]          -- splice locations
+  -> InstIfaceMap
+  -> DynFlags
+  -> Avails
+  -> IfM m [ExportItem GhcRn]
+fullModuleContents is_sig modMap pkgName thisMod semMod warnings gre exportedNames
+  decls maps@(_, _, declMap, _) fixMap splices instIfaceMap dflags avails = do
+  let availEnv = availsToNameEnv (nubAvails avails)
+  (concat . concat) `fmap` (for decls $ \decl -> do
+    case decl of
+      (L _ (DocD _ (DocGroup lev docStr))) -> do
+        !doc <- force <$> processDocString dflags gre (hsDocString . unLoc $ docStr)
+        return [[ExportGroup lev "" doc]]
+      (L _ (DocD _ (DocCommentNamed _ docStr))) -> do
+        !doc <- force <$> processDocStringParas dflags pkgName gre (hsDocString . unLoc $ docStr)
+        return [[ExportDoc doc]]
+      (L _ (ValD _ valDecl))
+        | name:_ <- collectHsBindBinders CollNoDictBinders valDecl
+        , Just (EOther (L _ SigD{})) <- M.lookup name declMap
+        -> return []
+      _ ->
+        for (getMainDeclBinder emptyOccEnv (unLoc decl)) $ \nm -> do
+          case lookupNameEnv availEnv nm of
+            Just avail ->
+              availExportItem is_sig modMap thisMod
+                semMod warnings exportedNames maps fixMap
+                splices instIfaceMap dflags avail
+            Nothing -> pure [])
+
+-- | Sometimes the declaration we want to export is not the "main" declaration:
+-- it might be an individual record selector or a class method.  In these
+-- cases we have to extract the required declaration (and somehow cobble
+-- together a type signature for it...).
+--
+-- This function looks through the declarations in this module to try to find
+-- the one with the right name.
+extractDecl
+  :: HasCallStack
+  => DeclMap                   -- ^ all declarations in the file
+  -> Name                      -- ^ name of the declaration to extract
+  -> LHsDecl GhcRn             -- ^ parent declaration
+  -> Either String (LHsDecl GhcRn)
+extractDecl declMap name decl
+  | name `elem` getMainDeclBinder emptyOccEnv (unLoc decl) = pure decl
+  | otherwise  =
+    case unLoc decl of
+      TyClD _ d@ClassDecl { tcdLName = L _ clsNm
+                          , tcdSigs = clsSigs
+                          , tcdATs = clsATs } ->
+        let
+          matchesMethod =
+            [ lsig
+            | lsig <- clsSigs
+            , ClassOpSig _ False _ _ <- pure $ unLoc lsig
+              -- Note: exclude `default` declarations (see #505)
+            , name `elem` sigName lsig
+            ]
+
+          matchesAssociatedType =
+            [ lfam_decl
+            | lfam_decl <- clsATs
+            , name == unLoc (fdLName (unLoc lfam_decl))
+            ]
+
+            -- TODO: document fixity
+        in case (matchesMethod, matchesAssociatedType)  of
+          ([s0], _) -> let tyvar_names = tyClDeclTyVars d
+                           L pos sig = addClassContext clsNm tyvar_names s0
+                       in pure (L pos (SigD noExtField sig))
+          (_, [L pos fam_decl]) -> pure (L pos (TyClD noExtField (FamDecl noExtField fam_decl)))
+
+          ([], [])
+            | Just (EOther famInstDecl) <- M.lookup name declMap
+            -> extractDecl declMap name famInstDecl
+          _ -> Left (concat [ "Ambiguous decl for ", getOccString name
+                            , " in class ", getOccString clsNm ])
+
+      TyClD _ d@DataDecl { tcdLName = L _ dataNm
+                         , tcdDataDefn = HsDataDefn { dd_cons = dataCons } } -> do
+        let ty_args = lHsQTyVarsToTypes (tyClDeclTyVars d)
+        lsig <- if isDataConName name
+                  then extractPatternSyn name dataNm ty_args (toList dataCons)
+                  else extractRecSel name dataNm ty_args (toList dataCons)
+        pure (SigD noExtField <$> lsig)
+
+      TyClD _ FamDecl {}
+        | isValName name
+        , Just (EOther famInst) <- M.lookup name declMap
+        -> extractDecl declMap name famInst
+      InstD _ (DataFamInstD _ (DataFamInstDecl
+                            (FamEqn { feqn_tycon = L _ n
+                                    , feqn_pats  = tys
+                                    , feqn_rhs   = defn }))) ->
+        if isDataConName name
+        then fmap (SigD noExtField) <$> extractPatternSyn name n tys (toList $ dd_cons defn)
+        else fmap (SigD noExtField) <$> extractRecSel name n tys (toList $ dd_cons defn)
+      InstD _ (ClsInstD _ ClsInstDecl { cid_datafam_insts = insts })
+        | isDataConName name ->
+            let matches = [ d' | L _ d'@(DataFamInstDecl (FamEqn { feqn_rhs = dd })) <- insts
+                               , name `elem` map unLoc (concatMap (toList . getConNames . unLoc) (dd_cons dd))
+                               ]
+            in case matches of
+                [d0] -> extractDecl declMap name (noLocA (InstD noExtField (DataFamInstD noExtField d0)))
+                _    -> Left "internal: extractDecl (ClsInstD)"
+        | otherwise ->
+            let matches = [ d' | L _ d'@(DataFamInstDecl d )
+                                   <- insts
+                                 -- , L _ ConDecl { con_details = RecCon rec } <- toList $ dd_cons (feqn_rhs d)
+                               , Just rec <- toList $ getRecConArgs_maybe . unLoc <$> dd_cons (feqn_rhs d)
+                               , ConDeclField { cd_fld_names = ns } <- map unLoc (unLoc rec)
+                               , L _ n <- ns
+                               , foExt n == name
+                          ]
+            in case matches of
+              [d0] -> extractDecl declMap name (noLocA . InstD noExtField $ DataFamInstD noExtField d0)
+              _ -> Left "internal: extractDecl (ClsInstD)"
+      _ -> Left ("extractDecl: Unhandled decl for " ++ getOccString name)
+
+extractPatternSyn :: Name -> Name
+                  -> [LHsTypeArg GhcRn] -> [LConDecl GhcRn]
+                  -> Either String (LSig GhcRn)
+extractPatternSyn nm t tvs cons =
+  case filter matches cons of
+    [] -> Left . O.showSDocOneLine O.defaultSDocContext $
+          O.text "constructor pattern " O.<+> O.ppr nm O.<+> O.text "not found in type" O.<+> O.ppr t
+    con:_ -> pure (extract <$> con)
+ where
+  matches :: LConDecl GhcRn -> Bool
+  matches (L _ con) = nm `elem` (unLoc <$> getConNames con)
+  extract :: ConDecl GhcRn -> Sig GhcRn
+  extract con =
+    let args =
+          case con of
+            ConDeclH98 { con_args = con_args' } -> case con_args' of
+              PrefixCon _ args' -> map hsScaledThing args'
+              RecCon (L _ fields) -> cd_fld_type . unLoc <$> fields
+              InfixCon arg1 arg2 -> map hsScaledThing [arg1, arg2]
+            ConDeclGADT { con_g_args = con_args' } -> case con_args' of
+              PrefixConGADT args' -> map hsScaledThing args'
+              RecConGADT (L _ fields) _ -> cd_fld_type . unLoc <$> fields
+        typ = longArrow args (data_ty con)
+        typ' =
+          case con of
+            ConDeclH98 { con_mb_cxt = Just cxt } -> noLocA (HsQualTy noExtField cxt typ)
+            _ -> typ
+        typ'' = noLocA (HsQualTy noExtField (noLocA []) typ')
+    in PatSynSig noAnn [noLocA nm] (mkEmptySigType typ'')
+
+  longArrow :: [LHsType GhcRn] -> LHsType GhcRn -> LHsType GhcRn
+  longArrow inputs output = foldr (\x y -> noLocA (HsFunTy noAnn (HsUnrestrictedArrow noHsUniTok) x y)) output inputs
+
+  data_ty con
+    | ConDeclGADT{} <- con = con_res_ty con
+    | otherwise = foldl' (\x y -> noLocA (mkAppTyArg x y)) (noLocA (HsTyVar noAnn NotPromoted (noLocA t))) tvs
+                    where mkAppTyArg :: LHsType GhcRn -> LHsTypeArg GhcRn -> HsType GhcRn
+                          mkAppTyArg f (HsValArg ty) = HsAppTy noExtField f ty
+                          mkAppTyArg f (HsTypeArg l ki) = HsAppKindTy l f ki
+                          mkAppTyArg f (HsArgPar _) = HsParTy noAnn f
+
+extractRecSel :: Name -> Name -> [LHsTypeArg GhcRn] -> [LConDecl GhcRn]
+              -> Either String (LSig GhcRn)
+extractRecSel _ _ _ [] = Left "extractRecSel: selector not found"
+
+extractRecSel nm t tvs (L _ con : rest) =
+  case getRecConArgs_maybe con of
+    Just (L _ fields) | ((l,L _ (ConDeclField _ _nn ty _)) : _) <- matching_fields fields ->
+      pure (L (noAnnSrcSpan l) (TypeSig noAnn [noLocA nm] (mkEmptyWildCardBndrs $ mkEmptySigType (noLocA (HsFunTy noAnn (HsUnrestrictedArrow noHsUniTok) data_ty (getBangType ty))))))
+    _ -> extractRecSel nm t tvs rest
+ where
+  matching_fields :: [LConDeclField GhcRn] -> [(SrcSpan, LConDeclField GhcRn)]
+  matching_fields flds = [ (locA l,f) | f@(L _ (ConDeclField _ ns _ _)) <- flds
+                                      , L l n <- ns, foExt n == nm ]
+  data_ty
+    -- ResTyGADT _ ty <- con_res con = ty
+    | ConDeclGADT{} <- con = con_res_ty con
+    | otherwise = foldl' (\x y -> noLocA (mkAppTyArg x y)) (noLocA (HsTyVar noAnn NotPromoted (noLocA t))) tvs
+                   where mkAppTyArg :: LHsType GhcRn -> LHsTypeArg GhcRn -> HsType GhcRn
+                         mkAppTyArg f (HsValArg ty) = HsAppTy noExtField f ty
+                         mkAppTyArg f (HsTypeArg l ki) = HsAppKindTy l f ki
+                         mkAppTyArg f (HsArgPar _) = HsParTy noAnn f
+
+-- | Keep export items with docs.
+pruneExportItems :: [ExportItem GhcRn] -> [ExportItem GhcRn]
+pruneExportItems = filter hasDoc
+  where
+    hasDoc (ExportDecl ExportD {expDMbDoc = (Documentation d _, _)}) = isJust d
+    hasDoc _ = True
+
+
+mkVisibleNames :: Maps -> [ExportItem GhcRn] -> [DocOption] -> [Name]
+mkVisibleNames (_, _, _, instMap) exports opts
+  | OptHide `elem` opts = []
+  | otherwise = let ns = concatMap exportName exports
+                in seqList ns `seq` ns
+  where
+    exportName (ExportDecl e@ExportD{}) = name ++ subs ++ patsyns
+      where subs    = map fst (expDSubDocs e)
+            patsyns = concatMap (getMainDeclBinder emptyOccEnv . fst) (expDPats e)
+            name = case unLoc $ expDDecl e of
+              InstD _ d -> maybeToList $ SrcLoc.lookupSrcSpan (getInstLoc d) instMap
+              decl      -> getMainDeclBinder emptyOccEnv decl
+    exportName ExportNoDecl {} = [] -- we don't count these as visible, since
+                                    -- we don't want links to go to them.
+    exportName _ = []
+
+seqList :: [a] -> ()
+seqList [] = ()
+seqList (x : xs) = x `seq` seqList xs
+
+-- | Find a stand-alone documentation comment by its name.
+findNamedDoc :: MonadIO m => String -> [HsDecl GhcRn] -> IfM m (Maybe HsDocString)
+findNamedDoc name = search
+  where
+    search [] = do
+      -- TODO: Make sure this isn't duplicating messages
+      warn $ "Cannot find documentation for: $" ++ name
+      return Nothing
+    search (DocD _ (DocCommentNamed name' doc) : rest)
+      | name == name' = return (Just (hsDocString . unLoc $ doc))
+
+      | otherwise = search rest
+    search (_other_decl : rest) = search rest
diff --git a/haddock-api/src/Haddock/Interface/Json.hs b/haddock-api/src/Haddock/Interface/Json.hs
new file mode 100644
--- /dev/null
+++ b/haddock-api/src/Haddock/Interface/Json.hs
@@ -0,0 +1,268 @@
+{-# LANGUAGE RecordWildCards #-}
+module Haddock.Interface.Json (
+    jsonInstalledInterface
+  , jsonInterfaceFile
+  , renderJson
+  ) where
+
+import GHC.Types.Fixity
+import GHC.Utils.Json
+import GHC.Unit.Module
+import GHC.Types.Name
+import GHC.Utils.Outputable
+
+import Control.Arrow
+import Data.Map (Map)
+import qualified Data.Map as Map
+
+import Haddock.Types
+import Haddock.InterfaceFile
+
+jsonInterfaceFile :: InterfaceFile -> JsonDoc
+jsonInterfaceFile InterfaceFile{..} =
+  jsonObject [ ("link_env" , jsonMap nameStableString (jsonString . moduleNameString . moduleName) ifLinkEnv)
+             , ("inst_ifaces", jsonArray (map jsonInstalledInterface ifInstalledIfaces))
+             ]
+
+jsonInstalledInterface :: InstalledInterface -> JsonDoc
+jsonInstalledInterface InstalledInterface{..} = jsonObject properties
+  where
+    properties =
+      [ ("module"          , jsonModule instMod)
+      , ("is_sig"          , jsonBool instIsSig)
+      , ("info"            , jsonHaddockModInfo instInfo)
+      , ("doc_map"         , jsonMap nameStableString jsonMDoc instDocMap)
+      , ("arg_map"         , jsonMap nameStableString (jsonMap show jsonMDoc) instArgMap)
+      , ("exports"         , jsonArray (map jsonName instExports))
+      , ("visible_exports" , jsonArray (map jsonName instVisibleExports))
+      , ("options"         , jsonArray (map (jsonString . show) instOptions))
+      , ("fix_map"         , jsonMap nameStableString jsonFixity instFixMap)
+      ]
+
+jsonHaddockModInfo :: HaddockModInfo Name -> JsonDoc
+jsonHaddockModInfo HaddockModInfo{..} =
+  jsonObject [ ("description" , jsonMaybe jsonDoc hmi_description)
+             , ("copyright"   , jsonMaybe jsonString hmi_copyright)
+             , ("maintainer"  , jsonMaybe jsonString hmi_maintainer)
+             , ("stability"   , jsonMaybe jsonString hmi_stability)
+             , ("protability" , jsonMaybe jsonString hmi_portability)
+             , ("safety"      , jsonMaybe jsonString hmi_safety)
+             , ("language"    , jsonMaybe (jsonString . show) hmi_language)
+             , ("extensions"  , jsonArray (map (jsonString . show) hmi_extensions))
+             ]
+
+jsonMap :: (a -> String) -> (b -> JsonDoc) -> Map a b -> JsonDoc
+jsonMap f g = jsonObject . map (f *** g) . Map.toList
+
+jsonMDoc :: MDoc Name -> JsonDoc
+jsonMDoc MetaDoc{..} =
+  jsonObject [ ("meta", jsonObject [("version", jsonMaybe (jsonString . show) (_version _meta))])
+             , ("document",  jsonDoc _doc)
+             ]
+
+showModName :: Wrap (ModuleName, OccName) -> String
+showModName = showWrapped (moduleNameString . fst)
+
+showName :: Wrap Name -> String
+showName = showWrapped nameStableString
+
+
+jsonDoc :: Doc Name -> JsonDoc
+
+jsonDoc DocEmpty = jsonObject
+    [ ("tag", jsonString "DocEmpty") ]
+
+jsonDoc (DocAppend x y) = jsonObject
+    [ ("tag", jsonString "DocAppend")
+    , ("first", jsonDoc x)
+    , ("second", jsonDoc y)
+    ]
+
+jsonDoc (DocString s) = jsonObject
+    [ ("tag", jsonString "DocString")
+    , ("string", jsonString s)
+    ]
+
+jsonDoc (DocParagraph x) = jsonObject
+    [ ("tag", jsonString "DocParagraph")
+    , ("document", jsonDoc x)
+    ]
+
+jsonDoc (DocIdentifier name) = jsonObject
+    [ ("tag", jsonString "DocIdentifier")
+    , ("name", jsonString (showName name))
+    ]
+
+jsonDoc (DocIdentifierUnchecked modName) = jsonObject
+    [ ("tag", jsonString "DocIdentifierUnchecked")
+    , ("modName", jsonString (showModName modName))
+    ]
+
+jsonDoc (DocModule (ModLink m _l)) = jsonObject
+    [ ("tag", jsonString "DocModule")
+    , ("string", jsonString m)
+    ]
+
+jsonDoc (DocWarning x) = jsonObject
+    [ ("tag", jsonString "DocWarning")
+    , ("document", jsonDoc x)
+    ]
+
+jsonDoc (DocEmphasis x) = jsonObject
+    [ ("tag", jsonString "DocEmphasis")
+    , ("document", jsonDoc x)
+    ]
+
+jsonDoc (DocMonospaced x) = jsonObject
+    [ ("tag", jsonString "DocMonospaced")
+    , ("document", jsonDoc x)
+    ]
+
+jsonDoc (DocBold x) = jsonObject
+    [ ("tag", jsonString "DocBold")
+    , ("document", jsonDoc x)
+    ]
+
+jsonDoc (DocUnorderedList xs) = jsonObject
+    [ ("tag", jsonString "DocUnorderedList")
+    , ("documents", jsonArray (fmap jsonDoc xs))
+    ]
+
+jsonDoc (DocOrderedList xs) = jsonObject
+    [ ("tag", jsonString "DocOrderedList")
+    , ("items", jsonArray (fmap jsonItem xs))
+    ]
+  where
+    jsonItem (index, a) = jsonObject [("document", jsonDoc a), ("seq", jsonInt index)]
+
+jsonDoc (DocDefList xys) = jsonObject
+    [ ("tag", jsonString "DocDefList")
+    , ("definitions", jsonArray (fmap jsonDef xys))
+    ]
+  where
+    jsonDef (x, y) = jsonObject [("document", jsonDoc x), ("y", jsonDoc y)]
+
+jsonDoc (DocCodeBlock x) = jsonObject
+    [ ("tag", jsonString "DocCodeBlock")
+    , ("document", jsonDoc x)
+    ]
+
+jsonDoc (DocHyperlink hyperlink) = jsonObject
+    [ ("tag", jsonString "DocHyperlink")
+    , ("hyperlink", jsonHyperlink hyperlink)
+    ]
+  where
+    jsonHyperlink Hyperlink{..} = jsonObject
+        [ ("hyperlinkUrl", jsonString hyperlinkUrl)
+        , ("hyperlinkLabel", jsonMaybe jsonDoc hyperlinkLabel)
+        ]
+
+jsonDoc (DocPic picture) = jsonObject
+    [ ("tag", jsonString "DocPic")
+    , ("picture", jsonPicture picture)
+    ]
+  where
+    jsonPicture Picture{..} = jsonObject
+        [ ("pictureUrl", jsonString pictureUri)
+        , ("pictureLabel", jsonMaybe jsonString pictureTitle)
+        ]
+
+jsonDoc (DocMathInline s) = jsonObject
+    [ ("tag", jsonString "DocMathInline")
+    , ("string", jsonString s)
+    ]
+
+jsonDoc (DocMathDisplay s) = jsonObject
+    [ ("tag", jsonString "DocMathDisplay")
+    , ("string", jsonString s)
+    ]
+
+jsonDoc (DocAName s) = jsonObject
+    [ ("tag", jsonString "DocAName")
+    , ("string", jsonString s)
+    ]
+
+jsonDoc (DocProperty s) = jsonObject
+    [ ("tag", jsonString "DocProperty")
+    , ("string", jsonString s)
+    ]
+
+jsonDoc (DocExamples examples) = jsonObject
+    [ ("tag", jsonString "DocExamples")
+    , ("examples", jsonArray (fmap jsonExample examples))
+    ]
+  where
+    jsonExample Example{..} = jsonObject
+        [ ("exampleExpression", jsonString exampleExpression)
+        , ("exampleResult", jsonArray (fmap jsonString exampleResult))
+        ]
+
+jsonDoc (DocHeader header) = jsonObject
+    [ ("tag", jsonString "DocHeader")
+    , ("header", jsonHeader header)
+    ]
+  where
+    jsonHeader Header{..} = jsonObject
+        [ ("headerLevel", jsonInt headerLevel)
+        , ("headerTitle", jsonDoc headerTitle)
+        ]
+
+jsonDoc (DocTable table) = jsonObject
+    [ ("tag", jsonString "DocTable")
+    , ("table", jsonTable table)
+    ]
+  where
+    jsonTable Table{..} = jsonObject
+        [ ("tableHeaderRows", jsonArray (fmap jsonTableRow tableHeaderRows))
+        , ("tableBodyRows", jsonArray (fmap jsonTableRow tableBodyRows))
+        ]
+
+    jsonTableRow TableRow{..} = jsonArray (fmap jsonTableCell tableRowCells)
+
+    jsonTableCell TableCell{..} = jsonObject
+        [ ("tableCellColspan", jsonInt tableCellColspan)
+        , ("tableCellRowspan", jsonInt tableCellRowspan)
+        , ("tableCellContents", jsonDoc tableCellContents)
+        ]
+
+
+jsonModule :: Module -> JsonDoc
+jsonModule = JSString . moduleStableString
+
+jsonName :: Name -> JsonDoc
+jsonName = JSString . nameStableString
+
+jsonFixity :: Fixity -> JsonDoc
+jsonFixity (Fixity _ prec dir) =
+  jsonObject [ ("prec"      , jsonInt prec)
+             , ("direction" , jsonFixityDirection dir)
+             ]
+
+jsonFixityDirection :: FixityDirection -> JsonDoc
+jsonFixityDirection InfixL = jsonString "infixl"
+jsonFixityDirection InfixR = jsonString "infixr"
+jsonFixityDirection InfixN = jsonString "infix"
+
+renderJson :: JsonDoc -> SDoc
+renderJson = renderJSON
+
+jsonMaybe :: (a -> JsonDoc) -> Maybe a -> JsonDoc
+jsonMaybe = maybe jsonNull
+
+jsonString :: String -> JsonDoc
+jsonString = JSString
+
+jsonObject :: [(String, JsonDoc)] -> JsonDoc
+jsonObject = JSObject
+
+jsonArray :: [JsonDoc] -> JsonDoc
+jsonArray = JSArray
+
+jsonNull :: JsonDoc
+jsonNull = JSNull
+
+jsonInt :: Int -> JsonDoc
+jsonInt = JSInt
+
+jsonBool :: Bool -> JsonDoc
+jsonBool = JSBool
diff --git a/haddock-api/src/Haddock/Interface/LexParseRn.hs b/haddock-api/src/Haddock/Interface/LexParseRn.hs
new file mode 100644
--- /dev/null
+++ b/haddock-api/src/Haddock/Interface/LexParseRn.hs
@@ -0,0 +1,312 @@
+{-# LANGUAGE BangPatterns     #-}
+{-# LANGUAGE FlexibleContexts #-}
+{-# LANGUAGE ViewPatterns     #-}
+{-# OPTIONS_GHC -Wwarn #-}
+  -----------------------------------------------------------------------------
+-- |
+-- Module      :  Haddock.Interface.LexParseRn
+-- Copyright   :  (c) Isaac Dupree 2009,
+--                    Mateusz Kowalczyk 2013
+-- License     :  BSD-like
+--
+-- Maintainer  :  haddock@projects.haskell.org
+-- Stability   :  experimental
+-- Portability :  portable
+-----------------------------------------------------------------------------
+module Haddock.Interface.LexParseRn
+  ( processDocString
+  , processDocStringFromString
+  , processDocStringParas
+  , processDocStrings
+  , processModuleHeader
+  ) where
+
+import Control.Arrow
+import Control.Monad
+import Control.Monad.State.Strict
+import Data.Functor
+import Data.List ((\\), maximumBy)
+import Data.Ord
+import qualified Data.Set as Set
+import Documentation.Haddock.Doc (metaDocConcat)
+import GHC.Driver.Session (languageExtensions)
+import qualified GHC.LanguageExtensions as LangExt
+import GHC
+import Haddock.Interface.ParseModuleHeader
+import Haddock.Parser
+import Haddock.Types
+import GHC.Data.EnumSet as EnumSet
+import GHC.Driver.Ppr ( showPpr, showSDoc )
+import GHC.Parser.PostProcess
+import GHC.Types.Name
+import GHC.Types.Avail ( availName )
+import GHC.Types.Name.Reader
+import GHC.Utils.Outputable (Outputable)
+
+processDocStrings
+  :: MonadIO m
+  => DynFlags
+  -> Maybe Package
+  -> GlobalRdrEnv
+  -> [HsDocString]
+  -> IfM m (Maybe (MDoc Name))
+processDocStrings dflags pkg gre strs = do
+  mdoc <- metaDocConcat <$> traverse (processDocStringParas dflags pkg gre) strs
+  case mdoc of
+    -- We check that we don't have any version info to render instead
+    -- of just checking if there is no comment: there may not be a
+    -- comment but we still want to pass through any meta data.
+    MetaDoc { _meta = Meta Nothing Nothing, _doc = DocEmpty } -> pure Nothing
+    x -> pure (Just x)
+
+processDocStringParas
+  :: MonadIO m
+  => DynFlags
+  -> Maybe Package
+  -> GlobalRdrEnv
+  -> HsDocString
+  -> IfM m (MDoc Name)
+processDocStringParas dflags pkg gre hds =
+    overDocF (rename dflags gre) (parseParas dflags pkg (renderHsDocString hds))
+
+processDocString
+  :: MonadIO m
+  => DynFlags
+  -> GlobalRdrEnv
+  -> HsDocString
+  -> IfM m (Doc Name)
+processDocString dflags gre hds =
+    processDocStringFromString dflags gre (renderHsDocString hds)
+
+processDocStringFromString
+  :: MonadIO m
+  => DynFlags
+  -> GlobalRdrEnv
+  -> String
+  -> IfM m (Doc Name)
+processDocStringFromString dflags gre hds =
+    rename dflags gre (parseString dflags hds)
+
+processModuleHeader
+  :: MonadIO m
+  => DynFlags
+  -> Maybe Package
+  -> GlobalRdrEnv
+  -> SafeHaskellMode
+  -> Maybe HsDocString
+  -> IfM m (HaddockModInfo Name, Maybe (MDoc Name))
+processModuleHeader dflags pkgName gre safety mayStr = do
+  (hmi, doc) <-
+    case mayStr of
+      Nothing -> return failure
+      Just hds -> do
+        let str = renderHsDocString hds
+            (hmi, doc) = parseModuleHeader dflags pkgName str
+        !descr <- case hmi_description hmi of
+                    Just hmi_descr -> Just <$> rename dflags gre hmi_descr
+                    Nothing        -> pure Nothing
+        let hmi' = hmi { hmi_description = descr }
+        doc'  <- overDocF (rename dflags gre) doc
+        return (hmi', Just doc')
+
+  let flags :: [LangExt.Extension]
+      -- We remove the flags implied by the language setting and we display the language instead
+      flags = EnumSet.toList (extensionFlags dflags) \\ languageExtensions (language dflags)
+  return
+    (hmi { hmi_safety = Just $ showPpr dflags safety
+         , hmi_language = language dflags
+         , hmi_extensions = flags
+         }
+    , doc
+    )
+  where
+    failure = (emptyHaddockModInfo, Nothing)
+
+traverseSnd :: (Traversable t, Applicative f) => (a -> f b) -> t (x, a) -> f (t (x, b))
+traverseSnd f = traverse (\(x, a) ->
+                             (\b -> (x, b)) <$> f a)
+
+-- | Takes a 'GlobalRdrEnv' which (hopefully) contains all the
+-- definitions and a parsed comment and we attempt to make sense of
+-- where the identifiers in the comment point to. We're in effect
+-- trying to convert 'RdrName's to 'Name's, with some guesswork and
+-- fallbacks in case we can't locate the identifiers.
+--
+-- See the comments in the source for implementation commentary.
+rename
+  :: MonadIO m
+  => DynFlags
+  -> GlobalRdrEnv
+  -> Doc NsRdrName
+  -> IfM m (Doc Name)
+rename dflags gre = rn
+  where
+    rn :: MonadIO m => Doc NsRdrName -> IfM m (Doc Name)
+    rn d = case d of
+      DocAppend a b -> DocAppend <$> rn a <*> rn b
+      DocParagraph p -> DocParagraph <$> rn p
+      DocIdentifier i -> do
+        let NsRdrName ns x = unwrap i
+            occ = rdrNameOcc x
+            isValueName = isDataOcc occ || isVarOcc occ
+
+        let valueNsChoices | isValueName = [x]
+                           | otherwise   = [] -- is this ever possible?
+            typeNsChoices  | isValueName = [setRdrNameSpace x tcName]
+                           | otherwise   = [x]
+
+        -- Generate the choices for the possible kind of thing this
+        -- is. We narrow down the possibilities with the namespace (if
+        -- there is one).
+        let choices = case ns of
+                        Value -> valueNsChoices
+                        Type  -> typeNsChoices
+                        None  -> valueNsChoices ++ typeNsChoices
+
+        -- Lookup any GlobalRdrElts that match the choices.
+        case concatMap (\c -> lookupGRE_RdrName c gre) choices of
+          -- We found no names in the env so we start guessing.
+          [] ->
+            case choices of
+              -- The only way this can happen is if a value namespace was
+              -- specified on something that cannot be a value.
+              [] -> invalidValue dflags i
+
+              -- There was nothing in the environment so we need to
+              -- pick some default from what's available to us. We
+              -- diverge here from the old way where we would default
+              -- to type constructors as we're much more likely to
+              -- actually want anchors to regular definitions than
+              -- type constructor names (such as in #253). So now we
+              -- only get type constructor links if they are actually
+              -- in scope.
+              a:_ -> outOfScope dflags ns (i $> a)
+
+          -- There is only one name in the environment that matches so
+          -- use it.
+          [a] -> pure $ DocIdentifier (i $> greMangledName a)
+
+          -- There are multiple names available.
+          gres -> ambiguous dflags i gres
+
+      DocWarning dw -> DocWarning <$> rn dw
+      DocEmphasis de -> DocEmphasis <$> rn de
+      DocBold db -> DocBold <$> rn db
+      DocMonospaced dm -> DocMonospaced <$> rn dm
+      DocUnorderedList docs -> DocUnorderedList <$> traverse rn docs
+      DocOrderedList docs -> DocOrderedList <$> traverseSnd rn docs
+      DocDefList list -> DocDefList <$> traverse (\(a, b) -> (,) <$> rn a <*> rn b) list
+      DocCodeBlock dcb -> DocCodeBlock <$> rn dcb
+      DocIdentifierUnchecked x -> pure (DocIdentifierUnchecked x)
+      DocModule (ModLink m l) -> DocModule . ModLink m <$> traverse rn l
+      DocHyperlink (Hyperlink u l) -> DocHyperlink . Hyperlink u <$> traverse rn l
+      DocPic str -> pure (DocPic str)
+      DocMathInline str -> pure (DocMathInline str)
+      DocMathDisplay str -> pure (DocMathDisplay str)
+      DocAName str -> pure (DocAName str)
+      DocProperty p -> pure (DocProperty p)
+      DocExamples e -> pure (DocExamples e)
+      DocEmpty -> pure (DocEmpty)
+      DocString str -> pure (DocString str)
+      DocHeader (Header l t) -> DocHeader . Header l <$> rn t
+      DocTable t -> DocTable <$> traverse rn t
+
+-- | Wrap an identifier that's out of scope (i.e. wasn't found in
+-- 'GlobalReaderEnv' during 'rename') in an appropriate doc. Currently
+-- we simply monospace the identifier in most cases except when the
+-- identifier is qualified: if the identifier is qualified then we can
+-- still try to guess and generate anchors across modules but the
+-- users shouldn't rely on this doing the right thing. See tickets
+-- #253 and #375 on the confusion this causes depending on which
+-- default we pick in 'rename'.
+outOfScope :: MonadIO m => DynFlags -> Namespace -> Wrap RdrName -> IfM m (Doc a)
+outOfScope dflags ns x =
+    case unwrap x of
+      Unqual occ -> warnAndMonospace (x $> occ)
+      Qual mdl occ -> pure (DocIdentifierUnchecked (x $> (mdl, occ)))
+      Orig _ occ -> warnAndMonospace (x $> occ)
+      Exact name -> warnAndMonospace (x $> name)  -- Shouldn't happen since x is out of scope
+  where
+    prefix =
+      case ns of
+        Value -> "the value "
+        Type -> "the type "
+        None -> ""
+
+    warnAndMonospace :: (MonadIO m, Outputable a) => Wrap a -> IfM m (DocH mod id)
+    warnAndMonospace a = do
+      let a' = showWrapped (showPpr dflags) a
+
+      -- If we have already warned for this identifier, don't warn again
+      firstWarn <- Set.notMember a' <$> gets ifeOutOfScopeNames
+      when firstWarn $ do
+        warn $
+          "Warning: " ++ prefix ++ "'" ++ a' ++ "' is out of scope.\n" ++
+          "    If you qualify the identifier, haddock can try to link it anyway."
+        modify' (\env -> env { ifeOutOfScopeNames = Set.insert a' (ifeOutOfScopeNames env) })
+
+      pure (monospaced a')
+    monospaced = DocMonospaced . DocString
+
+-- | Handle ambiguous identifiers.
+--
+-- Prefers local names primarily and type constructors or class names secondarily.
+--
+-- Emits a warning if the 'GlobalRdrElts's don't belong to the same type or class.
+ambiguous
+  :: MonadIO m
+  => DynFlags
+  -> Wrap NsRdrName
+  -> [GlobalRdrElt] -- ^ More than one @gre@s sharing the same `RdrName` above.
+  -> IfM m (Doc Name)
+ambiguous dflags x gres = do
+    let noChildren = map availName (gresToAvailInfo gres)
+        dflt = maximumBy (comparing (isLocalName &&& isTyConName)) noChildren
+        nameStr = showNsRdrName dflags x
+        msg = "Warning: " ++ nameStr ++ " is ambiguous. It is defined\n" ++
+              concatMap (\n -> "    * " ++ defnLoc n ++ "\n") (map greMangledName gres) ++
+              "    You may be able to disambiguate the identifier by qualifying it or\n" ++
+              "    by specifying the type/value namespace explicitly.\n" ++
+              "    Defaulting to the one defined " ++ defnLoc dflt
+
+    -- TODO: Once we have a syntax for namespace qualification (#667) we may also
+    -- want to emit a warning when an identifier is a data constructor for a type
+    -- of the same name, but not the only constructor.
+    -- For example, for @data D = C | D@, someone may want to reference the @D@
+    -- constructor.
+
+    -- If we have already warned for this name, do not warn again
+    firstWarn <- Set.notMember nameStr <$> gets ifeAmbiguousNames
+    when (length noChildren > 1 && firstWarn) $ do
+      warn msg
+      modify' (\env -> env { ifeAmbiguousNames = Set.insert nameStr (ifeAmbiguousNames env) })
+
+    pure (DocIdentifier (x $> dflt))
+  where
+    isLocalName (nameSrcLoc -> RealSrcLoc {}) = True
+    isLocalName _ = False
+    defnLoc = showSDoc dflags . pprNameDefnLoc
+
+-- | Handle value-namespaced names that cannot be for values.
+--
+-- Emits a warning that the value-namespace is invalid on a non-value identifier.
+invalidValue :: MonadIO m => DynFlags -> Wrap NsRdrName -> IfM m (Doc a)
+invalidValue dflags x = do
+    let nameStr = showNsRdrName dflags x
+
+    -- If we have already warned for this name, do not warn again
+    firstWarn <- Set.notMember nameStr <$> gets ifeInvalidValues
+    when firstWarn $ do
+      warn $
+        "Warning: " ++ nameStr ++ " cannot be value, yet it is\n" ++
+        "    namespaced as such. Did you mean to specify a type namespace\n" ++
+        "    instead?"
+      modify' (\env -> env { ifeInvalidValues = Set.insert nameStr (ifeInvalidValues env) })
+    pure (DocMonospaced (DocString (showNsRdrName dflags x)))
+
+-- | Printable representation of a wrapped and namespaced name
+showNsRdrName :: DynFlags -> Wrap NsRdrName -> String
+showNsRdrName dflags = (\p i -> p ++ "'" ++ i ++ "'") <$> prefix <*> ident
+  where
+    ident = showWrapped (showPpr dflags . rdrName)
+    prefix = renderNs . namespace . unwrap
diff --git a/haddock-api/src/Haddock/Interface/ParseModuleHeader.hs b/haddock-api/src/Haddock/Interface/ParseModuleHeader.hs
new file mode 100644
--- /dev/null
+++ b/haddock-api/src/Haddock/Interface/ParseModuleHeader.hs
@@ -0,0 +1,189 @@
+{-# OPTIONS_GHC -Wwarn #-}
+{-# LANGUAGE DeriveFunctor #-}
+
+-----------------------------------------------------------------------------
+-- |
+-- Module      :  Haddock.Interface.ParseModuleHeader
+-- Copyright   :  (c) Simon Marlow 2006, Isaac Dupree 2009
+-- License     :  BSD-like
+--
+-- Maintainer  :  haddock@projects.haskell.org
+-- Stability   :  experimental
+-- Portability :  portable
+-----------------------------------------------------------------------------
+module Haddock.Interface.ParseModuleHeader (parseModuleHeader) where
+
+import Control.Applicative (Alternative (..))
+import Control.Monad (ap)
+import Data.Char
+import GHC.Driver.Session
+import Haddock.Parser
+import Haddock.Types
+
+-- -----------------------------------------------------------------------------
+-- Parsing module headers
+
+-- NB.  The headers must be given in the order Module, Description,
+-- Copyright, License, Maintainer, Stability, Portability, except that
+-- any or all may be omitted.
+parseModuleHeader :: DynFlags -> Maybe Package -> String -> (HaddockModInfo NsRdrName, MDoc NsRdrName)
+parseModuleHeader dflags pkgName str0 =
+   let
+      kvs :: [(String, String)]
+      str1 :: String
+
+      (kvs, str1) = maybe ([], str0) id $ runP fields str0
+
+      -- trim whitespaces
+      trim :: String -> String
+      trim = dropWhile isSpace . reverse . dropWhile isSpace . reverse
+
+      getKey :: String -> Maybe String
+      getKey key = fmap trim (lookup key kvs)
+
+      descriptionOpt = getKey "Description"
+      copyrightOpt   = getKey "Copyright"
+      licenseOpt     = getKey "License"
+      licenceOpt     = getKey "Licence"
+      spdxLicenceOpt = getKey "SPDX-License-Identifier"
+      maintainerOpt  = getKey "Maintainer"
+      stabilityOpt   = getKey "Stability"
+      portabilityOpt = getKey "Portability"
+
+   in (HaddockModInfo {
+          hmi_description = parseString dflags <$> descriptionOpt,
+          hmi_copyright = copyrightOpt,
+          hmi_license = spdxLicenceOpt <|> licenseOpt <|> licenceOpt,
+          hmi_maintainer = maintainerOpt,
+          hmi_stability = stabilityOpt,
+          hmi_portability = portabilityOpt,
+          hmi_safety = Nothing,
+          hmi_language = Nothing, -- set in LexParseRn
+          hmi_extensions = [] -- also set in LexParseRn
+          }, parseParas dflags pkgName str1)
+
+-------------------------------------------------------------------------------
+-- Small parser to parse module header.
+-------------------------------------------------------------------------------
+
+-- | The below is a small parser framework how we read keys.
+--
+-- all fields in the header are optional and have the form
+--
+-- [spaces1][field name][spaces] ":"
+--    [text]"\n" ([spaces2][space][text]"\n" | [spaces]"\n")*
+-- where each [spaces2] should have [spaces1] as a prefix.
+--
+-- Thus for the key "Description",
+--
+-- > Description : this is a
+-- >    rather long
+-- >
+-- >    description
+-- >
+-- > The module comment starts here
+--
+-- the value will be "this is a .. description" and the rest will begin
+-- at "The module comment".
+
+-- | 'C' is a 'Char' carrying its column.
+--
+-- This let us make an indentation-aware parser, as we know current indentation.
+-- by looking at the next character in the stream ('curInd').
+--
+-- Thus we can munch all spaces but only not-spaces which are indented.
+--
+data C = C {-# UNPACK #-} !Int Char
+
+newtype P a = P { unP :: [C] -> Maybe ([C], a) }
+  deriving Functor
+
+instance Applicative P where
+    pure x = P $ \s -> Just (s, x)
+    (<*>)  = ap
+
+instance Monad P where
+    return = pure
+    m >>= k = P $ \s0 -> do
+        (s1, x) <- unP m s0
+        unP (k x) s1
+
+instance Alternative P where
+    empty   = P $ \_ -> Nothing
+    a <|> b = P $ \s -> unP a s <|> unP b s
+
+runP :: P a -> String -> Maybe a
+runP p input = fmap snd (unP p input')
+  where
+    input' = concat
+        [ zipWith C [0..] l ++ [C (length l) '\n']
+        | l <- lines input
+        ]
+
+-------------------------------------------------------------------------------
+--
+-------------------------------------------------------------------------------
+
+curInd :: P Int
+curInd = P $ \s -> Just . (,) s $ case s of
+    []        -> 0
+    C i _ : _ -> i
+
+rest :: P String
+rest = P $ \cs -> Just ([], [ c | C _ c <- cs ])
+
+munch :: (Int -> Char -> Bool) -> P String
+munch p = P $ \cs ->
+    let (xs,ys) = takeWhileMaybe p' cs in Just (ys, xs)
+  where
+    p' (C i c)
+        | p i c  = Just c
+        | otherwise = Nothing
+
+munch1 :: (Int -> Char -> Bool) -> P String
+munch1 p = P $ \s -> case s of
+    [] -> Nothing
+    (c:cs) | Just c' <- p' c -> let (xs,ys) = takeWhileMaybe p' cs in Just (ys, c' : xs)
+           | otherwise -> Nothing
+  where
+    p' (C i c)
+        | p i c  = Just c
+        | otherwise = Nothing
+
+char :: Char -> P Char
+char c = P $ \s -> case s of
+    []                        -> Nothing
+    (C _ c' : cs) | c == c'   -> Just (cs, c)
+                  | otherwise -> Nothing
+
+skipSpaces :: P ()
+skipSpaces = P $ \cs -> Just (dropWhile (\(C _ c) -> isSpace c) cs, ())
+
+takeWhileMaybe :: (a -> Maybe b) -> [a] -> ([b], [a])
+takeWhileMaybe f = go where
+    go xs0@[] = ([], xs0)
+    go xs0@(x:xs) = case f x of
+        Just y  -> let (ys, zs) = go xs in (y : ys, zs)
+        Nothing -> ([], xs0)
+
+-------------------------------------------------------------------------------
+-- Fields
+-------------------------------------------------------------------------------
+
+field :: Int -> P (String, String)
+field i = do
+    fn <- munch1 $ \_ c -> isAlpha c || c == '-'
+    skipSpaces
+    _ <- char ':'
+    skipSpaces
+    val <- munch $ \j c -> isSpace c || j > i
+    return (fn, val)
+
+fields :: P ([(String, String)], String)
+fields = do
+    skipSpaces
+    i  <- curInd
+    fs <- many (field i)
+    r  <- rest
+    return (fs, r)
+
diff --git a/haddock-api/src/Haddock/Interface/Rename.hs b/haddock-api/src/Haddock/Interface/Rename.hs
new file mode 100644
--- /dev/null
+++ b/haddock-api/src/Haddock/Interface/Rename.hs
@@ -0,0 +1,819 @@
+{-# LANGUAGE BangPatterns               #-}
+{-# LANGUAGE RecordWildCards            #-}
+{-# LANGUAGE TypeFamilies               #-}
+{-# LANGUAGE DerivingStrategies         #-}
+{-# LANGUAGE GeneralizedNewtypeDeriving #-}
+
+----------------------------------------------------------------------------
+-- |
+-- Module      :  Haddock.Interface.Rename
+-- Copyright   :  (c) Simon Marlow 2003-2006,
+--                    David Waern  2006-2009
+-- License     :  BSD-like
+--
+-- Maintainer  :  haddock@projects.haskell.org
+-- Stability   :  experimental
+-- Portability :  portable
+-----------------------------------------------------------------------------
+module Haddock.Interface.Rename (renameInterface) where
+
+
+import Data.Traversable (mapM)
+
+import Haddock.Backends.Hoogle (ppExportD)
+import Haddock.GhcUtils
+import Haddock.Types
+
+import GHC.Data.Bag (emptyBag)
+import GHC hiding (NoLink)
+import GHC.Types.Name
+import GHC.Types.Name.Reader (RdrName(Exact))
+import GHC.Builtin.Types (eqTyCon_RDR)
+
+import Control.Applicative
+import Control.DeepSeq (force)
+import Control.Monad hiding (mapM)
+import Control.Monad.Reader
+import Control.Monad.Writer.CPS
+import Data.Foldable (traverse_)
+import qualified Data.Map.Strict as Map
+import qualified Data.Set as Set
+import Prelude hiding (mapM)
+import GHC.Types.Basic ( TopLevelFlag(..) )
+
+-- | Traverse docstrings and ASTs in the Haddock interface, renaming 'Name' to
+-- 'DocName'.
+--
+-- What this really boils down to is: for each 'Name', figure out which of the
+-- modules that export the name is the preferred place to link to.
+--
+-- The renamed output gets written into fields in the Haddock interface record
+-- that were previously left empty.
+renameInterface
+  :: DynFlags
+  -- ^ GHC session dyn flags
+  -> Map.Map (Maybe String) (Set.Set String)
+  -- ^ Ignored symbols. A map from module names to unqualified names. Module
+  -- 'Just M' mapping to name 'f' means that link warnings should not be
+  -- generated for occurances of specifically 'M.f'. Module 'Nothing' mapping to
+  -- name 'f' means that link warnings should not be generated for any 'f'.
+  -> LinkEnv
+  -- ^ Link environment. A map from 'Name' to 'Module', where name 'n' maps to
+  -- module 'M' if 'M' is the preferred link destination for name 'n'.
+  -> Bool
+  -- ^ Are warnings enabled?
+  -> Bool
+  -- ^ Is Hoogle output enabled?
+  -> Interface
+  -- ^ The interface we are renaming.
+  -> Ghc Interface
+  -- ^ The renamed interface. Note that there is nothing really special about
+  -- this being in the 'Ghc' monad. This could very easily be any 'MonadIO' or
+  -- even pure, depending on the link warnings are reported.
+renameInterface dflags ignoreSet renamingEnv warnings hoogle iface = do
+    let (iface', warnedNames) =
+          runRnM
+            dflags
+            mdl
+            localLinkEnv
+            warnName
+            (hoogle && not (OptHide `elem` ifaceOptions iface))
+            (renameInterfaceRn iface)
+    reportMissingLinks mdl warnedNames
+    return iface'
+  where
+    -- The current module
+    mdl :: Module
+    mdl = ifaceMod iface
+
+    -- The local link environment, where every name exported by this module is
+    -- mapped to the module itself, and everything else comes from the global
+    -- renaming env
+    localLinkEnv :: LinkEnv
+    localLinkEnv = foldr f renamingEnv (ifaceVisibleExports iface)
+      where f name !env = Map.insert name mdl env
+
+    -- The function used to determine whether we should warn about a name
+    -- which we do not find in the renaming environment
+    warnName name =
+           -- Warnings must be enabled
+           warnings
+
+           -- Current module must not be hidden from Haddock
+        && not (OptHide `elem` ifaceOptions iface)
+
+           -- Must be an external name that is not built-in syntax, not a type
+           -- variable, and not '~'
+        && isExternalName name
+        && not (isBuiltInSyntax name)
+        && not (isTyVarName name)
+        && Exact name /= eqTyCon_RDR
+
+           -- Must not be in the set of ignored symbols for the module or the
+           -- unqualified ignored symbols
+        && not (getOccString name `Set.member` ignoreSet')
+      where
+        -- The set of ignored symbols within the module this name is located
+        -- in unioned with the set of globally ignored symbols
+        ignoreSet' :: Set.Set String
+        ignoreSet' =
+          Set.union
+            (Map.findWithDefault Set.empty (Just $ modString name) ignoreSet)
+            (Map.findWithDefault Set.empty Nothing ignoreSet)
+
+        modString :: Name -> String
+        modString = moduleString . nameModule
+
+-- | Output warning messages indicating that the renamer could not find link
+-- destinations for the names in the given set as they occur in the given
+-- module.
+reportMissingLinks :: Module -> Set.Set Name -> Ghc ()
+reportMissingLinks mdl names
+    | Set.null names = return ()
+    | otherwise =
+        liftIO $ do
+          putStrLn $ "Warning: " ++ moduleString mdl ++ ": could not find link destinations for: "
+          traverse_ (putStrLn . ("\t- " ++) . qualifiedName) names
+  where
+    qualifiedName :: Name -> String
+    qualifiedName name = moduleString (nameModule name) ++ "." ++ getOccString name
+
+--------------------------------------------------------------------------------
+-- Monad for renaming
+--------------------------------------------------------------------------------
+
+-- | A renaming monad which provides 'MonadReader' access to a renaming
+-- environment, and 'MonadWriter' access to a 'Set' of names for which link
+-- warnings should be generated, based on the renaming environment.
+newtype RnM a = RnM { unRnM :: ReaderT RnMEnv (Writer (Set.Set Name)) a }
+  deriving newtype (Functor, Applicative, Monad, MonadReader RnMEnv, MonadWriter (Set.Set Name))
+
+-- | The renaming monad environment. Stores the linking environment (mapping
+-- names to modules), the link warning predicate, and the current module.
+data RnMEnv = RnMEnv
+    { -- | The linking environment (map from names to modules)
+      rnLinkEnv      :: LinkEnv
+
+      -- | Link warning predicate (whether failing to find a link destination
+      -- for a given name should result in a warning)
+    , rnWarnName     :: (Name -> Bool)
+
+      -- | The current module
+    , rnModuleString :: String
+
+      -- | Should Hoogle output be generated for this module?
+    , rnHoogleOutput :: Bool
+
+      -- | GHC Session DynFlags, necessary for Hoogle output generation
+    , rnDynFlags :: DynFlags
+    }
+
+-- | Run the renamer action in a renaming environment built using the given
+-- module, link env, and link warning predicate. Returns the renamed value along
+-- with a set of 'Name's that were not renamed and should be warned for (i.e.
+-- they satisfied the link warning predicate).
+runRnM :: DynFlags -> Module -> LinkEnv -> (Name -> Bool) -> Bool -> RnM a -> (a, Set.Set Name)
+runRnM dflags mdl linkEnv warnName hoogleOutput rn =
+    runWriter $ runReaderT (unRnM rn) rnEnv
+  where
+    rnEnv :: RnMEnv
+    rnEnv = RnMEnv
+      { rnLinkEnv      = linkEnv
+      , rnWarnName     = warnName
+      , rnModuleString = moduleString mdl
+      , rnHoogleOutput = hoogleOutput
+      , rnDynFlags     = dflags
+      }
+
+--------------------------------------------------------------------------------
+-- Renaming
+--------------------------------------------------------------------------------
+
+-- | Rename an `Interface` in the renaming environment.
+renameInterfaceRn :: Interface -> RnM Interface
+renameInterfaceRn iface = do
+  exportItems <- renameExportItems (ifaceExportItems iface)
+  orphans     <- mapM renameDocInstance (ifaceOrphanInstances iface)
+  finalModDoc <- renameDocumentation (ifaceDoc iface)
+  pure $! iface
+    { ifaceRnDoc             = finalModDoc
+
+    -- The un-renamed export items are not used after renaming
+    , ifaceRnExportItems     = exportItems
+    , ifaceExportItems       = []
+
+    -- The un-renamed orphan instances are not used after renaming
+    , ifaceRnOrphanInstances = orphans
+    , ifaceOrphanInstances   = []
+    }
+
+-- | Lookup a 'Name' in the renaming environment.
+lookupRn :: Name -> RnM DocName
+lookupRn name = RnM $ do
+    linkEnv <- asks rnLinkEnv
+    case Map.lookup name linkEnv of
+      Nothing  -> return $ Undocumented name
+      Just mdl -> return $ Documented name mdl
+
+-- | Rename a 'Name' in the renaming environment. This is very similar to
+-- 'lookupRn', but tracks any names not found in the renaming environment if the
+-- `rnWarnName` predicate is true.
+renameName :: Name -> RnM DocName
+renameName name = do
+    warnName <- asks rnWarnName
+    docName <- lookupRn name
+    case docName of
+      Undocumented _ -> do
+        when (warnName name) $
+          tell $ Set.singleton name
+        return docName
+      _ -> return docName
+
+-- | Rename a located 'Name' in the current renaming environment.
+renameNameL :: GenLocated l Name -> RnM (GenLocated l DocName)
+renameNameL = mapM renameName
+
+-- | Rename a list of export items in the current renaming environment.
+renameExportItems :: [ExportItem GhcRn] -> RnM [ExportItem DocNameI]
+renameExportItems = mapM renameExportItem
+
+-- | Rename an 'ExportItem' in the current renaming environment.
+renameExportItem :: ExportItem GhcRn -> RnM (ExportItem DocNameI)
+renameExportItem item = case item of
+  ExportModule mdl -> return (ExportModule mdl)
+  ExportGroup lev id_ doc -> do
+    doc' <- renameDoc doc
+    return (ExportGroup lev id_ doc')
+  ExportDecl ed@(ExportD decl pats doc subs instances fixities splice) -> do
+    -- If Hoogle output should be generated, generate it
+    RnMEnv{..} <- ask
+    let !hoogleOut = force $
+          if rnHoogleOutput then
+            ppExportD rnDynFlags ed
+          else
+            []
+
+    decl' <- renameLDecl decl
+    pats' <- renamePats pats
+    doc'  <- renameDocForDecl doc
+    subs' <- mapM renameSub subs
+    instances' <- forM instances renameDocInstance
+    fixities' <- forM fixities $ \(name, fixity) -> do
+      name' <- lookupRn name
+      return (name', fixity)
+
+    return $
+      ExportDecl RnExportD
+        { rnExpDExpD   = ExportD decl' pats' doc' subs' instances' fixities' splice
+        , rnExpDHoogle = hoogleOut
+        }
+  ExportNoDecl x subs -> do
+    x'    <- lookupRn x
+    subs' <- mapM lookupRn subs
+    return (ExportNoDecl x' subs')
+  ExportDoc doc -> do
+    doc' <- renameDoc doc
+    return (ExportDoc doc')
+
+renameDocForDecl :: DocForDecl Name -> RnM (DocForDecl DocName)
+renameDocForDecl (doc, fnArgsDoc) =
+  (,) <$> renameDocumentation doc <*> renameFnArgsDoc fnArgsDoc
+
+renameDocumentation :: Documentation Name -> RnM (Documentation DocName)
+renameDocumentation (Documentation mDoc mWarning) =
+  Documentation <$> mapM renameDoc mDoc <*> mapM renameDoc mWarning
+
+renameLDocHsSyn :: Located (WithHsDocIdentifiers HsDocString a) -> RnM (Located (WithHsDocIdentifiers HsDocString b))
+renameLDocHsSyn (L l doc) = return (L l (WithHsDocIdentifiers (hsDocString doc) []))
+
+renameDoc :: Traversable t => t (Wrap Name) -> RnM (t (Wrap DocName))
+renameDoc = traverse (traverse renameName)
+
+renameFnArgsDoc :: FnArgsDoc Name -> RnM (FnArgsDoc DocName)
+renameFnArgsDoc = mapM renameDoc
+
+renameLType :: LHsType GhcRn -> RnM (LHsType DocNameI)
+renameLType = mapM renameType
+
+renameLTypeArg :: LHsTypeArg GhcRn -> RnM (LHsTypeArg DocNameI)
+renameLTypeArg (HsValArg ty) = do { ty' <- renameLType ty
+                                     ; return $ HsValArg ty' }
+renameLTypeArg (HsTypeArg l ki) = do { ki' <- renameLKind ki
+                                     ; return $ HsTypeArg l ki' }
+renameLTypeArg (HsArgPar sp) = return $ HsArgPar sp
+
+renameLSigType :: LHsSigType GhcRn -> RnM (LHsSigType DocNameI)
+renameLSigType = mapM renameSigType
+
+renameLSigWcType :: LHsSigWcType GhcRn -> RnM (LHsSigWcType DocNameI)
+renameLSigWcType = renameWc renameLSigType
+
+renameLKind :: LHsKind GhcRn -> RnM (LHsKind DocNameI)
+renameLKind = renameLType
+
+renameMaybeLKind :: Maybe (LHsKind GhcRn) -> RnM (Maybe (LHsKind DocNameI))
+renameMaybeLKind = traverse renameLKind
+
+renameFamilyResultSig :: LFamilyResultSig GhcRn -> RnM (LFamilyResultSig DocNameI)
+renameFamilyResultSig (L loc (NoSig _))
+    = return (L loc (NoSig noExtField))
+renameFamilyResultSig (L loc (KindSig _ ki))
+    = do { ki' <- renameLKind ki
+         ; return (L loc (KindSig noExtField ki')) }
+renameFamilyResultSig (L loc (TyVarSig _ bndr))
+    = do { bndr' <- renameLTyVarBndr bndr
+         ; return (L loc (TyVarSig noExtField bndr')) }
+
+renameInjectivityAnn :: LInjectivityAnn GhcRn -> RnM (LInjectivityAnn DocNameI)
+renameInjectivityAnn (L loc (InjectivityAnn _ lhs rhs))
+    = do { lhs' <- renameNameL lhs
+         ; rhs' <- mapM renameNameL rhs
+         ; return (L loc (InjectivityAnn noExtField lhs' rhs')) }
+
+renameMaybeInjectivityAnn :: Maybe (LInjectivityAnn GhcRn)
+                          -> RnM (Maybe (LInjectivityAnn DocNameI))
+renameMaybeInjectivityAnn = traverse renameInjectivityAnn
+
+renameArrow :: HsArrow GhcRn -> RnM (HsArrow DocNameI)
+renameArrow (HsUnrestrictedArrow arr) = return (HsUnrestrictedArrow arr)
+renameArrow (HsLinearArrow (HsPct1 pct1 arr)) = return (HsLinearArrow (HsPct1 pct1 arr))
+renameArrow (HsLinearArrow (HsLolly arr)) = return (HsLinearArrow (HsLolly arr))
+renameArrow (HsExplicitMult pct p arr) = (\p' -> HsExplicitMult pct p' arr) <$> renameLType p
+
+renameType :: HsType GhcRn -> RnM (HsType DocNameI)
+renameType t = case t of
+  HsForAllTy { hst_tele = tele, hst_body = ltype } -> do
+    tele'  <- renameHsForAllTelescope tele
+    ltype' <- renameLType ltype
+    return (HsForAllTy { hst_xforall = noAnn
+                       , hst_tele = tele', hst_body = ltype' })
+
+  HsQualTy { hst_ctxt = lcontext , hst_body = ltype } -> do
+    lcontext' <- renameLContext lcontext
+    ltype'    <- renameLType ltype
+    return (HsQualTy { hst_xqual = noAnn, hst_ctxt = lcontext', hst_body = ltype' })
+
+  HsTyVar _ ip (L l n) -> return . HsTyVar noAnn ip . L l =<< renameName n
+  HsBangTy _ b ltype -> return . HsBangTy noAnn b =<< renameLType ltype
+
+  HsStarTy _ isUni -> return (HsStarTy noAnn isUni)
+
+  HsAppTy _ a b -> do
+    a' <- renameLType a
+    b' <- renameLType b
+    return (HsAppTy noAnn a' b')
+
+  HsAppKindTy _ a b -> do
+    a' <- renameLType a
+    b' <- renameLKind b
+    return (HsAppKindTy noAnn a' b')
+
+  HsFunTy _ w a b -> do
+    a' <- renameLType a
+    b' <- renameLType b
+    w' <- renameArrow w
+    return (HsFunTy noAnn w' a' b')
+
+  HsListTy _ ty -> return . (HsListTy noAnn) =<< renameLType ty
+  HsIParamTy _ n ty -> liftM (HsIParamTy noAnn n) (renameLType ty)
+
+  HsTupleTy _ b ts -> return . HsTupleTy noAnn b =<< mapM renameLType ts
+  HsSumTy _ ts -> HsSumTy noAnn <$> mapM renameLType ts
+
+  HsOpTy _ prom a (L loc op) b -> do
+    op' <- renameName op
+    a'  <- renameLType a
+    b'  <- renameLType b
+    return (HsOpTy noAnn prom a' (L loc op') b')
+
+  HsParTy _ ty -> return . (HsParTy noAnn) =<< renameLType ty
+
+  HsKindSig _ ty k -> do
+    ty' <- renameLType ty
+    k' <- renameLKind k
+    return (HsKindSig noAnn ty' k')
+
+  HsDocTy _ ty doc -> do
+    ty' <- renameLType ty
+    doc' <- renameLDocHsSyn doc
+    return (HsDocTy noAnn ty' doc')
+
+  HsTyLit _ x -> return (HsTyLit noAnn (renameTyLit x))
+
+  HsRecTy _ a               -> HsRecTy noAnn <$> mapM renameConDeclFieldField a
+  XHsType a                 -> pure (XHsType a)
+  HsExplicitListTy _ a b  -> HsExplicitListTy noAnn a <$> mapM renameLType b
+  HsExplicitTupleTy _ b   -> HsExplicitTupleTy noAnn <$> mapM renameLType b
+  HsSpliceTy (HsUntypedSpliceTop _ st)  _ -> renameType (unLoc st)
+  HsSpliceTy (HsUntypedSpliceNested _) _ -> error "renameType: not an top level type splice"
+  HsWildCardTy _          -> pure (HsWildCardTy noAnn)
+
+renameTyLit :: HsTyLit GhcRn -> HsTyLit DocNameI
+renameTyLit t = case t of
+  HsNumTy  _ v -> HsNumTy noExtField v
+  HsStrTy  _ v -> HsStrTy noExtField v
+  HsCharTy _ v -> HsCharTy noExtField v
+
+
+renameSigType :: HsSigType GhcRn -> RnM (HsSigType DocNameI)
+renameSigType (HsSig { sig_bndrs = bndrs, sig_body = body }) = do
+  bndrs' <- renameOuterTyVarBndrs bndrs
+  body'  <- renameLType body
+  pure $ HsSig { sig_ext = noExtField, sig_bndrs = bndrs', sig_body = body' }
+
+renameLHsQTyVars :: LHsQTyVars GhcRn -> RnM (LHsQTyVars DocNameI)
+renameLHsQTyVars (HsQTvs { hsq_explicit = tvs })
+  = do { tvs' <- mapM renameLTyVarBndr tvs
+       ; return (HsQTvs { hsq_ext = noExtField
+                        , hsq_explicit = tvs' }) }
+
+renameHsForAllTelescope :: HsForAllTelescope GhcRn -> RnM (HsForAllTelescope DocNameI)
+renameHsForAllTelescope tele = case tele of
+  HsForAllVis   _ bndrs -> do bndrs' <- mapM renameLTyVarBndr bndrs
+                              pure $ HsForAllVis noExtField bndrs'
+  HsForAllInvis _ bndrs -> do bndrs' <- mapM renameLTyVarBndr bndrs
+                              pure $ HsForAllInvis noExtField bndrs'
+
+renameLTyVarBndr :: LHsTyVarBndr flag GhcRn -> RnM (LHsTyVarBndr flag DocNameI)
+renameLTyVarBndr (L loc (UserTyVar _ fl (L l n)))
+  = do { n' <- renameName n
+       ; return (L loc (UserTyVar noExtField fl (L l n'))) }
+renameLTyVarBndr (L loc (KindedTyVar _ fl (L lv n) kind))
+  = do { n' <- renameName n
+       ; kind' <- renameLKind kind
+       ; return (L loc (KindedTyVar noExtField fl (L lv n') kind')) }
+
+renameLContext :: LocatedC [LHsType GhcRn] -> RnM (LocatedC [LHsType DocNameI])
+renameLContext (L loc context) = do
+  context' <- mapM renameLType context
+  return (L loc context')
+
+renameInstHead :: InstHead GhcRn -> RnM (InstHead DocNameI)
+renameInstHead InstHead {..} = do
+  cname <- renameName ihdClsName
+  types <- mapM renameType ihdTypes
+  itype <- case ihdInstType of
+    ClassInst { .. } -> ClassInst
+        <$> mapM renameType clsiCtx
+        <*> renameLHsQTyVars clsiTyVars
+        <*> mapM renameSig clsiSigs
+        <*> mapM renamePseudoFamilyDecl clsiAssocTys
+    TypeInst  ts -> TypeInst  <$> traverse renameType ts
+    DataInst  dd -> DataInst  <$> renameTyClD dd
+  return InstHead
+    { ihdClsName = cname
+    , ihdTypes = types
+    , ihdInstType = itype
+    }
+
+renameLDecl :: LHsDecl GhcRn -> RnM (LHsDecl DocNameI)
+renameLDecl (L loc d) = return . L loc =<< renameDecl d
+
+renamePats :: [(HsDecl GhcRn, DocForDecl Name)] -> RnM [(HsDecl DocNameI, DocForDecl DocName)]
+renamePats = mapM
+  (\(d,doc) -> do { d'   <- renameDecl d
+                  ; doc' <- renameDocForDecl doc
+                  ; return (d',doc')})
+
+renameDecl :: HsDecl GhcRn -> RnM (HsDecl DocNameI)
+renameDecl decl = case decl of
+  TyClD _ d -> do
+    d' <- renameTyClD d
+    return (TyClD noExtField d')
+  SigD _ s -> do
+    s' <- renameSig s
+    return (SigD noExtField s')
+  ForD _ d -> do
+    d' <- renameForD d
+    return (ForD noExtField d')
+  InstD _ d -> do
+    d' <- renameInstD d
+    return (InstD noExtField d')
+  DerivD _ d -> do
+    d' <- renameDerivD d
+    return (DerivD noExtField d')
+  _ -> error "renameDecl"
+
+renameLThing :: (a GhcRn -> RnM (a DocNameI)) -> LocatedAn an (a GhcRn) -> RnM (Located (a DocNameI))
+renameLThing fn (L loc x) = return . L (locA loc) =<< fn x
+
+renameTyClD :: TyClDecl GhcRn -> RnM (TyClDecl DocNameI)
+renameTyClD d = case d of
+--  TyFamily flav lname ltyvars kind tckind -> do
+  FamDecl { tcdFam = decl } -> do
+    decl' <- renameFamilyDecl decl
+    return (FamDecl { tcdFExt = noExtField, tcdFam = decl' })
+
+  SynDecl { tcdLName = lname, tcdTyVars = tyvars, tcdFixity = fixity, tcdRhs = rhs } -> do
+    lname'    <- renameNameL lname
+    tyvars'   <- renameLHsQTyVars tyvars
+    rhs'     <- renameLType rhs
+    return (SynDecl { tcdSExt = noExtField, tcdLName = lname', tcdTyVars = tyvars'
+                    , tcdFixity = fixity, tcdRhs = rhs' })
+
+  DataDecl { tcdLName = lname, tcdTyVars = tyvars, tcdFixity = fixity, tcdDataDefn = defn } -> do
+    lname'    <- renameNameL lname
+    tyvars'   <- renameLHsQTyVars tyvars
+    defn'     <- renameDataDefn defn
+    return (DataDecl { tcdDExt = noExtField, tcdLName = lname', tcdTyVars = tyvars'
+                     , tcdFixity = fixity, tcdDataDefn = defn' })
+
+  ClassDecl { tcdLayout = layout
+            , tcdCtxt = lcontext, tcdLName = lname, tcdTyVars = ltyvars, tcdFixity = fixity
+            , tcdFDs = lfundeps, tcdSigs = lsigs, tcdATs = ats, tcdATDefs = at_defs } -> do
+    lcontext' <- traverse renameLContext lcontext
+    lname'    <- renameNameL lname
+    ltyvars'  <- renameLHsQTyVars ltyvars
+    lfundeps' <- mapM renameLFunDep lfundeps
+    lsigs'    <- mapM renameLSig lsigs
+    ats'      <- mapM (renameLThing renameFamilyDecl) ats
+    at_defs'  <- mapM (mapM renameTyFamDefltD) at_defs
+    -- we don't need the default methods or the already collected doc entities
+    return (ClassDecl { tcdCExt = noExtField
+                      , tcdLayout = renameLayoutInfo layout
+                      , tcdCtxt = lcontext', tcdLName = lname', tcdTyVars = ltyvars'
+                      , tcdFixity = fixity
+                      , tcdFDs = lfundeps', tcdSigs = lsigs', tcdMeths= emptyBag
+                      , tcdATs = ats', tcdATDefs = at_defs', tcdDocs = [] })
+
+  where
+    renameLFunDep :: LHsFunDep GhcRn -> RnM (LHsFunDep DocNameI)
+    renameLFunDep (L loc (FunDep _ xs ys)) = do
+      xs' <- mapM renameName (map unLoc xs)
+      ys' <- mapM renameName (map unLoc ys)
+      return (L (locA loc) (FunDep noExtField (map noLocA xs') (map noLocA ys')))
+
+    renameLSig (L loc sig) = return . L (locA loc) =<< renameSig sig
+
+renameLayoutInfo :: LayoutInfo GhcRn -> LayoutInfo DocNameI
+renameLayoutInfo (ExplicitBraces ob cb) = ExplicitBraces ob cb
+renameLayoutInfo (VirtualBraces n) = VirtualBraces n
+renameLayoutInfo NoLayoutInfo = NoLayoutInfo
+
+renameFamilyDecl :: FamilyDecl GhcRn -> RnM (FamilyDecl DocNameI)
+renameFamilyDecl (FamilyDecl { fdInfo = info, fdLName = lname
+                             , fdTyVars = ltyvars
+                             , fdFixity = fixity
+                             , fdResultSig = result
+                             , fdInjectivityAnn = injectivity }) = do
+    info'        <- renameFamilyInfo info
+    lname'       <- renameNameL lname
+    ltyvars'     <- renameLHsQTyVars ltyvars
+    result'      <- renameFamilyResultSig result
+    injectivity' <- renameMaybeInjectivityAnn injectivity
+    return (FamilyDecl { fdExt = noExtField, fdInfo = info', fdTopLevel = TopLevel
+                       , fdLName = lname'
+                       , fdTyVars = ltyvars'
+                       , fdFixity = fixity
+                       , fdResultSig = result'
+                       , fdInjectivityAnn = injectivity' })
+
+
+renamePseudoFamilyDecl :: PseudoFamilyDecl GhcRn
+                       -> RnM (PseudoFamilyDecl DocNameI)
+renamePseudoFamilyDecl (PseudoFamilyDecl { .. }) =  PseudoFamilyDecl
+    <$> renameFamilyInfo pfdInfo
+    <*> renameNameL pfdLName
+    <*> mapM renameLType pfdTyVars
+    <*> renameFamilyResultSig pfdKindSig
+
+
+renameFamilyInfo :: FamilyInfo GhcRn -> RnM (FamilyInfo DocNameI)
+renameFamilyInfo DataFamily     = return DataFamily
+renameFamilyInfo OpenTypeFamily = return OpenTypeFamily
+renameFamilyInfo (ClosedTypeFamily eqns)
+  = do { eqns' <- mapM (mapM (mapM renameTyFamInstEqn)) eqns
+       ; return $ ClosedTypeFamily eqns' }
+
+renameDataDefn :: HsDataDefn GhcRn -> RnM (HsDataDefn DocNameI)
+renameDataDefn (HsDataDefn { dd_ctxt = lcontext, dd_cType = cType
+                           , dd_kindSig = k, dd_cons = cons }) = do
+    lcontext' <- traverse renameLContext lcontext
+    k'        <- renameMaybeLKind k
+    cons'     <- mapM (mapMA renameCon) cons
+    -- I don't think we need the derivings, so we return Nothing
+    return (HsDataDefn { dd_ext = noExtField
+                       , dd_ctxt = lcontext', dd_cType = cType
+                       , dd_kindSig = k', dd_cons = cons'
+                       , dd_derivs = [] })
+
+renameCon :: ConDecl GhcRn -> RnM (ConDecl DocNameI)
+renameCon decl@(ConDeclH98 { con_name = lname, con_ex_tvs = ltyvars
+                           , con_mb_cxt = lcontext, con_args = details
+                           , con_doc = mbldoc
+                           , con_forall = forall_ }) = do
+      lname'    <- renameNameL lname
+      ltyvars'  <- mapM renameLTyVarBndr ltyvars
+      lcontext' <- traverse renameLContext lcontext
+      details'  <- renameH98Details details
+      mbldoc'   <- mapM (renameLDocHsSyn) mbldoc
+      return (decl { con_ext = noExtField, con_name = lname', con_ex_tvs = ltyvars'
+                   , con_mb_cxt = lcontext'
+                   , con_forall = forall_ -- Remove when #18311 is fixed
+                   , con_args = details', con_doc = mbldoc' })
+
+renameCon ConDeclGADT { con_names = lnames, con_bndrs = bndrs
+                            , con_dcolon = dcol
+                            , con_mb_cxt = lcontext, con_g_args = details
+                            , con_res_ty = res_ty
+                            , con_doc = mbldoc } = do
+      lnames'   <- mapM renameNameL lnames
+      bndrs'    <- mapM renameOuterTyVarBndrs bndrs
+      lcontext' <- traverse renameLContext lcontext
+      details'  <- renameGADTDetails details
+      res_ty'   <- renameLType res_ty
+      mbldoc'   <- mapM renameLDocHsSyn mbldoc
+      return (ConDeclGADT
+                   { con_g_ext = noExtField, con_names = lnames'
+                   , con_dcolon = dcol, con_bndrs = bndrs'
+                   , con_mb_cxt = lcontext', con_g_args = details'
+                   , con_res_ty = res_ty', con_doc = mbldoc' })
+
+renameHsScaled :: HsScaled GhcRn (LHsType GhcRn)
+               -> RnM (HsScaled DocNameI (LHsType DocNameI))
+renameHsScaled (HsScaled w ty) = HsScaled <$> renameArrow w <*> renameLType ty
+
+renameH98Details :: HsConDeclH98Details GhcRn
+                 -> RnM (HsConDeclH98Details DocNameI)
+renameH98Details (RecCon (L l fields)) = do
+  fields' <- mapM renameConDeclFieldField fields
+  return (RecCon (L (locA l) fields'))
+renameH98Details (PrefixCon ts ps) = PrefixCon ts <$> mapM renameHsScaled ps
+renameH98Details (InfixCon a b) = do
+  a' <- renameHsScaled a
+  b' <- renameHsScaled b
+  return (InfixCon a' b')
+
+renameGADTDetails :: HsConDeclGADTDetails GhcRn
+                  -> RnM (HsConDeclGADTDetails DocNameI)
+renameGADTDetails (RecConGADT (L l fields) arr) = do
+  fields' <- mapM renameConDeclFieldField fields
+  return (RecConGADT (L (locA l) fields') arr)
+renameGADTDetails (PrefixConGADT ps) = PrefixConGADT <$> mapM renameHsScaled ps
+
+renameConDeclFieldField :: LConDeclField GhcRn -> RnM (LConDeclField DocNameI)
+renameConDeclFieldField (L l (ConDeclField _ names t doc)) = do
+  names' <- mapM renameLFieldOcc names
+  t'   <- renameLType t
+  doc' <- mapM renameLDocHsSyn doc
+  return $ L (locA l) (ConDeclField noExtField names' t' doc')
+
+renameLFieldOcc :: LFieldOcc GhcRn -> RnM (LFieldOcc DocNameI)
+renameLFieldOcc (L l (FieldOcc sel lbl)) = do
+  sel' <- renameName sel
+  return $ L l (FieldOcc sel' lbl)
+
+renameSig :: Sig GhcRn -> RnM (Sig DocNameI)
+renameSig sig = case sig of
+  TypeSig _ lnames ltype -> do
+    lnames' <- mapM renameNameL lnames
+    ltype' <- renameLSigWcType ltype
+    return (TypeSig noExtField lnames' ltype')
+  ClassOpSig _ is_default lnames sig_ty -> do
+    lnames' <- mapM renameNameL lnames
+    ltype' <- renameLSigType sig_ty
+    return (ClassOpSig noExtField is_default lnames' ltype')
+  PatSynSig _ lnames sig_ty -> do
+    lnames' <- mapM renameNameL lnames
+    sig_ty' <- renameLSigType sig_ty
+    return $ PatSynSig noExtField lnames' sig_ty'
+  FixSig _ (FixitySig _ lnames fixity) -> do
+    lnames' <- mapM renameNameL lnames
+    return $ FixSig noExtField (FixitySig noExtField lnames' fixity)
+  MinimalSig _ (L l s) -> do
+    s' <- traverse (traverse lookupRn) s
+    return $ MinimalSig noExtField (L l s')
+  -- we have filtered out all other kinds of signatures in Interface.Create
+  _ -> error "expected TypeSig"
+
+
+renameForD :: ForeignDecl GhcRn -> RnM (ForeignDecl DocNameI)
+renameForD (ForeignImport _ lname ltype x) = do
+  lname' <- renameNameL lname
+  ltype' <- renameLSigType ltype
+  return (ForeignImport noExtField lname' ltype' (renameForI x))
+renameForD (ForeignExport _ lname ltype x) = do
+  lname' <- renameNameL lname
+  ltype' <- renameLSigType ltype
+  return (ForeignExport noExtField lname' ltype' (renameForE x))
+
+renameForI :: ForeignImport GhcRn -> ForeignImport DocNameI
+renameForI (CImport _ cconv safety mHeader spec) = CImport noExtField cconv safety mHeader spec
+
+renameForE :: ForeignExport GhcRn -> ForeignExport DocNameI
+renameForE (CExport _ spec) = CExport noExtField spec
+
+
+renameInstD :: InstDecl GhcRn -> RnM (InstDecl DocNameI)
+renameInstD (ClsInstD { cid_inst = d }) = do
+  d' <- renameClsInstD d
+  return (ClsInstD { cid_d_ext = noExtField, cid_inst = d' })
+renameInstD (TyFamInstD { tfid_inst = d }) = do
+  d' <- renameTyFamInstD d
+  return (TyFamInstD { tfid_ext = noExtField, tfid_inst = d' })
+renameInstD (DataFamInstD { dfid_inst = d }) = do
+  d' <- renameDataFamInstD d
+  return (DataFamInstD { dfid_ext = noExtField, dfid_inst = d' })
+
+renameDerivD :: DerivDecl GhcRn -> RnM (DerivDecl DocNameI)
+renameDerivD (DerivDecl { deriv_type = ty
+                        , deriv_strategy = strat
+                        , deriv_overlap_mode = omode }) = do
+  ty'    <- renameLSigWcType ty
+  strat' <- mapM (mapM renameDerivStrategy) strat
+  return (DerivDecl { deriv_ext = noExtField
+                    , deriv_type = ty'
+                    , deriv_strategy = strat'
+                    , deriv_overlap_mode = omode })
+
+renameDerivStrategy :: DerivStrategy GhcRn -> RnM (DerivStrategy DocNameI)
+renameDerivStrategy (StockStrategy a)    = pure (StockStrategy a)
+renameDerivStrategy (AnyclassStrategy a) = pure (AnyclassStrategy a)
+renameDerivStrategy (NewtypeStrategy a)  = pure (NewtypeStrategy a)
+renameDerivStrategy (ViaStrategy ty)     = ViaStrategy <$> renameLSigType ty
+
+renameClsInstD :: ClsInstDecl GhcRn -> RnM (ClsInstDecl DocNameI)
+renameClsInstD (ClsInstDecl { cid_overlap_mode = omode
+                            , cid_poly_ty =ltype, cid_tyfam_insts = lATs
+                            , cid_datafam_insts = lADTs }) = do
+  ltype' <- renameLSigType ltype
+  lATs'  <- mapM (mapM renameTyFamInstD) lATs
+  lADTs' <- mapM (mapM renameDataFamInstD) lADTs
+  return (ClsInstDecl { cid_ext = noExtField, cid_overlap_mode = omode
+                      , cid_poly_ty = ltype', cid_binds = emptyBag
+                      , cid_sigs = []
+                      , cid_tyfam_insts = lATs', cid_datafam_insts = lADTs' })
+
+
+renameTyFamInstD :: TyFamInstDecl GhcRn -> RnM (TyFamInstDecl DocNameI)
+renameTyFamInstD (TyFamInstDecl { tfid_eqn = eqn })
+  = do { eqn' <- renameTyFamInstEqn eqn
+       ; return (TyFamInstDecl { tfid_xtn = noExtField, tfid_eqn = eqn' }) }
+
+renameTyFamInstEqn :: TyFamInstEqn GhcRn -> RnM (TyFamInstEqn DocNameI)
+renameTyFamInstEqn (FamEqn { feqn_tycon = tc, feqn_bndrs = bndrs
+                           , feqn_pats = pats, feqn_fixity = fixity
+                           , feqn_rhs = rhs })
+  = do { tc' <- renameNameL tc
+       ; bndrs' <- renameOuterTyVarBndrs bndrs
+       ; pats' <- mapM renameLTypeArg pats
+       ; rhs' <- renameLType rhs
+       ; return (FamEqn { feqn_ext    = noExtField
+                        , feqn_tycon  = tc'
+                        , feqn_bndrs  = bndrs'
+                        , feqn_pats   = pats'
+                        , feqn_fixity = fixity
+                        , feqn_rhs    = rhs' }) }
+
+renameTyFamDefltD :: TyFamDefltDecl GhcRn -> RnM (TyFamDefltDecl DocNameI)
+renameTyFamDefltD = renameTyFamInstD
+
+renameDataFamInstD :: DataFamInstDecl GhcRn -> RnM (DataFamInstDecl DocNameI)
+renameDataFamInstD (DataFamInstDecl { dfid_eqn = eqn })
+  = do { eqn' <- rename_data_fam_eqn eqn
+       ; return (DataFamInstDecl { dfid_eqn = eqn' }) }
+  where
+    rename_data_fam_eqn
+      :: FamEqn GhcRn (HsDataDefn GhcRn)
+      -> RnM (FamEqn DocNameI (HsDataDefn DocNameI))
+    rename_data_fam_eqn (FamEqn { feqn_tycon = tc, feqn_bndrs = bndrs
+                                , feqn_pats = pats, feqn_fixity = fixity
+                                , feqn_rhs = defn })
+      = do { tc' <- renameNameL tc
+           ; bndrs' <- renameOuterTyVarBndrs bndrs
+           ; pats' <- mapM renameLTypeArg pats
+           ; defn' <- renameDataDefn defn
+           ; return (FamEqn { feqn_ext    = noExtField
+                            , feqn_tycon  = tc'
+                            , feqn_bndrs  = bndrs'
+                            , feqn_pats   = pats'
+                            , feqn_fixity = fixity
+                            , feqn_rhs    = defn' }) }
+
+renameOuterTyVarBndrs :: HsOuterTyVarBndrs flag GhcRn
+                      -> RnM (HsOuterTyVarBndrs flag DocNameI)
+renameOuterTyVarBndrs (HsOuterImplicit{}) =
+  pure $ HsOuterImplicit{hso_ximplicit = noExtField}
+renameOuterTyVarBndrs (HsOuterExplicit{hso_bndrs = exp_bndrs}) =
+  HsOuterExplicit noExtField <$> mapM renameLTyVarBndr exp_bndrs
+
+renameWc :: (in_thing -> RnM out_thing)
+         -> HsWildCardBndrs GhcRn in_thing
+         -> RnM (HsWildCardBndrs DocNameI out_thing)
+renameWc rn_thing (HsWC { hswc_body = thing })
+  = do { thing' <- rn_thing thing
+       ; return (HsWC { hswc_body = thing'
+                      , hswc_ext = noExtField }) }
+
+renameDocInstance :: DocInstance GhcRn -> RnM (DocInstance DocNameI)
+renameDocInstance (inst, idoc, L l n, m) = do
+  inst' <- renameInstHead inst
+  n' <- renameName n
+  idoc' <- mapM renameDoc idoc
+  return (inst', idoc', L l n', m)
+
+renameSub :: (Name, DocForDecl Name) -> RnM (DocName, DocForDecl DocName)
+renameSub (n,doc) = do
+  n' <- renameName n
+  doc' <- renameDocForDecl doc
+  return (n', doc')
diff --git a/haddock-api/src/Haddock/Interface/Specialize.hs b/haddock-api/src/Haddock/Interface/Specialize.hs
new file mode 100644
--- /dev/null
+++ b/haddock-api/src/Haddock/Interface/Specialize.hs
@@ -0,0 +1,407 @@
+{-# LANGUAGE FlexibleContexts #-}
+{-# LANGUAGE Rank2Types #-}
+{-# LANGUAGE ScopedTypeVariables #-}
+{-# LANGUAGE TypeApplications #-}
+{-# LANGUAGE RecordWildCards #-}
+{-# LANGUAGE GADTs #-}
+{-# OPTIONS_GHC -Wno-incomplete-record-updates #-}
+
+module Haddock.Interface.Specialize
+    ( specializeInstHead
+    ) where
+
+
+import Haddock.GhcUtils ( hsTyVarBndrName )
+import Haddock.Syb
+import Haddock.Types
+
+import GHC
+import GHC.Types.Name
+import GHC.Data.FastString
+import GHC.Builtin.Types ( listTyConName, unrestrictedFunTyConName )
+
+import Control.Monad
+import Control.Monad.Trans.State
+
+import Data.Data
+import qualified Data.List as List
+import Data.Maybe
+import Data.Map (Map)
+import qualified Data.Map as Map
+import Data.Set (Set)
+import qualified Data.Set as Set
+
+-- | Instantiate all occurrences of given names with corresponding types.
+specialize :: Data a => [(Name, HsType GhcRn)] -> a -> a
+specialize specs = go spec_map0
+  where
+    go :: forall x. Data x => Map Name (HsType GhcRn) -> x -> x
+    go spec_map = everywhereButType @Name $ mkT $ sugar . strip_kind_sig . specialize_ty_var spec_map
+
+    strip_kind_sig :: HsType GhcRn -> HsType GhcRn
+    strip_kind_sig (HsKindSig _ (L _ t) _) = t
+    strip_kind_sig typ = typ
+
+    specialize_ty_var :: Map Name (HsType GhcRn) -> HsType GhcRn -> HsType GhcRn
+    specialize_ty_var spec_map (HsTyVar _ _ (L _ name'))
+      | Just t <- Map.lookup name' spec_map = t
+    specialize_ty_var _ typ = typ
+
+    -- This is a tricky recursive definition. By adding in the specializations
+    -- one by one, we should avoid infinite loops.
+    spec_map0 = foldr (\(n,t) acc -> Map.insert n (go acc t) acc) mempty specs
+
+{-# SPECIALIZE specialize :: [(Name, HsType GhcRn)] -> HsType GhcRn -> HsType GhcRn #-}
+
+-- | Instantiate given binders with corresponding types.
+--
+-- Again, it is just a convenience function around 'specialize'. Note that
+-- length of type list should be the same as the number of binders.
+specializeTyVarBndrs :: Data a => LHsQTyVars GhcRn -> [HsType GhcRn] -> a -> a
+specializeTyVarBndrs bndrs typs = specialize $ zip bndrs' typs
+  where
+    bndrs' = map (hsTyVarBndrName . unLoc) . hsq_explicit $ bndrs
+
+
+
+specializePseudoFamilyDecl :: LHsQTyVars GhcRn -> [HsType GhcRn]
+                           -> PseudoFamilyDecl GhcRn
+                           -> PseudoFamilyDecl GhcRn
+specializePseudoFamilyDecl bndrs typs decl =
+  decl {pfdTyVars = map (fmap (specializeTyVarBndrs bndrs typs)) (pfdTyVars decl)}
+
+specializeSig :: LHsQTyVars GhcRn -> [HsType GhcRn]
+              -> Sig GhcRn
+              -> Sig GhcRn
+specializeSig bndrs typs (TypeSig _ lnames typ) =
+  TypeSig noAnn lnames (typ {hswc_body = noLocA typ'})
+  where
+    true_type :: HsSigType GhcRn
+    true_type = unLoc (dropWildCards typ)
+    typ' :: HsSigType GhcRn
+    typ' = rename fv $ specializeTyVarBndrs bndrs typs true_type
+    fv = foldr Set.union Set.empty . map freeVariablesType $ typs
+specializeSig _ _ sig = sig
+
+
+-- | Make all details of instance head (signatures, associated types)
+-- specialized to that particular instance type.
+specializeInstHead :: InstHead GhcRn -> InstHead GhcRn
+specializeInstHead ihd@InstHead { ihdInstType = clsi@ClassInst { .. }, .. } =
+    ihd { ihdInstType = instType' }
+  where
+    instType' = clsi
+        { clsiSigs = map specializeSig' clsiSigs
+        , clsiAssocTys = map specializeFamilyDecl' clsiAssocTys
+        }
+    specializeSig' = specializeSig clsiTyVars ihdTypes
+    specializeFamilyDecl' = specializePseudoFamilyDecl clsiTyVars ihdTypes
+specializeInstHead ihd = ihd
+
+
+-- | Make given type use tuple and list literals where appropriate.
+--
+-- After applying 'specialize' function some terms may not use idiomatic list
+-- and tuple literals resulting in types like @[] a@ or @(,,) a b c@. This
+-- can be fixed using 'sugar' function, that will turn such types into @[a]@
+-- and @(a, b, c)@.
+sugar :: HsType GhcRn -> HsType GhcRn
+sugar = sugarOperators . sugarTuples . sugarLists
+
+sugarLists :: NamedThing (IdP (GhcPass p)) => HsType (GhcPass p) -> HsType (GhcPass p)
+sugarLists (HsAppTy _ (L _ (HsTyVar _ _ (L _ name))) ltyp)
+    | getName name == listTyConName = HsListTy noAnn ltyp
+sugarLists typ = typ
+
+
+sugarTuples :: NamedThing (IdP (GhcPass p)) => HsType (GhcPass p) -> HsType (GhcPass p)
+sugarTuples typ =
+    aux [] typ
+  where
+    aux apps (HsAppTy _ (L _ ftyp) atyp) = aux (atyp:apps) ftyp
+    aux apps (HsParTy _ (L _ typ')) = aux apps typ'
+    aux apps (HsTyVar _ _ (L _ name))
+        | isBuiltInSyntax name' && suitable = HsTupleTy noAnn HsBoxedOrConstraintTuple apps
+      where
+        name' = getName name
+        strName = getOccString name
+        suitable = case parseTupleArity strName of
+            Just arity -> arity == length apps
+            Nothing -> False
+    aux _ _ = typ
+
+
+sugarOperators :: HsType GhcRn -> HsType GhcRn
+sugarOperators (HsAppTy _ (L _ (HsAppTy _ (L _ (HsTyVar _ prom (L l name))) la)) lb)
+    | isSymOcc $ getOccName name' = mkHsOpTy prom la (L l name) lb
+    | unrestrictedFunTyConName == name' = HsFunTy noAnn (HsUnrestrictedArrow noHsUniTok) la lb
+  where
+    name' = getName name
+sugarOperators typ = typ
+
+
+-- | Compute arity of given tuple operator.
+--
+-- >>> parseTupleArity "(,,)"
+-- Just 3
+--
+-- >>> parseTupleArity "(,,,,)"
+-- Just 5
+--
+-- >>> parseTupleArity "abc"
+-- Nothing
+--
+-- >>> parseTupleArity "()"
+-- Nothing
+parseTupleArity :: String -> Maybe Int
+parseTupleArity ('(':commas) = do
+    n <- parseCommas commas
+    guard $ n /= 0
+    return $ n + 1
+  where
+    parseCommas (',':rest) = (+ 1) <$> parseCommas rest
+    parseCommas ")" = Just 0
+    parseCommas _ = Nothing
+parseTupleArity _ = Nothing
+
+
+-- | Haskell AST type representation.
+--
+-- This type is used for renaming (more below), essentially the ambiguous (!)
+-- version of 'Name'. So, why is this 'FastString' instead of 'OccName'? Well,
+-- it was 'OccName' before, but turned out that 'OccName' sometimes also
+-- contains namespace information, differentiating visually same types.
+--
+-- And 'FastString' is used because it is /visual/ part of 'OccName' - it is
+-- not converted to 'String' or alike to avoid new allocations. Additionally,
+-- since it is stored mostly in 'Set', fast comparison of 'FastString' is also
+-- quite nice.
+newtype NameRep
+   = NameRep FastString
+   deriving (Eq)
+
+instance Ord NameRep where
+   compare (NameRep fs1) (NameRep fs2) = uniqCompareFS fs1 fs2
+
+
+getNameRep :: NamedThing name => name -> NameRep
+getNameRep = NameRep . getOccFS
+
+nameRepString :: NameRep -> String
+nameRepString (NameRep fs) = unpackFS fs
+
+stringNameRep :: String -> NameRep
+stringNameRep = NameRep . mkFastString
+
+setInternalNameRep :: SetName name => NameRep -> name -> name
+setInternalNameRep (NameRep fs) = setInternalOccName (mkVarOccFS fs)
+
+setInternalOccName :: SetName name => OccName -> name -> name
+setInternalOccName occ name =
+    setName nname' name
+  where
+    nname = getName name
+    nname' = mkInternalName (nameUnique nname) occ (nameSrcSpan nname)
+
+
+-- | Compute set of free variables of a given 'HsType'.
+freeVariablesType :: HsType GhcRn -> Set Name
+freeVariablesType =
+    everythingWithState Set.empty Set.union
+      (mkQ (\ctx -> (Set.empty, ctx)) queryType)
+
+-- | Compute set of free variables of a given 'HsType'.
+freeVariablesSigType :: HsSigType GhcRn -> Set Name
+freeVariablesSigType =
+    everythingWithState Set.empty Set.union
+      (mkQ (\ctx -> (Set.empty, ctx)) queryType `extQ` querySigType)
+
+queryType :: HsType GhcRn -> Set Name -> (Set Name, Set Name)
+queryType term ctx = case term of
+    HsForAllTy _ tele _ ->
+        (Set.empty, Set.union ctx (teleNames tele))
+    HsTyVar _ _ (L _ name)
+        | getName name `Set.member` ctx -> (Set.empty, ctx)
+        | otherwise -> (Set.singleton $ getName name, ctx)
+    _ -> (Set.empty, ctx)
+  where
+    teleNames :: HsForAllTelescope GhcRn -> Set Name
+    teleNames (HsForAllVis   _ bndrs) = bndrsNames bndrs
+    teleNames (HsForAllInvis _ bndrs) = bndrsNames bndrs
+
+querySigType :: HsSigType GhcRn -> Set Name -> (Set Name, Set Name)
+querySigType (HsSig { sig_bndrs = outer_bndrs }) ctx =
+  (Set.empty, Set.union ctx (bndrsNames (hsOuterExplicitBndrs outer_bndrs)))
+
+bndrsNames :: [LHsTyVarBndr flag GhcRn] -> Set Name
+bndrsNames = Set.fromList . map (getName . tyVarName . unLoc)
+
+
+-- | Make given type visually unambiguous.
+--
+-- After applying 'specialize' method, some free type variables may become
+-- visually ambiguous - for example, having @a -> b@ and specializing @a@ to
+-- @(a -> b)@ we get @(a -> b) -> b@ where first occurrence of @b@ refers to
+-- different type variable than latter one. Applying 'rename' function
+-- will fix that type to be visually unambiguous again (making it something
+-- like @(a -> b0) -> b@).
+rename :: Set Name -> HsSigType GhcRn -> HsSigType GhcRn
+rename fv typ = evalState (renameSigType typ) env
+  where
+    env = RenameEnv
+      { rneHeadFVs = Map.fromList . map mkPair . Set.toList $ fv
+      , rneSigFVs = Set.map getNameRep $ freeVariablesSigType typ
+      , rneCtx = Map.empty
+      }
+    mkPair name = (getNameRep name, name)
+
+-- | Renaming monad.
+type Rename name = State (RenameEnv name)
+
+data RenameEnv name = RenameEnv
+  { rneHeadFVs :: Map NameRep Name
+  , rneSigFVs :: Set NameRep
+  , rneCtx :: Map Name name
+  }
+
+
+renameSigType :: HsSigType GhcRn -> Rename (IdP GhcRn) (HsSigType GhcRn)
+renameSigType (HsSig x bndrs body) =
+  HsSig x <$> renameOuterTyVarBndrs bndrs <*> renameLType body
+
+renameOuterTyVarBndrs :: HsOuterTyVarBndrs flag GhcRn
+                      -> Rename (IdP GhcRn) (HsOuterTyVarBndrs flag GhcRn)
+renameOuterTyVarBndrs (HsOuterImplicit imp_tvs) =
+  HsOuterImplicit <$> mapM renameName imp_tvs
+renameOuterTyVarBndrs (HsOuterExplicit x exp_bndrs) =
+  HsOuterExplicit x <$> mapM renameLBinder exp_bndrs
+
+renameType :: HsType GhcRn -> Rename (IdP GhcRn) (HsType GhcRn)
+renameType (HsForAllTy x tele lt) =
+    HsForAllTy x
+        <$> renameForAllTelescope tele
+        <*> renameLType lt
+renameType (HsQualTy x lctxt lt) =
+    HsQualTy x
+        <$> renameLContext lctxt
+        <*> renameLType lt
+renameType (HsTyVar x ip name) = HsTyVar x ip <$> locatedN renameName name
+renameType t@(HsStarTy _ _) = pure t
+renameType (HsAppTy x lf la) = HsAppTy x <$> renameLType lf <*> renameLType la
+renameType (HsAppKindTy x lt lk) = HsAppKindTy x <$> renameLType lt <*> renameLKind lk
+renameType (HsFunTy x w la lr) = HsFunTy x <$> renameHsArrow w <*> renameLType la <*> renameLType lr
+renameType (HsListTy x lt) = HsListTy x <$> renameLType lt
+renameType (HsTupleTy x srt lt) = HsTupleTy x srt <$> mapM renameLType lt
+renameType (HsSumTy x lt) = HsSumTy x <$> mapM renameLType lt
+renameType (HsOpTy x prom la lop lb) =
+    HsOpTy x prom <$> renameLType la <*> locatedN renameName lop <*> renameLType lb
+renameType (HsParTy x lt) = HsParTy x <$> renameLType lt
+renameType (HsIParamTy x ip lt) = HsIParamTy x ip <$> renameLType lt
+renameType (HsKindSig x lt lk) = HsKindSig x <$> renameLType lt <*> pure lk
+renameType t@(HsSpliceTy _ _) = pure t
+renameType (HsDocTy x lt doc) = HsDocTy x <$> renameLType lt <*> pure doc
+renameType (HsBangTy x bang lt) = HsBangTy x bang <$> renameLType lt
+renameType t@(HsRecTy _ _) = pure t
+renameType t@(XHsType _) = pure t
+renameType (HsExplicitListTy x ip ltys) =
+    HsExplicitListTy x ip <$> renameLTypes ltys
+renameType (HsExplicitTupleTy x ltys) =
+    HsExplicitTupleTy x <$> renameLTypes ltys
+renameType t@(HsTyLit _ _) = pure t
+renameType (HsWildCardTy wc) = pure (HsWildCardTy wc)
+
+renameHsArrow :: HsArrow GhcRn -> Rename (IdP GhcRn) (HsArrow GhcRn)
+renameHsArrow (HsExplicitMult pct p arr) = (\p' -> HsExplicitMult pct p' arr) <$> renameLType p
+renameHsArrow mult = pure mult
+
+
+renameLType :: LHsType GhcRn -> Rename (IdP GhcRn) (LHsType GhcRn)
+renameLType = located renameType
+
+renameLKind :: LHsKind GhcRn -> Rename (IdP GhcRn) (LHsKind GhcRn)
+renameLKind = renameLType
+
+renameLTypes :: [LHsType GhcRn] -> Rename (IdP GhcRn) [LHsType GhcRn]
+renameLTypes = mapM renameLType
+
+renameLContext :: LHsContext GhcRn -> Rename (IdP GhcRn) (LHsContext GhcRn)
+renameLContext (L l ctxt) = do
+  ctxt' <- renameContext ctxt
+  return (L l ctxt')
+
+renameContext :: HsContext GhcRn -> Rename (IdP GhcRn) (HsContext GhcRn)
+renameContext = renameLTypes
+
+renameForAllTelescope :: HsForAllTelescope GhcRn
+                      -> Rename (IdP GhcRn) (HsForAllTelescope GhcRn)
+renameForAllTelescope (HsForAllVis x bndrs) =
+  HsForAllVis x <$> mapM renameLBinder bndrs
+renameForAllTelescope (HsForAllInvis x bndrs) =
+  HsForAllInvis x <$> mapM renameLBinder bndrs
+
+renameBinder :: HsTyVarBndr flag GhcRn -> Rename (IdP GhcRn) (HsTyVarBndr flag GhcRn)
+renameBinder (UserTyVar x fl lname) = UserTyVar x fl <$> locatedN renameName lname
+renameBinder (KindedTyVar x fl lname lkind) =
+  KindedTyVar x fl <$> locatedN renameName lname <*> located renameType lkind
+
+renameLBinder :: LHsTyVarBndr flag GhcRn -> Rename (IdP GhcRn) (LHsTyVarBndr flag GhcRn)
+renameLBinder = located renameBinder
+
+-- | Core renaming logic.
+renameName :: SetName name => name -> Rename name name
+renameName name = do
+    RenameEnv { .. } <- get
+    case Map.lookup (getName name) rneCtx of
+      Nothing
+        | Just headTv <- Map.lookup (getNameRep name) rneHeadFVs
+        , headTv /= getName name -> freshName name
+      Just name' -> return name'
+      _ -> return name
+
+
+-- | Generate fresh occurrence name, put it into context and return.
+freshName :: SetName name => name -> Rename name name
+freshName name = do
+    taken <- takenNames
+    let name' = setInternalNameRep (findFreshName taken rep) name
+    modify $ \rne -> rne
+      { rneCtx = Map.insert (getName name) name' (rneCtx rne) }
+    return name'
+  where
+    nname = getName name
+    rep = getNameRep nname
+
+
+takenNames :: NamedThing name => Rename name (Set NameRep)
+takenNames = do
+    RenameEnv { .. } <- get
+    return $ Set.unions [headReps rneHeadFVs, rneSigFVs, ctxElems rneCtx]
+  where
+    headReps = Set.fromList . Map.keys
+    ctxElems = Set.fromList . map getNameRep . Map.elems
+
+
+findFreshName :: Set NameRep -> NameRep -> NameRep
+findFreshName taken =
+    fromJust . List.find isFresh . alternativeNames
+  where
+    isFresh = not . flip Set.member taken
+
+
+alternativeNames :: NameRep -> [NameRep]
+alternativeNames name =
+    [ stringNameRep $ str ++ show i | i :: Int <- [0..] ]
+  where
+    str = nameRepString name
+
+
+located :: Functor f => (a -> f b) -> GenLocated l a -> f (GenLocated l b)
+located f (L loc e) = L loc <$> f e
+
+locatedN :: Functor f => (a -> f b) -> LocatedN a -> f (LocatedN b)
+locatedN f (L loc e) = L loc <$> f e
+
+
+tyVarName :: HsTyVarBndr flag GhcRn -> IdP GhcRn
+tyVarName (UserTyVar _ _ name) = unLoc name
+tyVarName (KindedTyVar _ _ (L _ name) _) = name
diff --git a/haddock-api/src/Haddock/InterfaceFile.hs b/haddock-api/src/Haddock/InterfaceFile.hs
new file mode 100644
--- /dev/null
+++ b/haddock-api/src/Haddock/InterfaceFile.hs
@@ -0,0 +1,682 @@
+{-# LANGUAGE CPP, RankNTypes, ScopedTypeVariables #-}
+{-# LANGUAGE BangPatterns #-}
+{-# LANGUAGE NamedFieldPuns #-}
+{-# OPTIONS_GHC -fno-warn-orphans #-}
+-----------------------------------------------------------------------------
+-- |
+-- Module      :  Haddock.InterfaceFile
+-- Copyright   :  (c) David Waern       2006-2009,
+--                    Mateusz Kowalczyk 2013
+-- License     :  BSD-like
+--
+-- Maintainer  :  haddock@projects.haskell.org
+-- Stability   :  experimental
+-- Portability :  portable
+--
+-- Reading and writing the .haddock interface file
+-----------------------------------------------------------------------------
+module Haddock.InterfaceFile (
+  InterfaceFile(..), PackageInfo(..), ifUnitId, ifModule,
+  PackageInterfaces(..), mkPackageInterfaces, ppPackageInfo,
+  readInterfaceFile, writeInterfaceFile,
+  freshNameCache,
+  binaryInterfaceVersion, binaryInterfaceVersionCompatibility
+) where
+
+
+import Haddock.Types
+
+import Data.IORef
+import qualified Data.Map as Map
+import Data.Map (Map)
+import Data.Version
+import Data.Word
+import Text.ParserCombinators.ReadP (readP_to_S)
+
+import GHC.Iface.Binary (getWithUserData, putSymbolTable)
+import GHC.Unit.State
+import GHC.Utils.Binary
+import GHC.Data.FastMutInt
+import GHC.Data.FastString
+import GHC hiding (NoLink)
+import GHC.Types.Name.Cache
+import GHC.Types.Unique.FM
+import GHC.Types.Unique
+
+import Haddock.Options (Visibility (..))
+
+data InterfaceFile = InterfaceFile {
+  ifLinkEnv         :: LinkEnv,
+  -- | Package meta data.  Currently it only consist of a package name, which
+  -- is not read from the interface file, but inferred from its name.
+  --
+  -- issue #
+  ifPackageInfo     :: PackageInfo,
+  ifInstalledIfaces :: [InstalledInterface]
+}
+
+data PackageInfo = PackageInfo {
+  piPackageName    :: PackageName,
+  piPackageVersion :: Data.Version.Version
+}
+
+ppPackageInfo :: PackageInfo -> String
+ppPackageInfo (PackageInfo name version) | version == makeVersion []
+                                         = unpackFS (unPackageName name)
+ppPackageInfo (PackageInfo name version) = unpackFS (unPackageName name) ++ "-" ++ showVersion version
+
+data PackageInterfaces = PackageInterfaces {
+  piPackageInfo         :: PackageInfo,
+  piVisibility          :: Visibility,
+  piInstalledInterfaces :: [InstalledInterface]
+}
+
+mkPackageInterfaces :: Visibility -> InterfaceFile -> PackageInterfaces
+mkPackageInterfaces piVisibility
+                    InterfaceFile { ifPackageInfo
+                                  , ifInstalledIfaces
+                                  } =
+  PackageInterfaces { piPackageInfo = ifPackageInfo
+                    , piVisibility
+                    , piInstalledInterfaces = ifInstalledIfaces
+                    }
+
+ifModule :: InterfaceFile -> Module
+ifModule if_ =
+  case ifInstalledIfaces if_ of
+    [] -> error "empty InterfaceFile"
+    iface:_ -> instMod iface
+
+ifUnitId :: InterfaceFile -> Unit
+ifUnitId if_ =
+  case ifInstalledIfaces if_ of
+    [] -> error "empty InterfaceFile"
+    iface:_ -> moduleUnit $ instMod iface
+
+
+binaryInterfaceMagic :: Word32
+binaryInterfaceMagic = 0xD0Cface
+
+-- Note [The DocModule story]
+--
+-- Breaking changes to the DocH type result in Haddock being unable to read
+-- existing interfaces. This is especially painful for interfaces shipped
+-- with GHC distributions since there is no easy way to regenerate them!
+--
+-- PR #1315 introduced a breaking change to the DocModule constructor. To
+-- maintain backward compatibility we
+--
+-- Parse the old DocModule constructor format (tag 5) and parse the contained
+-- string into a proper ModLink structure. When writing interfaces we exclusively
+-- use the new DocModule format (tag 24)
+
+-- IMPORTANT: Since datatypes in the GHC API might change between major
+-- versions, and because we store GHC datatypes in our interface files, we need
+-- to make sure we version our interface files accordingly.
+--
+-- If you change the interface file format or adapt Haddock to work with a new
+-- major version of GHC (so that the format changes indirectly) *you* need to
+-- follow these steps:
+--
+-- (1) increase `binaryInterfaceVersion`
+--
+-- (2) set `binaryInterfaceVersionCompatibility` to [binaryInterfaceVersion]
+--
+binaryInterfaceVersion :: Word16
+#if MIN_VERSION_ghc(9,6,0) && !MIN_VERSION_ghc(9,7,0)
+binaryInterfaceVersion = 42
+
+binaryInterfaceVersionCompatibility :: [Word16]
+binaryInterfaceVersionCompatibility = [binaryInterfaceVersion]
+#else
+#error Unsupported GHC version
+#endif
+
+
+initBinMemSize :: Int
+initBinMemSize = 1024*1024
+
+
+writeInterfaceFile :: FilePath -> InterfaceFile -> IO ()
+writeInterfaceFile filename iface = do
+  bh0 <- openBinMem initBinMemSize
+  put_ bh0 binaryInterfaceMagic
+  put_ bh0 binaryInterfaceVersion
+
+  -- remember where the dictionary pointer will go
+  dict_p_p <- tellBin bh0
+  put_ bh0 dict_p_p
+
+  -- remember where the symbol table pointer will go
+  symtab_p_p <- tellBin bh0
+  put_ bh0 symtab_p_p
+
+  -- Make some intial state
+  symtab_next <- newFastMutInt 0
+  symtab_map <- newIORef emptyUFM
+  let bin_symtab = BinSymbolTable {
+                      bin_symtab_next = symtab_next,
+                      bin_symtab_map  = symtab_map }
+  dict_next_ref <- newFastMutInt 0
+  dict_map_ref <- newIORef emptyUFM
+  let bin_dict = BinDictionary {
+                      bin_dict_next = dict_next_ref,
+                      bin_dict_map  = dict_map_ref }
+
+  -- put the main thing
+  let bh = setUserData bh0 $ newWriteState (putName bin_symtab)
+                                           (putName bin_symtab)
+                                           (putFastString bin_dict)
+  putInterfaceFile_ bh iface
+
+  -- write the symtab pointer at the front of the file
+  symtab_p <- tellBin bh
+  putAt bh symtab_p_p symtab_p
+  seekBin bh symtab_p
+
+  -- write the symbol table itself
+  symtab_next' <- readFastMutInt symtab_next
+  symtab_map'  <- readIORef symtab_map
+  putSymbolTable bh symtab_next' symtab_map'
+
+  -- write the dictionary pointer at the fornt of the file
+  dict_p <- tellBin bh
+  putAt bh dict_p_p dict_p
+  seekBin bh dict_p
+
+  -- write the dictionary itself
+  dict_next <- readFastMutInt dict_next_ref
+  dict_map  <- readIORef dict_map_ref
+  putDictionary bh dict_next dict_map
+
+  -- and send the result to the file
+  writeBinMem bh filename
+  return ()
+
+
+freshNameCache :: IO NameCache
+freshNameCache = initNameCache 'a' -- ??
+                               []
+
+-- | Read a Haddock (@.haddock@) interface file. Return either an
+-- 'InterfaceFile' or an error message.
+--
+-- This function can be called in two ways.  Within a GHC session it will
+-- update the use and update the session's name cache.  Outside a GHC session
+-- a new empty name cache is used.
+readInterfaceFile :: NameCache
+                  -> FilePath
+                  -> Bool  -- ^ Disable version check. Can cause runtime crash.
+                  -> IO (Either String InterfaceFile)
+readInterfaceFile name_cache filename bypass_checks = do
+  bh <- readBinMem filename
+
+  magic   <- get bh
+  if magic /= binaryInterfaceMagic
+    then return . Left $ "Magic number mismatch: couldn't load interface file: " ++ filename
+    else do
+      version <- get bh
+      if not bypass_checks && (version `notElem` binaryInterfaceVersionCompatibility)
+        then return . Left $ "Interface file is of wrong version: " ++ filename
+        else Right <$> getWithUserData name_cache bh
+
+-------------------------------------------------------------------------------
+-- * Symbol table
+-------------------------------------------------------------------------------
+
+
+putName :: BinSymbolTable -> BinHandle -> Name -> IO ()
+putName BinSymbolTable{
+            bin_symtab_map = symtab_map_ref,
+            bin_symtab_next = symtab_next }    bh name
+  = do
+    symtab_map <- readIORef symtab_map_ref
+    case lookupUFM symtab_map name of
+      Just (off,_) -> put_ bh (fromIntegral off :: Word32)
+      Nothing -> do
+         off <- readFastMutInt symtab_next
+         writeFastMutInt symtab_next (off+1)
+         writeIORef symtab_map_ref
+             $! addToUFM symtab_map name (off,name)
+         put_ bh (fromIntegral off :: Word32)
+
+
+data BinSymbolTable = BinSymbolTable {
+        bin_symtab_next :: !FastMutInt, -- The next index to use
+        bin_symtab_map  :: !(IORef (UniqFM Name (Int,Name)))
+                                -- indexed by Name
+  }
+
+
+putFastString :: BinDictionary -> BinHandle -> FastString -> IO ()
+putFastString BinDictionary { bin_dict_next = j_r,
+                              bin_dict_map  = out_r}  bh f
+  = do
+    out <- readIORef out_r
+    let !unique = getUnique f
+    case lookupUFM_Directly out unique of
+        Just (j, _)  -> put_ bh (fromIntegral j :: Word32)
+        Nothing -> do
+           j <- readFastMutInt j_r
+           put_ bh (fromIntegral j :: Word32)
+           writeFastMutInt j_r (j + 1)
+           writeIORef out_r $! addToUFM_Directly out unique (j, f)
+
+
+data BinDictionary = BinDictionary {
+        bin_dict_next :: !FastMutInt, -- The next index to use
+        bin_dict_map  :: !(IORef (UniqFM FastString (Int,FastString)))
+                                -- indexed by FastString
+  }
+
+-------------------------------------------------------------------------------
+-- * GhcBinary instances
+-------------------------------------------------------------------------------
+
+
+instance (Ord k, Binary k, Binary v) => Binary (Map k v) where
+  put_ bh m = put_ bh (Map.toList m)
+  get bh = fmap (Map.fromList) (get bh)
+
+instance Binary PackageInfo where
+  put_ bh PackageInfo { piPackageName, piPackageVersion } = do
+    put_ bh (unPackageName piPackageName)
+    put_ bh (showVersion piPackageVersion)
+  get bh = do
+    name <- PackageName <$> get bh
+    versionString <- get bh
+    let version = case readP_to_S parseVersion versionString of
+          [] -> makeVersion []
+          vs -> fst (last vs)
+    return $ PackageInfo name version
+
+instance Binary InterfaceFile where
+  put_ bh (InterfaceFile env info ifaces) = do
+    put_ bh env
+    put_ bh info
+    put_ bh ifaces
+
+  get bh = do
+    env    <- get bh
+    info   <- get bh
+    ifaces <- get bh
+    return (InterfaceFile env info ifaces)
+
+
+putInterfaceFile_ :: BinHandle -> InterfaceFile -> IO ()
+putInterfaceFile_ bh (InterfaceFile env info ifaces) = do
+  put_ bh env
+  put_ bh info
+  put_ bh ifaces
+
+instance Binary InstalledInterface where
+  put_ bh (InstalledInterface modu is_sig info docMap argMap
+           exps visExps opts fixMap) = do
+    put_ bh modu
+    put_ bh is_sig
+    put_ bh info
+    lazyPut bh (docMap, argMap)
+    put_ bh exps
+    put_ bh visExps
+    put_ bh opts
+    put_ bh fixMap
+
+  get bh = do
+    modu    <- get bh
+    is_sig  <- get bh
+    info    <- get bh
+    ~(docMap, argMap) <- lazyGet bh
+    exps    <- get bh
+    visExps <- get bh
+    opts    <- get bh
+    fixMap  <- get bh
+    return (InstalledInterface modu is_sig info docMap argMap
+            exps visExps opts fixMap)
+
+
+instance Binary DocOption where
+    put_ bh OptHide = do
+            putByte bh 0
+    put_ bh OptPrune = do
+            putByte bh 1
+    put_ bh OptIgnoreExports = do
+            putByte bh 2
+    put_ bh OptNotHome = do
+            putByte bh 3
+    put_ bh OptShowExtensions = do
+            putByte bh 4
+    get bh = do
+            h <- getByte bh
+            case h of
+              0 -> do
+                    return OptHide
+              1 -> do
+                    return OptPrune
+              2 -> do
+                    return OptIgnoreExports
+              3 -> do
+                    return OptNotHome
+              4 -> do
+                    return OptShowExtensions
+              _ -> fail "invalid binary data found"
+
+
+instance Binary Example where
+    put_ bh (Example expression result) = do
+        put_ bh expression
+        put_ bh result
+    get bh = do
+        expression <- get bh
+        result <- get bh
+        return (Example expression result)
+
+instance Binary a => Binary (Hyperlink a) where
+    put_ bh (Hyperlink url label) = do
+        put_ bh url
+        put_ bh label
+    get bh = do
+        url <- get bh
+        label <- get bh
+        return (Hyperlink url label)
+
+instance Binary a => Binary (ModLink a) where
+    put_ bh (ModLink m label) = do
+        put_ bh m
+        put_ bh label
+    get bh = do
+        m <- get bh
+        label <- get bh
+        return (ModLink m label)
+
+instance Binary Picture where
+    put_ bh (Picture uri title) = do
+        put_ bh uri
+        put_ bh title
+    get bh = do
+        uri <- get bh
+        title <- get bh
+        return (Picture uri title)
+
+instance Binary a => Binary (Header a) where
+    put_ bh (Header l t) = do
+        put_ bh l
+        put_ bh t
+    get bh = do
+        l <- get bh
+        t <- get bh
+        return (Header l t)
+
+instance Binary a => Binary (Table a) where
+    put_ bh (Table h b) = do
+        put_ bh h
+        put_ bh b
+    get bh = do
+        h <- get bh
+        b <- get bh
+        return (Table h b)
+
+instance Binary a => Binary (TableRow a) where
+    put_ bh (TableRow cs) = put_ bh cs
+    get bh = do
+        cs <- get bh
+        return (TableRow cs)
+
+instance Binary a => Binary (TableCell a) where
+    put_ bh (TableCell i j c) = do
+        put_ bh i
+        put_ bh j
+        put_ bh c
+    get bh = do
+        i <- get bh
+        j <- get bh
+        c <- get bh
+        return (TableCell i j c)
+
+instance Binary Meta where
+    put_ bh (Meta v p) = do
+        put_ bh v
+        put_ bh p
+    get bh = do
+        v <- get bh
+        p <- get bh
+        return (Meta v p)
+
+instance (Binary mod, Binary id) => Binary (MetaDoc mod id) where
+  put_ bh MetaDoc { _meta = m, _doc = d } = do
+    put_ bh m
+    put_ bh d
+  get bh = do
+    m <- get bh
+    d <- get bh
+    return $ MetaDoc { _meta = m, _doc = d }
+
+instance (Binary mod, Binary id) => Binary (DocH mod id) where
+    put_ bh DocEmpty = do
+            putByte bh 0
+    put_ bh (DocAppend aa ab) = do
+            putByte bh 1
+            put_ bh aa
+            put_ bh ab
+    put_ bh (DocString ac) = do
+            putByte bh 2
+            put_ bh ac
+    put_ bh (DocParagraph ad) = do
+            putByte bh 3
+            put_ bh ad
+    put_ bh (DocIdentifier ae) = do
+            putByte bh 4
+            put_ bh ae
+    put_ bh (DocEmphasis ag) = do
+            putByte bh 6
+            put_ bh ag
+    put_ bh (DocMonospaced ah) = do
+            putByte bh 7
+            put_ bh ah
+    put_ bh (DocUnorderedList ai) = do
+            putByte bh 8
+            put_ bh ai
+    put_ bh (DocOrderedList aj) = do
+            putByte bh 9
+            put_ bh aj
+    put_ bh (DocDefList ak) = do
+            putByte bh 10
+            put_ bh ak
+    put_ bh (DocCodeBlock al) = do
+            putByte bh 11
+            put_ bh al
+    put_ bh (DocHyperlink am) = do
+            putByte bh 12
+            put_ bh am
+    put_ bh (DocPic x) = do
+            putByte bh 13
+            put_ bh x
+    put_ bh (DocAName an) = do
+            putByte bh 14
+            put_ bh an
+    put_ bh (DocExamples ao) = do
+            putByte bh 15
+            put_ bh ao
+    put_ bh (DocIdentifierUnchecked x) = do
+            putByte bh 16
+            put_ bh x
+    put_ bh (DocWarning ag) = do
+            putByte bh 17
+            put_ bh ag
+    put_ bh (DocProperty x) = do
+            putByte bh 18
+            put_ bh x
+    put_ bh (DocBold x) = do
+            putByte bh 19
+            put_ bh x
+    put_ bh (DocHeader aa) = do
+            putByte bh 20
+            put_ bh aa
+    put_ bh (DocMathInline x) = do
+            putByte bh 21
+            put_ bh x
+    put_ bh (DocMathDisplay x) = do
+            putByte bh 22
+            put_ bh x
+    put_ bh (DocTable x) = do
+            putByte bh 23
+            put_ bh x
+    -- See note [The DocModule story]
+    put_ bh (DocModule af) = do
+            putByte bh 24
+            put_ bh af
+
+    get bh = do
+            h <- getByte bh
+            case h of
+              0 -> do
+                    return DocEmpty
+              1 -> do
+                    aa <- get bh
+                    ab <- get bh
+                    return (DocAppend aa ab)
+              2 -> do
+                    ac <- get bh
+                    return (DocString ac)
+              3 -> do
+                    ad <- get bh
+                    return (DocParagraph ad)
+              4 -> do
+                    ae <- get bh
+                    return (DocIdentifier ae)
+              -- See note [The DocModule story]
+              5 -> do
+                    af <- get bh
+                    return $ DocModule ModLink
+                      { modLinkName  = af
+                      , modLinkLabel = Nothing
+                      }
+              6 -> do
+                    ag <- get bh
+                    return (DocEmphasis ag)
+              7 -> do
+                    ah <- get bh
+                    return (DocMonospaced ah)
+              8 -> do
+                    ai <- get bh
+                    return (DocUnorderedList ai)
+              9 -> do
+                    aj <- get bh
+                    return (DocOrderedList aj)
+              10 -> do
+                    ak <- get bh
+                    return (DocDefList ak)
+              11 -> do
+                    al <- get bh
+                    return (DocCodeBlock al)
+              12 -> do
+                    am <- get bh
+                    return (DocHyperlink am)
+              13 -> do
+                    x <- get bh
+                    return (DocPic x)
+              14 -> do
+                    an <- get bh
+                    return (DocAName an)
+              15 -> do
+                    ao <- get bh
+                    return (DocExamples ao)
+              16 -> do
+                    x <- get bh
+                    return (DocIdentifierUnchecked x)
+              17 -> do
+                    ag <- get bh
+                    return (DocWarning ag)
+              18 -> do
+                    x <- get bh
+                    return (DocProperty x)
+              19 -> do
+                    x <- get bh
+                    return (DocBold x)
+              20 -> do
+                    aa <- get bh
+                    return (DocHeader aa)
+              21 -> do
+                    x <- get bh
+                    return (DocMathInline x)
+              22 -> do
+                    x <- get bh
+                    return (DocMathDisplay x)
+              23 -> do
+                    x <- get bh
+                    return (DocTable x)
+              -- See note [The DocModule story]
+              24 -> do
+                    af <- get bh
+                    return (DocModule af)
+              _ -> error "invalid binary data found in the interface file"
+
+
+instance Binary name => Binary (HaddockModInfo name) where
+  put_ bh hmi = do
+    put_ bh (hmi_description hmi)
+    put_ bh (hmi_copyright   hmi)
+    put_ bh (hmi_license     hmi)
+    put_ bh (hmi_maintainer  hmi)
+    put_ bh (hmi_stability   hmi)
+    put_ bh (hmi_portability hmi)
+    put_ bh (hmi_safety      hmi)
+    put_ bh (fromEnum <$> hmi_language hmi)
+    put_ bh (map fromEnum $ hmi_extensions hmi)
+
+  get bh = do
+    descr <- get bh
+    copyr <- get bh
+    licen <- get bh
+    maint <- get bh
+    stabi <- get bh
+    porta <- get bh
+    safet <- get bh
+    langu <- fmap toEnum <$> get bh
+    exten <- map toEnum <$> get bh
+    return (HaddockModInfo descr copyr licen maint stabi porta safet langu exten)
+
+instance Binary DocName where
+  put_ bh (Documented name modu) = do
+    putByte bh 0
+    put_ bh name
+    put_ bh modu
+  put_ bh (Undocumented name) = do
+    putByte bh 1
+    put_ bh name
+
+  get bh = do
+    h <- getByte bh
+    case h of
+      0 -> do
+        name <- get bh
+        modu <- get bh
+        return (Documented name modu)
+      1 -> do
+        name <- get bh
+        return (Undocumented name)
+      _ -> error "get DocName: Bad h"
+
+instance Binary n => Binary (Wrap n) where
+  put_ bh (Unadorned n) = do
+    putByte bh 0
+    put_ bh n
+  put_ bh (Parenthesized n) = do
+    putByte bh 1
+    put_ bh n
+  put_ bh (Backticked n) = do
+    putByte bh 2
+    put_ bh n
+
+  get bh = do
+    h <- getByte bh
+    case h of
+      0 -> do
+        name <- get bh
+        return (Unadorned name)
+      1 -> do
+        name <- get bh
+        return (Parenthesized name)
+      2 -> do
+        name <- get bh
+        return (Backticked name)
+      _ -> error "get Wrap: Bad h"
diff --git a/haddock-api/src/Haddock/ModuleTree.hs b/haddock-api/src/Haddock/ModuleTree.hs
new file mode 100644
--- /dev/null
+++ b/haddock-api/src/Haddock/ModuleTree.hs
@@ -0,0 +1,62 @@
+-----------------------------------------------------------------------------
+-- |
+-- Module      :  Haddock.ModuleTree
+-- Copyright   :  (c) Simon Marlow 2003-2006,
+--                    David Waern  2006
+-- License     :  BSD-like
+--
+-- Maintainer  :  haddock@projects.haskell.org
+-- Stability   :  experimental
+-- Portability :  portable
+-----------------------------------------------------------------------------
+module Haddock.ModuleTree ( ModuleTree(..), mkModuleTree ) where
+
+
+import Haddock.Types ( MDoc )
+
+import GHC             ( Name )
+import GHC.Unit.Module ( Module, moduleNameString, moduleName, moduleUnit, unitString )
+import GHC.Unit.State  ( UnitState, lookupUnit, unitPackageIdString )
+
+import qualified Control.Applicative as A
+
+
+data ModuleTree = Node String (Maybe Module) (Maybe String) (Maybe String) (Maybe (MDoc Name)) [ModuleTree]
+
+
+mkModuleTree :: UnitState -> Bool -> [(Module, Maybe (MDoc Name))] -> [ModuleTree]
+mkModuleTree state showPkgs mods =
+  foldr fn [] [ (mdl, splitModule mdl, modPkg mdl, modSrcPkg mdl, short) | (mdl, short) <- mods ]
+  where
+    modPkg mod_ | showPkgs = Just (unitString (moduleUnit mod_))
+                | otherwise = Nothing
+    modSrcPkg mod_ | showPkgs = fmap unitPackageIdString
+                                     (lookupUnit state (moduleUnit mod_))
+                   | otherwise = Nothing
+    fn (m,mod_,pkg,srcPkg,short) = addToTrees mod_ m pkg srcPkg short
+
+
+addToTrees :: [String] -> Module -> Maybe String -> Maybe String -> Maybe (MDoc Name) -> [ModuleTree] -> [ModuleTree]
+addToTrees [] _ _ _ _ ts = ts
+addToTrees ss m pkg srcPkg short [] = mkSubTree ss m pkg srcPkg short
+addToTrees (s1:ss) m pkg srcPkg short (t@(Node s2 leaf node_pkg node_srcPkg node_short subs) : ts)
+  | s1 >  s2  = t : addToTrees (s1:ss) m pkg srcPkg short ts
+  | s1 == s2  = Node s2 (leaf A.<|> (if null ss then Just m else Nothing)) this_pkg this_srcPkg this_short (addToTrees ss m pkg srcPkg short subs) : ts
+  | otherwise = mkSubTree (s1:ss) m pkg srcPkg short ++ t : ts
+ where
+  this_pkg = if null ss then pkg else node_pkg
+  this_srcPkg = if null ss then srcPkg else node_srcPkg
+  this_short = if null ss then short else node_short
+
+
+mkSubTree :: [String] -> Module -> Maybe String -> Maybe String -> Maybe (MDoc Name) -> [ModuleTree]
+mkSubTree []     _ _   _      _     = []
+mkSubTree [s]    m pkg srcPkg short = [Node s (Just m) pkg srcPkg short []]
+mkSubTree (s:s':ss) m pkg srcPkg short = [Node s Nothing Nothing Nothing Nothing (mkSubTree (s':ss) m pkg srcPkg short)]
+
+
+splitModule :: Module -> [String]
+splitModule mdl = split (moduleNameString (moduleName mdl))
+  where split mod0 = case break (== '.') mod0 of
+          (s1, '.':s2) -> s1 : split s2
+          (s1, _)      -> [s1]
diff --git a/haddock-api/src/Haddock/Options.hs b/haddock-api/src/Haddock/Options.hs
new file mode 100644
--- /dev/null
+++ b/haddock-api/src/Haddock/Options.hs
@@ -0,0 +1,454 @@
+-----------------------------------------------------------------------------
+-- |
+-- Module      :  Haddock.Options
+-- Copyright   :  (c) Simon Marlow      2003-2006,
+--                    David Waern       2006-2009,
+--                    Mateusz Kowalczyk 2013
+-- License     :  BSD-like
+--
+-- Maintainer  :  haddock@projects.haskell.org
+-- Stability   :  experimental
+-- Portability :  portable
+--
+-- Definition of the command line interface of Haddock.
+-----------------------------------------------------------------------------
+module Haddock.Options (
+  parseHaddockOpts,
+  Flag(..),
+  Visibility(..),
+  getUsage,
+  optTitle,
+  outputDir,
+  optContentsUrl,
+  optIndexUrl,
+  optCssFile,
+  optSourceCssFile,
+  sourceUrls,
+  wikiUrls,
+  baseUrl,
+  optParCount,
+  optDumpInterfaceFile,
+  optShowInterfaceFile,
+  optLaTeXStyle,
+  optMathjax,
+  qualification,
+  sinceQualification,
+  verbosity,
+  ghcFlags,
+  reexportFlags,
+  readIfaceArgs,
+  optPackageName,
+  optPackageVersion,
+  modulePackageInfo,
+  ignoredSymbols
+) where
+
+
+import qualified Data.Char as Char
+import           Data.List (dropWhileEnd)
+import           Data.Map (Map)
+import qualified Data.Map as Map
+import           Data.Set (Set)
+import qualified Data.Set as Set
+import           Data.Version
+import           Control.Applicative
+import           GHC.Data.FastString
+import           GHC ( Module, moduleUnit )
+import           GHC.Unit.State
+import           Haddock.Types
+import           Haddock.Utils
+import           System.Console.GetOpt
+import qualified Text.ParserCombinators.ReadP as RP
+
+
+data Flag
+  = Flag_BuiltInThemes
+  | Flag_CSS String
+--  | Flag_DocBook
+  | Flag_ReadInterface String
+  | Flag_DumpInterface String
+  | Flag_ShowInterface String
+  | Flag_Heading String
+  | Flag_Html
+  | Flag_Hoogle
+  | Flag_Lib String
+  | Flag_OutputDir FilePath
+  | Flag_Prologue FilePath
+  | Flag_SourceBaseURL    String
+  | Flag_SourceModuleURL  String
+  | Flag_SourceEntityURL  String
+  | Flag_SourceLEntityURL String
+  | Flag_WikiBaseURL   String
+  | Flag_BaseURL       String
+  | Flag_WikiModuleURL String
+  | Flag_WikiEntityURL String
+  | Flag_LaTeX
+  | Flag_LaTeXStyle String
+  | Flag_QuickJumpIndex
+  | Flag_HyperlinkedSource
+  | Flag_SourceCss String
+  | Flag_Mathjax String
+  | Flag_Help
+  | Flag_Verbosity String
+  | Flag_Version
+  | Flag_CompatibleInterfaceVersions
+  | Flag_InterfaceVersion
+  | Flag_BypassInterfaceVersonCheck
+  | Flag_UseContents String
+  | Flag_GenContents
+  | Flag_UseIndex String
+  | Flag_GenIndex
+  | Flag_IgnoreAllExports
+  | Flag_HideModule String
+  | Flag_ShowModule String
+  | Flag_ShowAllModules
+  | Flag_ShowExtensions String
+  | Flag_OptGhc String
+  | Flag_GhcLibDir String
+  | Flag_GhcVersion
+  | Flag_PrintGhcPath
+  | Flag_PrintGhcLibDir
+  | Flag_NoWarnings
+  | Flag_UseUnicode
+  | Flag_NoTmpCompDir
+  | Flag_Qualification String
+  | Flag_PrettyHtml
+  | Flag_NoPrintMissingDocs
+  | Flag_PackageName String
+  | Flag_PackageVersion String
+  | Flag_Reexport String
+  | Flag_SinceQualification String
+  | Flag_IgnoreLinkSymbol String
+  | Flag_ParCount (Maybe Int)
+  deriving (Eq, Show)
+
+
+options :: Bool -> [OptDescr Flag]
+options backwardsCompat =
+  [
+    Option ['B']  []     (ReqArg Flag_GhcLibDir "DIR")
+      "path to a GHC lib dir, to override the default path",
+    Option ['o']  ["odir"]     (ReqArg Flag_OutputDir "DIR")
+      "directory in which to put the output files",
+    Option ['l']  ["lib"]         (ReqArg Flag_Lib "DIR")
+      "location of Haddock's auxiliary files",
+    Option ['i'] ["read-interface"] (ReqArg Flag_ReadInterface "FILE")
+      "read an interface from FILE",
+    Option ['D']  ["dump-interface"] (ReqArg Flag_DumpInterface "FILE")
+      "write the resulting interface to FILE",
+    Option []     ["show-interface"] (ReqArg Flag_ShowInterface "FILE")
+      "print the interface in a human readable form",
+--    Option ['S']  ["docbook"]  (NoArg Flag_DocBook)
+--  "output in DocBook XML",
+    Option ['h']  ["html"]     (NoArg Flag_Html)
+      "output in HTML (XHTML 1.0)",
+    Option []  ["latex"]  (NoArg Flag_LaTeX) "use experimental LaTeX rendering",
+    Option []  ["latex-style"]  (ReqArg Flag_LaTeXStyle "FILE") "provide your own LaTeX style in FILE",
+    Option []  ["mathjax"]  (ReqArg Flag_Mathjax "URL") "URL FOR mathjax",
+    Option ['U'] ["use-unicode"] (NoArg Flag_UseUnicode) "use Unicode in HTML output",
+    Option []  ["hoogle"]     (NoArg Flag_Hoogle)
+      "output for Hoogle; you may want --package-name and --package-version too",
+    Option [] ["quickjump"] (NoArg Flag_QuickJumpIndex)
+      "generate an index for interactive documentation navigation",
+    Option [] ["hyperlinked-source"] (NoArg Flag_HyperlinkedSource)
+      "generate highlighted and hyperlinked source code (for use with --html)",
+    Option [] ["source-css"] (ReqArg Flag_SourceCss "FILE")
+      "use custom CSS file instead of default one in hyperlinked source",
+    Option []  ["source-base"]   (ReqArg Flag_SourceBaseURL "URL")
+      "URL for a source code link on the contents\nand index pages",
+    Option ['s'] (if backwardsCompat then ["source", "source-module"] else ["source-module"])
+      (ReqArg Flag_SourceModuleURL "URL")
+      "URL for a source code link for each module\n(using the %{FILE} or %{MODULE} vars)",
+    Option []  ["source-entity"]  (ReqArg Flag_SourceEntityURL "URL")
+      "URL for a source code link for each entity\n(using the %{FILE}, %{MODULE}, %{NAME},\n%{KIND} or %{LINE} vars)",
+    Option []  ["source-entity-line"] (ReqArg Flag_SourceLEntityURL "URL")
+      "URL for a source code link for each entity.\nUsed if name links are unavailable, eg. for TH splices.",
+    Option []  ["comments-base"]   (ReqArg Flag_WikiBaseURL "URL")
+      "URL for a comments link on the contents\nand index pages",
+    Option [] ["base-url"] (ReqArg Flag_BaseURL "URL")
+      "Base URL for static assets (eg. css, javascript, json files etc.).\nWhen given statis assets will not be copied.",
+    Option []  ["comments-module"]  (ReqArg Flag_WikiModuleURL "URL")
+      "URL for a comments link for each module\n(using the %{MODULE} var)",
+    Option []  ["comments-entity"]  (ReqArg Flag_WikiEntityURL "URL")
+      "URL for a comments link for each entity\n(using the %{FILE}, %{MODULE}, %{NAME},\n%{KIND} or %{LINE} vars)",
+    Option ['c']  ["css", "theme"] (ReqArg Flag_CSS "PATH")
+      "the CSS file or theme directory to use for HTML output",
+    Option []  ["built-in-themes"] (NoArg Flag_BuiltInThemes)
+      "include all the built-in haddock themes",
+    Option ['p']  ["prologue"] (ReqArg Flag_Prologue "FILE")
+      "file containing prologue text",
+    Option ['t']  ["title"]    (ReqArg Flag_Heading "TITLE")
+      "page heading",
+    Option ['q']  ["qual"] (ReqArg Flag_Qualification "QUAL")
+      "qualification of names, one of \n'none' (default), 'full', 'local'\n'relative' or 'aliased'",
+    Option ['?']  ["help"]  (NoArg Flag_Help)
+      "display this help and exit",
+    Option ['V']  ["version"]  (NoArg Flag_Version)
+      "output version information and exit",
+    Option []  ["compatible-interface-versions"]  (NoArg Flag_CompatibleInterfaceVersions)
+      "output compatible interface file versions and exit",
+    Option []  ["interface-version"]  (NoArg Flag_InterfaceVersion)
+      "output interface file version and exit",
+    Option []  ["bypass-interface-version-check"] (NoArg Flag_BypassInterfaceVersonCheck)
+      "bypass the interface file version check (dangerous)",
+    Option ['v']  ["verbosity"]  (ReqArg Flag_Verbosity "VERBOSITY")
+      "set verbosity level",
+    Option [] ["use-contents"] (ReqArg Flag_UseContents "URL")
+      "use a separately-generated HTML contents page",
+    Option [] ["gen-contents"] (NoArg Flag_GenContents)
+      "generate an HTML contents from specified\ninterfaces",
+    Option [] ["use-index"] (ReqArg Flag_UseIndex "URL")
+      "use a separately-generated HTML index",
+    Option [] ["gen-index"] (NoArg Flag_GenIndex)
+      "generate an HTML index from specified\ninterfaces",
+    Option [] ["ignore-all-exports"] (NoArg Flag_IgnoreAllExports)
+      "behave as if all modules have the\nignore-exports attribute",
+    Option [] ["hide"] (ReqArg Flag_HideModule "MODULE")
+      "behave as if MODULE has the hide attribute",
+    Option [] ["show"] (ReqArg Flag_ShowModule "MODULE")
+      "behave as if MODULE does not have the hide attribute",
+    Option [] ["show-all"] (NoArg Flag_ShowAllModules)
+      "behave as if not modules have the hide attribute",
+    Option [] ["show-extensions"] (ReqArg Flag_ShowExtensions "MODULE")
+      "behave as if MODULE has the show-extensions attribute",
+    Option [] ["optghc"] (ReqArg Flag_OptGhc "OPTION")
+      "option to be forwarded to GHC",
+    Option []  ["ghc-version"]  (NoArg Flag_GhcVersion)
+      "output GHC version in numeric format",
+    Option []  ["print-ghc-path"]  (NoArg Flag_PrintGhcPath)
+      "output path to GHC binary",
+    Option []  ["print-ghc-libdir"]  (NoArg Flag_PrintGhcLibDir)
+      "output GHC lib dir",
+    Option ['w'] ["no-warnings"] (NoArg Flag_NoWarnings) "turn off all warnings",
+    Option [] ["no-tmp-comp-dir"] (NoArg Flag_NoTmpCompDir)
+      "do not re-direct compilation output to a temporary directory",
+    Option [] ["pretty-html"] (NoArg Flag_PrettyHtml)
+      "generate html with newlines and indenting (for use with --html)",
+    Option [] ["no-print-missing-docs"] (NoArg Flag_NoPrintMissingDocs)
+      "don't print information about any undocumented entities",
+    Option []  ["reexport"] (ReqArg Flag_Reexport "MOD")
+      "reexport the module MOD, adding it to the index",
+    Option [] ["package-name"] (ReqArg Flag_PackageName "NAME")
+      "name of the package being documented",
+    Option [] ["package-version"] (ReqArg Flag_PackageVersion "VERSION")
+      "version of the package being documented in usual x.y.z.w format",
+    Option []  ["since-qual"] (ReqArg Flag_SinceQualification "QUAL")
+      "package qualification of @since, one of\n'always' (default) or 'only-external'",
+    Option [] ["ignore-link-symbol"] (ReqArg Flag_IgnoreLinkSymbol "SYMBOL")
+      "name of a symbol which does not trigger a warning in case of link issue",
+    Option ['j'] [] (OptArg (\count -> Flag_ParCount (fmap read count)) "n")
+      "load modules in parallel"
+  ]
+
+
+getUsage :: IO String
+getUsage = do
+  prog <- getProgramName
+  return $ usageInfo (usageHeader prog) (options False)
+  where
+    usageHeader :: String -> String
+    usageHeader prog = "Usage: " ++ prog ++ " [OPTION...] file...\n"
+
+
+parseHaddockOpts :: [String] -> IO ([Flag], [String])
+parseHaddockOpts params =
+  case getOpt Permute (options True) params  of
+    (flags, args, []) -> return (flags, args)
+    (_, _, errors)    -> do
+      usage <- getUsage
+      throwE (concat errors ++ usage)
+
+optPackageVersion :: [Flag] -> Maybe Data.Version.Version
+optPackageVersion flags =
+  let ver = optLast [ v | Flag_PackageVersion v <- flags ]
+  in ver >>= fmap fst . optLast . RP.readP_to_S parseVersion
+
+optPackageName :: [Flag] -> Maybe PackageName
+optPackageName flags =
+  optLast [ PackageName $ mkFastString n | Flag_PackageName n <- flags ]
+
+
+optTitle :: [Flag] -> Maybe String
+optTitle flags =
+  case [str | Flag_Heading str <- flags] of
+    [] -> Nothing
+    (t:_) -> Just t
+
+
+outputDir :: [Flag] -> FilePath
+outputDir flags =
+  case [ path | Flag_OutputDir path <- flags ] of
+    []    -> "."
+    paths -> last paths
+
+
+optContentsUrl :: [Flag] -> Maybe String
+optContentsUrl flags = optLast [ url | Flag_UseContents url <- flags ]
+
+
+optIndexUrl :: [Flag] -> Maybe String
+optIndexUrl flags = optLast [ url | Flag_UseIndex url <- flags ]
+
+
+optCssFile :: [Flag] -> Maybe FilePath
+optCssFile flags = optLast [ str | Flag_CSS str <- flags ]
+
+optSourceCssFile :: [Flag] -> Maybe FilePath
+optSourceCssFile flags = optLast [ str | Flag_SourceCss str <- flags ]
+
+sourceUrls :: [Flag] -> (Maybe String, Maybe String, Maybe String, Maybe String)
+sourceUrls flags =
+  (optLast [str | Flag_SourceBaseURL    str <- flags]
+  ,optLast [str | Flag_SourceModuleURL  str <- flags]
+  ,optLast [str | Flag_SourceEntityURL  str <- flags]
+  ,optLast [str | Flag_SourceLEntityURL str <- flags])
+
+
+wikiUrls :: [Flag] -> (Maybe String, Maybe String, Maybe String)
+wikiUrls flags =
+  (optLast [str | Flag_WikiBaseURL   str <- flags]
+  ,optLast [str | Flag_WikiModuleURL str <- flags]
+  ,optLast [str | Flag_WikiEntityURL str <- flags])
+
+
+baseUrl :: [Flag] -> Maybe String
+baseUrl flags = optLast [str | Flag_BaseURL str <- flags]
+
+optDumpInterfaceFile :: [Flag] -> Maybe FilePath
+optDumpInterfaceFile flags = optLast [ str | Flag_DumpInterface str <- flags ]
+
+optShowInterfaceFile :: [Flag] -> Maybe FilePath
+optShowInterfaceFile flags = optLast [ str | Flag_ShowInterface str <- flags ]
+
+optLaTeXStyle :: [Flag] -> Maybe String
+optLaTeXStyle flags = optLast [ str | Flag_LaTeXStyle str <- flags ]
+
+optMathjax :: [Flag] -> Maybe String
+optMathjax flags = optLast [ str | Flag_Mathjax str <- flags ]
+
+optParCount :: [Flag] -> Maybe (Maybe Int)
+optParCount flags = optLast [ n | Flag_ParCount n <- flags ]
+
+qualification :: [Flag] -> Either String QualOption
+qualification flags =
+  case map (map Char.toLower) [ str | Flag_Qualification str <- flags ] of
+      []             -> Right OptNoQual
+      ["none"]       -> Right OptNoQual
+      ["full"]       -> Right OptFullQual
+      ["local"]      -> Right OptLocalQual
+      ["relative"]   -> Right OptRelativeQual
+      ["aliased"]    -> Right OptAliasedQual
+      [arg]          -> Left $ "unknown qualification type " ++ show arg
+      _:_            -> Left "qualification option given multiple times"
+
+sinceQualification :: [Flag] -> Either String SinceQual
+sinceQualification flags =
+  case map (map Char.toLower) [ str | Flag_SinceQualification str <- flags ] of
+      []             -> Right Always
+      ["always"]     -> Right Always
+      ["external"]   -> Right External
+      [arg]          -> Left $ "unknown since-qualification type " ++ show arg
+      _:_            -> Left "since-qualification option given multiple times"
+
+verbosity :: [Flag] -> Verbosity
+verbosity flags =
+  case [ str | Flag_Verbosity str <- flags ] of
+    []  -> Normal
+    x:_ -> case parseVerbosity x of
+      Left e -> throwE e
+      Right v -> v
+
+-- | Get the ignored symbols from the given flags. These are the symbols for
+-- which no link warnings will be generated if their link destinations cannot be
+-- determined.
+--
+-- Symbols may be provided as qualified or unqualified names (e.g.
+-- 'Data.Map.dropWhileEnd' or 'dropWhileEnd', resp). If qualified, no link
+-- warnings will be produced for occurances of that name when it is imported
+-- from that module. If unqualified, no link warnings will be produced for any
+-- occurances of that name from any module.
+ignoredSymbols :: [Flag] -> Map (Maybe String) (Set String)
+ignoredSymbols flags =
+    foldr addToMap Map.empty [ splitSymbol symbol | Flag_IgnoreLinkSymbol symbol <- flags ]
+  where
+    -- Split a symbol into its module name and unqualified name, producing
+    -- 'Nothing' for the module name if the given symbol is already unqualified
+    splitSymbol :: String -> (Maybe String, String)
+    splitSymbol s =
+      -- Drop the longest suffix not containing a '.' character
+      case dropWhileEnd (/= '.') s of
+
+        -- If the longest suffix is empty, there was no '.'.
+        -- Assume it is an unqualified name (no module string).
+        "" -> (Nothing, s)
+
+        -- If the longest suffix is not empty, there was a '.'.
+        -- Assume it is a qualified name. `s'` will be the module string followed
+        -- by the last '.', e.g. "Data.List.", so take `init s'` as the module
+        -- string. Drop the length of `s'` from the original string `s` to
+        -- obtain to the unqualified name.
+        s' -> (Just $ init s', drop (length s') s)
+
+    -- Add a (module name, name) pair to the map from modules to their ignored
+    -- symbols
+    addToMap :: (Maybe String, String) -> Map (Maybe String) (Set String) -> Map (Maybe String) (Set String)
+    addToMap (m, name) symbs = Map.insertWith (Set.union) m (Set.singleton name) symbs
+
+ghcFlags :: [Flag] -> [String]
+ghcFlags flags = [ option | Flag_OptGhc option <- flags ]
+
+reexportFlags :: [Flag] -> [String]
+reexportFlags flags = [ option | Flag_Reexport option <- flags ]
+
+data Visibility = Visible | Hidden
+  deriving (Eq, Show)
+
+readIfaceArgs :: [Flag] -> [(DocPaths, Visibility, FilePath)]
+readIfaceArgs flags = [ parseIfaceOption s | Flag_ReadInterface s <- flags ]
+  where
+    parseIfaceOption :: String -> (DocPaths, Visibility, FilePath)
+    parseIfaceOption str =
+      case break (==',') str of
+        (fpath, ',':rest) ->
+          case break (==',') rest of
+            (src, ',':rest') ->
+              let src' = case src of
+                    "" -> Nothing
+                    _  -> Just src
+              in
+              case break (==',') rest' of
+                (visibility, ',':file) | visibility == "hidden" ->
+                  ((fpath, src'), Hidden, file)
+                                       | otherwise ->
+                  ((fpath, src'), Visible, file)
+                (file, _) ->
+                  ((fpath, src'), Visible, file)
+            (file, _) -> ((fpath, Nothing), Visible, file)
+        (file, _) -> (("", Nothing), Visible, file)
+
+
+-- | Like 'listToMaybe' but returns the last element instead of the first.
+optLast :: [a] -> Maybe a
+optLast [] = Nothing
+optLast xs = Just (last xs)
+
+
+-- | This function has a potential to return 'Nothing' because package name and
+-- versions can no longer reliably be extracted in all cases: if the package is
+-- not installed yet then this info is no longer available.
+--
+-- The @--package-name@ and @--package-version@ Haddock flags allow the user to
+-- specify this information manually and it is returned here if present.
+modulePackageInfo :: UnitState
+                  -> [Flag] -- ^ Haddock flags are checked as they may contain
+                            -- the package name or version provided by the user
+                            -- which we prioritise
+                  -> Maybe Module
+                  -> (Maybe PackageName, Maybe Data.Version.Version)
+modulePackageInfo _unit_state _flags Nothing = (Nothing, Nothing)
+modulePackageInfo unit_state flags (Just modu) =
+  ( optPackageName flags    <|> fmap unitPackageName pkgDb
+  , optPackageVersion flags <|> fmap unitPackageVersion pkgDb
+  )
+  where
+    pkgDb = lookupUnit unit_state (moduleUnit modu)
diff --git a/haddock-api/src/Haddock/Parser.hs b/haddock-api/src/Haddock/Parser.hs
new file mode 100644
--- /dev/null
+++ b/haddock-api/src/Haddock/Parser.hs
@@ -0,0 +1,56 @@
+-- |
+-- Module      :  Haddock.Parser
+-- Copyright   :  (c) Mateusz Kowalczyk 2013,
+--                    Simon Hengel      2013
+-- License     :  BSD-like
+--
+-- Maintainer  :  haddock@projects.haskell.org
+-- Stability   :  experimental
+-- Portability :  portable
+
+module Haddock.Parser ( parseParas
+                      , parseString
+                      , parseIdent
+                      ) where
+
+import qualified Documentation.Haddock.Parser as P
+import Documentation.Haddock.Types
+import Haddock.Types
+
+import GHC.Driver.Session ( DynFlags )
+import GHC.Driver.Config.Parser (initParserOpts)
+import GHC.Data.FastString   ( fsLit )
+import GHC.Parser.Lexer ( initParserState, unP, ParseResult(POk, PFailed) )
+import GHC.Parser       ( parseIdentifier )
+import GHC.Types.Name.Occurrence ( occNameString )
+import GHC.Types.Name.Reader ( RdrName(..) )
+import GHC.Types.SrcLoc ( mkRealSrcLoc, GenLocated(..) )
+import GHC.Data.StringBuffer ( stringToStringBuffer )
+
+
+parseParas :: DynFlags -> Maybe Package -> String -> MetaDoc mod (Wrap NsRdrName)
+parseParas d p = overDoc (P.overIdentifier (parseIdent d)) . P.parseParas p
+
+parseString :: DynFlags -> String -> DocH mod (Wrap NsRdrName)
+parseString d = P.overIdentifier (parseIdent d) . P.parseString
+
+parseIdent :: DynFlags -> Namespace -> String -> Maybe (Wrap NsRdrName)
+parseIdent dflags ns str0 =
+  case unP parseIdentifier (pstate str1) of
+    POk _ (L _ name)
+      -- Guards against things like 'Q.--', 'Q.case', etc.
+      -- See https://github.com/haskell/haddock/issues/952 and Trac #14109
+      | Qual _ occ <- name
+      , PFailed{} <- unP parseIdentifier (pstate (occNameString occ))
+      -> Nothing
+      | otherwise
+      -> Just (wrap (NsRdrName ns name))
+    PFailed{} -> Nothing
+  where
+    realSrcLc = mkRealSrcLoc (fsLit "<unknown file>") 0 0
+    pstate str = initParserState (initParserOpts dflags) (stringToStringBuffer str) realSrcLc
+    (wrap,str1) = case str0 of
+                    '(' : s@(c : _) | c /= ',', c /= ')'  -- rule out tuple names
+                                    -> (Parenthesized, init s)
+                    '`' : s@(_ : _) -> (Backticked,    init s)
+                    _               -> (Unadorned,     str0)
diff --git a/haddock-api/src/Haddock/Syb.hs b/haddock-api/src/Haddock/Syb.hs
new file mode 100644
--- /dev/null
+++ b/haddock-api/src/Haddock/Syb.hs
@@ -0,0 +1,73 @@
+{-# LANGUAGE Rank2Types #-}
+{-# LANGUAGE AllowAmbiguousTypes #-}
+{-# LANGUAGE TypeApplications #-}
+{-# LANGUAGE ScopedTypeVariables #-}
+
+module Haddock.Syb
+    ( everythingWithState
+    , everywhereButType
+    , mkT
+    , mkQ
+    , extQ
+    ) where
+
+
+import Data.Data
+import Data.Maybe
+import Data.Foldable
+
+-- | Returns true if a == t.
+-- requires AllowAmbiguousTypes
+isType :: forall a b. (Typeable a, Typeable b) => b -> Bool
+isType _ = isJust $ eqT @a @b
+
+-- | Perform a query with state on each level of a tree.
+--
+-- This is the same as 'everything' but allows for stateful computations. In
+-- SYB it is called @everythingWithContext@ but I find this name somewhat
+-- nicer.
+everythingWithState :: s -> (r -> r -> r)
+                    -> (forall a. Data a => a -> s -> (r, s))
+                    -> (forall a. Data a => a -> r)
+everythingWithState s k f x =
+    let (r, s') = f x s
+    in foldl' k r (gmapQ (everythingWithState s' k f) x)
+
+-- | Variation on everywhere with an extra stop condition
+-- Just like 'everything', this is stolen from SYB package.
+everywhereBut :: (forall a. Data a => a -> Bool)
+  -> (forall a. Data a => a -> a)
+  -> (forall a. Data a => a -> a)
+everywhereBut q f x
+    | q x       = x
+    | otherwise = f (gmapT (everywhereBut q f) x)
+
+-- | Variation of "everywhere" that does not recurse into children of type t
+-- requires AllowAmbiguousTypes
+everywhereButType :: forall t . (Typeable t)
+  => (forall a. Data a => a -> a)
+  -> (forall a. Data a => a -> a)
+everywhereButType = everywhereBut (isType @t)
+
+-- | Create generic transformation.
+--
+-- Another function stolen from SYB package.
+mkT :: (Typeable a, Typeable b) => (b -> b) -> (a -> a)
+mkT f = case cast f of
+    Just f' -> f'
+    Nothing -> id
+
+-- | Create generic query.
+--
+-- Another function stolen from SYB package.
+mkQ :: (Typeable a, Typeable b) => r -> (b -> r) -> a -> r
+(r `mkQ` br) a = case cast a of
+                        Just b  -> br b
+                        Nothing -> r
+
+
+-- | Extend a generic query by a type-specific case.
+--
+-- Another function stolen from SYB package.
+extQ :: (Typeable a, Typeable b) => (a -> q) -> (b -> q) -> a -> q
+extQ f g a = maybe (f a) g (cast a)
diff --git a/haddock-api/src/Haddock/Types.hs b/haddock-api/src/Haddock/Types.hs
new file mode 100644
--- /dev/null
+++ b/haddock-api/src/Haddock/Types.hs
@@ -0,0 +1,1142 @@
+{-# LANGUAGE BangPatterns #-}
+{-# LANGUAGE CPP #-}
+{-# LANGUAGE DeriveDataTypeable #-}
+{-# LANGUAGE DeriveTraversable #-}
+{-# LANGUAGE StandaloneDeriving #-}
+{-# LANGUAGE TypeFamilies #-}
+{-# LANGUAGE RecordWildCards #-}
+{-# LANGUAGE TypeOperators #-}
+{-# LANGUAGE ConstraintKinds #-}
+{-# LANGUAGE FlexibleContexts #-}
+{-# LANGUAGE PartialTypeSignatures #-}
+{-# LANGUAGE UndecidableInstances #-} -- Note [Pass sensitive types]
+{-# LANGUAGE FlexibleInstances #-}
+{-# LANGUAGE DerivingStrategies #-}
+{-# LANGUAGE MultiParamTypeClasses #-}
+{-# LANGUAGE GeneralizedNewtypeDeriving #-}
+{-# OPTIONS_GHC -fno-warn-orphans #-}
+
+-----------------------------------------------------------------------------
+-- |
+-- Module      :  Haddock.Types
+-- Copyright   :  (c) Simon Marlow      2003-2006,
+--                    David Waern       2006-2009,
+--                    Mateusz Kowalczyk 2013
+-- License     :  BSD-like
+--
+-- Maintainer  :  haddock@projects.haskellorg
+-- Stability   :  experimental
+-- Portability :  portable
+--
+-- Types that are commonly used through-out Haddock. Some of the most
+-- important types are defined here, like 'Interface' and 'DocName'.
+-----------------------------------------------------------------------------
+module Haddock.Types (
+  module Haddock.Types
+  , HsDocString, LHsDocString
+  , Fixity(..)
+  , module Documentation.Haddock.Types
+ ) where
+
+import Control.DeepSeq
+import Control.Exception (throw)
+import Control.Monad.Catch
+import Control.Monad.State.Strict
+import Data.Typeable (Typeable)
+import Data.Map (Map)
+import Data.Data (Data)
+import qualified Data.Set as Set
+import Documentation.Haddock.Types
+import qualified GHC.Data.Strict as Strict
+import GHC.Types.Fixity (Fixity(..))
+import GHC.Types.Name (stableNameCmp)
+import GHC.Types.Name.Reader (RdrName(..))
+import GHC.Types.SourceText (SourceText(..))
+import GHC.Types.SrcLoc (BufSpan(..), BufPos(..))
+import GHC.Types.Var (Specificity)
+
+import GHC
+import GHC.Driver.Session (Language)
+import qualified GHC.LanguageExtensions as LangExt
+import GHC.Types.Name.Occurrence
+import GHC.Utils.Outputable
+
+-----------------------------------------------------------------------------
+-- * Convenient synonyms
+-----------------------------------------------------------------------------
+
+
+type IfaceMap      = Map Module Interface
+type InstIfaceMap  = Map Module InstalledInterface  -- TODO: rename
+type DocMap a      = Map Name (MDoc a)
+type ArgMap a      = Map Name (Map Int (MDoc a))
+type SubMap        = Map Name [Name]
+type DeclMap       = Map Name DeclMapEntry
+type InstMap       = Map RealSrcSpan Name
+type FixMap        = Map Name Fixity
+type DocPaths      = (FilePath, Maybe FilePath) -- paths to HTML and sources
+type WarningMap    = Map Name (Doc Name)
+
+
+-----------------------------------------------------------------------------
+-- * Interfaces and Interface creation
+-----------------------------------------------------------------------------
+
+-- | 'Interface' holds all information used to render a single Haddock page.
+-- It represents the /interface/ of a module. The core business of Haddock
+-- lies in creating this structure. Note that the record contains some fields
+-- that are only used to create the final record, and that are not used by the
+-- backends.
+data Interface = Interface
+  {
+    -- | The module behind this interface.
+    ifaceMod             :: !Module
+
+    -- | Is this a signature?
+  , ifaceIsSig           :: !Bool
+
+    -- | Original file name of the module.
+  , ifaceOrigFilename    :: !FilePath
+
+    -- | Textual information about the module.
+  , ifaceInfo            :: !(HaddockModInfo Name)
+
+    -- | Documentation header.
+  , ifaceDoc             :: !(Documentation Name)
+
+    -- | Documentation header with cross-reference information.
+  , ifaceRnDoc           :: !(Documentation DocName)
+
+    -- | Haddock options for this module (prune, ignore-exports, etc).
+  , ifaceOptions         :: [DocOption]
+
+    -- | Declarations originating from the module. Excludes declarations without
+    -- names (instances and stand-alone documentation comments). Includes
+    -- names of subordinate declarations mapped to their parent declarations.
+  , ifaceDeclMap         :: !DeclMap
+
+    -- | Documentation of declarations originating from the module (including
+    -- subordinates).
+  , ifaceDocMap          :: !(DocMap Name)
+  , ifaceArgMap          :: !(ArgMap Name)
+
+  , ifaceFixMap          :: !(Map Name Fixity)
+
+  , ifaceExportItems     :: [ExportItem GhcRn]
+  , ifaceRnExportItems   :: [ExportItem DocNameI]
+
+    -- | All names exported by the module.
+  , ifaceExports         :: [Name]
+
+    -- | All \"visible\" names exported by the module.
+    -- A visible name is a name that will show up in the documentation of the
+    -- module.
+  , ifaceVisibleExports  :: [Name]
+
+    -- | Aliases of module imports as in @import A.B.C as C@.
+  , ifaceModuleAliases   :: !AliasMap
+
+    -- | Instances exported by the module.
+  , ifaceInstances       :: [HaddockClsInst]
+
+    -- | Orphan instances
+  , ifaceOrphanInstances   :: [DocInstance GhcRn]
+  , ifaceRnOrphanInstances :: [DocInstance DocNameI]
+
+    -- | The number of haddockable and haddocked items in the module, as a
+    -- tuple. Haddockable items are the exports and the module itself.
+  , ifaceHaddockCoverage :: (Int, Int)
+
+    -- | Warnings for things defined in this module.
+  , ifaceWarningMap :: WarningMap
+
+    -- | Tokenized source code of module (available if Haddock is invoked with
+    -- source generation flag).
+  , ifaceHieFile :: !(Maybe FilePath)
+
+  , ifaceDynFlags :: !DynFlags
+  }
+
+-- | A subset of the fields of 'Interface' that we store in the interface
+-- files.
+data InstalledInterface = InstalledInterface
+  {
+    -- | The module represented by this interface.
+    instMod              :: Module
+
+    -- | Is this a signature?
+  , instIsSig            :: Bool
+
+    -- | Textual information about the module.
+  , instInfo             :: HaddockModInfo Name
+
+    -- | Documentation of declarations originating from the module (including
+    -- subordinates).
+  , instDocMap           :: DocMap Name
+
+  , instArgMap           :: ArgMap Name
+
+    -- | All names exported by this module.
+  , instExports          :: [Name]
+
+    -- | All \"visible\" names exported by the module.
+    -- A visible name is a name that will show up in the documentation of the
+    -- module.
+  , instVisibleExports   :: [Name]
+
+    -- | Haddock options for this module (prune, ignore-exports, etc).
+  , instOptions          :: [DocOption]
+
+  , instFixMap           :: Map Name Fixity
+  }
+
+-- | Convert an 'Interface' to an 'InstalledInterface'
+toInstalledIface :: Interface -> InstalledInterface
+toInstalledIface interface = InstalledInterface
+  { instMod              = ifaceMod              interface
+  , instIsSig            = ifaceIsSig            interface
+  , instInfo             = ifaceInfo             interface
+  , instDocMap           = ifaceDocMap           interface
+  , instArgMap           = ifaceArgMap           interface
+  , instExports          = ifaceExports          interface
+  , instVisibleExports   = ifaceVisibleExports   interface
+  , instOptions          = ifaceOptions          interface
+  , instFixMap           = ifaceFixMap           interface
+  }
+
+
+-- | A monad in which we create Haddock interfaces. Not to be confused with
+-- `GHC.Tc.Types.IfM` which is used to write GHC interfaces.
+--
+-- In the past `createInterface` was running in the `Ghc` monad but proved hard
+-- to sustain as soon as we moved over for Haddock to be a plugin. Also abstracting
+-- over the Ghc specific clarifies where side effects happen.
+newtype IfM m a = IfM { unIfM :: StateT (IfEnv m) m a }
+
+deriving newtype instance Functor m                => Functor (IfM m)
+deriving newtype instance (Monad m, Applicative m) => Applicative (IfM m)
+deriving newtype instance Monad m                  => Monad (IfM m)
+deriving newtype instance MonadIO m                => MonadIO (IfM m)
+deriving newtype instance Monad m                  => MonadState (IfEnv m) (IfM m)
+
+-- | Interface creation environment. The name sets are used primarily during
+-- processing of doc strings to avoid emitting the same type of warning for the
+-- same name twice. This was previously done using a Writer monad and then
+-- nubbing the list of warning messages after accumulation. This new approach
+-- was implemented to avoid the nubbing of potentially large lists of strings.
+data IfEnv m = IfEnv
+  {
+    -- | Lookup names in the environment.
+    ifeLookupName :: Name -> m (Maybe TyThing)
+
+    -- | Names which we have warned about for being out of scope
+  , ifeOutOfScopeNames :: !(Set.Set String)
+
+    -- | Names which we have warned about for being ambiguous
+  , ifeAmbiguousNames  :: !(Set.Set String)
+
+    -- | Named which we have warned about for being inappropriately namespaced
+    -- as values
+  , ifeInvalidValues   :: !(Set.Set String)
+  }
+
+-- | Run an `IfM` action.
+runIfM
+  :: (Monad m)
+  -- | Lookup a global name in the current session. Used in cases
+  -- where declarations don't
+  => (Name -> m (Maybe TyThing))
+  -- | The action to run.
+  -> IfM m a
+  -- | Result and accumulated error/warning messages.
+  -> m a
+runIfM lookup_name action = do
+  let
+    if_env = IfEnv
+      {
+        ifeLookupName      = lookup_name
+      , ifeOutOfScopeNames = Set.empty
+      , ifeAmbiguousNames  = Set.empty
+      , ifeInvalidValues   = Set.empty
+      }
+  evalStateT (unIfM action) if_env
+
+-- | Look up a name in the current environment
+lookupName :: Monad m => Name -> IfM m (Maybe TyThing)
+lookupName name = IfM $ do
+  lookup_name <- gets ifeLookupName
+  lift (lookup_name name)
+
+-- | Very basic logging function that simply prints to stdout
+warn :: MonadIO m => String -> IfM m ()
+warn msg = liftIO $ putStrLn msg
+
+-----------------------------------------------------------------------------
+-- * Export items & declarations
+-----------------------------------------------------------------------------
+
+
+data ExportItem name
+
+  -- | An exported declaration.
+  = ExportDecl (XExportDecl name)
+
+  -- | An exported entity for which we have no documentation (perhaps because it
+  -- resides in another package).
+  | ExportNoDecl
+      { expItemName :: !(IdP name)
+
+        -- | Subordinate names.
+      , expItemSubs :: [IdP name]
+      }
+
+  -- | A section heading.
+  | ExportGroup
+      {
+        -- | Section level (1, 2, 3, ...).
+        expItemSectionLevel :: !Int
+
+        -- | Section id (for hyperlinks).
+      , expItemSectionId :: !String
+
+        -- | Section heading text.
+      , expItemSectionText :: !(Doc (IdP name))
+      }
+
+  -- | Some documentation.
+  | ExportDoc !(MDoc (IdP name))
+
+  -- | A cross-reference to another module.
+  | ExportModule !Module
+
+-- | A type family mapping a name type index to types of export declarations.
+-- The pre-renaming type index ('GhcRn') is mapped to the type of export
+-- declarations which do not include Hoogle output ('ExportD'), since Hoogle output is
+-- generated during the Haddock renaming step. The post-renaming type index
+-- ('DocNameI') is mapped to the type of export declarations which do include
+-- Hoogle output ('RnExportD').
+type family XExportDecl x where
+  XExportDecl GhcRn    = ExportD GhcRn
+  XExportDecl DocNameI = RnExportD
+
+-- | Represents an export declaration that Haddock has discovered to be exported
+-- from a module. The @name@ index indicated whether the declaration has been
+-- renamed such that each 'Name' points to it's optimal link destination.
+data ExportD name = ExportD
+      {
+        -- | A declaration.
+        expDDecl :: !(LHsDecl name)
+
+        -- | Bundled patterns for a data type declaration
+      , expDPats :: [(HsDecl name, DocForDecl (IdP name))]
+
+        -- | Maybe a doc comment, and possibly docs for arguments (if this
+        -- decl is a function or type-synonym).
+      , expDMbDoc :: !(DocForDecl (IdP name))
+
+        -- | Subordinate names, possibly with documentation.
+      , expDSubDocs :: [(IdP name, DocForDecl (IdP name))]
+
+        -- | Instances relevant to this declaration, possibly with
+        -- documentation.
+      , expDInstances :: [DocInstance name]
+
+        -- | Fixity decls relevant to this declaration (including subordinates).
+      , expDFixities :: [(IdP name, Fixity)]
+
+        -- | Whether the ExportD is from a TH splice or not, for generating
+        -- the appropriate type of Source link.
+      , expDSpliced :: !Bool
+      }
+
+-- | Represents export declarations that have undergone renaming such that every
+-- 'Name' in the declaration points to an optimal link destination. Since Hoogle
+-- output is also generated during the renaming step, each declaration is also
+-- attached to its Hoogle textual database entries, /if/ Hoogle output is
+-- enabled and the module is not hidden in the generated documentation using the
+-- @{-# OPTIONS_HADDOCK hide #-}@ pragma.
+data RnExportD = RnExportD
+      {
+        -- | The renamed export declaration
+        rnExpDExpD :: !(ExportD DocNameI)
+
+      -- | If Hoogle textbase (textual database) output is enabled, the text
+      -- output lines for this declaration. If Hoogle output is not enabled, the
+      -- list will be empty.
+      , rnExpDHoogle :: [String]
+      }
+
+data Documentation name = Documentation
+  { documentationDoc     :: Maybe (MDoc name)
+  , documentationWarning :: Maybe (Doc name)
+  } deriving Functor
+
+instance NFData name => NFData (Documentation name) where
+  rnf (Documentation d w) = d `deepseq` w `deepseq` ()
+
+-- | Arguments and result are indexed by Int, zero-based from the left,
+-- because that's the easiest to use when recursing over types.
+type FnArgsDoc name = Map Int (MDoc name)
+type DocForDecl name = (Documentation name, FnArgsDoc name)
+
+noDocForDecl :: DocForDecl name
+noDocForDecl = (Documentation Nothing Nothing, mempty)
+
+-- | As we build the declaration map, we really only care to track whether we
+-- have only seen a value declaration for a 'Name', or anything else. This type
+-- is used to represent those cases. If the only declaration attached to a
+-- 'Name' is a 'ValD', we will consult the GHC interface file to determine the
+-- type of the value, and attach the 'SrcSpan' from the 'EValD' constructor to
+-- it. If we see any other type of declaration for the 'Name', we can just use
+-- it.
+--
+-- This type saves us from storing /every/ declaration we see for a given 'Name'
+-- in the map, which is unnecessary and very problematic for overall memory
+-- usage.
+data DeclMapEntry
+    = EValD !SrcSpan
+    | EOther (LHsDecl GhcRn)
+
+instance Semigroup DeclMapEntry where
+  (EValD _)   <> e         = e
+  e           <> _         = e
+
+-- | Transform a declaration into a 'DeclMapEntry'. If it is a 'ValD'
+-- declaration, only the source location will be noted (since that is all we
+-- care to store in the 'DeclMap' due to the way top-level bindings with no type
+-- signatures are handled). Otherwise, the entire declaration will be kept.
+toDeclMapEntry :: LHsDecl GhcRn -> DeclMapEntry
+toDeclMapEntry (L l (ValD _ _)) = EValD (locA l)
+toDeclMapEntry d                = EOther d
+
+-----------------------------------------------------------------------------
+-- * Cross-referencing
+-----------------------------------------------------------------------------
+
+
+-- | Type of environment used to cross-reference identifiers in the syntax.
+type LinkEnv = Map Name Module
+
+-- | An 'RdrName' tagged with some type/value namespace information.
+data NsRdrName = NsRdrName
+  { namespace :: !Namespace
+  , rdrName :: !RdrName
+  }
+
+instance NFData NsRdrName where
+  rnf (NsRdrName ns rdrN) = ns `seq` rdrN `deepseq` ()
+
+-- | Extends 'Name' with cross-reference information.
+data DocName
+  = Documented Name Module
+     -- ^ This thing is part of the (existing or resulting)
+     -- documentation. The 'Module' is the preferred place
+     -- in the documentation to refer to.
+  | Undocumented Name
+     -- ^ This thing is not part of the (existing or resulting)
+     -- documentation, as far as Haddock knows.
+  deriving (Eq, Data)
+
+data DocNameI
+
+type instance NoGhcTc DocNameI = DocNameI
+
+type instance IdP DocNameI = DocName
+
+instance CollectPass DocNameI where
+  collectXXPat _ ext = dataConCantHappen ext
+  collectXXHsBindsLR ext = dataConCantHappen ext
+  collectXSplicePat _ ext = dataConCantHappen ext
+
+instance NamedThing DocName where
+  getName (Documented name _) = name
+  getName (Undocumented name) = name
+
+-- | Useful for debugging
+instance Outputable DocName where
+  ppr = ppr . getName
+
+instance OutputableBndr DocName where
+  pprBndr _ = ppr . getName
+  pprPrefixOcc = pprPrefixOcc . getName
+  pprInfixOcc = pprInfixOcc . getName
+
+class NamedThing name => SetName name where
+
+    setName :: Name -> name -> name
+
+
+instance SetName Name where
+
+    setName name' _ = name'
+
+
+instance SetName DocName where
+
+    setName name' (Documented _ mdl) = Documented name' mdl
+    setName name' (Undocumented _) = Undocumented name'
+
+-- | Adds extra "wrapper" information to a name.
+--
+-- This is to work around the fact that most name types in GHC ('Name', 'RdrName',
+-- 'OccName', ...) don't include backticks or parens.
+data Wrap n
+  = Unadorned { unwrap :: n  }     -- ^ don't do anything to the name
+  | Parenthesized { unwrap :: n }  -- ^ add parentheses around the name
+  | Backticked { unwrap :: n }     -- ^ add backticks around the name
+  deriving (Show, Functor, Foldable, Traversable)
+
+instance NFData n => NFData (Wrap n) where
+  rnf w = case w of
+    Unadorned n     -> rnf n
+    Parenthesized n -> rnf n
+    Backticked n    -> rnf n
+
+-- | Useful for debugging
+instance Outputable n => Outputable (Wrap n) where
+  ppr (Unadorned n)     = ppr n
+  ppr (Parenthesized n) = hcat [ char '(', ppr n, char ')' ]
+  ppr (Backticked n)    = hcat [ char '`', ppr n, char '`' ]
+
+showWrapped :: (a -> String) -> Wrap a -> String
+showWrapped f (Unadorned n) = f n
+showWrapped f (Parenthesized n) = "(" ++ f n ++ ")"
+showWrapped f (Backticked n) = "`" ++ f n ++ "`"
+
+instance HasOccName DocName where
+
+    occName = occName . getName
+
+-----------------------------------------------------------------------------
+-- * Instances
+-----------------------------------------------------------------------------
+
+data HaddockClsInst = HaddockClsInst
+    { haddockClsInstPprHoogle :: Maybe String
+    , haddockClsInstName      :: Name
+    , haddockClsInstClsName   :: Name
+    , haddockClsInstIsOrphan  :: Bool
+    , haddockClsInstHead      :: ([Int], SName, [SimpleType])
+    , haddockClsInstSynified  :: InstHead GhcRn
+    , haddockClsInstTyNames   :: Set.Set Name
+    }
+
+-- | TODO: This instance is not lawful. We leave the 'InstHead' segment of the
+-- class instance evaluated only to WHNF. This should probably be fixed.
+instance NFData HaddockClsInst where
+  rnf (HaddockClsInst h n cn o hd s ns) =
+              h
+    `deepseq` n
+    `deepseq` cn
+    `deepseq` o
+    `deepseq` hd
+    `deepseq` s
+    `seq`     ns
+    `deepseq` ()
+
+-- | Stable name for stable comparisons. GHC's `Name` uses unstable
+-- ordering based on their `Unique`'s.
+newtype SName = SName Name
+  deriving newtype NFData
+
+instance Eq SName where
+  SName n1 == SName n2 = n1 `stableNameCmp` n2 == EQ
+
+instance Ord SName where
+  SName n1 `compare` SName n2 = n1 `stableNameCmp` n2
+
+-- | Simplified type for sorting types, ignoring qualification (not visible
+-- in Haddock output) and unifying special tycons with normal ones.
+-- For the benefit of the user (looks nice and predictable) and the
+-- tests (which prefer output to be deterministic).
+data SimpleType = SimpleType SName [SimpleType]
+                | SimpleIntTyLit Integer
+                | SimpleStringTyLit String
+                | SimpleCharTyLit Char
+                  deriving (Eq,Ord)
+
+instance NFData SimpleType where
+  rnf st =
+    case st of
+      SimpleType sn sts   -> sn `deepseq` sts `deepseq` ()
+      SimpleIntTyLit i    -> rnf i
+      SimpleStringTyLit s -> rnf s
+      SimpleCharTyLit c   -> rnf c
+
+-- | The three types of instances
+data InstType name
+  = ClassInst
+      { clsiCtx :: [HsType name]
+      , clsiTyVars :: LHsQTyVars name
+      , clsiSigs :: [Sig name]
+      , clsiAssocTys :: [PseudoFamilyDecl name]
+      }
+  | TypeInst  (Maybe (HsType name)) -- ^ Body (right-hand side)
+  | DataInst (TyClDecl name)        -- ^ Data constructors
+
+instance (OutputableBndrId p)
+         => Outputable (InstType (GhcPass p)) where
+  ppr (ClassInst { .. }) = text "ClassInst"
+      <+> ppr clsiCtx
+      <+> ppr clsiTyVars
+      <+> ppr clsiSigs
+  ppr (TypeInst  a) = text "TypeInst"  <+> ppr a
+  ppr (DataInst  a) = text "DataInst"  <+> ppr a
+
+
+-- | Almost the same as 'FamilyDecl' except for type binders.
+--
+-- In order to perform type specialization for class instances, we need to
+-- substitute class variables to appropriate type. However, type variables in
+-- associated type are specified using 'LHsTyVarBndrs' instead of 'HsType'.
+-- This makes type substitution impossible and to overcome this issue,
+-- 'PseudoFamilyDecl' type is introduced.
+data PseudoFamilyDecl name = PseudoFamilyDecl
+    { pfdInfo :: FamilyInfo name
+    , pfdLName :: LocatedN (IdP name)
+    , pfdTyVars :: [LHsType name]
+    , pfdKindSig :: LFamilyResultSig name
+    }
+
+
+mkPseudoFamilyDecl :: FamilyDecl GhcRn -> PseudoFamilyDecl GhcRn
+mkPseudoFamilyDecl (FamilyDecl { .. }) = PseudoFamilyDecl
+    { pfdInfo = fdInfo
+    , pfdLName = fdLName
+    , pfdTyVars = [ L loc (mkType bndr) | L loc bndr <- hsq_explicit fdTyVars ]
+    , pfdKindSig = fdResultSig
+    }
+  where
+    mkType :: HsTyVarBndr flag GhcRn -> HsType GhcRn
+    mkType (KindedTyVar _ _ (L loc name) lkind) =
+        HsKindSig noAnn tvar lkind
+      where
+        tvar = L (na2la loc) (HsTyVar noAnn NotPromoted (L loc name))
+    mkType (UserTyVar _ _ name) = HsTyVar noAnn NotPromoted name
+
+
+-- | An instance head that may have documentation and a source location.
+type DocInstance name = (InstHead name, Maybe (MDoc (IdP name)), Located (IdP name), Maybe Module)
+
+-- | The head of an instance. Consists of a class name, a list of type
+-- parameters (which may be annotated with kinds), and an instance type
+data InstHead name = InstHead
+    { ihdClsName :: IdP name
+    , ihdTypes :: [HsType name]
+    , ihdInstType :: InstType name
+    }
+
+
+-- | An instance origin information.
+--
+-- This is used primarily in HTML backend to generate unique instance
+-- identifiers (for expandable sections).
+data InstOrigin name
+    = OriginClass name
+    | OriginData name
+    | OriginFamily name
+
+
+instance NamedThing name => NamedThing (InstOrigin name) where
+
+    getName (OriginClass name) = getName name
+    getName (OriginData name) = getName name
+    getName (OriginFamily name) = getName name
+
+
+-----------------------------------------------------------------------------
+-- * Documentation comments
+-----------------------------------------------------------------------------
+
+
+type LDoc id = Located (Doc id)
+
+type Doc id = DocH (Wrap (ModuleName, OccName)) (Wrap id)
+type MDoc id = MetaDoc (Wrap (ModuleName, OccName)) (Wrap id)
+
+type DocMarkup id a = DocMarkupH (Wrap (ModuleName, OccName)) id a
+
+instance NFData Meta where
+  rnf (Meta v p) = v `deepseq` p `deepseq` ()
+
+instance NFData id => NFData (MDoc id) where
+  rnf (MetaDoc m d) = m `deepseq` d `deepseq` ()
+
+instance (NFData a, NFData mod)
+         => NFData (DocH mod a) where
+  rnf doc = case doc of
+    DocEmpty                  -> ()
+    DocAppend a b             -> a `deepseq` b `deepseq` ()
+    DocString a               -> a `deepseq` ()
+    DocParagraph a            -> a `deepseq` ()
+    DocIdentifier a           -> a `deepseq` ()
+    DocIdentifierUnchecked a  -> a `deepseq` ()
+    DocModule a               -> a `deepseq` ()
+    DocWarning a              -> a `deepseq` ()
+    DocEmphasis a             -> a `deepseq` ()
+    DocBold a                 -> a `deepseq` ()
+    DocMonospaced a           -> a `deepseq` ()
+    DocUnorderedList a        -> a `deepseq` ()
+    DocOrderedList a          -> a `deepseq` ()
+    DocDefList a              -> a `deepseq` ()
+    DocCodeBlock a            -> a `deepseq` ()
+    DocHyperlink a            -> a `deepseq` ()
+    DocPic a                  -> a `deepseq` ()
+    DocMathInline a           -> a `deepseq` ()
+    DocMathDisplay a          -> a `deepseq` ()
+    DocAName a                -> a `deepseq` ()
+    DocProperty a             -> a `deepseq` ()
+    DocExamples a             -> a `deepseq` ()
+    DocHeader a               -> a `deepseq` ()
+    DocTable a                -> a `deepseq` ()
+
+#if !MIN_VERSION_ghc(8,0,2)
+-- These were added to GHC itself in 8.0.2
+instance NFData Name where rnf x = seq x ()
+instance NFData OccName where rnf x = seq x ()
+instance NFData ModuleName where rnf x = seq x ()
+#endif
+
+instance NFData id => NFData (Header id) where
+  rnf (Header a b) = a `deepseq` b `deepseq` ()
+
+instance NFData id => NFData (Hyperlink id) where
+  rnf (Hyperlink a b) = a `deepseq` b `deepseq` ()
+
+instance NFData id => NFData (ModLink id) where
+  rnf (ModLink a b) = a `deepseq` b `deepseq` ()
+
+instance NFData Picture where
+  rnf (Picture a b) = a `deepseq` b `deepseq` ()
+
+instance NFData Example where
+  rnf (Example a b) = a `deepseq` b `deepseq` ()
+
+instance NFData id => NFData (Table id) where
+    rnf (Table h b) = h `deepseq` b `deepseq` ()
+
+instance NFData id => NFData (TableRow id) where
+    rnf (TableRow cs) = cs `deepseq` ()
+
+instance NFData id => NFData (TableCell id) where
+    rnf (TableCell i j c) = i `deepseq` j `deepseq` c `deepseq` ()
+
+exampleToString :: Example -> String
+exampleToString (Example expression result) =
+    ">>> " ++ expression ++ "\n" ++  unlines result
+
+instance NFData name => NFData (HaddockModInfo name) where
+  rnf (HaddockModInfo{..}) =
+              hmi_description
+    `deepseq` hmi_copyright
+    `deepseq` hmi_license
+    `deepseq` hmi_maintainer
+    `deepseq` hmi_stability
+    `deepseq` hmi_portability
+    `deepseq` hmi_safety
+    `deepseq` hmi_language
+    `deepseq` hmi_extensions
+    `deepseq` ()
+
+instance NFData LangExt.Extension
+
+data HaddockModInfo name = HaddockModInfo
+  { hmi_description :: Maybe (Doc name)
+  , hmi_copyright   :: Maybe String
+  , hmi_license     :: Maybe String
+  , hmi_maintainer  :: Maybe String
+  , hmi_stability   :: Maybe String
+  , hmi_portability :: Maybe String
+  , hmi_safety      :: Maybe String
+  , hmi_language    :: Maybe Language
+  , hmi_extensions  :: [LangExt.Extension]
+  }
+
+emptyHaddockModInfo :: HaddockModInfo a
+emptyHaddockModInfo = HaddockModInfo
+  { hmi_description = Nothing
+  , hmi_copyright   = Nothing
+  , hmi_license     = Nothing
+  , hmi_maintainer  = Nothing
+  , hmi_stability   = Nothing
+  , hmi_portability = Nothing
+  , hmi_safety      = Nothing
+  , hmi_language    = Nothing
+  , hmi_extensions  = []
+  }
+
+
+-----------------------------------------------------------------------------
+-- * Options
+-----------------------------------------------------------------------------
+
+
+-- | Source-level options for controlling the documentation.
+data DocOption
+  = OptHide            -- ^ This module should not appear in the docs.
+  | OptPrune
+  | OptIgnoreExports   -- ^ Pretend everything is exported.
+  | OptNotHome         -- ^ Not the best place to get docs for things
+                       -- exported by this module.
+  | OptShowExtensions  -- ^ Render enabled extensions for this module.
+  deriving (Eq, Show)
+
+
+-- | Option controlling how to qualify names
+data QualOption
+  = OptNoQual         -- ^ Never qualify any names.
+  | OptFullQual       -- ^ Qualify all names fully.
+  | OptLocalQual      -- ^ Qualify all imported names fully.
+  | OptRelativeQual   -- ^ Like local, but strip module prefix
+                      --   from modules in the same hierarchy.
+  | OptAliasedQual    -- ^ Uses aliases of module names
+                      --   as suggested by module import renamings.
+                      --   However, we are unfortunately not able
+                      --   to maintain the original qualifications.
+                      --   Image a re-export of a whole module,
+                      --   how could the re-exported identifiers be qualified?
+
+type AliasMap = Map Module ModuleName
+
+data Qualification
+  = NoQual
+  | FullQual
+  | LocalQual Module
+  | RelativeQual Module
+  | AliasedQual AliasMap Module
+       -- ^ @Module@ contains the current module.
+       --   This way we can distinguish imported and local identifiers.
+
+makeContentsQual :: QualOption -> Qualification
+makeContentsQual qual =
+  case qual of
+    OptNoQual -> NoQual
+    _         -> FullQual
+
+makeModuleQual :: QualOption -> AliasMap -> Module -> Qualification
+makeModuleQual qual aliases mdl =
+  case qual of
+    OptLocalQual      -> LocalQual mdl
+    OptRelativeQual   -> RelativeQual mdl
+    OptAliasedQual    -> AliasedQual aliases mdl
+    OptFullQual       -> FullQual
+    OptNoQual         -> NoQual
+
+-- | Whether to hide empty contexts
+-- Since pattern synonyms have two contexts with different semantics, it is
+-- important to all of them, even if one of them is empty.
+data HideEmptyContexts
+  = HideEmptyContexts
+  | ShowEmptyToplevelContexts
+
+-- | When to qualify @since@ annotations with their package
+data SinceQual
+  = Always
+  | External -- ^ only qualify when the thing being annotated is from
+             -- an external package
+
+-----------------------------------------------------------------------------
+-- * Error handling
+-----------------------------------------------------------------------------
+
+-- | Haddock's own exception type.
+data HaddockException
+  = HaddockException String
+  | WithContext [String] SomeException
+  deriving Typeable
+
+instance Show HaddockException where
+  show (HaddockException str) = str
+  show (WithContext ctxts se)  = unlines $ ["While " ++ ctxt ++ ":\n" | ctxt <- reverse ctxts] ++ [show se]
+
+throwE :: String -> a
+instance Exception HaddockException
+throwE str = throw (HaddockException str)
+
+withExceptionContext :: MonadCatch m => String -> m a -> m a
+withExceptionContext ctxt =
+  handle (\ex ->
+      case ex of
+        HaddockException _ -> throwM $ WithContext [ctxt] (toException ex)
+        WithContext ctxts se -> throwM $ WithContext (ctxt:ctxts) se
+          ) .
+  handle (throwM . WithContext [ctxt])
+
+-----------------------------------------------------------------------------
+-- * Pass sensitive types
+-----------------------------------------------------------------------------
+
+type instance XRec DocNameI a = GenLocated (Anno a) a
+instance UnXRec DocNameI where
+  unXRec = unLoc
+instance MapXRec DocNameI where
+  mapXRec = fmap
+instance WrapXRec DocNameI (HsType DocNameI) where
+  wrapXRec = noLocA
+
+type instance Anno DocName                           = SrcSpanAnnN
+type instance Anno (HsTyVarBndr flag DocNameI)       = SrcSpanAnnA
+type instance Anno [LocatedA (HsType DocNameI)]      = SrcSpanAnnC
+type instance Anno (HsType DocNameI)                 = SrcSpanAnnA
+type instance Anno (DataFamInstDecl DocNameI)        = SrcSpanAnnA
+type instance Anno (DerivStrategy DocNameI)          = SrcAnn NoEpAnns
+type instance Anno (FieldOcc DocNameI)               = SrcAnn NoEpAnns
+type instance Anno (ConDeclField DocNameI)           = SrcSpan
+type instance Anno (Located (ConDeclField DocNameI)) = SrcSpan
+type instance Anno [Located (ConDeclField DocNameI)] = SrcSpan
+type instance Anno (ConDecl DocNameI)                = SrcSpan
+type instance Anno (FunDep DocNameI)                 = SrcSpan
+type instance Anno (TyFamInstDecl DocNameI)          = SrcSpanAnnA
+type instance Anno [LocatedA (TyFamInstDecl DocNameI)] = SrcSpanAnnL
+type instance Anno (FamilyDecl DocNameI)               = SrcSpan
+type instance Anno (Sig DocNameI)                      = SrcSpan
+type instance Anno (InjectivityAnn DocNameI)           = SrcAnn NoEpAnns
+type instance Anno (HsDecl DocNameI)                   = SrcSpanAnnA
+type instance Anno (FamilyResultSig DocNameI)          = SrcAnn NoEpAnns
+type instance Anno (HsOuterTyVarBndrs Specificity DocNameI) = SrcSpanAnnA
+type instance Anno (HsSigType DocNameI)                     = SrcSpanAnnA
+
+type XRecCond a
+  = ( XParTy a           ~ EpAnn AnnParen
+    , NoGhcTc a ~ a
+    , MapXRec a
+    , UnXRec a
+    , WrapXRec a (HsType a)
+    )
+
+type instance XForAllTy        DocNameI = EpAnn [AddEpAnn]
+type instance XQualTy          DocNameI = EpAnn [AddEpAnn]
+type instance XTyVar           DocNameI = EpAnn [AddEpAnn]
+type instance XStarTy          DocNameI = EpAnn [AddEpAnn]
+type instance XAppTy           DocNameI = EpAnn [AddEpAnn]
+type instance XAppKindTy       DocNameI = EpAnn [AddEpAnn]
+type instance XFunTy           DocNameI = EpAnn [AddEpAnn]
+type instance XListTy          DocNameI = EpAnn AnnParen
+type instance XTupleTy         DocNameI = EpAnn AnnParen
+type instance XSumTy           DocNameI = EpAnn AnnParen
+type instance XOpTy            DocNameI = EpAnn [AddEpAnn]
+type instance XParTy           DocNameI = EpAnn AnnParen
+type instance XIParamTy        DocNameI = EpAnn [AddEpAnn]
+type instance XKindSig         DocNameI = EpAnn [AddEpAnn]
+type instance XSpliceTy        DocNameI = DataConCantHappen
+type instance XDocTy           DocNameI = EpAnn [AddEpAnn]
+type instance XBangTy          DocNameI = EpAnn [AddEpAnn]
+type instance XRecTy           DocNameI = EpAnn [AddEpAnn]
+type instance XExplicitListTy  DocNameI = EpAnn [AddEpAnn]
+type instance XExplicitTupleTy DocNameI = EpAnn [AddEpAnn]
+type instance XTyLit           DocNameI = EpAnn [AddEpAnn]
+type instance XWildCardTy      DocNameI = EpAnn [AddEpAnn]
+type instance XXType           DocNameI = HsCoreTy
+
+type instance XNumTy           DocNameI = NoExtField
+type instance XStrTy           DocNameI = NoExtField
+type instance XCharTy          DocNameI = NoExtField
+type instance XXTyLit          DocNameI = DataConCantHappen
+
+type instance XHsForAllVis        DocNameI = NoExtField
+type instance XHsForAllInvis      DocNameI = NoExtField
+type instance XXHsForAllTelescope DocNameI = DataConCantHappen
+
+type instance XUserTyVar    DocNameI = NoExtField
+type instance XKindedTyVar  DocNameI = NoExtField
+type instance XXTyVarBndr   DocNameI = DataConCantHappen
+
+type instance XCFieldOcc   DocNameI = DocName
+type instance XXFieldOcc   DocNameI = NoExtField
+
+type instance XFixitySig   DocNameI = NoExtField
+type instance XFixSig      DocNameI = NoExtField
+type instance XPatSynSig   DocNameI = NoExtField
+type instance XClassOpSig  DocNameI = NoExtField
+type instance XTypeSig     DocNameI = NoExtField
+type instance XMinimalSig  DocNameI = NoExtField
+
+type instance XForeignExport  DocNameI = NoExtField
+type instance XForeignImport  DocNameI = NoExtField
+
+type instance XCImport  DocNameI = NoExtField
+type instance XCExport  DocNameI = NoExtField
+
+type instance XXForeignImport DocNameI = DataConCantHappen
+type instance XXForeignExport DocNameI = DataConCantHappen
+
+type instance XConDeclGADT    DocNameI = NoExtField
+type instance XConDeclH98     DocNameI = NoExtField
+type instance XXConDecl       DocNameI = DataConCantHappen
+
+type instance XDerivD     DocNameI = NoExtField
+type instance XInstD      DocNameI = NoExtField
+type instance XForD       DocNameI = NoExtField
+type instance XSigD       DocNameI = NoExtField
+type instance XTyClD      DocNameI = NoExtField
+
+type instance XNoSig            DocNameI = NoExtField
+type instance XCKindSig         DocNameI = NoExtField
+type instance XTyVarSig         DocNameI = NoExtField
+type instance XXFamilyResultSig DocNameI = DataConCantHappen
+
+type instance XCFamEqn       DocNameI _ = NoExtField
+type instance XXFamEqn       DocNameI _ = DataConCantHappen
+
+type instance XCClsInstDecl DocNameI = NoExtField
+type instance XCDerivDecl   DocNameI = NoExtField
+type instance XStockStrategy    DocNameI = NoExtField
+type instance XAnyClassStrategy DocNameI = NoExtField
+type instance XNewtypeStrategy  DocNameI = NoExtField
+type instance XViaStrategy  DocNameI = LHsSigType DocNameI
+type instance XDataFamInstD DocNameI = NoExtField
+type instance XTyFamInstD   DocNameI = NoExtField
+type instance XClsInstD     DocNameI = NoExtField
+type instance XCHsDataDefn  DocNameI = NoExtField
+type instance XCFamilyDecl  DocNameI = NoExtField
+type instance XClassDecl    DocNameI = NoExtField
+type instance XDataDecl     DocNameI = NoExtField
+type instance XSynDecl      DocNameI = NoExtField
+type instance XFamDecl      DocNameI = NoExtField
+type instance XXFamilyDecl  DocNameI = DataConCantHappen
+type instance XXTyClDecl    DocNameI = DataConCantHappen
+
+type instance XHsWC DocNameI _ = NoExtField
+
+type instance XHsOuterExplicit    DocNameI _ = NoExtField
+type instance XHsOuterImplicit    DocNameI   = NoExtField
+type instance XXHsOuterTyVarBndrs DocNameI   = DataConCantHappen
+
+type instance XHsSig      DocNameI = NoExtField
+type instance XXHsSigType DocNameI = DataConCantHappen
+
+type instance XHsQTvs        DocNameI = NoExtField
+type instance XConDeclField  DocNameI = NoExtField
+type instance XXConDeclField DocNameI = DataConCantHappen
+
+type instance XXPat DocNameI = DataConCantHappen
+type instance XXHsBindsLR DocNameI a = DataConCantHappen
+
+type instance XSplicePat DocNameI = DataConCantHappen
+
+type instance XCInjectivityAnn DocNameI = NoExtField
+
+type instance XCFunDep DocNameI = NoExtField
+
+type instance XCTyFamInstDecl DocNameI = NoExtField
+
+-----------------------------------------------------------------------------
+-- * NFData instances for GHC types
+-----------------------------------------------------------------------------
+
+instance NFData RdrName where
+  rnf (Unqual on) = rnf on
+  rnf (Qual mn on) = mn `deepseq` on `deepseq` ()
+  rnf (Orig m on) = m `deepseq` on `deepseq` ()
+  rnf (Exact n) = rnf n
+
+instance NFData SourceText where
+  rnf NoSourceText   = ()
+  rnf (SourceText s) = rnf s
+
+instance NFData FixityDirection where
+  rnf InfixL = ()
+  rnf InfixR = ()
+  rnf InfixN = ()
+
+instance NFData Fixity where
+  rnf (Fixity sourceText n dir) =
+    sourceText `deepseq` n `deepseq` dir `deepseq` ()
+
+instance NFData ann => NFData (SrcSpanAnn' ann) where
+  rnf (SrcSpanAnn a ss) = a `deepseq` ss `deepseq` ()
+
+instance NFData (EpAnn NameAnn) where
+  rnf EpAnnNotUsed = ()
+  rnf (EpAnn en ann cs) = en `deepseq` ann `deepseq` cs `deepseq` ()
+
+instance NFData NameAnn where
+  rnf (NameAnn a b c d e) =
+              a
+    `deepseq` b
+    `deepseq` c
+    `deepseq` d
+    `deepseq` e
+    `deepseq` ()
+  rnf (NameAnnCommas a b c d e) =
+              a
+    `deepseq` b
+    `deepseq` c
+    `deepseq` d
+    `deepseq` e
+    `deepseq` ()
+  rnf (NameAnnBars a b c d e) =
+              a
+    `deepseq` b
+    `deepseq` c
+    `deepseq` d
+    `deepseq` e
+    `deepseq` ()
+  rnf (NameAnnOnly a b c d) =
+              a
+    `deepseq` b
+    `deepseq` c
+    `deepseq` d
+    `deepseq` ()
+  rnf (NameAnnRArrow a b) =
+              a
+    `deepseq` b
+    `deepseq` ()
+  rnf (NameAnnQuote a b c) =
+              a
+    `deepseq` b
+    `deepseq` c
+    `deepseq` ()
+  rnf (NameAnnTrailing a) = rnf a
+
+instance NFData TrailingAnn where
+  rnf (AddSemiAnn epaL)  = rnf epaL
+  rnf (AddCommaAnn epaL) = rnf epaL
+  rnf (AddVbarAnn epaL)  = rnf epaL
+
+instance NFData NameAdornment where
+  rnf NameParens     = ()
+  rnf NameParensHash = ()
+  rnf NameBackquotes = ()
+  rnf NameSquare     = ()
+
+instance NFData EpaLocation where
+  rnf (EpaSpan ss bs)  = ss `seq` bs `deepseq` ()
+  rnf (EpaDelta dp lc) = dp `seq` lc `deepseq` ()
+
+instance NFData EpAnnComments where
+  rnf (EpaComments cs) = rnf cs
+  rnf (EpaCommentsBalanced cs1 cs2) = cs1 `deepseq` cs2 `deepseq` ()
+
+instance NFData EpaComment where
+  rnf (EpaComment t rss) = t `deepseq` rss `seq` ()
+
+instance NFData EpaCommentTok where
+  rnf (EpaDocComment ds)  = rnf ds
+  rnf (EpaDocOptions s)   = rnf s
+  rnf (EpaLineComment s)  = rnf s
+  rnf (EpaBlockComment s) = rnf s
+  rnf EpaEofComment       = ()
+
+
+instance NFData a => NFData (Strict.Maybe a) where
+  rnf Strict.Nothing  = ()
+  rnf (Strict.Just x) = rnf x
+
+instance NFData BufSpan where
+  rnf (BufSpan p1 p2) = p1 `deepseq` p2 `deepseq` ()
+
+instance NFData BufPos where
+  rnf (BufPos n) = rnf n
+
+instance NFData Anchor where
+  rnf (Anchor ss op) = ss `seq` op `deepseq` ()
+
+instance NFData AnchorOperation where
+  rnf UnchangedAnchor  = ()
+  rnf (MovedAnchor dp) = rnf dp
+
+instance NFData DeltaPos where
+  rnf (SameLine n)        = rnf n
+  rnf (DifferentLine n m) = n `deepseq` m `deepseq` ()
+
diff --git a/haddock-api/src/Haddock/Utils.hs b/haddock-api/src/Haddock/Utils.hs
new file mode 100644
--- /dev/null
+++ b/haddock-api/src/Haddock/Utils.hs
@@ -0,0 +1,343 @@
+{-# LANGUAGE CPP #-}
+{-# LANGUAGE GADTs #-}
+
+{-# OPTIONS_GHC -Wno-incomplete-record-updates #-}
+-----------------------------------------------------------------------------
+-- |
+-- Module      :  Haddock.Utils
+-- Copyright   :  (c) The University of Glasgow 2001-2002,
+--                    Simon Marlow 2003-2006,
+--                    David Waern  2006-2009
+-- License     :  BSD-like
+--
+-- Maintainer  :  haddock@projects.haskell.org
+-- Stability   :  experimental
+-- Portability :  portable
+-----------------------------------------------------------------------------
+module Haddock.Utils (
+
+  -- * Filename utilities
+  moduleHtmlFile, moduleHtmlFile',
+  contentsHtmlFile, indexHtmlFile, indexJsonFile,
+  subIndexHtmlFile,
+  haddockJsFile, jsQuickJumpFile,
+  quickJumpCssFile,
+
+  -- * Anchor and URL utilities
+  moduleNameUrl, moduleNameUrl', moduleUrl,
+  nameAnchorId,
+  makeAnchorId,
+
+  -- * Miscellaneous utilities
+  getProgramName, bye, die, escapeStr,
+  writeUtf8File, withTempDir,
+
+  -- * HTML cross reference mapping
+  html_xrefs_ref, html_xrefs_ref',
+
+  -- * Doc markup
+  mkMeta,
+
+  -- * List utilities
+  replace,
+  spanWith,
+
+  -- * Logging
+  parseVerbosity, Verbosity(..), silent, normal, verbose, deafening,
+  out,
+
+  -- * System tools
+  getProcessID
+ ) where
+
+
+import Documentation.Haddock.Doc (emptyMetaDoc)
+import Haddock.Types
+
+import GHC
+import GHC.Types.Name
+
+import Control.Monad.IO.Class ( MonadIO(..) )
+import Control.Monad.Catch ( MonadMask, bracket_ )
+import Data.Char ( isAlpha, isAlphaNum, isAscii, ord, chr )
+import Numeric ( showIntAtBase )
+import Data.Map ( Map )
+import qualified Data.Map as Map hiding ( Map )
+import Data.IORef ( IORef, newIORef, readIORef )
+import Data.List ( isSuffixOf )
+import System.Environment ( getProgName )
+import System.Exit
+import System.Directory ( createDirectory, removeDirectoryRecursive )
+import System.IO ( hPutStr, hSetEncoding, IOMode(..), utf8, withFile )
+import System.IO.Unsafe ( unsafePerformIO )
+import qualified System.FilePath.Posix as HtmlPath
+
+#ifndef mingw32_HOST_OS
+import qualified System.Posix.Internals
+#endif
+
+--------------------------------------------------------------------------------
+-- * Logging
+--------------------------------------------------------------------------------
+
+data Verbosity = Silent | Normal | Verbose | Deafening
+  deriving (Eq, Ord, Enum, Bounded, Show)
+
+silent, normal, verbose, deafening :: Verbosity
+silent    = Silent
+normal    = Normal
+verbose   = Verbose
+deafening = Deafening
+
+-- | Parse out a verbosity level. Inspired from Cabal's verbosity parsing.
+parseVerbosity :: String -> Either String Verbosity
+parseVerbosity "0" = Right Silent
+parseVerbosity "1" = Right Normal
+parseVerbosity "2" = Right Silent
+parseVerbosity "3" = Right Deafening
+parseVerbosity "silent"    = return Silent
+parseVerbosity "normal"    = return Normal
+parseVerbosity "verbose"   = return Verbose
+parseVerbosity "debug"     = return Deafening
+parseVerbosity "deafening" = return Deafening
+parseVerbosity other = Left ("Can't parse verbosity " ++ other)
+
+-- | Print a message to stdout, if it is not too verbose
+out :: MonadIO m
+    => Verbosity -- ^ program verbosity
+    -> Verbosity -- ^ message verbosity
+    -> String -> m ()
+out progVerbosity msgVerbosity msg
+  | msgVerbosity <= progVerbosity = liftIO $ putStrLn msg
+  | otherwise = return ()
+
+
+--------------------------------------------------------------------------------
+-- * Some Utilities
+--------------------------------------------------------------------------------
+
+
+
+mkMeta :: Doc a -> MDoc a
+mkMeta x = emptyMetaDoc { _doc = x }
+
+--------------------------------------------------------------------------------
+-- * Filename mangling functions stolen from s main/DriverUtil.lhs.
+--------------------------------------------------------------------------------
+
+baseName :: ModuleName -> FilePath
+baseName = map (\c -> if c == '.' then '-' else c) . moduleNameString
+
+
+moduleHtmlFile :: Module -> FilePath
+moduleHtmlFile mdl =
+  case Map.lookup mdl html_xrefs of
+    Nothing  -> baseName mdl' ++ ".html"
+    Just fp0 -> HtmlPath.joinPath [fp0, baseName mdl' ++ ".html"]
+  where
+   mdl' = moduleName mdl
+
+
+moduleHtmlFile' :: ModuleName -> FilePath
+moduleHtmlFile' mdl =
+  case Map.lookup mdl html_xrefs' of
+    Nothing  -> baseName mdl ++ ".html"
+    Just fp0 -> HtmlPath.joinPath [fp0, baseName mdl ++ ".html"]
+
+
+contentsHtmlFile, indexHtmlFile, indexJsonFile :: String
+contentsHtmlFile = "index.html"
+indexHtmlFile = "doc-index.html"
+indexJsonFile = "doc-index.json"
+
+
+subIndexHtmlFile :: String -> String
+subIndexHtmlFile ls = "doc-index-" ++ b ++ ".html"
+   where b | all isAlpha ls = ls
+           | otherwise = concatMap (show . ord) ls
+
+
+-------------------------------------------------------------------------------
+-- * Anchor and URL utilities
+--
+-- NB: Anchor IDs, used as the destination of a link within a document must
+-- conform to XML's NAME production. That, taken with XHTML and HTML 4.01's
+-- various needs and compatibility constraints, means these IDs have to match:
+--      [A-Za-z][A-Za-z0-9:_.-]*
+-- Such IDs do not need to be escaped in any way when used as the fragment part
+-- of a URL. Indeed, %-escaping them can lead to compatibility issues as it
+-- isn't clear if such fragment identifiers should, or should not be unescaped
+-- before being matched with IDs in the target document.
+-------------------------------------------------------------------------------
+
+
+moduleUrl :: Module -> String
+moduleUrl = moduleHtmlFile
+
+
+moduleNameUrl :: Module -> OccName -> String
+moduleNameUrl mdl n = moduleUrl mdl ++ '#' : nameAnchorId n
+
+
+moduleNameUrl' :: ModuleName -> OccName -> String
+moduleNameUrl' mdl n = moduleHtmlFile' mdl ++ '#' : nameAnchorId n
+
+
+nameAnchorId :: OccName -> String
+nameAnchorId name = makeAnchorId (prefix : ':' : occNameString name)
+ where prefix | isValOcc name = 'v'
+              | otherwise     = 't'
+
+
+-- | Takes an arbitrary string and makes it a valid anchor ID. The mapping is
+-- identity preserving.
+makeAnchorId :: String -> String
+makeAnchorId [] = []
+makeAnchorId (f:r) = escape isAlpha f ++ concatMap (escape isLegal) r
+  where
+    escape p c | p c = [c]
+               | otherwise = '-' : show (ord c) ++ "-"
+    isLegal ':' = True
+    isLegal '_' = True
+    isLegal '.' = True
+    isLegal c = isAscii c && isAlphaNum c
+       -- NB: '-' is legal in IDs, but we use it as the escape char
+
+
+-------------------------------------------------------------------------------
+-- * Files we need to copy from our $libdir
+-------------------------------------------------------------------------------
+
+
+haddockJsFile :: String
+haddockJsFile = "haddock-bundle.min.js"
+
+jsQuickJumpFile :: String
+jsQuickJumpFile = "quick-jump.min.js"
+
+quickJumpCssFile :: String
+quickJumpCssFile = "quick-jump.css"
+
+-------------------------------------------------------------------------------
+-- * Misc.
+-------------------------------------------------------------------------------
+
+
+getProgramName :: IO String
+getProgramName = fmap (`withoutSuffix` ".bin") getProgName
+   where str `withoutSuffix` suff
+            | suff `isSuffixOf` str = take (length str - length suff) str
+            | otherwise             = str
+
+
+bye :: String -> IO a
+bye s = putStr s >> exitSuccess
+
+escapeStr :: String -> String
+escapeStr = escapeURIString isUnreserved
+
+
+-- Following few functions are copy'n'pasted from Network.URI module
+-- to avoid depending on the network lib, since doing so gives a
+-- circular build dependency between haddock and network
+-- (at least if you want to build network with haddock docs)
+escapeURIChar :: (Char -> Bool) -> Char -> String
+escapeURIChar p c
+    | p c       = [c]
+    | otherwise = '%' : myShowHex (ord c) ""
+    where
+        myShowHex :: Int -> ShowS
+        myShowHex n r =  case showIntAtBase 16 toChrHex n r of
+            []  -> "00"
+            [a] -> ['0',a]
+            cs  -> cs
+        toChrHex d
+            | d < 10    = chr (ord '0' + fromIntegral d)
+            | otherwise = chr (ord 'A' + fromIntegral (d - 10))
+
+
+escapeURIString :: (Char -> Bool) -> String -> String
+escapeURIString = concatMap . escapeURIChar
+
+
+isUnreserved :: Char -> Bool
+isUnreserved c = isAlphaNumChar c || (c `elem` "-_.~")
+
+
+isAlphaChar, isDigitChar, isAlphaNumChar :: Char -> Bool
+isAlphaChar c    = (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')
+isDigitChar c    = c >= '0' && c <= '9'
+isAlphaNumChar c = isAlphaChar c || isDigitChar c
+
+-- | Utility to write output to UTF-8 encoded files.
+--
+-- The problem with 'writeFile' is that it picks up its 'TextEncoding' from
+-- 'getLocaleEncoding', and on some platforms (like Windows) this default
+-- encoding isn't enough for the characters we want to write.
+writeUtf8File :: FilePath -> String -> IO ()
+writeUtf8File filepath contents = withFile filepath WriteMode $ \h -> do
+    hSetEncoding h utf8
+    hPutStr h contents
+
+withTempDir :: (MonadIO m, MonadMask m) => FilePath -> m a -> m a
+withTempDir dir = bracket_ (liftIO $ createDirectory dir)
+                           (liftIO $ removeDirectoryRecursive dir)
+
+-----------------------------------------------------------------------------
+-- * HTML cross references
+--
+-- For each module, we need to know where its HTML documentation lives
+-- so that we can point hyperlinks to it.  It is extremely
+-- inconvenient to plumb this information to all the places that need
+-- it (basically every function in HaddockHtml), and furthermore the
+-- mapping is constant for any single run of Haddock.  So for the time
+-- being I'm going to use a write-once global variable.
+-----------------------------------------------------------------------------
+
+
+{-# NOINLINE html_xrefs_ref #-}
+html_xrefs_ref :: IORef (Map Module FilePath)
+html_xrefs_ref = unsafePerformIO (newIORef (error "module_map"))
+
+
+{-# NOINLINE html_xrefs_ref' #-}
+html_xrefs_ref' :: IORef (Map ModuleName FilePath)
+html_xrefs_ref' = unsafePerformIO (newIORef (error "module_map"))
+
+
+{-# NOINLINE html_xrefs #-}
+html_xrefs :: Map Module FilePath
+html_xrefs = unsafePerformIO (readIORef html_xrefs_ref)
+
+
+{-# NOINLINE html_xrefs' #-}
+html_xrefs' :: Map ModuleName FilePath
+html_xrefs' = unsafePerformIO (readIORef html_xrefs_ref')
+
+
+-----------------------------------------------------------------------------
+-- * List utils
+-----------------------------------------------------------------------------
+
+
+replace :: Eq a => a -> a -> [a] -> [a]
+replace a b = map (\x -> if x == a then b else x)
+
+
+spanWith :: (a -> Maybe b) -> [a] -> ([b],[a])
+spanWith _ [] = ([],[])
+spanWith p xs@(a:as)
+  | Just b <- p a = let (bs,cs) = spanWith p as in (b:bs,cs)
+  | otherwise     = ([],xs)
+
+-----------------------------------------------------------------------------
+-- * System tools
+-----------------------------------------------------------------------------
+
+
+#ifdef mingw32_HOST_OS
+foreign import ccall unsafe "_getpid" getProcessID :: IO Int -- relies on Int == Int32 on Windows
+#else
+getProcessID :: IO Int
+getProcessID = fmap fromIntegral System.Posix.Internals.c_getpid
+#endif
diff --git a/haddock-api/src/Haddock/Utils/Json.hs b/haddock-api/src/Haddock/Utils/Json.hs
new file mode 100644
--- /dev/null
+++ b/haddock-api/src/Haddock/Utils/Json.hs
@@ -0,0 +1,558 @@
+{-# LANGUAGE OverloadedStrings #-}
+{-# LANGUAGE RankNTypes        #-}
+
+-- | Minimal JSON / RFC 7159 support
+--
+-- The API is heavily inspired by @aeson@'s API but puts emphasis on
+-- simplicity rather than performance. The 'ToJSON' instances are
+-- intended to have an encoding compatible with @aeson@'s encoding.
+--
+module Haddock.Utils.Json
+    ( Value(..)
+    , Object, object, Pair, (.=)
+    , encodeToString
+    , encodeToBuilder
+    , ToJSON(toJSON)
+
+    , Parser(..)
+    , Result(..)
+    , FromJSON(parseJSON)
+    , withObject
+    , withArray
+    , withString
+    , withDouble
+    , withBool
+    , fromJSON
+    , parse
+    , parseEither
+    , (.:)
+    , (.:?)
+    , decode
+    , decodeWith
+    , eitherDecode
+    , eitherDecodeWith
+    , decodeFile
+    , eitherDecodeFile
+    )
+    where
+
+import Control.Applicative (Alternative (..))
+import Control.Monad (MonadPlus (..), zipWithM, (>=>))
+import qualified Control.Monad as Monad
+import qualified Control.Monad.Fail as Fail
+
+import qualified Data.ByteString.Lazy as BSL
+import Data.ByteString.Builder (Builder)
+import qualified Data.ByteString.Builder as BB
+import Data.Char
+import Data.Int
+import Data.Word
+import Data.List (intersperse)
+import Data.Monoid
+
+import GHC.Natural
+
+-- TODO: We may want to replace 'String' with 'Text' or 'ByteString'
+
+import qualified Text.Parsec.ByteString.Lazy as Parsec.Lazy
+import qualified Text.ParserCombinators.Parsec as Parsec
+
+import Haddock.Utils.Json.Types
+import Haddock.Utils.Json.Parser
+
+
+infixr 8 .=
+
+-- | A key-value pair for encoding a JSON object.
+(.=) :: ToJSON v => String -> v -> Pair
+k .= v  = (k, toJSON v)
+
+
+-- | A type that can be converted to JSON.
+class ToJSON a where
+  -- | Convert a Haskell value to a JSON-friendly intermediate type.
+  toJSON :: a -> Value
+
+instance ToJSON () where
+  toJSON () = Array []
+
+instance ToJSON Value where
+  toJSON = id
+
+instance ToJSON Bool where
+  toJSON = Bool
+
+instance ToJSON a => ToJSON [a] where
+  toJSON = Array . map toJSON
+
+instance ToJSON a => ToJSON (Maybe a) where
+  toJSON Nothing  = Null
+  toJSON (Just a) = toJSON a
+
+instance (ToJSON a,ToJSON b) => ToJSON (a,b) where
+  toJSON (a,b) = Array [toJSON a, toJSON b]
+
+instance (ToJSON a,ToJSON b,ToJSON c) => ToJSON (a,b,c) where
+  toJSON (a,b,c) = Array [toJSON a, toJSON b, toJSON c]
+
+instance (ToJSON a,ToJSON b,ToJSON c, ToJSON d) => ToJSON (a,b,c,d) where
+  toJSON (a,b,c,d) = Array [toJSON a, toJSON b, toJSON c, toJSON d]
+
+instance ToJSON Float where
+  toJSON = Number . realToFrac
+
+instance ToJSON Double where
+  toJSON = Number
+
+instance ToJSON Int    where  toJSON = Number . realToFrac
+instance ToJSON Int8   where  toJSON = Number . realToFrac
+instance ToJSON Int16  where  toJSON = Number . realToFrac
+instance ToJSON Int32  where  toJSON = Number . realToFrac
+
+instance ToJSON Word   where  toJSON = Number . realToFrac
+instance ToJSON Word8  where  toJSON = Number . realToFrac
+instance ToJSON Word16 where  toJSON = Number . realToFrac
+instance ToJSON Word32 where  toJSON = Number . realToFrac
+
+-- | Possibly lossy due to conversion to 'Double'
+instance ToJSON Int64  where  toJSON = Number . realToFrac
+
+-- | Possibly lossy due to conversion to 'Double'
+instance ToJSON Word64 where  toJSON = Number . realToFrac
+
+-- | Possibly lossy due to conversion to 'Double'
+instance ToJSON Integer where toJSON = Number . fromInteger
+
+------------------------------------------------------------------------------
+-- 'BB.Builder'-based encoding
+
+-- | Serialise value as JSON/UTF8-encoded 'Builder'
+encodeToBuilder :: ToJSON a => a -> Builder
+encodeToBuilder = encodeValueBB . toJSON
+
+encodeValueBB :: Value -> Builder
+encodeValueBB jv = case jv of
+  Bool True  -> "true"
+  Bool False -> "false"
+  Null       -> "null"
+  Number n
+    | isNaN n || isInfinite n   -> encodeValueBB Null
+    | Just i <- doubleToInt64 n -> BB.int64Dec i
+    | otherwise                 -> BB.doubleDec n
+  Array a  -> encodeArrayBB a
+  String s -> encodeStringBB s
+  Object o -> encodeObjectBB o
+
+encodeArrayBB :: [Value] -> Builder
+encodeArrayBB [] = "[]"
+encodeArrayBB jvs = BB.char8 '[' <> go jvs <> BB.char8 ']'
+  where
+    go = Data.Monoid.mconcat . intersperse (BB.char8 ',') . map encodeValueBB
+
+encodeObjectBB :: Object -> Builder
+encodeObjectBB [] = "{}"
+encodeObjectBB jvs = BB.char8 '{' <> go jvs <> BB.char8 '}'
+  where
+    go = Data.Monoid.mconcat . intersperse (BB.char8 ',') . map encPair
+    encPair (l,x) = encodeStringBB l <> BB.char8 ':' <> encodeValueBB x
+
+encodeStringBB :: String -> Builder
+encodeStringBB str = BB.char8 '"' <> go str <> BB.char8 '"'
+  where
+    go = BB.stringUtf8 . escapeString
+
+------------------------------------------------------------------------------
+-- 'String'-based encoding
+
+-- | Serialise value as JSON-encoded Unicode 'String'
+encodeToString :: ToJSON a => a -> String
+encodeToString jv = encodeValue (toJSON jv) []
+
+encodeValue :: Value -> ShowS
+encodeValue jv = case jv of
+  Bool b   -> showString (if b then "true" else "false")
+  Null     -> showString "null"
+  Number n
+    | isNaN n || isInfinite n    -> encodeValue Null
+    | Just i <- doubleToInt64 n -> shows i
+    | otherwise                 -> shows n
+  Array a -> encodeArray a
+  String s -> encodeString s
+  Object o -> encodeObject o
+
+encodeArray :: [Value] -> ShowS
+encodeArray [] = showString "[]"
+encodeArray jvs = ('[':) . go jvs . (']':)
+  where
+    go []     = id
+    go [x]    = encodeValue x
+    go (x:xs) = encodeValue x . (',':) . go xs
+
+encodeObject :: Object -> ShowS
+encodeObject [] = showString "{}"
+encodeObject jvs = ('{':) . go jvs . ('}':)
+  where
+    go []          = id
+    go [(l,x)]     = encodeString l . (':':) . encodeValue x
+    go ((l,x):lxs) = encodeString l . (':':) . encodeValue x . (',':) . go lxs
+
+encodeString :: String -> ShowS
+encodeString str = ('"':) . showString (escapeString str) . ('"':)
+
+------------------------------------------------------------------------------
+-- helpers
+
+-- | Try to convert 'Double' into 'Int64', return 'Nothing' if not
+-- representable loss-free as integral 'Int64' value.
+doubleToInt64 :: Double -> Maybe Int64
+doubleToInt64 x
+  | fromInteger x' == x
+  , x' <= toInteger (maxBound :: Int64)
+  , x' >= toInteger (minBound :: Int64)
+    = Just (fromIntegral x')
+  | otherwise = Nothing
+  where
+    x' = round x
+
+-- | Minimally escape a 'String' in accordance with RFC 7159, "7. Strings"
+escapeString :: String -> String
+escapeString s
+  | not (any needsEscape s) = s
+  | otherwise               = escape s
+  where
+    escape [] = []
+    escape (x:xs) = case x of
+      '\\' -> '\\':'\\':escape xs
+      '"'  -> '\\':'"':escape xs
+      '\b' -> '\\':'b':escape xs
+      '\f' -> '\\':'f':escape xs
+      '\n' -> '\\':'n':escape xs
+      '\r' -> '\\':'r':escape xs
+      '\t' -> '\\':'t':escape xs
+      c | ord c < 0x10 -> '\\':'u':'0':'0':'0':intToDigit (ord c):escape xs
+        | ord c < 0x20 -> '\\':'u':'0':'0':'1':intToDigit (ord c - 0x10):escape xs
+        | otherwise    -> c : escape xs
+
+    -- unescaped = %x20-21 / %x23-5B / %x5D-10FFFF
+    needsEscape c = ord c < 0x20 || c `elem` ['\\','"']
+
+------------------------------------------------------------------------------
+-- FromJSON
+
+-- | Elements of a JSON path used to describe the location of an
+-- error.
+data JSONPathElement
+  = Key String
+  -- ^ JSON path element of a key into an object,
+  -- \"object.key\".
+  | Index !Int
+  -- ^ JSON path element of an index into an
+  -- array, \"array[index]\".
+  deriving (Eq, Show, Ord)
+
+type JSONPath = [JSONPathElement]
+
+-- | Failure continuation.
+type Failure f r   = JSONPath -> String -> f r
+
+-- | Success continuation.
+type Success a f r = a -> f r
+
+newtype Parser a = Parser {
+      runParser :: forall f r.
+                   JSONPath
+                -> Failure f r
+                -> Success a f r
+                -> f r
+    }
+
+modifyFailure :: (String -> String) -> Parser a -> Parser a
+modifyFailure f (Parser p) = Parser $ \path kf ks ->
+    p path (\p' m -> kf p' (f m)) ks
+
+prependFailure :: String -> Parser a -> Parser a
+prependFailure = modifyFailure . (++)
+
+prependContext :: String -> Parser a -> Parser a
+prependContext name = prependFailure ("parsing " ++ name ++ " failed, ")
+
+typeMismatch :: String -> Value -> Parser a
+typeMismatch expected actual =
+    fail $ "expected " ++ expected ++ ", but encountered " ++ typeOf actual
+
+instance Monad.Monad Parser where
+    m >>= g = Parser $ \path kf ks ->
+      runParser m path kf
+                       (\a -> runParser (g a) path kf ks)
+    return = pure
+
+instance Fail.MonadFail Parser where
+    fail msg = Parser $ \path kf _ks -> kf (reverse path) msg
+
+instance Functor Parser where
+    fmap f m = Parser $ \path kf ks ->
+      let ks' a = ks (f a)
+      in runParser m path kf ks'
+
+instance Applicative Parser where
+    pure a = Parser $ \_path _kf ks -> ks a
+    (<*>) = apP
+
+instance Alternative Parser where
+    empty = fail "empty"
+    (<|>) = mplus
+
+instance MonadPlus Parser where
+    mzero = fail "mzero"
+    mplus a b = Parser $ \path kf ks ->
+      runParser a path (\_ _ -> runParser b path kf ks) ks
+
+instance Semigroup (Parser a) where
+    (<>) = mplus
+
+instance Monoid (Parser a) where
+    mempty  = fail "mempty"
+    mappend = (<>)
+
+apP :: Parser (a -> b) -> Parser a -> Parser b
+apP d e = do
+  b <- d
+  b <$> e
+
+(<?>) :: Parser a -> JSONPathElement -> Parser a
+p <?> pathElem = Parser $ \path kf ks -> runParser p (pathElem:path) kf ks
+
+parseIndexedJSON :: (Value -> Parser a) -> Int -> Value -> Parser a
+parseIndexedJSON p idx value = p value <?> Index idx
+
+unexpected :: Value -> Parser a
+unexpected actual = fail $ "unexpected " ++ typeOf actual
+
+withObject :: String -> (Object -> Parser a) -> Value -> Parser a
+withObject _    f (Object obj) = f obj
+withObject name _ v            = prependContext name (typeMismatch "Object" v)
+
+withArray :: String -> ([Value] -> Parser a) -> Value -> Parser a
+withArray _    f (Array arr) = f arr
+withArray name _ v           = prependContext name (typeMismatch "Array" v)
+
+withString :: String -> (String -> Parser a) -> Value -> Parser a
+withString _    f (String txt) = f txt
+withString name _ v            = prependContext name (typeMismatch "String" v)
+
+withDouble :: String -> (Double -> Parser a) -> Value -> Parser a
+withDouble _    f (Number duble) = f duble
+withDouble name _ v              = prependContext name (typeMismatch "Number" v)
+
+withBool :: String -> (Bool -> Parser a) -> Value -> Parser a
+withBool _    f (Bool arr) = f arr
+withBool name _ v          = prependContext name (typeMismatch "Boolean" v)
+
+class FromJSON a where
+    parseJSON     :: Value -> Parser a
+
+    parseJSONList :: Value -> Parser [a]
+    parseJSONList = withArray "[]" (zipWithM (parseIndexedJSON parseJSON) [0..])
+
+instance FromJSON Bool where
+    parseJSON (Bool b)  = pure b
+    parseJSON v = typeMismatch "Bool" v
+
+instance FromJSON () where
+    parseJSON =
+      withArray "()" $ \v ->
+        if null v
+          then pure ()
+          else prependContext "()" $ fail "expected an empty array"
+
+instance FromJSON Char where
+    parseJSON = withString "Char" parseChar
+
+    parseJSONList (String s) = pure s
+    parseJSONList v = typeMismatch "String" v
+
+parseChar :: String -> Parser Char
+parseChar t =
+    if length t == 1
+      then pure $ head t
+      else prependContext "Char" $ fail "expected a string of length 1"
+
+parseRealFloat :: RealFloat a => String -> Value -> Parser a
+parseRealFloat _    (Number s) = pure $ realToFrac s
+parseRealFloat _    Null       = pure (0/0)
+parseRealFloat name v          = prependContext name (unexpected v)
+
+instance FromJSON Double where
+    parseJSON = parseRealFloat "Double"
+
+instance FromJSON Float where
+    parseJSON = parseRealFloat "Float"
+
+parseNatural :: Integer -> Parser Natural
+parseNatural integer =
+    if integer < 0 then
+        fail $ "parsing Natural failed, unexpected negative number " <> show integer
+    else
+        pure $ fromIntegral integer
+
+parseIntegralFromDouble :: Integral a => Double -> Parser a
+parseIntegralFromDouble d =
+    let r = toRational d
+        x = truncate r
+    in if toRational x == r
+         then pure x
+         else fail $ "unexpected floating number " <> show d
+
+parseIntegral :: Integral a => String -> Value -> Parser a
+parseIntegral name = withDouble name parseIntegralFromDouble
+
+instance FromJSON Integer where
+    parseJSON = parseIntegral "Integer"
+
+instance FromJSON Natural where
+    parseJSON = withDouble "Natural"
+                  (parseIntegralFromDouble >=> parseNatural)
+
+instance FromJSON Int where
+    parseJSON = parseIntegral "Int"
+
+instance FromJSON Int8 where
+    parseJSON = parseIntegral "Int8"
+
+instance FromJSON Int16 where
+    parseJSON = parseIntegral "Int16"
+
+instance FromJSON Int32 where
+    parseJSON = parseIntegral "Int32"
+
+instance FromJSON Int64 where
+    parseJSON = parseIntegral "Int64"
+
+instance FromJSON Word where
+    parseJSON = parseIntegral "Word"
+
+instance FromJSON Word8 where
+    parseJSON = parseIntegral "Word8"
+
+instance FromJSON Word16 where
+    parseJSON = parseIntegral "Word16"
+
+instance FromJSON Word32 where
+    parseJSON = parseIntegral "Word32"
+
+instance FromJSON Word64 where
+    parseJSON = parseIntegral "Word64"
+
+instance FromJSON a => FromJSON [a] where
+    parseJSON = parseJSONList
+
+data Result a = Error String
+              | Success a
+                deriving (Eq, Show)
+
+fromJSON :: FromJSON a => Value -> Result a
+fromJSON = parse parseJSON
+
+parse :: (a -> Parser b) -> a -> Result b
+parse m v = runParser (m v) [] (const Error) Success
+
+parseEither :: (a -> Parser b) -> a -> Either String b
+parseEither m v = runParser (m v) [] onError Right
+  where onError path msg = Left (formatError path msg)
+
+formatError :: JSONPath -> String -> String
+formatError path msg = "Error in " ++ formatPath path ++ ": " ++ msg
+
+formatPath :: JSONPath -> String
+formatPath path = "$" ++ formatRelativePath path
+
+formatRelativePath :: JSONPath -> String
+formatRelativePath path = format "" path
+  where
+    format :: String -> JSONPath -> String
+    format pfx []                = pfx
+    format pfx (Index idx:parts) = format (pfx ++ "[" ++ show idx ++ "]") parts
+    format pfx (Key key:parts)   = format (pfx ++ formatKey key) parts
+
+    formatKey :: String -> String
+    formatKey key
+       | isIdentifierKey key = "." ++ key
+       | otherwise           = "['" ++ escapeKey key ++ "']"
+
+    isIdentifierKey :: String -> Bool
+    isIdentifierKey []     = False
+    isIdentifierKey (x:xs) = isAlpha x && all isAlphaNum xs
+
+    escapeKey :: String -> String
+    escapeKey = concatMap escapeChar
+
+    escapeChar :: Char -> String
+    escapeChar '\'' = "\\'"
+    escapeChar '\\' = "\\\\"
+    escapeChar c    = [c]
+
+explicitParseField :: (Value -> Parser a) -> Object -> String -> Parser a
+explicitParseField p obj key =
+    case key `lookup` obj of
+      Nothing -> fail $ "key " ++ key ++ " not found"
+      Just v  -> p v <?> Key key
+
+(.:) :: FromJSON a => Object -> String -> Parser a
+(.:) = explicitParseField parseJSON
+
+explicitParseFieldMaybe :: (Value -> Parser a) -> Object -> String -> Parser (Maybe a)
+explicitParseFieldMaybe p obj key =
+    case key `lookup` obj of
+      Nothing -> pure Nothing
+      Just v  -> Just <$> p v <?> Key key
+
+(.:?) :: FromJSON a => Object -> String -> Parser (Maybe a)
+(.:?) = explicitParseFieldMaybe parseJSON
+
+
+decodeWith :: (Value -> Result a) -> BSL.ByteString -> Maybe a
+decodeWith decoder bsl =
+   case Parsec.parse parseJSONValue "<input>" bsl of
+     Left  _    -> Nothing
+     Right json ->
+       case decoder json of
+         Success a -> Just a
+         Error _   -> Nothing
+
+decode :: FromJSON a => BSL.ByteString -> Maybe a
+decode = decodeWith fromJSON
+
+eitherDecodeWith :: (Value -> Result a) -> BSL.ByteString -> Either String a
+eitherDecodeWith decoder bsl =
+    case Parsec.parse parseJSONValue "<input>" bsl of
+      Left parsecError -> Left (show parsecError)
+      Right json ->
+        case decoder json of
+          Success a -> Right a
+          Error err -> Left  err
+
+eitherDecode :: FromJSON a => BSL.ByteString -> Either String a
+eitherDecode = eitherDecodeWith fromJSON
+
+
+decodeFile :: FromJSON a => FilePath -> IO (Maybe a)
+decodeFile filePath = do
+    parsecResult <- Parsec.Lazy.parseFromFile parseJSONValue filePath
+    case parsecResult of
+      Right r ->
+        case fromJSON r of
+          Success a -> return (Just a)
+          Error   _ -> return Nothing
+      Left _ -> return Nothing
+
+
+eitherDecodeFile :: FromJSON a => FilePath -> IO (Either String a)
+eitherDecodeFile filePath = do
+    parsecResult <- Parsec.Lazy.parseFromFile parseJSONValue filePath
+    case parsecResult of
+      Right r ->
+        case fromJSON r of
+          Success a -> return (Right a)
+          Error err -> return (Left err)
+      Left err -> return $ Left (show err)
+
diff --git a/haddock-api/src/Haddock/Utils/Json/Parser.hs b/haddock-api/src/Haddock/Utils/Json/Parser.hs
new file mode 100644
--- /dev/null
+++ b/haddock-api/src/Haddock/Utils/Json/Parser.hs
@@ -0,0 +1,102 @@
+-- | Json "Parsec" parser, based on
+-- [json](https://hackage.haskell.org/package/json) package.
+--
+module Haddock.Utils.Json.Parser
+  ( parseJSONValue
+  ) where
+
+import Prelude hiding (null)
+
+import Control.Applicative (Alternative (..))
+import Control.Monad (MonadPlus (..))
+import Data.Char (isHexDigit)
+import Data.Functor (($>))
+import qualified Data.ByteString.Lazy.Char8 as BSCL
+import Numeric
+import Text.Parsec.ByteString.Lazy (Parser)
+import Text.ParserCombinators.Parsec ((<?>))
+import qualified Text.ParserCombinators.Parsec as Parsec
+
+import Haddock.Utils.Json.Types hiding (object)
+
+parseJSONValue :: Parser Value
+parseJSONValue = Parsec.spaces *> parseValue
+
+tok :: Parser a -> Parser a
+tok p = p <* Parsec.spaces
+
+parseValue :: Parser Value
+parseValue =
+         parseNull
+     <|> Bool   <$> parseBoolean
+     <|> Array  <$> parseArray
+     <|> String <$> parseString
+     <|> Object <$> parseObject
+     <|> Number <$> parseNumber
+     <?> "JSON value"
+
+parseNull :: Parser Value
+parseNull = tok
+     $  Parsec.string "null"
+     $> Null
+
+parseBoolean :: Parser Bool
+parseBoolean = tok
+     $  Parsec.string "true"  $> True
+    <|> Parsec.string "false" $> False
+
+parseArray :: Parser [Value]
+parseArray =
+    Parsec.between
+      (tok (Parsec.char '['))
+      (tok (Parsec.char ']'))
+      (parseValue `Parsec.sepBy` tok (Parsec.char ','))
+
+parseString :: Parser String
+parseString =
+    Parsec.between
+      (tok (Parsec.char '"'))
+      (tok (Parsec.char '"'))
+      (many char)
+  where
+    char = (Parsec.char '\\' >> escapedChar)
+       <|> Parsec.satisfy (\x -> x /= '"' && x /= '\\')
+
+    escapedChar =
+          Parsec.char '"'  $> '"'
+      <|> Parsec.char '\\' $> '\\'
+      <|> Parsec.char '/'  $> '/'
+      <|> Parsec.char 'b'  $> '\b'
+      <|> Parsec.char 'f'  $> '\f'
+      <|> Parsec.char 'n'  $> '\n'
+      <|> Parsec.char 'r'  $> '\r'
+      <|> Parsec.char 't'  $> '\t'
+      <|> Parsec.char 'u'  *> uni
+      <?> "escape character"
+
+    uni = check =<< Parsec.count 4 (Parsec.satisfy isHexDigit)
+      where
+        check x | code <= max_char = return (toEnum code)
+                | otherwise        = mzero
+          where code      = fst $ head $ readHex x
+                max_char  = fromEnum (maxBound :: Char)
+
+parseObject :: Parser Object
+parseObject =
+      Parsec.between
+        (tok (Parsec.char '{'))
+        (tok (Parsec.char '}'))
+        (field `Parsec.sepBy` tok (Parsec.char ','))
+  where
+    field :: Parser (String, Value)
+    field = (,)
+        <$> parseString
+        <*  tok (Parsec.char ':')
+        <*> parseValue
+
+parseNumber :: Parser Double
+parseNumber = tok $ do
+  s <- BSCL.unpack <$> Parsec.getInput
+  case readSigned readFloat s of
+    [(n,s')] -> Parsec.setInput (BSCL.pack s') $> n
+    _        -> mzero
diff --git a/haddock-api/src/Haddock/Utils/Json/Types.hs b/haddock-api/src/Haddock/Utils/Json/Types.hs
new file mode 100644
--- /dev/null
+++ b/haddock-api/src/Haddock/Utils/Json/Types.hs
@@ -0,0 +1,42 @@
+module Haddock.Utils.Json.Types
+  ( Value(..)
+  , typeOf
+  , Pair
+  , Object
+  , object
+  ) where
+
+import Data.String
+
+-- TODO: We may want to replace 'String' with 'Text' or 'ByteString'
+
+-- | A JSON value represented as a Haskell value.
+data Value = Object !Object
+           | Array  [Value]
+           | String  String
+           | Number !Double
+           | Bool   !Bool
+           | Null
+           deriving (Eq, Read, Show)
+
+typeOf :: Value -> String
+typeOf v = case v of
+    Object _ -> "Object"
+    Array _  -> "Array"
+    String _ -> "String"
+    Number _ -> "Number"
+    Bool _   -> "Boolean"
+    Null     -> "Null"
+
+-- | A key\/value pair for an 'Object'
+type Pair = (String, Value)
+
+-- | A JSON \"object\" (key/value map).
+type Object = [Pair]
+
+-- | Create a 'Value' from a list of name\/value 'Pair's.
+object :: [Pair] -> Value
+object = Object
+
+instance IsString Value where
+  fromString = String
diff --git a/haddock-api/src/Haddock/Version.hs b/haddock-api/src/Haddock/Version.hs
new file mode 100644
--- /dev/null
+++ b/haddock-api/src/Haddock/Version.hs
@@ -0,0 +1,30 @@
+{-# LANGUAGE CPP #-}
+-----------------------------------------------------------------------------
+-- |
+-- Module      :  Haddock.Version
+-- Copyright   :  (c) Simon Marlow 2003
+-- License     :  BSD-like
+--
+-- Maintainer  :  haddock@projects.haskell.org
+-- Stability   :  experimental
+-- Portability :  portable
+-----------------------------------------------------------------------------
+module Haddock.Version (
+  projectName, projectVersion, projectUrl
+) where
+
+#ifdef IN_GHC_TREE
+import Paths_haddock ( version )
+#else
+import Paths_haddock_api ( version )
+#endif
+import Data.Version  ( showVersion )
+
+projectName :: String
+projectName = "Haddock"
+
+projectUrl :: String
+projectUrl  = "http://www.haskell.org/haddock/"
+
+projectVersion :: String
+projectVersion = showVersion version
diff --git a/haddock-api/src/haddock.sh b/haddock-api/src/haddock.sh
new file mode 100644
--- /dev/null
+++ b/haddock-api/src/haddock.sh
@@ -0,0 +1,7 @@
+# Mini-driver for Haddock
+
+# needs the following variables:
+#	HADDOCKLIB
+#	HADDOCKBIN
+
+$HADDOCKBIN --lib $HADDOCKLIB ${1+"$@"}
diff --git a/haddock-library/src/CompatPrelude.hs b/haddock-library/src/CompatPrelude.hs
new file mode 100644
--- /dev/null
+++ b/haddock-library/src/CompatPrelude.hs
@@ -0,0 +1,53 @@
+{-# LANGUAGE CPP #-}
+
+#ifdef __HLINT__
+#elif !MIN_VERSION_base(4,5,0)
+# error This module doesn't provide compat-shims for versions prior to base-4.5
+#endif
+
+-- | Bridge impedance mismatch of different @base@ versions back till @base-4.5@ (GHC 7.4.2)
+module CompatPrelude
+    ( ($>)
+    , isSymbolChar
+    ) where
+
+#if MIN_VERSION_base(4,7,0)
+import           Data.Functor                ( ($>) )
+#else
+import           Data.Functor                ( (<$) )
+#endif
+
+#if MIN_VERSION_base(4,9,0)
+import           Text.Read.Lex                      (isSymbolChar)
+#else
+import           Data.Char (GeneralCategory(..), generalCategory)
+#endif
+
+
+#if !MIN_VERSION_base(4,7,0)
+infixl 4 $>
+
+-- | Flipped version of '<$'.
+--
+-- @since 4.7.0.0
+($>) :: Functor f => f a -> b -> f b
+($>) = flip (<$)
+#endif
+
+#if !MIN_VERSION_base(4,9,0)
+-- inlined from base-4.10.0.0
+isSymbolChar :: Char -> Bool
+isSymbolChar c = not (isPuncChar c) && case generalCategory c of
+    MathSymbol           -> True
+    CurrencySymbol       -> True
+    ModifierSymbol       -> True
+    OtherSymbol          -> True
+    DashPunctuation      -> True
+    OtherPunctuation     -> c `notElem` "'\""
+    ConnectorPunctuation -> c /= '_'
+    _                    -> False
+  where
+    -- | The @special@ character class as defined in the Haskell Report.
+    isPuncChar :: Char -> Bool
+    isPuncChar = (`elem` (",;()[]{}`" :: String))
+#endif
diff --git a/haddock-library/src/Documentation/Haddock/Doc.hs b/haddock-library/src/Documentation/Haddock/Doc.hs
new file mode 100644
--- /dev/null
+++ b/haddock-library/src/Documentation/Haddock/Doc.hs
@@ -0,0 +1,89 @@
+{-# OPTIONS_GHC -fno-warn-orphans #-}
+module Documentation.Haddock.Doc (docParagraph, docAppend,
+                                  docConcat, metaDocConcat,
+                                  metaDocAppend, emptyMetaDoc,
+                                  metaAppend, metaConcat) where
+
+import Control.Applicative ((<|>), empty)
+import Documentation.Haddock.Types
+import Data.Char (isSpace)
+
+docConcat :: [DocH mod id] -> DocH mod id
+docConcat = foldr docAppend DocEmpty
+
+-- | Concat using 'metaAppend'.
+metaConcat :: [Meta] -> Meta
+metaConcat = foldr metaAppend emptyMeta
+
+-- | Like 'docConcat' but also joins the 'Meta' info.
+metaDocConcat :: [MetaDoc mod id] -> MetaDoc mod id
+metaDocConcat = foldr metaDocAppend emptyMetaDoc
+
+-- | We do something perhaps unexpected here and join the meta info
+-- in ‘reverse’: this results in the metadata from the ‘latest’
+-- paragraphs taking precedence.
+metaDocAppend :: MetaDoc mod id -> MetaDoc mod id -> MetaDoc mod id
+metaDocAppend (MetaDoc { _meta = m, _doc = d })
+              (MetaDoc { _meta = m', _doc = d' }) =
+  MetaDoc { _meta = m' `metaAppend` m, _doc = d `docAppend` d' }
+
+-- | This is not a monoidal append, it uses '<|>' for the '_version' and
+-- '_package'.
+metaAppend :: Meta -> Meta -> Meta
+metaAppend (Meta v1 p1) (Meta v2 p2) = Meta (v1 <|> v2) (p1 <|> p2)
+
+emptyMetaDoc :: MetaDoc mod id
+emptyMetaDoc = MetaDoc { _meta = emptyMeta, _doc = DocEmpty }
+
+emptyMeta :: Meta
+emptyMeta = Meta empty empty
+
+docAppend :: DocH mod id -> DocH mod id -> DocH mod id
+docAppend (DocDefList ds1) (DocDefList ds2) = DocDefList (ds1++ds2)
+docAppend (DocDefList ds1) (DocAppend (DocDefList ds2) d) = DocAppend (DocDefList (ds1++ds2)) d
+docAppend (DocOrderedList ds1) (DocOrderedList ds2) = DocOrderedList (ds1 ++ ds2)
+docAppend (DocOrderedList ds1) (DocAppend (DocOrderedList ds2) d) = DocAppend (DocOrderedList (ds1++ds2)) d
+docAppend (DocUnorderedList ds1) (DocUnorderedList ds2) = DocUnorderedList (ds1 ++ ds2)
+docAppend (DocUnorderedList ds1) (DocAppend (DocUnorderedList ds2) d) = DocAppend (DocUnorderedList (ds1++ds2)) d
+docAppend DocEmpty d = d
+docAppend d DocEmpty = d
+docAppend (DocString s1) (DocString s2) = DocString (s1 ++ s2)
+docAppend (DocAppend d (DocString s1)) (DocString s2) = DocAppend d (DocString (s1 ++ s2))
+docAppend (DocString s1) (DocAppend (DocString s2) d) = DocAppend (DocString (s1 ++ s2)) d
+docAppend d1 d2 = DocAppend d1 d2
+
+-- again to make parsing easier - we spot a paragraph whose only item
+-- is a DocMonospaced and make it into a DocCodeBlock
+docParagraph :: DocH mod id -> DocH mod id
+docParagraph (DocMonospaced p)
+  = DocCodeBlock (docCodeBlock p)
+docParagraph (DocAppend (DocString s1) (DocMonospaced p))
+  | all isSpace s1
+  = DocCodeBlock (docCodeBlock p)
+docParagraph (DocAppend (DocString s1)
+    (DocAppend (DocMonospaced p) (DocString s2)))
+  | all isSpace s1 && all isSpace s2
+  = DocCodeBlock (docCodeBlock p)
+docParagraph (DocAppend (DocMonospaced p) (DocString s2))
+  | all isSpace s2
+  = DocCodeBlock (docCodeBlock p)
+docParagraph p
+  = DocParagraph p
+
+
+-- Drop trailing whitespace from @..@ code blocks.  Otherwise this:
+--
+--    -- @
+--    -- foo
+--    -- @
+--
+-- turns into (DocCodeBlock "\nfoo\n ") which when rendered in HTML
+-- gives an extra vertical space after the code block.  The single space
+-- on the final line seems to trigger the extra vertical space.
+--
+docCodeBlock :: DocH mod id -> DocH mod id
+docCodeBlock (DocString s)
+  = DocString (reverse $ dropWhile (`elem` " \t") $ reverse s)
+docCodeBlock (DocAppend l r)
+  = DocAppend l (docCodeBlock r)
+docCodeBlock d = d
diff --git a/haddock-library/src/Documentation/Haddock/Markup.hs b/haddock-library/src/Documentation/Haddock/Markup.hs
new file mode 100644
--- /dev/null
+++ b/haddock-library/src/Documentation/Haddock/Markup.hs
@@ -0,0 +1,99 @@
+-- | @since 1.4.5
+module Documentation.Haddock.Markup (
+    markup
+  , idMarkup
+  , plainMarkup
+  ) where
+
+import Documentation.Haddock.Types
+
+import Data.Maybe ( fromMaybe )
+
+markup :: DocMarkupH mod id a -> DocH mod id -> a
+markup m DocEmpty                       = markupEmpty m
+markup m (DocAppend d1 d2)              = markupAppend m (markup m d1) (markup m d2)
+markup m (DocString s)                  = markupString m s
+markup m (DocParagraph d)               = markupParagraph m (markup m d)
+markup m (DocIdentifier x)              = markupIdentifier m x
+markup m (DocIdentifierUnchecked x)     = markupIdentifierUnchecked m x
+markup m (DocModule (ModLink mo l))     = markupModule m (ModLink mo (fmap (markup m) l))
+markup m (DocWarning d)                 = markupWarning m (markup m d)
+markup m (DocEmphasis d)                = markupEmphasis m (markup m d)
+markup m (DocBold d)                    = markupBold m (markup m d)
+markup m (DocMonospaced d)              = markupMonospaced m (markup m d)
+markup m (DocUnorderedList ds)          = markupUnorderedList m (map (markup m) ds)
+markup m (DocOrderedList ds)            = markupOrderedList m (map (\(index, a) -> (index, markup m a)) ds)
+markup m (DocDefList ds)                = markupDefList m (map (markupPair m) ds)
+markup m (DocCodeBlock d)               = markupCodeBlock m (markup m d)
+markup m (DocHyperlink (Hyperlink u l)) = markupHyperlink m (Hyperlink u (fmap (markup m) l))
+markup m (DocAName ref)                 = markupAName m ref
+markup m (DocPic img)                   = markupPic m img
+markup m (DocMathInline mathjax)        = markupMathInline m mathjax
+markup m (DocMathDisplay mathjax)       = markupMathDisplay m mathjax
+markup m (DocProperty p)                = markupProperty m p
+markup m (DocExamples e)                = markupExample m e
+markup m (DocHeader (Header l t))       = markupHeader m (Header l (markup m t))
+markup m (DocTable (Table h b))         = markupTable m (Table (map (fmap (markup m)) h) (map (fmap (markup m)) b))
+
+markupPair :: DocMarkupH mod id a -> (DocH mod id, DocH mod id) -> (a, a)
+markupPair m (a,b) = (markup m a, markup m b)
+
+-- | The identity markup
+idMarkup :: DocMarkupH mod id (DocH mod id)
+idMarkup = Markup {
+  markupEmpty                = DocEmpty,
+  markupString               = DocString,
+  markupParagraph            = DocParagraph,
+  markupAppend               = DocAppend,
+  markupIdentifier           = DocIdentifier,
+  markupIdentifierUnchecked  = DocIdentifierUnchecked,
+  markupModule               = DocModule,
+  markupWarning              = DocWarning,
+  markupEmphasis             = DocEmphasis,
+  markupBold                 = DocBold,
+  markupMonospaced           = DocMonospaced,
+  markupUnorderedList        = DocUnorderedList,
+  markupOrderedList          = DocOrderedList,
+  markupDefList              = DocDefList,
+  markupCodeBlock            = DocCodeBlock,
+  markupHyperlink            = DocHyperlink,
+  markupAName                = DocAName,
+  markupPic                  = DocPic,
+  markupMathInline           = DocMathInline,
+  markupMathDisplay          = DocMathDisplay,
+  markupProperty             = DocProperty,
+  markupExample              = DocExamples,
+  markupHeader               = DocHeader,
+  markupTable                = DocTable
+  }
+
+-- | Map a 'DocH' into a best estimate of an alternate string. The idea is to
+-- strip away any formatting while preserving as much of the actual text as
+-- possible.
+plainMarkup :: (mod -> String) -> (id -> String) -> DocMarkupH mod id String
+plainMarkup plainMod plainIdent = Markup {
+  markupEmpty                = "",
+  markupString               = id,
+  markupParagraph            = id,
+  markupAppend               = (++),
+  markupIdentifier           = plainIdent,
+  markupIdentifierUnchecked  = plainMod,
+  markupModule               = \(ModLink m lbl) -> fromMaybe m lbl,
+  markupWarning              = id,
+  markupEmphasis             = id,
+  markupBold                 = id,
+  markupMonospaced           = id,
+  markupUnorderedList        = const "",
+  markupOrderedList          = const "",
+  markupDefList              = const "",
+  markupCodeBlock            = id,
+  markupHyperlink            = \(Hyperlink url lbl) -> fromMaybe url lbl,
+  markupAName                = id,
+  markupPic                  = \(Picture uri title) -> fromMaybe uri title,
+  markupMathInline           = id,
+  markupMathDisplay          = id,
+  markupProperty             = id,
+  markupExample              = const "",
+  markupHeader               = \(Header _ title) -> title,
+  markupTable                = const ""
+  }
diff --git a/haddock-library/src/Documentation/Haddock/Parser.hs b/haddock-library/src/Documentation/Haddock/Parser.hs
new file mode 100644
--- /dev/null
+++ b/haddock-library/src/Documentation/Haddock/Parser.hs
@@ -0,0 +1,859 @@
+{-# LANGUAGE OverloadedStrings #-}
+{-# LANGUAGE ViewPatterns      #-}
+-- |
+-- Module      :  Documentation.Haddock.Parser
+-- Copyright   :  (c) Mateusz Kowalczyk 2013-2014,
+--                    Simon Hengel      2013
+-- License     :  BSD-like
+--
+-- Maintainer  :  haddock@projects.haskell.org
+-- Stability   :  experimental
+-- Portability :  portable
+--
+-- Parser used for Haddock comments. For external users of this
+-- library, the most commonly used combination of functions is going
+-- to be
+--
+-- @'toRegular' . '_doc' . 'parseParas'@
+module Documentation.Haddock.Parser (
+  parseString,
+  parseParas,
+  overIdentifier,
+  toRegular,
+  Identifier
+) where
+
+import           Control.Applicative
+import           Control.Arrow (first)
+import           Control.Monad
+import           Data.Char (chr, isUpper, isAlpha, isSpace)
+import           Data.List (intercalate, unfoldr, elemIndex)
+import           Data.Maybe (fromMaybe, mapMaybe)
+import           Data.Monoid
+import qualified Data.Set as Set
+import           Documentation.Haddock.Doc
+import           Documentation.Haddock.Markup ( markup, plainMarkup )
+import           Documentation.Haddock.Parser.Monad
+import           Documentation.Haddock.Parser.Util
+import           Documentation.Haddock.Parser.Identifier
+import           Documentation.Haddock.Types
+import           Prelude hiding (takeWhile)
+import qualified Prelude as P
+
+import qualified Text.Parsec as Parsec
+import           Text.Parsec (try)
+
+import qualified Data.Text as T
+import           Data.Text (Text)
+
+
+-- $setup
+-- >>> :set -XOverloadedStrings
+
+-- | Drops the quotes/backticks around all identifiers, as if they
+-- were valid but still 'String's.
+toRegular :: DocH mod Identifier -> DocH mod String
+toRegular = fmap (\(Identifier _ _ x _) -> x)
+
+-- | Maps over 'DocIdentifier's over 'String' with potentially failing
+-- conversion using user-supplied function. If the conversion fails,
+-- the identifier is deemed to not be valid and is treated as a
+-- regular string.
+overIdentifier :: (Namespace -> String -> Maybe a)
+               -> DocH mod Identifier
+               -> DocH mod a
+overIdentifier f d = g d
+  where
+    g (DocIdentifier (Identifier ns o x e)) = case f ns x of
+      Nothing -> DocString $ renderNs ns ++ [o] ++ x ++ [e]
+      Just x' -> DocIdentifier x'
+    g DocEmpty = DocEmpty
+    g (DocAppend x x') = DocAppend (g x) (g x')
+    g (DocString x) = DocString x
+    g (DocParagraph x) = DocParagraph $ g x
+    g (DocIdentifierUnchecked x) = DocIdentifierUnchecked x
+    g (DocModule (ModLink m x)) = DocModule (ModLink m (fmap g x))
+    g (DocWarning x) = DocWarning $ g x
+    g (DocEmphasis x) = DocEmphasis $ g x
+    g (DocMonospaced x) = DocMonospaced $ g x
+    g (DocBold x) = DocBold $ g x
+    g (DocUnorderedList x) = DocUnorderedList $ fmap g x
+    g (DocOrderedList x) = DocOrderedList $ fmap (\(index, a) -> (index, g a)) x
+    g (DocDefList x) = DocDefList $ fmap (\(y, z) -> (g y, g z)) x
+    g (DocCodeBlock x) = DocCodeBlock $ g x
+    g (DocHyperlink (Hyperlink u x)) = DocHyperlink (Hyperlink u (fmap g x))
+    g (DocPic x) = DocPic x
+    g (DocMathInline x) = DocMathInline x
+    g (DocMathDisplay x) = DocMathDisplay x
+    g (DocAName x) = DocAName x
+    g (DocProperty x) = DocProperty x
+    g (DocExamples x) = DocExamples x
+    g (DocHeader (Header l x)) = DocHeader . Header l $ g x
+    g (DocTable (Table h b)) = DocTable (Table (map (fmap g) h) (map (fmap g) b))
+
+
+choice' :: [Parser a] -> Parser a
+choice' [] = empty
+choice' [p] = p
+choice' (p : ps) = try p <|> choice' ps
+
+parse :: Parser a -> Text -> (ParserState, a)
+parse p = either err id . parseOnly (p <* Parsec.eof)
+  where
+    err = error . ("Haddock.Parser.parse: " ++)
+
+-- | Main entry point to the parser. Appends the newline character
+-- to the input string.
+parseParas :: Maybe Package
+           -> String -- ^ String to parse
+           -> MetaDoc mod Identifier
+parseParas pkg input = case parseParasState input of
+  (state, a) -> MetaDoc { _meta = Meta { _version = parserStateSince state
+                                       , _package = pkg
+                                       }
+                        , _doc = a
+                        }
+
+parseParasState :: String -> (ParserState, DocH mod Identifier)
+parseParasState = parse (emptyLines *> p) . T.pack . (++ "\n") . filter (/= '\r')
+  where
+    p :: Parser (DocH mod Identifier)
+    p = docConcat <$> many (paragraph <* emptyLines)
+
+    emptyLines :: Parser ()
+    emptyLines = void $ many (try (skipHorizontalSpace *> "\n"))
+
+parseParagraphs :: String -> Parser (DocH mod Identifier)
+parseParagraphs input = case parseParasState input of
+  (state, a) -> Parsec.putState state *> pure a
+
+-- | Variant of 'parseText' for 'String' instead of 'Text'
+parseString :: String -> DocH mod Identifier
+parseString = parseText . T.pack
+
+-- | Parse a text paragraph. Actually just a wrapper over 'parseParagraph' which
+-- drops leading whitespace.
+parseText :: Text -> DocH mod Identifier
+parseText = parseParagraph . T.dropWhile isSpace . T.filter (/= '\r')
+
+parseParagraph :: Text -> DocH mod Identifier
+parseParagraph = snd . parse p
+  where
+    p :: Parser (DocH mod Identifier)
+    p = docConcat <$> many (choice' [ monospace
+                                    , anchor
+                                    , identifier
+                                    , moduleName
+                                    , picture
+                                    , mathDisplay
+                                    , mathInline
+                                    , markdownImage
+                                    , markdownLink
+                                    , hyperlink
+                                    , bold
+                                    , emphasis
+                                    , encodedChar
+                                    , string'
+                                    , skipSpecialChar
+                                    ])
+
+-- | Parses and processes
+-- <https://en.wikipedia.org/wiki/Numeric_character_reference Numeric character references>
+--
+-- >>> parseString "&#65;"
+-- DocString "A"
+encodedChar :: Parser (DocH mod a)
+encodedChar = "&#" *> c <* ";"
+  where
+    c = DocString . return . chr <$> num
+    num = hex <|> decimal
+    hex = ("x" <|> "X") *> hexadecimal
+
+-- | List of characters that we use to delimit any special markup.
+-- Once we have checked for any of these and tried to parse the
+-- relevant markup, we can assume they are used as regular text.
+specialChar :: [Char]
+specialChar = "_/<@\"&'`#[ "
+
+-- | Plain, regular parser for text. Called as one of the last parsers
+-- to ensure that we have already given a chance to more meaningful parsers
+-- before capturing their characters.
+string' :: Parser (DocH mod a)
+string' = DocString . unescape . T.unpack <$> takeWhile1_ (`notElem` specialChar)
+  where
+    unescape "" = ""
+    unescape ('\\':x:xs) = x : unescape xs
+    unescape (x:xs) = x : unescape xs
+
+-- | Skips a single special character and treats it as a plain string.
+-- This is done to skip over any special characters belonging to other
+-- elements but which were not deemed meaningful at their positions.
+skipSpecialChar :: Parser (DocH mod a)
+skipSpecialChar = DocString . return <$> Parsec.oneOf specialChar
+
+-- | Emphasis parser.
+--
+-- >>> parseString "/Hello world/"
+-- DocEmphasis (DocString "Hello world")
+emphasis :: Parser (DocH mod Identifier)
+emphasis = DocEmphasis . parseParagraph <$>
+  disallowNewline ("/" *> takeWhile1_ (/= '/') <* "/")
+
+-- | Bold parser.
+--
+-- >>> parseString "__Hello world__"
+-- DocBold (DocString "Hello world")
+bold :: Parser (DocH mod Identifier)
+bold = DocBold . parseParagraph <$> disallowNewline ("__" *> takeUntil "__")
+
+disallowNewline :: Parser Text -> Parser Text
+disallowNewline = mfilter (T.all (/= '\n'))
+
+-- | Like `takeWhile`, but unconditionally take escaped characters.
+takeWhile_ :: (Char -> Bool) -> Parser Text
+takeWhile_ p = scan p_ False
+  where
+    p_ escaped c
+      | escaped = Just False
+      | not $ p c = Nothing
+      | otherwise = Just (c == '\\')
+
+-- | Like 'takeWhile1', but unconditionally take escaped characters.
+takeWhile1_ :: (Char -> Bool) -> Parser Text
+takeWhile1_ = mfilter (not . T.null) . takeWhile_
+
+-- | Text anchors to allow for jumping around the generated documentation.
+--
+-- >>> parseString "#Hello world#"
+-- DocAName "Hello world"
+anchor :: Parser (DocH mod a)
+anchor = DocAName . T.unpack <$>
+         ("#" *> takeWhile1_ (\x -> x /= '#' && not (isSpace x)) <* "#")
+
+-- | Monospaced strings.
+--
+-- >>> parseString "@cruel@"
+-- DocMonospaced (DocString "cruel")
+monospace :: Parser (DocH mod Identifier)
+monospace = DocMonospaced . parseParagraph
+            <$> ("@" *> takeWhile1_ (/= '@') <* "@")
+
+-- | Module names.
+--
+-- Note that we allow '#' and '\' to support anchors (old style anchors are of
+-- the form "SomeModule\#anchor").
+moduleName :: Parser (DocH mod a)
+moduleName = DocModule . flip ModLink Nothing <$> ("\"" *> moduleNameString <* "\"")
+
+-- | A module name, optionally with an anchor
+--
+moduleNameString :: Parser String
+moduleNameString = modid `maybeFollowedBy` anchor_
+  where
+    modid = intercalate "." <$> conid `Parsec.sepBy1` "."
+    anchor_ = (++)
+      <$> (Parsec.string "#" <|> Parsec.string "\\#")
+      <*> many (Parsec.satisfy (\c -> c /= '"' && not (isSpace c)))
+
+    maybeFollowedBy pre suf = (\x -> maybe x (x ++)) <$> pre <*> optional suf
+    conid :: Parser String
+    conid = (:)
+      <$> Parsec.satisfy (\c -> isAlpha c && isUpper c)
+      <*> many conChar
+
+    conChar = Parsec.alphaNum <|> Parsec.char '_'
+
+-- | A labeled link to an indentifier, module or url using markdown
+-- syntax.
+markdownLink :: Parser (DocH mod Identifier)
+markdownLink = do
+  lbl <- markdownLinkText
+  choice' [ markdownModuleName lbl, markdownURL lbl ]
+  where
+    markdownModuleName lbl = do
+      mn <- "(" *> skipHorizontalSpace *>
+            "\"" *> moduleNameString <* "\""
+            <* skipHorizontalSpace <* ")"
+      pure $ DocModule (ModLink mn (Just lbl))
+
+    markdownURL lbl = do
+      target <- markdownLinkTarget
+      pure $ DocHyperlink $ Hyperlink target (Just lbl)
+
+-- | Picture parser, surrounded by \<\< and \>\>. It's possible to specify
+-- a title for the picture.
+--
+-- >>> parseString "<<hello.png>>"
+-- DocPic (Picture {pictureUri = "hello.png", pictureTitle = Nothing})
+-- >>> parseString "<<hello.png world>>"
+-- DocPic (Picture {pictureUri = "hello.png", pictureTitle = Just "world"})
+picture :: Parser (DocH mod a)
+picture = DocPic . makeLabeled Picture
+          <$> disallowNewline ("<<" *> takeUntil ">>")
+
+-- | Inline math parser, surrounded by \\( and \\).
+--
+-- >>> parseString "\\(\\int_{-\\infty}^{\\infty} e^{-x^2/2} = \\sqrt{2\\pi}\\)"
+-- DocMathInline "\\int_{-\\infty}^{\\infty} e^{-x^2/2} = \\sqrt{2\\pi}"
+mathInline :: Parser (DocH mod a)
+mathInline = DocMathInline . T.unpack
+             <$> disallowNewline  ("\\(" *> takeUntil "\\)")
+
+-- | Display math parser, surrounded by \\[ and \\].
+--
+-- >>> parseString "\\[\\int_{-\\infty}^{\\infty} e^{-x^2/2} = \\sqrt{2\\pi}\\]"
+-- DocMathDisplay "\\int_{-\\infty}^{\\infty} e^{-x^2/2} = \\sqrt{2\\pi}"
+mathDisplay :: Parser (DocH mod a)
+mathDisplay = DocMathDisplay . T.unpack
+              <$> ("\\[" *> takeUntil "\\]")
+
+-- | Markdown image parser. As per the commonmark reference recommendation, the
+-- description text for an image converted to its a plain string representation.
+--
+-- >>> parseString "![some /emphasis/ in a description](www.site.com)"
+-- DocPic (Picture "www.site.com" (Just "some emphasis in a description"))
+markdownImage :: Parser (DocH mod Identifier)
+markdownImage = do
+  text <- markup stringMarkup <$> ("!" *> markdownLinkText)
+  url <- markdownLinkTarget
+  pure $ DocPic (Picture url (Just text))
+  where
+    stringMarkup = plainMarkup (const "") renderIdent
+    renderIdent (Identifier ns l c r) = renderNs ns <> [l] <> c <> [r]
+
+-- | Paragraph parser, called by 'parseParas'.
+paragraph :: Parser (DocH mod Identifier)
+paragraph = choice' [ examples
+                    , table
+                    , do indent <- takeIndent
+                         choice' [ since
+                                 , unorderedList indent
+                                 , orderedList indent
+                                 , birdtracks
+                                 , codeblock
+                                 , property
+                                 , header
+                                 , textParagraphThatStartsWithMarkdownLink
+                                 , definitionList indent
+                                 , docParagraph <$> textParagraph
+                                 ]
+                    ]
+
+-- | Provides support for grid tables.
+--
+-- Tables are composed by an optional header and body. The header is composed by
+-- a single row. The body is composed by a non-empty list of rows.
+--
+-- Example table with header:
+--
+-- > +----------+----------+
+-- > | /32bit/  |   64bit  |
+-- > +==========+==========+
+-- > |  0x0000  | @0x0000@ |
+-- > +----------+----------+
+--
+-- Algorithms loosely follows ideas in
+-- http://docutils.sourceforge.net/docutils/parsers/rst/tableparser.py
+--
+table :: Parser (DocH mod Identifier)
+table = do
+    -- first we parse the first row, which determines the width of the table
+    firstRow <- parseFirstRow
+    let len = T.length firstRow
+
+    -- then we parse all consecutive rows starting and ending with + or |,
+    -- of the width `len`.
+    restRows <- many (try (parseRestRows len))
+
+    -- Now we gathered the table block, the next step is to split the block
+    -- into cells.
+    DocTable <$> tableStepTwo len (firstRow : restRows)
+  where
+    parseFirstRow :: Parser Text
+    parseFirstRow = do
+        skipHorizontalSpace
+        cs <- takeWhile (\c -> c == '-' || c == '+')
+
+        -- upper-left and upper-right corners are `+`
+        guard (T.length cs >= 2 &&
+               T.head cs == '+' &&
+               T.last cs == '+')
+
+        -- trailing space
+        skipHorizontalSpace
+        _ <- Parsec.newline
+
+        return cs
+
+    parseRestRows :: Int -> Parser Text
+    parseRestRows l = do
+        skipHorizontalSpace
+        bs <- scan predicate l
+
+        -- Left and right edges are `|` or `+`
+        guard (T.length bs >= 2 &&
+               (T.head bs == '|' || T.head bs == '+') &&
+               (T.last bs == '|' || T.last bs == '+'))
+
+        -- trailing space
+        skipHorizontalSpace
+        _ <- Parsec.newline
+
+        return bs
+      where
+        predicate n c
+            | n <= 0    = Nothing
+            | c == '\n' = Nothing
+            | otherwise = Just (n - 1)
+
+-- Second step searchs for row of '+' and '=' characters, records it's index
+-- and changes to '=' to '-'.
+tableStepTwo
+    :: Int              -- ^ width
+    -> [Text]           -- ^ rows
+    -> Parser (Table (DocH mod Identifier))
+tableStepTwo width = go 0 [] where
+    go _ left [] = tableStepThree width (reverse left) Nothing
+    go n left (r : rs)
+        | T.all (`elem` ['+', '=']) r =
+            tableStepThree width (reverse left ++ r' : rs) (Just n)
+        | otherwise =
+            go (n + 1) (r :  left) rs
+      where
+        r' = T.map (\c -> if c == '=' then '-' else c) r
+
+-- Third step recognises cells in the table area, returning a list of TC, cells.
+tableStepThree
+    :: Int              -- ^ width
+    -> [Text]           -- ^ rows
+    -> Maybe Int        -- ^ index of header separator
+    -> Parser (Table (DocH mod Identifier))
+tableStepThree width rs hdrIndex = do
+    cells <- loop (Set.singleton (0, 0))
+    tableStepFour rs hdrIndex cells
+  where
+    height = length rs
+
+    loop :: Set.Set (Int, Int) -> Parser [TC]
+    loop queue = case Set.minView queue of
+        Nothing -> return []
+        Just ((y, x), queue')
+            | y + 1 >= height || x + 1 >= width -> loop queue'
+            | otherwise -> case scanRight x y of
+                Nothing -> loop queue'
+                Just (x2, y2) -> do
+                    let tc = TC y x y2 x2
+                    fmap (tc :) $ loop $ queue' `Set.union` Set.fromList
+                        [(y, x2), (y2, x), (y2, x2)]
+
+    -- scan right looking for +, then try scan down
+    --
+    -- do we need to record + saw on the way left and down?
+    scanRight :: Int -> Int -> Maybe (Int, Int)
+    scanRight x y = go (x + 1) where
+        bs = rs !! y
+        go x' | x' >= width          = fail "overflow right "
+              | T.index bs x' == '+' = scanDown x y x' <|> go (x' + 1)
+              | T.index bs x' == '-' = go (x' + 1)
+              | otherwise            = fail $ "not a border (right) " ++ show (x,y,x')
+
+    -- scan down looking for +
+    scanDown :: Int -> Int -> Int -> Maybe (Int, Int)
+    scanDown x y x2 = go (y + 1) where
+        go y' | y' >= height                 = fail "overflow down"
+              | T.index (rs !! y') x2 == '+' = scanLeft x y x2 y' <|> go (y' + 1)
+              | T.index (rs !! y') x2 == '|' = go (y' + 1)
+              | otherwise                    = fail $ "not a border (down) " ++ show (x,y,x2,y')
+
+    -- check that at y2 x..x2 characters are '+' or '-'
+    scanLeft :: Int -> Int -> Int -> Int -> Maybe (Int, Int)
+    scanLeft x y x2 y2
+        | all (\x' -> T.index bs x' `elem` ['+', '-']) [x..x2] = scanUp x y x2 y2
+        | otherwise                                            = fail $ "not a border (left) " ++ show (x,y,x2,y2)
+      where
+        bs = rs !! y2
+
+    -- check that at y2 x..x2 characters are '+' or '-'
+    scanUp :: Int -> Int -> Int -> Int -> Maybe (Int, Int)
+    scanUp x y x2 y2
+        | all (\y' -> T.index (rs !! y') x `elem` ['+', '|']) [y..y2] = return (x2, y2)
+        | otherwise                                                   = fail $ "not a border (up) " ++ show (x,y,x2,y2)
+
+-- | table cell: top left bottom right
+data TC = TC !Int !Int !Int !Int
+  deriving Show
+
+tcXS :: TC -> [Int]
+tcXS (TC _ x _ x2) = [x, x2]
+
+tcYS :: TC -> [Int]
+tcYS (TC y _ y2 _) = [y, y2]
+
+-- | Fourth step. Given the locations of cells, forms 'Table' structure.
+tableStepFour :: [Text] -> Maybe Int -> [TC] -> Parser (Table (DocH mod Identifier))
+tableStepFour rs hdrIndex cells =  case hdrIndex of
+    Nothing -> return $ Table [] rowsDoc
+    Just i  -> case elemIndex i yTabStops of
+        Nothing -> return $ Table [] rowsDoc
+        Just i' -> return $ uncurry Table $ splitAt i' rowsDoc
+  where
+    xTabStops = sortNub $ concatMap tcXS cells
+    yTabStops = sortNub $ concatMap tcYS cells
+
+    sortNub :: Ord a => [a] -> [a]
+    sortNub = Set.toList . Set.fromList
+
+    init' :: [a] -> [a]
+    init' []       = []
+    init' [_]      = []
+    init' (x : xs) = x : init' xs
+
+    rowsDoc = (fmap . fmap) parseParagraph rows
+
+    rows = map makeRow (init' yTabStops)
+      where
+        makeRow y = TableRow $ mapMaybe (makeCell y) cells
+        makeCell y (TC y' x y2 x2)
+            | y /= y' = Nothing
+            | otherwise = Just $ TableCell xts yts (extract (x + 1) (y + 1) (x2 - 1) (y2 - 1))
+          where
+            xts = length $ P.takeWhile (< x2) $ dropWhile (< x) xTabStops
+            yts = length $ P.takeWhile (< y2) $ dropWhile (< y) yTabStops
+
+    -- extract cell contents given boundaries
+    extract :: Int -> Int -> Int -> Int -> Text
+    extract x y x2 y2 = T.intercalate "\n"
+        [ T.stripEnd $ T.stripStart $ T.take (x2 - x + 1) $ T.drop x $ rs !! y'
+        | y' <- [y .. y2]
+        ]
+
+-- | Parse \@since annotations.
+since :: Parser (DocH mod a)
+since = ("@since " *> version <* skipHorizontalSpace <* endOfLine) >>= setSince >> return DocEmpty
+  where
+    version = decimal `Parsec.sepBy1` "."
+
+-- | Headers inside the comment denoted with @=@ signs, up to 6 levels
+-- deep.
+--
+-- >>> snd <$> parseOnly header "= Hello"
+-- Right (DocHeader (Header {headerLevel = 1, headerTitle = DocString "Hello"}))
+-- >>> snd <$> parseOnly header "== World"
+-- Right (DocHeader (Header {headerLevel = 2, headerTitle = DocString "World"}))
+header :: Parser (DocH mod Identifier)
+header = do
+  let psers = map (string . flip T.replicate "=") [6, 5 .. 1]
+      pser = Parsec.choice psers
+  depth <- T.length <$> pser
+  line <- parseText <$> (skipHorizontalSpace *> nonEmptyLine)
+  rest <- try paragraph <|> return DocEmpty
+  return $ DocHeader (Header depth line) `docAppend` rest
+
+textParagraph :: Parser (DocH mod Identifier)
+textParagraph = parseText . T.intercalate "\n" <$> some nonEmptyLine
+
+textParagraphThatStartsWithMarkdownLink :: Parser (DocH mod Identifier)
+textParagraphThatStartsWithMarkdownLink = docParagraph <$> (docAppend <$> markdownLink <*> optionalTextParagraph)
+  where
+    optionalTextParagraph :: Parser (DocH mod Identifier)
+    optionalTextParagraph = choice' [ docAppend <$> whitespace <*> textParagraph
+                                    , pure DocEmpty ]
+
+    whitespace :: Parser (DocH mod a)
+    whitespace = DocString <$> (f <$> takeHorizontalSpace <*> optional "\n")
+      where
+        f :: Text -> Maybe Text -> String
+        f xs (fromMaybe "" -> x)
+          | T.null (xs <> x) = ""
+          | otherwise = " "
+
+-- | Parses unordered (bullet) lists.
+unorderedList :: Text -> Parser (DocH mod Identifier)
+unorderedList indent = DocUnorderedList <$> p
+  where
+    p = ("*" <|> "-") *> innerList indent p
+
+-- | Parses ordered lists (numbered or dashed).
+orderedList :: Text -> Parser (DocH mod Identifier)
+orderedList indent = DocOrderedList <$> p
+  where
+    p = do
+      index <- paren <|> dot
+      innerList' indent p index
+    dot = (decimal :: Parser Int) <* "."
+    paren = "(" *> decimal <* ")"
+
+-- | Like 'innerList' but takes the parsed index of the list item
+innerList' :: Text -> Parser [(Int, DocH mod Identifier)]
+           -> Int
+           -> Parser [(Int, DocH mod Identifier)]
+innerList' indent item index = do
+  c <- takeLine
+  (cs, items) <- more indent item
+  let contents = docParagraph . parseText . dropNLs . T.unlines $ c : cs
+  return $ case items of
+    Left p -> [(index, contents `docAppend` p)]
+    Right i -> (index, contents) : i
+
+-- | Generic function collecting any further lines belonging to the
+-- list entry and recursively collecting any further lists in the
+-- same paragraph. Usually used as
+--
+-- > someListFunction = listBeginning *> innerList someListFunction
+innerList :: Text -> Parser [DocH mod Identifier]
+          -> Parser [DocH mod Identifier]
+innerList indent item = do
+  c <- takeLine
+  (cs, items) <- more indent item
+  let contents = docParagraph . parseText . dropNLs . T.unlines $ c : cs
+  return $ case items of
+    Left p -> [contents `docAppend` p]
+    Right i -> contents : i
+
+-- | Parses definition lists.
+definitionList :: Text -> Parser (DocH mod Identifier)
+definitionList indent = DocDefList <$> p
+  where
+    p = do
+      label <- "[" *> (parseParagraph <$> takeWhile1_ (`notElem` ("]\n" :: String))) <* ("]" <* optional ":")
+      c <- takeLine
+      (cs, items) <- more indent p
+      let contents = parseText . dropNLs . T.unlines $ c : cs
+      return $ case items of
+        Left x -> [(label, contents `docAppend` x)]
+        Right i -> (label, contents) : i
+
+-- | Drops all trailing newlines.
+dropNLs :: Text -> Text
+dropNLs = T.dropWhileEnd (== '\n')
+
+-- | Main worker for 'innerList' and 'definitionList'.
+-- We need the 'Either' here to be able to tell in the respective functions
+-- whether we're dealing with the next list or a nested paragraph.
+more :: Monoid a => Text -> Parser a
+     -> Parser ([Text], Either (DocH mod Identifier) a)
+more indent item = choice' [ innerParagraphs indent
+                           , moreListItems indent item
+                           , moreContent indent item
+                           , pure ([], Right mempty)
+                           ]
+
+-- | Used by 'innerList' and 'definitionList' to parse any nested paragraphs.
+innerParagraphs :: Text
+                -> Parser ([Text], Either (DocH mod Identifier) a)
+innerParagraphs indent = (,) [] . Left <$> ("\n" *> indentedParagraphs indent)
+
+-- | Attempts to fetch the next list if possibly. Used by 'innerList' and
+-- 'definitionList' to recursively grab lists that aren't separated by a whole
+-- paragraph.
+moreListItems :: Text -> Parser a
+              -> Parser ([Text], Either (DocH mod Identifier) a)
+moreListItems indent item = (,) [] . Right <$> indentedItem
+  where
+    indentedItem = string indent *> Parsec.spaces *> item
+
+-- | Helper for 'innerList' and 'definitionList' which simply takes
+-- a line of text and attempts to parse more list content with 'more'.
+moreContent :: Monoid a => Text -> Parser a
+            -> Parser ([Text], Either (DocH mod Identifier) a)
+moreContent indent item = first . (:) <$> nonEmptyLine <*> more indent item
+
+-- | Parses an indented paragraph.
+-- The indentation is 4 spaces.
+indentedParagraphs :: Text -> Parser (DocH mod Identifier)
+indentedParagraphs indent =
+    (T.unpack . T.concat <$> dropFrontOfPara indent') >>= parseParagraphs
+  where
+    indent' = string $ indent <> "    "
+
+-- | Grab as many fully indented paragraphs as we can.
+dropFrontOfPara :: Parser Text -> Parser [Text]
+dropFrontOfPara sp = do
+  currentParagraph <- some (try (sp *> takeNonEmptyLine))
+  followingParagraphs <-
+    choice' [ skipHorizontalSpace *> nextPar -- we have more paragraphs to take
+            , skipHorizontalSpace *> nlList -- end of the ride, remember the newline
+            , Parsec.eof *> return []       -- nothing more to take at all
+            ]
+  return (currentParagraph ++ followingParagraphs)
+  where
+    nextPar = (++) <$> nlList <*> dropFrontOfPara sp
+    nlList = "\n" *> return ["\n"]
+
+nonSpace :: Text -> Parser Text
+nonSpace xs
+  | T.all isSpace xs = fail "empty line"
+  | otherwise = return xs
+
+-- | Takes a non-empty, not fully whitespace line.
+--
+--  Doesn't discard the trailing newline.
+takeNonEmptyLine :: Parser Text
+takeNonEmptyLine = do
+    l <- takeWhile1 (/= '\n') >>= nonSpace
+    _ <- "\n"
+    pure (l <> "\n")
+
+-- | Takes indentation of first non-empty line.
+--
+-- More precisely: skips all whitespace-only lines and returns indentation
+-- (horizontal space, might be empty) of that non-empty line.
+takeIndent :: Parser Text
+takeIndent = do
+  indent <- takeHorizontalSpace
+  choice' [ "\n" *> takeIndent
+          , return indent
+          ]
+
+-- | Blocks of text of the form:
+--
+-- >> foo
+-- >> bar
+-- >> baz
+--
+birdtracks :: Parser (DocH mod a)
+birdtracks = DocCodeBlock . DocString . T.unpack . T.intercalate "\n" . stripSpace <$> some line
+  where
+    line = try (skipHorizontalSpace *> ">" *> takeLine)
+
+stripSpace :: [Text] -> [Text]
+stripSpace = fromMaybe <*> mapM strip'
+  where
+    strip' t = case T.uncons t of
+                 Nothing -> Just ""
+                 Just (' ',t') -> Just t'
+                 _ -> Nothing
+
+-- | Parses examples. Examples are a paragraph level entity (separated by an empty line).
+-- Consecutive examples are accepted.
+examples :: Parser (DocH mod a)
+examples = DocExamples <$> (many (try (skipHorizontalSpace *> "\n")) *> go)
+  where
+    go :: Parser [Example]
+    go = do
+      prefix <- takeHorizontalSpace <* ">>>"
+      expr <- takeLine
+      (rs, es) <- resultAndMoreExamples
+      return (makeExample prefix expr rs : es)
+      where
+        resultAndMoreExamples :: Parser ([Text], [Example])
+        resultAndMoreExamples = choice' [ moreExamples, result, pure ([], []) ]
+          where
+            moreExamples :: Parser ([Text], [Example])
+            moreExamples = (,) [] <$> go
+
+            result :: Parser ([Text], [Example])
+            result = first . (:) <$> nonEmptyLine <*> resultAndMoreExamples
+
+    makeExample :: Text -> Text -> [Text] -> Example
+    makeExample prefix expression res =
+      Example (T.unpack (T.strip expression)) result
+      where
+        result = map (T.unpack . substituteBlankLine . tryStripPrefix) res
+
+        tryStripPrefix xs = fromMaybe xs (T.stripPrefix prefix xs)
+
+        substituteBlankLine "<BLANKLINE>" = ""
+        substituteBlankLine xs = xs
+
+nonEmptyLine :: Parser Text
+nonEmptyLine = try (mfilter (T.any (not . isSpace)) takeLine)
+
+takeLine :: Parser Text
+takeLine = try (takeWhile (/= '\n') <* endOfLine)
+
+endOfLine :: Parser ()
+endOfLine = void "\n" <|> Parsec.eof
+
+-- | Property parser.
+--
+-- >>> snd <$> parseOnly property "prop> hello world"
+-- Right (DocProperty "hello world")
+property :: Parser (DocH mod a)
+property = DocProperty . T.unpack . T.strip <$> ("prop>" *> takeWhile1 (/= '\n'))
+
+-- |
+-- Paragraph level codeblock. Anything between the two delimiting \@ is parsed
+-- for markup.
+codeblock :: Parser (DocH mod Identifier)
+codeblock =
+  DocCodeBlock . parseParagraph . dropSpaces
+  <$> ("@" *> skipHorizontalSpace *> "\n" *> block' <* "@")
+  where
+    dropSpaces xs =
+      case splitByNl xs of
+        [] -> xs
+        ys -> case T.uncons (last ys) of
+          Just (' ',_) -> case mapM dropSpace ys of
+                            Nothing -> xs
+                            Just zs -> T.intercalate "\n" zs
+          _ -> xs
+
+    -- This is necessary because ‘lines’ swallows up a trailing newline
+    -- and we lose information about whether the last line belongs to @ or to
+    -- text which we need to decide whether we actually want to be dropping
+    -- anything at all.
+    splitByNl = unfoldr (\x -> case T.uncons x of
+                                 Just ('\n',x') -> Just (T.span (/= '\n') x')
+                                 _ -> Nothing)
+                . ("\n" <>)
+
+    dropSpace t = case T.uncons t of
+                    Nothing -> Just ""
+                    Just (' ',t') -> Just t'
+                    _ -> Nothing
+
+    block' = scan p False
+      where
+        p isNewline c
+          | isNewline && c == '@' = Nothing
+          | isNewline && isSpace c = Just isNewline
+          | otherwise = Just $ c == '\n'
+
+hyperlink :: Parser (DocH mod Identifier)
+hyperlink = choice' [ angleBracketLink, autoUrl ]
+
+angleBracketLink :: Parser (DocH mod a)
+angleBracketLink =
+    DocHyperlink . makeLabeled (\s -> Hyperlink s . fmap DocString)
+    <$> disallowNewline ("<" *> takeUntil ">")
+
+-- | The text for a markdown link, enclosed in square brackets.
+markdownLinkText :: Parser (DocH mod Identifier)
+markdownLinkText = parseParagraph . T.strip <$> ("[" *> takeUntil "]")
+
+-- | The target for a markdown link, enclosed in parenthesis.
+markdownLinkTarget :: Parser String
+markdownLinkTarget = whitespace *> url
+  where
+    whitespace :: Parser ()
+    whitespace = skipHorizontalSpace <* optional ("\n" *> skipHorizontalSpace)
+
+    url :: Parser String
+    url = rejectWhitespace (decode <$> ("(" *> takeUntil ")"))
+
+    rejectWhitespace :: MonadPlus m => m String -> m String
+    rejectWhitespace = mfilter (all (not . isSpace))
+
+    decode :: Text -> String
+    decode = T.unpack . removeEscapes
+
+-- | Looks for URL-like things to automatically hyperlink even if they
+-- weren't marked as links.
+autoUrl :: Parser (DocH mod a)
+autoUrl = mkLink <$> url
+  where
+    url = mappend <$> choice' [ "http://", "https://", "ftp://"] <*> takeWhile1 (not . isSpace)
+
+    mkLink :: Text -> DocH mod a
+    mkLink s = case T.unsnoc s of
+      Just (xs,x) | x `elem` (",.!?" :: String) -> DocHyperlink (mkHyperlink xs) `docAppend` DocString [x]
+      _ -> DocHyperlink (mkHyperlink s)
+
+    mkHyperlink :: Text -> Hyperlink (DocH mod a)
+    mkHyperlink lnk = Hyperlink (T.unpack lnk) Nothing
+
+
+-- | Parses identifiers with help of 'parseValid'.
+identifier :: Parser (DocH mod Identifier)
+identifier = DocIdentifier <$> parseValid
diff --git a/haddock-library/src/Documentation/Haddock/Parser/Identifier.hs b/haddock-library/src/Documentation/Haddock/Parser/Identifier.hs
new file mode 100644
--- /dev/null
+++ b/haddock-library/src/Documentation/Haddock/Parser/Identifier.hs
@@ -0,0 +1,159 @@
+{-# LANGUAGE BangPatterns #-}
+-- |
+-- Module      :  Documentation.Haddock.Parser.Identifier
+-- Copyright   :  (c) Alec Theriault 2019,
+-- License     :  BSD-like
+--
+-- Maintainer  :  haddock@projects.haskell.org
+-- Stability   :  experimental
+-- Portability :  portable
+--
+-- Functionality for parsing identifiers and operators
+
+module Documentation.Haddock.Parser.Identifier (
+  Identifier(..),
+  parseValid,
+) where
+
+import Documentation.Haddock.Types           ( Namespace(..) )
+import Documentation.Haddock.Parser.Monad
+import qualified Text.Parsec as Parsec
+import           Text.Parsec.Pos             ( updatePosChar )
+import           Text.Parsec                 ( State(..)
+                                             , getParserState, setParserState )
+
+import Data.Text (Text)
+import qualified Data.Text as T
+
+import           Data.Char (isAlpha, isAlphaNum)
+import Control.Monad (guard)
+import Data.Maybe
+import CompatPrelude
+
+-- | Identifier string surrounded with namespace, opening, and closing quotes/backticks.
+data Identifier = Identifier !Namespace !Char String !Char
+  deriving (Show, Eq)
+
+parseValid :: Parser Identifier
+parseValid = do
+  s@State{ stateInput = inp, statePos = pos } <- getParserState
+
+  case takeIdentifier inp of
+    Nothing -> Parsec.parserFail "parseValid: Failed to match a valid identifier"
+    Just (ns, op, ident, cl, inp') ->
+      let posOp = updatePosChar pos op
+          posIdent = T.foldl updatePosChar posOp ident
+          posCl = updatePosChar posIdent cl
+          s' = s{ stateInput = inp', statePos = posCl }
+      in setParserState s' $> Identifier ns op (T.unpack ident) cl
+
+
+-- | Try to parse a delimited identifier off the front of the given input.
+--
+-- This tries to match as many valid Haskell identifiers/operators as possible,
+-- to the point of sometimes accepting invalid things (ex: keywords). Some
+-- considerations:
+--
+--   - operators and identifiers can have module qualifications
+--   - operators can be wrapped in parens (for prefix)
+--   - identifiers can be wrapped in backticks (for infix)
+--   - delimiters are backticks or regular ticks
+--   - since regular ticks are also valid in identifiers, we opt for the
+--     longest successful parse
+--
+-- This function should make /O(1)/ allocations
+takeIdentifier :: Text -> Maybe (Namespace, Char, Text, Char, Text)
+takeIdentifier input = listToMaybe $ do
+
+    -- Optional namespace
+    let (ns, input') = case T.uncons input of
+                         Just ('v', i) -> (Value, i)
+                         Just ('t', i) -> (Type, i)
+                         _             -> (None, input)
+
+    -- Opening tick
+    (op, input'') <- maybeToList (T.uncons input')
+    guard (op == '\'' || op == '`')
+
+    -- Identifier/operator
+    (ident, input''') <- wrapped input''
+
+    -- Closing tick
+    (cl, input'''') <- maybeToList (T.uncons input''')
+    guard (cl == '\'' || cl == '`')
+
+    return (ns, op, ident, cl, input'''')
+
+  where
+
+    -- | Parse out a wrapped, possibly qualified, operator or identifier
+    wrapped t = do
+      (c, t'  ) <- maybeToList (T.uncons t)
+      -- Tuples
+      case c of
+        '(' | Just (c', _) <- T.uncons t'
+            , c' == ',' || c' == ')'
+            -> do let (commas, t'') = T.span (== ',') t'
+                  (')', t''') <- maybeToList (T.uncons t'')
+                  return (T.take (T.length commas + 2) t, t''')
+
+        -- Parenthesized
+        '(' -> do (n,   t'' ) <- general False 0 [] t'
+                  (')', t''') <- maybeToList (T.uncons t'')
+                  return (T.take (n + 2) t, t''')
+
+        -- Backticked
+        '`' -> do (n,   t'' ) <- general False 0 [] t'
+                  ('`', t''') <- maybeToList (T.uncons t'')
+                  return (T.take (n + 2) t, t''')
+
+        -- Unadorned
+        _   -> do (n,   t'' ) <- general False 0 [] t
+                  return (T.take n t, t'')
+
+    -- | Parse out a possibly qualified operator or identifier
+    general :: Bool           -- ^ refuse inputs starting with operators
+            -> Int            -- ^ total characters \"consumed\" so far
+            -> [(Int, Text)]  -- ^ accumulated results
+            -> Text           -- ^ current input
+            -> [(Int, Text)]  -- ^ total characters parsed & what remains
+    general !identOnly !i acc t
+      -- Starts with an identifier (either just an identifier, or a module qual)
+      | Just (n, rest) <- identLike t
+      = if T.null rest
+          then acc
+          else case T.head rest of
+                 '`' -> (n + i, rest) : acc
+                 ')' -> (n + i, rest) : acc
+                 '.' -> general False (n + i + 1) acc (T.tail rest)
+                 '\'' -> let (m, rest') = quotes rest
+                         in general True (n + m + 1 + i) ((n + m + i, rest') : acc) (T.tail rest')
+                 _ -> acc
+
+      -- An operator
+      | Just (n, rest) <- optr t
+      , not identOnly
+      = (n + i, rest) : acc
+
+      -- Anything else
+      | otherwise
+      = acc
+
+    -- | Parse an identifier off the front of the input
+    identLike t
+      | T.null t = Nothing
+      | isAlpha (T.head t) || '_' == T.head t
+      = let !(idt, rest) = T.span (\c -> isAlphaNum c || c == '_') t
+            !(octos, rest') = T.span (== '#') rest
+      in Just (T.length idt + T.length octos, rest')
+      | otherwise = Nothing
+
+    -- | Parse all but the last quote off the front of the input
+    -- PRECONDITION: T.head t `elem` ['\'', '`']
+    quotes :: Text -> (Int, Text)
+    quotes t = let !n = T.length (T.takeWhile (`elem` ['\'', '`']) t) - 1
+               in (n, T.drop n t)
+
+    -- | Parse an operator off the front of the input
+    optr t = let !(op, rest) = T.span isSymbolChar t
+             in if T.null op then Nothing else Just (T.length op, rest)
diff --git a/haddock-library/src/Documentation/Haddock/Parser/Monad.hs b/haddock-library/src/Documentation/Haddock/Parser/Monad.hs
new file mode 100644
--- /dev/null
+++ b/haddock-library/src/Documentation/Haddock/Parser/Monad.hs
@@ -0,0 +1,149 @@
+{-# LANGUAGE FlexibleContexts #-}
+{-# LANGUAGE FlexibleInstances #-}
+{-# LANGUAGE TypeFamilies #-}
+{-# LANGUAGE TypeOperators #-}
+{-# LANGUAGE BangPatterns #-}
+-- |
+-- Module      :  Documentation.Haddock.Parser.Monad
+-- Copyright   :  (c) Alec Theriault 2018-2019,
+-- License     :  BSD-like
+--
+-- Maintainer  :  haddock@projects.haskell.org
+-- Stability   :  experimental
+-- Portability :  portable
+--
+-- Defines the Parsec monad over which all parsing is done and also provides
+-- more efficient versions of the usual parsec combinator functions (but
+-- specialized to 'Text').
+
+module Documentation.Haddock.Parser.Monad where
+
+import qualified Text.Parsec.Char as Parsec
+import qualified Text.Parsec as Parsec
+import           Text.Parsec.Pos             ( updatePosChar )
+import           Text.Parsec                 ( State(..)
+                                             , getParserState, setParserState )
+
+import qualified Data.Text as T
+import           Data.Text                   ( Text )
+
+import           Control.Monad               ( mfilter )
+import           Data.String                 ( IsString(..) )
+import           Data.Bits                   ( Bits(..) )
+import           Data.Char                   ( ord )
+import           Data.List                   ( foldl' )
+import           Control.Applicative as App
+
+import           Documentation.Haddock.Types ( Version )
+
+import           Prelude hiding (takeWhile)
+import           CompatPrelude
+
+-- | The only bit of information we really care about trudging along with us
+-- through parsing is the version attached to a @\@since@ annotation - if
+-- the doc even contained one.
+newtype ParserState = ParserState {
+  parserStateSince :: Maybe Version
+} deriving (Eq, Show)
+
+initialParserState :: ParserState
+initialParserState = ParserState Nothing
+
+setSince :: Version -> Parser ()
+setSince since = Parsec.modifyState (\st -> st{ parserStateSince = Just since })
+
+type Parser = Parsec.Parsec Text ParserState
+
+instance (a ~ Text) => IsString (Parser a) where
+  fromString = fmap T.pack . Parsec.string
+
+parseOnly :: Parser a -> Text -> Either String (ParserState, a)
+parseOnly p t = case Parsec.runParser p' initialParserState "<haddock>" t of
+                  Left e -> Left (show e)
+                  Right (x,s) -> Right (s,x)
+  where p' = (,) <$> p <*> Parsec.getState
+
+-- | Always succeeds, but returns 'Nothing' if at the end of input. Does not
+-- consume input.
+--
+-- Equivalent to @Parsec.optionMaybe . Parsec.lookAhead $ Parsec.anyChar@, but
+-- more efficient.
+peekChar :: Parser (Maybe Char)
+peekChar = headOpt . stateInput <$> getParserState
+  where headOpt t | T.null t = Nothing
+                  | otherwise = Just (T.head t)
+{-# INLINE peekChar #-}
+
+-- | Fails if at the end of input. Does not consume input.
+--
+-- Equivalent to @Parsec.lookAhead Parsec.anyChar@, but more efficient.
+peekChar' :: Parser Char
+peekChar' = headFail . stateInput =<< getParserState
+  where headFail t | T.null t = Parsec.parserFail "peekChar': reached EOF"
+                   | otherwise = App.pure (T.head t)
+{-# INLINE peekChar' #-}
+
+-- | Parses the given string. Returns the parsed string.
+--
+-- Equivalent to @Parsec.string (T.unpack t) $> t@, but more efficient.
+string :: Text -> Parser Text
+string t = do
+  s@State{ stateInput = inp, statePos = pos } <- getParserState
+  case T.stripPrefix t inp of
+    Nothing -> Parsec.parserFail "string: Failed to match the input string"
+    Just inp' ->
+      let pos' = T.foldl updatePosChar pos t
+          s' = s{ stateInput = inp', statePos = pos' }
+      in setParserState s' $> t
+
+-- | Keep matching characters as long as the predicate function holds (and
+-- return them).
+--
+-- Equivalent to @fmap T.pack . Parsec.many@, but more efficient.
+takeWhile :: (Char -> Bool) -> Parser Text
+takeWhile f = do
+  s@State{ stateInput = inp, statePos = pos } <- getParserState
+  let (t, inp') = T.span f inp
+      pos' = T.foldl updatePosChar pos t
+      s' = s{ stateInput = inp', statePos = pos' }
+  setParserState s' $> t
+
+-- | Like 'takeWhile', but fails if no characters matched.
+--
+-- Equivalent to @fmap T.pack . Parsec.many1@, but more efficient.
+takeWhile1 :: (Char -> Bool) -> Parser Text
+takeWhile1 = mfilter (not . T.null) . takeWhile
+
+-- | Scan the input text, accumulating characters as long as the scanning
+-- function returns true.
+scan :: (s -> Char -> Maybe s) -- ^ scan function
+     -> s                      -- ^ initial state
+     -> Parser Text 
+scan f st = do
+  s@State{ stateInput = inp, statePos = pos } <- getParserState
+  go inp st pos 0 $ \inp' pos' n ->
+    let s' = s{ Parsec.stateInput = inp', Parsec.statePos = pos' }
+    in setParserState s' $> T.take n inp
+  where
+    go inp s !pos !n cont
+      = case T.uncons inp of
+          Nothing -> cont inp pos n        -- ran out of input
+          Just (c, inp') ->
+             case f s c of
+               Nothing -> cont inp pos n   -- scan function failed
+               Just s' -> go inp' s' (updatePosChar pos c) (n+1) cont
+
+
+-- | Parse a decimal number.
+decimal :: Integral a => Parser a
+decimal = foldl' step 0 `fmap` Parsec.many1 Parsec.digit
+  where step a c = a * 10 + fromIntegral (ord c - 48)
+
+-- | Parse a hexadecimal number.
+hexadecimal :: (Integral a, Bits a) => Parser a
+hexadecimal = foldl' step 0 `fmap` Parsec.many1 Parsec.hexDigit 
+  where
+  step a c | w >= 48 && w <= 57  = (a `shiftL` 4) .|. fromIntegral (w - 48)
+           | w >= 97             = (a `shiftL` 4) .|. fromIntegral (w - 87)
+           | otherwise           = (a `shiftL` 4) .|. fromIntegral (w - 55)
+    where w = ord c
diff --git a/haddock-library/src/Documentation/Haddock/Parser/Util.hs b/haddock-library/src/Documentation/Haddock/Parser/Util.hs
new file mode 100644
--- /dev/null
+++ b/haddock-library/src/Documentation/Haddock/Parser/Util.hs
@@ -0,0 +1,79 @@
+{-# LANGUAGE OverloadedStrings #-}
+-- |
+-- Module      :  Documentation.Haddock.Parser.Util
+-- Copyright   :  (c) Mateusz Kowalczyk 2013-2014,
+--                    Simon Hengel      2013
+-- License     :  BSD-like
+--
+-- Maintainer  :  haddock@projects.haskell.org
+-- Stability   :  experimental
+-- Portability :  portable
+--
+-- Various utility functions used by the parser.
+module Documentation.Haddock.Parser.Util (
+  takeUntil,
+  removeEscapes,
+  makeLabeled,
+  takeHorizontalSpace,
+  skipHorizontalSpace,
+) where
+
+import qualified Text.Parsec as Parsec
+
+import qualified Data.Text as T
+import           Data.Text (Text)
+
+import           Control.Applicative
+import           Control.Monad (mfilter)
+import           Documentation.Haddock.Parser.Monad
+import           Prelude hiding (takeWhile)
+
+import           Data.Char (isSpace)
+
+-- | Characters that count as horizontal space
+horizontalSpace :: Char -> Bool
+horizontalSpace c = isSpace c && c /= '\n'
+
+-- | Skip and ignore leading horizontal space
+skipHorizontalSpace :: Parser ()
+skipHorizontalSpace = Parsec.skipMany (Parsec.satisfy horizontalSpace)
+
+-- | Take leading horizontal space
+takeHorizontalSpace :: Parser Text
+takeHorizontalSpace = takeWhile horizontalSpace
+
+makeLabeled :: (String -> Maybe String -> a) -> Text -> a
+makeLabeled f input = case T.break isSpace $ removeEscapes $ T.strip input of
+  (uri, "")    -> f (T.unpack uri) Nothing
+  (uri, label) -> f (T.unpack uri) (Just . T.unpack $ T.stripStart label)
+
+-- | Remove escapes from given string.
+--
+-- Only do this if you do not process (read: parse) the input any further.
+removeEscapes :: Text -> Text
+removeEscapes = T.unfoldr go
+  where
+  go :: Text -> Maybe (Char, Text)
+  go xs = case T.uncons xs of
+            Just ('\\',ys) -> T.uncons ys
+            unconsed -> unconsed
+
+-- | Consume characters from the input up to and including the given pattern.
+-- Return everything consumed except for the end pattern itself.
+takeUntil :: Text -> Parser Text
+takeUntil end_ = T.dropEnd (T.length end_) <$> requireEnd (scan p (False, end)) >>= gotSome
+  where
+    end = T.unpack end_
+
+    p :: (Bool, String) -> Char -> Maybe (Bool, String)
+    p acc c = case acc of
+      (True, _) -> Just (False, end)
+      (_, []) -> Nothing
+      (_, x:xs) | x == c -> Just (False, xs)
+      _ -> Just (c == '\\', end)
+
+    requireEnd = mfilter (T.isSuffixOf end_)
+
+    gotSome xs
+      | T.null xs = fail "didn't get any content"
+      | otherwise = return xs
diff --git a/haddock-library/src/Documentation/Haddock/Types.hs b/haddock-library/src/Documentation/Haddock/Types.hs
new file mode 100644
--- /dev/null
+++ b/haddock-library/src/Documentation/Haddock/Types.hs
@@ -0,0 +1,262 @@
+{-# LANGUAGE CPP, DeriveTraversable #-}
+
+-- |
+-- Module      :  Documentation.Haddock.Types
+-- Copyright   :  (c) Simon Marlow      2003-2006,
+--                    David Waern       2006-2009,
+--                    Mateusz Kowalczyk 2013
+-- License     :  BSD-like
+--
+-- Maintainer  :  haddock@projects.haskellorg
+-- Stability   :  experimental
+-- Portability :  portable
+--
+-- Exposes documentation data types used for (some) of Haddock.
+module Documentation.Haddock.Types where
+
+#if !MIN_VERSION_base(4,8,0)
+import Control.Applicative
+import Data.Foldable
+import Data.Traversable
+#endif
+
+#if MIN_VERSION_base(4,8,0)
+import Control.Arrow ((***))
+import Data.Bifunctor
+#endif
+
+#if MIN_VERSION_base(4,10,0)
+import Data.Bifoldable
+import Data.Bitraversable
+#endif
+
+-- | With the advent of 'Version', we may want to start attaching more
+-- meta-data to comments. We make a structure for this ahead of time
+-- so we don't have to gut half the core each time we want to add such
+-- info.
+data Meta = Meta { _version :: Maybe Version
+                 , _package :: Maybe Package
+                 } deriving (Eq, Show)
+
+data MetaDoc mod id =
+  MetaDoc { _meta :: Meta
+          , _doc :: DocH mod id
+          } deriving (Eq, Show, Functor, Foldable, Traversable)
+
+#if MIN_VERSION_base(4,8,0)
+-- | __NOTE__: Only defined for @base >= 4.8.0@
+instance Bifunctor MetaDoc where
+  bimap f g (MetaDoc m d) = MetaDoc m (bimap f g d)
+#endif
+
+#if MIN_VERSION_base(4,10,0)
+-- | __NOTE__: Only defined for @base >= 4.10.0@
+instance Bifoldable MetaDoc where
+  bifoldr f g z d = bifoldr f g z (_doc d)
+
+-- | __NOTE__: Only defined for @base >= 4.10.0@
+instance Bitraversable MetaDoc where
+  bitraverse f g (MetaDoc m d) = MetaDoc m <$> bitraverse f g d
+#endif
+
+overDoc :: (DocH a b -> DocH c d) -> MetaDoc a b -> MetaDoc c d
+overDoc f d = d { _doc = f $ _doc d }
+
+overDocF :: Functor f => (DocH a b -> f (DocH c d)) -> MetaDoc a b -> f (MetaDoc c d)
+overDocF f d = (\x -> d { _doc = x }) <$> f (_doc d)
+
+type Version = [Int]
+type Package = String
+
+data Hyperlink id = Hyperlink
+  { hyperlinkUrl   :: String
+  , hyperlinkLabel :: Maybe id
+  } deriving (Eq, Show, Functor, Foldable, Traversable)
+
+data ModLink id = ModLink
+  { modLinkName   :: String
+  , modLinkLabel :: Maybe id
+  } deriving (Eq, Show, Functor, Foldable, Traversable)
+
+data Picture = Picture
+  { pictureUri   :: String
+  , pictureTitle :: Maybe String
+  } deriving (Eq, Show)
+
+data Header id = Header
+  { headerLevel :: Int  -- ^ between 1 and 6 inclusive
+  , headerTitle :: id
+  } deriving (Eq, Show, Functor, Foldable, Traversable)
+
+data Example = Example
+  { exampleExpression :: String
+  , exampleResult     :: [String]
+  } deriving (Eq, Show)
+
+data TableCell id = TableCell
+  { tableCellColspan  :: Int
+  , tableCellRowspan  :: Int
+  , tableCellContents :: id
+  } deriving (Eq, Show, Functor, Foldable, Traversable)
+
+newtype TableRow id = TableRow
+  { tableRowCells :: [TableCell id]
+  } deriving (Eq, Show, Functor, Foldable, Traversable)
+
+data Table id = Table
+  { tableHeaderRows :: [TableRow id]
+  , tableBodyRows   :: [TableRow id]
+  } deriving (Eq, Show, Functor, Foldable, Traversable)
+
+data DocH mod id
+  = DocEmpty
+  | DocAppend (DocH mod id) (DocH mod id)
+  | DocString String
+  | DocParagraph (DocH mod id)
+  | DocIdentifier id
+  | DocIdentifierUnchecked mod
+  -- ^ A qualified identifier that couldn't be resolved.
+  | DocModule (ModLink (DocH mod id))
+  -- ^ A link to a module, with an optional label.
+  | DocWarning (DocH mod id)
+  -- ^ This constructor has no counterpart in Haddock markup.
+  | DocEmphasis (DocH mod id)
+  | DocMonospaced (DocH mod id)
+  | DocBold (DocH mod id)
+  | DocUnorderedList [DocH mod id]
+  | DocOrderedList [(Int, DocH mod id)]
+  | DocDefList [(DocH mod id, DocH mod id)]
+  | DocCodeBlock (DocH mod id)
+  | DocHyperlink (Hyperlink (DocH mod id))
+  | DocPic Picture
+  | DocMathInline String
+  | DocMathDisplay String
+  | DocAName String
+  -- ^ A (HTML) anchor. It must not contain any spaces.
+  | DocProperty String
+  | DocExamples [Example]
+  | DocHeader (Header (DocH mod id))
+  | DocTable (Table (DocH mod id))
+  deriving (Eq, Show, Functor, Foldable, Traversable)
+
+#if MIN_VERSION_base(4,8,0)
+-- | __NOTE__: Only defined for @base >= 4.8.0@
+instance Bifunctor DocH where
+  bimap _ _ DocEmpty = DocEmpty
+  bimap f g (DocAppend docA docB) = DocAppend (bimap f g docA) (bimap f g docB)
+  bimap _ _ (DocString s) = DocString s
+  bimap f g (DocParagraph doc) = DocParagraph (bimap f g doc)
+  bimap _ g (DocIdentifier i) = DocIdentifier (g i)
+  bimap f _ (DocIdentifierUnchecked m) = DocIdentifierUnchecked (f m)
+  bimap f g (DocModule (ModLink m lbl)) = DocModule (ModLink m (fmap (bimap f g) lbl))
+  bimap f g (DocWarning doc) = DocWarning (bimap f g doc)
+  bimap f g (DocEmphasis doc) = DocEmphasis (bimap f g doc)
+  bimap f g (DocMonospaced doc) = DocMonospaced (bimap f g doc)
+  bimap f g (DocBold doc) = DocBold (bimap f g doc)
+  bimap f g (DocUnorderedList docs) = DocUnorderedList (map (bimap f g) docs)
+  bimap f g (DocOrderedList docs) = DocOrderedList (map (\(index, a) -> (index, bimap f g a)) docs)
+  bimap f g (DocDefList docs) = DocDefList (map (bimap f g *** bimap f g) docs)
+  bimap f g (DocCodeBlock doc) = DocCodeBlock (bimap f g doc)
+  bimap f g (DocHyperlink (Hyperlink url lbl)) = DocHyperlink (Hyperlink url (fmap (bimap f g) lbl))
+  bimap _ _ (DocPic picture) = DocPic picture
+  bimap _ _ (DocMathInline s) = DocMathInline s
+  bimap _ _ (DocMathDisplay s) = DocMathDisplay s
+  bimap _ _ (DocAName s) = DocAName s
+  bimap _ _ (DocProperty s) = DocProperty s
+  bimap _ _ (DocExamples examples) = DocExamples examples
+  bimap f g (DocHeader (Header level title)) = DocHeader (Header level (bimap f g title))
+  bimap f g (DocTable (Table header body)) = DocTable (Table (map (fmap (bimap f g)) header) (map (fmap (bimap f g)) body))
+#endif
+
+#if MIN_VERSION_base(4,10,0)
+-- | __NOTE__: Only defined for @base >= 4.10.0@
+instance Bifoldable DocH where
+  bifoldr f g z (DocAppend docA docB) = bifoldr f g (bifoldr f g z docA) docB
+  bifoldr f g z (DocParagraph doc) = bifoldr f g z doc
+  bifoldr _ g z (DocIdentifier i) = g i z
+  bifoldr f _ z (DocIdentifierUnchecked m) = f m z
+  bifoldr f g z (DocWarning doc) = bifoldr f g z doc
+  bifoldr f g z (DocEmphasis doc) = bifoldr f g z doc
+  bifoldr f g z (DocMonospaced doc) = bifoldr f g z doc
+  bifoldr f g z (DocBold doc) = bifoldr f g z doc
+  bifoldr f g z (DocUnorderedList docs) = foldr (flip (bifoldr f g)) z docs
+  bifoldr f g z (DocOrderedList docs) = foldr (flip (bifoldr f g)) z (map snd docs)
+  bifoldr f g z (DocDefList docs) = foldr (\(l, r) acc -> bifoldr f g (bifoldr f g acc l) r) z docs
+  bifoldr f g z (DocCodeBlock doc) = bifoldr f g z doc
+  bifoldr f g z (DocHeader (Header _ title)) = bifoldr f g z title
+  bifoldr f g z (DocTable (Table header body)) = foldr (\r acc -> foldr (flip (bifoldr f g)) acc r) (foldr (\r acc -> foldr (flip (bifoldr f g)) acc r) z body) header
+  bifoldr _ _ z _ = z
+
+-- | __NOTE__: Only defined for @base >= 4.10.0@
+instance Bitraversable DocH where
+  bitraverse _ _ DocEmpty = pure DocEmpty
+  bitraverse f g (DocAppend docA docB) = DocAppend <$> bitraverse f g docA <*> bitraverse f g docB
+  bitraverse _ _ (DocString s) = pure (DocString s)
+  bitraverse f g (DocParagraph doc) = DocParagraph <$> bitraverse f g doc
+  bitraverse _ g (DocIdentifier i) = DocIdentifier <$> g i
+  bitraverse f _ (DocIdentifierUnchecked m) = DocIdentifierUnchecked <$> f m
+  bitraverse f g (DocModule (ModLink m lbl)) = DocModule <$> (ModLink m <$> traverse (bitraverse f g) lbl)
+  bitraverse f g (DocWarning doc) = DocWarning <$> bitraverse f g doc
+  bitraverse f g (DocEmphasis doc) = DocEmphasis <$> bitraverse f g doc
+  bitraverse f g (DocMonospaced doc) = DocMonospaced <$> bitraverse f g doc
+  bitraverse f g (DocBold doc) = DocBold <$> bitraverse f g doc
+  bitraverse f g (DocUnorderedList docs) = DocUnorderedList <$> traverse (bitraverse f g) docs
+  bitraverse f g (DocOrderedList docs) = DocOrderedList <$> traverseSnd (bitraverse f g) docs
+    where traverseSnd f' = traverse (\(x, a) -> (\b -> (x, b)) <$> f' a)
+  bitraverse f g (DocDefList docs) = DocDefList <$> traverse (bitraverse (bitraverse f g) (bitraverse f g)) docs
+  bitraverse f g (DocCodeBlock doc) = DocCodeBlock <$> bitraverse f g doc
+  bitraverse f g (DocHyperlink (Hyperlink url lbl)) = DocHyperlink <$> (Hyperlink url <$> traverse (bitraverse f g) lbl)
+  bitraverse _ _ (DocPic picture) = pure (DocPic picture)
+  bitraverse _ _ (DocMathInline s) = pure (DocMathInline s)
+  bitraverse _ _ (DocMathDisplay s) = pure (DocMathDisplay s)
+  bitraverse _ _ (DocAName s) = pure (DocAName s)
+  bitraverse _ _ (DocProperty s) = pure (DocProperty s)
+  bitraverse _ _ (DocExamples examples) = pure (DocExamples examples)
+  bitraverse f g (DocHeader (Header level title)) = (DocHeader . Header level) <$> bitraverse f g title
+  bitraverse f g (DocTable (Table header body)) = (\h b -> DocTable (Table h b)) <$> traverse (traverse (bitraverse f g)) header <*> traverse (traverse (bitraverse f g)) body
+#endif
+
+-- | The namespace qualification for an identifier.
+data Namespace = Value | Type | None deriving (Eq, Ord, Enum, Show)
+
+-- | Render the a namespace into the same format it was initially parsed.
+renderNs :: Namespace -> String
+renderNs Value = "v"
+renderNs Type = "t"
+renderNs None = ""
+
+
+-- | 'DocMarkupH' is a set of instructions for marking up documentation.
+-- In fact, it's really just a mapping from 'Doc' to some other
+-- type [a], where [a] is usually the type of the output (HTML, say).
+-- Use 'Documentation.Haddock.Markup.markup' to apply a 'DocMarkupH' to
+-- a 'DocH'.
+--
+-- @since 1.4.5
+--
+data DocMarkupH mod id a = Markup
+  { markupEmpty                :: a
+  , markupString               :: String -> a
+  , markupParagraph            :: a -> a
+  , markupAppend               :: a -> a -> a
+  , markupIdentifier           :: id -> a
+  , markupIdentifierUnchecked  :: mod -> a
+  , markupModule               :: ModLink a -> a
+  , markupWarning              :: a -> a
+  , markupEmphasis             :: a -> a
+  , markupBold                 :: a -> a
+  , markupMonospaced           :: a -> a
+  , markupUnorderedList        :: [a] -> a
+  , markupOrderedList          :: [(Int,a)] -> a
+  , markupDefList              :: [(a,a)] -> a
+  , markupCodeBlock            :: a -> a
+  , markupHyperlink            :: Hyperlink a -> a
+  , markupAName                :: String -> a
+  , markupPic                  :: Picture -> a
+  , markupMathInline           :: String -> a
+  , markupMathDisplay          :: String -> a
+  , markupProperty             :: String -> a
+  , markupExample              :: [Example] -> a
+  , markupHeader               :: Header a -> a
+  , markupTable                :: Table a -> a
+  }
diff --git a/haddock.cabal b/haddock.cabal
--- a/haddock.cabal
+++ b/haddock.cabal
@@ -1,215 +1,194 @@
+cabal-version:        3.0
 name:                 haddock
-version:              2.9.4
+version:              2.29.1
 synopsis:             A documentation-generation tool for Haskell libraries
-description:          Haddock is a documentation-generation tool for Haskell
-                      libraries
-license:              BSD3
+description:
+  This is Haddock, a tool for automatically generating documentation
+  from annotated Haskell source code. It is primary intended for documenting
+  library interfaces, but it should be useful for any kind of Haskell code.
+  .
+  Haddock lets you write documentation annotations next to the definitions of
+  functions and types in the source code, in a syntax that is easy on the eye
+  when writing the source code (no heavyweight mark-up).
+  .
+  Haddock understands Haskell's module system, so you can structure your code
+  however you like without worrying that internal structure will be exposed in
+  the generated documentation. For example, it is common to implement a library
+  in several modules, but define the external API by having a single module
+  which re-exports parts of these implementation modules. Using Haddock, you can
+  still write documentation annotations next to the actual definitions of the
+  functions and types in the library, but the documentation annotations from the
+  implementation will be propagated to the external API when the documentation is
+  generated. Abstract types and classes are handled correctly. In fact, even
+  without any documentation annotations, Haddock can generate useful documentation
+  from your source code.
+  .
+  Documentation for the haddock binary is available at [readthedocs](https://haskell-haddock.readthedocs.io/en/latest/).
+  .
+  <<https://cdn.rawgit.com/haskell/haddock/ghc-8.10/doc/cheatsheet/haddocks.svg>>
+license:              BSD-3-Clause
 license-file:         LICENSE
 author:               Simon Marlow, David Waern
-maintainer:           David Waern <david.waern@gmail.com>
+maintainer:           Alec Theriault <alec.theriault@gmail.com>, Alex Biehl <alexbiehl@gmail.com>, Simon Hengel <sol@typeful.net>, Mateusz Kowalczyk <fuuzetsu@fuuzetsu.co.uk>
 homepage:             http://www.haskell.org/haddock/
-bug-reports:          http://trac.haskell.org/haddock
+bug-reports:          https://github.com/haskell/haddock/issues
 copyright:            (c) Simon Marlow, David Waern
 category:             Documentation
 build-type:           Simple
-cabal-version:        >= 1.10
-stability:            experimental
+tested-with:          GHC==9.6.*
 
 extra-source-files:
-  CHANGES
-  README
+  CHANGES.md
+  README.md
   doc/Makefile
-  doc/README
-  doc/aclocal.m4
-  doc/config.mk.in
-  doc/configure.ac
-  doc/docbook-xml.mk
-  doc/fptools.css
-  doc/haddock.xml
-  examples/A.hs
-  examples/B.hs
-  examples/Bug1.hs
-  examples/Bug2.hs
-  examples/Bug3.hs
-  examples/Bug4.hs
-  examples/Bug6.hs
-  examples/Bug7.hs
-  examples/Bug8.hs
-  examples/Bug9.hs
-  examples/Hash.hs
-  examples/Hidden.hs
-  examples/Makefile
-  examples/NoLayout.hs
-  examples/Test.hs
-  examples/Visible.hs
-  examples/hide-bug/A.hs
-  examples/hide-bug/B.hs
-  examples/hide-bug/C.hs
-  examples/hide-bug/D.hs
-  haddock.spec
-  haskell.vim
-  src/haddock.sh
--- The test files shouldn't have to go here, but the source files for
--- the test-suite stanzas don't get picked up by `cabal sdist`.
-  tests/html-tests/runtests.hs
-
-data-files:
-  html/frames.html
-  html/haddock-util.js
-  html/Classic.theme/haskell_icon.gif
-  html/Classic.theme/minus.gif
-  html/Classic.theme/plus.gif
-  html/Classic.theme/xhaddock.css
-  html/Ocean.std-theme/hslogo-16.png
-  html/Ocean.std-theme/minus.gif
-  html/Ocean.std-theme/ocean.css
-  html/Ocean.std-theme/plus.gif
-  html/Ocean.std-theme/synopsis.png
-  latex/haddock.sty
+  doc/README.md
+  doc/*.rst
+  doc/conf.py
+  haddock-api/src/haddock.sh
+  html-test/src/*.hs
+  html-test/ref/*.html
+  hypsrc-test/src/*.hs
+  hypsrc-test/src/*.h
+  hypsrc-test/ref/src/*.html
+  latex-test/src/**/*.hs
+  latex-test/ref/**/*.tex
+  hoogle-test/src/**/*.hs
+  hoogle-test/ref/**/*.txt
 
 flag in-ghc-tree
   description: Are we in a GHC tree?
   default: False
   manual: True
 
-flag test
-  default: False
-  manual: True
-
 executable haddock
   default-language:     Haskell2010
+  main-is:              Main.hs
+  hs-source-dirs:       driver
+  ghc-options:          -funbox-strict-fields -Wall -Wincomplete-uni-patterns -Wincomplete-record-updates -O2 -threaded
+
+  -- haddock typically only supports a single GHC major version
   build-depends:
-    base >= 4.3 && < 4.5,
-    filepath,
-    directory,
-    pretty,
-    containers,
-    array,
-    xhtml >= 3000.2 && < 3000.3,
-    Cabal >= 1.10,
-    ghc >= 7.2 && < 7.4
+    base ^>= 4.13.0.0 || ^>= 4.14.0.0 || ^>= 4.15.0.0 || ^>= 4.16.0.0 || ^>= 4.17.0.0 || ^>= 4.18.0.0 || ^>= 4.19.0.0
 
   if flag(in-ghc-tree)
+    hs-source-dirs: haddock-api/src,  haddock-library/src
     cpp-options: -DIN_GHC_TREE
-  else
-    build-depends: ghc-paths
+    build-depends:
+      filepath,
+      directory,
+      containers,
+      deepseq,
+      exceptions,
+      array,
+      xhtml >= 3000.2 && < 3000.3,
+      ghc-boot,
+      ghc-boot-th,
+      ghc == 9.6.*,
+      bytestring,
+      parsec,
+      text,
+      transformers,
+      mtl
 
-  if flag(test)
-    cpp-options: -DTEST
-    build-depends: QuickCheck >= 2.1 && < 3
+    other-modules:
+      CompatPrelude
+      Documentation.Haddock.Parser
+      Documentation.Haddock.Parser.Monad
+      Documentation.Haddock.Parser.Identifier
+      Documentation.Haddock.Types
+      Documentation.Haddock.Doc
+      Documentation.Haddock.Parser.Util
+      Documentation.Haddock.Markup
 
-  main-is:              Main.hs
-  hs-source-dirs:       src
-  default-extensions:   CPP, DeriveDataTypeable,
-                        ScopedTypeVariables, MagicHash
-  ghc-options:          -funbox-strict-fields -O2 -Wall -fwarn-tabs
+      Documentation.Haddock
+      Haddock
+      Haddock.Interface
+      Haddock.Interface.Json
+      Haddock.Interface.Rename
+      Haddock.Interface.Create
+      Haddock.Interface.AttachInstances
+      Haddock.Interface.LexParseRn
+      Haddock.Interface.ParseModuleHeader
+      Haddock.Interface.Specialize
+      Haddock.Parser
+      Haddock.Utils
+      Haddock.Utils.Json
+      Haddock.Utils.Json.Parser
+      Haddock.Utils.Json.Types
+      Haddock.Backends.Xhtml
+      Haddock.Backends.Xhtml.Decl
+      Haddock.Backends.Xhtml.DocMarkup
+      Haddock.Backends.Xhtml.Layout
+      Haddock.Backends.Xhtml.Meta
+      Haddock.Backends.Xhtml.Names
+      Haddock.Backends.Xhtml.Themes
+      Haddock.Backends.Xhtml.Types
+      Haddock.Backends.Xhtml.Utils
+      Haddock.Backends.LaTeX
+      Haddock.Backends.HaddockDB
+      Haddock.Backends.Hoogle
+      Haddock.Backends.Hyperlinker
+      Haddock.Backends.Hyperlinker.Parser
+      Haddock.Backends.Hyperlinker.Renderer
+      Haddock.Backends.Hyperlinker.Types
+      Haddock.Backends.Hyperlinker.Utils
+      Haddock.ModuleTree
+      Haddock.Types
+      Haddock.Doc
+      Haddock.Version
+      Haddock.InterfaceFile
+      Haddock.Options
+      Haddock.GhcUtils
+      Haddock.Syb
+      Haddock.Convert
 
-  other-modules:
-    Haddock.Interface
-    Haddock.Interface.Rename
-    Haddock.Interface.Create
-    Haddock.Interface.ExtractFnArgDocs
-    Haddock.Interface.AttachInstances
-    Haddock.Interface.Rn
-    Haddock.Interface.LexParseRn
-    Haddock.Interface.ParseModuleHeader
-    Haddock.Lex
-    Haddock.Parse
-    Haddock.Utils
-    Haddock.Backends.Xhtml
-    Haddock.Backends.Xhtml.Decl
-    Haddock.Backends.Xhtml.DocMarkup
-    Haddock.Backends.Xhtml.Layout
-    Haddock.Backends.Xhtml.Names
-    Haddock.Backends.Xhtml.Themes
-    Haddock.Backends.Xhtml.Types
-    Haddock.Backends.Xhtml.Utils
-    Haddock.Backends.LaTeX
-    Haddock.Backends.HaddockDB
-    Haddock.Backends.Hoogle
-    Haddock.ModuleTree
-    Haddock.Types
-    Haddock.Doc
-    Haddock.Version
-    Haddock.InterfaceFile        
-    Haddock.Options
-    Haddock.GhcUtils
-    Haddock.Convert
-   
-library
-  default-language:     Haskell2010
-  build-depends:
-    base >= 4.3 && < 4.5,
-    filepath,
-    directory,
-    pretty,
-    containers,
-    array,
-    xhtml >= 3000.2 && < 3000.3,
-    Cabal >= 1.10,
-    ghc >= 7.2 && < 7.4
+      Paths_haddock
 
-  if flag(in-ghc-tree)
-    cpp-options: -DIN_GHC_TREE
-  else
-    build-depends: ghc-paths
+    autogen-modules:
+      Paths_haddock
 
-  if flag(test)
-    cpp-options: -DTEST
-    build-depends: QuickCheck >= 2.1 && < 3
+  else
+    -- in order for haddock's advertised version number to have proper meaning,
+    -- we pin down to a single haddock-api version.
+    build-depends:  haddock-api == 2.29.1
 
-  hs-source-dirs:       src
-  default-extensions:   CPP, DeriveDataTypeable,
-                        ScopedTypeVariables, MagicHash
-  ghc-options:          -funbox-strict-fields -O2 -Wall -fwarn-tabs
+test-suite html-test
+  type:             exitcode-stdio-1.0
+  -- This tells cabal that this test depends on the executable
+  -- component 'haddock' from this very same package, as well
+  -- as adding the build-folder where the `haddock`
+  -- executable can be found in front of $PATH
+  build-tool-depends: haddock:haddock
+  default-language:   Haskell2010
+  main-is:            Main.hs
+  hs-source-dirs:     html-test
+  build-depends:      base, filepath, haddock-test == 0.0.1
 
-  exposed-modules:
-    Documentation.Haddock
+test-suite hypsrc-test
+  type:               exitcode-stdio-1.0
+  build-tool-depends: haddock:haddock
+  default-language:   Haskell2010
+  main-is:            Main.hs
+  hs-source-dirs:     hypsrc-test
+  build-depends:      base, filepath, haddock-test == 0.0.1
+  ghc-options:        -Wall -fwarn-tabs
 
-  other-modules:
-    Main
-    Haddock.Interface
-    Haddock.Interface.Rename
-    Haddock.Interface.Create
-    Haddock.Interface.ExtractFnArgDocs
-    Haddock.Interface.AttachInstances
-    Haddock.Interface.Rn
-    Haddock.Interface.LexParseRn
-    Haddock.Interface.ParseModuleHeader
-    Haddock.Lex
-    Haddock.Parse
-    Haddock.Utils
-    Haddock.Backends.Xhtml
-    Haddock.Backends.Xhtml.Decl
-    Haddock.Backends.Xhtml.DocMarkup
-    Haddock.Backends.Xhtml.Layout
-    Haddock.Backends.Xhtml.Names
-    Haddock.Backends.Xhtml.Themes
-    Haddock.Backends.Xhtml.Types
-    Haddock.Backends.Xhtml.Utils
-    Haddock.Backends.LaTeX
-    Haddock.Backends.HaddockDB
-    Haddock.Backends.Hoogle
-    Haddock.ModuleTree
-    Haddock.Types
-    Haddock.Doc
-    Haddock.Version
-    Haddock.InterfaceFile
-    Haddock.Options
-    Haddock.GhcUtils
-    Haddock.Convert
-    Paths_haddock
-  
-  if flag(in-ghc-tree)
-    buildable: False
+test-suite latex-test
+  type:               exitcode-stdio-1.0
+  build-tool-depends: haddock:haddock
+  default-language:   Haskell2010
+  main-is:            Main.hs
+  hs-source-dirs:     latex-test
+  build-depends:      base, filepath, haddock-test == 0.0.1
 
-test-suite html-tests
-  type:             exitcode-stdio-1.0
-  default-language: Haskell2010
-  main-is:          runtests.hs
-  hs-source-dirs:   tests/html-tests
-  build-depends:    base, directory, process, filepath, Cabal, regex-compat
+test-suite hoogle-test
+  type:               exitcode-stdio-1.0
+  build-tool-depends: haddock:haddock
+  default-language:   Haskell2010
+  main-is:            Main.hs
+  hs-source-dirs:     hoogle-test
+  build-depends:      base, filepath, haddock-test == 0.0.1
 
 source-repository head
   type:     git
-  location: http://darcs.haskell.org/haddock.git
+  location: https://github.com/haskell/haddock.git
diff --git a/haddock.spec b/haddock.spec
deleted file mode 100644
--- a/haddock.spec
+++ /dev/null
@@ -1,81 +0,0 @@
-# This is an RPM spec file that specifies how to package
-# haddock for Red Hat Linux and, possibly, similar systems.
-# It has been tested on Red Hat Linux 7.2 and SuSE Linux 9.1.
-#
-# If this file is part of a tarball, you can build RPMs directly from
-# the tarball by using the following command:
-#
-#    rpm -ta haddock-(VERSION).tar.gz
-#
-# The resulting package will be placed in the RPMS/(arch) subdirectory
-# of your RPM build directory (usually /usr/src/redhat or ~/rpm), with
-# the name haddock-(VERSION)-(RELEASE).noarch.rpm.  A corresponding
-# source RPM package will be in the SRPMS subdirectory.
-#
-# NOTE TO HADDOCK MAINTAINERS: When you release a new version of
-# Haskell mode, update the version definition below to match the
-# version label of your release tarball.
-
-%define name    haddock
-%define version 2.9.4
-%define release 1
-
-Name:           %{name}
-Version:        %{version}
-Release:        %{release}
-License:        BSD-like
-Group:          Development/Languages/Haskell
-URL:            http://haskell.org/haddock/
-Source:         http://haskell.org/haddock/haddock-%{version}.tar.gz
-Packager:       Sven Panne <sven.panne@aedion.de>
-BuildRoot:      %{_tmppath}/%{name}-%{version}-build
-Prefix:         %{_prefix}
-BuildRequires:  ghc, docbook-dtd, docbook-xsl-stylesheets, libxslt, libxml2, fop, xmltex, dvips
-Summary:        A documentation tool for annotated Haskell source code
-
-%description
-Haddock is a tool for automatically generating documentation from
-annotated Haskell source code. It is primary intended for documenting
-libraries, but it should be useful for any kind of Haskell code.
-
-Haddock lets you write documentation annotations next to the
-definitions of functions and types in the source code, in a syntax
-that is easy on the eye when writing the source code (no heavyweight
-mark-up). The documentation generated by Haddock is fully hyperlinked
--- click on a type name in a type signature to go straight to the
-definition, and documentation, for that type.
-
-Haddock can generate documentation in multiple formats; currently HTML
-is implemented, and there is partial support for generating DocBook.
-The generated HTML uses stylesheets, so you need a fairly up-to-date
-browser to view it properly (Mozilla, Konqueror, Opera, and IE 6
-should all be ok).
-
-%prep
-%setup
-
-%build
-runhaskell Setup.lhs configure --prefix=%{_prefix} --docdir=%{_datadir}/doc/packages/%{name}
-runhaskell Setup.lhs build
-cd doc
-test -f configure || autoreconf
-./configure
-make html
-
-%install
-runhaskell Setup.lhs copy --destdir=${RPM_BUILD_ROOT}
-
-%clean
-rm -rf ${RPM_BUILD_ROOT}
-
-%files
-%defattr(-,root,root)
-%doc CHANGES
-%doc LICENSE
-%doc README
-%doc TODO
-%doc doc/haddock
-%doc examples
-%doc haskell.vim
-%{prefix}/bin/haddock
-%{prefix}/share/haddock-%{version}
diff --git a/haskell.vim b/haskell.vim
deleted file mode 100644
--- a/haskell.vim
+++ /dev/null
@@ -1,68 +0,0 @@
-" Attempt to add haddock highlighting for haskell comments
-" It should be placed in ~/.vim/after/syntax/haskell.vim
-" Brad Bowman <haddock.vim@bereft.net>
-
-syn match   hsHdocChunk "$\i\+" contained
-syn match   hsHdocMod /"\(\i\|[.]\)\+"/ contained
-syn match   hsHdocLink "'\(\i\|[.#]\)\+'" contained
-syn region  hsHdocAnchor start="\\\@<!#" skip="\\#" end="\\\@<!#" contained oneline
-" I think emphasis can span multiple lines
-syn region  hsHdocEm start="\\\@<!/" skip="\\/" end="\\\@!/" contained oneline
-syn region  hsHdocURL start="\\\@<!<" end="\\\@<!>" contained oneline
-syn region  hsHdocCode start="\\\@<!@" skip="\\@" end="\\\@<!@" contained oneline
-syn region  hsHdocBCodeBlock start="^@\(\s\|$\)" end="^@\s*$" contained
-syn region  hsHdocLCodeBlock start="\(^\s*--\s*\)\@<=@\s*$" end="\(^\s*--\s*\)\@<=@\s*$" contained
-syn match   hsHdocBHeading "^\s*\*\+" contained
-syn match   hsHdocLHeading "\(^\s*--\s*\)\@<=\*\+" contained
-syn match   hsHdocBTracks "^\s*>" contained
-" match only the > using a look-behind
-syn match   hsHdocLTracks "\(^\s*--\s*\)\@<=>" contained
-
-" todo: numbered lists, mark haddock start separately
-"syn match   hsHdocStart "\([$^|]\|\*\+\)" contained
-
-syn cluster hsHdocSpecial 
-  \ contains=hsHdocMod,hsHdocLink,hsHdocEm,hsHdocCode,hsHdocURL,
-  \ hsHdocAnchor,hsHdocChunk
-
-syn region  hsHdocDef start="^\s*\(--\)\?\s*\[" end="\]" contained contains=hsHdocSpecial
-
-syn region  hsHdocLines start="--\s*\([$\^|]\|\*\+\)" 
-                      \ skip="^\s*\(--.*\)$" 
-                      \ end="^\s*\(\$\|--\)\@!" 
-                      \ contains=@hsHdocSpecial,hsHdocLTracks,hsHdocLHeading,hsHdocLCodeBlock,hsHdocDef
-syn region  hsHdocBlock start="{-\s*\([$\^|]\|\*\+\)" end="-}" 
-                      \ contains=@hsHdocSpecial,hsHdocBTracks,hsHdocBHeading,hsHdocBCodeBlock,hsHdocDef
-
-syn sync minlines=20
-
-if version >= 508 || !exists("did_haddock_syntax_inits")
-  if version < 508
-    let did_haddock_syntax_inits = 1
-    command -nargs=+ HiLink hi link <args>
-  else
-    command -nargs=+ HiLink hi def link <args>
-  endif
-
-  HiLink hsHdocLines            hsHdoc
-  HiLink hsHdocBlock            hsHdoc
-  HiLink hsHdoc                 PreProc
-  HiLink hsHdocAnchor           Special
-  HiLink hsHdocChunk            Special
-  HiLink hsHdocMod              Special
-  HiLink hsHdocLink             Special
-  HiLink hsHdocEm               Special
-  HiLink hsHdocURL              Special
-  HiLink hsHdocCode             Special
-  HiLink hsHdocLHeading         Special
-  HiLink hsHdocBHeading         Special
-  HiLink hsHdocLTracks          Special
-  HiLink hsHdocBTracks          Special
-  HiLink hsHdocBCodeBlock       Special
-  HiLink hsHdocLCodeBlock       Special
-  HiLink hsHdocSpecial          Special
-
-  delcommand HiLink                       
-endif
-
-" Options for vi: sw=2 sts=2 nowrap ft=vim
diff --git a/hoogle-test/Main.hs b/hoogle-test/Main.hs
new file mode 100644
--- /dev/null
+++ b/hoogle-test/Main.hs
@@ -0,0 +1,34 @@
+{-# LANGUAGE CPP #-}
+
+
+import Data.Function
+import System.Environment
+import System.FilePath
+
+import Test.Haddock
+import Test.Haddock.Utils
+
+
+checkConfig :: CheckConfig String
+checkConfig = CheckConfig
+    { ccfgRead = Just
+    , ccfgClean = \_ -> id
+    , ccfgDump = id
+    , ccfgEqual = (==) `on` crlfToLf
+    }
+
+
+dirConfig :: DirConfig
+dirConfig = defaultDirConfig $ takeDirectory __FILE__
+
+
+main :: IO ()
+main = do
+    cfg <- parseArgs checkConfig dirConfig =<< getArgs
+    runAndCheck $ cfg
+        { cfgHaddockArgs = cfgHaddockArgs cfg ++
+            [ "--package-name=test"
+            , "--package-version=0.0.0"
+            , "--hoogle"
+            ]
+        }
diff --git a/hoogle-test/ref/Bug722/test.txt b/hoogle-test/ref/Bug722/test.txt
new file mode 100644
--- /dev/null
+++ b/hoogle-test/ref/Bug722/test.txt
@@ -0,0 +1,16 @@
+-- Hoogle documentation, generated by Haddock
+-- See Hoogle, http://www.haskell.org/hoogle/
+
+@package test
+@version 0.0.0
+
+module Bug722
+class Foo a
+(!@#) :: Foo a => a -> a -> a
+infixl 4 !@#
+type family (&*) :: * -> * -> *
+infixr 3 &*
+data a :-& b
+(:^&) :: a -> b -> (:-&) a b
+infixl 6 :-&
+infixl 6 :^&
diff --git a/hoogle-test/ref/Bug806/test.txt b/hoogle-test/ref/Bug806/test.txt
new file mode 100644
--- /dev/null
+++ b/hoogle-test/ref/Bug806/test.txt
@@ -0,0 +1,25 @@
+-- Hoogle documentation, generated by Haddock
+-- See Hoogle, http://www.haskell.org/hoogle/
+
+@package test
+@version 0.0.0
+
+module Bug806
+
+-- | <a>F1</a> docs
+type family F1 a b :: * -> *
+
+-- | <a>F2</a> docs
+type family F2 a b :: * -> *
+
+-- | <a>D</a> docs
+data family D a :: * -> *
+v :: Int
+
+-- | <a>C</a> docs
+class C a where {
+    
+    -- | <a>AT</a> docs
+    type AT a;
+    type AT a = Proxy (Proxy (Proxy (Proxy (Proxy (Proxy (Proxy (Proxy (Proxy (Proxy)))))))));
+}
diff --git a/hoogle-test/ref/Bug825/test.txt b/hoogle-test/ref/Bug825/test.txt
new file mode 100644
--- /dev/null
+++ b/hoogle-test/ref/Bug825/test.txt
@@ -0,0 +1,9 @@
+-- Hoogle documentation, generated by Haddock
+-- See Hoogle, http://www.haskell.org/hoogle/
+
+@package test
+@version 0.0.0
+
+module Bug825
+data a :~: b
+data (:~~:) a b
diff --git a/hoogle-test/ref/Bug946/test.txt b/hoogle-test/ref/Bug946/test.txt
new file mode 100644
--- /dev/null
+++ b/hoogle-test/ref/Bug946/test.txt
@@ -0,0 +1,19 @@
+-- Hoogle documentation, generated by Haddock
+-- See Hoogle, http://www.haskell.org/hoogle/
+
+@package test
+@version 0.0.0
+
+module Bug946
+
+-- | A wrapper around <a>Int</a>
+data AnInt
+
+-- | some <a>Int</a>
+AnInt :: Int -> AnInt
+
+-- | The <a>Int</a> 0
+pattern Zero :: AnInt
+
+-- | The double 2.5
+pattern TwoPointFive :: Double
diff --git a/hoogle-test/ref/Bug992/test.txt b/hoogle-test/ref/Bug992/test.txt
new file mode 100644
--- /dev/null
+++ b/hoogle-test/ref/Bug992/test.txt
@@ -0,0 +1,9 @@
+-- Hoogle documentation, generated by Haddock
+-- See Hoogle, http://www.haskell.org/hoogle/
+
+@package test
+@version 0.0.0
+
+module Bug992
+data K (m :: * -> *)
+K :: K (m :: * -> *)
diff --git a/hoogle-test/ref/assoc-types/test.txt b/hoogle-test/ref/assoc-types/test.txt
new file mode 100644
--- /dev/null
+++ b/hoogle-test/ref/assoc-types/test.txt
@@ -0,0 +1,14 @@
+-- Hoogle documentation, generated by Haddock
+-- See Hoogle, http://www.haskell.org/hoogle/
+
+@package test
+@version 0.0.0
+
+module AssocTypes
+class Foo a where {
+    type Bar a b;
+    type Baz a;
+    type Baz a = [(a, a)];
+}
+bar :: Foo a => Bar a a
+instance AssocTypes.Foo [a]
diff --git a/hoogle-test/ref/classes/test.txt b/hoogle-test/ref/classes/test.txt
new file mode 100644
--- /dev/null
+++ b/hoogle-test/ref/classes/test.txt
@@ -0,0 +1,17 @@
+-- Hoogle documentation, generated by Haddock
+-- See Hoogle, http://www.haskell.org/hoogle/
+
+@package test
+@version 0.0.0
+
+module Classes
+class Foo f
+bar :: Foo f => f a -> f b -> f (a, b)
+baz :: Foo f => f ()
+class Quux q
+(+++) :: Quux q => q -> q -> q
+(///) :: Quux q => q -> q -> q
+(***) :: Quux q => q -> q -> q
+logBase :: Quux q => q -> q -> q
+foo :: Quux q => q -> q -> q
+quux :: Quux q => q -> q -> q
diff --git a/hoogle-test/ref/fixity/test.txt b/hoogle-test/ref/fixity/test.txt
new file mode 100644
--- /dev/null
+++ b/hoogle-test/ref/fixity/test.txt
@@ -0,0 +1,13 @@
+-- Hoogle documentation, generated by Haddock
+-- See Hoogle, http://www.haskell.org/hoogle/
+
+@package test
+@version 0.0.0
+
+module Fixity
+(+++) :: a -> a -> a
+infix 6 +++
+(***) :: a -> a -> a
+infixl 7 ***
+(///) :: a -> a -> a
+infixr 8 ///
diff --git a/hoogle-test/ref/modules/test.txt b/hoogle-test/ref/modules/test.txt
new file mode 100644
--- /dev/null
+++ b/hoogle-test/ref/modules/test.txt
@@ -0,0 +1,13 @@
+-- Hoogle documentation, generated by Haddock
+-- See Hoogle, http://www.haskell.org/hoogle/
+
+@package test
+@version 0.0.0
+
+module Foo
+foo :: Int -> Int
+foo' :: Int -> Int -> Int
+
+module Bar
+bar :: Int -> Int
+bar' :: Int -> Int -> Int
diff --git a/hoogle-test/ref/type-sigs/test.txt b/hoogle-test/ref/type-sigs/test.txt
new file mode 100644
--- /dev/null
+++ b/hoogle-test/ref/type-sigs/test.txt
@@ -0,0 +1,16 @@
+-- Hoogle documentation, generated by Haddock
+-- See Hoogle, http://www.haskell.org/hoogle/
+
+@package test
+@version 0.0.0
+
+module ReaderT
+newtype ReaderT r m a
+ReaderT :: (r -> m a) -> ReaderT r m a
+[runReaderT] :: ReaderT r m a -> r -> m a
+
+module ReaderTReexport
+newtype ReaderT r m a
+ReaderT :: (r -> m a) -> ReaderT r m a
+[runReaderT] :: ReaderT r m a -> r -> m a
+runReaderT :: ReaderT r m a -> r -> m a
diff --git a/hoogle-test/src/Bug722/Bug722.hs b/hoogle-test/src/Bug722/Bug722.hs
new file mode 100644
--- /dev/null
+++ b/hoogle-test/src/Bug722/Bug722.hs
@@ -0,0 +1,14 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE TypeOperators, TypeFamilies #-}
+module Bug722 where
+
+class Foo a where
+  (!@#) :: a -> a -> a
+infixl 4 !@#
+
+type family (&*) :: * -> * -> *
+infixr 3 &*
+
+data a :-& b = a :^& b
+infixl 6 :-&, :^&
+
diff --git a/hoogle-test/src/Bug806/Bug806.hs b/hoogle-test/src/Bug806/Bug806.hs
new file mode 100644
--- /dev/null
+++ b/hoogle-test/src/Bug806/Bug806.hs
@@ -0,0 +1,24 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE TypeFamilies #-}
+{-# LANGUAGE UndecidableInstances #-}
+module Bug806 where
+
+import Data.Proxy
+
+-- | 'F1' docs
+type family F1 a b :: * -> *
+-- | 'F2' docs
+type family F2 a b :: * -> * where
+  F2 Int b = Maybe
+  F2 a   b = []
+-- | 'D' docs
+data family D a :: * -> *
+
+v :: Int
+v = 42
+
+-- | 'C' docs
+class C a where
+  -- | 'AT' docs
+  type AT a
+  type AT a = Proxy (Proxy (Proxy (Proxy (Proxy (Proxy (Proxy (Proxy (Proxy (Proxy)))))))))
diff --git a/hoogle-test/src/Bug825/Bug825.hs b/hoogle-test/src/Bug825/Bug825.hs
new file mode 100644
--- /dev/null
+++ b/hoogle-test/src/Bug825/Bug825.hs
@@ -0,0 +1,7 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE MultiParamTypeClasses #-}
+{-# LANGUAGE TypeOperators #-}
+module Bug825 where
+
+data a :~: b
+data (:~~:) a b
diff --git a/hoogle-test/src/Bug946/Bug946.hs b/hoogle-test/src/Bug946/Bug946.hs
new file mode 100644
--- /dev/null
+++ b/hoogle-test/src/Bug946/Bug946.hs
@@ -0,0 +1,17 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE PatternSynonyms #-}
+module Bug946 (
+  AnInt(AnInt, Zero),
+  pattern TwoPointFive,
+) where
+
+-- | A wrapper around 'Int'
+data AnInt = AnInt Int -- ^ some 'Int'
+
+-- | The 'Int' 0
+pattern Zero :: AnInt
+pattern Zero = AnInt 0
+
+-- | The double 2.5
+pattern TwoPointFive :: Double
+pattern TwoPointFive = 2.5
diff --git a/hoogle-test/src/Bug992/Bug992.hs b/hoogle-test/src/Bug992/Bug992.hs
new file mode 100644
--- /dev/null
+++ b/hoogle-test/src/Bug992/Bug992.hs
@@ -0,0 +1,6 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE KindSignatures #-}
+
+module Bug992 where
+
+data K (m :: * -> *) = K
diff --git a/hoogle-test/src/assoc-types/AssocTypes.hs b/hoogle-test/src/assoc-types/AssocTypes.hs
new file mode 100644
--- /dev/null
+++ b/hoogle-test/src/assoc-types/AssocTypes.hs
@@ -0,0 +1,25 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE TypeFamilies #-}
+{-# LANGUAGE AllowAmbiguousTypes #-}
+
+
+module AssocTypes where
+
+
+class Foo a where
+
+    type Bar a b
+    type Baz a
+
+    type Baz a = [(a, a)]
+
+    bar :: Bar a a
+    bar = undefined
+
+
+instance Foo [a] where
+
+    type Bar [a] Int = [(a, Bool)]
+    type Bar [a] Bool = [(Int, a)]
+
+    type Baz [a] = (a, a, a)
diff --git a/hoogle-test/src/classes/Classes.hs b/hoogle-test/src/classes/Classes.hs
new file mode 100644
--- /dev/null
+++ b/hoogle-test/src/classes/Classes.hs
@@ -0,0 +1,17 @@
+{-# LANGUAGE Haskell2010 #-}
+module Classes where
+
+
+class Foo f where
+
+    bar :: f a -> f b -> f (a, b)
+    baz :: f ()
+
+    baz = undefined
+
+
+class Quux q where
+
+    (+++), (///) :: q -> q -> q
+    (***), logBase :: q -> q -> q
+    foo, quux :: q -> q -> q
diff --git a/hoogle-test/src/fixity/Fixity.hs b/hoogle-test/src/fixity/Fixity.hs
new file mode 100644
--- /dev/null
+++ b/hoogle-test/src/fixity/Fixity.hs
@@ -0,0 +1,13 @@
+{-# LANGUAGE Haskell2010 #-}
+module Fixity where
+
+
+(+++), (***), (///) :: a -> a -> a
+(+++) = undefined
+(***) = undefined
+(///) = undefined
+
+
+infix 6 +++
+infixl 7 ***
+infixr 8 ///
diff --git a/hoogle-test/src/modules/Bar.hs b/hoogle-test/src/modules/Bar.hs
new file mode 100644
--- /dev/null
+++ b/hoogle-test/src/modules/Bar.hs
@@ -0,0 +1,13 @@
+{-# LANGUAGE Haskell2010 #-}
+module Bar where
+
+
+import Foo
+
+
+bar :: Int -> Int
+bar x = foo' x x
+
+
+bar' :: Int -> Int -> Int
+bar' x y = foo' (bar (foo x)) (bar (foo y))
diff --git a/hoogle-test/src/modules/Foo.hs b/hoogle-test/src/modules/Foo.hs
new file mode 100644
--- /dev/null
+++ b/hoogle-test/src/modules/Foo.hs
@@ -0,0 +1,10 @@
+{-# LANGUAGE Haskell2010 #-}
+module Foo where
+
+
+foo :: Int -> Int
+foo = (* 2)
+
+
+foo' :: Int -> Int -> Int
+foo' x y = foo x + foo y
diff --git a/hoogle-test/src/type-sigs/ReaderT.hs b/hoogle-test/src/type-sigs/ReaderT.hs
new file mode 100644
--- /dev/null
+++ b/hoogle-test/src/type-sigs/ReaderT.hs
@@ -0,0 +1,4 @@
+{-# LANGUAGE Haskell2010 #-}
+module ReaderT where
+
+newtype ReaderT r m a = ReaderT { runReaderT :: r -> m a }
diff --git a/hoogle-test/src/type-sigs/ReaderTReexport.hs b/hoogle-test/src/type-sigs/ReaderTReexport.hs
new file mode 100644
--- /dev/null
+++ b/hoogle-test/src/type-sigs/ReaderTReexport.hs
@@ -0,0 +1,4 @@
+{-# LANGUAGE Haskell2010 #-}
+module ReaderTReexport (ReaderT(..), runReaderT) where
+
+import ReaderT
diff --git a/html-test/Main.hs b/html-test/Main.hs
new file mode 100644
--- /dev/null
+++ b/html-test/Main.hs
@@ -0,0 +1,62 @@
+{-# LANGUAGE CPP #-}
+
+
+import Data.Char
+import Data.Function (on)
+
+import System.Environment
+import System.FilePath
+
+import Test.Haddock
+import Test.Haddock.Xhtml
+
+
+checkConfig :: CheckConfig Xml
+checkConfig = CheckConfig
+    { ccfgRead = parseXml
+    , ccfgClean = stripIfRequired
+    , ccfgDump = dumpXml
+    , ccfgEqual = (==) `on` dumpXml
+    }
+
+
+dirConfig :: DirConfig
+dirConfig = (defaultDirConfig $ takeDirectory __FILE__)
+    { dcfgCheckIgnore = checkIgnore
+    }
+
+
+main :: IO ()
+main = do
+    cfg <- parseArgs checkConfig dirConfig =<< getArgs
+    runAndCheck $ cfg
+        { cfgHaddockArgs = cfgHaddockArgs cfg ++ ["--pretty-html", "--html"]
+        }
+
+
+stripIfRequired :: String -> Xml -> Xml
+stripIfRequired mdl =
+    stripLinks' . stripFooter
+  where
+    stripLinks'
+        | mdl `elem` preserveLinksModules = id
+        | otherwise = stripLinks
+
+
+-- | List of modules in which we don't 'stripLinks'
+preserveLinksModules :: [String]
+preserveLinksModules = ["Bug253.html", "NamespacedIdentifiers.html"]
+
+ingoredTests :: [FilePath]
+ingoredTests =
+  [
+    -- Currently some declarations are exported twice
+    -- we need a reliable way to deduplicate here.
+    -- Happens since PR #688.
+    "B"
+  ]
+
+checkIgnore :: FilePath -> Bool
+checkIgnore file | takeBaseName file `elem` ingoredTests = True
+checkIgnore file@(c:_) | takeExtension file == ".html" && isUpper c = False
+checkIgnore _ = True
diff --git a/html-test/ref/A.html b/html-test/ref/A.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/A.html
@@ -0,0 +1,192 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >A</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>A</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > <a href="#"
+	      >A</a
+	      > = <a href="#"
+	      >A</a
+	      ></li
+	    ><li class="src short"
+	    ><a href="#"
+	      >other</a
+	      > :: <a href="#" title="Data.Int"
+	      >Int</a
+	      ></li
+	    ><li class="src short"
+	    ><a href="#"
+	      >test2</a
+	      > :: <a href="#" title="Data.Bool"
+	      >Bool</a
+	      ></li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > <a href="#"
+	      >X</a
+	      > = <a href="#"
+	      >X</a
+	      ></li
+	    ><li class="src short"
+	    ><a href="#"
+	      >reExport</a
+	      > :: <a href="#" title="Data.Int"
+	      >Int</a
+	      ></li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:A" class="def"
+	    >A</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:A" class="def"
+		  >A</a
+		  ></td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:other" class="def"
+	    >other</a
+	    > :: <a href="#" title="Data.Int"
+	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:test2" class="def"
+	    >test2</a
+	    > :: <a href="#" title="Data.Bool"
+	    >Bool</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Doc for test2</p
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:X" class="def"
+	    >X</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Should show up on the page for both modules A and B</p
+	    ></div
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:X" class="def"
+		  >X</a
+		  ></td
+		><td class="doc"
+		><p
+		  >Doc for consructor</p
+		  ></td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:reExport" class="def"
+	    >reExport</a
+	    > :: <a href="#" title="Data.Int"
+	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Should show up on the page for both modules A and B</p
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/B.html b/html-test/ref/B.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/B.html
@@ -0,0 +1,174 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >B</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      ></span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>B</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    >module <a href="#"
+	      >A</a
+	      ></li
+	    ><li class="src short"
+	    ><a href="#"
+	      >test</a
+	      > :: <a href="#"
+	      >Int</a
+	      ></li
+	    ><li class="src short"
+	    ><a href="#"
+	      >reExport</a
+	      > :: <a href="#"
+	      >Int</a
+	      ></li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > <a href="#"
+	      >X</a
+	      > = <a href="#"
+	      >X</a
+	      ></li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  >module <a href="#"
+	    >A</a
+	    ></p
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:test" class="def"
+	    >test</a
+	    > :: <a href="#"
+	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >This link shouldn't work: <code
+	      >other</code
+	      >.
+   These links should work: <code
+	      ><a href="#"
+		>other</a
+		></code
+	      >, <code
+	      ><a href="#"
+		>sortBy</a
+		></code
+	      >, <code
+	      ><a href="#"
+		>test2</a
+		></code
+	      >, <code
+	      ><a href="#"
+		>test2</a
+		></code
+	      >, <code
+	      ><a href="#"
+		>fromMaybe</a
+		></code
+	      >.
+   Module link: <a href="#"
+	      >Prelude</a
+	      >.</p
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:reExport" class="def"
+	    >reExport</a
+	    > :: <a href="#"
+	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Should show up on the page for both modules A and B</p
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:X" class="def"
+	    >X</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Should show up on the page for both modules A and B</p
+	    ></div
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:X" class="def"
+		  >X</a
+		  ></td
+		><td class="doc"
+		><p
+		  >Doc for consructor</p
+		  ></td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	></div
+      ></div
+    ><div id="footer"
+    ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Bold.html b/html-test/ref/Bold.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Bold.html
@@ -0,0 +1,104 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Bold</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Bold</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><a href="#"
+	      >foo</a
+	      > :: a</li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><a id="v:foo" class="def"
+	    >foo</a
+	    > :: a <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Some <strong
+	      >bold text</strong
+	      >.</p
+	    ><ul
+	    ><li
+	      ><strong
+		>Bold</strong
+		> in a list</li
+	      ></ul
+	    ><dl
+	    ><dt
+	      ><strong
+		>bold in a definition</strong
+		></dt
+	      ><dd
+	      >list</dd
+	      ></dl
+	    ><pre
+	    > bold <strong
+	      >in</strong
+	      > a <strong
+	      >code</strong
+	      > block</pre
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Bug1.html b/html-test/ref/Bug1.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Bug1.html
@@ -0,0 +1,107 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Bug1</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Bug1</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > <a href="#"
+	      >T</a
+	      > = <a href="#"
+	      >T</a
+	      ></li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:T" class="def"
+	    >T</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >We should have different anchors for constructors and types/classes.  This
+ hyperlink should point to the type constructor by default: <code
+	      ><a href="#" title="Bug1"
+		>T</a
+		></code
+	      >.</p
+	    ></div
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:T" class="def"
+		  >T</a
+		  ></td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Bug1004.html b/html-test/ref/Bug1004.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Bug1004.html
@@ -0,0 +1,2216 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Bug1004</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Bug1004</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > <a href="#"
+	      >Product</a
+	      > (f :: k -&gt; <a href="#" title="Data.Kind"
+	      >Type</a
+	      >) (g :: k -&gt; <a href="#" title="Data.Kind"
+	      >Type</a
+	      >) (a :: k) = <a href="#"
+	      >Pair</a
+	      > (f a) (g a)</li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:Product" class="def"
+	    >Product</a
+	    > (f :: k -&gt; <a href="#" title="Data.Kind"
+	    >Type</a
+	    >) (g :: k -&gt; <a href="#" title="Data.Kind"
+	    >Type</a
+	    >) (a :: k) <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Lifted product of functors.</p
+	    ></div
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:Pair" class="def"
+		  >Pair</a
+		  > (f a) (g a)</td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ></table
+	    ></div
+	  ><div class="subs instances"
+	  ><h4 class="instances details-toggle-control details-toggle" data-details-id="i:Product"
+	    >Instances</h4
+	    ><details id="i:Product" open="open"
+	    ><summary class="hide-when-js-enabled"
+	      >Instances details</summary
+	      ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:Product:Generic1:1"
+		      ></span
+		      > <a href="#" title="GHC.Generics"
+		      >Generic1</a
+		      > (<a href="#" title="Bug1004"
+		      >Product</a
+		      > f g :: k -&gt; <a href="#" title="Data.Kind"
+		      >Type</a
+		      >)</span
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:Product:Generic1:1"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Data.Functor.Product</a
+			></p
+		      > <div class="subs associated-types"
+		      ><p class="caption"
+			>Associated Types</p
+			><p class="src"
+			><span class="keyword"
+			  >type</span
+			  > <a href="#" title="GHC.Generics"
+			  >Rep1</a
+			  > (<a href="#" title="Bug1004"
+			  >Product</a
+			  > f g) :: k -&gt; <a href="#" title="Data.Kind"
+			  >Type</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >from1</a
+			  > :: <span class="keyword"
+			  >forall</span
+			  > (a :: k0). <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; <a href="#" title="GHC.Generics"
+			  >Rep1</a
+			  > (<a href="#" title="Bug1004"
+			  >Product</a
+			  > f g) a <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >to1</a
+			  > :: <span class="keyword"
+			  >forall</span
+			  > (a :: k0). <a href="#" title="GHC.Generics"
+			  >Rep1</a
+			  > (<a href="#" title="Bug1004"
+			  >Product</a
+			  > f g) a -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:Product:MonadFix:2"
+		      ></span
+		      > (<a href="#" title="Control.Monad.Fix"
+		      >MonadFix</a
+		      > f, <a href="#" title="Control.Monad.Fix"
+		      >MonadFix</a
+		      > g) =&gt; <a href="#" title="Control.Monad.Fix"
+		      >MonadFix</a
+		      > (<a href="#" title="Bug1004"
+		      >Product</a
+		      > f g)</span
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    ><em
+		      >Since: base-4.9.0.0</em
+		      ></p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:Product:MonadFix:2"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Data.Functor.Product</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >mfix</a
+			  > :: (a -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a) -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:Product:MonadZip:3"
+		      ></span
+		      > (<a href="#" title="Control.Monad.Zip"
+		      >MonadZip</a
+		      > f, <a href="#" title="Control.Monad.Zip"
+		      >MonadZip</a
+		      > g) =&gt; <a href="#" title="Control.Monad.Zip"
+		      >MonadZip</a
+		      > (<a href="#" title="Bug1004"
+		      >Product</a
+		      > f g)</span
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    ><em
+		      >Since: base-4.9.0.0</em
+		      ></p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:Product:MonadZip:3"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Data.Functor.Product</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >mzip</a
+			  > :: <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g b -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g (a, b) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >mzipWith</a
+			  > :: (a -&gt; b -&gt; c) -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g b -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g c <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >munzip</a
+			  > :: <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g (a, b) -&gt; (<a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a, <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g b) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:Product:Foldable:4"
+		      ></span
+		      > (<a href="#" title="Data.Foldable"
+		      >Foldable</a
+		      > f, <a href="#" title="Data.Foldable"
+		      >Foldable</a
+		      > g) =&gt; <a href="#" title="Data.Foldable"
+		      >Foldable</a
+		      > (<a href="#" title="Bug1004"
+		      >Product</a
+		      > f g)</span
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    ><em
+		      >Since: base-4.9.0.0</em
+		      ></p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:Product:Foldable:4"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Data.Functor.Product</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >fold</a
+			  > :: <a href="#" title="Data.Monoid"
+			  >Monoid</a
+			  > m =&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g m -&gt; m <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >foldMap</a
+			  > :: <a href="#" title="Data.Monoid"
+			  >Monoid</a
+			  > m =&gt; (a -&gt; m) -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; m <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >foldMap'</a
+			  > :: <a href="#" title="Data.Monoid"
+			  >Monoid</a
+			  > m =&gt; (a -&gt; m) -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; m <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >foldr</a
+			  > :: (a -&gt; b -&gt; b) -&gt; b -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; b <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >foldr'</a
+			  > :: (a -&gt; b -&gt; b) -&gt; b -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; b <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >foldl</a
+			  > :: (b -&gt; a -&gt; b) -&gt; b -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; b <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >foldl'</a
+			  > :: (b -&gt; a -&gt; b) -&gt; b -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; b <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >foldr1</a
+			  > :: (a -&gt; a -&gt; a) -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; a <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >foldl1</a
+			  > :: (a -&gt; a -&gt; a) -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; a <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >toList</a
+			  > :: <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; [a] <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >null</a
+			  > :: <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; <a href="#" title="Data.Bool"
+			  >Bool</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >length</a
+			  > :: <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; <a href="#" title="Data.Int"
+			  >Int</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >elem</a
+			  > :: <a href="#" title="Data.Eq"
+			  >Eq</a
+			  > a =&gt; a -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; <a href="#" title="Data.Bool"
+			  >Bool</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >maximum</a
+			  > :: <a href="#" title="Data.Ord"
+			  >Ord</a
+			  > a =&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; a <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >minimum</a
+			  > :: <a href="#" title="Data.Ord"
+			  >Ord</a
+			  > a =&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; a <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >sum</a
+			  > :: <a href="#" title="Prelude"
+			  >Num</a
+			  > a =&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; a <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >product</a
+			  > :: <a href="#" title="Prelude"
+			  >Num</a
+			  > a =&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; a <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:Product:Eq1:5"
+		      ></span
+		      > (<a href="#" title="Data.Functor.Classes"
+		      >Eq1</a
+		      > f, <a href="#" title="Data.Functor.Classes"
+		      >Eq1</a
+		      > g) =&gt; <a href="#" title="Data.Functor.Classes"
+		      >Eq1</a
+		      > (<a href="#" title="Bug1004"
+		      >Product</a
+		      > f g)</span
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    ><em
+		      >Since: base-4.9.0.0</em
+		      ></p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:Product:Eq1:5"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Data.Functor.Product</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >liftEq</a
+			  > :: (a -&gt; b -&gt; <a href="#" title="Data.Bool"
+			  >Bool</a
+			  >) -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g b -&gt; <a href="#" title="Data.Bool"
+			  >Bool</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:Product:Ord1:6"
+		      ></span
+		      > (<a href="#" title="Data.Functor.Classes"
+		      >Ord1</a
+		      > f, <a href="#" title="Data.Functor.Classes"
+		      >Ord1</a
+		      > g) =&gt; <a href="#" title="Data.Functor.Classes"
+		      >Ord1</a
+		      > (<a href="#" title="Bug1004"
+		      >Product</a
+		      > f g)</span
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    ><em
+		      >Since: base-4.9.0.0</em
+		      ></p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:Product:Ord1:6"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Data.Functor.Product</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >liftCompare</a
+			  > :: (a -&gt; b -&gt; <a href="#" title="Data.Ord"
+			  >Ordering</a
+			  >) -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g b -&gt; <a href="#" title="Data.Ord"
+			  >Ordering</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:Product:Read1:7"
+		      ></span
+		      > (<a href="#" title="Data.Functor.Classes"
+		      >Read1</a
+		      > f, <a href="#" title="Data.Functor.Classes"
+		      >Read1</a
+		      > g) =&gt; <a href="#" title="Data.Functor.Classes"
+		      >Read1</a
+		      > (<a href="#" title="Bug1004"
+		      >Product</a
+		      > f g)</span
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    ><em
+		      >Since: base-4.9.0.0</em
+		      ></p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:Product:Read1:7"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Data.Functor.Product</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >liftReadsPrec</a
+			  > :: (<a href="#" title="Data.Int"
+			  >Int</a
+			  > -&gt; <a href="#" title="Text.ParserCombinators.ReadP"
+			  >ReadS</a
+			  > a) -&gt; <a href="#" title="Text.ParserCombinators.ReadP"
+			  >ReadS</a
+			  > [a] -&gt; <a href="#" title="Data.Int"
+			  >Int</a
+			  > -&gt; <a href="#" title="Text.ParserCombinators.ReadP"
+			  >ReadS</a
+			  > (<a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >liftReadList</a
+			  > :: (<a href="#" title="Data.Int"
+			  >Int</a
+			  > -&gt; <a href="#" title="Text.ParserCombinators.ReadP"
+			  >ReadS</a
+			  > a) -&gt; <a href="#" title="Text.ParserCombinators.ReadP"
+			  >ReadS</a
+			  > [a] -&gt; <a href="#" title="Text.ParserCombinators.ReadP"
+			  >ReadS</a
+			  > [<a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a] <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >liftReadPrec</a
+			  > :: <a href="#" title="Text.ParserCombinators.ReadPrec"
+			  >ReadPrec</a
+			  > a -&gt; <a href="#" title="Text.ParserCombinators.ReadPrec"
+			  >ReadPrec</a
+			  > [a] -&gt; <a href="#" title="Text.ParserCombinators.ReadPrec"
+			  >ReadPrec</a
+			  > (<a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >liftReadListPrec</a
+			  > :: <a href="#" title="Text.ParserCombinators.ReadPrec"
+			  >ReadPrec</a
+			  > a -&gt; <a href="#" title="Text.ParserCombinators.ReadPrec"
+			  >ReadPrec</a
+			  > [a] -&gt; <a href="#" title="Text.ParserCombinators.ReadPrec"
+			  >ReadPrec</a
+			  > [<a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a] <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:Product:Show1:8"
+		      ></span
+		      > (<a href="#" title="Data.Functor.Classes"
+		      >Show1</a
+		      > f, <a href="#" title="Data.Functor.Classes"
+		      >Show1</a
+		      > g) =&gt; <a href="#" title="Data.Functor.Classes"
+		      >Show1</a
+		      > (<a href="#" title="Bug1004"
+		      >Product</a
+		      > f g)</span
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    ><em
+		      >Since: base-4.9.0.0</em
+		      ></p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:Product:Show1:8"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Data.Functor.Product</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >liftShowsPrec</a
+			  > :: (<a href="#" title="Data.Int"
+			  >Int</a
+			  > -&gt; a -&gt; <a href="#" title="Text.Show"
+			  >ShowS</a
+			  >) -&gt; ([a] -&gt; <a href="#" title="Text.Show"
+			  >ShowS</a
+			  >) -&gt; <a href="#" title="Data.Int"
+			  >Int</a
+			  > -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; <a href="#" title="Text.Show"
+			  >ShowS</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >liftShowList</a
+			  > :: (<a href="#" title="Data.Int"
+			  >Int</a
+			  > -&gt; a -&gt; <a href="#" title="Text.Show"
+			  >ShowS</a
+			  >) -&gt; ([a] -&gt; <a href="#" title="Text.Show"
+			  >ShowS</a
+			  >) -&gt; [<a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a] -&gt; <a href="#" title="Text.Show"
+			  >ShowS</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:Product:Traversable:9"
+		      ></span
+		      > (<a href="#" title="Data.Traversable"
+		      >Traversable</a
+		      > f, <a href="#" title="Data.Traversable"
+		      >Traversable</a
+		      > g) =&gt; <a href="#" title="Data.Traversable"
+		      >Traversable</a
+		      > (<a href="#" title="Bug1004"
+		      >Product</a
+		      > f g)</span
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    ><em
+		      >Since: base-4.9.0.0</em
+		      ></p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:Product:Traversable:9"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Data.Functor.Product</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >traverse</a
+			  > :: <a href="#" title="Control.Applicative"
+			  >Applicative</a
+			  > f0 =&gt; (a -&gt; f0 b) -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; f0 (<a href="#" title="Bug1004"
+			  >Product</a
+			  > f g b) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >sequenceA</a
+			  > :: <a href="#" title="Control.Applicative"
+			  >Applicative</a
+			  > f0 =&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g (f0 a) -&gt; f0 (<a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >mapM</a
+			  > :: <a href="#" title="Control.Monad"
+			  >Monad</a
+			  > m =&gt; (a -&gt; m b) -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; m (<a href="#" title="Bug1004"
+			  >Product</a
+			  > f g b) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >sequence</a
+			  > :: <a href="#" title="Control.Monad"
+			  >Monad</a
+			  > m =&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g (m a) -&gt; m (<a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:Product:Alternative:10"
+		      ></span
+		      > (<a href="#" title="Control.Applicative"
+		      >Alternative</a
+		      > f, <a href="#" title="Control.Applicative"
+		      >Alternative</a
+		      > g) =&gt; <a href="#" title="Control.Applicative"
+		      >Alternative</a
+		      > (<a href="#" title="Bug1004"
+		      >Product</a
+		      > f g)</span
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    ><em
+		      >Since: base-4.9.0.0</em
+		      ></p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:Product:Alternative:10"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Data.Functor.Product</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >empty</a
+			  > :: <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >(&lt;|&gt;)</a
+			  > :: <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >some</a
+			  > :: <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g [a] <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >many</a
+			  > :: <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g [a] <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:Product:Applicative:11"
+		      ></span
+		      > (<a href="#" title="Control.Applicative"
+		      >Applicative</a
+		      > f, <a href="#" title="Control.Applicative"
+		      >Applicative</a
+		      > g) =&gt; <a href="#" title="Control.Applicative"
+		      >Applicative</a
+		      > (<a href="#" title="Bug1004"
+		      >Product</a
+		      > f g)</span
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    ><em
+		      >Since: base-4.9.0.0</em
+		      ></p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:Product:Applicative:11"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Data.Functor.Product</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >pure</a
+			  > :: a -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >(&lt;*&gt;)</a
+			  > :: <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g (a -&gt; b) -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g b <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >liftA2</a
+			  > :: (a -&gt; b -&gt; c) -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g b -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g c <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >(*&gt;)</a
+			  > :: <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g b -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g b <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >(&lt;*)</a
+			  > :: <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g b -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:Product:Functor:12"
+		      ></span
+		      > (<a href="#" title="Data.Functor"
+		      >Functor</a
+		      > f, <a href="#" title="Data.Functor"
+		      >Functor</a
+		      > g) =&gt; <a href="#" title="Data.Functor"
+		      >Functor</a
+		      > (<a href="#" title="Bug1004"
+		      >Product</a
+		      > f g)</span
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    ><em
+		      >Since: base-4.9.0.0</em
+		      ></p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:Product:Functor:12"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Data.Functor.Product</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >fmap</a
+			  > :: (a -&gt; b) -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g b <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >(&lt;$)</a
+			  > :: a -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g b -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:Product:Monad:13"
+		      ></span
+		      > (<a href="#" title="Control.Monad"
+		      >Monad</a
+		      > f, <a href="#" title="Control.Monad"
+		      >Monad</a
+		      > g) =&gt; <a href="#" title="Control.Monad"
+		      >Monad</a
+		      > (<a href="#" title="Bug1004"
+		      >Product</a
+		      > f g)</span
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    ><em
+		      >Since: base-4.9.0.0</em
+		      ></p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:Product:Monad:13"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Data.Functor.Product</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >(&gt;&gt;=)</a
+			  > :: <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; (a -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g b) -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g b <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >(&gt;&gt;)</a
+			  > :: <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g b -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g b <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >return</a
+			  > :: a -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:Product:MonadPlus:14"
+		      ></span
+		      > (<a href="#" title="Control.Monad"
+		      >MonadPlus</a
+		      > f, <a href="#" title="Control.Monad"
+		      >MonadPlus</a
+		      > g) =&gt; <a href="#" title="Control.Monad"
+		      >MonadPlus</a
+		      > (<a href="#" title="Bug1004"
+		      >Product</a
+		      > f g)</span
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    ><em
+		      >Since: base-4.9.0.0</em
+		      ></p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:Product:MonadPlus:14"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Data.Functor.Product</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >mzero</a
+			  > :: <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >mplus</a
+			  > :: <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:Product:Data:15"
+		      ></span
+		      > (<a href="#" title="Type.Reflection"
+		      >Typeable</a
+		      > a, <a href="#" title="Type.Reflection"
+		      >Typeable</a
+		      > f, <a href="#" title="Type.Reflection"
+		      >Typeable</a
+		      > g, <a href="#" title="Type.Reflection"
+		      >Typeable</a
+		      > k, <a href="#" title="Data.Data"
+		      >Data</a
+		      > (f a), <a href="#" title="Data.Data"
+		      >Data</a
+		      > (g a)) =&gt; <a href="#" title="Data.Data"
+		      >Data</a
+		      > (<a href="#" title="Bug1004"
+		      >Product</a
+		      > f g a)</span
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    ><em
+		      >Since: base-4.9.0.0</em
+		      ></p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:Product:Data:15"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Data.Functor.Product</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >gfoldl</a
+			  > :: (<span class="keyword"
+			  >forall</span
+			  > d b. <a href="#" title="Data.Data"
+			  >Data</a
+			  > d =&gt; c (d -&gt; b) -&gt; d -&gt; c b) -&gt; (<span class="keyword"
+			  >forall</span
+			  > g0. g0 -&gt; c g0) -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; c (<a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >gunfold</a
+			  > :: (<span class="keyword"
+			  >forall</span
+			  > b r. <a href="#" title="Data.Data"
+			  >Data</a
+			  > b =&gt; c (b -&gt; r) -&gt; c r) -&gt; (<span class="keyword"
+			  >forall</span
+			  > r. r -&gt; c r) -&gt; <a href="#" title="Data.Data"
+			  >Constr</a
+			  > -&gt; c (<a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >toConstr</a
+			  > :: <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; <a href="#" title="Data.Data"
+			  >Constr</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >dataTypeOf</a
+			  > :: <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; <a href="#" title="Data.Data"
+			  >DataType</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >dataCast1</a
+			  > :: <a href="#" title="Type.Reflection"
+			  >Typeable</a
+			  > t =&gt; (<span class="keyword"
+			  >forall</span
+			  > d. <a href="#" title="Data.Data"
+			  >Data</a
+			  > d =&gt; c (t d)) -&gt; <a href="#" title="Data.Maybe"
+			  >Maybe</a
+			  > (c (<a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a)) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >dataCast2</a
+			  > :: <a href="#" title="Type.Reflection"
+			  >Typeable</a
+			  > t =&gt; (<span class="keyword"
+			  >forall</span
+			  > d e. (<a href="#" title="Data.Data"
+			  >Data</a
+			  > d, <a href="#" title="Data.Data"
+			  >Data</a
+			  > e) =&gt; c (t d e)) -&gt; <a href="#" title="Data.Maybe"
+			  >Maybe</a
+			  > (c (<a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a)) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >gmapT</a
+			  > :: (<span class="keyword"
+			  >forall</span
+			  > b. <a href="#" title="Data.Data"
+			  >Data</a
+			  > b =&gt; b -&gt; b) -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >gmapQl</a
+			  > :: (r -&gt; r' -&gt; r) -&gt; r -&gt; (<span class="keyword"
+			  >forall</span
+			  > d. <a href="#" title="Data.Data"
+			  >Data</a
+			  > d =&gt; d -&gt; r') -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; r <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >gmapQr</a
+			  > :: <span class="keyword"
+			  >forall</span
+			  > r r'. (r' -&gt; r -&gt; r) -&gt; r -&gt; (<span class="keyword"
+			  >forall</span
+			  > d. <a href="#" title="Data.Data"
+			  >Data</a
+			  > d =&gt; d -&gt; r') -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; r <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >gmapQ</a
+			  > :: (<span class="keyword"
+			  >forall</span
+			  > d. <a href="#" title="Data.Data"
+			  >Data</a
+			  > d =&gt; d -&gt; u) -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; [u] <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >gmapQi</a
+			  > :: <a href="#" title="Data.Int"
+			  >Int</a
+			  > -&gt; (<span class="keyword"
+			  >forall</span
+			  > d. <a href="#" title="Data.Data"
+			  >Data</a
+			  > d =&gt; d -&gt; u) -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; u <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >gmapM</a
+			  > :: <a href="#" title="Control.Monad"
+			  >Monad</a
+			  > m =&gt; (<span class="keyword"
+			  >forall</span
+			  > d. <a href="#" title="Data.Data"
+			  >Data</a
+			  > d =&gt; d -&gt; m d) -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; m (<a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >gmapMp</a
+			  > :: <a href="#" title="Control.Monad"
+			  >MonadPlus</a
+			  > m =&gt; (<span class="keyword"
+			  >forall</span
+			  > d. <a href="#" title="Data.Data"
+			  >Data</a
+			  > d =&gt; d -&gt; m d) -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; m (<a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >gmapMo</a
+			  > :: <a href="#" title="Control.Monad"
+			  >MonadPlus</a
+			  > m =&gt; (<span class="keyword"
+			  >forall</span
+			  > d. <a href="#" title="Data.Data"
+			  >Data</a
+			  > d =&gt; d -&gt; m d) -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; m (<a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:Product:Monoid:16"
+		      ></span
+		      > (<a href="#" title="Data.Monoid"
+		      >Monoid</a
+		      > (f a), <a href="#" title="Data.Monoid"
+		      >Monoid</a
+		      > (g a)) =&gt; <a href="#" title="Data.Monoid"
+		      >Monoid</a
+		      > (<a href="#" title="Bug1004"
+		      >Product</a
+		      > f g a)</span
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    ><em
+		      >Since: base-4.16.0.0</em
+		      ></p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:Product:Monoid:16"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Data.Functor.Product</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >mempty</a
+			  > :: <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >mappend</a
+			  > :: <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >mconcat</a
+			  > :: [<a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a] -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:Product:Semigroup:17"
+		      ></span
+		      > (<a href="#" title="Prelude"
+		      >Semigroup</a
+		      > (f a), <a href="#" title="Prelude"
+		      >Semigroup</a
+		      > (g a)) =&gt; <a href="#" title="Prelude"
+		      >Semigroup</a
+		      > (<a href="#" title="Bug1004"
+		      >Product</a
+		      > f g a)</span
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    ><em
+		      >Since: base-4.16.0.0</em
+		      ></p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:Product:Semigroup:17"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Data.Functor.Product</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >(&lt;&gt;)</a
+			  > :: <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >sconcat</a
+			  > :: <a href="#" title="Data.List.NonEmpty"
+			  >NonEmpty</a
+			  > (<a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a) -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >stimes</a
+			  > :: <a href="#" title="Prelude"
+			  >Integral</a
+			  > b =&gt; b -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:Product:Generic:18"
+		      ></span
+		      > <a href="#" title="GHC.Generics"
+		      >Generic</a
+		      > (<a href="#" title="Bug1004"
+		      >Product</a
+		      > f g a)</span
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:Product:Generic:18"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Data.Functor.Product</a
+			></p
+		      > <div class="subs associated-types"
+		      ><p class="caption"
+			>Associated Types</p
+			><p class="src"
+			><span class="keyword"
+			  >type</span
+			  > <a href="#" title="GHC.Generics"
+			  >Rep</a
+			  > (<a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a) :: <a href="#" title="Data.Kind"
+			  >Type</a
+			  > -&gt; <a href="#" title="Data.Kind"
+			  >Type</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >from</a
+			  > :: <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; <a href="#" title="GHC.Generics"
+			  >Rep</a
+			  > (<a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a) x <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >to</a
+			  > :: <a href="#" title="GHC.Generics"
+			  >Rep</a
+			  > (<a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a) x -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:Product:Read:19"
+		      ></span
+		      > (<a href="#" title="Text.Read"
+		      >Read</a
+		      > (f a), <a href="#" title="Text.Read"
+		      >Read</a
+		      > (g a)) =&gt; <a href="#" title="Text.Read"
+		      >Read</a
+		      > (<a href="#" title="Bug1004"
+		      >Product</a
+		      > f g a)</span
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    ><em
+		      >Since: base-4.18.0.0</em
+		      ></p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:Product:Read:19"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Data.Functor.Product</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >readsPrec</a
+			  > :: <a href="#" title="Data.Int"
+			  >Int</a
+			  > -&gt; <a href="#" title="Text.ParserCombinators.ReadP"
+			  >ReadS</a
+			  > (<a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >readList</a
+			  > :: <a href="#" title="Text.ParserCombinators.ReadP"
+			  >ReadS</a
+			  > [<a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a] <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >readPrec</a
+			  > :: <a href="#" title="Text.ParserCombinators.ReadPrec"
+			  >ReadPrec</a
+			  > (<a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >readListPrec</a
+			  > :: <a href="#" title="Text.ParserCombinators.ReadPrec"
+			  >ReadPrec</a
+			  > [<a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a] <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:Product:Show:20"
+		      ></span
+		      > (<a href="#" title="Text.Show"
+		      >Show</a
+		      > (f a), <a href="#" title="Text.Show"
+		      >Show</a
+		      > (g a)) =&gt; <a href="#" title="Text.Show"
+		      >Show</a
+		      > (<a href="#" title="Bug1004"
+		      >Product</a
+		      > f g a)</span
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    ><em
+		      >Since: base-4.18.0.0</em
+		      ></p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:Product:Show:20"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Data.Functor.Product</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >showsPrec</a
+			  > :: <a href="#" title="Data.Int"
+			  >Int</a
+			  > -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; <a href="#" title="Text.Show"
+			  >ShowS</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >show</a
+			  > :: <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; <a href="#" title="Data.String"
+			  >String</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >showList</a
+			  > :: [<a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a] -&gt; <a href="#" title="Text.Show"
+			  >ShowS</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:Product:Eq:21"
+		      ></span
+		      > (<a href="#" title="Data.Eq"
+		      >Eq</a
+		      > (f a), <a href="#" title="Data.Eq"
+		      >Eq</a
+		      > (g a)) =&gt; <a href="#" title="Data.Eq"
+		      >Eq</a
+		      > (<a href="#" title="Bug1004"
+		      >Product</a
+		      > f g a)</span
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    ><em
+		      >Since: base-4.18.0.0</em
+		      ></p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:Product:Eq:21"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Data.Functor.Product</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >(==)</a
+			  > :: <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; <a href="#" title="Data.Bool"
+			  >Bool</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >(/=)</a
+			  > :: <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; <a href="#" title="Data.Bool"
+			  >Bool</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:Product:Ord:22"
+		      ></span
+		      > (<a href="#" title="Data.Ord"
+		      >Ord</a
+		      > (f a), <a href="#" title="Data.Ord"
+		      >Ord</a
+		      > (g a)) =&gt; <a href="#" title="Data.Ord"
+		      >Ord</a
+		      > (<a href="#" title="Bug1004"
+		      >Product</a
+		      > f g a)</span
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    ><em
+		      >Since: base-4.18.0.0</em
+		      ></p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:Product:Ord:22"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Data.Functor.Product</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >compare</a
+			  > :: <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; <a href="#" title="Data.Ord"
+			  >Ordering</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >(&lt;)</a
+			  > :: <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; <a href="#" title="Data.Bool"
+			  >Bool</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >(&lt;=)</a
+			  > :: <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; <a href="#" title="Data.Bool"
+			  >Bool</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >(&gt;)</a
+			  > :: <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; <a href="#" title="Data.Bool"
+			  >Bool</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >(&gt;=)</a
+			  > :: <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; <a href="#" title="Data.Bool"
+			  >Bool</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >max</a
+			  > :: <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >min</a
+			  > :: <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a -&gt; <a href="#" title="Bug1004"
+			  >Product</a
+			  > f g a <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:Product:Rep1:23"
+		      ></span
+		      > <span class="keyword"
+		      >type</span
+		      > <a href="#" title="GHC.Generics"
+		      >Rep1</a
+		      > (<a href="#" title="Bug1004"
+		      >Product</a
+		      > f g :: k -&gt; <a href="#" title="Data.Kind"
+		      >Type</a
+		      >)</span
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    ><em
+		      >Since: base-4.9.0.0</em
+		      ></p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:Product:Rep1:23"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Data.Functor.Product</a
+			></p
+		      > <div class="src"
+		      ><span class="keyword"
+			>type</span
+			> <a href="#" title="GHC.Generics"
+			>Rep1</a
+			> (<a href="#" title="Bug1004"
+			>Product</a
+			> f g :: k -&gt; <a href="#" title="Data.Kind"
+			>Type</a
+			>) = <a href="#" title="GHC.Generics"
+			>D1</a
+			> ('<a href="#" title="GHC.Generics"
+			>MetaData</a
+			> &quot;Product&quot; &quot;Data.Functor.Product&quot; &quot;base&quot; '<a href="#" title="Data.Bool"
+			>False</a
+			>) (<a href="#" title="GHC.Generics"
+			>C1</a
+			> ('<a href="#" title="GHC.Generics"
+			>MetaCons</a
+			> &quot;Pair&quot; '<a href="#" title="GHC.Generics"
+			>PrefixI</a
+			> '<a href="#" title="Data.Bool"
+			>False</a
+			>) (<a href="#" title="GHC.Generics"
+			>S1</a
+			> ('<a href="#" title="GHC.Generics"
+			>MetaSel</a
+			> ('<a href="#" title="Data.Maybe"
+			>Nothing</a
+			> :: <a href="#" title="Data.Maybe"
+			>Maybe</a
+			> <a href="#" title="GHC.TypeLits"
+			>Symbol</a
+			>) '<a href="#" title="GHC.Generics"
+			>NoSourceUnpackedness</a
+			> '<a href="#" title="GHC.Generics"
+			>NoSourceStrictness</a
+			> '<a href="#" title="GHC.Generics"
+			>DecidedLazy</a
+			>) (<a href="#" title="GHC.Generics"
+			>Rec1</a
+			> f) <a href="#" title="GHC.Generics"
+			>:*:</a
+			> <a href="#" title="GHC.Generics"
+			>S1</a
+			> ('<a href="#" title="GHC.Generics"
+			>MetaSel</a
+			> ('<a href="#" title="Data.Maybe"
+			>Nothing</a
+			> :: <a href="#" title="Data.Maybe"
+			>Maybe</a
+			> <a href="#" title="GHC.TypeLits"
+			>Symbol</a
+			>) '<a href="#" title="GHC.Generics"
+			>NoSourceUnpackedness</a
+			> '<a href="#" title="GHC.Generics"
+			>NoSourceStrictness</a
+			> '<a href="#" title="GHC.Generics"
+			>DecidedLazy</a
+			>) (<a href="#" title="GHC.Generics"
+			>Rec1</a
+			> g)))</div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:Product:Rep:24"
+		      ></span
+		      > <span class="keyword"
+		      >type</span
+		      > <a href="#" title="GHC.Generics"
+		      >Rep</a
+		      > (<a href="#" title="Bug1004"
+		      >Product</a
+		      > f g a)</span
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    ><em
+		      >Since: base-4.9.0.0</em
+		      ></p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:Product:Rep:24"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Data.Functor.Product</a
+			></p
+		      > <div class="src"
+		      ><span class="keyword"
+			>type</span
+			> <a href="#" title="GHC.Generics"
+			>Rep</a
+			> (<a href="#" title="Bug1004"
+			>Product</a
+			> f g a) = <a href="#" title="GHC.Generics"
+			>D1</a
+			> ('<a href="#" title="GHC.Generics"
+			>MetaData</a
+			> &quot;Product&quot; &quot;Data.Functor.Product&quot; &quot;base&quot; '<a href="#" title="Data.Bool"
+			>False</a
+			>) (<a href="#" title="GHC.Generics"
+			>C1</a
+			> ('<a href="#" title="GHC.Generics"
+			>MetaCons</a
+			> &quot;Pair&quot; '<a href="#" title="GHC.Generics"
+			>PrefixI</a
+			> '<a href="#" title="Data.Bool"
+			>False</a
+			>) (<a href="#" title="GHC.Generics"
+			>S1</a
+			> ('<a href="#" title="GHC.Generics"
+			>MetaSel</a
+			> ('<a href="#" title="Data.Maybe"
+			>Nothing</a
+			> :: <a href="#" title="Data.Maybe"
+			>Maybe</a
+			> <a href="#" title="GHC.TypeLits"
+			>Symbol</a
+			>) '<a href="#" title="GHC.Generics"
+			>NoSourceUnpackedness</a
+			> '<a href="#" title="GHC.Generics"
+			>NoSourceStrictness</a
+			> '<a href="#" title="GHC.Generics"
+			>DecidedLazy</a
+			>) (<a href="#" title="GHC.Generics"
+			>Rec0</a
+			> (f a)) <a href="#" title="GHC.Generics"
+			>:*:</a
+			> <a href="#" title="GHC.Generics"
+			>S1</a
+			> ('<a href="#" title="GHC.Generics"
+			>MetaSel</a
+			> ('<a href="#" title="Data.Maybe"
+			>Nothing</a
+			> :: <a href="#" title="Data.Maybe"
+			>Maybe</a
+			> <a href="#" title="GHC.TypeLits"
+			>Symbol</a
+			>) '<a href="#" title="GHC.Generics"
+			>NoSourceUnpackedness</a
+			> '<a href="#" title="GHC.Generics"
+			>NoSourceStrictness</a
+			> '<a href="#" title="GHC.Generics"
+			>DecidedLazy</a
+			>) (<a href="#" title="GHC.Generics"
+			>Rec0</a
+			> (g a))))</div
+		      ></details
+		    ></td
+		  ></tr
+		></table
+	      ></details
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Bug1033.html b/html-test/ref/Bug1033.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Bug1033.html
@@ -0,0 +1,226 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Bug1033</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Bug1033</p
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:Foo" class="def"
+	    >Foo</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:Foo" class="def"
+		  >Foo</a
+		  ></td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ></table
+	    ></div
+	  ><div class="subs instances"
+	  ><h4 class="instances details-toggle-control details-toggle" data-details-id="i:Foo"
+	    >Instances</h4
+	    ><details id="i:Foo" open="open"
+	    ><summary class="hide-when-js-enabled"
+	      >Instances details</summary
+	      ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:Foo:Generic:1"
+		      ></span
+		      > <a href="#" title="GHC.Generics"
+		      >Generic</a
+		      > <a href="#" title="Bug1033"
+		      >Foo</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:Foo:Generic:1"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Bug1033</a
+			></p
+		      > <div class="subs associated-types"
+		      ><p class="caption"
+			>Associated Types</p
+			><p class="src"
+			><span class="keyword"
+			  >type</span
+			  > <a href="#" title="GHC.Generics"
+			  >Rep</a
+			  > <a href="#" title="Bug1033"
+			  >Foo</a
+			  > :: <a href="#" title="Data.Kind"
+			  >Type</a
+			  > -&gt; <a href="#" title="Data.Kind"
+			  >Type</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >from</a
+			  > :: <a href="#" title="Bug1033"
+			  >Foo</a
+			  > -&gt; <a href="#" title="GHC.Generics"
+			  >Rep</a
+			  > <a href="#" title="Bug1033"
+			  >Foo</a
+			  > x <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >to</a
+			  > :: <a href="#" title="GHC.Generics"
+			  >Rep</a
+			  > <a href="#" title="Bug1033"
+			  >Foo</a
+			  > x -&gt; <a href="#" title="Bug1033"
+			  >Foo</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:Foo:Rep:2"
+		      ></span
+		      > <span class="keyword"
+		      >type</span
+		      > <a href="#" title="GHC.Generics"
+		      >Rep</a
+		      > <a href="#" title="Bug1033"
+		      >Foo</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    >This does some generic foos.</p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:Foo:Rep:2"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Bug1033</a
+			></p
+		      > <div class="src"
+		      ><span class="keyword"
+			>type</span
+			> <a href="#" title="GHC.Generics"
+			>Rep</a
+			> <a href="#" title="Bug1033"
+			>Foo</a
+			> = <a href="#" title="GHC.Generics"
+			>D1</a
+			> ('<a href="#" title="GHC.Generics"
+			>MetaData</a
+			> &quot;Foo&quot; &quot;Bug1033&quot; &quot;main&quot; '<a href="#" title="Data.Bool"
+			>False</a
+			>) (<a href="#" title="GHC.Generics"
+			>C1</a
+			> ('<a href="#" title="GHC.Generics"
+			>MetaCons</a
+			> &quot;Foo&quot; '<a href="#" title="GHC.Generics"
+			>PrefixI</a
+			> '<a href="#" title="Data.Bool"
+			>False</a
+			>) (<a href="#" title="GHC.Generics"
+			>U1</a
+			> :: <a href="#" title="Data.Kind"
+			>Type</a
+			> -&gt; <a href="#" title="Data.Kind"
+			>Type</a
+			>))</div
+		      ></details
+		    ></td
+		  ></tr
+		></table
+	      ></details
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Bug1035.html b/html-test/ref/Bug1035.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Bug1035.html
@@ -0,0 +1,150 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Bug1035</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Bug1035</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > <a href="#"
+	      >Foo</a
+	      > = <a href="#"
+	      >Bar</a
+	      ></li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > <a href="#"
+	      >Bar</a
+	      > = <a href="#"
+	      >Foo</a
+	      ></li
+	    ><li class="src short"
+	    ><a href="#"
+	      >foo</a
+	      > :: ()</li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:Foo" class="def"
+	    >Foo</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:Bar" class="def"
+		  >Bar</a
+		  ></td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:Bar" class="def"
+	    >Bar</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:Foo" class="def"
+		  >Foo</a
+		  ></td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:foo" class="def"
+	    >foo</a
+	    > :: () <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >A link to <code
+	      ><a href="#" title="Bug1035"
+		>Foo</a
+		></code
+	      ></p
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Bug1050.html b/html-test/ref/Bug1050.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Bug1050.html
@@ -0,0 +1,116 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Bug1050</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Bug1050</p
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >newtype</span
+	    > <a id="t:T" class="def"
+	    >T</a
+	    > :: (<span class="keyword"
+	    >forall</span
+	    > k. k -&gt; <a href="#" title="Data.Kind"
+	    >Type</a
+	    >) -&gt; <span class="keyword"
+	    >forall</span
+	    > k. k -&gt; <a href="#" title="Data.Kind"
+	    >Type</a
+	    > <span class="keyword"
+	    >where</span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:MkT" class="def"
+		  >MkT</a
+		  > :: <span class="keyword"
+		  >forall</span
+		  > (f :: <span class="keyword"
+		  >forall</span
+		  > k. k -&gt; <a href="#" title="Data.Kind"
+		  >Type</a
+		  >) k (a :: k). f a -&gt; <a href="#" title="Bug1050"
+		  >T</a
+		  > f a</td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:mkT" class="def"
+	    >mkT</a
+	    > :: <span class="keyword"
+	    >forall</span
+	    > {k} {f :: <span class="keyword"
+	    >forall</span
+	    > k. k -&gt; <a href="#" title="Data.Kind"
+	    >Type</a
+	    >} {a :: k}. f a -&gt; <a href="#" title="Bug1050"
+	    >T</a
+	    > f a <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Bug1054.html b/html-test/ref/Bug1054.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Bug1054.html
@@ -0,0 +1,96 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Bug1054</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Bug1054</p
+	></div
+      ><div id="table-of-contents"
+      ><div id="contents-list"
+	><p class="caption" onclick="window.scrollTo(0,0)"
+	  >Contents</p
+	  ><ul
+	  ><li
+	    ><a href="#"
+	      >Header with <code
+		>foo</code
+		> link</a
+	      ></li
+	    ></ul
+	  ></div
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><a href="#"
+	      >foo</a
+	      > :: ()</li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><a href="#" id="g:1"
+	><h1
+	  >Header with <code
+	    >foo</code
+	    > link</h1
+	  ></a
+	><div class="top"
+	><p class="src"
+	  ><a id="v:foo" class="def"
+	    >foo</a
+	    > :: () <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Bug1063.html b/html-test/ref/Bug1063.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Bug1063.html
@@ -0,0 +1,104 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Bug1063</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Bug1063</p
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >class</span
+	    > (c =&gt; d) =&gt; <a id="t:Implies" class="def"
+	    >Implies</a
+	    > c d <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs instances"
+	  ><h4 class="instances details-toggle-control details-toggle" data-details-id="i:Implies"
+	    >Instances</h4
+	    ><details id="i:Implies" open="open"
+	    ><summary class="hide-when-js-enabled"
+	      >Instances details</summary
+	      ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:ic:Implies:Implies:1"
+		      ></span
+		      > (c =&gt; d) =&gt; <a href="#" title="Bug1063"
+		      >Implies</a
+		      > c d</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:ic:Implies:Implies:1"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Bug1063</a
+			></p
+		      ></details
+		    ></td
+		  ></tr
+		></table
+	      ></details
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Bug1067A.html b/html-test/ref/Bug1067A.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Bug1067A.html
@@ -0,0 +1,120 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Bug1067A</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Bug1067A</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > <a href="#"
+	      >Foo</a
+	      > <span class="keyword"
+	      >where</span
+	      ><ul class="subs"
+	      ><li
+		><span class="keyword"
+		  >pattern</span
+		  > <a href="#"
+		  >P</a
+		  > :: <a href="#" title="Bug1067A"
+		  >Foo</a
+		  ></li
+		></ul
+	      ></li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:Foo" class="def"
+	    >Foo</a
+	    > <span class="keyword"
+	    >where</span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >A foo</p
+	    ></div
+	  ><div class="subs bundled-patterns"
+	  ><p class="caption"
+	    >Bundled Patterns</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><span class="keyword"
+		  >pattern</span
+		  > <a id="v:P" class="def"
+		  >P</a
+		  > :: <a href="#" title="Bug1067A"
+		  >Foo</a
+		  ></td
+		><td class="doc"
+		><p
+		  >A pattern</p
+		  ></td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Bug1067B.html b/html-test/ref/Bug1067B.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Bug1067B.html
@@ -0,0 +1,90 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Bug1067B</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Bug1067B</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><span class="keyword"
+	      >pattern</span
+	      > <a href="#"
+	      >P</a
+	      > :: <a href="#" title="Bug1067A"
+	      >Foo</a
+	      ></li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >pattern</span
+	    > <a id="v:P" class="def"
+	    >P</a
+	    > :: <a href="#" title="Bug1067A"
+	    >Foo</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >A pattern</p
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Bug1103.html b/html-test/ref/Bug1103.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Bug1103.html
@@ -0,0 +1,560 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Bug1103</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Bug1103</p
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data family</span
+	    > <a id="t:Foo1" class="def"
+	    >Foo1</a
+	    > :: <a href="#" title="Data.Kind"
+	    >Type</a
+	    > -&gt; <a href="#" title="Data.Kind"
+	    >Type</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs instances"
+	  ><h4 class="instances details-toggle-control details-toggle" data-details-id="i:Foo1"
+	    >Instances</h4
+	    ><details id="i:Foo1" open="open"
+	    ><summary class="hide-when-js-enabled"
+	      >Instances details</summary
+	      ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:if:Foo1:Foo1:1"
+		      ></span
+		      > <span class="keyword"
+		      >data</span
+		      > <a href="#" title="Bug1103"
+		      >Foo1</a
+		      > <a href="#" title="Data.Bool"
+		      >Bool</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:if:Foo1:Foo1:1"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Bug1103</a
+			></p
+		      > <div class="src"
+		      ><span class="keyword"
+			>data</span
+			> <a href="#" title="Bug1103"
+			>Foo1</a
+			> <a href="#" title="Data.Bool"
+			>Bool</a
+			> = <a id="v:Foo1Bool" class="def"
+			>Foo1Bool</a
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:if:Foo1:Foo1:2"
+		      ></span
+		      > <span class="keyword"
+		      >data</span
+		      > <a href="#" title="Bug1103"
+		      >Foo1</a
+		      > (<a href="#" title="Data.Maybe"
+		      >Maybe</a
+		      > a)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:if:Foo1:Foo1:2"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Bug1103</a
+			></p
+		      > <div class="src"
+		      ><span class="keyword"
+			>data</span
+			> <a href="#" title="Bug1103"
+			>Foo1</a
+			> (<a href="#" title="Data.Maybe"
+			>Maybe</a
+			> a)</div
+		      ></details
+		    ></td
+		  ></tr
+		></table
+	      ></details
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data family</span
+	    > <a id="t:Foo2" class="def"
+	    >Foo2</a
+	    > :: k -&gt; <a href="#" title="Data.Kind"
+	    >Type</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs instances"
+	  ><h4 class="instances details-toggle-control details-toggle" data-details-id="i:Foo2"
+	    >Instances</h4
+	    ><details id="i:Foo2" open="open"
+	    ><summary class="hide-when-js-enabled"
+	      >Instances details</summary
+	      ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:if:Foo2:Foo2:1"
+		      ></span
+		      > <span class="keyword"
+		      >data</span
+		      > <a href="#" title="Bug1103"
+		      >Foo2</a
+		      > (a :: <a href="#" title="Data.Char"
+		      >Char</a
+		      >)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:if:Foo2:Foo2:1"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Bug1103</a
+			></p
+		      > <div class="src"
+		      ><span class="keyword"
+			>data</span
+			> <a href="#" title="Bug1103"
+			>Foo2</a
+			> (a :: <a href="#" title="Data.Char"
+			>Char</a
+			>)</div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:if:Foo2:Foo2:2"
+		      ></span
+		      > <span class="keyword"
+		      >data</span
+		      > <a href="#" title="Bug1103"
+		      >Foo2</a
+		      > <a href="#" title="Data.Bool"
+		      >Bool</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:if:Foo2:Foo2:2"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Bug1103</a
+			></p
+		      > <div class="src"
+		      ><span class="keyword"
+			>data</span
+			> <a href="#" title="Bug1103"
+			>Foo2</a
+			> <a href="#" title="Data.Bool"
+			>Bool</a
+			> = <a id="v:Foo2Bool" class="def"
+			>Foo2Bool</a
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:if:Foo2:Foo2:3"
+		      ></span
+		      > <span class="keyword"
+		      >data</span
+		      > <a href="#" title="Bug1103"
+		      >Foo2</a
+		      > (<a href="#" title="Data.Maybe"
+		      >Maybe</a
+		      > a :: <a href="#" title="Data.Kind"
+		      >Type</a
+		      >)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:if:Foo2:Foo2:3"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Bug1103</a
+			></p
+		      > <div class="src"
+		      ><span class="keyword"
+			>data</span
+			> <a href="#" title="Bug1103"
+			>Foo2</a
+			> (<a href="#" title="Data.Maybe"
+			>Maybe</a
+			> a :: <a href="#" title="Data.Kind"
+			>Type</a
+			>)</div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:if:Foo2:Foo2:4"
+		      ></span
+		      > <span class="keyword"
+		      >data</span
+		      > <a href="#" title="Bug1103"
+		      >Foo2</a
+		      > (a :: <a href="#" title="Data.Char"
+		      >Char</a
+		      > -&gt; <a href="#" title="Data.Char"
+		      >Char</a
+		      >)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:if:Foo2:Foo2:4"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Bug1103</a
+			></p
+		      > <div class="src"
+		      ><span class="keyword"
+			>data</span
+			> <a href="#" title="Bug1103"
+			>Foo2</a
+			> (a :: <a href="#" title="Data.Char"
+			>Char</a
+			> -&gt; <a href="#" title="Data.Char"
+			>Char</a
+			>)</div
+		      ></details
+		    ></td
+		  ></tr
+		></table
+	      ></details
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data family</span
+	    > <a id="t:Foo3" class="def"
+	    >Foo3</a
+	    > :: k <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs instances"
+	  ><h4 class="instances details-toggle-control details-toggle" data-details-id="i:Foo3"
+	    >Instances</h4
+	    ><details id="i:Foo3" open="open"
+	    ><summary class="hide-when-js-enabled"
+	      >Instances details</summary
+	      ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:if:Foo3:Foo3:1"
+		      ></span
+		      > <span class="keyword"
+		      >data</span
+		      > <a href="#" title="Bug1103"
+		      >Foo3</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:if:Foo3:Foo3:1"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Bug1103</a
+			></p
+		      > <div class="src"
+		      ><span class="keyword"
+			>data</span
+			> <a href="#" title="Bug1103"
+			>Foo3</a
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:if:Foo3:Foo3:2"
+		      ></span
+		      > <span class="keyword"
+		      >data</span
+		      > <a href="#" title="Bug1103"
+		      >Foo3</a
+		      > (a :: <a href="#" title="Data.Char"
+		      >Char</a
+		      > -&gt; <a href="#" title="Data.Char"
+		      >Char</a
+		      >)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:if:Foo3:Foo3:2"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Bug1103</a
+			></p
+		      > <div class="src"
+		      ><span class="keyword"
+			>data</span
+			> <a href="#" title="Bug1103"
+			>Foo3</a
+			> (a :: <a href="#" title="Data.Char"
+			>Char</a
+			> -&gt; <a href="#" title="Data.Char"
+			>Char</a
+			>)</div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:if:Foo3:Foo3:3"
+		      ></span
+		      > <span class="keyword"
+		      >data</span
+		      > <a href="#" title="Bug1103"
+		      >Foo3</a
+		      > (a :: <a href="#" title="Data.Char"
+		      >Char</a
+		      >)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:if:Foo3:Foo3:3"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Bug1103</a
+			></p
+		      > <div class="src"
+		      ><span class="keyword"
+			>data</span
+			> <a href="#" title="Bug1103"
+			>Foo3</a
+			> (a :: <a href="#" title="Data.Char"
+			>Char</a
+			>)</div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:if:Foo3:Foo3:4"
+		      ></span
+		      > <span class="keyword"
+		      >data</span
+		      > <a href="#" title="Bug1103"
+		      >Foo3</a
+		      > <a href="#" title="Data.Bool"
+		      >Bool</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:if:Foo3:Foo3:4"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Bug1103</a
+			></p
+		      > <div class="src"
+		      ><span class="keyword"
+			>data</span
+			> <a href="#" title="Bug1103"
+			>Foo3</a
+			> <a href="#" title="Data.Bool"
+			>Bool</a
+			> = <a id="v:Foo3Bool" class="def"
+			>Foo3Bool</a
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:if:Foo3:Foo3:5"
+		      ></span
+		      > <span class="keyword"
+		      >data</span
+		      > <a href="#" title="Bug1103"
+		      >Foo3</a
+		      > (<a href="#" title="Data.Maybe"
+		      >Maybe</a
+		      > a :: <a href="#" title="Data.Kind"
+		      >Type</a
+		      >)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:if:Foo3:Foo3:5"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Bug1103</a
+			></p
+		      > <div class="src"
+		      ><span class="keyword"
+			>data</span
+			> <a href="#" title="Bug1103"
+			>Foo3</a
+			> (<a href="#" title="Data.Maybe"
+			>Maybe</a
+			> a :: <a href="#" title="Data.Kind"
+			>Type</a
+			>)</div
+		      ></details
+		    ></td
+		  ></tr
+		></table
+	      ></details
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Bug195.html b/html-test/ref/Bug195.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Bug195.html
@@ -0,0 +1,188 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Bug195</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Bug195</p
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:T" class="def"
+	    >T</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:A" class="def"
+		  >A</a
+		  ></td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ><tr
+	      ><td colspan="2"
+		><div class="subs fields"
+		  ><p class="caption"
+		    >Fields</p
+		    ><ul
+		    ><li
+		      ><dfn class="src"
+			><a id="v:someField" class="def"
+			  >someField</a
+			  > :: ()</dfn
+			><div class="doc"
+			><p
+			  >Doc for someField of A</p
+			  ></div
+			></li
+		      ><li
+		      ><dfn class="src"
+			><a id="v:someOtherField" class="def"
+			  >someOtherField</a
+			  > :: ()</dfn
+			><div class="doc"
+			><p
+			  >Doc for someOtherField of A</p
+			  ></div
+			></li
+		      ></ul
+		    ></div
+		  ></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		><a id="v:B" class="def"
+		  >B</a
+		  ></td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ><tr
+	      ><td colspan="2"
+		><div class="subs fields"
+		  ><p class="caption"
+		    >Fields</p
+		    ><ul
+		    ><li
+		      ><dfn class="src"
+			><a id="v:someField" class="def"
+			  >someField</a
+			  > :: ()</dfn
+			><div class="doc"
+			><p
+			  >Doc for someField of A</p
+			  ></div
+			></li
+		      ><li
+		      ><dfn class="src"
+			><a id="v:someOtherField" class="def"
+			  >someOtherField</a
+			  > :: ()</dfn
+			><div class="doc"
+			><p
+			  >Doc for someOtherField of A</p
+			  ></div
+			></li
+		      ></ul
+		    ></div
+		  ></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		><a id="v:C" class="def"
+		  >C</a
+		  ></td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ><tr
+	      ><td colspan="2"
+		><div class="subs fields"
+		  ><p class="caption"
+		    >Fields</p
+		    ><ul
+		    ><li
+		      ><dfn class="src"
+			><a id="v:someField" class="def"
+			  >someField</a
+			  > :: ()</dfn
+			><div class="doc"
+			><p
+			  >Doc for someField of A</p
+			  ></div
+			></li
+		      ><li
+		      ><dfn class="src"
+			><a id="v:someOtherField" class="def"
+			  >someOtherField</a
+			  > :: ()</dfn
+			><div class="doc"
+			><p
+			  >Doc for someOtherField of A</p
+			  ></div
+			></li
+		      ></ul
+		    ></div
+		  ></td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Bug2.html b/html-test/ref/Bug2.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Bug2.html
@@ -0,0 +1,68 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Bug2</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Bug2</p
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><a id="v:x" class="def"
+	    >x</a
+	    > :: <a href="#" title="A"
+	    >A</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Bug201.html b/html-test/ref/Bug201.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Bug201.html
@@ -0,0 +1,109 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Bug201</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Bug201</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><a href="#"
+	      >f</a
+	      > :: ()</li
+	    ><li class="src short"
+	    ><a href="#"
+	      >g</a
+	      > :: ()</li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><a id="v:f" class="def"
+	    >f</a
+	    > :: () <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><pre
+	    >This leading whitespace
+should be dropped
+</pre
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:g" class="def"
+	    >g</a
+	    > :: () <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><pre
+	    > But this one
+ should not
+</pre
+	    ><pre
+	    >this should
+be dropped</pre
+	    ><pre
+	    >and so should this
+because there's a space before closing @
+</pre
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Bug253.html b/html-test/ref/Bug253.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Bug253.html
@@ -0,0 +1,104 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Bug253</title
+    ><link href="linuwial.css" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="quick-jump.css"
+     /><link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=PT+Sans:400,400i,700"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="index.html"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="doc-index.html"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Bug253</p
+	></div
+      ><div id="description"
+      ><p class="caption"
+	>Description</p
+	><div class="doc"
+	><p
+	  >This module tests that if we're trying to link to a <em
+	    >qualified</em
+	    >
+ identifier that's not in scope, we get an anchor as if it was a
+ variable. Previous behaviour was to treat it as a type constructor
+ so issue like #253 arose. Also see <code
+	    >rename</code
+	    > function comments in
+ source.</p
+	  ></div
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><a href="#v:foo"
+	      >foo</a
+	      > :: ()</li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><a id="v:foo" class="def"
+	    >foo</a
+	    > :: () <a href="#v:foo" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >This link should generate <code
+	      >#v</code
+	      > anchor: <code
+	      ><a href="DoesNotExist.html#v:fakeFakeFake" title="DoesNotExist"
+		>fakeFakeFake</a
+		></code
+	      ></p
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Bug26.html b/html-test/ref/Bug26.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Bug26.html
@@ -0,0 +1,216 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Bug26</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Bug26</p
+	></div
+      ><div id="description"
+      ><p class="caption"
+	>Description</p
+	><div class="doc"
+	><p
+	  >This module tests the &#8216;@since &#8230;&#8217; annotation.</p
+	  ><p
+	  ><em
+	    >Since: 1.2.3</em
+	    ></p
+	  ></div
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><a href="#"
+	      >f</a
+	      > :: ()</li
+	    ><li class="src short"
+	    ><a href="#"
+	      >g</a
+	      > :: ()</li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >class</span
+	      > <a href="#"
+	      >C</a
+	      > a <span class="keyword"
+	      >where</span
+	      ><ul class="subs"
+	      ><li
+		><a href="#"
+		  >c_f</a
+		  > :: a</li
+		></ul
+	      ></li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><a id="v:f" class="def"
+	    >f</a
+	    > :: () <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Foo</p
+	    ><p
+	    ><em
+	      >Since: 2.10.8</em
+	      ></p
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:g" class="def"
+	    >g</a
+	    > :: () <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Bar</p
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >class</span
+	    > <a id="t:C" class="def"
+	    >C</a
+	    > a <span class="keyword"
+	    >where</span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Class</p
+	    ><p
+	    ><em
+	      >Since: 1.0</em
+	      ></p
+	    ></div
+	  ><div class="subs methods"
+	  ><p class="caption"
+	    >Methods</p
+	    ><p class="src"
+	    ><a id="v:c_f" class="def"
+	      >c_f</a
+	      > :: a <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ><div class="doc"
+	    ><p
+	      ><em
+		>Since: 1.2.3</em
+		></p
+	      ></div
+	    ></div
+	  ><div class="subs instances"
+	  ><h4 class="instances details-toggle-control details-toggle" data-details-id="i:C"
+	    >Instances</h4
+	    ><details id="i:C" open="open"
+	    ><summary class="hide-when-js-enabled"
+	      >Instances details</summary
+	      ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:ic:C:C:1"
+		      ></span
+		      > <a href="#" title="Bug26"
+		      >C</a
+		      > ()</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    >instance for ()</p
+		    ><p
+		    ><em
+		      >Since: 0.7.8</em
+		      ></p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:ic:C:C:1"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Bug26</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >c_f</a
+			  > :: () <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		></table
+	      ></details
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Bug280.html b/html-test/ref/Bug280.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Bug280.html
@@ -0,0 +1,84 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Bug280</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th valign="top"
+	    >Copyright</th
+	    ><td
+	    >Foo<br
+	       />Bar<br
+	       />Baz</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Bug280</p
+	></div
+      ><div id="description"
+      ><p class="caption"
+	>Description</p
+	><div class="doc"
+	><p
+	  >The module description</p
+	  ></div
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><a id="v:x" class="def"
+	    >x</a
+	    > :: <a href="#" title="Data.String"
+	    >String</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Bug294.html b/html-test/ref/Bug294.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Bug294.html
@@ -0,0 +1,378 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Bug294</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Bug294</p
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:A" class="def"
+	    >A</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs instances"
+	  ><h4 class="instances details-toggle-control details-toggle" data-details-id="i:A"
+	    >Instances</h4
+	    ><details id="i:A" open="open"
+	    ><summary class="hide-when-js-enabled"
+	      >Instances details</summary
+	      ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:A:DP:1"
+		      ></span
+		      > <span class="keyword"
+		      >data</span
+		      > <a href="#" title="Bug294"
+		      >DP</a
+		      > <a href="#" title="Bug294"
+		      >A</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:A:DP:1"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Bug294</a
+			></p
+		      > <div class="src"
+		      ><span class="keyword"
+			>data</span
+			> <a href="#" title="Bug294"
+			>DP</a
+			> <a href="#" title="Bug294"
+			>A</a
+			> = <a id="v:ProblemCtor-39-" class="def"
+			>ProblemCtor'</a
+			> <a href="#" title="Bug294"
+			>A</a
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:A:TP:2"
+		      ></span
+		      > <span class="keyword"
+		      >data</span
+		      > <a href="#" title="Bug294"
+		      >TP</a
+		      > <a href="#" title="Bug294"
+		      >A</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:A:TP:2"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Bug294</a
+			></p
+		      > <div class="src"
+		      ><span class="keyword"
+			>data</span
+			> <a href="#" title="Bug294"
+			>TP</a
+			> <a href="#" title="Bug294"
+			>A</a
+			> = <a id="v:ProblemCtor" class="def"
+			>ProblemCtor</a
+			> <a href="#" title="Bug294"
+			>A</a
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		></table
+	      ></details
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:problemField" class="def"
+	    >problemField</a
+	    > :: TO <a href="#" title="Bug294"
+	    >A</a
+	    > -&gt; <a href="#" title="Bug294"
+	    >A</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:problemField-39-" class="def"
+	    >problemField'</a
+	    > :: DO <a href="#" title="Bug294"
+	    >A</a
+	    > -&gt; <a href="#" title="Bug294"
+	    >A</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:gadtField" class="def"
+	    >gadtField</a
+	    > :: GADT <a href="#" title="Bug294"
+	    >A</a
+	    > -&gt; <a href="#" title="Bug294"
+	    >A</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data family</span
+	    > <a id="t:TP" class="def"
+	    >TP</a
+	    > t :: * <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs instances"
+	  ><h4 class="instances details-toggle-control details-toggle" data-details-id="i:TP"
+	    >Instances</h4
+	    ><details id="i:TP" open="open"
+	    ><summary class="hide-when-js-enabled"
+	      >Instances details</summary
+	      ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:if:TP:TP:1"
+		      ></span
+		      > <span class="keyword"
+		      >data</span
+		      > <a href="#" title="Bug294"
+		      >TP</a
+		      > <a href="#" title="Bug294"
+		      >A</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:if:TP:TP:1"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Bug294</a
+			></p
+		      > <div class="src"
+		      ><span class="keyword"
+			>data</span
+			> <a href="#" title="Bug294"
+			>TP</a
+			> <a href="#" title="Bug294"
+			>A</a
+			> = <a id="v:ProblemCtor" class="def"
+			>ProblemCtor</a
+			> <a href="#" title="Bug294"
+			>A</a
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		></table
+	      ></details
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data family</span
+	    > <a id="t:DP" class="def"
+	    >DP</a
+	    > t :: * <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs instances"
+	  ><h4 class="instances details-toggle-control details-toggle" data-details-id="i:DP"
+	    >Instances</h4
+	    ><details id="i:DP" open="open"
+	    ><summary class="hide-when-js-enabled"
+	      >Instances details</summary
+	      ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:if:DP:DP:1"
+		      ></span
+		      > <span class="keyword"
+		      >data</span
+		      > <a href="#" title="Bug294"
+		      >DP</a
+		      > <a href="#" title="Bug294"
+		      >A</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:if:DP:DP:1"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Bug294</a
+			></p
+		      > <div class="src"
+		      ><span class="keyword"
+			>data</span
+			> <a href="#" title="Bug294"
+			>DP</a
+			> <a href="#" title="Bug294"
+			>A</a
+			> = <a id="v:ProblemCtor-39-" class="def"
+			>ProblemCtor'</a
+			> <a href="#" title="Bug294"
+			>A</a
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		></table
+	      ></details
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data family</span
+	    > <a id="t:TO-39-" class="def"
+	    >TO'</a
+	    > t :: * <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs instances"
+	  ><h4 class="instances details-toggle-control details-toggle" data-details-id="i:TO-39-"
+	    >Instances</h4
+	    ><details id="i:TO-39-" open="open"
+	    ><summary class="hide-when-js-enabled"
+	      >Instances details</summary
+	      ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:if:TO-39-:TO-39-:1"
+		      ></span
+		      > <span class="keyword"
+		      >data</span
+		      > <a href="#" title="Bug294"
+		      >TO'</a
+		      > a</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:if:TO-39-:TO-39-:1"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Bug294</a
+			></p
+		      > <div class="src"
+		      ><span class="keyword"
+			>data</span
+			> <a href="#" title="Bug294"
+			>TO'</a
+			> a = <a id="v:PolyCtor" class="def"
+			>PolyCtor</a
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		></table
+	      ></details
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Bug298.html b/html-test/ref/Bug298.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Bug298.html
@@ -0,0 +1,146 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Bug298</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Bug298</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><a href="#"
+	      >(&lt;^&gt;)</a
+	      > :: (a -&gt; a) -&gt; a -&gt; a</li
+	    ><li class="src short"
+	    ><a href="#"
+	      >(&lt;^)</a
+	      > :: a -&gt; a -&gt; a</li
+	    ><li class="src short"
+	    ><a href="#"
+	      >(^&gt;)</a
+	      > :: a -&gt; a -&gt; a</li
+	    ><li class="src short"
+	    ><a href="#"
+	      >(&#8902;^)</a
+	      > :: a -&gt; a -&gt; a</li
+	    ><li class="src short"
+	    ><a href="#"
+	      >f</a
+	      > :: ()</li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><a id="v:-60--94--62-" class="def"
+	    >(&lt;^&gt;)</a
+	    > :: (a -&gt; a) -&gt; a -&gt; a <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:-60--94-" class="def"
+	    >(&lt;^)</a
+	    > :: a -&gt; a -&gt; a <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:-94--62-" class="def"
+	    >(^&gt;)</a
+	    > :: a -&gt; a -&gt; a <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:-8902--94-" class="def"
+	    >(&#8902;^)</a
+	    > :: a -&gt; a -&gt; a <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:f" class="def"
+	    >f</a
+	    > :: () <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Links to <code
+	      ><a href="#" title="Bug298"
+		>&lt;^&gt;</a
+		></code
+	      > and <code
+	      ><a href="#" title="Bug298"
+		>^&gt;</a
+		></code
+	      >, <code
+	      ><a href="#" title="Bug298"
+		>&lt;^</a
+		></code
+	      > and <code
+	      ><a href="#" title="Bug298"
+		>&#8902;^</a
+		></code
+	      >.</p
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Bug3.html b/html-test/ref/Bug3.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Bug3.html
@@ -0,0 +1,87 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Bug3</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Bug3</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><a href="#"
+	      >foo</a
+	      > :: <a href="#" title="Data.Int"
+	      >Int</a
+	      ></li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><a id="v:foo" class="def"
+	    >foo</a
+	    > :: <a href="#" title="Data.Int"
+	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >/multi-line
+ emphasis/</p
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Bug308.html b/html-test/ref/Bug308.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Bug308.html
@@ -0,0 +1,118 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Bug308</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Bug308</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><a href="#"
+	      >f</a
+	      > :: ()</li
+	    ><li class="src short"
+	    ><a href="#"
+	      >g</a
+	      > :: ()</li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><a id="v:f" class="def"
+	    >f</a
+	    > :: () <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >start<a id="startAnchor"
+	      ></a
+	      > followed by middle<a id="middleAnchor"
+	      ></a
+	      > and end<a id="endAnchor"
+	      ></a
+	      ></p
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:g" class="def"
+	    >g</a
+	    > :: () <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >start <a href="#"
+	      >Bug308</a
+	      ></p
+	    ><p
+	    >startOldStyle <a href="#"
+	      >Bug308</a
+	      ></p
+	    ><p
+	    >middle <a href="#"
+	      >Bug308</a
+	      ></p
+	    ><p
+	    >end <a href="#"
+	      >Bug308</a
+	      ></p
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Bug308CrossModule.html b/html-test/ref/Bug308CrossModule.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Bug308CrossModule.html
@@ -0,0 +1,96 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Bug308CrossModule</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Bug308CrossModule</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><a href="#"
+	      >h</a
+	      > :: ()</li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><a id="v:h" class="def"
+	    >h</a
+	    > :: () <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >start <a href="#"
+	      >Bug308</a
+	      ></p
+	    ><p
+	    >startOldStyle <a href="#"
+	      >Bug308</a
+	      ></p
+	    ><p
+	    >middle <a href="#"
+	      >Bug308</a
+	      ></p
+	    ><p
+	    >end <a href="#"
+	      >Bug308</a
+	      ></p
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Bug310.html b/html-test/ref/Bug310.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Bug310.html
@@ -0,0 +1,110 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Bug310</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Bug310</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><span class="keyword"
+	      >type family</span
+	      > (a :: <a href="#" title="Numeric.Natural"
+	      >Natural</a
+	      >) <a href="#"
+	      >+</a
+	      > (b :: <a href="#" title="Numeric.Natural"
+	      >Natural</a
+	      >) :: <a href="#" title="Numeric.Natural"
+	      >Natural</a
+	      > <span class="keyword"
+	      >where ...</span
+	      ></li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >type family</span
+	    > (a :: <a href="#" title="Numeric.Natural"
+	    >Natural</a
+	    >) <a id="t:-43-" class="def"
+	    >+</a
+	    > (b :: <a href="#" title="Numeric.Natural"
+	    >Natural</a
+	    >) :: <a href="#" title="Numeric.Natural"
+	    >Natural</a
+	    > <span class="keyword"
+	    >where ...</span
+	    > <span class="fixity"
+	    >infixl 6</span
+	    ><span class="rightedge"
+	    ></span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Addition of type-level naturals.</p
+	    ><p
+	    ><em
+	      >Since: base-4.7.0.0</em
+	      ></p
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Bug313.html b/html-test/ref/Bug313.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Bug313.html
@@ -0,0 +1,139 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Bug313</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Bug313</p
+	></div
+      ><div id="description"
+      ><p class="caption"
+	>Description</p
+	><div class="doc"
+	><p
+	  >The first list is incorrectly numbered as 1. 2. 1.; the second example
+ renders fine (1. 2. 3.).</p
+	  ><p
+	  >See <a href="#"
+	    >https://github.com/haskell/haddock/issues/313</a
+	    ></p
+	  ></div
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><a href="#"
+	      >a</a
+	      > :: a</li
+	    ><li class="src short"
+	    ><a href="#"
+	      >b</a
+	      > :: a</li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><a id="v:a" class="def"
+	    >a</a
+	    > :: a <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Some text.</p
+	    ><ol
+	    ><li value="1"
+	      >Item 1</li
+	      ><li value="2"
+	      ><p
+		>Item 2</p
+		><pre
+		>Some code</pre
+		></li
+	      ><li value="3"
+	      >Item 3</li
+	      ></ol
+	    ><p
+	    >Some more text.</p
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:b" class="def"
+	    >b</a
+	    > :: a <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Some text.</p
+	    ><ol
+	    ><li value="1"
+	      >Item 1</li
+	      ><li value="2"
+	      ><p
+		>Item 2</p
+		><pre
+		>Some code</pre
+		></li
+	      ><li value="3"
+	      >Item 3</li
+	      ></ol
+	    ><p
+	    >Some more text.</p
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Bug335.html b/html-test/ref/Bug335.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Bug335.html
@@ -0,0 +1,136 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Bug335</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Bug335</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><a href="#"
+	      >f</a
+	      > :: ()</li
+	    ><li class="src short"
+	    ><a href="#"
+	      >g</a
+	      > :: ()</li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><a id="v:f" class="def"
+	    >f</a
+	    > :: () <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><h3 class="subheading details-toggle-control details-toggle" data-details-id="ch:f0"
+	    >ExF:</h3
+	    ><details id="ch:f0"
+	    ><summary class="hide-when-js-enabled"
+	      >Expand</summary
+	      ><p
+	      >abc</p
+	      ></details
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:g" class="def"
+	    >g</a
+	    > :: () <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><h3 class="subheading details-toggle-control details-toggle" data-details-id="ch:g0"
+	    >ExG:</h3
+	    ><details id="ch:g0"
+	    ><summary class="hide-when-js-enabled"
+	      >Expand</summary
+	      ><pre class="screen"
+	      ><code class="prompt"
+		>&gt;&gt;&gt; </code
+		><strong class="userinput"
+		><code
+		  >a
+</code
+		  ></strong
+		>b
+</pre
+	      ><pre class="screen"
+	      ><code class="prompt"
+		>&gt;&gt;&gt; </code
+		><strong class="userinput"
+		><code
+		  >c
+</code
+		  ></strong
+		>d
+</pre
+	      ><h4
+	      >Under ex</h4
+	      ><p
+	      >foo</p
+	      ></details
+	    ><h2
+	    >Out of Ex</h2
+	    ><p
+	    >foo</p
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Bug4.html b/html-test/ref/Bug4.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Bug4.html
@@ -0,0 +1,86 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Bug4</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Bug4</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><a href="#"
+	      >foo</a
+	      > :: <a href="#" title="Data.Int"
+	      >Int</a
+	      ></li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><a id="v:foo" class="def"
+	    >foo</a
+	    > :: <a href="#" title="Data.Int"
+	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >don't use apostrophe's in the wrong place's</p
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Bug458.html b/html-test/ref/Bug458.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Bug458.html
@@ -0,0 +1,88 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Bug458</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Bug458</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><a href="#"
+	      >(&#8838;)</a
+	      > :: () -&gt; () -&gt; ()</li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><a id="v:-8838-" class="def"
+	    >(&#8838;)</a
+	    > :: () -&gt; () -&gt; () <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >See the defn of <code
+	      ><code
+		><a href="#" title="Bug458"
+		  >&#8838;</a
+		  ></code
+		></code
+	      >.</p
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Bug466.html b/html-test/ref/Bug466.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Bug466.html
@@ -0,0 +1,252 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Bug466</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Bug466</p
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >class</span
+	    > <a id="t:Cl" class="def"
+	    >Cl</a
+	    > a <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs associated-types"
+	  ><p class="caption"
+	    >Associated Types</p
+	    ><p class="src"
+	    ><span class="keyword"
+	      >type</span
+	      > <a id="t:Fam" class="def"
+	      >Fam</a
+	      > a :: [*] <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ></div
+	  ><div class="subs instances"
+	  ><h4 class="instances details-toggle-control details-toggle" data-details-id="i:Cl"
+	    >Instances</h4
+	    ><details id="i:Cl" open="open"
+	    ><summary class="hide-when-js-enabled"
+	      >Instances details</summary
+	      ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:ic:Cl:Cl:1"
+		      ></span
+		      > <a href="#" title="Bug466"
+		      >Cl</a
+		      > <a href="#" title="Bug466"
+		      >X</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:ic:Cl:Cl:1"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Bug466</a
+			></p
+		      > <div class="subs associated-types"
+		      ><p class="caption"
+			>Associated Types</p
+			><p class="src"
+			><span class="keyword"
+			  >type</span
+			  > <a href="#" title="Bug466"
+			  >Fam</a
+			  > <a href="#" title="Bug466"
+			  >X</a
+			  > :: [<a href="#" title="Data.Kind"
+			  >Type</a
+			  >] <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		></table
+	      ></details
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:X" class="def"
+	    >X</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:X" class="def"
+		  >X</a
+		  ></td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ></table
+	    ></div
+	  ><div class="subs instances"
+	  ><h4 class="instances details-toggle-control details-toggle" data-details-id="i:X"
+	    >Instances</h4
+	    ><details id="i:X" open="open"
+	    ><summary class="hide-when-js-enabled"
+	      >Instances details</summary
+	      ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:X:Cl:1"
+		      ></span
+		      > <a href="#" title="Bug466"
+		      >Cl</a
+		      > <a href="#" title="Bug466"
+		      >X</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:X:Cl:1"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Bug466</a
+			></p
+		      > <div class="subs associated-types"
+		      ><p class="caption"
+			>Associated Types</p
+			><p class="src"
+			><span class="keyword"
+			  >type</span
+			  > <a href="#" title="Bug466"
+			  >Fam</a
+			  > <a href="#" title="Bug466"
+			  >X</a
+			  > :: [<a href="#" title="Data.Kind"
+			  >Type</a
+			  >] <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:X:Fam:2"
+		      ></span
+		      > <span class="keyword"
+		      >type</span
+		      > <a href="#" title="Bug466"
+		      >Fam</a
+		      > <a href="#" title="Bug466"
+		      >X</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:X:Fam:2"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Bug466</a
+			></p
+		      > <div class="src"
+		      ><span class="keyword"
+			>type</span
+			> <a href="#" title="Bug466"
+			>Fam</a
+			> <a href="#" title="Bug466"
+			>X</a
+			> = '[<a href="#" title="Data.Char"
+			>Char</a
+			>]</div
+		      ></details
+		    ></td
+		  ></tr
+		></table
+	      ></details
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Bug546.html b/html-test/ref/Bug546.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Bug546.html
@@ -0,0 +1,281 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Bug546</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Bug546</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><a href="#"
+	      >x</a
+	      > :: <a href="#" title="Prelude"
+	      >Integer</a
+	      ></li
+	    ><li class="src short"
+	    ><a href="#"
+	      >compile</a
+	      > :: <a href="#" title="Data.String"
+	      >String</a
+	      > -&gt; <a href="#" title="Data.String"
+	      >String</a
+	      ></li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><a id="v:x" class="def"
+	    >x</a
+	    > :: <a href="#" title="Prelude"
+	    >Integer</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Test:</p
+	    ><dl
+	    ><dt
+	      ><code
+		>[code with square \ brackets]</code
+		></dt
+	      ><dd
+	      >lorem ipsum</dd
+	      ></dl
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:compile" class="def"
+	    >compile</a
+	    > :: <a href="#" title="Data.String"
+	    >String</a
+	    > -&gt; <a href="#" title="Data.String"
+	    >String</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><dl
+	    ><dt
+	      ><code
+		>[..]</code
+		></dt
+	      ><dd
+	      >Matches any of the enclosed characters. Ranges of characters can
+            be specified by separating the endpoints with a <code
+		>'-'</code
+		>. <code
+		>'-'</code
+		> or
+            <code
+		>']'</code
+		> can be matched by including them as the first character(s)
+            in the list. Never matches path separators: <code
+		>[/]</code
+		> matches
+            nothing at all. Named character classes can also be matched:
+            <code
+		>[:x:]</code
+		> within <code
+		>[]</code
+		> specifies the class named <code
+		>x</code
+		>, which matches
+            certain predefined characters. See below for a full list.</dd
+	      ><dt
+	      ><code
+		>[^..]</code
+		> or <code
+		>[!..]</code
+		></dt
+	      ><dd
+	      >Like <code
+		>[..]</code
+		>, but matches any character <em
+		>not</em
+		> listed.
+                        Note that <code
+		>[^-x]</code
+		> is not the inverse of <code
+		>[-x]</code
+		>, but
+                        the range <code
+		>[^-x]</code
+		>.</dd
+	      ><dt
+	      ><code
+		>&lt;m-n&gt;</code
+		></dt
+	      ><dd
+	      >Matches any integer in the range m to n, inclusive. The range may
+            be open-ended by leaving out either number: <code
+		>&quot;&lt;-&gt;&quot;</code
+		>, for
+            instance, matches any integer.</dd
+	      ><dt
+	      ><code
+		>**/</code
+		></dt
+	      ><dd
+	      >Matches any number of characters, including path separators,
+            excluding the empty string.</dd
+	      ></dl
+	    ><p
+	    >Supported character classes:</p
+	    ><dl
+	    ><dt
+	      ><code
+		>[:alnum:]</code
+		></dt
+	      ><dd
+	      >Equivalent to <code
+		>&quot;0-9A-Za-z&quot;</code
+		>.</dd
+	      ><dt
+	      ><code
+		>[:alpha:]</code
+		></dt
+	      ><dd
+	      >Equivalent to <code
+		>&quot;A-Za-z&quot;</code
+		>.</dd
+	      ><dt
+	      ><code
+		>[:blank:]</code
+		></dt
+	      ><dd
+	      >Equivalent to <code
+		>&quot;\t &quot;</code
+		>.</dd
+	      ><dt
+	      ><code
+		>[:cntrl:]</code
+		></dt
+	      ><dd
+	      >Equivalent to <code
+		>&quot;\0-\x1f\x7f&quot;</code
+		>.</dd
+	      ><dt
+	      ><code
+		>[:digit:]</code
+		></dt
+	      ><dd
+	      >Equivalent to <code
+		>&quot;0-9&quot;</code
+		>.</dd
+	      ><dt
+	      ><code
+		>[:graph:]</code
+		></dt
+	      ><dd
+	      >Equivalent to <code
+		>&quot;!-~&quot;</code
+		>.</dd
+	      ><dt
+	      ><code
+		>[:lower:]</code
+		></dt
+	      ><dd
+	      >Equivalent to <code
+		>&quot;a-z&quot;</code
+		>.</dd
+	      ><dt
+	      ><code
+		>[:print:]</code
+		></dt
+	      ><dd
+	      >Equivalent to <code
+		>&quot; -~&quot;</code
+		>.</dd
+	      ><dt
+	      ><code
+		>[:punct:]</code
+		></dt
+	      ><dd
+	      >Equivalent to <code
+		>&quot;!-/:-@[-`{-~&quot;</code
+		>.</dd
+	      ><dt
+	      ><code
+		>[:space:]</code
+		></dt
+	      ><dd
+	      >Equivalent to <code
+		>&quot;\t-\r &quot;</code
+		>.</dd
+	      ><dt
+	      ><code
+		>[:upper:]</code
+		></dt
+	      ><dd
+	      >Equivalent to <code
+		>&quot;A-Z&quot;</code
+		>.</dd
+	      ><dt
+	      ><code
+		>[:xdigit:]</code
+		></dt
+	      ><dd
+	      >Equivalent to <code
+		>&quot;0-9A-Fa-f&quot;</code
+		>.</dd
+	      ></dl
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Bug548.html b/html-test/ref/Bug548.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Bug548.html
@@ -0,0 +1,636 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Bug548</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Bug548</p
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >newtype</span
+	    > <a id="t:WrappedArrow" class="def"
+	    >WrappedArrow</a
+	    > (a :: <a href="#" title="Data.Kind"
+	    >Type</a
+	    > -&gt; <a href="#" title="Data.Kind"
+	    >Type</a
+	    > -&gt; <a href="#" title="Data.Kind"
+	    >Type</a
+	    >) b c <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:WrapArrow" class="def"
+		  >WrapArrow</a
+		  ></td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ><tr
+	      ><td colspan="2"
+		><div class="subs fields"
+		  ><p class="caption"
+		    >Fields</p
+		    ><ul
+		    ><li
+		      ><dfn class="src"
+			><a id="v:unwrapArrow" class="def"
+			  >unwrapArrow</a
+			  > :: a b c</dfn
+			><div class="doc empty"
+			>&nbsp;</div
+			></li
+		      ></ul
+		    ></div
+		  ></td
+		></tr
+	      ></table
+	    ></div
+	  ><div class="subs instances"
+	  ><h4 class="instances details-toggle-control details-toggle" data-details-id="i:WrappedArrow"
+	    >Instances</h4
+	    ><details id="i:WrappedArrow" open="open"
+	    ><summary class="hide-when-js-enabled"
+	      >Instances details</summary
+	      ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:WrappedArrow:Generic1:1"
+		      ></span
+		      > <a href="#" title="GHC.Generics"
+		      >Generic1</a
+		      > (<a href="#" title="Bug548"
+		      >WrappedArrow</a
+		      > a b :: <a href="#" title="Data.Kind"
+		      >Type</a
+		      > -&gt; <a href="#" title="Data.Kind"
+		      >Type</a
+		      >)</span
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:WrappedArrow:Generic1:1"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Control.Applicative</a
+			></p
+		      > <div class="subs associated-types"
+		      ><p class="caption"
+			>Associated Types</p
+			><p class="src"
+			><span class="keyword"
+			  >type</span
+			  > <a href="#" title="GHC.Generics"
+			  >Rep1</a
+			  > (<a href="#" title="Bug548"
+			  >WrappedArrow</a
+			  > a b) :: k -&gt; <a href="#" title="Data.Kind"
+			  >Type</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >from1</a
+			  > :: <span class="keyword"
+			  >forall</span
+			  > (a0 :: k). <a href="#" title="Bug548"
+			  >WrappedArrow</a
+			  > a b a0 -&gt; <a href="#" title="GHC.Generics"
+			  >Rep1</a
+			  > (<a href="#" title="Bug548"
+			  >WrappedArrow</a
+			  > a b) a0 <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >to1</a
+			  > :: <span class="keyword"
+			  >forall</span
+			  > (a0 :: k). <a href="#" title="GHC.Generics"
+			  >Rep1</a
+			  > (<a href="#" title="Bug548"
+			  >WrappedArrow</a
+			  > a b) a0 -&gt; <a href="#" title="Bug548"
+			  >WrappedArrow</a
+			  > a b a0 <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:WrappedArrow:Alternative:2"
+		      ></span
+		      > (<a href="#" title="Control.Arrow"
+		      >ArrowZero</a
+		      > a, <a href="#" title="Control.Arrow"
+		      >ArrowPlus</a
+		      > a) =&gt; <a href="#" title="Control.Applicative"
+		      >Alternative</a
+		      > (<a href="#" title="Bug548"
+		      >WrappedArrow</a
+		      > a b)</span
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    ><em
+		      >Since: base-2.1</em
+		      ></p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:WrappedArrow:Alternative:2"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Control.Applicative</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >empty</a
+			  > :: <a href="#" title="Bug548"
+			  >WrappedArrow</a
+			  > a b a0 <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >(&lt;|&gt;)</a
+			  > :: <a href="#" title="Bug548"
+			  >WrappedArrow</a
+			  > a b a0 -&gt; <a href="#" title="Bug548"
+			  >WrappedArrow</a
+			  > a b a0 -&gt; <a href="#" title="Bug548"
+			  >WrappedArrow</a
+			  > a b a0 <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >some</a
+			  > :: <a href="#" title="Bug548"
+			  >WrappedArrow</a
+			  > a b a0 -&gt; <a href="#" title="Bug548"
+			  >WrappedArrow</a
+			  > a b [a0] <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >many</a
+			  > :: <a href="#" title="Bug548"
+			  >WrappedArrow</a
+			  > a b a0 -&gt; <a href="#" title="Bug548"
+			  >WrappedArrow</a
+			  > a b [a0] <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:WrappedArrow:Applicative:3"
+		      ></span
+		      > <a href="#" title="Control.Arrow"
+		      >Arrow</a
+		      > a =&gt; <a href="#" title="Control.Applicative"
+		      >Applicative</a
+		      > (<a href="#" title="Bug548"
+		      >WrappedArrow</a
+		      > a b)</span
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    ><em
+		      >Since: base-2.1</em
+		      ></p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:WrappedArrow:Applicative:3"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Control.Applicative</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >pure</a
+			  > :: a0 -&gt; <a href="#" title="Bug548"
+			  >WrappedArrow</a
+			  > a b a0 <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >(&lt;*&gt;)</a
+			  > :: <a href="#" title="Bug548"
+			  >WrappedArrow</a
+			  > a b (a0 -&gt; b0) -&gt; <a href="#" title="Bug548"
+			  >WrappedArrow</a
+			  > a b a0 -&gt; <a href="#" title="Bug548"
+			  >WrappedArrow</a
+			  > a b b0 <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >liftA2</a
+			  > :: (a0 -&gt; b0 -&gt; c) -&gt; <a href="#" title="Bug548"
+			  >WrappedArrow</a
+			  > a b a0 -&gt; <a href="#" title="Bug548"
+			  >WrappedArrow</a
+			  > a b b0 -&gt; <a href="#" title="Bug548"
+			  >WrappedArrow</a
+			  > a b c <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >(*&gt;)</a
+			  > :: <a href="#" title="Bug548"
+			  >WrappedArrow</a
+			  > a b a0 -&gt; <a href="#" title="Bug548"
+			  >WrappedArrow</a
+			  > a b b0 -&gt; <a href="#" title="Bug548"
+			  >WrappedArrow</a
+			  > a b b0 <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >(&lt;*)</a
+			  > :: <a href="#" title="Bug548"
+			  >WrappedArrow</a
+			  > a b a0 -&gt; <a href="#" title="Bug548"
+			  >WrappedArrow</a
+			  > a b b0 -&gt; <a href="#" title="Bug548"
+			  >WrappedArrow</a
+			  > a b a0 <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:WrappedArrow:Functor:4"
+		      ></span
+		      > <a href="#" title="Control.Arrow"
+		      >Arrow</a
+		      > a =&gt; <a href="#" title="Data.Functor"
+		      >Functor</a
+		      > (<a href="#" title="Bug548"
+		      >WrappedArrow</a
+		      > a b)</span
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    ><em
+		      >Since: base-2.1</em
+		      ></p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:WrappedArrow:Functor:4"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Control.Applicative</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >fmap</a
+			  > :: (a0 -&gt; b0) -&gt; <a href="#" title="Bug548"
+			  >WrappedArrow</a
+			  > a b a0 -&gt; <a href="#" title="Bug548"
+			  >WrappedArrow</a
+			  > a b b0 <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >(&lt;$)</a
+			  > :: a0 -&gt; <a href="#" title="Bug548"
+			  >WrappedArrow</a
+			  > a b b0 -&gt; <a href="#" title="Bug548"
+			  >WrappedArrow</a
+			  > a b a0 <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:WrappedArrow:Generic:5"
+		      ></span
+		      > <a href="#" title="GHC.Generics"
+		      >Generic</a
+		      > (<a href="#" title="Bug548"
+		      >WrappedArrow</a
+		      > a b c)</span
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:WrappedArrow:Generic:5"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Control.Applicative</a
+			></p
+		      > <div class="subs associated-types"
+		      ><p class="caption"
+			>Associated Types</p
+			><p class="src"
+			><span class="keyword"
+			  >type</span
+			  > <a href="#" title="GHC.Generics"
+			  >Rep</a
+			  > (<a href="#" title="Bug548"
+			  >WrappedArrow</a
+			  > a b c) :: <a href="#" title="Data.Kind"
+			  >Type</a
+			  > -&gt; <a href="#" title="Data.Kind"
+			  >Type</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >from</a
+			  > :: <a href="#" title="Bug548"
+			  >WrappedArrow</a
+			  > a b c -&gt; <a href="#" title="GHC.Generics"
+			  >Rep</a
+			  > (<a href="#" title="Bug548"
+			  >WrappedArrow</a
+			  > a b c) x <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >to</a
+			  > :: <a href="#" title="GHC.Generics"
+			  >Rep</a
+			  > (<a href="#" title="Bug548"
+			  >WrappedArrow</a
+			  > a b c) x -&gt; <a href="#" title="Bug548"
+			  >WrappedArrow</a
+			  > a b c <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:WrappedArrow:Rep1:6"
+		      ></span
+		      > <span class="keyword"
+		      >type</span
+		      > <a href="#" title="GHC.Generics"
+		      >Rep1</a
+		      > (<a href="#" title="Bug548"
+		      >WrappedArrow</a
+		      > a b :: <a href="#" title="Data.Kind"
+		      >Type</a
+		      > -&gt; <a href="#" title="Data.Kind"
+		      >Type</a
+		      >)</span
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    ><em
+		      >Since: base-4.7.0.0</em
+		      ></p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:WrappedArrow:Rep1:6"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Control.Applicative</a
+			></p
+		      > <div class="src"
+		      ><span class="keyword"
+			>type</span
+			> <a href="#" title="GHC.Generics"
+			>Rep1</a
+			> (<a href="#" title="Bug548"
+			>WrappedArrow</a
+			> a b :: <a href="#" title="Data.Kind"
+			>Type</a
+			> -&gt; <a href="#" title="Data.Kind"
+			>Type</a
+			>) = <a href="#" title="GHC.Generics"
+			>D1</a
+			> ('<a href="#" title="GHC.Generics"
+			>MetaData</a
+			> &quot;WrappedArrow&quot; &quot;Control.Applicative&quot; &quot;base&quot; '<a href="#" title="Data.Bool"
+			>True</a
+			>) (<a href="#" title="GHC.Generics"
+			>C1</a
+			> ('<a href="#" title="GHC.Generics"
+			>MetaCons</a
+			> &quot;WrapArrow&quot; '<a href="#" title="GHC.Generics"
+			>PrefixI</a
+			> '<a href="#" title="Data.Bool"
+			>True</a
+			>) (<a href="#" title="GHC.Generics"
+			>S1</a
+			> ('<a href="#" title="GHC.Generics"
+			>MetaSel</a
+			> ('<a href="#" title="Data.Maybe"
+			>Just</a
+			> &quot;unwrapArrow&quot;) '<a href="#" title="GHC.Generics"
+			>NoSourceUnpackedness</a
+			> '<a href="#" title="GHC.Generics"
+			>NoSourceStrictness</a
+			> '<a href="#" title="GHC.Generics"
+			>DecidedLazy</a
+			>) (<a href="#" title="GHC.Generics"
+			>Rec1</a
+			> (a b))))</div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:WrappedArrow:Rep:7"
+		      ></span
+		      > <span class="keyword"
+		      >type</span
+		      > <a href="#" title="GHC.Generics"
+		      >Rep</a
+		      > (<a href="#" title="Bug548"
+		      >WrappedArrow</a
+		      > a b c)</span
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    ><em
+		      >Since: base-4.7.0.0</em
+		      ></p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:WrappedArrow:Rep:7"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Control.Applicative</a
+			></p
+		      > <div class="src"
+		      ><span class="keyword"
+			>type</span
+			> <a href="#" title="GHC.Generics"
+			>Rep</a
+			> (<a href="#" title="Bug548"
+			>WrappedArrow</a
+			> a b c) = <a href="#" title="GHC.Generics"
+			>D1</a
+			> ('<a href="#" title="GHC.Generics"
+			>MetaData</a
+			> &quot;WrappedArrow&quot; &quot;Control.Applicative&quot; &quot;base&quot; '<a href="#" title="Data.Bool"
+			>True</a
+			>) (<a href="#" title="GHC.Generics"
+			>C1</a
+			> ('<a href="#" title="GHC.Generics"
+			>MetaCons</a
+			> &quot;WrapArrow&quot; '<a href="#" title="GHC.Generics"
+			>PrefixI</a
+			> '<a href="#" title="Data.Bool"
+			>True</a
+			>) (<a href="#" title="GHC.Generics"
+			>S1</a
+			> ('<a href="#" title="GHC.Generics"
+			>MetaSel</a
+			> ('<a href="#" title="Data.Maybe"
+			>Just</a
+			> &quot;unwrapArrow&quot;) '<a href="#" title="GHC.Generics"
+			>NoSourceUnpackedness</a
+			> '<a href="#" title="GHC.Generics"
+			>NoSourceStrictness</a
+			> '<a href="#" title="GHC.Generics"
+			>DecidedLazy</a
+			>) (<a href="#" title="GHC.Generics"
+			>Rec0</a
+			> (a b c))))</div
+		      ></details
+		    ></td
+		  ></tr
+		></table
+	      ></details
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Bug574.html b/html-test/ref/Bug574.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Bug574.html
@@ -0,0 +1,94 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Bug574</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Bug574</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><a href="#"
+	      >foo</a
+	      > :: <a href="#" title="Data.Int"
+	      >Int</a
+	      > -&gt; <a href="#" title="Data.Int"
+	      >Int</a
+	      > -&gt; <a href="#" title="Data.Int"
+	      >Int</a
+	      ></li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><a id="v:foo" class="def"
+	    >foo</a
+	    > :: <a href="#" title="Data.Int"
+	    >Int</a
+	    > -&gt; <a href="#" title="Data.Int"
+	    >Int</a
+	    > -&gt; <a href="#" title="Data.Int"
+	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Something with a spliced type</p
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Bug6.html b/html-test/ref/Bug6.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Bug6.html
@@ -0,0 +1,340 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Bug6</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Bug6</p
+	></div
+      ><div id="description"
+      ><p class="caption"
+	>Description</p
+	><div class="doc"
+	><p
+	  >Exporting records.</p
+	  ></div
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > <a href="#"
+	      >A</a
+	      > = <a href="#"
+	      >A</a
+	      > <a href="#" title="Data.Int"
+	      >Int</a
+	      ></li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > <a href="#"
+	      >B</a
+	      > = <a href="#"
+	      >B</a
+	      > <a href="#" title="Data.Int"
+	      >Int</a
+	      ></li
+	    ><li class="src short"
+	    ><a href="#"
+	      >b</a
+	      > :: <a href="#" title="Bug6"
+	      >B</a
+	      > -&gt; <a href="#" title="Data.Int"
+	      >Int</a
+	      ></li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > <a href="#"
+	      >C</a
+	      > = <a href="#"
+	      >C</a
+	      > {<ul class="subs"
+	      ><li
+		><a href="#"
+		  >c1</a
+		  > :: <a href="#" title="Data.Int"
+		  >Int</a
+		  ></li
+		><li
+		><a href="#"
+		  >c2</a
+		  > :: <a href="#" title="Data.Int"
+		  >Int</a
+		  ></li
+		></ul
+	      >}</li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > <a href="#"
+	      >D</a
+	      > = <a href="#"
+	      >D</a
+	      > <a href="#" title="Data.Int"
+	      >Int</a
+	      > <a href="#" title="Data.Int"
+	      >Int</a
+	      ></li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >newtype</span
+	      > <a href="#"
+	      >E</a
+	      > = <a href="#"
+	      >E</a
+	      > <a href="#" title="Data.Int"
+	      >Int</a
+	      ></li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:A" class="def"
+	    >A</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >This record is exported without its field</p
+	    ></div
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:A" class="def"
+		  >A</a
+		  > <a href="#" title="Data.Int"
+		  >Int</a
+		  ></td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:B" class="def"
+	    >B</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >.. with its field, but the field is named separately in the export list
+ (the field isn't documented separately since it is already documented here)</p
+	    ></div
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:B" class="def"
+		  >B</a
+		  > <a href="#" title="Data.Int"
+		  >Int</a
+		  ></td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:b" class="def"
+	    >b</a
+	    > :: <a href="#" title="Bug6"
+	    >B</a
+	    > -&gt; <a href="#" title="Data.Int"
+	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:C" class="def"
+	    >C</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >.. with fields names as subordinate names in the export</p
+	    ></div
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:C" class="def"
+		  >C</a
+		  ></td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ><tr
+	      ><td colspan="2"
+		><div class="subs fields"
+		  ><p class="caption"
+		    >Fields</p
+		    ><ul
+		    ><li
+		      ><dfn class="src"
+			><a id="v:c1" class="def"
+			  >c1</a
+			  > :: <a href="#" title="Data.Int"
+			  >Int</a
+			  ></dfn
+			><div class="doc empty"
+			>&nbsp;</div
+			></li
+		      ><li
+		      ><dfn class="src"
+			><a id="v:c2" class="def"
+			  >c2</a
+			  > :: <a href="#" title="Data.Int"
+			  >Int</a
+			  ></dfn
+			><div class="doc empty"
+			>&nbsp;</div
+			></li
+		      ></ul
+		    ></div
+		  ></td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:D" class="def"
+	    >D</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >.. with only some of the fields exported (we can't handle this one -
+ how do we render the declaration?)</p
+	    ></div
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:D" class="def"
+		  >D</a
+		  > <a href="#" title="Data.Int"
+		  >Int</a
+		  > <a href="#" title="Data.Int"
+		  >Int</a
+		  ></td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >newtype</span
+	    > <a id="t:E" class="def"
+	    >E</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >a newtype with a field</p
+	    ></div
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:E" class="def"
+		  >E</a
+		  > <a href="#" title="Data.Int"
+		  >Int</a
+		  ></td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Bug613.html b/html-test/ref/Bug613.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Bug613.html
@@ -0,0 +1,284 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Bug613</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Bug613</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><span class="keyword"
+	      >class</span
+	      > <a href="#"
+	      >Functor</a
+	      > f <span class="keyword"
+	      >where</span
+	      ><ul class="subs"
+	      ><li
+		><a href="#"
+		  >fmap</a
+		  > :: (a -&gt; b) -&gt; f a -&gt; f b</li
+		></ul
+	      ></li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > <a href="#"
+	      >ThreeVars</a
+	      > a0 a b = <a href="#"
+	      >ThreeVars</a
+	      > a b</li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >class</span
+	    > <a id="t:Functor" class="def"
+	    >Functor</a
+	    > f <span class="keyword"
+	    >where</span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs methods"
+	  ><p class="caption"
+	    >Methods</p
+	    ><p class="src"
+	    ><a id="v:fmap" class="def"
+	      >fmap</a
+	      > :: (a -&gt; b) -&gt; f a -&gt; f b <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ></div
+	  ><div class="subs instances"
+	  ><h4 class="instances details-toggle-control details-toggle" data-details-id="i:Functor"
+	    >Instances</h4
+	    ><details id="i:Functor" open="open"
+	    ><summary class="hide-when-js-enabled"
+	      >Instances details</summary
+	      ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:ic:Functor:Functor:1"
+		      ></span
+		      > <a href="#" title="Bug613"
+		      >Functor</a
+		      > (<a href="#" title="Data.Either"
+		      >Either</a
+		      > a)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:ic:Functor:Functor:1"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Bug613</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >fmap</a
+			  > :: (a0 -&gt; b) -&gt; <a href="#" title="Data.Either"
+			  >Either</a
+			  > a a0 -&gt; <a href="#" title="Data.Either"
+			  >Either</a
+			  > a b <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:ic:Functor:Functor:2"
+		      ></span
+		      > <a href="#" title="Bug613"
+		      >Functor</a
+		      > (<a href="#" title="Bug613"
+		      >ThreeVars</a
+		      > a0 a)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:ic:Functor:Functor:2"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Bug613</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >fmap</a
+			  > :: (a1 -&gt; b) -&gt; <a href="#" title="Bug613"
+			  >ThreeVars</a
+			  > a0 a a1 -&gt; <a href="#" title="Bug613"
+			  >ThreeVars</a
+			  > a0 a b <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		></table
+	      ></details
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:ThreeVars" class="def"
+	    >ThreeVars</a
+	    > a0 a b <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Phantom type a0 is added to block the first renaming from a to a0. This ensures that the renamer doesn't create a new conflict</p
+	    ></div
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:ThreeVars" class="def"
+		  >ThreeVars</a
+		  > a b</td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ></table
+	    ></div
+	  ><div class="subs instances"
+	  ><h4 class="instances details-toggle-control details-toggle" data-details-id="i:ThreeVars"
+	    >Instances</h4
+	    ><details id="i:ThreeVars" open="open"
+	    ><summary class="hide-when-js-enabled"
+	      >Instances details</summary
+	      ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:ThreeVars:Functor:1"
+		      ></span
+		      > <a href="#" title="Bug613"
+		      >Functor</a
+		      > (<a href="#" title="Bug613"
+		      >ThreeVars</a
+		      > a0 a)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:ThreeVars:Functor:1"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Bug613</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >fmap</a
+			  > :: (a1 -&gt; b) -&gt; <a href="#" title="Bug613"
+			  >ThreeVars</a
+			  > a0 a a1 -&gt; <a href="#" title="Bug613"
+			  >ThreeVars</a
+			  > a0 a b <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		></table
+	      ></details
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Bug647.html b/html-test/ref/Bug647.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Bug647.html
@@ -0,0 +1,110 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Bug647</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Bug647</p
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >class</span
+	    > <a id="t:Bug647" class="def"
+	    >Bug647</a
+	    > a <span class="keyword"
+	    >where</span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs methods"
+	  ><p class="caption"
+	    >Methods</p
+	    ><p class="src"
+	    ><a id="v:f" class="def"
+	      >f</a
+	      > <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ><div class="subs arguments"
+	    ><p class="caption"
+	      >Arguments</p
+	      ><table
+	      ><tr
+		><td class="src"
+		  >:: a</td
+		  ><td class="doc"
+		  ><p
+		    >doc for arg1</p
+		    ></td
+		  ></tr
+		><tr
+		><td class="src"
+		  >-&gt; a</td
+		  ><td class="doc"
+		  ><p
+		    >doc for arg2</p
+		    ></td
+		  ></tr
+		><tr
+		><td class="src"
+		  >-&gt; a</td
+		  ><td class="doc"
+		  ><p
+		    >doc for arg3</p
+		    ></td
+		  ></tr
+		></table
+	      ></div
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Bug679.html b/html-test/ref/Bug679.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Bug679.html
@@ -0,0 +1,208 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Bug679</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Bug679</p
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:Bar" class="def"
+	    >Bar</a
+	    > a <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:Bar" class="def"
+		  >Bar</a
+		  ></td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ></table
+	    ></div
+	  ><div class="subs instances"
+	  ><h4 class="instances details-toggle-control details-toggle" data-details-id="i:Bar"
+	    >Instances</h4
+	    ><details id="i:Bar" open="open"
+	    ><summary class="hide-when-js-enabled"
+	      >Instances details</summary
+	      ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:Bar:Foo:1"
+		      ></span
+		      > <a href="#" title="Bug679"
+		      >Foo</a
+		      > (<a href="#" title="Bug679"
+		      >Bar</a
+		      > a)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:Bar:Foo:1"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Bug679</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >foo</a
+			  > :: <a href="#" title="Bug679"
+			  >Bar</a
+			  > a -&gt; <a href="#" title="Bug679"
+			  >Bar</a
+			  > a <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		></table
+	      ></details
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >class</span
+	    > <a id="t:Foo" class="def"
+	    >Foo</a
+	    > a <span class="keyword"
+	    >where</span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs methods"
+	  ><p class="caption"
+	    >Methods</p
+	    ><p class="src"
+	    ><a id="v:foo" class="def"
+	      >foo</a
+	      > :: a -&gt; a <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ></div
+	  ><div class="subs instances"
+	  ><h4 class="instances details-toggle-control details-toggle" data-details-id="i:Foo"
+	    >Instances</h4
+	    ><details id="i:Foo" open="open"
+	    ><summary class="hide-when-js-enabled"
+	      >Instances details</summary
+	      ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:ic:Foo:Foo:1"
+		      ></span
+		      > <a href="#" title="Bug679"
+		      >Foo</a
+		      > (<a href="#" title="Bug679"
+		      >Bar</a
+		      > a)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:ic:Foo:Foo:1"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Bug679</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >foo</a
+			  > :: <a href="#" title="Bug679"
+			  >Bar</a
+			  > a -&gt; <a href="#" title="Bug679"
+			  >Bar</a
+			  > a <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		></table
+	      ></details
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Bug7.html b/html-test/ref/Bug7.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Bug7.html
@@ -0,0 +1,215 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Bug7</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Bug7</p
+	></div
+      ><div id="description"
+      ><p class="caption"
+	>Description</p
+	><div class="doc"
+	><p
+	  >This module caused a duplicate instance in the documentation for the Foo
+ type.</p
+	  ></div
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > <a href="#"
+	      >Foo</a
+	      > = <a href="#"
+	      >Foo</a
+	      ></li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >class</span
+	      > <a href="#"
+	      >Bar</a
+	      > x y</li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:Foo" class="def"
+	    >Foo</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >The Foo datatype</p
+	    ></div
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:Foo" class="def"
+		  >Foo</a
+		  ></td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ></table
+	    ></div
+	  ><div class="subs instances"
+	  ><h4 class="instances details-toggle-control details-toggle" data-details-id="i:Foo"
+	    >Instances</h4
+	    ><details id="i:Foo" open="open"
+	    ><summary class="hide-when-js-enabled"
+	      >Instances details</summary
+	      ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:Foo:Bar:1"
+		      ></span
+		      > <a href="#" title="Bug7"
+		      >Bar</a
+		      > <a href="#" title="Bug7"
+		      >Foo</a
+		      > <a href="#" title="Bug7"
+		      >Foo</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    >Just one instance</p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:Foo:Bar:1"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Bug7</a
+			></p
+		      ></details
+		    ></td
+		  ></tr
+		></table
+	      ></details
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >class</span
+	    > <a id="t:Bar" class="def"
+	    >Bar</a
+	    > x y <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >The Bar class</p
+	    ></div
+	  ><div class="subs instances"
+	  ><h4 class="instances details-toggle-control details-toggle" data-details-id="i:Bar"
+	    >Instances</h4
+	    ><details id="i:Bar" open="open"
+	    ><summary class="hide-when-js-enabled"
+	      >Instances details</summary
+	      ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:ic:Bar:Bar:1"
+		      ></span
+		      > <a href="#" title="Bug7"
+		      >Bar</a
+		      > <a href="#" title="Bug7"
+		      >Foo</a
+		      > <a href="#" title="Bug7"
+		      >Foo</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    >Just one instance</p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:ic:Bar:Bar:1"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Bug7</a
+			></p
+		      ></details
+		    ></td
+		  ></tr
+		></table
+	      ></details
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Bug8.html b/html-test/ref/Bug8.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Bug8.html
@@ -0,0 +1,154 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Bug8</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Bug8</p
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:Typ" class="def"
+	    >Typ</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:Type" class="def"
+		  >Type</a
+		  > (<a href="#" title="Bug8"
+		  >Typ</a
+		  >, [<a href="#" title="Bug8"
+		  >Typ</a
+		  >])</td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ><tr
+	      ><td class="src"
+		><a id="v:TFree" class="def"
+		  >TFree</a
+		  > (<a href="#" title="Bug8"
+		  >Typ</a
+		  >, [<a href="#" title="Bug8"
+		  >Typ</a
+		  >])</td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:-45--45--62-" class="def"
+	    >(--&gt;)</a
+	    > :: p -&gt; p -&gt; <a href="#" title="Bug8"
+	    >Typ</a
+	    > <span class="fixity"
+	    >infix 9</span
+	    ><span class="rightedge"
+	    ></span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:-45--45--45--62-" class="def"
+	    >(---&gt;)</a
+	    > :: <a href="#" title="Data.Foldable"
+	    >Foldable</a
+	    > t0 =&gt; t0 t -&gt; <a href="#" title="Bug8"
+	    >Typ</a
+	    > -&gt; <a href="#" title="Bug8"
+	    >Typ</a
+	    > <span class="fixity"
+	    >infix 9</span
+	    ><span class="rightedge"
+	    ></span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:s" class="def"
+	    >s</a
+	    > :: a <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:t" class="def"
+	    >t</a
+	    > :: a <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:main" class="def"
+	    >main</a
+	    > :: a <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Bug85.html b/html-test/ref/Bug85.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Bug85.html
@@ -0,0 +1,142 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Bug85</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Bug85</p
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:Foo" class="def"
+	    >Foo</a
+	    > :: (* -&gt; *) -&gt; * -&gt; * <span class="keyword"
+	    >where</span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:Bar" class="def"
+		  >Bar</a
+		  > :: f x -&gt; <a href="#" title="Bug85"
+		  >Foo</a
+		  > f (f x)</td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:Baz" class="def"
+	    >Baz</a
+	    > :: * <span class="keyword"
+	    >where</span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:Baz-39-" class="def"
+		  >Baz'</a
+		  > :: <a href="#" title="Bug85"
+		  >Baz</a
+		  ></td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:Qux" class="def"
+	    >Qux</a
+	    > <span class="keyword"
+	    >where</span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:Quux" class="def"
+		  >Quux</a
+		  > :: <a href="#" title="Bug85"
+		  >Qux</a
+		  ></td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Bug865.html b/html-test/ref/Bug865.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Bug865.html
@@ -0,0 +1,92 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Bug865</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Bug865</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><a href="#"
+	      >link</a
+	      > :: ()</li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><a id="v:link" class="def"
+	    >link</a
+	    > :: () <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >An emphasized link <a href="#"
+	      >yes <em
+		>this</em
+		> is emphasized while this is
+ <code
+		>monospaced</code
+		></a
+	      >. And here is an image:</p
+	    ><p
+	    ><img src="https://www.haskell.org/static/img/haskell-logo.svg" title="emphasis stripped"
+	       /></p
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Bug923.html b/html-test/ref/Bug923.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Bug923.html
@@ -0,0 +1,204 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Bug923</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Bug923</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > <a href="#"
+	      >T</a
+	      > :: (* -&gt; (*, *)) -&gt; * <span class="keyword"
+	      >where</span
+	      ><ul class="subs"
+	      ><li
+		><a href="#"
+		  >T</a
+		  > :: a -&gt; <a href="#" title="Bug923"
+		  >T</a
+		  > ('<a href="#" title="GHC.Tuple.Prim"
+		  >(,)</a
+		  > a)</li
+		></ul
+	      ></li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:T" class="def"
+	    >T</a
+	    > :: (* -&gt; (*, *)) -&gt; * <span class="keyword"
+	    >where</span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >A promoted tuple type</p
+	    ></div
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:T" class="def"
+		  >T</a
+		  > :: a -&gt; <a href="#" title="Bug923"
+		  >T</a
+		  > ('<a href="#" title="GHC.Tuple.Prim"
+		  >(,)</a
+		  > a)</td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ></table
+	    ></div
+	  ><div class="subs instances"
+	  ><h4 class="instances details-toggle-control details-toggle" data-details-id="i:T"
+	    >Instances</h4
+	    ><details id="i:T" open="open"
+	    ><summary class="hide-when-js-enabled"
+	      >Instances details</summary
+	      ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:T:Eq:1"
+		      ></span
+		      > <a href="#" title="Data.Eq"
+		      >Eq</a
+		      > a =&gt; <a href="#" title="Data.Eq"
+		      >Eq</a
+		      > (<a href="#" title="Bug923"
+		      >T</a
+		      > ('<a href="#" title="GHC.Tuple.Prim"
+		      >(,)</a
+		      > a :: <a href="#" title="Data.Kind"
+		      >Type</a
+		      > -&gt; (<a href="#" title="Data.Kind"
+		      >Type</a
+		      >, <a href="#" title="Data.Kind"
+		      >Type</a
+		      >)))</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    >A promoted tuple type in an instance</p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:T:Eq:1"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Bug923</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >(==)</a
+			  > :: <a href="#" title="Bug923"
+			  >T</a
+			  > ('<a href="#" title="GHC.Tuple.Prim"
+			  >(,)</a
+			  > a) -&gt; <a href="#" title="Bug923"
+			  >T</a
+			  > ('<a href="#" title="GHC.Tuple.Prim"
+			  >(,)</a
+			  > a) -&gt; <a href="#" title="Data.Bool"
+			  >Bool</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >(/=)</a
+			  > :: <a href="#" title="Bug923"
+			  >T</a
+			  > ('<a href="#" title="GHC.Tuple.Prim"
+			  >(,)</a
+			  > a) -&gt; <a href="#" title="Bug923"
+			  >T</a
+			  > ('<a href="#" title="GHC.Tuple.Prim"
+			  >(,)</a
+			  > a) -&gt; <a href="#" title="Data.Bool"
+			  >Bool</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		></table
+	      ></details
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Bug952.html b/html-test/ref/Bug952.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Bug952.html
@@ -0,0 +1,82 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Bug952</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Bug952</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><a href="#"
+	      >foo</a
+	      > :: ()</li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><a id="v:foo" class="def"
+	    >foo</a
+	    > :: () <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >See 'case', 'of', '--' compared to 'Q.case', 'Q.of', 'Q.--'</p
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Bug953.html b/html-test/ref/Bug953.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Bug953.html
@@ -0,0 +1,154 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Bug953</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Bug953</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > <a href="#"
+	      >Foo</a
+	      > = <a href="#"
+	      >Foo'</a
+	      ></li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > <a href="#"
+	      >Bar</a
+	      > = <a href="#"
+	      >Bar'</a
+	      ></li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:Foo" class="def"
+	    >Foo</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >A foo</p
+	    ><h4 class="subheading details-toggle-control details-toggle" data-details-id="ch:Foo0"
+	    >Examples</h4
+	    ><details id="ch:Foo0"
+	    ><summary class="hide-when-js-enabled"
+	      >Expand</summary
+	      ><p
+	      >Foo example body</p
+	      ></details
+	    ></div
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:Foo-39-" class="def"
+		  >Foo'</a
+		  ></td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:Bar" class="def"
+	    >Bar</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >A bar</p
+	    ><h4 class="subheading details-toggle-control details-toggle" data-details-id="ch:Bar0"
+	    >Examples</h4
+	    ><details id="ch:Bar0"
+	    ><summary class="hide-when-js-enabled"
+	      >Expand</summary
+	      ><p
+	      >Bar example body</p
+	      ></details
+	    ></div
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:Bar-39-" class="def"
+		  >Bar'</a
+		  ></td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Bug973.html b/html-test/ref/Bug973.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Bug973.html
@@ -0,0 +1,178 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Bug973</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Bug973</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><a href="#"
+	      >showRead</a
+	      > :: <span class="keyword"
+	      >forall</span
+	      > a b. (<a href="#" title="Text.Show"
+	      >Show</a
+	      > a, <a href="#" title="Text.Read"
+	      >Read</a
+	      > b) =&gt; a -&gt; b</li
+	    ><li class="src short"
+	    ><a href="#"
+	      >showRead'</a
+	      > :: <span class="keyword"
+	      >forall</span
+	      > b a. (<a href="#" title="Text.Show"
+	      >Show</a
+	      > a, <a href="#" title="Text.Read"
+	      >Read</a
+	      > b) =&gt; a -&gt; b</li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><a id="v:showRead" class="def"
+	    >showRead</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs arguments"
+	  ><p class="caption"
+	    >Arguments</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		>:: <span class="keyword"
+		  >forall</span
+		  > a b. (<a href="#" title="Text.Show"
+		  >Show</a
+		  > a, <a href="#" title="Text.Read"
+		  >Read</a
+		  > b)</td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ><tr
+	      ><td class="src"
+		>=&gt; a</td
+		><td class="doc"
+		><p
+		  >this gets turned into a string...</p
+		  ></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		>-&gt; b</td
+		><td class="doc"
+		><p
+		  >...from which this is read</p
+		  ></td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:showRead-39-" class="def"
+	    >showRead'</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs arguments"
+	  ><p class="caption"
+	    >Arguments</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		>:: <span class="keyword"
+		  >forall</span
+		  > b a. (<a href="#" title="Text.Show"
+		  >Show</a
+		  > a, <a href="#" title="Text.Read"
+		  >Read</a
+		  > b)</td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ><tr
+	      ><td class="src"
+		>=&gt; a</td
+		><td class="doc"
+		><p
+		  >this gets turned into a string...</p
+		  ></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		>-&gt; b</td
+		><td class="doc"
+		><p
+		  >...from which this is read</p
+		  ></td
+		></tr
+	      ></table
+	    ></div
+	  ><div class="doc"
+	  ><p
+	    >Same as <code
+	      ><a href="#" title="Bug973"
+		>showRead</a
+		></code
+	      >, but with type variable order flipped</p
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/BugDeprecated.html b/html-test/ref/BugDeprecated.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/BugDeprecated.html
@@ -0,0 +1,200 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >BugDeprecated</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>BugDeprecated</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><a href="#"
+	      >foo</a
+	      > :: <a href="#" title="Data.Int"
+	      >Int</a
+	      ></li
+	    ><li class="src short"
+	    ><a href="#"
+	      >bar</a
+	      > :: <a href="#" title="Data.Int"
+	      >Int</a
+	      ></li
+	    ><li class="src short"
+	    ><a href="#"
+	      >baz</a
+	      > :: <a href="#" title="Data.Int"
+	      >Int</a
+	      ></li
+	    ><li class="src short"
+	    ><a href="#"
+	      >one</a
+	      > :: <a href="#" title="Data.Int"
+	      >Int</a
+	      ></li
+	    ><li class="src short"
+	    ><a href="#"
+	      >two</a
+	      > :: <a href="#" title="Data.Int"
+	      >Int</a
+	      ></li
+	    ><li class="src short"
+	    ><a href="#"
+	      >three</a
+	      > :: <a href="#" title="Data.Int"
+	      >Int</a
+	      ></li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><a id="v:foo" class="def"
+	    >foo</a
+	    > :: <a href="#" title="Data.Int"
+	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><div class="warning"
+	    ><p
+	      >Deprecated: for foo</p
+	      ></div
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:bar" class="def"
+	    >bar</a
+	    > :: <a href="#" title="Data.Int"
+	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><div class="warning"
+	    ><p
+	      >Deprecated: for bar</p
+	      ></div
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:baz" class="def"
+	    >baz</a
+	    > :: <a href="#" title="Data.Int"
+	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><div class="warning"
+	    ><p
+	      >Deprecated: for baz</p
+	      ></div
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:one" class="def"
+	    >one</a
+	    > :: <a href="#" title="Data.Int"
+	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><div class="warning"
+	    ><p
+	      >Deprecated: for one</p
+	      ></div
+	    ><p
+	    >some documentation for one</p
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:two" class="def"
+	    >two</a
+	    > :: <a href="#" title="Data.Int"
+	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><div class="warning"
+	    ><p
+	      >Deprecated: for two</p
+	      ></div
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:three" class="def"
+	    >three</a
+	    > :: <a href="#" title="Data.Int"
+	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><div class="warning"
+	    ><p
+	      >Deprecated: for three</p
+	      ></div
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/BugExportHeadings.html b/html-test/ref/BugExportHeadings.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/BugExportHeadings.html
@@ -0,0 +1,234 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >BugExportHeadings</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>BugExportHeadings</p
+	></div
+      ><div id="table-of-contents"
+      ><div id="contents-list"
+	><p class="caption" onclick="window.scrollTo(0,0)"
+	  >Contents</p
+	  ><ul
+	  ><li
+	    ><a href="#"
+	      >Foo</a
+	      ></li
+	    ><li
+	    ><a href="#"
+	      >Bar</a
+	      ></li
+	    ><li
+	    ><a href="#"
+	      >Baz</a
+	      ></li
+	    ><li
+	    ><a href="#"
+	      >One</a
+	      ></li
+	    ><li
+	    ><a href="#"
+	      >Two</a
+	      ></li
+	    ><li
+	    ><a href="#"
+	      >Three</a
+	      ></li
+	    ></ul
+	  ></div
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><a href="#"
+	      >foo</a
+	      > :: <a href="#" title="Data.Int"
+	      >Int</a
+	      ></li
+	    ><li class="src short"
+	    ><a href="#"
+	      >bar</a
+	      > :: <a href="#" title="Data.Int"
+	      >Int</a
+	      ></li
+	    ><li class="src short"
+	    ><a href="#"
+	      >baz</a
+	      > :: <a href="#" title="Data.Int"
+	      >Int</a
+	      ></li
+	    ><li class="src short"
+	    ><a href="#"
+	      >one</a
+	      > :: <a href="#" title="Data.Int"
+	      >Int</a
+	      ></li
+	    ><li class="src short"
+	    ><a href="#"
+	      >two</a
+	      > :: <a href="#" title="Data.Int"
+	      >Int</a
+	      ></li
+	    ><li class="src short"
+	    ><a href="#"
+	      >three</a
+	      > :: <a href="#" title="Data.Int"
+	      >Int</a
+	      ></li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><a href="#" id="g:1"
+	><h1
+	  >Foo</h1
+	  ></a
+	><div class="top"
+	><p class="src"
+	  ><a id="v:foo" class="def"
+	    >foo</a
+	    > :: <a href="#" title="Data.Int"
+	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	><a href="#" id="g:2"
+	><h1
+	  >Bar</h1
+	  ></a
+	><div class="top"
+	><p class="src"
+	  ><a id="v:bar" class="def"
+	    >bar</a
+	    > :: <a href="#" title="Data.Int"
+	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	><a href="#" id="g:3"
+	><h1
+	  >Baz</h1
+	  ></a
+	><div class="top"
+	><p class="src"
+	  ><a id="v:baz" class="def"
+	    >baz</a
+	    > :: <a href="#" title="Data.Int"
+	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	><a href="#" id="g:4"
+	><h1
+	  >One</h1
+	  ></a
+	><div class="top"
+	><p class="src"
+	  ><a id="v:one" class="def"
+	    >one</a
+	    > :: <a href="#" title="Data.Int"
+	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><div class="warning"
+	    ><p
+	      >Deprecated: for one</p
+	      ></div
+	    ></div
+	  ></div
+	><a href="#" id="g:5"
+	><h1
+	  >Two</h1
+	  ></a
+	><div class="top"
+	><p class="src"
+	  ><a id="v:two" class="def"
+	    >two</a
+	    > :: <a href="#" title="Data.Int"
+	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><div class="warning"
+	    ><p
+	      >Deprecated: for two</p
+	      ></div
+	    ></div
+	  ></div
+	><a href="#" id="g:6"
+	><h1
+	  >Three</h1
+	  ></a
+	><div class="top"
+	><p class="src"
+	  ><a id="v:three" class="def"
+	    >three</a
+	    > :: <a href="#" title="Data.Int"
+	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><div class="warning"
+	    ><p
+	      >Deprecated: for three</p
+	      ></div
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Bugs.html b/html-test/ref/Bugs.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Bugs.html
@@ -0,0 +1,84 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Bugs</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Bugs</p
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:A" class="def"
+	    >A</a
+	    > a <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:A" class="def"
+		  >A</a
+		  > a (a -&gt; <a href="#" title="Data.Int"
+		  >Int</a
+		  >)</td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/BundledPatterns.html b/html-test/ref/BundledPatterns.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/BundledPatterns.html
@@ -0,0 +1,464 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >BundledPatterns</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>BundledPatterns</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > <a href="#"
+	      >Vec</a
+	      > :: <a href="#" title="GHC.TypeNats"
+	      >Nat</a
+	      > -&gt; * -&gt; * <span class="keyword"
+	      >where</span
+	      ><ul class="subs"
+	      ><li
+		><a href="#"
+		  >Nil</a
+		  > :: <a href="#" title="BundledPatterns"
+		  >Vec</a
+		  > 0 a</li
+		><li
+		><span class="keyword"
+		  >pattern</span
+		  > <a href="#"
+		  >(:&gt;)</a
+		  > :: a -&gt; <a href="#" title="BundledPatterns"
+		  >Vec</a
+		  > n a -&gt; <a href="#" title="BundledPatterns"
+		  >Vec</a
+		  > (n <a href="#" title="Bug310"
+		  >+</a
+		  > 1) a</li
+		></ul
+	      ></li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > <a href="#"
+	      >RTree</a
+	      > :: <a href="#" title="GHC.TypeNats"
+	      >Nat</a
+	      > -&gt; * -&gt; * <span class="keyword"
+	      >where</span
+	      ><ul class="subs"
+	      ><li
+		><span class="keyword"
+		  >pattern</span
+		  > <a href="#"
+		  >LR</a
+		  > :: a -&gt; <a href="#" title="BundledPatterns"
+		  >RTree</a
+		  > 0 a</li
+		><li
+		><span class="keyword"
+		  >pattern</span
+		  > <a href="#"
+		  >BR</a
+		  > :: <a href="#" title="BundledPatterns"
+		  >RTree</a
+		  > d a -&gt; <a href="#" title="BundledPatterns"
+		  >RTree</a
+		  > d a -&gt; <a href="#" title="BundledPatterns"
+		  >RTree</a
+		  > (d <a href="#" title="Bug310"
+		  >+</a
+		  > 1) a</li
+		></ul
+	      ></li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:Vec" class="def"
+	    >Vec</a
+	    > :: <a href="#" title="GHC.TypeNats"
+	    >Nat</a
+	    > -&gt; * -&gt; * <span class="keyword"
+	    >where</span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Fixed size vectors.</p
+	    ><ul
+	    ><li
+	      >Lists with their length encoded in their type</li
+	      ><li
+	      ><code
+		><a href="#" title="BundledPatterns"
+		  >Vec</a
+		  ></code
+		>tor elements have an <strong
+		>ASCENDING</strong
+		> subscript starting from 0 and
+   ending at <code
+		><code
+		  ><a href="#" title="Data.Foldable"
+		    >length</a
+		    ></code
+		  > - 1</code
+		>.</li
+	      ></ul
+	    ></div
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:Nil" class="def"
+		  >Nil</a
+		  > :: <a href="#" title="BundledPatterns"
+		  >Vec</a
+		  > 0 a</td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ></table
+	    ></div
+	  ><div class="subs bundled-patterns"
+	  ><p class="caption"
+	    >Bundled Patterns</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><span class="keyword"
+		  >pattern</span
+		  > <a id="v::-62-" class="def"
+		  >(:&gt;)</a
+		  > :: a -&gt; <a href="#" title="BundledPatterns"
+		  >Vec</a
+		  > n a -&gt; <a href="#" title="BundledPatterns"
+		  >Vec</a
+		  > (n <a href="#" title="Bug310"
+		  >+</a
+		  > 1) a <span class="fixity"
+		  >infixr 5</span
+		  ><span class="rightedge"
+		  ></span
+		  ></td
+		><td class="doc"
+		><p
+		  >Add an element to the head of a vector.</p
+		  ><pre class="screen"
+		  ><code class="prompt"
+		    >&gt;&gt;&gt; </code
+		    ><strong class="userinput"
+		    ><code
+		      >3:&gt;4:&gt;5:&gt;Nil
+</code
+		      ></strong
+		    >&lt;3,4,5&gt;
+<code class="prompt"
+		    >&gt;&gt;&gt; </code
+		    ><strong class="userinput"
+		    ><code
+		      >let x = 3:&gt;4:&gt;5:&gt;Nil
+</code
+		      ></strong
+		    ><code class="prompt"
+		    >&gt;&gt;&gt; </code
+		    ><strong class="userinput"
+		    ><code
+		      >:t x
+</code
+		      ></strong
+		    >x :: Num a =&gt; Vec 3 a
+</pre
+		  ><p
+		  >Can be used as a pattern:</p
+		  ><pre class="screen"
+		  ><code class="prompt"
+		    >&gt;&gt;&gt; </code
+		    ><strong class="userinput"
+		    ><code
+		      >let f (x :&gt; y :&gt; _) = x + y
+</code
+		      ></strong
+		    ><code class="prompt"
+		    >&gt;&gt;&gt; </code
+		    ><strong class="userinput"
+		    ><code
+		      >:t f
+</code
+		      ></strong
+		    >f :: Num a =&gt; Vec ((n + 1) + 1) a -&gt; a
+<code class="prompt"
+		    >&gt;&gt;&gt; </code
+		    ><strong class="userinput"
+		    ><code
+		      >f (3:&gt;4:&gt;5:&gt;6:&gt;7:&gt;Nil)
+</code
+		      ></strong
+		    >7
+</pre
+		  ><p
+		  >Also in conjunctions with (<code
+		    >:&lt;</code
+		    >):</p
+		  ><pre class="screen"
+		  ><code class="prompt"
+		    >&gt;&gt;&gt; </code
+		    ><strong class="userinput"
+		    ><code
+		      >let g (a :&gt; b :&gt; (_ :&lt; y :&lt; x)) = a + b +  x + y
+</code
+		      ></strong
+		    ><code class="prompt"
+		    >&gt;&gt;&gt; </code
+		    ><strong class="userinput"
+		    ><code
+		      >:t g
+</code
+		      ></strong
+		    >g :: Num a =&gt; Vec ((((n + 1) + 1) + 1) + 1) a -&gt; a
+<code class="prompt"
+		    >&gt;&gt;&gt; </code
+		    ><strong class="userinput"
+		    ><code
+		      >g (1:&gt;2:&gt;3:&gt;4:&gt;5:&gt;Nil)
+</code
+		      ></strong
+		    >12
+</pre
+		  ></td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:RTree" class="def"
+	    >RTree</a
+	    > :: <a href="#" title="GHC.TypeNats"
+	    >Nat</a
+	    > -&gt; * -&gt; * <span class="keyword"
+	    >where</span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Perfect depth binary tree.</p
+	    ><ul
+	    ><li
+	      >Only has elements at the leaf of the tree</li
+	      ><li
+	      >A tree of depth <em
+		>d</em
+		> has <em
+		>2^d</em
+		> elements.</li
+	      ></ul
+	    ></div
+	  ><div class="subs bundled-patterns"
+	  ><p class="caption"
+	    >Bundled Patterns</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><span class="keyword"
+		  >pattern</span
+		  > <a id="v:LR" class="def"
+		  >LR</a
+		  > :: a -&gt; <a href="#" title="BundledPatterns"
+		  >RTree</a
+		  > 0 a</td
+		><td class="doc"
+		><p
+		  >Leaf of a perfect depth tree</p
+		  ><pre class="screen"
+		  ><code class="prompt"
+		    >&gt;&gt;&gt; </code
+		    ><strong class="userinput"
+		    ><code
+		      >LR 1
+</code
+		      ></strong
+		    >1
+<code class="prompt"
+		    >&gt;&gt;&gt; </code
+		    ><strong class="userinput"
+		    ><code
+		      >let x = LR 1
+</code
+		      ></strong
+		    ><code class="prompt"
+		    >&gt;&gt;&gt; </code
+		    ><strong class="userinput"
+		    ><code
+		      >:t x
+</code
+		      ></strong
+		    >x :: Num a =&gt; RTree 0 a
+</pre
+		  ><p
+		  >Can be used as a pattern:</p
+		  ><pre class="screen"
+		  ><code class="prompt"
+		    >&gt;&gt;&gt; </code
+		    ><strong class="userinput"
+		    ><code
+		      >let f (LR a) (LR b) = a + b
+</code
+		      ></strong
+		    ><code class="prompt"
+		    >&gt;&gt;&gt; </code
+		    ><strong class="userinput"
+		    ><code
+		      >:t f
+</code
+		      ></strong
+		    >f :: Num a =&gt; RTree 0 a -&gt; RTree 0 a -&gt; a
+<code class="prompt"
+		    >&gt;&gt;&gt; </code
+		    ><strong class="userinput"
+		    ><code
+		      >f (LR 1) (LR 2)
+</code
+		      ></strong
+		    >3
+</pre
+		  ></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		><span class="keyword"
+		  >pattern</span
+		  > <a id="v:BR" class="def"
+		  >BR</a
+		  > :: <a href="#" title="BundledPatterns"
+		  >RTree</a
+		  > d a -&gt; <a href="#" title="BundledPatterns"
+		  >RTree</a
+		  > d a -&gt; <a href="#" title="BundledPatterns"
+		  >RTree</a
+		  > (d <a href="#" title="Bug310"
+		  >+</a
+		  > 1) a</td
+		><td class="doc"
+		><p
+		  >Branch of a perfect depth tree</p
+		  ><pre class="screen"
+		  ><code class="prompt"
+		    >&gt;&gt;&gt; </code
+		    ><strong class="userinput"
+		    ><code
+		      >BR (LR 1) (LR 2)
+</code
+		      ></strong
+		    >&lt;1,2&gt;
+<code class="prompt"
+		    >&gt;&gt;&gt; </code
+		    ><strong class="userinput"
+		    ><code
+		      >let x = BR (LR 1) (LR 2)
+</code
+		      ></strong
+		    ><code class="prompt"
+		    >&gt;&gt;&gt; </code
+		    ><strong class="userinput"
+		    ><code
+		      >:t x
+</code
+		      ></strong
+		    >x :: Num a =&gt; RTree 1 a
+</pre
+		  ><p
+		  >Case be used a pattern:</p
+		  ><pre class="screen"
+		  ><code class="prompt"
+		    >&gt;&gt;&gt; </code
+		    ><strong class="userinput"
+		    ><code
+		      >let f (BR (LR a) (LR b)) = LR (a + b)
+</code
+		      ></strong
+		    ><code class="prompt"
+		    >&gt;&gt;&gt; </code
+		    ><strong class="userinput"
+		    ><code
+		      >:t f
+</code
+		      ></strong
+		    >f :: Num a =&gt; RTree 1 a -&gt; RTree 0 a
+<code class="prompt"
+		    >&gt;&gt;&gt; </code
+		    ><strong class="userinput"
+		    ><code
+		      >f (BR (LR 1) (LR 2))
+</code
+		      ></strong
+		    >3
+</pre
+		  ></td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/BundledPatterns2.html b/html-test/ref/BundledPatterns2.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/BundledPatterns2.html
@@ -0,0 +1,462 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >BundledPatterns2</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>BundledPatterns2</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > <a href="#"
+	      >Vec</a
+	      > :: <a href="#" title="GHC.TypeNats"
+	      >Nat</a
+	      > -&gt; * -&gt; * <span class="keyword"
+	      >where</span
+	      ><ul class="subs"
+	      ><li
+		><span class="keyword"
+		  >pattern</span
+		  > <a href="#"
+		  >(:&gt;)</a
+		  > :: a -&gt; <a href="#" title="BundledPatterns2"
+		  >Vec</a
+		  > n a -&gt; <a href="#" title="BundledPatterns2"
+		  >Vec</a
+		  > (n <a href="#" title="Bug310"
+		  >+</a
+		  > 1) a</li
+		><li
+		><span class="keyword"
+		  >pattern</span
+		  > <a href="#"
+		  >Empty</a
+		  > :: <a href="#" title="BundledPatterns2"
+		  >Vec</a
+		  > 0 a</li
+		></ul
+	      ></li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > <a href="#"
+	      >RTree</a
+	      > :: <a href="#" title="GHC.TypeNats"
+	      >Nat</a
+	      > -&gt; * -&gt; * <span class="keyword"
+	      >where</span
+	      ><ul class="subs"
+	      ><li
+		><span class="keyword"
+		  >pattern</span
+		  > <a href="#"
+		  >LR</a
+		  > :: a -&gt; <a href="#" title="BundledPatterns2"
+		  >RTree</a
+		  > 0 a</li
+		><li
+		><span class="keyword"
+		  >pattern</span
+		  > <a href="#"
+		  >BR</a
+		  > :: <a href="#" title="BundledPatterns2"
+		  >RTree</a
+		  > d a -&gt; <a href="#" title="BundledPatterns2"
+		  >RTree</a
+		  > d a -&gt; <a href="#" title="BundledPatterns2"
+		  >RTree</a
+		  > (d <a href="#" title="Bug310"
+		  >+</a
+		  > 1) a</li
+		></ul
+	      ></li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:Vec" class="def"
+	    >Vec</a
+	    > :: <a href="#" title="GHC.TypeNats"
+	    >Nat</a
+	    > -&gt; * -&gt; * <span class="keyword"
+	    >where</span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Fixed size vectors.</p
+	    ><ul
+	    ><li
+	      >Lists with their length encoded in their type</li
+	      ><li
+	      ><code
+		><a href="#" title="BundledPatterns2"
+		  >Vec</a
+		  ></code
+		>tor elements have an <strong
+		>ASCENDING</strong
+		> subscript starting from 0 and
+   ending at <code
+		><code
+		  ><a href="#" title="Data.Foldable"
+		    >length</a
+		    ></code
+		  > - 1</code
+		>.</li
+	      ></ul
+	    ></div
+	  ><div class="subs bundled-patterns"
+	  ><p class="caption"
+	    >Bundled Patterns</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><span class="keyword"
+		  >pattern</span
+		  > <a id="v::-62-" class="def"
+		  >(:&gt;)</a
+		  > :: a -&gt; <a href="#" title="BundledPatterns2"
+		  >Vec</a
+		  > n a -&gt; <a href="#" title="BundledPatterns2"
+		  >Vec</a
+		  > (n <a href="#" title="Bug310"
+		  >+</a
+		  > 1) a <span class="fixity"
+		  >infixr 5</span
+		  ><span class="rightedge"
+		  ></span
+		  ></td
+		><td class="doc"
+		><p
+		  >Add an element to the head of a vector.</p
+		  ><pre class="screen"
+		  ><code class="prompt"
+		    >&gt;&gt;&gt; </code
+		    ><strong class="userinput"
+		    ><code
+		      >3:&gt;4:&gt;5:&gt;Nil
+</code
+		      ></strong
+		    >&lt;3,4,5&gt;
+<code class="prompt"
+		    >&gt;&gt;&gt; </code
+		    ><strong class="userinput"
+		    ><code
+		      >let x = 3:&gt;4:&gt;5:&gt;Nil
+</code
+		      ></strong
+		    ><code class="prompt"
+		    >&gt;&gt;&gt; </code
+		    ><strong class="userinput"
+		    ><code
+		      >:t x
+</code
+		      ></strong
+		    >x :: Num a =&gt; Vec 3 a
+</pre
+		  ><p
+		  >Can be used as a pattern:</p
+		  ><pre class="screen"
+		  ><code class="prompt"
+		    >&gt;&gt;&gt; </code
+		    ><strong class="userinput"
+		    ><code
+		      >let f (x :&gt; y :&gt; _) = x + y
+</code
+		      ></strong
+		    ><code class="prompt"
+		    >&gt;&gt;&gt; </code
+		    ><strong class="userinput"
+		    ><code
+		      >:t f
+</code
+		      ></strong
+		    >f :: Num a =&gt; Vec ((n + 1) + 1) a -&gt; a
+<code class="prompt"
+		    >&gt;&gt;&gt; </code
+		    ><strong class="userinput"
+		    ><code
+		      >f (3:&gt;4:&gt;5:&gt;6:&gt;7:&gt;Nil)
+</code
+		      ></strong
+		    >7
+</pre
+		  ><p
+		  >Also in conjunctions with (<code
+		    >:&lt;</code
+		    >):</p
+		  ><pre class="screen"
+		  ><code class="prompt"
+		    >&gt;&gt;&gt; </code
+		    ><strong class="userinput"
+		    ><code
+		      >let g (a :&gt; b :&gt; (_ :&lt; y :&lt; x)) = a + b +  x + y
+</code
+		      ></strong
+		    ><code class="prompt"
+		    >&gt;&gt;&gt; </code
+		    ><strong class="userinput"
+		    ><code
+		      >:t g
+</code
+		      ></strong
+		    >g :: Num a =&gt; Vec ((((n + 1) + 1) + 1) + 1) a -&gt; a
+<code class="prompt"
+		    >&gt;&gt;&gt; </code
+		    ><strong class="userinput"
+		    ><code
+		      >g (1:&gt;2:&gt;3:&gt;4:&gt;5:&gt;Nil)
+</code
+		      ></strong
+		    >12
+</pre
+		  ></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		><span class="keyword"
+		  >pattern</span
+		  > <a id="v:Empty" class="def"
+		  >Empty</a
+		  > :: <a href="#" title="BundledPatterns2"
+		  >Vec</a
+		  > 0 a</td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:RTree" class="def"
+	    >RTree</a
+	    > :: <a href="#" title="GHC.TypeNats"
+	    >Nat</a
+	    > -&gt; * -&gt; * <span class="keyword"
+	    >where</span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Perfect depth binary tree.</p
+	    ><ul
+	    ><li
+	      >Only has elements at the leaf of the tree</li
+	      ><li
+	      >A tree of depth <em
+		>d</em
+		> has <em
+		>2^d</em
+		> elements.</li
+	      ></ul
+	    ></div
+	  ><div class="subs bundled-patterns"
+	  ><p class="caption"
+	    >Bundled Patterns</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><span class="keyword"
+		  >pattern</span
+		  > <a id="v:LR" class="def"
+		  >LR</a
+		  > :: a -&gt; <a href="#" title="BundledPatterns2"
+		  >RTree</a
+		  > 0 a</td
+		><td class="doc"
+		><p
+		  >Leaf of a perfect depth tree</p
+		  ><pre class="screen"
+		  ><code class="prompt"
+		    >&gt;&gt;&gt; </code
+		    ><strong class="userinput"
+		    ><code
+		      >LR 1
+</code
+		      ></strong
+		    >1
+<code class="prompt"
+		    >&gt;&gt;&gt; </code
+		    ><strong class="userinput"
+		    ><code
+		      >let x = LR 1
+</code
+		      ></strong
+		    ><code class="prompt"
+		    >&gt;&gt;&gt; </code
+		    ><strong class="userinput"
+		    ><code
+		      >:t x
+</code
+		      ></strong
+		    >x :: Num a =&gt; RTree 0 a
+</pre
+		  ><p
+		  >Can be used as a pattern:</p
+		  ><pre class="screen"
+		  ><code class="prompt"
+		    >&gt;&gt;&gt; </code
+		    ><strong class="userinput"
+		    ><code
+		      >let f (LR a) (LR b) = a + b
+</code
+		      ></strong
+		    ><code class="prompt"
+		    >&gt;&gt;&gt; </code
+		    ><strong class="userinput"
+		    ><code
+		      >:t f
+</code
+		      ></strong
+		    >f :: Num a =&gt; RTree 0 a -&gt; RTree 0 a -&gt; a
+<code class="prompt"
+		    >&gt;&gt;&gt; </code
+		    ><strong class="userinput"
+		    ><code
+		      >f (LR 1) (LR 2)
+</code
+		      ></strong
+		    >3
+</pre
+		  ></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		><span class="keyword"
+		  >pattern</span
+		  > <a id="v:BR" class="def"
+		  >BR</a
+		  > :: <a href="#" title="BundledPatterns2"
+		  >RTree</a
+		  > d a -&gt; <a href="#" title="BundledPatterns2"
+		  >RTree</a
+		  > d a -&gt; <a href="#" title="BundledPatterns2"
+		  >RTree</a
+		  > (d <a href="#" title="Bug310"
+		  >+</a
+		  > 1) a</td
+		><td class="doc"
+		><p
+		  >Branch of a perfect depth tree</p
+		  ><pre class="screen"
+		  ><code class="prompt"
+		    >&gt;&gt;&gt; </code
+		    ><strong class="userinput"
+		    ><code
+		      >BR (LR 1) (LR 2)
+</code
+		      ></strong
+		    >&lt;1,2&gt;
+<code class="prompt"
+		    >&gt;&gt;&gt; </code
+		    ><strong class="userinput"
+		    ><code
+		      >let x = BR (LR 1) (LR 2)
+</code
+		      ></strong
+		    ><code class="prompt"
+		    >&gt;&gt;&gt; </code
+		    ><strong class="userinput"
+		    ><code
+		      >:t x
+</code
+		      ></strong
+		    >x :: Num a =&gt; RTree 1 a
+</pre
+		  ><p
+		  >Case be used a pattern:</p
+		  ><pre class="screen"
+		  ><code class="prompt"
+		    >&gt;&gt;&gt; </code
+		    ><strong class="userinput"
+		    ><code
+		      >let f (BR (LR a) (LR b)) = LR (a + b)
+</code
+		      ></strong
+		    ><code class="prompt"
+		    >&gt;&gt;&gt; </code
+		    ><strong class="userinput"
+		    ><code
+		      >:t f
+</code
+		      ></strong
+		    >f :: Num a =&gt; RTree 1 a -&gt; RTree 0 a
+<code class="prompt"
+		    >&gt;&gt;&gt; </code
+		    ><strong class="userinput"
+		    ><code
+		      >f (BR (LR 1) (LR 2))
+</code
+		      ></strong
+		    >3
+</pre
+		  ></td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/ConstructorArgs.html b/html-test/ref/ConstructorArgs.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/ConstructorArgs.html
@@ -0,0 +1,728 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >ConstructorArgs</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>ConstructorArgs</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > <a href="#"
+	      >Foo</a
+	      ><ul class="subs"
+	      ><li
+		>= <a href="#"
+		  >Rec</a
+		  > { <ul class="subs"
+		  ><li
+		    ><a href="#"
+		      >x</a
+		      > :: <a href="#" title="Data.String"
+		      >String</a
+		      ></li
+		    ><li
+		    ><a href="#"
+		      >y</a
+		      > :: <a href="#" title="Data.String"
+		      >String</a
+		      ></li
+		    ></ul
+		  > }</li
+		><li
+		>| <a href="#"
+		  >Baz</a
+		  > <a href="#" title="Data.Int"
+		  >Int</a
+		  > <a href="#" title="Data.String"
+		  >String</a
+		  ></li
+		><li
+		>| <a href="#"
+		  >Boa</a
+		  > !<a href="#" title="Data.Int"
+		  >Int</a
+		  > !<a href="#" title="Data.String"
+		  >String</a
+		  ></li
+		><li
+		>| <a href="#" title="Data.Int"
+		  >Int</a
+		  > <a href="#"
+		  >:|</a
+		  > <a href="#" title="Data.String"
+		  >String</a
+		  ></li
+		><li
+		>| <a href="#" title="Data.Int"
+		  >Int</a
+		  > <a href="#"
+		  >:*</a
+		  > <a href="#" title="Data.String"
+		  >String</a
+		  ></li
+		></ul
+	      ></li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > <a href="#"
+	      >Boo</a
+	      > <span class="keyword"
+	      >where</span
+	      ><ul class="subs"
+	      ><li
+		><a href="#"
+		  >Foo</a
+		  > :: <a href="#" title="Data.Int"
+		  >Int</a
+		  > -&gt; <a href="#" title="Data.String"
+		  >String</a
+		  > -&gt; <a href="#" title="ConstructorArgs"
+		  >Boo</a
+		  ></li
+		><li
+		><a href="#"
+		  >Foa</a
+		  > :: <a href="#" title="Data.Int"
+		  >Int</a
+		  > -&gt; <a href="#" title="ConstructorArgs"
+		  >Boo</a
+		  ></li
+		><li
+		><span class="keyword"
+		  >pattern</span
+		  > <a href="#"
+		  >Fo</a
+		  > :: <a href="#" title="Data.Int"
+		  >Int</a
+		  > -&gt; <a href="#" title="Data.String"
+		  >String</a
+		  > -&gt; <a href="#" title="ConstructorArgs"
+		  >Boo</a
+		  ></li
+		><li
+		><span class="keyword"
+		  >pattern</span
+		  > <a href="#"
+		  >Fo'</a
+		  > :: <a href="#" title="ConstructorArgs"
+		  >Boo</a
+		  ></li
+		></ul
+	      ></li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >pattern</span
+	      > <a href="#"
+	      >Bo</a
+	      > :: <a href="#" title="Data.Int"
+	      >Int</a
+	      > -&gt; <a href="#" title="Data.String"
+	      >String</a
+	      > -&gt; <a href="#" title="ConstructorArgs"
+	      >Boo</a
+	      ></li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >pattern</span
+	      > <a href="#"
+	      >Bo'</a
+	      > :: <a href="#" title="Data.Int"
+	      >Int</a
+	      > -&gt; <a href="#" title="Data.String"
+	      >String</a
+	      > -&gt; <a href="#" title="ConstructorArgs"
+	      >Boo</a
+	      ></li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:Foo" class="def"
+	    >Foo</a
+	    > <span class="fixity"
+	    >infixr 1</span
+	    ><span class="rightedge"
+	    ></span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:Rec" class="def"
+		  >Rec</a
+		  ></td
+		><td class="doc"
+		><p
+		  >doc on a record</p
+		  ></td
+		></tr
+	      ><tr
+	      ><td colspan="2"
+		><div class="subs fields"
+		  ><p class="caption"
+		    >Fields</p
+		    ><ul
+		    ><li
+		      ><dfn class="src"
+			><a id="v:x" class="def"
+			  >x</a
+			  > :: <a href="#" title="Data.String"
+			  >String</a
+			  ></dfn
+			><div class="doc"
+			><p
+			  >doc on the <code
+			    ><a href="#" title="Data.String"
+			      >String</a
+			      ></code
+			    > field of <code
+			    ><a href="#" title="ConstructorArgs"
+			      >Rec</a
+			      ></code
+			    ></p
+			  ></div
+			></li
+		      ><li
+		      ><dfn class="src"
+			><a id="v:y" class="def"
+			  >y</a
+			  > :: <a href="#" title="Data.String"
+			  >String</a
+			  ></dfn
+			><div class="doc"
+			><p
+			  >doc on the <code
+			    ><a href="#" title="Data.String"
+			      >String</a
+			      ></code
+			    > field of <code
+			    ><a href="#" title="ConstructorArgs"
+			      >Rec</a
+			      ></code
+			    ></p
+			  ></div
+			></li
+		      ></ul
+		    ></div
+		  ></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		><a id="v:Baz" class="def"
+		  >Baz</a
+		  > <a href="#" title="Data.Int"
+		  >Int</a
+		  > <a href="#" title="Data.String"
+		  >String</a
+		  ></td
+		><td class="doc"
+		><p
+		  >old prefix doc style</p
+		  ></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		><a id="v:Boa" class="def"
+		  >Boa</a
+		  > <span class="fixity"
+		  >infixr 2</span
+		  ><span class="rightedge"
+		  ></span
+		  ></td
+		><td class="doc"
+		><p
+		  >doc on the <code
+		    ><a href="#" title="ConstructorArgs"
+		      >Boa</a
+		      ></code
+		    > constrictor</p
+		  ></td
+		></tr
+	      ><tr
+	      ><td colspan="2"
+		><div class="subs fields"
+		  ><p class="caption"
+		    >Fields</p
+		    ><ul
+		    ><li
+		      ><dfn class="src"
+			>!<a href="#" title="Data.Int"
+			  >Int</a
+			  ></dfn
+			><div class="doc"
+			><p
+			  >doc on the <code
+			    ><a href="#" title="Data.Int"
+			      >Int</a
+			      ></code
+			    > field of <code
+			    ><a href="#" title="ConstructorArgs"
+			      >Boa</a
+			      ></code
+			    ></p
+			  ></div
+			></li
+		      ><li
+		      ><dfn class="src"
+			>!<a href="#" title="Data.String"
+			  >String</a
+			  ></dfn
+			><div class="doc"
+			><p
+			  >doc on the <code
+			    ><a href="#" title="Data.String"
+			      >String</a
+			      ></code
+			    > field of <code
+			    ><a href="#" title="ConstructorArgs"
+			      >Boa</a
+			      ></code
+			    ></p
+			  ></div
+			></li
+		      ></ul
+		    ></div
+		  ></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		><a href="#" title="Data.Int"
+		  >Int</a
+		  > <a id="v::-124-" class="def"
+		  >:|</a
+		  > <a href="#" title="Data.String"
+		  >String</a
+		  ></td
+		><td class="doc"
+		><p
+		  >old infix doc style</p
+		  ></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		><a id="v::-42-" class="def"
+		  >(:*)</a
+		  > <span class="fixity"
+		  >infixr 3</span
+		  ><span class="rightedge"
+		  ></span
+		  ></td
+		><td class="doc"
+		><p
+		  >doc on the <code
+		    ><a href="#" title="ConstructorArgs"
+		      >:*</a
+		      ></code
+		    > constructor</p
+		  ></td
+		></tr
+	      ><tr
+	      ><td colspan="2"
+		><div class="subs fields"
+		  ><p class="caption"
+		    >Fields</p
+		    ><ul
+		    ><li
+		      ><dfn class="src"
+			><a href="#" title="Data.Int"
+			  >Int</a
+			  ></dfn
+			><div class="doc"
+			><p
+			  >doc on the <code
+			    ><a href="#" title="Data.Int"
+			      >Int</a
+			      ></code
+			    > field of the <code
+			    ><a href="#" title="ConstructorArgs"
+			      >:*</a
+			      ></code
+			    > constructor</p
+			  ></div
+			></li
+		      ><li
+		      ><dfn class="src"
+			><a href="#" title="Data.String"
+			  >String</a
+			  ></dfn
+			><div class="doc"
+			><p
+			  >doc on the <code
+			    ><a href="#" title="Data.String"
+			      >String</a
+			      ></code
+			    > field of the <code
+			    ><a href="#" title="ConstructorArgs"
+			      >:*</a
+			      ></code
+			    > constructor</p
+			  ></div
+			></li
+		      ></ul
+		    ></div
+		  ></td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:Boo" class="def"
+	    >Boo</a
+	    > <span class="keyword"
+	    >where</span
+	    > <span class="fixity"
+	    >infixr 4</span
+	    ><span class="rightedge"
+	    ></span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:Foo" class="def"
+		  >Foo</a
+		  > <span class="fixity"
+		  >infixr 1</span
+		  ><span class="rightedge"
+		  ></span
+		  ></td
+		><td class="doc"
+		><p
+		  >Info about a <code
+		    ><a href="#" title="ConstructorArgs"
+		      >Foo</a
+		      ></code
+		    ></p
+		  ></td
+		></tr
+	      ><tr
+	      ><td colspan="2"
+		><div class="subs fields"
+		  ><p class="caption"
+		    >Fields</p
+		    ><ul
+		    ><li
+		      ><dfn class="src"
+			>:: <a href="#" title="Data.Int"
+			  >Int</a
+			  ></dfn
+			><div class="doc"
+			><p
+			  ><code
+			    ><a href="#" title="Data.Int"
+			      >Int</a
+			      ></code
+			    > field of <code
+			    ><a href="#" title="ConstructorArgs"
+			      >Foo</a
+			      ></code
+			    ></p
+			  ></div
+			></li
+		      ><li
+		      ><dfn class="src"
+			>-&gt; <a href="#" title="Data.String"
+			  >String</a
+			  ></dfn
+			><div class="doc"
+			><p
+			  ><code
+			    ><a href="#" title="Data.String"
+			      >String</a
+			      ></code
+			    > field of <code
+			    ><a href="#" title="ConstructorArgs"
+			      >Foo</a
+			      ></code
+			    ></p
+			  ></div
+			></li
+		      ><li
+		      ><dfn class="src"
+			>-&gt; <a href="#" title="ConstructorArgs"
+			  >Boo</a
+			  ></dfn
+			><div class="doc"
+			><p
+			  >Make a <code
+			    ><a href="#" title="ConstructorArgs"
+			      >Boo</a
+			      ></code
+			    ></p
+			  ></div
+			></li
+		      ></ul
+		    ></div
+		  ></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		><a id="v:Foa" class="def"
+		  >Foa</a
+		  > :: <a href="#" title="Data.Int"
+		  >Int</a
+		  > -&gt; <a href="#" title="ConstructorArgs"
+		  >Boo</a
+		  ></td
+		><td class="doc"
+		><p
+		  >no argument docs GADT</p
+		  ></td
+		></tr
+	      ></table
+	    ></div
+	  ><div class="subs bundled-patterns"
+	  ><p class="caption"
+	    >Bundled Patterns</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><span class="keyword"
+		  >pattern</span
+		  > <a id="v:Fo" class="def"
+		  >Fo</a
+		  > <span class="fixity"
+		  >infixr 5</span
+		  ><span class="rightedge"
+		  ></span
+		  ></td
+		><td class="doc"
+		><p
+		  >Info about bundled <code
+		    ><a href="#" title="ConstructorArgs"
+		      >Fo</a
+		      ></code
+		    ></p
+		  ></td
+		></tr
+	      ><tr
+	      ><td colspan="2"
+		><div class="subs fields"
+		  ><p class="caption"
+		    >Fields</p
+		    ><ul
+		    ><li
+		      ><dfn class="src"
+			>:: <a href="#" title="Data.Int"
+			  >Int</a
+			  ></dfn
+			><div class="doc"
+			><p
+			  >an <code
+			    ><a href="#" title="Data.Int"
+			      >Int</a
+			      ></code
+			    ></p
+			  ></div
+			></li
+		      ><li
+		      ><dfn class="src"
+			>-&gt; <a href="#" title="Data.String"
+			  >String</a
+			  ></dfn
+			><div class="doc"
+			><p
+			  >a <code
+			    ><a href="#" title="Data.String"
+			      >String</a
+			      ></code
+			    ></p
+			  ></div
+			></li
+		      ><li
+		      ><dfn class="src"
+			>-&gt; <a href="#" title="ConstructorArgs"
+			  >Boo</a
+			  ></dfn
+			><div class="doc"
+			><p
+			  >a <code
+			    ><a href="#" title="ConstructorArgs"
+			      >Boo</a
+			      ></code
+			    ></p
+			  ></div
+			></li
+		      ></ul
+		    ></div
+		  ></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		><span class="keyword"
+		  >pattern</span
+		  > <a id="v:Fo-39-" class="def"
+		  >Fo'</a
+		  > :: <a href="#" title="ConstructorArgs"
+		  >Boo</a
+		  ></td
+		><td class="doc"
+		><p
+		  >Bundled and no argument docs</p
+		  ></td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >pattern</span
+	    > <a id="v:Bo" class="def"
+	    >Bo</a
+	    > <span class="fixity"
+	    >infixr 6</span
+	    ><span class="rightedge"
+	    ></span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs arguments"
+	  ><p class="caption"
+	    >Arguments</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		>:: <a href="#" title="Data.Int"
+		  >Int</a
+		  ></td
+		><td class="doc"
+		><p
+		  >an <code
+		    ><a href="#" title="Data.Int"
+		      >Int</a
+		      ></code
+		    ></p
+		  ></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		>-&gt; <a href="#" title="Data.String"
+		  >String</a
+		  ></td
+		><td class="doc"
+		><p
+		  >a <code
+		    ><a href="#" title="Data.String"
+		      >String</a
+		      ></code
+		    ></p
+		  ></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		>-&gt; <a href="#" title="ConstructorArgs"
+		  >Boo</a
+		  ></td
+		><td class="doc"
+		><p
+		  >a <code
+		    ><a href="#" title="ConstructorArgs"
+		      >Boo</a
+		      ></code
+		    > pattern</p
+		  ></td
+		></tr
+	      ></table
+	    ></div
+	  ><div class="doc"
+	  ><p
+	    >Info about not-bundled <code
+	      ><a href="#" title="ConstructorArgs"
+		>Bo</a
+		></code
+	      ></p
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >pattern</span
+	    > <a id="v:Bo-39-" class="def"
+	    >Bo'</a
+	    > :: <a href="#" title="Data.Int"
+	    >Int</a
+	    > -&gt; <a href="#" title="Data.String"
+	    >String</a
+	    > -&gt; <a href="#" title="ConstructorArgs"
+	    >Boo</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Not bundled and no argument docs</p
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/ConstructorPatternExport.html b/html-test/ref/ConstructorPatternExport.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/ConstructorPatternExport.html
@@ -0,0 +1,124 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >ConstructorPatternExport</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>ConstructorPatternExport</p
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >pattern</span
+	    > <a id="v:FooCons" class="def"
+	    >FooCons</a
+	    > :: <a href="#" title="Data.String"
+	    >String</a
+	    > -&gt; a -&gt; Foo a <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >pattern</span
+	    > <a id="v:MyRecCons" class="def"
+	    >MyRecCons</a
+	    > :: <a href="#" title="Data.Bool"
+	    >Bool</a
+	    > -&gt; <a href="#" title="Data.Int"
+	    >Int</a
+	    > -&gt; MyRec <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >pattern</span
+	    > <a id="v::-43-" class="def"
+	    >(:+)</a
+	    > :: <a href="#" title="Data.String"
+	    >String</a
+	    > -&gt; a -&gt; MyInfix a <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >pattern</span
+	    > <a id="v:BlubCons" class="def"
+	    >BlubCons</a
+	    > :: () =&gt; <a href="#" title="Text.Show"
+	    >Show</a
+	    > b =&gt; b -&gt; Blub <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >pattern</span
+	    > <a id="v:MyGADTCons" class="def"
+	    >MyGADTCons</a
+	    > :: a -&gt; <a href="#" title="Data.Int"
+	    >Int</a
+	    > -&gt; MyGADT (<a href="#" title="Data.Maybe"
+	    >Maybe</a
+	    > <a href="#" title="Data.String"
+	    >String</a
+	    >) <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/CrossPackageDocs.html b/html-test/ref/CrossPackageDocs.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/CrossPackageDocs.html
@@ -0,0 +1,287 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >CrossPackageDocs</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();setSynopsis("mini_CrossPackageDocs.html");};
+//]]>
+</script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+    >&nbsp;</span
+    ><ul class="links" id="page-menu"
+      ><li
+	><a href=""
+	  >Contents</a
+	  ></li
+	><li
+	><a href=""
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>CrossPackageDocs</p
+	></div
+      ><div id="synopsis"
+      ><p id="control.syn" class="caption expander" onclick="toggleSection('syn')"
+	>Synopsis</p
+	><ul id="section.syn" class="hide" onclick="toggleSection('syn')"
+	><li class="src short"
+	  ><a href=""
+	    >map</a
+	    > ::  (a -&gt; b) -&gt; [a] -&gt; [b]</li
+	  ><li class="src short"
+	  ><span class="keyword"
+	    >class</span
+	    > <a href=""
+	    >IsString</a
+	    > a <span class="keyword"
+	    >where</span
+	    ><ul class="subs"
+	    ><li
+	      ><a href=""
+		>fromString</a
+		> :: <a href=""
+		>String</a
+		> -&gt; a</li
+	      ></ul
+	    ></li
+	  ><li class="src short"
+	  ><a href=""
+	    >runInteractiveProcess</a
+	    > :: <a href=""
+	    >FilePath</a
+	    > -&gt; [<a href=""
+	    >String</a
+	    >] -&gt; <a href=""
+	    >Maybe</a
+	    > <a href=""
+	    >FilePath</a
+	    > -&gt; <a href=""
+	    >Maybe</a
+	    > [(<a href=""
+	    >String</a
+	    >, <a href=""
+	    >String</a
+	    >)] -&gt; <a href=""
+	    >IO</a
+	    > (<a href=""
+	    >Handle</a
+	    >, <a href=""
+	    >Handle</a
+	    >, <a href=""
+	    >Handle</a
+	    >, <a href=""
+	    >ProcessHandle</a
+	    >)</li
+	  ></ul
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><a name="v:map" class="def"
+	    >map</a
+	    > ::  (a -&gt; b) -&gt; [a] -&gt; [b]</p
+	  ><div class="doc"
+	  ><p
+	    ><code
+	      ><a href=""
+		>map</a
+		></code
+	      > <code
+	      >f xs</code
+	      > is the list obtained by applying <code
+	      >f</code
+	      > to each element
+ of <code
+	      >xs</code
+	      >, i.e.,</p
+	    ><pre
+	    > map f [x1, x2, ..., xn] == [f x1, f x2, ..., f xn]
+ map f [x1, x2, ...] == [f x1, f x2, ...]</pre
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >class</span
+	    > <a name="t:IsString" class="def"
+	    >IsString</a
+	    > a <span class="keyword"
+	    >where</span
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Class for string-like datastructures; used by the overloaded string
+   extension (-XOverloadedStrings in GHC).</p
+	    ></div
+	  ><div class="subs methods"
+	  ><p class="caption"
+	    >Methods</p
+	    ><p class="src"
+	    ><a name="v:fromString" class="def"
+	      >fromString</a
+	      > :: <a href=""
+	      >String</a
+	      > -&gt; a</p
+	    ></div
+	  ><div class="subs instances"
+	  ><p id="control.i:IsString" class="caption collapser" onclick="toggleSection('i:IsString')"
+	    >Instances</p
+	    ><div id="section.i:IsString" class="show"
+	    ><table
+	      ><tr
+		><td class="src"
+		  ><a href=""
+		    >IsString</a
+		    > [<a href=""
+		    >Char</a
+		    >]</td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		></table
+	      ></div
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a name="v:runInteractiveProcess" class="def"
+	    >runInteractiveProcess</a
+	    ></p
+	  ><div class="subs arguments"
+	  ><p class="caption"
+	    >Arguments</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		>:: <a href=""
+		  >FilePath</a
+		  ></td
+		><td class="doc"
+		><p
+		  >Filename of the executable (see <code
+		    ><a href=""
+		      >proc</a
+		      ></code
+		    > for details)</p
+		  ></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		>-&gt; [<a href=""
+		  >String</a
+		  >]</td
+		><td class="doc"
+		><p
+		  >Arguments to pass to the executable</p
+		  ></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		>-&gt; <a href=""
+		  >Maybe</a
+		  > <a href=""
+		  >FilePath</a
+		  ></td
+		><td class="doc"
+		><p
+		  >Optional path to the working directory</p
+		  ></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		>-&gt; <a href=""
+		  >Maybe</a
+		  > [(<a href=""
+		  >String</a
+		  >, <a href=""
+		  >String</a
+		  >)]</td
+		><td class="doc"
+		><p
+		  >Optional environment (otherwise inherit)</p
+		  ></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		>-&gt; <a href=""
+		  >IO</a
+		  > (<a href=""
+		  >Handle</a
+		  >, <a href=""
+		  >Handle</a
+		  >, <a href=""
+		  >Handle</a
+		  >, <a href=""
+		  >ProcessHandle</a
+		  >)</td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ></table
+	    ></div
+	  ><div class="doc"
+	  ><p
+	    >Runs a raw command, and returns <code
+	      ><a href=""
+		>Handle</a
+		></code
+	      >s that may be used to communicate
+     with the process via its <code
+	      >stdin</code
+	      >, <code
+	      >stdout</code
+	      > and <code
+	      >stderr</code
+	      > respectively.</p
+	    ><p
+	    >For example, to start a process and feed a string to its stdin:</p
+	    ><pre
+	    >   (inp,out,err,pid) &lt;- runInteractiveProcess &quot;...&quot;
+   forkIO (hPutStr inp str)</pre
+	    ><p
+	    >The <code
+	      ><a href=""
+		>Handle</a
+		></code
+	      >s are initially in binary mode; if you need them to be
+    in text mode then use <code
+	      ><a href=""
+		>hSetBinaryMode</a
+		></code
+	      >.</p
+	    ></div
+	  ></div
+	></div
+      ></div
+    ><div id="footer"
+    ><p
+      >Produced by <a href=""
+	>Haddock</a
+	> version 2.15.0</p
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/DefaultAssociatedTypes.html b/html-test/ref/DefaultAssociatedTypes.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/DefaultAssociatedTypes.html
@@ -0,0 +1,160 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >DefaultAssociatedTypes</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>DefaultAssociatedTypes</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><span class="keyword"
+	      >class</span
+	      > <a href="#"
+	      >Foo</a
+	      > a <span class="keyword"
+	      >where</span
+	      ><ul class="subs"
+	      ><li
+		><span class="keyword"
+		  >type</span
+		  > <a href="#"
+		  >Qux</a
+		  > a :: *</li
+		><li
+		><a href="#"
+		  >bar</a
+		  >, <a href="#"
+		  >baz</a
+		  > :: a -&gt; <a href="#" title="Data.String"
+		  >String</a
+		  ></li
+		></ul
+	      ></li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >class</span
+	    > <a id="t:Foo" class="def"
+	    >Foo</a
+	    > a <span class="keyword"
+	    >where</span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Documentation for Foo.</p
+	    ></div
+	  ><div class="subs associated-types"
+	  ><p class="caption"
+	    >Associated Types</p
+	    ><p class="src"
+	    ><span class="keyword"
+	      >type</span
+	      > <a id="t:Qux" class="def"
+	      >Qux</a
+	      > a :: * <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ><div class="doc"
+	    ><p
+	      >Doc for Qux</p
+	      ></div
+	    > <div class="subs default"
+	    ><p class="caption"
+	      ></p
+	      ><p class="src"
+	      ><span class="keyword"
+		>type</span
+		> <a href="#" title="DefaultAssociatedTypes"
+		>Qux</a
+		> a = [a]</p
+	      ></div
+	    ></div
+	  ><div class="subs methods"
+	  ><p class="caption"
+	    >Methods</p
+	    ><p class="src"
+	    ><a id="v:bar" class="def"
+	      >bar</a
+	      > :: a -&gt; <a href="#" title="Data.String"
+	      >String</a
+	      > <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ><div class="doc"
+	    ><p
+	      >Documentation for bar and baz.</p
+	      ></div
+	    ><p class="src"
+	    ><a id="v:baz" class="def"
+	      >baz</a
+	      > :: a -&gt; <a href="#" title="Data.String"
+	      >String</a
+	      > <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ><div class="doc"
+	    ><p
+	      >Documentation for bar and baz.</p
+	      ></div
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/DefaultSignatures.html b/html-test/ref/DefaultSignatures.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/DefaultSignatures.html
@@ -0,0 +1,186 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >DefaultSignatures</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>DefaultSignatures</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><span class="keyword"
+	      >class</span
+	      > <a href="#"
+	      >Foo</a
+	      > a <span class="keyword"
+	      >where</span
+	      ><ul class="subs"
+	      ><li
+		><a href="#"
+		  >bar</a
+		  >, <a href="#"
+		  >baz</a
+		  > :: a -&gt; <a href="#" title="Data.String"
+		  >String</a
+		  ></li
+		><li
+		><a href="#"
+		  >baz'</a
+		  > :: <a href="#" title="Data.String"
+		  >String</a
+		  > -&gt; a</li
+		></ul
+	      ></li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >class</span
+	    > <a id="t:Foo" class="def"
+	    >Foo</a
+	    > a <span class="keyword"
+	    >where</span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Documentation for Foo.</p
+	    ></div
+	  ><div class="subs minimal"
+	  ><p class="caption"
+	    >Minimal complete definition</p
+	    ><p class="src"
+	    ><a href="#" title="DefaultSignatures"
+	      >baz</a
+	      ></p
+	    ></div
+	  ><div class="subs methods"
+	  ><p class="caption"
+	    >Methods</p
+	    ><p class="src"
+	    ><a id="v:bar" class="def"
+	      >bar</a
+	      > :: a -&gt; <a href="#" title="Data.String"
+	      >String</a
+	      > <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ><div class="doc"
+	    ><p
+	      >Documentation for bar and baz.</p
+	      ></div
+	    > <div class="subs default"
+	    ><p class="caption"
+	      ></p
+	      ><p class="src"
+	      ><span class="keyword"
+		>default</span
+		> <a id="v:bar" class="def"
+		>bar</a
+		> :: <a href="#" title="Text.Show"
+		>Show</a
+		> a =&gt; a -&gt; <a href="#" title="Data.String"
+		>String</a
+		> <a href="#" class="selflink"
+		>#</a
+		></p
+	      ></div
+	    ><p class="src"
+	    ><a id="v:baz" class="def"
+	      >baz</a
+	      > :: a -&gt; <a href="#" title="Data.String"
+	      >String</a
+	      > <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ><div class="doc"
+	    ><p
+	      >Documentation for bar and baz.</p
+	      ></div
+	    ><p class="src"
+	    ><a id="v:baz-39-" class="def"
+	      >baz'</a
+	      > :: <a href="#" title="Data.String"
+	      >String</a
+	      > -&gt; a <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ><div class="doc"
+	    ><p
+	      >Documentation for baz'.</p
+	      ></div
+	    > <div class="subs default"
+	    ><p class="caption"
+	      ></p
+	      ><p class="src"
+	      ><span class="keyword"
+		>default</span
+		> <a id="v:baz-39-" class="def"
+		>baz'</a
+		> :: <a href="#" title="Text.Read"
+		>Read</a
+		> a =&gt; <a href="#" title="Data.String"
+		>String</a
+		> -&gt; a <a href="#" class="selflink"
+		>#</a
+		></p
+	      ></div
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/DeprecatedClass.html b/html-test/ref/DeprecatedClass.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/DeprecatedClass.html
@@ -0,0 +1,166 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >DeprecatedClass</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>DeprecatedClass</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><span class="keyword"
+	      >class</span
+	      > <a href="#"
+	      >SomeClass</a
+	      > a <span class="keyword"
+	      >where</span
+	      ><ul class="subs"
+	      ><li
+		><a href="#"
+		  >foo</a
+		  > :: a -&gt; a</li
+		></ul
+	      ></li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >class</span
+	      > <a href="#"
+	      >SomeOtherClass</a
+	      > a <span class="keyword"
+	      >where</span
+	      ><ul class="subs"
+	      ><li
+		><a href="#"
+		  >bar</a
+		  > :: a -&gt; a</li
+		></ul
+	      ></li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >class</span
+	    > <a id="t:SomeClass" class="def"
+	    >SomeClass</a
+	    > a <span class="keyword"
+	    >where</span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><div class="warning"
+	    ><p
+	      >Deprecated: SomeClass</p
+	      ></div
+	    ><p
+	    >some class</p
+	    ></div
+	  ><div class="subs methods"
+	  ><p class="caption"
+	    >Methods</p
+	    ><p class="src"
+	    ><a id="v:foo" class="def"
+	      >foo</a
+	      > :: a -&gt; a <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ><div class="doc"
+	    ><div class="warning"
+	      ><p
+		>Deprecated: foo</p
+		></div
+	      ><p
+	      >documentation for foo</p
+	      ></div
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >class</span
+	    > <a id="t:SomeOtherClass" class="def"
+	    >SomeOtherClass</a
+	    > a <span class="keyword"
+	    >where</span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><div class="warning"
+	    ><p
+	      >Deprecated: SomeOtherClass</p
+	      ></div
+	    ></div
+	  ><div class="subs methods"
+	  ><p class="caption"
+	    >Methods</p
+	    ><p class="src"
+	    ><a id="v:bar" class="def"
+	      >bar</a
+	      > :: a -&gt; a <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ><div class="doc"
+	    ><div class="warning"
+	      ><p
+		>Deprecated: bar</p
+		></div
+	      ></div
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/DeprecatedData.html b/html-test/ref/DeprecatedData.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/DeprecatedData.html
@@ -0,0 +1,196 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >DeprecatedData</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>DeprecatedData</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > <a href="#"
+	      >Foo</a
+	      ><ul class="subs"
+	      ><li
+		>= <a href="#"
+		  >Foo</a
+		  ></li
+		><li
+		>| <a href="#"
+		  >Bar</a
+		  ></li
+		></ul
+	      ></li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > <a href="#"
+	      >One</a
+	      ><ul class="subs"
+	      ><li
+		>= <a href="#"
+		  >One</a
+		  ></li
+		><li
+		>| <a href="#"
+		  >Two</a
+		  ></li
+		></ul
+	      ></li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:Foo" class="def"
+	    >Foo</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><div class="warning"
+	    ><p
+	      >Deprecated: Foo</p
+	      ></div
+	    ><p
+	    >type Foo</p
+	    ></div
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:Foo" class="def"
+		  >Foo</a
+		  ></td
+		><td class="doc"
+		><div class="warning"
+		  ><p
+		    >Deprecated: Foo</p
+		    ></div
+		  ><p
+		  >constructor Foo</p
+		  ></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		><a id="v:Bar" class="def"
+		  >Bar</a
+		  ></td
+		><td class="doc"
+		><div class="warning"
+		  ><p
+		    >Deprecated: Bar</p
+		    ></div
+		  ><p
+		  >constructor Bar</p
+		  ></td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:One" class="def"
+	    >One</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><div class="warning"
+	    ><p
+	      >Deprecated: One</p
+	      ></div
+	    ></div
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:One" class="def"
+		  >One</a
+		  ></td
+		><td class="doc"
+		><div class="warning"
+		  ><p
+		    >Deprecated: One</p
+		    ></div
+		  ></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		><a id="v:Two" class="def"
+		  >Two</a
+		  ></td
+		><td class="doc"
+		><div class="warning"
+		  ><p
+		    >Deprecated: Two</p
+		    ></div
+		  ></td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/DeprecatedFunction.html b/html-test/ref/DeprecatedFunction.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/DeprecatedFunction.html
@@ -0,0 +1,114 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >DeprecatedFunction</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>DeprecatedFunction</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><a href="#"
+	      >foo</a
+	      > :: <a href="#" title="Data.Int"
+	      >Int</a
+	      ></li
+	    ><li class="src short"
+	    ><a href="#"
+	      >bar</a
+	      > :: <a href="#" title="Data.Int"
+	      >Int</a
+	      ></li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><a id="v:foo" class="def"
+	    >foo</a
+	    > :: <a href="#" title="Data.Int"
+	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><div class="warning"
+	    ><p
+	      >Deprecated: use <code
+		><a href="#" title="DeprecatedFunction"
+		  >bar</a
+		  ></code
+		> instead</p
+	      ></div
+	    ><p
+	    >some documentation for foo</p
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:bar" class="def"
+	    >bar</a
+	    > :: <a href="#" title="Data.Int"
+	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >some documentation for bar</p
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/DeprecatedFunction2.html b/html-test/ref/DeprecatedFunction2.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/DeprecatedFunction2.html
@@ -0,0 +1,88 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >DeprecatedFunction2</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>DeprecatedFunction2</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><a href="#"
+	      >foo</a
+	      > :: <a href="#" title="Data.Int"
+	      >Int</a
+	      ></li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><a id="v:foo" class="def"
+	    >foo</a
+	    > :: <a href="#" title="Data.Int"
+	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><div class="warning"
+	    ><p
+	      >Deprecated: use bar instead</p
+	      ></div
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/DeprecatedFunction3.html b/html-test/ref/DeprecatedFunction3.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/DeprecatedFunction3.html
@@ -0,0 +1,88 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >DeprecatedFunction3</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>DeprecatedFunction3</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><a href="#"
+	      >foo</a
+	      > :: <a href="#" title="Prelude"
+	      >Integer</a
+	      ></li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><a id="v:foo" class="def"
+	    >foo</a
+	    > :: <a href="#" title="Prelude"
+	    >Integer</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><div class="warning"
+	    ><p
+	      >Deprecated: use bar instead</p
+	      ></div
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/DeprecatedModule.html b/html-test/ref/DeprecatedModule.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/DeprecatedModule.html
@@ -0,0 +1,84 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >DeprecatedModule</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>DeprecatedModule</p
+	></div
+      ><div id="description"
+      ><p class="caption"
+	>Description</p
+	><div class="doc"
+	><div class="warning"
+	  ><p
+	    >Deprecated: Use <a href="#"
+	      >Foo</a
+	      > instead</p
+	    ></div
+	  ><p
+	  >Documentation for <a href="#"
+	    >DeprecatedModule</a
+	    >.</p
+	  ></div
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><a id="v:foo" class="def"
+	    >foo</a
+	    > :: <a href="#" title="Data.Int"
+	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/DeprecatedModule2.html b/html-test/ref/DeprecatedModule2.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/DeprecatedModule2.html
@@ -0,0 +1,78 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >DeprecatedModule2</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>DeprecatedModule2</p
+	></div
+      ><div id="description"
+      ><p class="caption"
+	>Description</p
+	><div class="doc"
+	><div class="warning"
+	  ><p
+	    >Deprecated: Use Foo instead</p
+	    ></div
+	  ></div
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><a id="v:foo" class="def"
+	    >foo</a
+	    > :: <a href="#" title="Data.Int"
+	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/DeprecatedNewtype.html b/html-test/ref/DeprecatedNewtype.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/DeprecatedNewtype.html
@@ -0,0 +1,162 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >DeprecatedNewtype</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>DeprecatedNewtype</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><span class="keyword"
+	      >newtype</span
+	      > <a href="#"
+	      >SomeNewType</a
+	      > = <a href="#"
+	      >SomeNewTypeConst</a
+	      > <a href="#" title="Data.String"
+	      >String</a
+	      ></li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >newtype</span
+	      > <a href="#"
+	      >SomeOtherNewType</a
+	      > = <a href="#"
+	      >SomeOtherNewTypeConst</a
+	      > <a href="#" title="Data.String"
+	      >String</a
+	      ></li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >newtype</span
+	    > <a id="t:SomeNewType" class="def"
+	    >SomeNewType</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><div class="warning"
+	    ><p
+	      >Deprecated: SomeNewType</p
+	      ></div
+	    ><p
+	    >some documentation</p
+	    ></div
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:SomeNewTypeConst" class="def"
+		  >SomeNewTypeConst</a
+		  > <a href="#" title="Data.String"
+		  >String</a
+		  ></td
+		><td class="doc"
+		><div class="warning"
+		  ><p
+		    >Deprecated: SomeNewTypeConst</p
+		    ></div
+		  ><p
+		  >constructor docu </p
+		  ></td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >newtype</span
+	    > <a id="t:SomeOtherNewType" class="def"
+	    >SomeOtherNewType</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><div class="warning"
+	    ><p
+	      >Deprecated: SomeOtherNewType</p
+	      ></div
+	    ></div
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:SomeOtherNewTypeConst" class="def"
+		  >SomeOtherNewTypeConst</a
+		  > <a href="#" title="Data.String"
+		  >String</a
+		  ></td
+		><td class="doc"
+		><div class="warning"
+		  ><p
+		    >Deprecated: SomeOtherNewTypeConst</p
+		    ></div
+		  ></td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/DeprecatedReExport.html b/html-test/ref/DeprecatedReExport.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/DeprecatedReExport.html
@@ -0,0 +1,135 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >DeprecatedReExport</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>DeprecatedReExport</p
+	></div
+      ><div id="table-of-contents"
+      ><div id="contents-list"
+	><p class="caption" onclick="window.scrollTo(0,0)"
+	  >Contents</p
+	  ><ul
+	  ><li
+	    ><a href="#"
+	      >Re-exported from an other module</a
+	      ></li
+	    ><li
+	    ><a href="#"
+	      >Re-exported from an other package</a
+	      ></li
+	    ></ul
+	  ></div
+	></div
+      ><div id="description"
+      ><p class="caption"
+	>Description</p
+	><div class="doc"
+	><p
+	  >What is tested here:</p
+	  ><ul
+	  ><li
+	    >Deprecation messages are shown for re-exported items.</li
+	    ></ul
+	  ></div
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><a href="#"
+	      >foo</a
+	      > :: <a href="#" title="Data.Int"
+	      >Int</a
+	      ></li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><a href="#" id="g:1"
+	><h1
+	  >Re-exported from an other module</h1
+	  ></a
+	><div class="top"
+	><p class="src"
+	  ><a id="v:foo" class="def"
+	    >foo</a
+	    > :: <a href="#" title="Data.Int"
+	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><div class="warning"
+	    ><p
+	      >Deprecated: use <code
+		><a href="#" title="DeprecatedFunction"
+		  >bar</a
+		  ></code
+		> instead</p
+	      ></div
+	    ><p
+	    >some documentation for foo</p
+	    ></div
+	  ></div
+	><a href="#" id="g:2"
+	><h1
+	  >Re-exported from an other package</h1
+	  ></a
+	><div class="doc"
+	><p
+	  >Not yet working, see <a href="#"
+	    >http://trac.haskell.org/haddock/ticket/223</a
+	    >
+ , isEmptyChan</p
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/DeprecatedRecord.html b/html-test/ref/DeprecatedRecord.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/DeprecatedRecord.html
@@ -0,0 +1,154 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >DeprecatedRecord</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>DeprecatedRecord</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > <a href="#"
+	      >Foo</a
+	      > = <a href="#"
+	      >Foo</a
+	      > {<ul class="subs"
+	      ><li
+		><a href="#"
+		  >fooName</a
+		  > :: <a href="#" title="Data.String"
+		  >String</a
+		  ></li
+		><li
+		><a href="#"
+		  >fooValue</a
+		  > :: <a href="#" title="Data.Int"
+		  >Int</a
+		  ></li
+		></ul
+	      >}</li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:Foo" class="def"
+	    >Foo</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >type Foo</p
+	    ></div
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:Foo" class="def"
+		  >Foo</a
+		  ></td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ><tr
+	      ><td colspan="2"
+		><div class="subs fields"
+		  ><p class="caption"
+		    >Fields</p
+		    ><ul
+		    ><li
+		      ><dfn class="src"
+			><a id="v:fooName" class="def"
+			  >fooName</a
+			  > :: <a href="#" title="Data.String"
+			  >String</a
+			  ></dfn
+			><div class="doc"
+			><p
+			  >some name</p
+			  ></div
+			></li
+		      ><li
+		      ><dfn class="src"
+			><a id="v:fooValue" class="def"
+			  >fooValue</a
+			  > :: <a href="#" title="Data.Int"
+			  >Int</a
+			  ></dfn
+			><div class="doc"
+			><div class="warning"
+			  ><p
+			    >Deprecated: do not use this</p
+			    ></div
+			  ><p
+			  >some value</p
+			  ></div
+			></li
+		      ></ul
+		    ></div
+		  ></td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/DeprecatedTypeFamily.html b/html-test/ref/DeprecatedTypeFamily.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/DeprecatedTypeFamily.html
@@ -0,0 +1,112 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >DeprecatedTypeFamily</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>DeprecatedTypeFamily</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><span class="keyword"
+	      >data family</span
+	      > <a href="#"
+	      >SomeTypeFamily</a
+	      > k :: * -&gt; *</li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >data family</span
+	      > <a href="#"
+	      >SomeOtherTypeFamily</a
+	      > k :: * -&gt; *</li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data family</span
+	    > <a id="t:SomeTypeFamily" class="def"
+	    >SomeTypeFamily</a
+	    > k :: * -&gt; * <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><div class="warning"
+	    ><p
+	      >Deprecated: SomeTypeFamily</p
+	      ></div
+	    ><p
+	    >some documentation</p
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data family</span
+	    > <a id="t:SomeOtherTypeFamily" class="def"
+	    >SomeOtherTypeFamily</a
+	    > k :: * -&gt; * <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><div class="warning"
+	    ><p
+	      >Deprecated: SomeOtherTypeFamily</p
+	      ></div
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/DeprecatedTypeSynonym.html b/html-test/ref/DeprecatedTypeSynonym.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/DeprecatedTypeSynonym.html
@@ -0,0 +1,120 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >DeprecatedTypeSynonym</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>DeprecatedTypeSynonym</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><span class="keyword"
+	      >type</span
+	      > <a href="#"
+	      >TypeSyn</a
+	      > = <a href="#" title="Data.String"
+	      >String</a
+	      ></li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >type</span
+	      > <a href="#"
+	      >OtherTypeSyn</a
+	      > = <a href="#" title="Data.String"
+	      >String</a
+	      ></li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >type</span
+	    > <a id="t:TypeSyn" class="def"
+	    >TypeSyn</a
+	    > = <a href="#" title="Data.String"
+	    >String</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><div class="warning"
+	    ><p
+	      >Deprecated: TypeSyn</p
+	      ></div
+	    ><p
+	    >some documentation</p
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >type</span
+	    > <a id="t:OtherTypeSyn" class="def"
+	    >OtherTypeSyn</a
+	    > = <a href="#" title="Data.String"
+	    >String</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><div class="warning"
+	    ><p
+	      >Deprecated: OtherTypeSyn</p
+	      ></div
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/DuplicateRecordFields.html b/html-test/ref/DuplicateRecordFields.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/DuplicateRecordFields.html
@@ -0,0 +1,164 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >DuplicateRecordFields</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>DuplicateRecordFields</p
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:RawReplay" class="def"
+	    >RawReplay</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:RawReplay" class="def"
+		  >RawReplay</a
+		  ></td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ><tr
+	      ><td colspan="2"
+		><div class="subs fields"
+		  ><p class="caption"
+		    >Fields</p
+		    ><ul
+		    ><li
+		      ><dfn class="src"
+			><a id="v:headerSize" class="def"
+			  >headerSize</a
+			  > :: Int</dfn
+			><div class="doc"
+			><p
+			  >The byte size of the first section.</p
+			  ></div
+			></li
+		      ><li
+		      ><dfn class="src"
+			><a id="v:headerCRC" class="def"
+			  >headerCRC</a
+			  > :: Int</dfn
+			><div class="doc"
+			><p
+			  >The CRC of the first section.</p
+			  ></div
+			></li
+		      ><li
+		      ><dfn class="src"
+			><a id="v:header" class="def"
+			  >header</a
+			  > :: Int</dfn
+			><div class="doc"
+			><p
+			  >The first section.</p
+			  ></div
+			></li
+		      ><li
+		      ><dfn class="src"
+			><a id="v:contentSize" class="def"
+			  >contentSize</a
+			  > :: Int</dfn
+			><div class="doc"
+			><p
+			  >The byte size of the second section.</p
+			  ></div
+			></li
+		      ><li
+		      ><dfn class="src"
+			><a id="v:contentCRC" class="def"
+			  >contentCRC</a
+			  > :: Int</dfn
+			><div class="doc"
+			><p
+			  >The CRC of the second section.</p
+			  ></div
+			></li
+		      ><li
+		      ><dfn class="src"
+			><a id="v:content" class="def"
+			  >content</a
+			  > :: Int</dfn
+			><div class="doc"
+			><p
+			  >The second section.</p
+			  ></div
+			></li
+		      ><li
+		      ><dfn class="src"
+			><a id="v:footer" class="def"
+			  >footer</a
+			  > :: Int</dfn
+			><div class="doc"
+			><p
+			  >Arbitrary data after the second section. In replays generated by
+ Rocket League, this is always empty. However it is not technically
+ invalid to put something here.</p
+			  ></div
+			></li
+		      ></ul
+		    ></div
+		  ></td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Examples.html b/html-test/ref/Examples.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Examples.html
@@ -0,0 +1,179 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Examples</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Examples</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><a href="#"
+	      >fib</a
+	      > :: <a href="#" title="Prelude"
+	      >Integer</a
+	      > -&gt; <a href="#" title="Prelude"
+	      >Integer</a
+	      ></li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><a id="v:fib" class="def"
+	    >fib</a
+	    > :: <a href="#" title="Prelude"
+	    >Integer</a
+	    > -&gt; <a href="#" title="Prelude"
+	    >Integer</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Fibonacci number of given <code
+	      ><a href="#" title="Prelude"
+		>Integer</a
+		></code
+	      >.</p
+	    ><p
+	    >Examples:</p
+	    ><pre class="screen"
+	    ><code class="prompt"
+	      >&gt;&gt;&gt; </code
+	      ><strong class="userinput"
+	      ><code
+		>fib 5
+</code
+		></strong
+	      >5
+<code class="prompt"
+	      >&gt;&gt;&gt; </code
+	      ><strong class="userinput"
+	      ><code
+		>fib 10
+</code
+		></strong
+	      >55
+</pre
+	    ><pre class="screen"
+	    ><code class="prompt"
+	      >&gt;&gt;&gt; </code
+	      ><strong class="userinput"
+	      ><code
+		>fib 10
+</code
+		></strong
+	      >55
+</pre
+	    ><p
+	    >One more Example:</p
+	    ><pre class="screen"
+	    ><code class="prompt"
+	      >&gt;&gt;&gt; </code
+	      ><strong class="userinput"
+	      ><code
+		>fib 5
+</code
+		></strong
+	      >5
+</pre
+	    ><p
+	    >One more Example:</p
+	    ><pre class="screen"
+	    ><code class="prompt"
+	      >&gt;&gt;&gt; </code
+	      ><strong class="userinput"
+	      ><code
+		>fib 5
+</code
+		></strong
+	      >5
+</pre
+	    ><p
+	    >Example with an import:</p
+	    ><pre class="screen"
+	    ><code class="prompt"
+	      >&gt;&gt;&gt; </code
+	      ><strong class="userinput"
+	      ><code
+		>import Data.Char
+</code
+		></strong
+	      ><code class="prompt"
+	      >&gt;&gt;&gt; </code
+	      ><strong class="userinput"
+	      ><code
+		>isSpace 'a'
+</code
+		></strong
+	      >False
+</pre
+	    ><pre class="screen"
+	    ><code class="prompt"
+	      >&gt;&gt;&gt; </code
+	      ><strong class="userinput"
+	      ><code
+		>putStrLn &quot;foo\n\nbar&quot;
+</code
+		></strong
+	      >foo
+
+bar
+</pre
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Extensions.html b/html-test/ref/Extensions.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Extensions.html
@@ -0,0 +1,88 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Extensions</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Extensions</th
+	    ><td
+	    >ExplicitForAll</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Extensions</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><a href="#"
+	      >foobar</a
+	      > :: t</li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><a id="v:foobar" class="def"
+	    >foobar</a
+	    > :: t <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Bar</p
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/FunArgs.html b/html-test/ref/FunArgs.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/FunArgs.html
@@ -0,0 +1,298 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >FunArgs</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>FunArgs</p
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><a id="v:f" class="def"
+	    >f</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs arguments"
+	  ><p class="caption"
+	    >Arguments</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		>:: <span class="keyword"
+		  >forall</span
+		  > a. <a href="#" title="Data.Ord"
+		  >Ord</a
+		  > a</td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ><tr
+	      ><td class="src"
+		>=&gt; <a href="#" title="Data.Int"
+		  >Int</a
+		  ></td
+		><td class="doc"
+		><p
+		  >First argument</p
+		  ></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		>-&gt; a</td
+		><td class="doc"
+		><p
+		  >Second argument</p
+		  ></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		>-&gt; <a href="#" title="Data.Bool"
+		  >Bool</a
+		  ></td
+		><td class="doc"
+		><p
+		  >Third argument</p
+		  ></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		>-&gt; (a -&gt; a)</td
+		><td class="doc"
+		><p
+		  >Fourth argument</p
+		  ></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		>-&gt; ()</td
+		><td class="doc"
+		><p
+		  >Result</p
+		  ></td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:g" class="def"
+	    >g</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs arguments"
+	  ><p class="caption"
+	    >Arguments</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		>:: a</td
+		><td class="doc"
+		><p
+		  >First argument</p
+		  ></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		>-&gt; b</td
+		><td class="doc"
+		><p
+		  >Second argument</p
+		  ></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		>-&gt; c</td
+		><td class="doc"
+		><p
+		  >Third argument</p
+		  ></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		>-&gt; d</td
+		><td class="doc"
+		><p
+		  >Result</p
+		  ></td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:h" class="def"
+	    >h</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs arguments"
+	  ><p class="caption"
+	    >Arguments</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		>:: <span class="keyword"
+		  >forall</span
+		  > a b c. a</td
+		><td class="doc"
+		><p
+		  >First argument</p
+		  ></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		>-&gt; b</td
+		><td class="doc"
+		><p
+		  >Second argument</p
+		  ></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		>-&gt; c</td
+		><td class="doc"
+		><p
+		  >Third argument</p
+		  ></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		>-&gt; <span class="keyword"
+		  >forall</span
+		  > d. d</td
+		><td class="doc"
+		><p
+		  >Result</p
+		  ></td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:i" class="def"
+	    >i</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs arguments"
+	  ><p class="caption"
+	    >Arguments</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		>:: <span class="keyword"
+		  >forall</span
+		  > a (b :: ()) d. d <a href="#" title="Data.Type.Equality"
+		  >~</a
+		  > '<a href="#" title="GHC.Tuple.Prim"
+		  >()</a
+		  ></td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ><tr
+	      ><td class="src"
+		>=&gt; <span class="keyword"
+		  >forall</span
+		  > c. a b c d</td
+		><td class="doc"
+		><p
+		  >abcd</p
+		  ></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		>-&gt; ()</td
+		><td class="doc"
+		><p
+		  >Result</p
+		  ></td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:j" class="def"
+	    >j</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs arguments"
+	  ><p class="caption"
+	    >Arguments</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		>:: <span class="keyword"
+		  >forall</span
+		  > proxy (a :: ()) b. proxy a</td
+		><td class="doc"
+		><p
+		  >First argument</p
+		  ></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		>-&gt; b</td
+		><td class="doc"
+		><p
+		  >Result</p
+		  ></td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/GADTRecords.html b/html-test/ref/GADTRecords.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/GADTRecords.html
@@ -0,0 +1,232 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >GADTRecords</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>GADTRecords</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > <a href="#"
+	      >H1</a
+	      > a b <span class="keyword"
+	      >where</span
+	      ><ul class="subs"
+	      ><li
+		><a href="#"
+		  >C1</a
+		  > :: <a href="#" title="GADTRecords"
+		  >H1</a
+		  > a b</li
+		><li
+		><a href="#"
+		  >C2</a
+		  > :: <a href="#" title="Data.Ord"
+		  >Ord</a
+		  > a =&gt; [a] -&gt; <a href="#" title="GADTRecords"
+		  >H1</a
+		  > a a</li
+		><li
+		><a href="#"
+		  >C3</a
+		  > :: {..} -&gt; <a href="#" title="GADTRecords"
+		  >H1</a
+		  > <a href="#" title="Data.Int"
+		  >Int</a
+		  > <a href="#" title="Data.Int"
+		  >Int</a
+		  ></li
+		><li
+		><a href="#"
+		  >C4</a
+		  > :: {..} -&gt; <a href="#" title="GADTRecords"
+		  >H1</a
+		  > <a href="#" title="Data.Int"
+		  >Int</a
+		  > a</li
+		></ul
+	      ></li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:H1" class="def"
+	    >H1</a
+	    > a b <span class="keyword"
+	    >where</span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >h1</p
+	    ></div
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:C1" class="def"
+		  >C1</a
+		  > :: <a href="#" title="GADTRecords"
+		  >H1</a
+		  > a b</td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ><tr
+	      ><td class="src"
+		><a id="v:C2" class="def"
+		  >C2</a
+		  > :: <a href="#" title="Data.Ord"
+		  >Ord</a
+		  > a =&gt; [a] -&gt; <a href="#" title="GADTRecords"
+		  >H1</a
+		  > a a</td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ><tr
+	      ><td class="src"
+		><a id="v:C3" class="def"
+		  >C3</a
+		  ></td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ><tr
+	      ><td colspan="2"
+		><div class="subs fields"
+		  ><p class="caption"
+		    >Fields</p
+		    ><ul
+		    ><li
+		      ><dfn class="src"
+			>:: { <a id="v:field" class="def"
+			  >field</a
+			  > :: <a href="#" title="Data.Int"
+			  >Int</a
+			  ></dfn
+			><div class="doc"
+			><p
+			  >hello docs</p
+			  ></div
+			></li
+		      ><li
+		      ><dfn class="src"
+			>&nbsp;&nbsp;&nbsp;} -&gt; <a href="#" title="GADTRecords"
+			  >H1</a
+			  > <a href="#" title="Data.Int"
+			  >Int</a
+			  > <a href="#" title="Data.Int"
+			  >Int</a
+			  ></dfn
+			><div class="doc empty"
+			>&nbsp;</div
+			></li
+		      ></ul
+		    ></div
+		  ></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		><a id="v:C4" class="def"
+		  >C4</a
+		  ></td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ><tr
+	      ><td colspan="2"
+		><div class="subs fields"
+		  ><p class="caption"
+		    >Fields</p
+		    ><ul
+		    ><li
+		      ><dfn class="src"
+			>:: { <a id="v:field2" class="def"
+			  >field2</a
+			  > :: a</dfn
+			><div class="doc"
+			><p
+			  >hello2 docs</p
+			  ></div
+			></li
+		      ><li
+		      ><dfn class="src"
+			>&nbsp;&nbsp;&nbsp;} -&gt; <a href="#" title="GADTRecords"
+			  >H1</a
+			  > <a href="#" title="Data.Int"
+			  >Int</a
+			  > a</dfn
+			><div class="doc empty"
+			>&nbsp;</div
+			></li
+		      ></ul
+		    ></div
+		  ></td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/GadtConstructorArgs.html b/html-test/ref/GadtConstructorArgs.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/GadtConstructorArgs.html
@@ -0,0 +1,200 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >GadtConstructorArgs</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>GadtConstructorArgs</p
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:Boo" class="def"
+	    >Boo</a
+	    > <span class="keyword"
+	    >where</span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:Fot" class="def"
+		  >Fot</a
+		  ></td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ><tr
+	      ><td colspan="2"
+		><div class="subs fields"
+		  ><p class="caption"
+		    >Fields</p
+		    ><ul
+		    ><li
+		      ><dfn class="src"
+			>:: { <a id="v:x" class="def"
+			  >x</a
+			  > :: <a href="#" title="Data.Int"
+			  >Int</a
+			  ></dfn
+			><div class="doc"
+			><p
+			  >an <code
+			    ><a href="#" title="GadtConstructorArgs"
+			      >x</a
+			      ></code
+			    ></p
+			  ></div
+			></li
+		      ><li
+		      ><dfn class="src"
+			>&nbsp;&nbsp;&nbsp;, <a id="v:y" class="def"
+			  >y</a
+			  > :: <a href="#" title="Data.Int"
+			  >Int</a
+			  ></dfn
+			><div class="doc"
+			><p
+			  >a <code
+			    ><a href="#" title="GadtConstructorArgs"
+			      >y</a
+			      ></code
+			    ></p
+			  ></div
+			></li
+		      ><li
+		      ><dfn class="src"
+			>&nbsp;&nbsp;&nbsp;} -&gt; <a href="#" title="GadtConstructorArgs"
+			  >Boo</a
+			  ></dfn
+			><div class="doc empty"
+			>&nbsp;</div
+			></li
+		      ></ul
+		    ></div
+		  ></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		><a id="v:Fob" class="def"
+		  >Fob</a
+		  ></td
+		><td class="doc"
+		><p
+		  >Record GADT with docs</p
+		  ></td
+		></tr
+	      ><tr
+	      ><td colspan="2"
+		><div class="subs fields"
+		  ><p class="caption"
+		    >Fields</p
+		    ><ul
+		    ><li
+		      ><dfn class="src"
+			>:: { <a id="v:w" class="def"
+			  >w</a
+			  > :: <a href="#" title="Data.Int"
+			  >Int</a
+			  ></dfn
+			><div class="doc"
+			><p
+			  >a <code
+			    ><a href="#" title="GadtConstructorArgs"
+			      >w</a
+			      ></code
+			    ></p
+			  ></div
+			></li
+		      ><li
+		      ><dfn class="src"
+			>&nbsp;&nbsp;&nbsp;, <a id="v:z" class="def"
+			  >z</a
+			  > :: <a href="#" title="Data.Int"
+			  >Int</a
+			  ></dfn
+			><div class="doc"
+			><p
+			  >a <code
+			    ><a href="#" title="GadtConstructorArgs"
+			      >z</a
+			      ></code
+			    ></p
+			  ></div
+			></li
+		      ><li
+		      ><dfn class="src"
+			>&nbsp;&nbsp;&nbsp;} -&gt; <a href="#" title="GadtConstructorArgs"
+			  >Boo</a
+			  ></dfn
+			><div class="doc"
+			><p
+			  >a <code
+			    ><a href="#" title="GadtConstructorArgs"
+			      >Boo</a
+			      ></code
+			    ></p
+			  ></div
+			></li
+		      ></ul
+		    ></div
+		  ></td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Hash.html b/html-test/ref/Hash.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Hash.html
@@ -0,0 +1,443 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Hash</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Hash</p
+	></div
+      ><div id="table-of-contents"
+      ><div id="contents-list"
+	><p class="caption" onclick="window.scrollTo(0,0)"
+	  >Contents</p
+	  ><ul
+	  ><li
+	    ><a href="#"
+	      >The <code
+		>HashTable</code
+		> type</a
+	      ><ul
+	      ><li
+		><a href="#"
+		  >Operations on <code
+		    >HashTable</code
+		    >s</a
+		  ></li
+		></ul
+	      ></li
+	    ><li
+	    ><a href="#"
+	      >The <code
+		>Hash</code
+		> class</a
+	      ></li
+	    ></ul
+	  ></div
+	></div
+      ><div id="description"
+      ><p class="caption"
+	>Description</p
+	><div class="doc"
+	><p
+	  >Implementation of fixed-size hash tables, with a type
+  class for constructing hash values for structured types.</p
+	  ></div
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > <a href="#"
+	      >HashTable</a
+	      > key val</li
+	    ><li class="src short"
+	    ><a href="#"
+	      >new</a
+	      > :: (<a href="#" title="Data.Eq"
+	      >Eq</a
+	      > key, <a href="#" title="Hash"
+	      >Hash</a
+	      > key) =&gt; <a href="#" title="Data.Int"
+	      >Int</a
+	      > -&gt; <a href="#" title="System.IO"
+	      >IO</a
+	      > (<a href="#" title="Hash"
+	      >HashTable</a
+	      > key val)</li
+	    ><li class="src short"
+	    ><a href="#"
+	      >insert</a
+	      > :: (<a href="#" title="Data.Eq"
+	      >Eq</a
+	      > key, <a href="#" title="Hash"
+	      >Hash</a
+	      > key) =&gt; key -&gt; val -&gt; <a href="#" title="System.IO"
+	      >IO</a
+	      > ()</li
+	    ><li class="src short"
+	    ><a href="#"
+	      >lookup</a
+	      > :: <a href="#" title="Hash"
+	      >Hash</a
+	      > key =&gt; key -&gt; <a href="#" title="System.IO"
+	      >IO</a
+	      > (<a href="#" title="Data.Maybe"
+	      >Maybe</a
+	      > val)</li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >class</span
+	      > <a href="#"
+	      >Hash</a
+	      > a <span class="keyword"
+	      >where</span
+	      ><ul class="subs"
+	      ><li
+		><a href="#"
+		  >hash</a
+		  > :: a -&gt; <a href="#" title="Data.Int"
+		  >Int</a
+		  ></li
+		></ul
+	      ></li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><a href="#" id="g:1"
+	><h1
+	  >The <code
+	    >HashTable</code
+	    > type</h1
+	  ></a
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:HashTable" class="def"
+	    >HashTable</a
+	    > key val <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >A hash table with keys of type <code
+	      >key</code
+	      > and values of type <code
+	      >val</code
+	      >.
+ The type <code
+	      >key</code
+	      > should be an instance of <code
+	      ><a href="#" title="Data.Eq"
+		>Eq</a
+		></code
+	      >.</p
+	    ></div
+	  ></div
+	><a href="#" id="g:2"
+	><h2
+	  >Operations on <code
+	    >HashTable</code
+	    >s</h2
+	  ></a
+	><div class="top"
+	><p class="src"
+	  ><a id="v:new" class="def"
+	    >new</a
+	    > :: (<a href="#" title="Data.Eq"
+	    >Eq</a
+	    > key, <a href="#" title="Hash"
+	    >Hash</a
+	    > key) =&gt; <a href="#" title="Data.Int"
+	    >Int</a
+	    > -&gt; <a href="#" title="System.IO"
+	    >IO</a
+	    > (<a href="#" title="Hash"
+	    >HashTable</a
+	    > key val) <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Builds a new hash table with a given size</p
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:insert" class="def"
+	    >insert</a
+	    > :: (<a href="#" title="Data.Eq"
+	    >Eq</a
+	    > key, <a href="#" title="Hash"
+	    >Hash</a
+	    > key) =&gt; key -&gt; val -&gt; <a href="#" title="System.IO"
+	    >IO</a
+	    > () <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Inserts a new element into the hash table</p
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:lookup" class="def"
+	    >lookup</a
+	    > :: <a href="#" title="Hash"
+	    >Hash</a
+	    > key =&gt; key -&gt; <a href="#" title="System.IO"
+	    >IO</a
+	    > (<a href="#" title="Data.Maybe"
+	    >Maybe</a
+	    > val) <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Looks up a key in the hash table, returns <code
+	      ><code
+		><a href="#" title="Data.Maybe"
+		  >Just</a
+		  ></code
+		> val</code
+	      > if the key
+ was found, or <code
+	      ><a href="#" title="Data.Maybe"
+		>Nothing</a
+		></code
+	      > otherwise.</p
+	    ></div
+	  ></div
+	><a href="#" id="g:3"
+	><h1
+	  >The <code
+	    >Hash</code
+	    > class</h1
+	  ></a
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >class</span
+	    > <a id="t:Hash" class="def"
+	    >Hash</a
+	    > a <span class="keyword"
+	    >where</span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >A class of types which can be hashed.</p
+	    ></div
+	  ><div class="subs methods"
+	  ><p class="caption"
+	    >Methods</p
+	    ><p class="src"
+	    ><a id="v:hash" class="def"
+	      >hash</a
+	      > :: a -&gt; <a href="#" title="Data.Int"
+	      >Int</a
+	      > <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ><div class="doc"
+	    ><p
+	      >hashes the value of type <code
+		>a</code
+		> into an <code
+		><a href="#" title="Data.Int"
+		  >Int</a
+		  ></code
+		></p
+	      ></div
+	    ></div
+	  ><div class="subs instances"
+	  ><h4 class="instances details-toggle-control details-toggle" data-details-id="i:Hash"
+	    >Instances</h4
+	    ><details id="i:Hash" open="open"
+	    ><summary class="hide-when-js-enabled"
+	      >Instances details</summary
+	      ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:ic:Hash:Hash:1"
+		      ></span
+		      > <a href="#" title="Hash"
+		      >Hash</a
+		      > <a href="#" title="Prelude"
+		      >Float</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:ic:Hash:Hash:1"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Hash</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >hash</a
+			  > :: <a href="#" title="Prelude"
+			  >Float</a
+			  > -&gt; <a href="#" title="Data.Int"
+			  >Int</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:ic:Hash:Hash:2"
+		      ></span
+		      > <a href="#" title="Hash"
+		      >Hash</a
+		      > <a href="#" title="Data.Int"
+		      >Int</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:ic:Hash:Hash:2"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Hash</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >hash</a
+			  > :: <a href="#" title="Data.Int"
+			  >Int</a
+			  > -&gt; <a href="#" title="Data.Int"
+			  >Int</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:ic:Hash:Hash:3"
+		      ></span
+		      > (<a href="#" title="Hash"
+		      >Hash</a
+		      > a, <a href="#" title="Hash"
+		      >Hash</a
+		      > b) =&gt; <a href="#" title="Hash"
+		      >Hash</a
+		      > (a, b)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:ic:Hash:Hash:3"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Hash</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >hash</a
+			  > :: (a, b) -&gt; <a href="#" title="Data.Int"
+			  >Int</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		></table
+	      ></details
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/HiddenInstances.html b/html-test/ref/HiddenInstances.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/HiddenInstances.html
@@ -0,0 +1,326 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >HiddenInstances</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>HiddenInstances</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><span class="keyword"
+	      >class</span
+	      > <a href="#"
+	      >VisibleClass</a
+	      > a</li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > <a href="#"
+	      >VisibleData</a
+	      ></li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >class</span
+	    > <a id="t:VisibleClass" class="def"
+	    >VisibleClass</a
+	    > a <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Should be visible</p
+	    ></div
+	  ><div class="subs instances"
+	  ><h4 class="instances details-toggle-control details-toggle" data-details-id="i:VisibleClass"
+	    >Instances</h4
+	    ><details id="i:VisibleClass" open="open"
+	    ><summary class="hide-when-js-enabled"
+	      >Instances details</summary
+	      ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:ic:VisibleClass:VisibleClass:1"
+		      ></span
+		      > <a href="#" title="HiddenInstances"
+		      >VisibleClass</a
+		      > <a href="#" title="HiddenInstances"
+		      >VisibleData</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    >Should be visible</p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:ic:VisibleClass:VisibleClass:1"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>HiddenInstances</a
+			></p
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:ic:VisibleClass:VisibleClass:2"
+		      ></span
+		      > <a href="#" title="HiddenInstances"
+		      >VisibleClass</a
+		      > <a href="#" title="Data.Int"
+		      >Int</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    >Should be visible</p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:ic:VisibleClass:VisibleClass:2"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>HiddenInstances</a
+			></p
+		      ></details
+		    ></td
+		  ></tr
+		></table
+	      ></details
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:VisibleData" class="def"
+	    >VisibleData</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Should be visible</p
+	    ></div
+	  ><div class="subs instances"
+	  ><h4 class="instances details-toggle-control details-toggle" data-details-id="i:VisibleData"
+	    >Instances</h4
+	    ><details id="i:VisibleData" open="open"
+	    ><summary class="hide-when-js-enabled"
+	      >Instances details</summary
+	      ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:VisibleData:Num:1"
+		      ></span
+		      > <a href="#" title="Prelude"
+		      >Num</a
+		      > <a href="#" title="HiddenInstances"
+		      >VisibleData</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    >Should be visible</p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:VisibleData:Num:1"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>HiddenInstances</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >(+)</a
+			  > :: <a href="#" title="HiddenInstances"
+			  >VisibleData</a
+			  > -&gt; <a href="#" title="HiddenInstances"
+			  >VisibleData</a
+			  > -&gt; <a href="#" title="HiddenInstances"
+			  >VisibleData</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >(-)</a
+			  > :: <a href="#" title="HiddenInstances"
+			  >VisibleData</a
+			  > -&gt; <a href="#" title="HiddenInstances"
+			  >VisibleData</a
+			  > -&gt; <a href="#" title="HiddenInstances"
+			  >VisibleData</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >(*)</a
+			  > :: <a href="#" title="HiddenInstances"
+			  >VisibleData</a
+			  > -&gt; <a href="#" title="HiddenInstances"
+			  >VisibleData</a
+			  > -&gt; <a href="#" title="HiddenInstances"
+			  >VisibleData</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >negate</a
+			  > :: <a href="#" title="HiddenInstances"
+			  >VisibleData</a
+			  > -&gt; <a href="#" title="HiddenInstances"
+			  >VisibleData</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >abs</a
+			  > :: <a href="#" title="HiddenInstances"
+			  >VisibleData</a
+			  > -&gt; <a href="#" title="HiddenInstances"
+			  >VisibleData</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >signum</a
+			  > :: <a href="#" title="HiddenInstances"
+			  >VisibleData</a
+			  > -&gt; <a href="#" title="HiddenInstances"
+			  >VisibleData</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >fromInteger</a
+			  > :: <a href="#" title="Prelude"
+			  >Integer</a
+			  > -&gt; <a href="#" title="HiddenInstances"
+			  >VisibleData</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:VisibleData:VisibleClass:2"
+		      ></span
+		      > <a href="#" title="HiddenInstances"
+		      >VisibleClass</a
+		      > <a href="#" title="HiddenInstances"
+		      >VisibleData</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    >Should be visible</p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:VisibleData:VisibleClass:2"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>HiddenInstances</a
+			></p
+		      ></details
+		    ></td
+		  ></tr
+		></table
+	      ></details
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/HiddenInstancesB.html b/html-test/ref/HiddenInstancesB.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/HiddenInstancesB.html
@@ -0,0 +1,186 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >HiddenInstancesB</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>HiddenInstancesB</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><span class="keyword"
+	      >class</span
+	      > <a href="#"
+	      >Foo</a
+	      > a</li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > <a href="#"
+	      >Bar</a
+	      ></li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >class</span
+	    > <a id="t:Foo" class="def"
+	    >Foo</a
+	    > a <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Should be visible</p
+	    ></div
+	  ><div class="subs instances"
+	  ><h4 class="instances details-toggle-control details-toggle" data-details-id="i:Foo"
+	    >Instances</h4
+	    ><details id="i:Foo" open="open"
+	    ><summary class="hide-when-js-enabled"
+	      >Instances details</summary
+	      ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:ic:Foo:Foo:1"
+		      ></span
+		      > <a href="#" title="HiddenInstancesB"
+		      >Foo</a
+		      > <a href="#" title="HiddenInstancesB"
+		      >Bar</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    >Should be visible</p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:ic:Foo:Foo:1"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>HiddenInstancesA</a
+			></p
+		      ></details
+		    ></td
+		  ></tr
+		></table
+	      ></details
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:Bar" class="def"
+	    >Bar</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Should be visible</p
+	    ></div
+	  ><div class="subs instances"
+	  ><h4 class="instances details-toggle-control details-toggle" data-details-id="i:Bar"
+	    >Instances</h4
+	    ><details id="i:Bar" open="open"
+	    ><summary class="hide-when-js-enabled"
+	      >Instances details</summary
+	      ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:Bar:Foo:1"
+		      ></span
+		      > <a href="#" title="HiddenInstancesB"
+		      >Foo</a
+		      > <a href="#" title="HiddenInstancesB"
+		      >Bar</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    >Should be visible</p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:Bar:Foo:1"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>HiddenInstancesA</a
+			></p
+		      ></details
+		    ></td
+		  ></tr
+		></table
+	      ></details
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Hyperlinks.html b/html-test/ref/Hyperlinks.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Hyperlinks.html
@@ -0,0 +1,92 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Hyperlinks</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Hyperlinks</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><a href="#"
+	      >foo</a
+	      > :: <a href="#" title="Data.Int"
+	      >Int</a
+	      ></li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><a id="v:foo" class="def"
+	    >foo</a
+	    > :: <a href="#" title="Data.Int"
+	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >A plain URL: <a href="#"
+	      >http://example.com/</a
+	      ></p
+	    ><p
+	    >A URL with a label: <a href="#"
+	      >some link</a
+	      ></p
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Identifiers.html b/html-test/ref/Identifiers.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Identifiers.html
@@ -0,0 +1,290 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Identifiers</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Identifiers</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > <a href="#"
+	      >Id</a
+	      > = <a href="#"
+	      >Id</a
+	      ></li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > a <a href="#"
+	      >:*</a
+	      > b = a <a href="#"
+	      >:*</a
+	      > b</li
+	    ><li class="src short"
+	    ><a href="#"
+	      >foo</a
+	      > :: ()</li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:Id" class="def"
+	    >Id</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:Id" class="def"
+		  >Id</a
+		  ></td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > a <a id="t::-42-" class="def"
+	    >:*</a
+	    > b <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		>a <a id="v::-42-" class="def"
+		  >:*</a
+		  > b</td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:foo" class="def"
+	    >foo</a
+	    > :: () <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><ul
+	    ><li
+	      ><p
+		>Unadorned:</p
+		><ul
+		><li
+		  >Unqualified: <code
+		    ><a href="#" title="GHC.List"
+		      >++</a
+		      ></code
+		    >, <code
+		    ><a href="#" title="Data.Foldable"
+		      >elem</a
+		      ></code
+		    ></li
+		  ><li
+		  >Qualified: <code
+		    ><a href="#" title="GHC.List"
+		      >++</a
+		      ></code
+		    >, <code
+		    ><a href="#" title="Data.Lis"
+		      >elem</a
+		      ></code
+		    ></li
+		  ><li
+		  >Namespaced: <code
+		    ><a href="#" title="GHC.List"
+		      >++</a
+		      ></code
+		    >, <code
+		    >++</code
+		    >, <code
+		    ><a href="#" title="Data.Foldable"
+		      >elem</a
+		      ></code
+		    >, <code
+		    >elem</code
+		    >, <code
+		    ><a href="#" title="Identifiers"
+		      >Id</a
+		      ></code
+		    >, <code
+		    ><a href="#" title="Identifiers"
+		      >Id</a
+		      ></code
+		    >, <code
+		    ><a href="#" title="Identifiers"
+		      >:*</a
+		      ></code
+		    >, <code
+		    ><a href="#" title="Identifiers"
+		      >:*</a
+		      ></code
+		    ></li
+		  ></ul
+		></li
+	      ><li
+	      ><p
+		>Parenthesized:</p
+		><ul
+		><li
+		  >Unqualified: <code
+		    ><code
+		      ><a href="#" title="GHC.List"
+			>(++)</a
+			></code
+		      > [1,2,3] [4,5,6]</code
+		    ></li
+		  ><li
+		  >Qualified: <code
+		    ><code
+		      ><a href="#" title="GHC.List"
+			>(++)</a
+			></code
+		      > [1,2,3] [4,5,6]</code
+		    ></li
+		  ><li
+		  >Namespaced: <code
+		    ><a href="#" title="GHC.List"
+		      >(++)</a
+		      ></code
+		    >, <code
+		    >++</code
+		    >, <code
+		    ><a href="#" title="Identifiers"
+		      >(:*)</a
+		      ></code
+		    >, <code
+		    ><a href="#" title="Identifiers"
+		      >(:*)</a
+		      ></code
+		    ></li
+		  ></ul
+		></li
+	      ><li
+	      ><p
+		>Backticked:</p
+		><ul
+		><li
+		  >Unqualified: <code
+		    >1 <code
+		      ><a href="#" title="Data.Foldable"
+			>`elem`</a
+			></code
+		      > [-3..3]</code
+		    ></li
+		  ><li
+		  >Qualified: <code
+		    >1 <code
+		      ><a href="#" title="Data.Foldable"
+			>`elem`</a
+			></code
+		      > [-3..3]</code
+		    ></li
+		  ><li
+		  >Namespaced: <code
+		    ><a href="#" title="Data.Foldable"
+		      >`elem`</a
+		      ></code
+		    >, <code
+		    >`elem`</code
+		    >, <code
+		    ><a href="#" title="Identifiers"
+		      >`Id`</a
+		      ></code
+		    >, <code
+		    ><a href="#" title="Identifiers"
+		      >`Id`</a
+		      ></code
+		    ></li
+		  ></ul
+		></li
+	      ><li
+	      ><p
+		>Edge cases:</p
+		><ul
+		><li
+		  >Tuples: <code
+		    >()</code
+		    >, <code
+		    >(,,,)</code
+		    ></li
+		  ></ul
+		></li
+	      ></ul
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/IgnoreExports.html b/html-test/ref/IgnoreExports.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/IgnoreExports.html
@@ -0,0 +1,106 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >IgnoreExports</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>IgnoreExports</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > <a href="#"
+	      >Foo</a
+	      ></li
+	    ><li class="src short"
+	    ><a href="#"
+	      >foo</a
+	      > :: <a href="#" title="Data.Int"
+	      >Int</a
+	      ></li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:Foo" class="def"
+	    >Foo</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >documentation for Foo</p
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:foo" class="def"
+	    >foo</a
+	    > :: <a href="#" title="Data.Int"
+	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >documentation for foo</p
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/ImplicitParams.html b/html-test/ref/ImplicitParams.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/ImplicitParams.html
@@ -0,0 +1,120 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >ImplicitParams</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>ImplicitParams</p
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:X" class="def"
+	    >X</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:X" class="def"
+		  >X</a
+		  ></td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:c" class="def"
+	    >c</a
+	    > :: (?x :: <a href="#" title="ImplicitParams"
+	    >X</a
+	    >) =&gt; <a href="#" title="ImplicitParams"
+	    >X</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:d" class="def"
+	    >d</a
+	    > :: (?x :: <a href="#" title="ImplicitParams"
+	    >X</a
+	    >, ?y :: <a href="#" title="ImplicitParams"
+	    >X</a
+	    >) =&gt; (<a href="#" title="ImplicitParams"
+	    >X</a
+	    >, <a href="#" title="ImplicitParams"
+	    >X</a
+	    >) <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:f" class="def"
+	    >f</a
+	    > :: ((?x :: <a href="#" title="ImplicitParams"
+	    >X</a
+	    >) =&gt; a) -&gt; a <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Instances.html b/html-test/ref/Instances.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Instances.html
@@ -0,0 +1,2152 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Instances</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Instances</p
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >newtype</span
+	    > a <a id="t:-60--126--126-" class="def"
+	    >&lt;~~</a
+	    > b <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:Xyzzy" class="def"
+		  >Xyzzy</a
+		  > (b -&gt; (a, a))</td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ></table
+	    ></div
+	  ><div class="subs instances"
+	  ><h4 class="instances details-toggle-control details-toggle" data-details-id="i:-60--126--126-"
+	    >Instances</h4
+	    ><details id="i:-60--126--126-" open="open"
+	    ><summary class="hide-when-js-enabled"
+	      >Instances details</summary
+	      ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:-60--126--126-:Foo:1"
+		      ></span
+		      > <a href="#" title="Instances"
+		      >Foo</a
+		      > (<a href="#" title="Instances"
+		      >(&lt;~~)</a
+		      > a)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:-60--126--126-:Foo:1"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Instances</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >foo</a
+			  > :: (a <a href="#" title="Instances"
+			  >&lt;~~</a
+			  > <a href="#" title="Data.Int"
+			  >Int</a
+			  >) -&gt; a0 -&gt; a <a href="#" title="Instances"
+			  >&lt;~~</a
+			  > a0 <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >foo'</a
+			  > :: (a <a href="#" title="Instances"
+			  >&lt;~~</a
+			  > (a <a href="#" title="Instances"
+			  >&lt;~~</a
+			  > a0)) -&gt; <a href="#" title="Data.Int"
+			  >Int</a
+			  > -&gt; a <a href="#" title="Instances"
+			  >&lt;~~</a
+			  > (a <a href="#" title="Instances"
+			  >&lt;~~</a
+			  > <a href="#" title="Data.Int"
+			  >Int</a
+			  >) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		></table
+	      ></details
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >class</span
+	    > <a id="t:Foo" class="def"
+	    >Foo</a
+	    > f <span class="keyword"
+	    >where</span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs minimal"
+	  ><p class="caption"
+	    >Minimal complete definition</p
+	    ><p class="src"
+	    >Nothing</p
+	    ></div
+	  ><div class="subs methods"
+	  ><p class="caption"
+	    >Methods</p
+	    ><p class="src"
+	    ><a id="v:foo" class="def"
+	      >foo</a
+	      > :: f <a href="#" title="Data.Int"
+	      >Int</a
+	      > -&gt; a -&gt; f a <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ><p class="src"
+	    ><a id="v:foo-39-" class="def"
+	      >foo'</a
+	      > :: f (f a) -&gt; <a href="#" title="Data.Int"
+	      >Int</a
+	      > -&gt; f (f <a href="#" title="Data.Int"
+	      >Int</a
+	      >) <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ></div
+	  ><div class="subs instances"
+	  ><h4 class="instances details-toggle-control details-toggle" data-details-id="i:Foo"
+	    >Instances</h4
+	    ><details id="i:Foo" open="open"
+	    ><summary class="hide-when-js-enabled"
+	      >Instances details</summary
+	      ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:ic:Foo:Foo:1"
+		      ></span
+		      > <a href="#" title="Instances"
+		      >Foo</a
+		      > <a href="#" title="Data.Maybe"
+		      >Maybe</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:ic:Foo:Foo:1"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Instances</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >foo</a
+			  > :: <a href="#" title="Data.Maybe"
+			  >Maybe</a
+			  > <a href="#" title="Data.Int"
+			  >Int</a
+			  > -&gt; a -&gt; <a href="#" title="Data.Maybe"
+			  >Maybe</a
+			  > a <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >foo'</a
+			  > :: <a href="#" title="Data.Maybe"
+			  >Maybe</a
+			  > (<a href="#" title="Data.Maybe"
+			  >Maybe</a
+			  > a) -&gt; <a href="#" title="Data.Int"
+			  >Int</a
+			  > -&gt; <a href="#" title="Data.Maybe"
+			  >Maybe</a
+			  > (<a href="#" title="Data.Maybe"
+			  >Maybe</a
+			  > <a href="#" title="Data.Int"
+			  >Int</a
+			  >) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:ic:Foo:Foo:2"
+		      ></span
+		      > <a href="#" title="Instances"
+		      >Foo</a
+		      > <a href="#" title="GHC.List"
+		      >List</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:ic:Foo:Foo:2"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Instances</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >foo</a
+			  > :: [<a href="#" title="Data.Int"
+			  >Int</a
+			  >] -&gt; a -&gt; [a] <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >foo'</a
+			  > :: [[a]] -&gt; <a href="#" title="Data.Int"
+			  >Int</a
+			  > -&gt; [[<a href="#" title="Data.Int"
+			  >Int</a
+			  >]] <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:ic:Foo:Foo:3"
+		      ></span
+		      > <a href="#" title="Instances"
+		      >Foo</a
+		      > (<a href="#" title="Data.Either"
+		      >Either</a
+		      > a)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:ic:Foo:Foo:3"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Instances</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >foo</a
+			  > :: <a href="#" title="Data.Either"
+			  >Either</a
+			  > a <a href="#" title="Data.Int"
+			  >Int</a
+			  > -&gt; a0 -&gt; <a href="#" title="Data.Either"
+			  >Either</a
+			  > a a0 <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >foo'</a
+			  > :: <a href="#" title="Data.Either"
+			  >Either</a
+			  > a (<a href="#" title="Data.Either"
+			  >Either</a
+			  > a a0) -&gt; <a href="#" title="Data.Int"
+			  >Int</a
+			  > -&gt; <a href="#" title="Data.Either"
+			  >Either</a
+			  > a (<a href="#" title="Data.Either"
+			  >Either</a
+			  > a <a href="#" title="Data.Int"
+			  >Int</a
+			  >) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:ic:Foo:Foo:4"
+		      ></span
+		      > <a href="#" title="Instances"
+		      >Foo</a
+		      > (<a href="#" title="Instances"
+		      >(&lt;~~)</a
+		      > a)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:ic:Foo:Foo:4"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Instances</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >foo</a
+			  > :: (a <a href="#" title="Instances"
+			  >&lt;~~</a
+			  > <a href="#" title="Data.Int"
+			  >Int</a
+			  >) -&gt; a0 -&gt; a <a href="#" title="Instances"
+			  >&lt;~~</a
+			  > a0 <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >foo'</a
+			  > :: (a <a href="#" title="Instances"
+			  >&lt;~~</a
+			  > (a <a href="#" title="Instances"
+			  >&lt;~~</a
+			  > a0)) -&gt; <a href="#" title="Data.Int"
+			  >Int</a
+			  > -&gt; a <a href="#" title="Instances"
+			  >&lt;~~</a
+			  > (a <a href="#" title="Instances"
+			  >&lt;~~</a
+			  > <a href="#" title="Data.Int"
+			  >Int</a
+			  >) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:ic:Foo:Foo:5"
+		      ></span
+		      > (<a href="#" title="Data.Eq"
+		      >Eq</a
+		      > a, <a href="#" title="Instances"
+		      >Foo</a
+		      > f) =&gt; <a href="#" title="Instances"
+		      >Foo</a
+		      > (<a href="#" title="GHC.Tuple.Prim"
+		      >(,)</a
+		      > (f a))</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:ic:Foo:Foo:5"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Instances</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >foo</a
+			  > :: (f a, <a href="#" title="Data.Int"
+			  >Int</a
+			  >) -&gt; a0 -&gt; (f a, a0) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >foo'</a
+			  > :: (f a, (f a, a0)) -&gt; <a href="#" title="Data.Int"
+			  >Int</a
+			  > -&gt; (f a, (f a, <a href="#" title="Data.Int"
+			  >Int</a
+			  >)) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:ic:Foo:Foo:6"
+		      ></span
+		      > <a href="#" title="Instances"
+		      >Foo</a
+		      > (<a href="#" title="Instances"
+		      >Quux</a
+		      > a b)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:ic:Foo:Foo:6"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Instances</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >foo</a
+			  > :: <a href="#" title="Instances"
+			  >Quux</a
+			  > a b <a href="#" title="Data.Int"
+			  >Int</a
+			  > -&gt; a0 -&gt; <a href="#" title="Instances"
+			  >Quux</a
+			  > a b a0 <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >foo'</a
+			  > :: <a href="#" title="Instances"
+			  >Quux</a
+			  > a b (<a href="#" title="Instances"
+			  >Quux</a
+			  > a b a0) -&gt; <a href="#" title="Data.Int"
+			  >Int</a
+			  > -&gt; <a href="#" title="Instances"
+			  >Quux</a
+			  > a b (<a href="#" title="Instances"
+			  >Quux</a
+			  > a b <a href="#" title="Data.Int"
+			  >Int</a
+			  >) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:ic:Foo:Foo:7"
+		      ></span
+		      > <a href="#" title="Instances"
+		      >Foo</a
+		      > (<a href="#" title="GHC.Tuple.Prim"
+		      >(,,)</a
+		      > a a)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:ic:Foo:Foo:7"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Instances</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >foo</a
+			  > :: (a, a, <a href="#" title="Data.Int"
+			  >Int</a
+			  >) -&gt; a0 -&gt; (a, a, a0) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >foo'</a
+			  > :: (a, a, (a, a, a0)) -&gt; <a href="#" title="Data.Int"
+			  >Int</a
+			  > -&gt; (a, a, (a, a, <a href="#" title="Data.Int"
+			  >Int</a
+			  >)) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:ic:Foo:Foo:8"
+		      ></span
+		      > <a href="#" title="Instances"
+		      >Foo</a
+		      > ((-&gt;) a)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:ic:Foo:Foo:8"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Instances</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >foo</a
+			  > :: (a -&gt; <a href="#" title="Data.Int"
+			  >Int</a
+			  >) -&gt; a0 -&gt; a -&gt; a0 <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >foo'</a
+			  > :: (a -&gt; (a -&gt; a0)) -&gt; <a href="#" title="Data.Int"
+			  >Int</a
+			  > -&gt; a -&gt; (a -&gt; <a href="#" title="Data.Int"
+			  >Int</a
+			  >) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		></table
+	      ></details
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >class</span
+	    > <a href="#" title="Instances"
+	    >Foo</a
+	    > f =&gt; <a id="t:Bar" class="def"
+	    >Bar</a
+	    > f a <span class="keyword"
+	    >where</span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs minimal"
+	  ><p class="caption"
+	    >Minimal complete definition</p
+	    ><p class="src"
+	    >Nothing</p
+	    ></div
+	  ><div class="subs methods"
+	  ><p class="caption"
+	    >Methods</p
+	    ><p class="src"
+	    ><a id="v:bar" class="def"
+	      >bar</a
+	      > :: f a -&gt; f <a href="#" title="Data.Bool"
+	      >Bool</a
+	      > -&gt; a <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ><p class="src"
+	    ><a id="v:bar-39-" class="def"
+	      >bar'</a
+	      > :: f (f a) -&gt; f (f (f b)) <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ><p class="src"
+	    ><a id="v:bar0" class="def"
+	      >bar0</a
+	      > :: (f a, f a) -&gt; (f b, f c) <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ><p class="src"
+	    ><a id="v:bar1" class="def"
+	      >bar1</a
+	      > :: (f a, f a) -&gt; (f b, f c) <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ></div
+	  ><div class="subs instances"
+	  ><h4 class="instances details-toggle-control details-toggle" data-details-id="i:Bar"
+	    >Instances</h4
+	    ><details id="i:Bar" open="open"
+	    ><summary class="hide-when-js-enabled"
+	      >Instances details</summary
+	      ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:ic:Bar:Bar:1"
+		      ></span
+		      > <a href="#" title="Instances"
+		      >Bar</a
+		      > <a href="#" title="Data.Maybe"
+		      >Maybe</a
+		      > <a href="#" title="Data.Bool"
+		      >Bool</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:ic:Bar:Bar:1"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Instances</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >bar</a
+			  > :: <a href="#" title="Data.Maybe"
+			  >Maybe</a
+			  > <a href="#" title="Data.Bool"
+			  >Bool</a
+			  > -&gt; <a href="#" title="Data.Maybe"
+			  >Maybe</a
+			  > <a href="#" title="Data.Bool"
+			  >Bool</a
+			  > -&gt; <a href="#" title="Data.Bool"
+			  >Bool</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >bar'</a
+			  > :: <a href="#" title="Data.Maybe"
+			  >Maybe</a
+			  > (<a href="#" title="Data.Maybe"
+			  >Maybe</a
+			  > <a href="#" title="Data.Bool"
+			  >Bool</a
+			  >) -&gt; <a href="#" title="Data.Maybe"
+			  >Maybe</a
+			  > (<a href="#" title="Data.Maybe"
+			  >Maybe</a
+			  > (<a href="#" title="Data.Maybe"
+			  >Maybe</a
+			  > b)) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >bar0</a
+			  > :: (<a href="#" title="Data.Maybe"
+			  >Maybe</a
+			  > <a href="#" title="Data.Bool"
+			  >Bool</a
+			  >, <a href="#" title="Data.Maybe"
+			  >Maybe</a
+			  > <a href="#" title="Data.Bool"
+			  >Bool</a
+			  >) -&gt; (<a href="#" title="Data.Maybe"
+			  >Maybe</a
+			  > b, <a href="#" title="Data.Maybe"
+			  >Maybe</a
+			  > c) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >bar1</a
+			  > :: (<a href="#" title="Data.Maybe"
+			  >Maybe</a
+			  > <a href="#" title="Data.Bool"
+			  >Bool</a
+			  >, <a href="#" title="Data.Maybe"
+			  >Maybe</a
+			  > <a href="#" title="Data.Bool"
+			  >Bool</a
+			  >) -&gt; (<a href="#" title="Data.Maybe"
+			  >Maybe</a
+			  > b, <a href="#" title="Data.Maybe"
+			  >Maybe</a
+			  > c) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:ic:Bar:Bar:2"
+		      ></span
+		      > <a href="#" title="Instances"
+		      >Bar</a
+		      > <a href="#" title="Data.Maybe"
+		      >Maybe</a
+		      > [a]</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:ic:Bar:Bar:2"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Instances</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >bar</a
+			  > :: <a href="#" title="Data.Maybe"
+			  >Maybe</a
+			  > [a] -&gt; <a href="#" title="Data.Maybe"
+			  >Maybe</a
+			  > <a href="#" title="Data.Bool"
+			  >Bool</a
+			  > -&gt; [a] <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >bar'</a
+			  > :: <a href="#" title="Data.Maybe"
+			  >Maybe</a
+			  > (<a href="#" title="Data.Maybe"
+			  >Maybe</a
+			  > [a]) -&gt; <a href="#" title="Data.Maybe"
+			  >Maybe</a
+			  > (<a href="#" title="Data.Maybe"
+			  >Maybe</a
+			  > (<a href="#" title="Data.Maybe"
+			  >Maybe</a
+			  > b)) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >bar0</a
+			  > :: (<a href="#" title="Data.Maybe"
+			  >Maybe</a
+			  > [a], <a href="#" title="Data.Maybe"
+			  >Maybe</a
+			  > [a]) -&gt; (<a href="#" title="Data.Maybe"
+			  >Maybe</a
+			  > b, <a href="#" title="Data.Maybe"
+			  >Maybe</a
+			  > c) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >bar1</a
+			  > :: (<a href="#" title="Data.Maybe"
+			  >Maybe</a
+			  > [a], <a href="#" title="Data.Maybe"
+			  >Maybe</a
+			  > [a]) -&gt; (<a href="#" title="Data.Maybe"
+			  >Maybe</a
+			  > b, <a href="#" title="Data.Maybe"
+			  >Maybe</a
+			  > c) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:ic:Bar:Bar:3"
+		      ></span
+		      > <a href="#" title="Instances"
+		      >Bar</a
+		      > <a href="#" title="GHC.List"
+		      >List</a
+		      > (a, a)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:ic:Bar:Bar:3"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Instances</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >bar</a
+			  > :: [(a, a)] -&gt; [<a href="#" title="Data.Bool"
+			  >Bool</a
+			  >] -&gt; (a, a) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >bar'</a
+			  > :: [[(a, a)]] -&gt; [[[b]]] <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >bar0</a
+			  > :: ([(a, a)], [(a, a)]) -&gt; ([b], [c]) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >bar1</a
+			  > :: ([(a, a)], [(a, a)]) -&gt; ([b], [c]) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:ic:Bar:Bar:4"
+		      ></span
+		      > <a href="#" title="Instances"
+		      >Foo</a
+		      > f =&gt; <a href="#" title="Instances"
+		      >Bar</a
+		      > (<a href="#" title="Data.Either"
+		      >Either</a
+		      > a) (f a)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:ic:Bar:Bar:4"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Instances</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >bar</a
+			  > :: <a href="#" title="Data.Either"
+			  >Either</a
+			  > a (f a) -&gt; <a href="#" title="Data.Either"
+			  >Either</a
+			  > a <a href="#" title="Data.Bool"
+			  >Bool</a
+			  > -&gt; f a <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >bar'</a
+			  > :: <a href="#" title="Data.Either"
+			  >Either</a
+			  > a (<a href="#" title="Data.Either"
+			  >Either</a
+			  > a (f a)) -&gt; <a href="#" title="Data.Either"
+			  >Either</a
+			  > a (<a href="#" title="Data.Either"
+			  >Either</a
+			  > a (<a href="#" title="Data.Either"
+			  >Either</a
+			  > a b)) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >bar0</a
+			  > :: (<a href="#" title="Data.Either"
+			  >Either</a
+			  > a (f a), <a href="#" title="Data.Either"
+			  >Either</a
+			  > a (f a)) -&gt; (<a href="#" title="Data.Either"
+			  >Either</a
+			  > a b, <a href="#" title="Data.Either"
+			  >Either</a
+			  > a c) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >bar1</a
+			  > :: (<a href="#" title="Data.Either"
+			  >Either</a
+			  > a (f a), <a href="#" title="Data.Either"
+			  >Either</a
+			  > a (f a)) -&gt; (<a href="#" title="Data.Either"
+			  >Either</a
+			  > a b, <a href="#" title="Data.Either"
+			  >Either</a
+			  > a c) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:ic:Bar:Bar:5"
+		      ></span
+		      > <a href="#" title="Instances"
+		      >Bar</a
+		      > (<a href="#" title="Instances"
+		      >Quux</a
+		      > a c) (<a href="#" title="Instances"
+		      >Quux</a
+		      > a b c)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:ic:Bar:Bar:5"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Instances</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >bar</a
+			  > :: <a href="#" title="Instances"
+			  >Quux</a
+			  > a c (<a href="#" title="Instances"
+			  >Quux</a
+			  > a b c) -&gt; <a href="#" title="Instances"
+			  >Quux</a
+			  > a c <a href="#" title="Data.Bool"
+			  >Bool</a
+			  > -&gt; <a href="#" title="Instances"
+			  >Quux</a
+			  > a b c <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >bar'</a
+			  > :: <a href="#" title="Instances"
+			  >Quux</a
+			  > a c (<a href="#" title="Instances"
+			  >Quux</a
+			  > a c (<a href="#" title="Instances"
+			  >Quux</a
+			  > a b c)) -&gt; <a href="#" title="Instances"
+			  >Quux</a
+			  > a c (<a href="#" title="Instances"
+			  >Quux</a
+			  > a c (<a href="#" title="Instances"
+			  >Quux</a
+			  > a c b0)) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >bar0</a
+			  > :: (<a href="#" title="Instances"
+			  >Quux</a
+			  > a c (<a href="#" title="Instances"
+			  >Quux</a
+			  > a b c), <a href="#" title="Instances"
+			  >Quux</a
+			  > a c (<a href="#" title="Instances"
+			  >Quux</a
+			  > a b c)) -&gt; (<a href="#" title="Instances"
+			  >Quux</a
+			  > a c b0, <a href="#" title="Instances"
+			  >Quux</a
+			  > a c c0) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >bar1</a
+			  > :: (<a href="#" title="Instances"
+			  >Quux</a
+			  > a c (<a href="#" title="Instances"
+			  >Quux</a
+			  > a b c), <a href="#" title="Instances"
+			  >Quux</a
+			  > a c (<a href="#" title="Instances"
+			  >Quux</a
+			  > a b c)) -&gt; (<a href="#" title="Instances"
+			  >Quux</a
+			  > a c b0, <a href="#" title="Instances"
+			  >Quux</a
+			  > a c c0) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:ic:Bar:Bar:6"
+		      ></span
+		      > <a href="#" title="Instances"
+		      >Foo</a
+		      > (<a href="#" title="GHC.Tuple.Prim"
+		      >(,,)</a
+		      > a b) =&gt; <a href="#" title="Instances"
+		      >Bar</a
+		      > (<a href="#" title="GHC.Tuple.Prim"
+		      >(,,)</a
+		      > a b) (a, b, a)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:ic:Bar:Bar:6"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Instances</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >bar</a
+			  > :: (a, b, (a, b, a)) -&gt; (a, b, <a href="#" title="Data.Bool"
+			  >Bool</a
+			  >) -&gt; (a, b, a) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >bar'</a
+			  > :: (a, b, (a, b, (a, b, a))) -&gt; (a, b, (a, b, (a, b, b0))) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >bar0</a
+			  > :: ((a, b, (a, b, a)), (a, b, (a, b, a))) -&gt; ((a, b, b0), (a, b, c)) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >bar1</a
+			  > :: ((a, b, (a, b, a)), (a, b, (a, b, a))) -&gt; ((a, b, b0), (a, b, c)) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		></table
+	      ></details
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >class</span
+	    > <a id="t:Baz" class="def"
+	    >Baz</a
+	    > a <span class="keyword"
+	    >where</span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs minimal"
+	  ><p class="caption"
+	    >Minimal complete definition</p
+	    ><p class="src"
+	    >Nothing</p
+	    ></div
+	  ><div class="subs methods"
+	  ><p class="caption"
+	    >Methods</p
+	    ><p class="src"
+	    ><a id="v:baz" class="def"
+	      >baz</a
+	      > :: a -&gt; (<span class="keyword"
+	      >forall</span
+	      > a. a -&gt; a) -&gt; (b, <span class="keyword"
+	      >forall</span
+	      > c. c -&gt; a) -&gt; (b, c) <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ><p class="src"
+	    ><a id="v:baz-39-" class="def"
+	      >baz'</a
+	      > :: b -&gt; (<span class="keyword"
+	      >forall</span
+	      > b. b -&gt; a) -&gt; (<span class="keyword"
+	      >forall</span
+	      > b. b -&gt; a) -&gt; [(b, a)] <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ><p class="src"
+	    ><a id="v:baz-39--39-" class="def"
+	      >baz''</a
+	      > :: b -&gt; (<span class="keyword"
+	      >forall</span
+	      > b. (<span class="keyword"
+	      >forall</span
+	      > b. b -&gt; a) -&gt; c) -&gt; <span class="keyword"
+	      >forall</span
+	      > c. c -&gt; b <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ></div
+	  ><div class="subs instances"
+	  ><h4 class="instances details-toggle-control details-toggle" data-details-id="i:Baz"
+	    >Instances</h4
+	    ><details id="i:Baz" open="open"
+	    ><summary class="hide-when-js-enabled"
+	      >Instances details</summary
+	      ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:ic:Baz:Baz:1"
+		      ></span
+		      > <a href="#" title="Instances"
+		      >Baz</a
+		      > [c]</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:ic:Baz:Baz:1"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Instances</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >baz</a
+			  > :: [c] -&gt; (<span class="keyword"
+			  >forall</span
+			  > a1. a1 -&gt; a1) -&gt; (b, <span class="keyword"
+			  >forall</span
+			  > c1. c1 -&gt; [c]) -&gt; (b, c0) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >baz'</a
+			  > :: b -&gt; (<span class="keyword"
+			  >forall</span
+			  > b1. b1 -&gt; [c]) -&gt; (<span class="keyword"
+			  >forall</span
+			  > b1. b1 -&gt; [c]) -&gt; [(b, [c])] <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >baz''</a
+			  > :: b -&gt; (<span class="keyword"
+			  >forall</span
+			  > b1. (<span class="keyword"
+			  >forall</span
+			  > b2. b2 -&gt; [c]) -&gt; c0) -&gt; <span class="keyword"
+			  >forall</span
+			  > c1. c1 -&gt; b <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:ic:Baz:Baz:2"
+		      ></span
+		      > <a href="#" title="Instances"
+		      >Baz</a
+		      > (a -&gt; b)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:ic:Baz:Baz:2"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Instances</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >baz</a
+			  > :: (a -&gt; b) -&gt; (<span class="keyword"
+			  >forall</span
+			  > a1. a1 -&gt; a1) -&gt; (b0, <span class="keyword"
+			  >forall</span
+			  > c1. c1 -&gt; a -&gt; b) -&gt; (b0, c) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >baz'</a
+			  > :: b0 -&gt; (<span class="keyword"
+			  >forall</span
+			  > b1. b1 -&gt; a -&gt; b) -&gt; (<span class="keyword"
+			  >forall</span
+			  > b1. b1 -&gt; a -&gt; b) -&gt; [(b0, a -&gt; b)] <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >baz''</a
+			  > :: b0 -&gt; (<span class="keyword"
+			  >forall</span
+			  > b1. (<span class="keyword"
+			  >forall</span
+			  > b2. b2 -&gt; a -&gt; b) -&gt; c) -&gt; <span class="keyword"
+			  >forall</span
+			  > c1. c1 -&gt; b0 <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:ic:Baz:Baz:3"
+		      ></span
+		      > <a href="#" title="Instances"
+		      >Baz</a
+		      > (<a href="#" title="Instances"
+		      >Quux</a
+		      > a b c)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:ic:Baz:Baz:3"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Instances</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >baz</a
+			  > :: <a href="#" title="Instances"
+			  >Quux</a
+			  > a b c -&gt; (<span class="keyword"
+			  >forall</span
+			  > a1. a1 -&gt; a1) -&gt; (b0, <span class="keyword"
+			  >forall</span
+			  > c1. c1 -&gt; <a href="#" title="Instances"
+			  >Quux</a
+			  > a b c) -&gt; (b0, c0) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >baz'</a
+			  > :: b0 -&gt; (<span class="keyword"
+			  >forall</span
+			  > b1. b1 -&gt; <a href="#" title="Instances"
+			  >Quux</a
+			  > a b c) -&gt; (<span class="keyword"
+			  >forall</span
+			  > b1. b1 -&gt; <a href="#" title="Instances"
+			  >Quux</a
+			  > a b c) -&gt; [(b0, <a href="#" title="Instances"
+			  >Quux</a
+			  > a b c)] <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >baz''</a
+			  > :: b0 -&gt; (<span class="keyword"
+			  >forall</span
+			  > b1. (<span class="keyword"
+			  >forall</span
+			  > b2. b2 -&gt; <a href="#" title="Instances"
+			  >Quux</a
+			  > a b c) -&gt; c0) -&gt; <span class="keyword"
+			  >forall</span
+			  > c1. c1 -&gt; b0 <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:ic:Baz:Baz:4"
+		      ></span
+		      > <a href="#" title="Instances"
+		      >Baz</a
+		      > (a, b, c)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:ic:Baz:Baz:4"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Instances</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >baz</a
+			  > :: (a, b, c) -&gt; (<span class="keyword"
+			  >forall</span
+			  > a1. a1 -&gt; a1) -&gt; (b0, <span class="keyword"
+			  >forall</span
+			  > c1. c1 -&gt; (a, b, c)) -&gt; (b0, c0) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >baz'</a
+			  > :: b0 -&gt; (<span class="keyword"
+			  >forall</span
+			  > b1. b1 -&gt; (a, b, c)) -&gt; (<span class="keyword"
+			  >forall</span
+			  > b1. b1 -&gt; (a, b, c)) -&gt; [(b0, (a, b, c))] <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >baz''</a
+			  > :: b0 -&gt; (<span class="keyword"
+			  >forall</span
+			  > b1. (<span class="keyword"
+			  >forall</span
+			  > b2. b2 -&gt; (a, b, c)) -&gt; c0) -&gt; <span class="keyword"
+			  >forall</span
+			  > c1. c1 -&gt; b0 <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:ic:Baz:Baz:5"
+		      ></span
+		      > <a href="#" title="Instances"
+		      >Baz</a
+		      > (a, [b], b, a)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:ic:Baz:Baz:5"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Instances</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >baz</a
+			  > :: (a, [b], b, a) -&gt; (<span class="keyword"
+			  >forall</span
+			  > a1. a1 -&gt; a1) -&gt; (b0, <span class="keyword"
+			  >forall</span
+			  > c1. c1 -&gt; (a, [b], b, a)) -&gt; (b0, c) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >baz'</a
+			  > :: b0 -&gt; (<span class="keyword"
+			  >forall</span
+			  > b1. b1 -&gt; (a, [b], b, a)) -&gt; (<span class="keyword"
+			  >forall</span
+			  > b1. b1 -&gt; (a, [b], b, a)) -&gt; [(b0, (a, [b], b, a))] <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >baz''</a
+			  > :: b0 -&gt; (<span class="keyword"
+			  >forall</span
+			  > b1. (<span class="keyword"
+			  >forall</span
+			  > b2. b2 -&gt; (a, [b], b, a)) -&gt; c) -&gt; <span class="keyword"
+			  >forall</span
+			  > c1. c1 -&gt; b0 <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		></table
+	      ></details
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:Quux" class="def"
+	    >Quux</a
+	    > a b c <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:Qx" class="def"
+		  >Qx</a
+		  > a</td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ><tr
+	      ><td class="src"
+		><a id="v:Qux" class="def"
+		  >Qux</a
+		  > a b</td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ><tr
+	      ><td class="src"
+		><a id="v:Quux" class="def"
+		  >Quux</a
+		  > a b c</td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ></table
+	    ></div
+	  ><div class="subs instances"
+	  ><h4 class="instances details-toggle-control details-toggle" data-details-id="i:Quux"
+	    >Instances</h4
+	    ><details id="i:Quux" open="open"
+	    ><summary class="hide-when-js-enabled"
+	      >Instances details</summary
+	      ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:Quux:Foo:1"
+		      ></span
+		      > <a href="#" title="Instances"
+		      >Foo</a
+		      > (<a href="#" title="Instances"
+		      >Quux</a
+		      > a b)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:Quux:Foo:1"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Instances</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >foo</a
+			  > :: <a href="#" title="Instances"
+			  >Quux</a
+			  > a b <a href="#" title="Data.Int"
+			  >Int</a
+			  > -&gt; a0 -&gt; <a href="#" title="Instances"
+			  >Quux</a
+			  > a b a0 <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >foo'</a
+			  > :: <a href="#" title="Instances"
+			  >Quux</a
+			  > a b (<a href="#" title="Instances"
+			  >Quux</a
+			  > a b a0) -&gt; <a href="#" title="Data.Int"
+			  >Int</a
+			  > -&gt; <a href="#" title="Instances"
+			  >Quux</a
+			  > a b (<a href="#" title="Instances"
+			  >Quux</a
+			  > a b <a href="#" title="Data.Int"
+			  >Int</a
+			  >) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:Quux:Bar:2"
+		      ></span
+		      > <a href="#" title="Instances"
+		      >Bar</a
+		      > (<a href="#" title="Instances"
+		      >Quux</a
+		      > a c) (<a href="#" title="Instances"
+		      >Quux</a
+		      > a b c)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:Quux:Bar:2"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Instances</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >bar</a
+			  > :: <a href="#" title="Instances"
+			  >Quux</a
+			  > a c (<a href="#" title="Instances"
+			  >Quux</a
+			  > a b c) -&gt; <a href="#" title="Instances"
+			  >Quux</a
+			  > a c <a href="#" title="Data.Bool"
+			  >Bool</a
+			  > -&gt; <a href="#" title="Instances"
+			  >Quux</a
+			  > a b c <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >bar'</a
+			  > :: <a href="#" title="Instances"
+			  >Quux</a
+			  > a c (<a href="#" title="Instances"
+			  >Quux</a
+			  > a c (<a href="#" title="Instances"
+			  >Quux</a
+			  > a b c)) -&gt; <a href="#" title="Instances"
+			  >Quux</a
+			  > a c (<a href="#" title="Instances"
+			  >Quux</a
+			  > a c (<a href="#" title="Instances"
+			  >Quux</a
+			  > a c b0)) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >bar0</a
+			  > :: (<a href="#" title="Instances"
+			  >Quux</a
+			  > a c (<a href="#" title="Instances"
+			  >Quux</a
+			  > a b c), <a href="#" title="Instances"
+			  >Quux</a
+			  > a c (<a href="#" title="Instances"
+			  >Quux</a
+			  > a b c)) -&gt; (<a href="#" title="Instances"
+			  >Quux</a
+			  > a c b0, <a href="#" title="Instances"
+			  >Quux</a
+			  > a c c0) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >bar1</a
+			  > :: (<a href="#" title="Instances"
+			  >Quux</a
+			  > a c (<a href="#" title="Instances"
+			  >Quux</a
+			  > a b c), <a href="#" title="Instances"
+			  >Quux</a
+			  > a c (<a href="#" title="Instances"
+			  >Quux</a
+			  > a b c)) -&gt; (<a href="#" title="Instances"
+			  >Quux</a
+			  > a c b0, <a href="#" title="Instances"
+			  >Quux</a
+			  > a c c0) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:Quux:Baz:3"
+		      ></span
+		      > <a href="#" title="Instances"
+		      >Baz</a
+		      > (<a href="#" title="Instances"
+		      >Quux</a
+		      > a b c)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:Quux:Baz:3"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Instances</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >baz</a
+			  > :: <a href="#" title="Instances"
+			  >Quux</a
+			  > a b c -&gt; (<span class="keyword"
+			  >forall</span
+			  > a1. a1 -&gt; a1) -&gt; (b0, <span class="keyword"
+			  >forall</span
+			  > c1. c1 -&gt; <a href="#" title="Instances"
+			  >Quux</a
+			  > a b c) -&gt; (b0, c0) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >baz'</a
+			  > :: b0 -&gt; (<span class="keyword"
+			  >forall</span
+			  > b1. b1 -&gt; <a href="#" title="Instances"
+			  >Quux</a
+			  > a b c) -&gt; (<span class="keyword"
+			  >forall</span
+			  > b1. b1 -&gt; <a href="#" title="Instances"
+			  >Quux</a
+			  > a b c) -&gt; [(b0, <a href="#" title="Instances"
+			  >Quux</a
+			  > a b c)] <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >baz''</a
+			  > :: b0 -&gt; (<span class="keyword"
+			  >forall</span
+			  > b1. (<span class="keyword"
+			  >forall</span
+			  > b2. b2 -&gt; <a href="#" title="Instances"
+			  >Quux</a
+			  > a b c) -&gt; c0) -&gt; <span class="keyword"
+			  >forall</span
+			  > c1. c1 -&gt; b0 <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:Quux:Thud:4"
+		      ></span
+		      > <span class="keyword"
+		      >data</span
+		      > <a href="#" title="Instances"
+		      >Thud</a
+		      > <a href="#" title="Data.Int"
+		      >Int</a
+		      > (<a href="#" title="Instances"
+		      >Quux</a
+		      > a [a] c)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:Quux:Thud:4"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Instances</a
+			></p
+		      > <div class="src"
+		      ><span class="keyword"
+			>data</span
+			> <a href="#" title="Instances"
+			>Thud</a
+			> <a href="#" title="Data.Int"
+			>Int</a
+			> (<a href="#" title="Instances"
+			>Quux</a
+			> a [a] c) <ul class="inst"
+			><li class="inst"
+			  >= <a id="v:Thuud" class="def"
+			    >Thuud</a
+			    > a</li
+			  ><li class="inst"
+			  >| <a id="v:Thuuud" class="def"
+			    >Thuuud</a
+			    > <a href="#" title="Data.Int"
+			    >Int</a
+			    > <a href="#" title="Data.Int"
+			    >Int</a
+			    ></li
+			  ></ul
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		></table
+	      ></details
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >class</span
+	    > <a id="t:Norf" class="def"
+	    >Norf</a
+	    > a b <span class="keyword"
+	    >where</span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs minimal"
+	  ><p class="caption"
+	    >Minimal complete definition</p
+	    ><p class="src"
+	    >Nothing</p
+	    ></div
+	  ><div class="subs associated-types"
+	  ><p class="caption"
+	    >Associated Types</p
+	    ><p class="src"
+	    ><span class="keyword"
+	      >type</span
+	      > <a id="t:Plugh" class="def"
+	      >Plugh</a
+	      > a c b <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ><p class="src"
+	    ><span class="keyword"
+	      >data</span
+	      > <a id="t:Thud" class="def"
+	      >Thud</a
+	      > a c <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ></div
+	  ><div class="subs methods"
+	  ><p class="caption"
+	    >Methods</p
+	    ><p class="src"
+	    ><a id="v:norf" class="def"
+	      >norf</a
+	      > :: <a href="#" title="Instances"
+	      >Plugh</a
+	      > a c b -&gt; a -&gt; (a -&gt; c) -&gt; b <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ></div
+	  ><div class="subs instances"
+	  ><h4 class="instances details-toggle-control details-toggle" data-details-id="i:Norf"
+	    >Instances</h4
+	    ><details id="i:Norf" open="open"
+	    ><summary class="hide-when-js-enabled"
+	      >Instances details</summary
+	      ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:ic:Norf:Norf:1"
+		      ></span
+		      > <a href="#" title="Instances"
+		      >Norf</a
+		      > <a href="#" title="Data.Int"
+		      >Int</a
+		      > <a href="#" title="Data.Bool"
+		      >Bool</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:ic:Norf:Norf:1"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Instances</a
+			></p
+		      > <div class="subs associated-types"
+		      ><p class="caption"
+			>Associated Types</p
+			><p class="src"
+			><span class="keyword"
+			  >type</span
+			  > <a href="#" title="Instances"
+			  >Plugh</a
+			  > <a href="#" title="Data.Int"
+			  >Int</a
+			  > c <a href="#" title="Data.Bool"
+			  >Bool</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><span class="keyword"
+			  >data</span
+			  > <a href="#" title="Instances"
+			  >Thud</a
+			  > <a href="#" title="Data.Int"
+			  >Int</a
+			  > c <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >norf</a
+			  > :: <a href="#" title="Instances"
+			  >Plugh</a
+			  > <a href="#" title="Data.Int"
+			  >Int</a
+			  > c <a href="#" title="Data.Bool"
+			  >Bool</a
+			  > -&gt; <a href="#" title="Data.Int"
+			  >Int</a
+			  > -&gt; (<a href="#" title="Data.Int"
+			  >Int</a
+			  > -&gt; c) -&gt; <a href="#" title="Data.Bool"
+			  >Bool</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:ic:Norf:Norf:2"
+		      ></span
+		      > <a href="#" title="Instances"
+		      >Norf</a
+		      > [a] [b]</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:ic:Norf:Norf:2"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Instances</a
+			></p
+		      > <div class="subs associated-types"
+		      ><p class="caption"
+			>Associated Types</p
+			><p class="src"
+			><span class="keyword"
+			  >type</span
+			  > <a href="#" title="Instances"
+			  >Plugh</a
+			  > [a] c [b] <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><span class="keyword"
+			  >data</span
+			  > <a href="#" title="Instances"
+			  >Thud</a
+			  > [a] c <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >norf</a
+			  > :: <a href="#" title="Instances"
+			  >Plugh</a
+			  > [a] c [b] -&gt; [a] -&gt; ([a] -&gt; c) -&gt; [b] <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		></table
+	      ></details
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/LinearTypes.html b/html-test/ref/LinearTypes.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/LinearTypes.html
@@ -0,0 +1,114 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >LinearTypes</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>LinearTypes</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><a href="#"
+	      >unrestricted</a
+	      > :: a -&gt; b</li
+	    ><li class="src short"
+	    ><a href="#"
+	      >linear</a
+	      > :: a %1 -&gt; b</li
+	    ><li class="src short"
+	    ><a href="#"
+	      >poly</a
+	      > :: a %m -&gt; b</li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><a id="v:unrestricted" class="def"
+	    >unrestricted</a
+	    > :: a -&gt; b <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Does something unrestricted.</p
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:linear" class="def"
+	    >linear</a
+	    > :: a %1 -&gt; b <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Does something linear.</p
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:poly" class="def"
+	    >poly</a
+	    > :: a %m -&gt; b <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Does something polymorphic.</p
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Math.html b/html-test/ref/Math.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Math.html
@@ -0,0 +1,114 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Math</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Math</p
+	></div
+      ><div id="description"
+      ><p class="caption"
+	>Description</p
+	><div class="doc"
+	><p
+	  >Math (display) for <code
+	    >normalDensity</code
+	    ></p
+	  ><p
+	  ><span class="mathjax"
+	    >\[
+ \int_{-\infty}^{\infty} e^{-x^2/2} = \sqrt{2\pi}
+ \]</span
+	    ></p
+	  ><p
+	  ><span class="mathjax"
+	    >\(\int_{-\infty}^{\infty} e^{-x^2/2} = \sqrt{2\pi}\)</span
+	    ></p
+	  ></div
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><a href="#"
+	      >f</a
+	      > :: <a href="#" title="Prelude"
+	      >Integer</a
+	      ></li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><a id="v:f" class="def"
+	    >f</a
+	    > :: <a href="#" title="Prelude"
+	    >Integer</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Math (inline) for <code
+	      >normalDensity</code
+	      >
+ <span class="mathjax"
+	      >\(\int_{-\infty}^{\infty} e^{-x^2/2} = \sqrt{2\pi}\)</span
+	      >
+ <span class="mathjax"
+	      >\[\int_{-\infty}^{\infty} e^{-x^2/2} = \sqrt{2\pi}\]</span
+	      ></p
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Minimal.html b/html-test/ref/Minimal.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Minimal.html
@@ -0,0 +1,348 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Minimal</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Minimal</p
+	></div
+      ><div id="description"
+      ><p class="caption"
+	>Description</p
+	><div class="doc"
+	><p
+	  >This tests the new MINIMAL pragma present in GHC 7.8</p
+	  ></div
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >class</span
+	    > <a id="t:Foo" class="def"
+	    >Foo</a
+	    > a <span class="keyword"
+	    >where</span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs minimal"
+	  ><p class="caption"
+	    >Minimal complete definition</p
+	    ><p class="src"
+	    ><a href="#" title="Minimal"
+	      >foo</a
+	      >, <a href="#" title="Minimal"
+	      >bar</a
+	      > | <a href="#" title="Minimal"
+	      >bar</a
+	      >, <a href="#" title="Minimal"
+	      >bat</a
+	      > | <a href="#" title="Minimal"
+	      >foo</a
+	      >, <a href="#" title="Minimal"
+	      >bat</a
+	      > | <a href="#" title="Minimal"
+	      >fooBarBat</a
+	      ></p
+	    ></div
+	  ><div class="subs methods"
+	  ><p class="caption"
+	    >Methods</p
+	    ><p class="src"
+	    ><a id="v:foo" class="def"
+	      >foo</a
+	      > :: a <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ><div class="doc"
+	    ><p
+	      >Any two of these are required...</p
+	      ></div
+	    ><p class="src"
+	    ><a id="v:bar" class="def"
+	      >bar</a
+	      > :: a <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ><p class="src"
+	    ><a id="v:bat" class="def"
+	      >bat</a
+	      > :: a <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ><p class="src"
+	    ><a id="v:fooBarBat" class="def"
+	      >fooBarBat</a
+	      > :: (a, a, a) <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ><div class="doc"
+	    ><p
+	      >.. or just this</p
+	      ></div
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >class</span
+	    > <a id="t:Weird" class="def"
+	    >Weird</a
+	    > a <span class="keyword"
+	    >where</span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs minimal"
+	  ><p class="caption"
+	    >Minimal complete definition</p
+	    ><p class="src"
+	    >(<a href="#" title="Minimal"
+	      >a</a
+	      >, <a href="#" title="Minimal"
+	      >b</a
+	      >, <a href="#" title="Minimal"
+	      >c</a
+	      > | (<a href="#" title="Minimal"
+	      >d</a
+	      > | <a href="#" title="Minimal"
+	      >e</a
+	      >, (<a href="#" title="Minimal"
+	      >f</a
+	      > | <a href="#" title="Minimal"
+	      >g</a
+	      >)))</p
+	    ></div
+	  ><div class="subs methods"
+	  ><p class="caption"
+	    >Methods</p
+	    ><p class="src"
+	    ><a id="v:a" class="def"
+	      >a</a
+	      > :: a <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ><p class="src"
+	    ><a id="v:b" class="def"
+	      >b</a
+	      > :: a <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ><p class="src"
+	    ><a id="v:c" class="def"
+	      >c</a
+	      > :: a <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ><p class="src"
+	    ><a id="v:d" class="def"
+	      >d</a
+	      > :: a <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ><p class="src"
+	    ><a id="v:e" class="def"
+	      >e</a
+	      > :: a <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ><p class="src"
+	    ><a id="v:f" class="def"
+	      >f</a
+	      > :: a <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ><p class="src"
+	    ><a id="v:g" class="def"
+	      >g</a
+	      > :: a <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >class</span
+	    > <a id="t:NoMins" class="def"
+	    >NoMins</a
+	    > a <span class="keyword"
+	    >where</span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs minimal"
+	  ><p class="caption"
+	    >Minimal complete definition</p
+	    ><p class="src"
+	    ><a href="#" title="Minimal"
+	      >x</a
+	      >, <a href="#" title="Minimal"
+	      >y</a
+	      ></p
+	    ></div
+	  ><div class="subs methods"
+	  ><p class="caption"
+	    >Methods</p
+	    ><p class="src"
+	    ><a id="v:x" class="def"
+	      >x</a
+	      > :: a <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ><p class="src"
+	    ><a id="v:y" class="def"
+	      >y</a
+	      > :: a <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ><p class="src"
+	    ><a id="v:z" class="def"
+	      >z</a
+	      > :: a <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >class</span
+	    > <a id="t:FullMin" class="def"
+	    >FullMin</a
+	    > a <span class="keyword"
+	    >where</span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs methods"
+	  ><p class="caption"
+	    >Methods</p
+	    ><p class="src"
+	    ><a id="v:aaa" class="def"
+	      >aaa</a
+	      > :: a <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ><p class="src"
+	    ><a id="v:bbb" class="def"
+	      >bbb</a
+	      > :: a <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >class</span
+	    > <a id="t:PartialMin" class="def"
+	    >PartialMin</a
+	    > a <span class="keyword"
+	    >where</span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs minimal"
+	  ><p class="caption"
+	    >Minimal complete definition</p
+	    ><p class="src"
+	    ><a href="#" title="Minimal"
+	      >ccc</a
+	      >, ddd</p
+	    ></div
+	  ><div class="subs methods"
+	  ><p class="caption"
+	    >Methods</p
+	    ><p class="src"
+	    ><a id="v:ccc" class="def"
+	      >ccc</a
+	      > :: a <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >class</span
+	    > <a id="t:EmptyMin" class="def"
+	    >EmptyMin</a
+	    > a <span class="keyword"
+	    >where</span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs minimal"
+	  ><p class="caption"
+	    >Minimal complete definition</p
+	    ><p class="src"
+	    >Nothing</p
+	    ></div
+	  ><div class="subs methods"
+	  ><p class="caption"
+	    >Methods</p
+	    ><p class="src"
+	    ><a id="v:eee" class="def"
+	      >eee</a
+	      > :: a <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ><p class="src"
+	    ><a id="v:fff" class="def"
+	      >fff</a
+	      > :: a <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/ModuleWithWarning.html b/html-test/ref/ModuleWithWarning.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/ModuleWithWarning.html
@@ -0,0 +1,84 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >ModuleWithWarning</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>ModuleWithWarning</p
+	></div
+      ><div id="description"
+      ><p class="caption"
+	>Description</p
+	><div class="doc"
+	><div class="warning"
+	  ><p
+	    >Warning: This is an unstable interface.  Prefer functions from <a href="#"
+	      >Prelude</a
+	      > instead!</p
+	    ></div
+	  ><p
+	  >Documentation for <a href="#"
+	    >ModuleWithWarning</a
+	    >.</p
+	  ></div
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><a id="v:foo" class="def"
+	    >foo</a
+	    > :: <a href="#" title="Data.Int"
+	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/NamedDoc.html b/html-test/ref/NamedDoc.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/NamedDoc.html
@@ -0,0 +1,70 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >NamedDoc</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>NamedDoc</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="doc"
+	><p
+	  >bar</p
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/NamespacedIdentifiers.html b/html-test/ref/NamespacedIdentifiers.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/NamespacedIdentifiers.html
@@ -0,0 +1,150 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >NamespacedIdentifiers</title
+    ><link href="linuwial.css" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="quick-jump.css"
+     /><link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=PT+Sans:400,400i,700"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="index.html"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="doc-index.html"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>NamespacedIdentifiers</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > <a href="#t:Foo"
+	      >Foo</a
+	      > = <a href="#v:Bar"
+	      >Bar</a
+	      ></li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > <a href="#t:Bar"
+	      >Bar</a
+	      ></li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:Foo" class="def"
+	    >Foo</a
+	    > <a href="#t:Foo" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >A link to:</p
+	    ><ul
+	    ><li
+	      >the type <code
+		><a href="NamespacedIdentifiers.html#t:Bar" title="NamespacedIdentifiers"
+		  >Bar</a
+		  ></code
+		></li
+	      ><li
+	      >the constructor <code
+		><a href="NamespacedIdentifiers.html#v:Bar" title="NamespacedIdentifiers"
+		  >Bar</a
+		  ></code
+		></li
+	      ><li
+	      >the unimported but qualified type <code
+		><a href="A.html#t:A" title="A"
+		  >A</a
+		  ></code
+		></li
+	      ><li
+	      >the unimported but qualified value <code
+		><a href="A.html#v:A" title="A"
+		  >A</a
+		  ></code
+		></li
+	      ></ul
+	    ></div
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:Bar" class="def"
+		  >Bar</a
+		  ></td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:Bar" class="def"
+	    >Bar</a
+	    > <a href="#t:Bar" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >A link to the value <code
+	      >Foo</code
+	      > (which shouldn't exist).</p
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Nesting.html b/html-test/ref/Nesting.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Nesting.html
@@ -0,0 +1,364 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Nesting</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Nesting</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><a href="#"
+	      >d</a
+	      > :: t</li
+	    ><li class="src short"
+	    ><a href="#"
+	      >e</a
+	      > :: t</li
+	    ><li class="src short"
+	    ><a href="#"
+	      >f</a
+	      > :: t</li
+	    ><li class="src short"
+	    ><a href="#"
+	      >g</a
+	      > :: t</li
+	    ><li class="src short"
+	    ><a href="#"
+	      >h</a
+	      > :: t</li
+	    ><li class="src short"
+	    ><a href="#"
+	      >i</a
+	      > :: t</li
+	    ><li class="src short"
+	    ><a href="#"
+	      >j</a
+	      > :: t</li
+	    ><li class="src short"
+	    ><a href="#"
+	      >k</a
+	      > :: t</li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><a id="v:d" class="def"
+	    >d</a
+	    > :: t <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><ul
+	    ><li
+	      ><p
+		>We can</p
+		><ul
+		><li
+		  ><p
+		    >easily go back</p
+		    ><ol
+		    ><li value="1"
+		      >some indentation</li
+		      ></ol
+		    ></li
+		  ><li
+		  >levels</li
+		  ></ul
+		></li
+	      ></ul
+	    ><ol
+	    ><li value="1"
+	      ><pre
+		>back at the top</pre
+		></li
+	      ></ol
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:e" class="def"
+	    >e</a
+	    > :: t <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><ul
+	    ><li
+	      ><p
+		>Beginning of list</p
+		><ul
+		><li
+		  >second list</li
+		  ></ul
+		></li
+	      ><li
+	      >Some indented list but
+the presence of this text pushes it out of nesting back to the top.</li
+	      ></ul
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:f" class="def"
+	    >f</a
+	    > :: t <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><ul
+	    ><li
+	      ><p
+		>Beginning of list</p
+		><pre
+		>nested code
+    we preserve the space correctly
+</pre
+		></li
+	      ></ul
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:g" class="def"
+	    >g</a
+	    > :: t <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><ul
+	    ><li
+	      ><p
+		>Beginning of list</p
+		><ul
+		><li
+		  >Nested list</li
+		  ></ul
+		></li
+	      ></ul
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:h" class="def"
+	    >h</a
+	    > :: t <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><ul
+	    ><li
+	      ><p
+		>Beginning of list</p
+		><pre
+		>nested
+bird
+tracks</pre
+		></li
+	      ></ul
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:i" class="def"
+	    >i</a
+	    > :: t <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><ul
+	    ><li
+	      ><p
+		>Beginning of list
+This belongs to the list above!</p
+		><pre
+		>nested
+bird
+tracks
+
+another line
+  with indentation</pre
+		><pre
+		>nested bird tracks
+  without leading space</pre
+		><ul
+		><li
+		  ><p
+		    >Next list
+More of the indented list.</p
+		    ><ul
+		    ><li
+		      ><p
+			>Deeper</p
+			><ul
+			><li
+			  ><p
+			    >Deeper</p
+			    ><ul
+			    ><li
+			      >Even deeper!</li
+			      ><li
+			      >No newline separation even in indented lists.</li
+			      ></ul
+			    ></li
+			  ></ul
+			></li
+		      ></ul
+		    ></li
+		  ></ul
+		></li
+	      ></ul
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:j" class="def"
+	    >j</a
+	    > :: t <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><dl
+	    ><dt
+	      >All this</dt
+	      ><dd
+	      >Works for
+definition lists too.<pre
+		>nested
+bird
+tracks</pre
+		><ul
+		><li
+		  ><p
+		    >Next list
+with more of the indented list content.</p
+		    ><p
+		    >Even more content on a new line.</p
+		    ><ol
+		    ><li value="1"
+		      ><p
+			>Different type of list</p
+			><ol
+			><li value="2"
+			  >Deeper</li
+			  ></ol
+			><pre class="screen"
+			><code class="prompt"
+			  >&gt;&gt;&gt; </code
+			  ><strong class="userinput"
+			  ><code
+			    >Here's an example in a list
+</code
+			    ></strong
+			  >example result
+</pre
+			><dl
+			><dt
+			  >b</dt
+			  ><dd
+			  >Even deeper!</dd
+			  ><dt
+			  >c</dt
+			  ><dd
+			  >No newline separation even in indented lists.
+        We can have any paragraph level element that we normally
+        can, like headers</dd
+			  ></dl
+			><h3
+			>Level 3 header</h3
+			><p
+			>with some content&#8230;</p
+			><ul
+			><li
+			  >and even more lists inside</li
+			  ></ul
+			></li
+		      ></ol
+		    ></li
+		  ></ul
+		></dd
+	      ></dl
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:k" class="def"
+	    >k</a
+	    > :: t <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><ul
+	    ><li
+	      >list may start at arbitrary depth</li
+	      ><li
+	      >and consecutive items at that depth
+      belong to the same list</li
+	      ><li
+	      ><p
+		>of course we can still</p
+		><ul
+		><li
+		  >nest items like we are used to</li
+		  ></ul
+		></li
+	      ><li
+	      >and then get back to initial list</li
+	      ></ul
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/NoLayout.html b/html-test/ref/NoLayout.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/NoLayout.html
@@ -0,0 +1,90 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >NoLayout</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>NoLayout</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><a href="#"
+	      >g</a
+	      > :: <a href="#" title="Data.Int"
+	      >Int</a
+	      ></li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><a id="v:g" class="def"
+	    >g</a
+	    > :: <a href="#" title="Data.Int"
+	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >the function <code
+	      ><a href="#" title="NoLayout"
+		>g</a
+		></code
+	      ></p
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/NonGreedy.html b/html-test/ref/NonGreedy.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/NonGreedy.html
@@ -0,0 +1,86 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >NonGreedy</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>NonGreedy</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><a href="#"
+	      >f</a
+	      > :: a</li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><a id="v:f" class="def"
+	    >f</a
+	    > :: a <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    ><a href="#"
+	      >url1</a
+	      > <a href="#"
+	      >url2</a
+	      ></p
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Operators.html b/html-test/ref/Operators.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Operators.html
@@ -0,0 +1,532 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Operators</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Operators</p
+	></div
+      ><div id="description"
+      ><p class="caption"
+	>Description</p
+	><div class="doc"
+	><p
+	  >Test operators with or without fixity declarations</p
+	  ></div
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><a href="#"
+	      >(+-)</a
+	      > :: a -&gt; a -&gt; a</li
+	    ><li class="src short"
+	    ><a href="#"
+	      >(*/)</a
+	      > :: a -&gt; a -&gt; a</li
+	    ><li class="src short"
+	    ><a href="#"
+	      >foo</a
+	      > :: a -&gt; a -&gt; a</li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > <a href="#"
+	      >Foo</a
+	      ><ul class="subs"
+	      ><li
+		>= <a href="#" title="Operators"
+		  >Foo</a
+		  > <a href="#"
+		  >`Bar`</a
+		  > <a href="#" title="Operators"
+		  >Foo</a
+		  ></li
+		><li
+		>| <a href="#" title="Operators"
+		  >Foo</a
+		  > <a href="#"
+		  >:-</a
+		  > <a href="#" title="Operators"
+		  >Foo</a
+		  ></li
+		></ul
+	      ></li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >pattern</span
+	      > <a href="#"
+	      >(:+)</a
+	      > :: a -&gt; a -&gt; [a]</li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > a <a href="#"
+	      >&lt;-&gt;</a
+	      > b <span class="keyword"
+	      >where</span
+	      ><ul class="subs"
+	      ><li
+		><a href="#"
+		  >(:&lt;-&gt;)</a
+		  > :: a -&gt; b -&gt; a <a href="#" title="Operators"
+		  >&lt;-&gt;</a
+		  > b</li
+		></ul
+	      ></li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >type family</span
+	      > a <a href="#"
+	      >++</a
+	      > b</li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >data family</span
+	      > a <a href="#"
+	      >**</a
+	      > b</li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >class</span
+	      > a <a href="#"
+	      >&gt;&lt;&gt;</a
+	      > b | a -&gt; b <span class="keyword"
+	      >where</span
+	      ><ul class="subs"
+	      ><li
+		><span class="keyword"
+		  >type</span
+		  > a <a href="#"
+		  >&lt;&gt;&lt;</a
+		  > b :: *</li
+		><li
+		><span class="keyword"
+		  >data</span
+		  > a <a href="#"
+		  >&gt;&lt;&lt;</a
+		  > b</li
+		><li
+		><a href="#"
+		  >(&gt;&gt;&lt;)</a
+		  >, <a href="#"
+		  >(&lt;&lt;&gt;)</a
+		  > :: a -&gt; b -&gt; ()</li
+		><li
+		><a href="#"
+		  >(**&gt;)</a
+		  >, <a href="#"
+		  >(**&lt;)</a
+		  >, <a href="#"
+		  >(&gt;**)</a
+		  >, <a href="#"
+		  >(&lt;**)</a
+		  > :: a -&gt; a -&gt; ()</li
+		></ul
+	      ></li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >type</span
+	      > <a href="#"
+	      >(&gt;-&lt;)</a
+	      > a b = a <a href="#" title="Operators"
+	      >&lt;-&gt;</a
+	      > b</li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><a id="v:-43--45-" class="def"
+	    >(+-)</a
+	    > :: a -&gt; a -&gt; a <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Operator with no fixity</p
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:-42--47-" class="def"
+	    >(*/)</a
+	    > :: a -&gt; a -&gt; a <span class="fixity"
+	    >infixr 7</span
+	    ><span class="rightedge"
+	    ></span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Operator with infixr 7</p
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:foo" class="def"
+	    >foo</a
+	    > :: a -&gt; a -&gt; a <span class="fixity"
+	    >infixl 3</span
+	    ><span class="rightedge"
+	    ></span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Named function with infixl 3</p
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:Foo" class="def"
+	    >Foo</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Data type with operator constructors</p
+	    ></div
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a href="#" title="Operators"
+		  >Foo</a
+		  > <a id="v:Bar" class="def"
+		  >`Bar`</a
+		  > <a href="#" title="Operators"
+		  >Foo</a
+		  > <span class="fixity"
+		  >infixl 3</span
+		  ><span class="rightedge"
+		  ></span
+		  ></td
+		><td class="doc"
+		><p
+		  >Has infixl 3</p
+		  ></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		><a href="#" title="Operators"
+		  >Foo</a
+		  > <a id="v::-45-" class="def"
+		  >:-</a
+		  > <a href="#" title="Operators"
+		  >Foo</a
+		  > <span class="fixity"
+		  >infixr 5</span
+		  ><span class="rightedge"
+		  ></span
+		  ></td
+		><td class="doc"
+		><p
+		  >Has infixr 5</p
+		  ></td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >pattern</span
+	    > <a id="v::-43-" class="def"
+	    >(:+)</a
+	    > :: a -&gt; a -&gt; [a] <span class="fixity"
+	    >infixr 3</span
+	    ><span class="rightedge"
+	    ></span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Pattern synonym, infixr 3</p
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > a <a id="t:-60--45--62-" class="def"
+	    >&lt;-&gt;</a
+	    > b <span class="keyword"
+	    >where</span
+	    > <span class="fixity"
+	    >infixl 6</span
+	    ><span class="rightedge"
+	    ></span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Type name, infixl 6 and GADT constructor</p
+	    ></div
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v::-60--45--62-" class="def"
+		  >(:&lt;-&gt;)</a
+		  > :: a -&gt; b -&gt; a <a href="#" title="Operators"
+		  >&lt;-&gt;</a
+		  > b <span class="fixity"
+		  >infixr 6</span
+		  ><span class="rightedge"
+		  ></span
+		  ></td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >type family</span
+	    > a <a id="t:-43--43-" class="def"
+	    >++</a
+	    > b <span class="fixity"
+	    >infix 3</span
+	    ><span class="rightedge"
+	    ></span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Type family with fixity</p
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data family</span
+	    > a <a id="t:-42--42-" class="def"
+	    >**</a
+	    > b <span class="fixity"
+	    >infix 9</span
+	    ><span class="rightedge"
+	    ></span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Data family with fixity</p
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >class</span
+	    > a <a id="t:-62--60--62-" class="def"
+	    >&gt;&lt;&gt;</a
+	    > b | a -&gt; b <span class="keyword"
+	    >where</span
+	    > <span class="fixity"
+	    >infixr 1</span
+	    ><span class="rightedge"
+	    ></span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Class with fixity, including associated types</p
+	    ></div
+	  ><div class="subs associated-types"
+	  ><p class="caption"
+	    >Associated Types</p
+	    ><p class="src"
+	    ><span class="keyword"
+	      >type</span
+	      > a <a id="t:-60--62--60-" class="def"
+	      >&lt;&gt;&lt;</a
+	      > b :: * <span class="fixity"
+	      >infixl 2</span
+	      ><span class="rightedge"
+	      ></span
+	      > <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ><p class="src"
+	    ><span class="keyword"
+	      >data</span
+	      > a <a id="t:-62--60--60-" class="def"
+	      >&gt;&lt;&lt;</a
+	      > b <span class="fixity"
+	      >infixl 3</span
+	      ><span class="rightedge"
+	      ></span
+	      > <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ></div
+	  ><div class="subs methods"
+	  ><p class="caption"
+	    >Methods</p
+	    ><p class="src"
+	    ><a id="v:-62--62--60-" class="def"
+	      >(&gt;&gt;&lt;)</a
+	      > :: a -&gt; b -&gt; () <span class="fixity"
+	      >infixr 4</span
+	      ><span class="rightedge"
+	      ></span
+	      > <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ><p class="src"
+	    ><a id="v:-60--60--62-" class="def"
+	      >(&lt;&lt;&gt;)</a
+	      > :: a -&gt; b -&gt; () <span class="fixity"
+	      >infixl 5</span
+	      ><span class="rightedge"
+	      ></span
+	      > <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ><p class="src"
+	    ><a id="v:-42--42--62-" class="def"
+	      >(**&gt;)</a
+	      > :: a -&gt; a -&gt; () <span class="fixity"
+	      >infixr 8</span
+	      ><span class="rightedge"
+	      ></span
+	      > <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ><div class="doc"
+	    ><p
+	      >Multiple fixities</p
+	      ></div
+	    ><p class="src"
+	    ><a id="v:-42--42--60-" class="def"
+	      >(**&lt;)</a
+	      > :: a -&gt; a -&gt; () <span class="fixity"
+	      >infixl 8</span
+	      ><span class="rightedge"
+	      ></span
+	      > <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ><div class="doc"
+	    ><p
+	      >Multiple fixities</p
+	      ></div
+	    ><p class="src"
+	    ><a id="v:-62--42--42-" class="def"
+	      >(&gt;**)</a
+	      > :: a -&gt; a -&gt; () <span class="fixity"
+	      >infixr 8</span
+	      ><span class="rightedge"
+	      ></span
+	      > <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ><div class="doc"
+	    ><p
+	      >Multiple fixities</p
+	      ></div
+	    ><p class="src"
+	    ><a id="v:-60--42--42-" class="def"
+	      >(&lt;**)</a
+	      > :: a -&gt; a -&gt; () <span class="fixity"
+	      >infixl 8</span
+	      ><span class="rightedge"
+	      ></span
+	      > <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ><div class="doc"
+	    ><p
+	      >Multiple fixities</p
+	      ></div
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >type</span
+	    > <a id="t:-62--45--60-" class="def"
+	    >(&gt;-&lt;)</a
+	    > a b = a <a href="#" title="Operators"
+	    >&lt;-&gt;</a
+	    > b <span class="fixity"
+	    >infixl 6</span
+	    ><span class="rightedge"
+	    ></span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Type synonym with fixity</p
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/OrphanInstances.html b/html-test/ref/OrphanInstances.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/OrphanInstances.html
@@ -0,0 +1,116 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >OrphanInstances</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>OrphanInstances</p
+	></div
+      ><div id="table-of-contents"
+      ><div id="contents-list"
+	><p class="caption" onclick="window.scrollTo(0,0)"
+	  >Contents</p
+	  ><ul
+	  ><li
+	    ><a href="#"
+	      >Orphan instances</a
+	      ></li
+	    ></ul
+	  ></div
+	></div
+      ><div id="interface"
+      ><h1
+	>Orphan instances</h1
+	><div id="section.orphans"
+	><table
+	  ><tr
+	    ><td class="src clearfix"
+	      ><span class="inst-left"
+		><span class="instance details-toggle-control details-toggle" data-details-id="i:o:ic:AClass:AClass:1"
+		  ></span
+		  > <a href="#" title="OrphanInstancesClass"
+		  >AClass</a
+		  > <a href="#" title="OrphanInstancesType"
+		  >AType</a
+		  ></span
+		> <a href="#" class="selflink"
+		>#</a
+		></td
+	      ><td class="doc"
+	      ><p
+		>This is an orphan instance.</p
+		></td
+	      ></tr
+	    ><tr
+	    ><td colspan="2"
+	      ><details id="i:o:ic:AClass:AClass:1"
+		><summary class="hide-when-js-enabled"
+		  >Instance details</summary
+		  ><p
+		  ></p
+		  > <div class="subs methods"
+		  ><p class="caption"
+		    >Methods</p
+		    ><p class="src"
+		    ><a href="#"
+		      >aClass</a
+		      > :: <a href="#" title="OrphanInstancesType"
+		      >AType</a
+		      > -&gt; <a href="#" title="Data.Int"
+		      >Int</a
+		      > <a href="#" class="selflink"
+		      >#</a
+		      ></p
+		    ></div
+		  ></details
+		></td
+	      ></tr
+	    ></table
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/OrphanInstancesClass.html b/html-test/ref/OrphanInstancesClass.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/OrphanInstancesClass.html
@@ -0,0 +1,136 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >OrphanInstancesClass</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>OrphanInstancesClass</p
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >class</span
+	    > <a id="t:AClass" class="def"
+	    >AClass</a
+	    > a <span class="keyword"
+	    >where</span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs methods"
+	  ><p class="caption"
+	    >Methods</p
+	    ><p class="src"
+	    ><a id="v:aClass" class="def"
+	      >aClass</a
+	      > :: a -&gt; <a href="#" title="Data.Int"
+	      >Int</a
+	      > <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ></div
+	  ><div class="subs instances"
+	  ><h4 class="instances details-toggle-control details-toggle" data-details-id="i:AClass"
+	    >Instances</h4
+	    ><details id="i:AClass" open="open"
+	    ><summary class="hide-when-js-enabled"
+	      >Instances details</summary
+	      ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:ic:AClass:AClass:1"
+		      ></span
+		      > <a href="#" title="OrphanInstancesClass"
+		      >AClass</a
+		      > <a href="#" title="OrphanInstancesType"
+		      >AType</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    >This is an orphan instance.</p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:ic:AClass:AClass:1"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>OrphanInstances</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >aClass</a
+			  > :: <a href="#" title="OrphanInstancesType"
+			  >AType</a
+			  > -&gt; <a href="#" title="Data.Int"
+			  >Int</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		></table
+	      ></details
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/OrphanInstancesType.html b/html-test/ref/OrphanInstancesType.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/OrphanInstancesType.html
@@ -0,0 +1,138 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >OrphanInstancesType</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>OrphanInstancesType</p
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:AType" class="def"
+	    >AType</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:AType" class="def"
+		  >AType</a
+		  > <a href="#" title="Data.Int"
+		  >Int</a
+		  ></td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ></table
+	    ></div
+	  ><div class="subs instances"
+	  ><h4 class="instances details-toggle-control details-toggle" data-details-id="i:AType"
+	    >Instances</h4
+	    ><details id="i:AType" open="open"
+	    ><summary class="hide-when-js-enabled"
+	      >Instances details</summary
+	      ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:AType:AClass:1"
+		      ></span
+		      > <a href="#" title="OrphanInstancesClass"
+		      >AClass</a
+		      > <a href="#" title="OrphanInstancesType"
+		      >AType</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    >This is an orphan instance.</p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:AType:AClass:1"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>OrphanInstances</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >aClass</a
+			  > :: <a href="#" title="OrphanInstancesType"
+			  >AType</a
+			  > -&gt; <a href="#" title="Data.Int"
+			  >Int</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		></table
+	      ></details
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/PR643.html b/html-test/ref/PR643.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/PR643.html
@@ -0,0 +1,86 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >PR643</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>PR643</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><a href="#"
+	      >test</a
+	      > :: ()</li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><a id="v:test" class="def"
+	    >test</a
+	    > :: () <span class="fixity"
+	    >infixr 5</span
+	    ><span class="rightedge"
+	    ></span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Some big documentation</p
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/PR643_1.html b/html-test/ref/PR643_1.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/PR643_1.html
@@ -0,0 +1,86 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >PR643_1</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>PR643_1</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><a href="#"
+	      >test</a
+	      > :: ()</li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><a id="v:test" class="def"
+	    >test</a
+	    > :: () <span class="fixity"
+	    >infixr 5</span
+	    ><span class="rightedge"
+	    ></span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Some big documentation</p
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/PatternSyns.html b/html-test/ref/PatternSyns.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/PatternSyns.html
@@ -0,0 +1,379 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >PatternSyns</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>PatternSyns</p
+	></div
+      ><div id="description"
+      ><p class="caption"
+	>Description</p
+	><div class="doc"
+	><p
+	  >Testing some pattern synonyms</p
+	  ></div
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > <a href="#"
+	      >FooType</a
+	      > x = <a href="#"
+	      >FooCtor</a
+	      > x</li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >pattern</span
+	      > <a href="#"
+	      >Foo</a
+	      > :: x -&gt; <a href="#" title="PatternSyns"
+	      >FooType</a
+	      > x</li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >pattern</span
+	      > <a href="#"
+	      >Bar</a
+	      > :: x -&gt; <a href="#" title="PatternSyns"
+	      >FooType</a
+	      > (<a href="#" title="PatternSyns"
+	      >FooType</a
+	      > x)</li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >pattern</span
+	      > <a href="#"
+	      >(:&lt;-&gt;)</a
+	      > :: x1 -&gt; x2 -&gt; (<a href="#" title="PatternSyns"
+	      >FooType</a
+	      > x1, <a href="#" title="PatternSyns"
+	      >FooType</a
+	      > (<a href="#" title="PatternSyns"
+	      >FooType</a
+	      > x2))</li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > <a href="#"
+	      >BlubType</a
+	      > = <span class="keyword"
+	      >forall</span
+	      > x.<a href="#" title="Text.Show"
+	      >Show</a
+	      > x =&gt;  <a href="#"
+	      >BlubCtor</a
+	      > x</li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >pattern</span
+	      > <a href="#"
+	      >Blub</a
+	      > :: () =&gt; <a href="#" title="Text.Show"
+	      >Show</a
+	      > x =&gt; x -&gt; <a href="#" title="PatternSyns"
+	      >BlubType</a
+	      ></li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > (a :: *) <a href="#"
+	      >&gt;&lt;</a
+	      > b = <a href="#"
+	      >Empty</a
+	      ></li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >pattern</span
+	      > <a href="#"
+	      >E</a
+	      > :: a <a href="#" title="PatternSyns"
+	      >&gt;&lt;</a
+	      > b</li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >pattern</span
+	      > <a href="#"
+	      >PatWithExplicitSig</a
+	      > :: <a href="#" title="Data.Eq"
+	      >Eq</a
+	      > somex =&gt; somex -&gt; <a href="#" title="PatternSyns"
+	      >FooType</a
+	      > somex</li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:FooType" class="def"
+	    >FooType</a
+	    > x <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >FooType doc</p
+	    ></div
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:FooCtor" class="def"
+		  >FooCtor</a
+		  > x</td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >pattern</span
+	    > <a id="v:Foo" class="def"
+	    >Foo</a
+	    > :: x -&gt; <a href="#" title="PatternSyns"
+	    >FooType</a
+	    > x <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Pattern synonym for <code
+	      ><a href="#" title="PatternSyns"
+		>Foo</a
+		></code
+	      > x</p
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >pattern</span
+	    > <a id="v:Bar" class="def"
+	    >Bar</a
+	    > :: x -&gt; <a href="#" title="PatternSyns"
+	    >FooType</a
+	    > (<a href="#" title="PatternSyns"
+	    >FooType</a
+	    > x) <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Pattern synonym for <code
+	      ><a href="#" title="PatternSyns"
+		>Bar</a
+		></code
+	      > x</p
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >pattern</span
+	    > <a id="v::-60--45--62-" class="def"
+	    >(:&lt;-&gt;)</a
+	    > :: x1 -&gt; x2 -&gt; (<a href="#" title="PatternSyns"
+	    >FooType</a
+	    > x1, <a href="#" title="PatternSyns"
+	    >FooType</a
+	    > (<a href="#" title="PatternSyns"
+	    >FooType</a
+	    > x2)) <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Pattern synonym for (<code
+	      ><a href="#" title="PatternSyns"
+		>:&lt;-&gt;</a
+		></code
+	      >)</p
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:BlubType" class="def"
+	    >BlubType</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >BlubType is existentially quantified</p
+	    ></div
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><span class="keyword"
+		  >forall</span
+		  > x.<a href="#" title="Text.Show"
+		  >Show</a
+		  > x =&gt;  <a id="v:BlubCtor" class="def"
+		  >BlubCtor</a
+		  > x</td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >pattern</span
+	    > <a id="v:Blub" class="def"
+	    >Blub</a
+	    > :: () =&gt; <a href="#" title="Text.Show"
+	    >Show</a
+	    > x =&gt; x -&gt; <a href="#" title="PatternSyns"
+	    >BlubType</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Pattern synonym for <code
+	      ><a href="#" title="PatternSyns"
+		>Blub</a
+		></code
+	      > x</p
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > (a :: *) <a id="t:-62--60-" class="def"
+	    >&gt;&lt;</a
+	    > b <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Doc for (<code
+	      ><a href="#" title="PatternSyns"
+		>&gt;&lt;</a
+		></code
+	      >)</p
+	    ></div
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:Empty" class="def"
+		  >Empty</a
+		  ></td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >pattern</span
+	    > <a id="v:E" class="def"
+	    >E</a
+	    > :: a <a href="#" title="PatternSyns"
+	    >&gt;&lt;</a
+	    > b <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Pattern for <code
+	      ><a href="#" title="PatternSyns"
+		>Empty</a
+		></code
+	      ></p
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >pattern</span
+	    > <a id="v:PatWithExplicitSig" class="def"
+	    >PatWithExplicitSig</a
+	    > :: <a href="#" title="Data.Eq"
+	    >Eq</a
+	    > somex =&gt; somex -&gt; <a href="#" title="PatternSyns"
+	    >FooType</a
+	    > somex <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Earlier ghc versions didn't allow explicit signatures
+ on pattern synonyms.</p
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/PromotedTypes.html b/html-test/ref/PromotedTypes.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/PromotedTypes.html
@@ -0,0 +1,210 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >PromotedTypes</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>PromotedTypes</p
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:RevList" class="def"
+	    >RevList</a
+	    > a <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:RNil" class="def"
+		  >RNil</a
+		  ></td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ><tr
+	      ><td class="src"
+		>(<a href="#" title="PromotedTypes"
+		  >RevList</a
+		  > a) <a id="v::-62-" class="def"
+		  >:&gt;</a
+		  > a</td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:Pattern" class="def"
+	    >Pattern</a
+	    > :: [*] -&gt; * <span class="keyword"
+	    >where</span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:Nil" class="def"
+		  >Nil</a
+		  > :: <a href="#" title="PromotedTypes"
+		  >Pattern</a
+		  > '[]</td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ><tr
+	      ><td class="src"
+		><a id="v:Cons" class="def"
+		  >Cons</a
+		  > :: <a href="#" title="Data.Maybe"
+		  >Maybe</a
+		  > h -&gt; <a href="#" title="PromotedTypes"
+		  >Pattern</a
+		  > t -&gt; <a href="#" title="PromotedTypes"
+		  >Pattern</a
+		  > (h ': t)</td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:RevPattern" class="def"
+	    >RevPattern</a
+	    > :: <a href="#" title="PromotedTypes"
+	    >RevList</a
+	    > * -&gt; * <span class="keyword"
+	    >where</span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:RevNil" class="def"
+		  >RevNil</a
+		  > :: <a href="#" title="PromotedTypes"
+		  >RevPattern</a
+		  > <a href="#" title="PromotedTypes"
+		  >RNil</a
+		  ></td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ><tr
+	      ><td class="src"
+		><a id="v:RevCons" class="def"
+		  >RevCons</a
+		  > :: <a href="#" title="Data.Maybe"
+		  >Maybe</a
+		  > h -&gt; <a href="#" title="PromotedTypes"
+		  >RevPattern</a
+		  > t -&gt; <a href="#" title="PromotedTypes"
+		  >RevPattern</a
+		  > (t <a href="#" title="PromotedTypes"
+		  >:&gt;</a
+		  > h)</td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:Tuple" class="def"
+	    >Tuple</a
+	    > :: (*, *) -&gt; * <span class="keyword"
+	    >where</span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:Tuple" class="def"
+		  >Tuple</a
+		  > :: a -&gt; b -&gt; <a href="#" title="PromotedTypes"
+		  >Tuple</a
+		  > '(a, b)</td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Properties.html b/html-test/ref/Properties.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Properties.html
@@ -0,0 +1,96 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Properties</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Properties</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><a href="#"
+	      >fib</a
+	      > :: <a href="#" title="Prelude"
+	      >Integer</a
+	      > -&gt; <a href="#" title="Prelude"
+	      >Integer</a
+	      ></li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><a id="v:fib" class="def"
+	    >fib</a
+	    > :: <a href="#" title="Prelude"
+	    >Integer</a
+	    > -&gt; <a href="#" title="Prelude"
+	    >Integer</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Fibonacci number of given <code
+	      ><a href="#" title="Prelude"
+		>Integer</a
+		></code
+	      >.</p
+	    ><pre
+	    >fib n &lt;= fib (n + 1)</pre
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/PruneWithWarning.html b/html-test/ref/PruneWithWarning.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/PruneWithWarning.html
@@ -0,0 +1,71 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >PruneWithWarning</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>PruneWithWarning</p
+	></div
+      ><div id="description"
+      ><p class="caption"
+	>Description</p
+	><div class="doc"
+	><p
+	  >What is tested here:</p
+	  ><ul
+	  ><li
+	    >If a binding has a deprecation message but no documentation, it is pruned
+   when <code
+	      >OPTIONS_HADDOCK prune</code
+	      > is used.</li
+	    ></ul
+	  ></div
+	></div
+      ><div id="interface"
+      ></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/QuantifiedConstraints.html b/html-test/ref/QuantifiedConstraints.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/QuantifiedConstraints.html
@@ -0,0 +1,108 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >QuantifiedConstraints</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>QuantifiedConstraints</p
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >class</span
+	    > <a id="t:Foo" class="def"
+	    >Foo</a
+	    > a <span class="keyword"
+	    >where</span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs methods"
+	  ><p class="caption"
+	    >Methods</p
+	    ><p class="src"
+	    ><a id="v:fooed" class="def"
+	      >fooed</a
+	      > :: a <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:needsParensAroundContext" class="def"
+	    >needsParensAroundContext</a
+	    > :: (<span class="keyword"
+	    >forall</span
+	    > x. <a href="#" title="QuantifiedConstraints"
+	    >Foo</a
+	    > (f x)) =&gt; f <a href="#" title="Data.Int"
+	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:needsNoParensAroundContext" class="def"
+	    >needsNoParensAroundContext</a
+	    > :: <a href="#" title="QuantifiedConstraints"
+	    >Foo</a
+	    > (f <a href="#" title="Data.Int"
+	    >Int</a
+	    >) =&gt; f <a href="#" title="Data.Int"
+	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/QuasiExpr.html b/html-test/ref/QuasiExpr.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/QuasiExpr.html
@@ -0,0 +1,350 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >QuasiExpr</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>QuasiExpr</p
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:Expr" class="def"
+	    >Expr</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:IntExpr" class="def"
+		  >IntExpr</a
+		  > <a href="#" title="Prelude"
+		  >Integer</a
+		  ></td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ><tr
+	      ><td class="src"
+		><a id="v:AntiIntExpr" class="def"
+		  >AntiIntExpr</a
+		  > <a href="#" title="Data.String"
+		  >String</a
+		  ></td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ><tr
+	      ><td class="src"
+		><a id="v:BinopExpr" class="def"
+		  >BinopExpr</a
+		  > <a href="#" title="QuasiExpr"
+		  >BinOp</a
+		  > <a href="#" title="QuasiExpr"
+		  >Expr</a
+		  > <a href="#" title="QuasiExpr"
+		  >Expr</a
+		  ></td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ><tr
+	      ><td class="src"
+		><a id="v:AntiExpr" class="def"
+		  >AntiExpr</a
+		  > <a href="#" title="Data.String"
+		  >String</a
+		  ></td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ></table
+	    ></div
+	  ><div class="subs instances"
+	  ><h4 class="instances details-toggle-control details-toggle" data-details-id="i:Expr"
+	    >Instances</h4
+	    ><details id="i:Expr" open="open"
+	    ><summary class="hide-when-js-enabled"
+	      >Instances details</summary
+	      ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:Expr:Show:1"
+		      ></span
+		      > <a href="#" title="Text.Show"
+		      >Show</a
+		      > <a href="#" title="QuasiExpr"
+		      >Expr</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:Expr:Show:1"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>QuasiExpr</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >showsPrec</a
+			  > :: <a href="#" title="Data.Int"
+			  >Int</a
+			  > -&gt; <a href="#" title="QuasiExpr"
+			  >Expr</a
+			  > -&gt; <a href="#" title="Text.Show"
+			  >ShowS</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >show</a
+			  > :: <a href="#" title="QuasiExpr"
+			  >Expr</a
+			  > -&gt; <a href="#" title="Data.String"
+			  >String</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >showList</a
+			  > :: [<a href="#" title="QuasiExpr"
+			  >Expr</a
+			  >] -&gt; <a href="#" title="Text.Show"
+			  >ShowS</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		></table
+	      ></details
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:BinOp" class="def"
+	    >BinOp</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:AddOp" class="def"
+		  >AddOp</a
+		  ></td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ><tr
+	      ><td class="src"
+		><a id="v:SubOp" class="def"
+		  >SubOp</a
+		  ></td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ><tr
+	      ><td class="src"
+		><a id="v:MulOp" class="def"
+		  >MulOp</a
+		  ></td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ><tr
+	      ><td class="src"
+		><a id="v:DivOp" class="def"
+		  >DivOp</a
+		  ></td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ></table
+	    ></div
+	  ><div class="subs instances"
+	  ><h4 class="instances details-toggle-control details-toggle" data-details-id="i:BinOp"
+	    >Instances</h4
+	    ><details id="i:BinOp" open="open"
+	    ><summary class="hide-when-js-enabled"
+	      >Instances details</summary
+	      ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:BinOp:Show:1"
+		      ></span
+		      > <a href="#" title="Text.Show"
+		      >Show</a
+		      > <a href="#" title="QuasiExpr"
+		      >BinOp</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:BinOp:Show:1"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>QuasiExpr</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >showsPrec</a
+			  > :: <a href="#" title="Data.Int"
+			  >Int</a
+			  > -&gt; <a href="#" title="QuasiExpr"
+			  >BinOp</a
+			  > -&gt; <a href="#" title="Text.Show"
+			  >ShowS</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >show</a
+			  > :: <a href="#" title="QuasiExpr"
+			  >BinOp</a
+			  > -&gt; <a href="#" title="Data.String"
+			  >String</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >showList</a
+			  > :: [<a href="#" title="QuasiExpr"
+			  >BinOp</a
+			  >] -&gt; <a href="#" title="Text.Show"
+			  >ShowS</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		></table
+	      ></details
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:eval" class="def"
+	    >eval</a
+	    > :: <a href="#" title="QuasiExpr"
+	    >Expr</a
+	    > -&gt; <a href="#" title="Prelude"
+	    >Integer</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:expr" class="def"
+	    >expr</a
+	    > :: <a href="#" title="Language.Haskell.TH.Quote"
+	    >QuasiQuoter</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:parseExprExp" class="def"
+	    >parseExprExp</a
+	    > :: <a href="#" title="Data.String"
+	    >String</a
+	    > -&gt; <a href="#" title="Language.Haskell.TH.Syntax"
+	    >Q</a
+	    > <a href="#" title="Language.Haskell.TH.Syntax"
+	    >Exp</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/QuasiQuote.html b/html-test/ref/QuasiQuote.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/QuasiQuote.html
@@ -0,0 +1,68 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >QuasiQuote</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>QuasiQuote</p
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><a id="v:val" class="def"
+	    >val</a
+	    > :: <a href="#" title="Prelude"
+	    >Integer</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/SectionLabels.html b/html-test/ref/SectionLabels.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/SectionLabels.html
@@ -0,0 +1,96 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >SectionLabels</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>SectionLabels</p
+	></div
+      ><div id="table-of-contents"
+      ><div id="contents-list"
+	><p class="caption" onclick="window.scrollTo(0,0)"
+	  >Contents</p
+	  ><ul
+	  ><li
+	    ><a href="#"
+	      >Section heading</a
+	      ></li
+	    ></ul
+	  ></div
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><a href="#"
+	      >n</a
+	      > :: <a href="#" title="Data.Int"
+	      >Int</a
+	      ></li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><a href="#" id="g:custom"
+	><h1
+	  >Section heading</h1
+	  ></a
+	><div class="top"
+	><p class="src"
+	  ><a id="v:n" class="def"
+	    >n</a
+	    > :: <a href="#" title="Data.Int"
+	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/SpuriousSuperclassConstraints.html b/html-test/ref/SpuriousSuperclassConstraints.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/SpuriousSuperclassConstraints.html
@@ -0,0 +1,246 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >SpuriousSuperclassConstraints</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>SpuriousSuperclassConstraints</p
+	></div
+      ><div id="description"
+      ><p class="caption"
+	>Description</p
+	><div class="doc"
+	><p
+	  >What is tested here:</p
+	  ><p
+	  >Due to a change in GHC 7.6.1 we had a bug that superclass contraints were
+ included in the instances list.  Edward K. repported it here:</p
+	  ><p
+	  ><a href="#"
+	    >http://www.haskell.org/pipermail/haskell-cafe/2012-September/103600.html</a
+	    ></p
+	  ><p
+	  >And here is the corresponding thread on glasgow-haskell-users:</p
+	  ><p
+	  ><a href="#"
+	    >http://www.haskell.org/pipermail/glasgow-haskell-users/2012-September/022914.html</a
+	    ></p
+	  ><p
+	  >It has been fixed in:</p
+	  ><pre
+	  >6ccf78e15a525282fef61bc4f58a279aa9c21771
+Fix spurious superclass constraints bug.</pre
+	  ></div
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:SomeType" class="def"
+	    >SomeType</a
+	    > (f :: * -&gt; *) a <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs instances"
+	  ><h4 class="instances details-toggle-control details-toggle" data-details-id="i:SomeType"
+	    >Instances</h4
+	    ><details id="i:SomeType" open="open"
+	    ><summary class="hide-when-js-enabled"
+	      >Instances details</summary
+	      ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:SomeType:Applicative:1"
+		      ></span
+		      > <a href="#" title="Control.Applicative"
+		      >Applicative</a
+		      > f =&gt; <a href="#" title="Control.Applicative"
+		      >Applicative</a
+		      > (<a href="#" title="SpuriousSuperclassConstraints"
+		      >SomeType</a
+		      > f)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:SomeType:Applicative:1"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>SpuriousSuperclassConstraints</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >pure</a
+			  > :: a -&gt; <a href="#" title="SpuriousSuperclassConstraints"
+			  >SomeType</a
+			  > f a <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >(&lt;*&gt;)</a
+			  > :: <a href="#" title="SpuriousSuperclassConstraints"
+			  >SomeType</a
+			  > f (a -&gt; b) -&gt; <a href="#" title="SpuriousSuperclassConstraints"
+			  >SomeType</a
+			  > f a -&gt; <a href="#" title="SpuriousSuperclassConstraints"
+			  >SomeType</a
+			  > f b <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >liftA2</a
+			  > :: (a -&gt; b -&gt; c) -&gt; <a href="#" title="SpuriousSuperclassConstraints"
+			  >SomeType</a
+			  > f a -&gt; <a href="#" title="SpuriousSuperclassConstraints"
+			  >SomeType</a
+			  > f b -&gt; <a href="#" title="SpuriousSuperclassConstraints"
+			  >SomeType</a
+			  > f c <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >(*&gt;)</a
+			  > :: <a href="#" title="SpuriousSuperclassConstraints"
+			  >SomeType</a
+			  > f a -&gt; <a href="#" title="SpuriousSuperclassConstraints"
+			  >SomeType</a
+			  > f b -&gt; <a href="#" title="SpuriousSuperclassConstraints"
+			  >SomeType</a
+			  > f b <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >(&lt;*)</a
+			  > :: <a href="#" title="SpuriousSuperclassConstraints"
+			  >SomeType</a
+			  > f a -&gt; <a href="#" title="SpuriousSuperclassConstraints"
+			  >SomeType</a
+			  > f b -&gt; <a href="#" title="SpuriousSuperclassConstraints"
+			  >SomeType</a
+			  > f a <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:SomeType:Functor:2"
+		      ></span
+		      > <a href="#" title="Data.Functor"
+		      >Functor</a
+		      > (<a href="#" title="SpuriousSuperclassConstraints"
+		      >SomeType</a
+		      > f)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:SomeType:Functor:2"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>SpuriousSuperclassConstraints</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >fmap</a
+			  > :: (a -&gt; b) -&gt; <a href="#" title="SpuriousSuperclassConstraints"
+			  >SomeType</a
+			  > f a -&gt; <a href="#" title="SpuriousSuperclassConstraints"
+			  >SomeType</a
+			  > f b <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >(&lt;$)</a
+			  > :: a -&gt; <a href="#" title="SpuriousSuperclassConstraints"
+			  >SomeType</a
+			  > f b -&gt; <a href="#" title="SpuriousSuperclassConstraints"
+			  >SomeType</a
+			  > f a <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		></table
+	      ></details
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/TH.html b/html-test/ref/TH.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/TH.html
@@ -0,0 +1,70 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >TH</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>TH</p
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><a id="v:decl" class="def"
+	    >decl</a
+	    > :: <a href="#" title="Language.Haskell.TH.Syntax"
+	    >Q</a
+	    > [<a href="#" title="Language.Haskell.TH.Syntax"
+	    >Dec</a
+	    >] <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/TH2.html b/html-test/ref/TH2.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/TH2.html
@@ -0,0 +1,66 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >TH2</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>TH2</p
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><a id="v:f" class="def"
+	    >f</a
+	    > :: p -&gt; p <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Table.html b/html-test/ref/Table.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Table.html
@@ -0,0 +1,248 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Table</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Table</p
+	></div
+      ><div id="description"
+      ><p class="caption"
+	>Description</p
+	><div class="doc"
+	><p
+	  >This tests the table markup</p
+	  ></div
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><a href="#"
+	      >tableWithHeader</a
+	      > :: a -&gt; a</li
+	    ><li class="src short"
+	    ><a href="#"
+	      >tableWithoutHeader</a
+	      > :: a -&gt; a</li
+	    ><li class="src short"
+	    ><a href="#"
+	      >fancyTable</a
+	      > :: a -&gt; a</li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><a id="v:tableWithHeader" class="def"
+	    >tableWithHeader</a
+	    > :: a -&gt; a <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Table with header.</p
+	    ><table
+	    ><thead
+	      ><tr
+		><th
+		  >code</th
+		  ><th
+		  >message</th
+		  ><th
+		  >description</th
+		  ></tr
+		></thead
+	      ><tbody
+	      ><tr
+		><td
+		  >200</td
+		  ><td
+		  ><code
+		    >OK</code
+		    ></td
+		  ><td
+		  >operation successful</td
+		  ></tr
+		><tr
+		><td
+		  >204</td
+		  ><td
+		  ><code
+		    >No Content</code
+		    ></td
+		  ><td
+		  >operation successful, no body returned</td
+		  ></tr
+		></tbody
+	      ></table
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:tableWithoutHeader" class="def"
+	    >tableWithoutHeader</a
+	    > :: a -&gt; a <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Table without header.</p
+	    ><table
+	    ><tbody
+	      ><tr
+		><td
+		  >200</td
+		  ><td
+		  ><code
+		    >OK</code
+		    ></td
+		  ><td
+		  >operation successful</td
+		  ></tr
+		><tr
+		><td
+		  >204</td
+		  ><td
+		  ><code
+		    >No Content</code
+		    ></td
+		  ><td
+		  >operation successful, no body returned</td
+		  ></tr
+		><tr
+		><td
+		  >404</td
+		  ><td
+		  ><code
+		    >Not Found</code
+		    ></td
+		  ><td
+		  >resource not found</td
+		  ></tr
+		></tbody
+	      ></table
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:fancyTable" class="def"
+	    >fancyTable</a
+	    > :: a -&gt; a <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Fancy table.</p
+	    ><table
+	    ><thead
+	      ><tr
+		><th
+		  >Header row, column 1
+(header rows optional)</th
+		  ><th
+		  >Header 2
+</th
+		  ><th
+		  >Header 3
+</th
+		  ><th
+		  >Header 4
+</th
+		  ></tr
+		></thead
+	      ><tbody
+	      ><tr
+		><td
+		  >body row 1, column 1</td
+		  ><td
+		  >column 2</td
+		  ><td
+		  >column 3</td
+		  ><td
+		  >column 4</td
+		  ></tr
+		><tr
+		><td
+		  ><code
+		    ><a href="#" title="Table"
+		      >tableWithHeader</a
+		      ></code
+		    ></td
+		  ><td colspan="3"
+		  >Cells may span columns.</td
+		  ></tr
+		><tr
+		><td
+		  >body row 3</td
+		  ><td rowspan="2"
+		  >Cells may
+span rows.
+</td
+		  ><td colspan="2" rowspan="2"
+		  ><span class="mathjax"
+		    >\[
+f(n) = \sum_{i=1}
+\]</span
+		    ></td
+		  ></tr
+		><tr
+		><td
+		  >body row 4</td
+		  ></tr
+		></tbody
+	      ></table
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Test.html b/html-test/ref/Test.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Test.html
@@ -0,0 +1,2418 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Test</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th valign="top"
+	    >Copyright</th
+	    ><td
+	    >(c) Simon Marlow 2002</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >License</th
+	    ><td
+	    >BSD-style</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Maintainer</th
+	    ><td
+	    >libraries@haskell.org</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Stability</th
+	    ><td
+	    >provisional</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Portability</th
+	    ><td
+	    >portable</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Test</p
+	></div
+      ><div id="table-of-contents"
+      ><div id="contents-list"
+	><p class="caption" onclick="window.scrollTo(0,0)"
+	  >Contents</p
+	  ><ul
+	  ><li
+	    ><a href="#"
+	      >Type declarations</a
+	      ><ul
+	      ><li
+		><a href="#"
+		  >Data types</a
+		  ></li
+		><li
+		><a href="#"
+		  >Records</a
+		  ></li
+		></ul
+	      ></li
+	    ><li
+	    ><a href="#"
+	      >Class declarations</a
+	      ></li
+	    ><li
+	    ><a href="#"
+	      >Function types</a
+	      ></li
+	    ><li
+	    ><a href="#"
+	      >Auxiliary stuff</a
+	      ></li
+	    ><li
+	    ><a href="#"
+	      >A hidden module</a
+	      ></li
+	    ><li
+	    ><a href="#"
+	      >A visible module</a
+	      ></li
+	    ><li
+	    ><a href="#"
+	      >Existential / Universal types</a
+	      ></li
+	    ><li
+	    ><a href="#"
+	      >Type signatures with argument docs</a
+	      ></li
+	    ><li
+	    ><a href="#"
+	      >A section</a
+	      ><ul
+	      ><li
+		><a href="#"
+		  >A subsection</a
+		  ></li
+		></ul
+	      ></li
+	    ></ul
+	  ></div
+	></div
+      ><div id="description"
+      ><p class="caption"
+	>Description</p
+	><div class="doc"
+	><p
+	  >This module illustrates &amp; tests most of the features of Haddock.
+ Testing references from the description: <code
+	    ><a href="#" title="Test"
+	      >T</a
+	      ></code
+	    >, <code
+	    ><a href="#" title="Test"
+	      >f</a
+	      ></code
+	    >, <code
+	    ><a href="#" title="Test"
+	      >g</a
+	      ></code
+	    >, <code
+	    ><a href="#" title="Visible"
+	      >visible</a
+	      ></code
+	    >.</p
+	  ></div
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > <a href="#"
+	      >T</a
+	      > a b<ul class="subs"
+	      ><li
+		>= <a href="#"
+		  >A</a
+		  > <a href="#" title="Data.Int"
+		  >Int</a
+		  > (<a href="#" title="Data.Maybe"
+		  >Maybe</a
+		  > <a href="#" title="Prelude"
+		  >Float</a
+		  >)</li
+		><li
+		>| <a href="#"
+		  >B</a
+		  > (<a href="#" title="Test"
+		  >T</a
+		  > a b, <a href="#" title="Test"
+		  >T</a
+		  > <a href="#" title="Data.Int"
+		  >Int</a
+		  > <a href="#" title="Prelude"
+		  >Float</a
+		  >)</li
+		></ul
+	      ></li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > <a href="#"
+	      >T2</a
+	      > a b</li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > <a href="#"
+	      >T3</a
+	      > a b<ul class="subs"
+	      ><li
+		>= <a href="#"
+		  >A1</a
+		  > a</li
+		><li
+		>| <a href="#"
+		  >B1</a
+		  > b</li
+		></ul
+	      ></li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > <a href="#"
+	      >T4</a
+	      > a b<ul class="subs"
+	      ><li
+		>= <a href="#"
+		  >A2</a
+		  > a</li
+		><li
+		>| <a href="#"
+		  >B2</a
+		  > b</li
+		></ul
+	      ></li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > <a href="#"
+	      >T5</a
+	      > a b<ul class="subs"
+	      ><li
+		>= <a href="#"
+		  >A3</a
+		  > a</li
+		><li
+		>| <a href="#"
+		  >B3</a
+		  > b</li
+		></ul
+	      ></li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > <a href="#"
+	      >T6</a
+	      ><ul class="subs"
+	      ><li
+		>= <a href="#"
+		  >A4</a
+		  ></li
+		><li
+		>| <a href="#"
+		  >B4</a
+		  ></li
+		><li
+		>| <a href="#"
+		  >C4</a
+		  ></li
+		></ul
+	      ></li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >newtype</span
+	      > <a href="#"
+	      >N1</a
+	      > a = <a href="#"
+	      >N1</a
+	      > a</li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >newtype</span
+	      > <a href="#"
+	      >N2</a
+	      > a b = <a href="#"
+	      >N2</a
+	      > {<ul class="subs"
+	      ><li
+		><a href="#"
+		  >n</a
+		  > :: a b</li
+		></ul
+	      >}</li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >newtype</span
+	      > <a href="#"
+	      >N3</a
+	      > a b = <a href="#"
+	      >N3</a
+	      > {<ul class="subs"
+	      ><li
+		><a href="#"
+		  >n3</a
+		  > :: a b</li
+		></ul
+	      >}</li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > <a href="#"
+	      >N4</a
+	      > a b</li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >newtype</span
+	      > <a href="#"
+	      >N5</a
+	      > a b = <a href="#"
+	      >N5</a
+	      > {<ul class="subs"
+	      ><li
+		><a href="#"
+		  >n5</a
+		  > :: a b</li
+		></ul
+	      >}</li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >newtype</span
+	      > <a href="#"
+	      >N6</a
+	      > a b = <a href="#"
+	      >N6</a
+	      > {<ul class="subs"
+	      ><li
+		><a href="#"
+		  >n6</a
+		  > :: a b</li
+		></ul
+	      >}</li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >newtype</span
+	      > <a href="#"
+	      >N7</a
+	      > a b = <a href="#"
+	      >N7</a
+	      > {<ul class="subs"
+	      ><li
+		><a href="#"
+		  >n7</a
+		  > :: a b</li
+		></ul
+	      >}</li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > <a href="#"
+	      >R</a
+	      ><ul class="subs"
+	      ><li
+		>= <a href="#"
+		  >C1</a
+		  > { <ul class="subs"
+		  ><li
+		    ><a href="#"
+		      >p</a
+		      > :: <a href="#" title="Data.Int"
+		      >Int</a
+		      ></li
+		    ><li
+		    ><a href="#"
+		      >q</a
+		      > :: <span class="keyword"
+		      >forall</span
+		      > a. a -&gt; a</li
+		    ><li
+		    ><a href="#"
+		      >r</a
+		      >, <a href="#"
+		      >s</a
+		      > :: <a href="#" title="Data.Int"
+		      >Int</a
+		      ></li
+		    ></ul
+		  > }</li
+		><li
+		>| <a href="#"
+		  >C2</a
+		  > { <ul class="subs"
+		  ><li
+		    ><a href="#"
+		      >t</a
+		      > :: T1 -&gt; <a href="#" title="Test"
+		      >T2</a
+		      > <a href="#" title="Data.Int"
+		      >Int</a
+		      > <a href="#" title="Data.Int"
+		      >Int</a
+		      > -&gt; <a href="#" title="Test"
+		      >T3</a
+		      > <a href="#" title="Data.Bool"
+		      >Bool</a
+		      > <a href="#" title="Data.Bool"
+		      >Bool</a
+		      > -&gt; <a href="#" title="Test"
+		      >T4</a
+		      > <a href="#" title="Prelude"
+		      >Float</a
+		      > <a href="#" title="Prelude"
+		      >Float</a
+		      > -&gt; <a href="#" title="Test"
+		      >T5</a
+		      > () ()</li
+		    ><li
+		    ><a href="#"
+		      >u</a
+		      >, <a href="#"
+		      >v</a
+		      > :: <a href="#" title="Data.Int"
+		      >Int</a
+		      ></li
+		    ></ul
+		  > }</li
+		></ul
+	      ></li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > <a href="#"
+	      >R1</a
+	      > = <a href="#"
+	      >C3</a
+	      > {<ul class="subs"
+	      ><li
+		><a href="#"
+		  >s1</a
+		  > :: <a href="#" title="Data.Int"
+		  >Int</a
+		  ></li
+		><li
+		><a href="#"
+		  >s2</a
+		  > :: <a href="#" title="Data.Int"
+		  >Int</a
+		  ></li
+		><li
+		><a href="#"
+		  >s3</a
+		  > :: <a href="#" title="Data.Int"
+		  >Int</a
+		  ></li
+		></ul
+	      >}</li
+	    ><li class="src short"
+	    ><a href="#"
+	      >p</a
+	      > :: <a href="#" title="Test"
+	      >R</a
+	      > -&gt; <a href="#" title="Data.Int"
+	      >Int</a
+	      ></li
+	    ><li class="src short"
+	    ><a href="#"
+	      >q</a
+	      > :: <a href="#" title="Test"
+	      >R</a
+	      > -&gt; <span class="keyword"
+	      >forall</span
+	      > a. a -&gt; a</li
+	    ><li class="src short"
+	    ><a href="#"
+	      >u</a
+	      > :: <a href="#" title="Test"
+	      >R</a
+	      > -&gt; <a href="#" title="Data.Int"
+	      >Int</a
+	      ></li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >class</span
+	      > <a href="#" title="Test"
+	      >D</a
+	      > a =&gt; <a href="#"
+	      >C</a
+	      > a <span class="keyword"
+	      >where</span
+	      ><ul class="subs"
+	      ><li
+		><a href="#"
+		  >a</a
+		  > :: <a href="#" title="System.IO"
+		  >IO</a
+		  > a</li
+		><li
+		><a href="#"
+		  >b</a
+		  > :: [a]</li
+		></ul
+	      ></li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >class</span
+	      > <a href="#"
+	      >D</a
+	      > a <span class="keyword"
+	      >where</span
+	      ><ul class="subs"
+	      ><li
+		><a href="#"
+		  >d</a
+		  > :: <a href="#" title="Test"
+		  >T</a
+		  > a b</li
+		><li
+		><a href="#"
+		  >e</a
+		  > :: (a, a)</li
+		></ul
+	      ></li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >class</span
+	      > <a href="#"
+	      >E</a
+	      > a</li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >class</span
+	      > <a href="#"
+	      >F</a
+	      > a <span class="keyword"
+	      >where</span
+	      ><ul class="subs"
+	      ><li
+		><a href="#"
+		  >ff</a
+		  > :: a</li
+		></ul
+	      ></li
+	    ><li class="src short"
+	    ><a href="#"
+	      >a</a
+	      > :: <a href="#" title="Test"
+	      >C</a
+	      > a =&gt; <a href="#" title="System.IO"
+	      >IO</a
+	      > a</li
+	    ><li class="src short"
+	    ><a href="#"
+	      >f</a
+	      > :: <a href="#" title="Test"
+	      >C</a
+	      > a =&gt; a -&gt; <a href="#" title="Data.Int"
+	      >Int</a
+	      ></li
+	    ><li class="src short"
+	    ><a href="#"
+	      >g</a
+	      > :: <a href="#" title="Data.Int"
+	      >Int</a
+	      > -&gt; <a href="#" title="System.IO"
+	      >IO</a
+	      > CInt</li
+	    ><li class="src short"
+	    ><a href="#"
+	      >hidden</a
+	      > :: <a href="#" title="Data.Int"
+	      >Int</a
+	      > -&gt; <a href="#" title="Data.Int"
+	      >Int</a
+	      ></li
+	    ><li class="src short"
+	    >module <a href="#"
+	      >Visible</a
+	      ></li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > <a href="#"
+	      >Ex</a
+	      > a<ul class="subs"
+	      ><li
+		>= <span class="keyword"
+		  >forall</span
+		  > b.<a href="#" title="Test"
+		  >C</a
+		  > b =&gt;  <a href="#"
+		  >Ex1</a
+		  > b</li
+		><li
+		>| <span class="keyword"
+		  >forall</span
+		  > b. <a href="#"
+		  >Ex2</a
+		  > b</li
+		><li
+		>| <span class="keyword"
+		  >forall</span
+		  > b.<a href="#" title="Test"
+		  >C</a
+		  > a =&gt;  <a href="#"
+		  >Ex3</a
+		  > b</li
+		><li
+		>| <a href="#"
+		  >Ex4</a
+		  > (<span class="keyword"
+		  >forall</span
+		  > a. a -&gt; a)</li
+		></ul
+	      ></li
+	    ><li class="src short"
+	    ><a href="#"
+	      >k</a
+	      > :: <a href="#" title="Test"
+	      >T</a
+	      > () () -&gt; <a href="#" title="Test"
+	      >T2</a
+	      > <a href="#" title="Data.Int"
+	      >Int</a
+	      > <a href="#" title="Data.Int"
+	      >Int</a
+	      > -&gt; (<a href="#" title="Test"
+	      >T3</a
+	      > <a href="#" title="Data.Bool"
+	      >Bool</a
+	      > <a href="#" title="Data.Bool"
+	      >Bool</a
+	      > -&gt; <a href="#" title="Test"
+	      >T4</a
+	      > <a href="#" title="Prelude"
+	      >Float</a
+	      > <a href="#" title="Prelude"
+	      >Float</a
+	      >) -&gt; <a href="#" title="Test"
+	      >T5</a
+	      > () () -&gt; <a href="#" title="System.IO"
+	      >IO</a
+	      > ()</li
+	    ><li class="src short"
+	    ><a href="#"
+	      >l</a
+	      > :: (<a href="#" title="Data.Int"
+	      >Int</a
+	      >, <a href="#" title="Data.Int"
+	      >Int</a
+	      >, <a href="#" title="Prelude"
+	      >Float</a
+	      >) -&gt; <a href="#" title="Data.Int"
+	      >Int</a
+	      ></li
+	    ><li class="src short"
+	    ><a href="#"
+	      >m</a
+	      > :: <a href="#" title="Test"
+	      >R</a
+	      > -&gt; <a href="#" title="Test"
+	      >N1</a
+	      > () -&gt; <a href="#" title="System.IO"
+	      >IO</a
+	      > <a href="#" title="Data.Int"
+	      >Int</a
+	      ></li
+	    ><li class="src short"
+	    ><a href="#"
+	      >o</a
+	      > :: <a href="#" title="Prelude"
+	      >Float</a
+	      > -&gt; <a href="#" title="System.IO"
+	      >IO</a
+	      > <a href="#" title="Prelude"
+	      >Float</a
+	      ></li
+	    ><li class="src short"
+	    ><a href="#"
+	      >f'</a
+	      > :: <a href="#" title="Data.Int"
+	      >Int</a
+	      ></li
+	    ><li class="src short"
+	    ><a href="#"
+	      >withType</a
+	      > :: <a href="#" title="Data.Int"
+	      >Int</a
+	      ></li
+	    ><li class="src short"
+	    ><a href="#"
+	      >withoutType</a
+	      > :: a</li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><a href="#" id="g:1"
+	><h1
+	  >Type declarations</h1
+	  ></a
+	><a href="#" id="g:2"
+	><h2
+	  >Data types</h2
+	  ></a
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:T" class="def"
+	    >T</a
+	    > a b <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >This comment applies to the <em
+	      >following</em
+	      > declaration
+ and it continues until the next non-comment line</p
+	    ></div
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:A" class="def"
+		  >A</a
+		  > <a href="#" title="Data.Int"
+		  >Int</a
+		  > (<a href="#" title="Data.Maybe"
+		  >Maybe</a
+		  > <a href="#" title="Prelude"
+		  >Float</a
+		  >)</td
+		><td class="doc"
+		><p
+		  >This comment describes the <code
+		    ><a href="#" title="Test"
+		      >A</a
+		      ></code
+		    > constructor</p
+		  ></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		><a id="v:B" class="def"
+		  >B</a
+		  > (<a href="#" title="Test"
+		  >T</a
+		  > a b, <a href="#" title="Test"
+		  >T</a
+		  > <a href="#" title="Data.Int"
+		  >Int</a
+		  > <a href="#" title="Prelude"
+		  >Float</a
+		  >)</td
+		><td class="doc"
+		><p
+		  >This comment describes the <code
+		    ><a href="#" title="Test"
+		      >B</a
+		      ></code
+		    > constructor</p
+		  ></td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:T2" class="def"
+	    >T2</a
+	    > a b <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >An abstract data declaration</p
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:T3" class="def"
+	    >T3</a
+	    > a b <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >A data declaration with no documentation annotations on the constructors</p
+	    ></div
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:A1" class="def"
+		  >A1</a
+		  > a</td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ><tr
+	      ><td class="src"
+		><a id="v:B1" class="def"
+		  >B1</a
+		  > b</td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:T4" class="def"
+	    >T4</a
+	    > a b <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:A2" class="def"
+		  >A2</a
+		  > a</td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ><tr
+	      ><td class="src"
+		><a id="v:B2" class="def"
+		  >B2</a
+		  > b</td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:T5" class="def"
+	    >T5</a
+	    > a b <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:A3" class="def"
+		  >A3</a
+		  > a</td
+		><td class="doc"
+		><p
+		  >documents <code
+		    ><a href="#" title="Test"
+		      >A3</a
+		      ></code
+		    ></p
+		  ></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		><a id="v:B3" class="def"
+		  >B3</a
+		  > b</td
+		><td class="doc"
+		><p
+		  >documents <code
+		    ><a href="#" title="Test"
+		      >B3</a
+		      ></code
+		    ></p
+		  ></td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:T6" class="def"
+	    >T6</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Testing alternative comment styles</p
+	    ></div
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:A4" class="def"
+		  >A4</a
+		  ></td
+		><td class="doc"
+		><p
+		  >This is the doc for <code
+		    ><a href="#" title="Test"
+		      >A4</a
+		      ></code
+		    ></p
+		  ></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		><a id="v:B4" class="def"
+		  >B4</a
+		  ></td
+		><td class="doc"
+		><p
+		  >This is the doc for <code
+		    ><a href="#" title="Test"
+		      >B4</a
+		      ></code
+		    ></p
+		  ></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		><a id="v:C4" class="def"
+		  >C4</a
+		  ></td
+		><td class="doc"
+		><p
+		  >This is the doc for <code
+		    ><a href="#" title="Test"
+		      >C4</a
+		      ></code
+		    ></p
+		  ></td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >newtype</span
+	    > <a id="t:N1" class="def"
+	    >N1</a
+	    > a <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >A newtype</p
+	    ></div
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:N1" class="def"
+		  >N1</a
+		  > a</td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >newtype</span
+	    > <a id="t:N2" class="def"
+	    >N2</a
+	    > a b <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >A newtype with a fieldname</p
+	    ></div
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:N2" class="def"
+		  >N2</a
+		  ></td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ><tr
+	      ><td colspan="2"
+		><div class="subs fields"
+		  ><p class="caption"
+		    >Fields</p
+		    ><ul
+		    ><li
+		      ><dfn class="src"
+			><a id="v:n" class="def"
+			  >n</a
+			  > :: a b</dfn
+			><div class="doc empty"
+			>&nbsp;</div
+			></li
+		      ></ul
+		    ></div
+		  ></td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >newtype</span
+	    > <a id="t:N3" class="def"
+	    >N3</a
+	    > a b <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >A newtype with a fieldname, documentation on the field</p
+	    ></div
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:N3" class="def"
+		  >N3</a
+		  ></td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ><tr
+	      ><td colspan="2"
+		><div class="subs fields"
+		  ><p class="caption"
+		    >Fields</p
+		    ><ul
+		    ><li
+		      ><dfn class="src"
+			><a id="v:n3" class="def"
+			  >n3</a
+			  > :: a b</dfn
+			><div class="doc"
+			><p
+			  >this is the <code
+			    ><a href="#" title="Test"
+			      >n3</a
+			      ></code
+			    > field</p
+			  ></div
+			></li
+		      ></ul
+		    ></div
+		  ></td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:N4" class="def"
+	    >N4</a
+	    > a b <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >An abstract newtype - we show this one as data rather than newtype because
+ the difference isn't visible to the programmer for an abstract type.</p
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >newtype</span
+	    > <a id="t:N5" class="def"
+	    >N5</a
+	    > a b <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:N5" class="def"
+		  >N5</a
+		  ></td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ><tr
+	      ><td colspan="2"
+		><div class="subs fields"
+		  ><p class="caption"
+		    >Fields</p
+		    ><ul
+		    ><li
+		      ><dfn class="src"
+			><a id="v:n5" class="def"
+			  >n5</a
+			  > :: a b</dfn
+			><div class="doc"
+			><p
+			  >no docs on the datatype or the constructor</p
+			  ></div
+			></li
+		      ></ul
+		    ></div
+		  ></td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >newtype</span
+	    > <a id="t:N6" class="def"
+	    >N6</a
+	    > a b <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:N6" class="def"
+		  >N6</a
+		  ></td
+		><td class="doc"
+		><p
+		  >docs on the constructor only</p
+		  ></td
+		></tr
+	      ><tr
+	      ><td colspan="2"
+		><div class="subs fields"
+		  ><p class="caption"
+		    >Fields</p
+		    ><ul
+		    ><li
+		      ><dfn class="src"
+			><a id="v:n6" class="def"
+			  >n6</a
+			  > :: a b</dfn
+			><div class="doc empty"
+			>&nbsp;</div
+			></li
+		      ></ul
+		    ></div
+		  ></td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >newtype</span
+	    > <a id="t:N7" class="def"
+	    >N7</a
+	    > a b <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >docs on the newtype and the constructor</p
+	    ></div
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:N7" class="def"
+		  >N7</a
+		  ></td
+		><td class="doc"
+		><p
+		  >The <code
+		    ><a href="#" title="Test"
+		      >N7</a
+		      ></code
+		    > constructor</p
+		  ></td
+		></tr
+	      ><tr
+	      ><td colspan="2"
+		><div class="subs fields"
+		  ><p class="caption"
+		    >Fields</p
+		    ><ul
+		    ><li
+		      ><dfn class="src"
+			><a id="v:n7" class="def"
+			  >n7</a
+			  > :: a b</dfn
+			><div class="doc empty"
+			>&nbsp;</div
+			></li
+		      ></ul
+		    ></div
+		  ></td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><a href="#" id="g:3"
+	><h2
+	  >Records</h2
+	  ></a
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:R" class="def"
+	    >R</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >This is the documentation for the <code
+	      ><a href="#" title="Test"
+		>R</a
+		></code
+	      > record, which has four fields,
+ <code
+	      ><a href="#" title="Test"
+		>p</a
+		></code
+	      >, <code
+	      ><a href="#" title="Test"
+		>q</a
+		></code
+	      >, <code
+	      ><a href="#" title="Test"
+		>r</a
+		></code
+	      >, and <code
+	      ><a href="#" title="Test"
+		>s</a
+		></code
+	      >.</p
+	    ></div
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:C1" class="def"
+		  >C1</a
+		  ></td
+		><td class="doc"
+		><p
+		  >This is the <code
+		    ><a href="#" title="Test"
+		      >C1</a
+		      ></code
+		    > record constructor, with the following fields:</p
+		  ></td
+		></tr
+	      ><tr
+	      ><td colspan="2"
+		><div class="subs fields"
+		  ><p class="caption"
+		    >Fields</p
+		    ><ul
+		    ><li
+		      ><dfn class="src"
+			><a id="v:p" class="def"
+			  >p</a
+			  > :: <a href="#" title="Data.Int"
+			  >Int</a
+			  ></dfn
+			><div class="doc"
+			><p
+			  >This comment applies to the <code
+			    ><a href="#" title="Test"
+			      >p</a
+			      ></code
+			    > field</p
+			  ></div
+			></li
+		      ><li
+		      ><dfn class="src"
+			><a id="v:q" class="def"
+			  >q</a
+			  > :: <span class="keyword"
+			  >forall</span
+			  > a. a -&gt; a</dfn
+			><div class="doc"
+			><p
+			  >This comment applies to the <code
+			    ><a href="#" title="Test"
+			      >q</a
+			      ></code
+			    > field</p
+			  ></div
+			></li
+		      ><li
+		      ><dfn class="src"
+			><a id="v:r" class="def"
+			  >r</a
+			  >, <a id="v:s" class="def"
+			  >s</a
+			  > :: <a href="#" title="Data.Int"
+			  >Int</a
+			  ></dfn
+			><div class="doc"
+			><p
+			  >This comment applies to both <code
+			    ><a href="#" title="Test"
+			      >r</a
+			      ></code
+			    > and <code
+			    ><a href="#" title="Test"
+			      >s</a
+			      ></code
+			    ></p
+			  ></div
+			></li
+		      ></ul
+		    ></div
+		  ></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		><a id="v:C2" class="def"
+		  >C2</a
+		  ></td
+		><td class="doc"
+		><p
+		  >This is the <code
+		    ><a href="#" title="Test"
+		      >C2</a
+		      ></code
+		    > record constructor, also with some fields:</p
+		  ></td
+		></tr
+	      ><tr
+	      ><td colspan="2"
+		><div class="subs fields"
+		  ><p class="caption"
+		    >Fields</p
+		    ><ul
+		    ><li
+		      ><dfn class="src"
+			><a id="v:t" class="def"
+			  >t</a
+			  > :: T1 -&gt; <a href="#" title="Test"
+			  >T2</a
+			  > <a href="#" title="Data.Int"
+			  >Int</a
+			  > <a href="#" title="Data.Int"
+			  >Int</a
+			  > -&gt; <a href="#" title="Test"
+			  >T3</a
+			  > <a href="#" title="Data.Bool"
+			  >Bool</a
+			  > <a href="#" title="Data.Bool"
+			  >Bool</a
+			  > -&gt; <a href="#" title="Test"
+			  >T4</a
+			  > <a href="#" title="Prelude"
+			  >Float</a
+			  > <a href="#" title="Prelude"
+			  >Float</a
+			  > -&gt; <a href="#" title="Test"
+			  >T5</a
+			  > () ()</dfn
+			><div class="doc empty"
+			>&nbsp;</div
+			></li
+		      ><li
+		      ><dfn class="src"
+			><a id="v:u" class="def"
+			  >u</a
+			  >, <a id="v:v" class="def"
+			  >v</a
+			  > :: <a href="#" title="Data.Int"
+			  >Int</a
+			  ></dfn
+			><div class="doc empty"
+			>&nbsp;</div
+			></li
+		      ></ul
+		    ></div
+		  ></td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:R1" class="def"
+	    >R1</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Testing different record commenting styles</p
+	    ></div
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:C3" class="def"
+		  >C3</a
+		  ></td
+		><td class="doc"
+		><p
+		  >This is the <code
+		    ><a href="#" title="Test"
+		      >C3</a
+		      ></code
+		    > record constructor</p
+		  ></td
+		></tr
+	      ><tr
+	      ><td colspan="2"
+		><div class="subs fields"
+		  ><p class="caption"
+		    >Fields</p
+		    ><ul
+		    ><li
+		      ><dfn class="src"
+			><a id="v:s1" class="def"
+			  >s1</a
+			  > :: <a href="#" title="Data.Int"
+			  >Int</a
+			  ></dfn
+			><div class="doc"
+			><p
+			  >The <code
+			    ><a href="#" title="Test"
+			      >s1</a
+			      ></code
+			    > record selector</p
+			  ></div
+			></li
+		      ><li
+		      ><dfn class="src"
+			><a id="v:s2" class="def"
+			  >s2</a
+			  > :: <a href="#" title="Data.Int"
+			  >Int</a
+			  ></dfn
+			><div class="doc"
+			><p
+			  >The <code
+			    ><a href="#" title="Test"
+			      >s2</a
+			      ></code
+			    > record selector</p
+			  ></div
+			></li
+		      ><li
+		      ><dfn class="src"
+			><a id="v:s3" class="def"
+			  >s3</a
+			  > :: <a href="#" title="Data.Int"
+			  >Int</a
+			  ></dfn
+			><div class="doc"
+			><p
+			  >The <code
+			    ><a href="#" title="Test"
+			      >s3</a
+			      ></code
+			    > record selector</p
+			  ></div
+			></li
+		      ></ul
+		    ></div
+		  ></td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><div class="doc"
+	><p
+	  >test that we can export record selectors on their own:</p
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:p" class="def"
+	    >p</a
+	    > :: <a href="#" title="Test"
+	    >R</a
+	    > -&gt; <a href="#" title="Data.Int"
+	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >This comment applies to the <code
+	      ><a href="#" title="Test"
+		>p</a
+		></code
+	      > field</p
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:q" class="def"
+	    >q</a
+	    > :: <a href="#" title="Test"
+	    >R</a
+	    > -&gt; <span class="keyword"
+	    >forall</span
+	    > a. a -&gt; a <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >This comment applies to the <code
+	      ><a href="#" title="Test"
+		>q</a
+		></code
+	      > field</p
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:u" class="def"
+	    >u</a
+	    > :: <a href="#" title="Test"
+	    >R</a
+	    > -&gt; <a href="#" title="Data.Int"
+	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	><a href="#" id="g:4"
+	><h1
+	  >Class declarations</h1
+	  ></a
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >class</span
+	    > <a href="#" title="Test"
+	    >D</a
+	    > a =&gt; <a id="t:C" class="def"
+	    >C</a
+	    > a <span class="keyword"
+	    >where</span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >This comment applies to the <em
+	      >previous</em
+	      > declaration (the <code
+	      ><a href="#" title="Test"
+		>C</a
+		></code
+	      > class)</p
+	    ></div
+	  ><div class="subs methods"
+	  ><p class="caption"
+	    >Methods</p
+	    ><p class="src"
+	    ><a id="v:a" class="def"
+	      >a</a
+	      > :: <a href="#" title="System.IO"
+	      >IO</a
+	      > a <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ><div class="doc"
+	    ><p
+	      >this is a description of the <code
+		><a href="#" title="Test"
+		  >a</a
+		  ></code
+		> method</p
+	      ></div
+	    ><p class="src"
+	    ><a id="v:b" class="def"
+	      >b</a
+	      > :: [a] <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ><div class="doc"
+	    ><p
+	      >this is a description of the <code
+		><a href="#" title="Test"
+		  >b</a
+		  ></code
+		> method</p
+	      ></div
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >class</span
+	    > <a id="t:D" class="def"
+	    >D</a
+	    > a <span class="keyword"
+	    >where</span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >This is a class declaration with no separate docs for the methods</p
+	    ></div
+	  ><div class="subs methods"
+	  ><p class="caption"
+	    >Methods</p
+	    ><p class="src"
+	    ><a id="v:d" class="def"
+	      >d</a
+	      > :: <a href="#" title="Test"
+	      >T</a
+	      > a b <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ><p class="src"
+	    ><a id="v:e" class="def"
+	      >e</a
+	      > :: (a, a) <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ></div
+	  ><div class="subs instances"
+	  ><h4 class="instances details-toggle-control details-toggle" data-details-id="i:D"
+	    >Instances</h4
+	    ><details id="i:D" open="open"
+	    ><summary class="hide-when-js-enabled"
+	      >Instances details</summary
+	      ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:ic:D:D:1"
+		      ></span
+		      > <a href="#" title="Test"
+		      >D</a
+		      > <a href="#" title="Prelude"
+		      >Float</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:ic:D:D:1"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Test</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >d</a
+			  > :: <a href="#" title="Test"
+			  >T</a
+			  > <a href="#" title="Prelude"
+			  >Float</a
+			  > b <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >e</a
+			  > :: (<a href="#" title="Prelude"
+			  >Float</a
+			  >, <a href="#" title="Prelude"
+			  >Float</a
+			  >) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:ic:D:D:2"
+		      ></span
+		      > <a href="#" title="Test"
+		      >D</a
+		      > <a href="#" title="Data.Int"
+		      >Int</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:ic:D:D:2"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>Test</a
+			></p
+		      > <div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >d</a
+			  > :: <a href="#" title="Test"
+			  >T</a
+			  > <a href="#" title="Data.Int"
+			  >Int</a
+			  > b <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >e</a
+			  > :: (<a href="#" title="Data.Int"
+			  >Int</a
+			  >, <a href="#" title="Data.Int"
+			  >Int</a
+			  >) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		></table
+	      ></details
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >class</span
+	    > <a id="t:E" class="def"
+	    >E</a
+	    > a <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >This is a class declaration with no methods (or no methods exported)</p
+	    ></div
+	  ><div class="subs minimal"
+	  ><p class="caption"
+	    >Minimal complete definition</p
+	    ><p class="src"
+	    >ee</p
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >class</span
+	    > <a id="t:F" class="def"
+	    >F</a
+	    > a <span class="keyword"
+	    >where</span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs methods"
+	  ><p class="caption"
+	    >Methods</p
+	    ><p class="src"
+	    ><a id="v:ff" class="def"
+	      >ff</a
+	      > :: a <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ></div
+	  ></div
+	><div class="doc"
+	><p
+	  >Test that we can export a class method on its own:</p
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:a" class="def"
+	    >a</a
+	    > :: <a href="#" title="Test"
+	    >C</a
+	    > a =&gt; <a href="#" title="System.IO"
+	    >IO</a
+	    > a <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >this is a description of the <code
+	      ><a href="#" title="Test"
+		>a</a
+		></code
+	      > method</p
+	    ></div
+	  ></div
+	><a href="#" id="g:5"
+	><h1
+	  >Function types</h1
+	  ></a
+	><div class="top"
+	><p class="src"
+	  ><a id="v:f" class="def"
+	    >f</a
+	    > :: <a href="#" title="Test"
+	    >C</a
+	    > a =&gt; a -&gt; <a href="#" title="Data.Int"
+	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >In a comment string we can refer to identifiers in scope with
+single quotes like this: <code
+	      ><a href="#" title="Test"
+		>T</a
+		></code
+	      >, and we can refer to modules by
+using double quotes: <a href="#"
+	      >Foo</a
+	      >.  We can add emphasis <em
+	      >like this</em
+	      >.</p
+	    ><ul
+	    ><li
+	      >This is a bulleted list</li
+	      ><li
+	      >This is the next item (different kind of bullet)</li
+	      ></ul
+	    ><ol
+	    ><li value="1"
+	      >This is an ordered list</li
+	      ><li value="2"
+	      >This is the next item (different kind of bullet)</li
+	      ></ol
+	    ><dl
+	    ><dt
+	      >cat</dt
+	      ><dd
+	      >a small, furry, domesticated mammal</dd
+	      ><dt
+	      >pineapple</dt
+	      ><dd
+	      >a fruit grown in the tropics</dd
+	      ></dl
+	    ><pre
+	    >     This is a block of code, which can include other markup: <code
+	      ><a href="#" title="Test"
+		>R</a
+		></code
+	      >
+     formatting
+               is
+                 significant
+</pre
+	    ><pre
+	    >this is another block of code</pre
+	    ><p
+	    >We can also include URLs in documentation: <a href="#"
+	      >http://www.haskell.org/</a
+	      >.</p
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:g" class="def"
+	    >g</a
+	    > :: <a href="#" title="Data.Int"
+	    >Int</a
+	    > -&gt; <a href="#" title="System.IO"
+	    >IO</a
+	    > CInt <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >we can export foreign declarations too</p
+	    ></div
+	  ></div
+	><a href="#" id="g:6"
+	><h1
+	  >Auxiliary stuff</h1
+	  ></a
+	><div class="doc"
+	><p
+	  >This is some documentation that is attached to a name ($aux1)
+ rather than a source declaration.  The documentation may be
+ referred to in the export list using its name.</p
+	  ><pre
+	  > code block in named doc</pre
+	  ></div
+	><div class="doc"
+	><p
+	  >This is some documentation that is attached to a name ($aux2)</p
+	  ></div
+	><div class="doc"
+	><pre
+	  > code block on its own in named doc</pre
+	  ></div
+	><div class="doc"
+	><pre
+	  > code block on its own in named doc (after newline)</pre
+	  ></div
+	><div class="doc"
+	><p
+	  >a nested, named doc comment</p
+	  ><p
+	  >with a paragraph,</p
+	  ><pre
+	  > and a code block</pre
+	  ></div
+	><div class="doc"
+	><pre
+	  >test
+test1</pre
+	  ><pre
+	  > test2
+  test3
+</pre
+	  ></div
+	><div class="doc"
+	><pre
+	  >test1
+test2
+</pre
+	  ></div
+	><div class="doc"
+	><pre
+	  >test3
+test4</pre
+	  ></div
+	><div class="doc"
+	><pre
+	  >test1
+test2
+</pre
+	  ><pre
+	  >test3
+test4</pre
+	  ></div
+	><div class="doc"
+	><pre
+	  >test3
+test4</pre
+	  ><pre
+	  >test1
+test2
+</pre
+	  ></div
+	><div class="doc"
+	><p
+	  >aux11:</p
+	  ><pre
+	  >test3
+test4</pre
+	  ><pre
+	  >test1
+test2
+</pre
+	  ></div
+	><div class="doc"
+	><pre
+	  >foo</pre
+	  ><pre
+	  >bar</pre
+	  ></div
+	><div class="doc"
+	><p
+	  >This is some inline documentation in the export list</p
+	  ><pre
+	  >a code block using bird-tracks
+each line must begin with &gt; (which isn't significant unless it
+is at the beginning of the line).</pre
+	  ></div
+	><a href="#" id="g:7"
+	><h1
+	  >A hidden module</h1
+	  ></a
+	><div class="top"
+	><p class="src"
+	  ><a id="v:hidden" class="def"
+	    >hidden</a
+	    > :: <a href="#" title="Data.Int"
+	    >Int</a
+	    > -&gt; <a href="#" title="Data.Int"
+	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	><a href="#" id="g:8"
+	><h1
+	  >A visible module</h1
+	  ></a
+	><div class="top"
+	><p class="src"
+	  >module <a href="#"
+	    >Visible</a
+	    ></p
+	  ></div
+	><div class="doc"
+	><p
+	  >nested-style doc comments </p
+	  ></div
+	><a href="#" id="g:9"
+	><h1
+	  >Existential / Universal types</h1
+	  ></a
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:Ex" class="def"
+	    >Ex</a
+	    > a <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >A data-type using existential/universal types</p
+	    ></div
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><span class="keyword"
+		  >forall</span
+		  > b.<a href="#" title="Test"
+		  >C</a
+		  > b =&gt;  <a id="v:Ex1" class="def"
+		  >Ex1</a
+		  > b</td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ><tr
+	      ><td class="src"
+		><span class="keyword"
+		  >forall</span
+		  > b. <a id="v:Ex2" class="def"
+		  >Ex2</a
+		  > b</td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ><tr
+	      ><td class="src"
+		><span class="keyword"
+		  >forall</span
+		  > b.<a href="#" title="Test"
+		  >C</a
+		  > a =&gt;  <a id="v:Ex3" class="def"
+		  >Ex3</a
+		  > b</td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ><tr
+	      ><td class="src"
+		><a id="v:Ex4" class="def"
+		  >Ex4</a
+		  > (<span class="keyword"
+		  >forall</span
+		  > a. a -&gt; a)</td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><a href="#" id="g:10"
+	><h1
+	  >Type signatures with argument docs</h1
+	  ></a
+	><div class="top"
+	><p class="src"
+	  ><a id="v:k" class="def"
+	    >k</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs arguments"
+	  ><p class="caption"
+	    >Arguments</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		>:: <a href="#" title="Test"
+		  >T</a
+		  > () ()</td
+		><td class="doc"
+		><p
+		  >This argument has type <code
+		    ><a href="#" title="Test"
+		      >T</a
+		      ></code
+		    ></p
+		  ></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		>-&gt; <a href="#" title="Test"
+		  >T2</a
+		  > <a href="#" title="Data.Int"
+		  >Int</a
+		  > <a href="#" title="Data.Int"
+		  >Int</a
+		  ></td
+		><td class="doc"
+		><p
+		  >This argument has type 'T2 Int Int'</p
+		  ></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		>-&gt; (<a href="#" title="Test"
+		  >T3</a
+		  > <a href="#" title="Data.Bool"
+		  >Bool</a
+		  > <a href="#" title="Data.Bool"
+		  >Bool</a
+		  > -&gt; <a href="#" title="Test"
+		  >T4</a
+		  > <a href="#" title="Prelude"
+		  >Float</a
+		  > <a href="#" title="Prelude"
+		  >Float</a
+		  >)</td
+		><td class="doc"
+		><p
+		  >This argument has type <code
+		    >T3 Bool Bool -&gt; T4 Float Float</code
+		    ></p
+		  ></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		>-&gt; <a href="#" title="Test"
+		  >T5</a
+		  > () ()</td
+		><td class="doc"
+		><p
+		  >This argument has a very long description that should
+ hopefully cause some wrapping to happen when it is finally
+ rendered by Haddock in the generated HTML page.</p
+		  ></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		>-&gt; <a href="#" title="System.IO"
+		  >IO</a
+		  > ()</td
+		><td class="doc"
+		><p
+		  >This is the result type</p
+		  ></td
+		></tr
+	      ></table
+	    ></div
+	  ><div class="doc"
+	  ><p
+	    >This is a function with documentation for each argument</p
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:l" class="def"
+	    >l</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs arguments"
+	  ><p class="caption"
+	    >Arguments</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		>:: (<a href="#" title="Data.Int"
+		  >Int</a
+		  >, <a href="#" title="Data.Int"
+		  >Int</a
+		  >, <a href="#" title="Prelude"
+		  >Float</a
+		  >)</td
+		><td class="doc"
+		><p
+		  >takes a triple</p
+		  ></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		>-&gt; <a href="#" title="Data.Int"
+		  >Int</a
+		  ></td
+		><td class="doc"
+		><p
+		  >returns an <code
+		    ><a href="#" title="Data.Int"
+		      >Int</a
+		      ></code
+		    ></p
+		  ></td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:m" class="def"
+	    >m</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs arguments"
+	  ><p class="caption"
+	    >Arguments</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		>:: <a href="#" title="Test"
+		  >R</a
+		  ></td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ><tr
+	      ><td class="src"
+		>-&gt; <a href="#" title="Test"
+		  >N1</a
+		  > ()</td
+		><td class="doc"
+		><p
+		  >one of the arguments</p
+		  ></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		>-&gt; <a href="#" title="System.IO"
+		  >IO</a
+		  > <a href="#" title="Data.Int"
+		  >Int</a
+		  ></td
+		><td class="doc"
+		><p
+		  >and the return value</p
+		  ></td
+		></tr
+	      ></table
+	    ></div
+	  ><div class="doc"
+	  ><p
+	    >This function has some arg docs</p
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:o" class="def"
+	    >o</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs arguments"
+	  ><p class="caption"
+	    >Arguments</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		>:: <a href="#" title="Prelude"
+		  >Float</a
+		  ></td
+		><td class="doc"
+		><p
+		  >The input float</p
+		  ></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		>-&gt; <a href="#" title="System.IO"
+		  >IO</a
+		  > <a href="#" title="Prelude"
+		  >Float</a
+		  ></td
+		><td class="doc"
+		><p
+		  >The output float</p
+		  ></td
+		></tr
+	      ></table
+	    ></div
+	  ><div class="doc"
+	  ><p
+	    >A foreign import with argument docs</p
+	    ></div
+	  ></div
+	><a href="#" id="g:11"
+	><h1
+	  >A section</h1
+	  ></a
+	><a href="#" id="g:12"
+	><h2
+	  >A subsection</h2
+	  ></a
+	><div class="doc"
+	><pre
+	  >a literal line</pre
+	  ><p
+	  >$ a non <em
+	    >literal</em
+	    > line $</p
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:f-39-" class="def"
+	    >f'</a
+	    > :: <a href="#" title="Data.Int"
+	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >a function with a prime can be referred to as <code
+	      ><a href="#" title="Test"
+		>f'</a
+		></code
+	      >
+ but f' doesn't get link'd 'f''</p
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:withType" class="def"
+	    >withType</a
+	    > :: <a href="#" title="Data.Int"
+	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Comment on a definition with type signature</p
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:withoutType" class="def"
+	    >withoutType</a
+	    > :: a <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Comment on a definition without type signature</p
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Threaded.html b/html-test/ref/Threaded.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Threaded.html
@@ -0,0 +1,99 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Threaded</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Threaded</p
+	></div
+      ><div id="description"
+      ><p class="caption"
+	>Description</p
+	><div class="doc"
+	><p
+	  >Ensures haddock built with <code
+	    >-threaded</code
+	    >.</p
+	  ></div
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><a href="#"
+	      >f</a
+	      > :: <a href="#" title="Prelude"
+	      >Integer</a
+	      ></li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><a id="v:f" class="def"
+	    >f</a
+	    > :: <a href="#" title="Prelude"
+	    >Integer</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    ><code
+	      >$(forkTH)</code
+	      > fails at compile time if haddock isn't using the
+ threaded RTS.</p
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Threaded_TH.html b/html-test/ref/Threaded_TH.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Threaded_TH.html
@@ -0,0 +1,104 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Threaded_TH</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Threaded_TH</p
+	></div
+      ><div id="description"
+      ><p class="caption"
+	>Description</p
+	><div class="doc"
+	><p
+	  >Imported by <code
+	    >Threaded</code
+	    >, since a TH splice can't be used in the
+ module where it is defined.</p
+	  ></div
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><a href="#"
+	      >forkTH</a
+	      > :: <a href="#" title="Language.Haskell.TH.Syntax"
+	      >Q</a
+	      > <a href="#" title="Language.Haskell.TH.Syntax"
+	      >Exp</a
+	      ></li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><a id="v:forkTH" class="def"
+	    >forkTH</a
+	    > :: <a href="#" title="Language.Haskell.TH.Syntax"
+	    >Q</a
+	    > <a href="#" title="Language.Haskell.TH.Syntax"
+	    >Exp</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >forkOS requires the threaded RTS, so this TH fails if haddock was
+ built without <code
+	      >-threaded</code
+	      >.</p
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Ticket112.html b/html-test/ref/Ticket112.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Ticket112.html
@@ -0,0 +1,86 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Ticket112</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Ticket112</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><a href="#"
+	      >f</a
+	      > :: a</li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><a id="v:f" class="def"
+	    >f</a
+	    > :: a <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >...given a raw <code
+	      ><a href="#" title="GHC.Exts"
+		>Addr#</a
+		></code
+	      > to the string, and the length of the string.</p
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Ticket61.html b/html-test/ref/Ticket61.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Ticket61.html
@@ -0,0 +1,84 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Ticket61</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Ticket61</p
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >class</span
+	    > <a id="t:C" class="def"
+	    >C</a
+	    > a <span class="keyword"
+	    >where</span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs methods"
+	  ><p class="caption"
+	    >Methods</p
+	    ><p class="src"
+	    ><a id="v:f" class="def"
+	      >f</a
+	      > :: a <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ><div class="doc"
+	    ><p
+	      >A comment about f</p
+	      ></div
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Ticket75.html b/html-test/ref/Ticket75.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Ticket75.html
@@ -0,0 +1,122 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Ticket75</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Ticket75</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > a <a href="#"
+	      >:-</a
+	      > b = <a href="#"
+	      >Q</a
+	      ></li
+	    ><li class="src short"
+	    ><a href="#"
+	      >f</a
+	      > :: <a href="#" title="Data.Int"
+	      >Int</a
+	      ></li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > a <a id="t::-45-" class="def"
+	    >:-</a
+	    > b <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:Q" class="def"
+		  >Q</a
+		  ></td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:f" class="def"
+	    >f</a
+	    > :: <a href="#" title="Data.Int"
+	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >A reference to <code
+	      ><a href="#" title="Ticket75"
+		>:-</a
+		></code
+	      ></p
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/TitledPicture.html b/html-test/ref/TitledPicture.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/TitledPicture.html
@@ -0,0 +1,116 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >TitledPicture</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>TitledPicture</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><a href="#"
+	      >foo</a
+	      > :: <a href="#" title="Prelude"
+	      >Integer</a
+	      ></li
+	    ><li class="src short"
+	    ><a href="#"
+	      >bar</a
+	      > :: <a href="#" title="Prelude"
+	      >Integer</a
+	      ></li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><a id="v:foo" class="def"
+	    >foo</a
+	    > :: <a href="#" title="Prelude"
+	    >Integer</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Picture for <code
+	      ><a href="#" title="TitledPicture"
+		>foo</a
+		></code
+	      > without a title <img src="bar"
+	       /></p
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:bar" class="def"
+	    >bar</a
+	    > :: <a href="#" title="Prelude"
+	    >Integer</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Picture for <code
+	      ><a href="#" title="TitledPicture"
+		>bar</a
+		></code
+	      > with title <img src="un&#8739;&#8705;&#8728;" title="&#948;&#8712;"
+	       /></p
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/TypeFamilies.html b/html-test/ref/TypeFamilies.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/TypeFamilies.html
@@ -0,0 +1,1928 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >TypeFamilies</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>TypeFamilies</p
+	></div
+      ><div id="description"
+      ><p class="caption"
+	>Description</p
+	><div class="doc"
+	><p
+	  >Doc for: module TypeFamilies</p
+	  ></div
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > <a href="#"
+	      >X</a
+	      ><ul class="subs"
+	      ><li
+		>= <a href="#"
+		  >X</a
+		  ></li
+		><li
+		>| <a href="#"
+		  >XX</a
+		  ></li
+		><li
+		>| <a href="#"
+		  >XXX</a
+		  ></li
+		></ul
+	      ></li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > <a href="#"
+	      >Y</a
+	      ></li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > <a href="#"
+	      >Z</a
+	      ><ul class="subs"
+	      ><li
+		>= <a href="#"
+		  >ZA</a
+		  ></li
+		><li
+		>| <a href="#"
+		  >ZB</a
+		  ></li
+		></ul
+	      ></li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >class</span
+	      > <a href="#"
+	      >Test</a
+	      > a</li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >type family</span
+	      > <a href="#"
+	      >Foo</a
+	      > a :: k</li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >data family</span
+	      > <a href="#"
+	      >Bat</a
+	      > (a :: k) :: *</li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >class</span
+	      > <a href="#"
+	      >Assoc</a
+	      > a <span class="keyword"
+	      >where</span
+	      ><ul class="subs"
+	      ><li
+		><span class="keyword"
+		  >data</span
+		  > <a href="#"
+		  >AssocD</a
+		  > a :: *</li
+		><li
+		><span class="keyword"
+		  >type</span
+		  > <a href="#"
+		  >AssocT</a
+		  > a :: *</li
+		></ul
+	      ></li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >type family</span
+	      > <a href="#"
+	      >Bar</a
+	      > b <span class="keyword"
+	      >where ...</span
+	      ></li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >type family</span
+	      > (a :: k) <a href="#"
+	      >&lt;&gt;</a
+	      > (b :: k) :: k</li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >class</span
+	      > (a :: k) <a href="#"
+	      >&gt;&lt;</a
+	      > (b :: k)</li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:X" class="def"
+	    >X</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Doc for: data X</p
+	    ></div
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:X" class="def"
+		  >X</a
+		  ></td
+		><td class="doc"
+		><p
+		  >Doc for: X</p
+		  ></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		><a id="v:XX" class="def"
+		  >XX</a
+		  ></td
+		><td class="doc"
+		><p
+		  >Doc for: XX</p
+		  ></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		><a id="v:XXX" class="def"
+		  >XXX</a
+		  ></td
+		><td class="doc"
+		><p
+		  >Doc for: XXX</p
+		  ></td
+		></tr
+	      ></table
+	    ></div
+	  ><div class="subs instances"
+	  ><h4 class="instances details-toggle-control details-toggle" data-details-id="i:X"
+	    >Instances</h4
+	    ><details id="i:X" open="open"
+	    ><summary class="hide-when-js-enabled"
+	      >Instances details</summary
+	      ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:X:Assoc:1"
+		      ></span
+		      > <a href="#" title="TypeFamilies"
+		      >Assoc</a
+		      > <a href="#" title="TypeFamilies"
+		      >X</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    >Doc for: instance Assoc X</p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:X:Assoc:1"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>TypeFamilies</a
+			></p
+		      > <div class="subs associated-types"
+		      ><p class="caption"
+			>Associated Types</p
+			><p class="src"
+			><span class="keyword"
+			  >data</span
+			  > <a href="#" title="TypeFamilies"
+			  >AssocD</a
+			  > <a href="#" title="TypeFamilies"
+			  >X</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><span class="keyword"
+			  >type</span
+			  > <a href="#" title="TypeFamilies"
+			  >AssocT</a
+			  > <a href="#" title="TypeFamilies"
+			  >X</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:X:Test:2"
+		      ></span
+		      > <a href="#" title="TypeFamilies"
+		      >Test</a
+		      > <a href="#" title="TypeFamilies"
+		      >X</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    >Doc for: instance Test X</p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:X:Test:2"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>TypeFamilies</a
+			></p
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:X:-62--60-:3"
+		      ></span
+		      > '<a href="#" title="TypeFamilies"
+		      >XX</a
+		      > <a href="#" title="TypeFamilies"
+		      >&gt;&lt;</a
+		      > '<a href="#" title="TypeFamilies"
+		      >XXX</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:X:-62--60-:3"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>TypeFamilies</a
+			></p
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:X:Foo:4"
+		      ></span
+		      > <span class="keyword"
+		      >type</span
+		      > <a href="#" title="TypeFamilies2"
+		      >Foo</a
+		      > <a href="#" title="TypeFamilies"
+		      >X</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    >External instance</p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:X:Foo:4"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>TypeFamilies</a
+			></p
+		      > <div class="src"
+		      ><span class="keyword"
+			>type</span
+			> <a href="#" title="TypeFamilies2"
+			>Foo</a
+			> <a href="#" title="TypeFamilies"
+			>X</a
+			> = <a href="#" title="TypeFamilies"
+			>Y</a
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:X:AssocD:5"
+		      ></span
+		      > <span class="keyword"
+		      >data</span
+		      > <a href="#" title="TypeFamilies"
+		      >AssocD</a
+		      > <a href="#" title="TypeFamilies"
+		      >X</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:X:AssocD:5"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>TypeFamilies</a
+			></p
+		      > <div class="src"
+		      ><span class="keyword"
+			>data</span
+			> <a href="#" title="TypeFamilies"
+			>AssocD</a
+			> <a href="#" title="TypeFamilies"
+			>X</a
+			> = <a id="v:AssocX" class="def"
+			>AssocX</a
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:X:AssocT:6"
+		      ></span
+		      > <span class="keyword"
+		      >type</span
+		      > <a href="#" title="TypeFamilies"
+		      >AssocT</a
+		      > <a href="#" title="TypeFamilies"
+		      >X</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:X:AssocT:6"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>TypeFamilies</a
+			></p
+		      > <div class="src"
+		      ><span class="keyword"
+			>type</span
+			> <a href="#" title="TypeFamilies"
+			>AssocT</a
+			> <a href="#" title="TypeFamilies"
+			>X</a
+			> = <a href="#" title="TypeFamilies"
+			>Foo</a
+			> <a href="#" title="TypeFamilies"
+			>X</a
+			> :: <a href="#" title="Data.Kind"
+			>Type</a
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:X:Bat:7"
+		      ></span
+		      > <span class="keyword"
+		      >data</span
+		      > <a href="#" title="TypeFamilies"
+		      >Bat</a
+		      > <a href="#" title="TypeFamilies"
+		      >X</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    >Doc for: data instance Bat X</p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:X:Bat:7"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>TypeFamilies</a
+			></p
+		      > <div class="src"
+		      ><span class="keyword"
+			>data</span
+			> <a href="#" title="TypeFamilies"
+			>Bat</a
+			> <a href="#" title="TypeFamilies"
+			>X</a
+			> <ul class="inst"
+			><li class="inst"
+			  >= <a id="v:BatX" class="def"
+			    >BatX</a
+			    > <a href="#" title="TypeFamilies"
+			    >X</a
+			    ></li
+			  ><li class="inst"
+			  >| <a id="v:BatXX" class="def"
+			    >BatXX</a
+			    > { <ul class="subs"
+			    ><li
+			      ><a id="v:aaa" class="def"
+				>aaa</a
+				> :: <a href="#" title="TypeFamilies"
+				>X</a
+				></li
+			      ><li
+			      ><a id="v:bbb" class="def"
+				>bbb</a
+				> :: <a href="#" title="TypeFamilies"
+				>Y</a
+				></li
+			      ></ul
+			    > }</li
+			  ></ul
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:X:Foo:8"
+		      ></span
+		      > <span class="keyword"
+		      >type</span
+		      > <a href="#" title="TypeFamilies"
+		      >Foo</a
+		      > <a href="#" title="TypeFamilies"
+		      >X</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    >Doc for: type instance Foo X = Y</p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:X:Foo:8"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>TypeFamilies</a
+			></p
+		      > <div class="src"
+		      ><span class="keyword"
+			>type</span
+			> <a href="#" title="TypeFamilies"
+			>Foo</a
+			> <a href="#" title="TypeFamilies"
+			>X</a
+			> = <a href="#" title="TypeFamilies"
+			>Y</a
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:X:-60--62-:9"
+		      ></span
+		      > <span class="keyword"
+		      >type</span
+		      > '<a href="#" title="TypeFamilies"
+		      >XXX</a
+		      > <a href="#" title="TypeFamilies"
+		      >&lt;&gt;</a
+		      > '<a href="#" title="TypeFamilies"
+		      >XX</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:X:-60--62-:9"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>TypeFamilies</a
+			></p
+		      > <div class="src"
+		      ><span class="keyword"
+			>type</span
+			> '<a href="#" title="TypeFamilies"
+			>XXX</a
+			> <a href="#" title="TypeFamilies"
+			>&lt;&gt;</a
+			> '<a href="#" title="TypeFamilies"
+			>XX</a
+			> = '<a href="#" title="TypeFamilies"
+			>X</a
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:X:-60--62-:10"
+		      ></span
+		      > <span class="keyword"
+		      >type</span
+		      > <a href="#" title="TypeFamilies"
+		      >X</a
+		      > <a href="#" title="TypeFamilies"
+		      >&lt;&gt;</a
+		      > (a :: <a href="#" title="Data.Kind"
+		      >Type</a
+		      >)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:X:-60--62-:10"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>TypeFamilies</a
+			></p
+		      > <div class="src"
+		      ><span class="keyword"
+			>type</span
+			> <a href="#" title="TypeFamilies"
+			>X</a
+			> <a href="#" title="TypeFamilies"
+			>&lt;&gt;</a
+			> (a :: <a href="#" title="Data.Kind"
+			>Type</a
+			>) = <a href="#" title="TypeFamilies"
+			>X</a
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		></table
+	      ></details
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:Y" class="def"
+	    >Y</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Doc for: data Y</p
+	    ></div
+	  ><div class="subs instances"
+	  ><h4 class="instances details-toggle-control details-toggle" data-details-id="i:Y"
+	    >Instances</h4
+	    ><details id="i:Y" open="open"
+	    ><summary class="hide-when-js-enabled"
+	      >Instances details</summary
+	      ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:Y:Assoc:1"
+		      ></span
+		      > <a href="#" title="TypeFamilies"
+		      >Assoc</a
+		      > <a href="#" title="TypeFamilies"
+		      >Y</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    >Doc for: instance Assoc Y</p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:Y:Assoc:1"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>TypeFamilies</a
+			></p
+		      > <div class="subs associated-types"
+		      ><p class="caption"
+			>Associated Types</p
+			><p class="src"
+			><span class="keyword"
+			  >data</span
+			  > <a href="#" title="TypeFamilies"
+			  >AssocD</a
+			  > <a href="#" title="TypeFamilies"
+			  >Y</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><span class="keyword"
+			  >type</span
+			  > <a href="#" title="TypeFamilies"
+			  >AssocT</a
+			  > <a href="#" title="TypeFamilies"
+			  >Y</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:Y:Test:2"
+		      ></span
+		      > <a href="#" title="TypeFamilies"
+		      >Test</a
+		      > <a href="#" title="TypeFamilies"
+		      >Y</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    >Doc for: instance Test Y</p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:Y:Test:2"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>TypeFamilies</a
+			></p
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:Y:Bar:3"
+		      ></span
+		      > <span class="keyword"
+		      >data</span
+		      > <a href="#" title="TypeFamilies2"
+		      >Bar</a
+		      > <a href="#" title="TypeFamilies"
+		      >Y</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:Y:Bar:3"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>TypeFamilies</a
+			></p
+		      > <div class="src"
+		      ><span class="keyword"
+			>data</span
+			> <a href="#" title="TypeFamilies2"
+			>Bar</a
+			> <a href="#" title="TypeFamilies"
+			>Y</a
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:Y:AssocD:4"
+		      ></span
+		      > <span class="keyword"
+		      >data</span
+		      > <a href="#" title="TypeFamilies"
+		      >AssocD</a
+		      > <a href="#" title="TypeFamilies"
+		      >Y</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:Y:AssocD:4"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>TypeFamilies</a
+			></p
+		      > <div class="src"
+		      ><span class="keyword"
+			>data</span
+			> <a href="#" title="TypeFamilies"
+			>AssocD</a
+			> <a href="#" title="TypeFamilies"
+			>Y</a
+			> = <a id="v:AssocY" class="def"
+			>AssocY</a
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:Y:AssocT:5"
+		      ></span
+		      > <span class="keyword"
+		      >type</span
+		      > <a href="#" title="TypeFamilies"
+		      >AssocT</a
+		      > <a href="#" title="TypeFamilies"
+		      >Y</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:Y:AssocT:5"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>TypeFamilies</a
+			></p
+		      > <div class="src"
+		      ><span class="keyword"
+			>type</span
+			> <a href="#" title="TypeFamilies"
+			>AssocT</a
+			> <a href="#" title="TypeFamilies"
+			>Y</a
+			> = <a href="#" title="TypeFamilies"
+			>Bat</a
+			> <a href="#" title="TypeFamilies"
+			>Y</a
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:Y:Bat:6"
+		      ></span
+		      > <span class="keyword"
+		      >data</span
+		      > <a href="#" title="TypeFamilies"
+		      >Bat</a
+		      > <a href="#" title="TypeFamilies"
+		      >Y</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    >Doc for: data instance Bat Y</p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:Y:Bat:6"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>TypeFamilies</a
+			></p
+		      > <div class="src"
+		      ><span class="keyword"
+			>data</span
+			> <a href="#" title="TypeFamilies"
+			>Bat</a
+			> <a href="#" title="TypeFamilies"
+			>Y</a
+			> = <a id="v:BatY" class="def"
+			>BatY</a
+			> <a href="#" title="TypeFamilies"
+			>Y</a
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:Y:Foo:7"
+		      ></span
+		      > <span class="keyword"
+		      >type</span
+		      > <a href="#" title="TypeFamilies"
+		      >Foo</a
+		      > <a href="#" title="TypeFamilies"
+		      >Y</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    >Doc for: type instance Foo Y = X</p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:Y:Foo:7"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>TypeFamilies</a
+			></p
+		      > <div class="src"
+		      ><span class="keyword"
+			>type</span
+			> <a href="#" title="TypeFamilies"
+			>Foo</a
+			> <a href="#" title="TypeFamilies"
+			>Y</a
+			> = <a href="#" title="TypeFamilies"
+			>X</a
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:Y:-60--62-:8"
+		      ></span
+		      > <span class="keyword"
+		      >type</span
+		      > <a href="#" title="TypeFamilies"
+		      >Y</a
+		      > <a href="#" title="TypeFamilies"
+		      >&lt;&gt;</a
+		      > (a :: <a href="#" title="Data.Kind"
+		      >Type</a
+		      >)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:Y:-60--62-:8"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>TypeFamilies</a
+			></p
+		      > <div class="src"
+		      ><span class="keyword"
+			>type</span
+			> <a href="#" title="TypeFamilies"
+			>Y</a
+			> <a href="#" title="TypeFamilies"
+			>&lt;&gt;</a
+			> (a :: <a href="#" title="Data.Kind"
+			>Type</a
+			>) = a</div
+		      ></details
+		    ></td
+		  ></tr
+		></table
+	      ></details
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:Z" class="def"
+	    >Z</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Doc for: data Z</p
+	    ></div
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:ZA" class="def"
+		  >ZA</a
+		  ></td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ><tr
+	      ><td class="src"
+		><a id="v:ZB" class="def"
+		  >ZB</a
+		  ></td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ></table
+	    ></div
+	  ><div class="subs instances"
+	  ><h4 class="instances details-toggle-control details-toggle" data-details-id="i:Z"
+	    >Instances</h4
+	    ><details id="i:Z" open="open"
+	    ><summary class="hide-when-js-enabled"
+	      >Instances details</summary
+	      ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:Z:Bat:1"
+		      ></span
+		      > <span class="keyword"
+		      >data</span
+		      > <a href="#" title="TypeFamilies"
+		      >Bat</a
+		      > (z :: <a href="#" title="TypeFamilies"
+		      >Z</a
+		      >)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    >Doc for: data instance Bat Z</p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:Z:Bat:1"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>TypeFamilies</a
+			></p
+		      > <div class="src"
+		      ><span class="keyword"
+			>data</span
+			> <a href="#" title="TypeFamilies"
+			>Bat</a
+			> (z :: <a href="#" title="TypeFamilies"
+			>Z</a
+			>) <span class="keyword"
+			>where</span
+			><ul class="inst"
+			><li class="inst"
+			  ><a id="v:BatZ1" class="def"
+			    >BatZ1</a
+			    > :: <a href="#" title="TypeFamilies"
+			    >Z</a
+			    > -&gt; <a href="#" title="TypeFamilies"
+			    >Bat</a
+			    > '<a href="#" title="TypeFamilies"
+			    >ZA</a
+			    ></li
+			  ><li class="inst"
+			  ><a id="v:BatZ2" class="def"
+			    >BatZ2</a
+			    > :: {..} -&gt; <a href="#" title="TypeFamilies"
+			    >Bat</a
+			    > '<a href="#" title="TypeFamilies"
+			    >ZB</a
+			    ></li
+			  ></ul
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		></table
+	      ></details
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >class</span
+	    > <a id="t:Test" class="def"
+	    >Test</a
+	    > a <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Doc for: class Test a</p
+	    ></div
+	  ><div class="subs instances"
+	  ><h4 class="instances details-toggle-control details-toggle" data-details-id="i:Test"
+	    >Instances</h4
+	    ><details id="i:Test" open="open"
+	    ><summary class="hide-when-js-enabled"
+	      >Instances details</summary
+	      ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:ic:Test:Test:1"
+		      ></span
+		      > <a href="#" title="TypeFamilies"
+		      >Test</a
+		      > <a href="#" title="TypeFamilies"
+		      >X</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    >Doc for: instance Test X</p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:ic:Test:Test:1"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>TypeFamilies</a
+			></p
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:ic:Test:Test:2"
+		      ></span
+		      > <a href="#" title="TypeFamilies"
+		      >Test</a
+		      > <a href="#" title="TypeFamilies"
+		      >Y</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    >Doc for: instance Test Y</p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:ic:Test:Test:2"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>TypeFamilies</a
+			></p
+		      ></details
+		    ></td
+		  ></tr
+		></table
+	      ></details
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >type family</span
+	    > <a id="t:Foo" class="def"
+	    >Foo</a
+	    > a :: k <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Doc for: type family Foo a</p
+	    ></div
+	  ><div class="subs instances"
+	  ><h4 class="instances details-toggle-control details-toggle" data-details-id="i:Foo"
+	    >Instances</h4
+	    ><details id="i:Foo" open="open"
+	    ><summary class="hide-when-js-enabled"
+	      >Instances details</summary
+	      ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:if:Foo:Foo:1"
+		      ></span
+		      > <span class="keyword"
+		      >type</span
+		      > <a href="#" title="TypeFamilies"
+		      >Foo</a
+		      > <a href="#" title="TypeFamilies"
+		      >X</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    >Doc for: type instance Foo X = Y</p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:if:Foo:Foo:1"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>TypeFamilies</a
+			></p
+		      > <div class="src"
+		      ><span class="keyword"
+			>type</span
+			> <a href="#" title="TypeFamilies"
+			>Foo</a
+			> <a href="#" title="TypeFamilies"
+			>X</a
+			> = <a href="#" title="TypeFamilies"
+			>Y</a
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:if:Foo:Foo:2"
+		      ></span
+		      > <span class="keyword"
+		      >type</span
+		      > <a href="#" title="TypeFamilies"
+		      >Foo</a
+		      > <a href="#" title="TypeFamilies"
+		      >Y</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    >Doc for: type instance Foo Y = X</p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:if:Foo:Foo:2"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>TypeFamilies</a
+			></p
+		      > <div class="src"
+		      ><span class="keyword"
+			>type</span
+			> <a href="#" title="TypeFamilies"
+			>Foo</a
+			> <a href="#" title="TypeFamilies"
+			>Y</a
+			> = <a href="#" title="TypeFamilies"
+			>X</a
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		></table
+	      ></details
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data family</span
+	    > <a id="t:Bat" class="def"
+	    >Bat</a
+	    > (a :: k) :: * <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Doc for: data family Bat a</p
+	    ></div
+	  ><div class="subs instances"
+	  ><h4 class="instances details-toggle-control details-toggle" data-details-id="i:Bat"
+	    >Instances</h4
+	    ><details id="i:Bat" open="open"
+	    ><summary class="hide-when-js-enabled"
+	      >Instances details</summary
+	      ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:if:Bat:Bat:1"
+		      ></span
+		      > <span class="keyword"
+		      >data</span
+		      > <a href="#" title="TypeFamilies"
+		      >Bat</a
+		      > (z :: <a href="#" title="TypeFamilies"
+		      >Z</a
+		      >)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    >Doc for: data instance Bat Z</p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:if:Bat:Bat:1"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>TypeFamilies</a
+			></p
+		      > <div class="src"
+		      ><span class="keyword"
+			>data</span
+			> <a href="#" title="TypeFamilies"
+			>Bat</a
+			> (z :: <a href="#" title="TypeFamilies"
+			>Z</a
+			>) <span class="keyword"
+			>where</span
+			><ul class="inst"
+			><li class="inst"
+			  ><a id="v:BatZ1" class="def"
+			    >BatZ1</a
+			    > :: <a href="#" title="TypeFamilies"
+			    >Z</a
+			    > -&gt; <a href="#" title="TypeFamilies"
+			    >Bat</a
+			    > '<a href="#" title="TypeFamilies"
+			    >ZA</a
+			    ></li
+			  ><li class="inst"
+			  ><a id="v:BatZ2" class="def"
+			    >BatZ2</a
+			    > :: {..} -&gt; <a href="#" title="TypeFamilies"
+			    >Bat</a
+			    > '<a href="#" title="TypeFamilies"
+			    >ZB</a
+			    ></li
+			  ></ul
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:if:Bat:Bat:2"
+		      ></span
+		      > <span class="keyword"
+		      >data</span
+		      > <a href="#" title="TypeFamilies"
+		      >Bat</a
+		      > <a href="#" title="TypeFamilies"
+		      >X</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    >Doc for: data instance Bat X</p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:if:Bat:Bat:2"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>TypeFamilies</a
+			></p
+		      > <div class="src"
+		      ><span class="keyword"
+			>data</span
+			> <a href="#" title="TypeFamilies"
+			>Bat</a
+			> <a href="#" title="TypeFamilies"
+			>X</a
+			> <ul class="inst"
+			><li class="inst"
+			  >= <a id="v:BatX" class="def"
+			    >BatX</a
+			    > <a href="#" title="TypeFamilies"
+			    >X</a
+			    ></li
+			  ><li class="inst"
+			  >| <a id="v:BatXX" class="def"
+			    >BatXX</a
+			    > { <ul class="subs"
+			    ><li
+			      ><a id="v:aaa" class="def"
+				>aaa</a
+				> :: <a href="#" title="TypeFamilies"
+				>X</a
+				></li
+			      ><li
+			      ><a id="v:bbb" class="def"
+				>bbb</a
+				> :: <a href="#" title="TypeFamilies"
+				>Y</a
+				></li
+			      ></ul
+			    > }</li
+			  ></ul
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:if:Bat:Bat:3"
+		      ></span
+		      > <span class="keyword"
+		      >data</span
+		      > <a href="#" title="TypeFamilies"
+		      >Bat</a
+		      > <a href="#" title="TypeFamilies"
+		      >Y</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    >Doc for: data instance Bat Y</p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:if:Bat:Bat:3"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>TypeFamilies</a
+			></p
+		      > <div class="src"
+		      ><span class="keyword"
+			>data</span
+			> <a href="#" title="TypeFamilies"
+			>Bat</a
+			> <a href="#" title="TypeFamilies"
+			>Y</a
+			> = <a id="v:BatY" class="def"
+			>BatY</a
+			> <a href="#" title="TypeFamilies"
+			>Y</a
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		></table
+	      ></details
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >class</span
+	    > <a id="t:Assoc" class="def"
+	    >Assoc</a
+	    > a <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Doc for: class Assoc a</p
+	    ></div
+	  ><div class="subs associated-types"
+	  ><p class="caption"
+	    >Associated Types</p
+	    ><p class="src"
+	    ><span class="keyword"
+	      >data</span
+	      > <a id="t:AssocD" class="def"
+	      >AssocD</a
+	      > a :: * <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ><div class="doc"
+	    ><p
+	      >Doc for: data AssocD a</p
+	      ></div
+	    ><p class="src"
+	    ><span class="keyword"
+	      >type</span
+	      > <a id="t:AssocT" class="def"
+	      >AssocT</a
+	      > a :: * <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ><div class="doc"
+	    ><p
+	      >Doc for: type AssocT a</p
+	      ></div
+	    ></div
+	  ><div class="subs instances"
+	  ><h4 class="instances details-toggle-control details-toggle" data-details-id="i:Assoc"
+	    >Instances</h4
+	    ><details id="i:Assoc" open="open"
+	    ><summary class="hide-when-js-enabled"
+	      >Instances details</summary
+	      ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:ic:Assoc:Assoc:1"
+		      ></span
+		      > <a href="#" title="TypeFamilies"
+		      >Assoc</a
+		      > <a href="#" title="TypeFamilies"
+		      >X</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    >Doc for: instance Assoc X</p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:ic:Assoc:Assoc:1"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>TypeFamilies</a
+			></p
+		      > <div class="subs associated-types"
+		      ><p class="caption"
+			>Associated Types</p
+			><p class="src"
+			><span class="keyword"
+			  >data</span
+			  > <a href="#" title="TypeFamilies"
+			  >AssocD</a
+			  > <a href="#" title="TypeFamilies"
+			  >X</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><span class="keyword"
+			  >type</span
+			  > <a href="#" title="TypeFamilies"
+			  >AssocT</a
+			  > <a href="#" title="TypeFamilies"
+			  >X</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:ic:Assoc:Assoc:2"
+		      ></span
+		      > <a href="#" title="TypeFamilies"
+		      >Assoc</a
+		      > <a href="#" title="TypeFamilies"
+		      >Y</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    >Doc for: instance Assoc Y</p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:ic:Assoc:Assoc:2"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>TypeFamilies</a
+			></p
+		      > <div class="subs associated-types"
+		      ><p class="caption"
+			>Associated Types</p
+			><p class="src"
+			><span class="keyword"
+			  >data</span
+			  > <a href="#" title="TypeFamilies"
+			  >AssocD</a
+			  > <a href="#" title="TypeFamilies"
+			  >Y</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><span class="keyword"
+			  >type</span
+			  > <a href="#" title="TypeFamilies"
+			  >AssocT</a
+			  > <a href="#" title="TypeFamilies"
+			  >Y</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		></table
+	      ></details
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >type family</span
+	    > <a id="t:Bar" class="def"
+	    >Bar</a
+	    > b <span class="keyword"
+	    >where ...</span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Doc for: type family Bar b</p
+	    ></div
+	  ><div class="subs equations"
+	  ><p class="caption"
+	    >Equations</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a href="#" title="TypeFamilies"
+		  >Bar</a
+		  > <a href="#" title="TypeFamilies"
+		  >X</a
+		  > = <a href="#" title="TypeFamilies"
+		  >X</a
+		  ></td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ><tr
+	      ><td class="src"
+		><a href="#" title="TypeFamilies"
+		  >Bar</a
+		  > y = <a href="#" title="TypeFamilies"
+		  >Y</a
+		  ></td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >type family</span
+	    > (a :: k) <a id="t:-60--62-" class="def"
+	    >&lt;&gt;</a
+	    > (b :: k) :: k <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs instances"
+	  ><h4 class="instances details-toggle-control details-toggle" data-details-id="i:-60--62-"
+	    >Instances</h4
+	    ><details id="i:-60--62-" open="open"
+	    ><summary class="hide-when-js-enabled"
+	      >Instances details</summary
+	      ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:if:-60--62-:-60--62-:1"
+		      ></span
+		      > <span class="keyword"
+		      >type</span
+		      > '<a href="#" title="TypeFamilies"
+		      >XXX</a
+		      > <a href="#" title="TypeFamilies"
+		      >&lt;&gt;</a
+		      > '<a href="#" title="TypeFamilies"
+		      >XX</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:if:-60--62-:-60--62-:1"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>TypeFamilies</a
+			></p
+		      > <div class="src"
+		      ><span class="keyword"
+			>type</span
+			> '<a href="#" title="TypeFamilies"
+			>XXX</a
+			> <a href="#" title="TypeFamilies"
+			>&lt;&gt;</a
+			> '<a href="#" title="TypeFamilies"
+			>XX</a
+			> = '<a href="#" title="TypeFamilies"
+			>X</a
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:if:-60--62-:-60--62-:2"
+		      ></span
+		      > <span class="keyword"
+		      >type</span
+		      > <a href="#" title="TypeFamilies"
+		      >X</a
+		      > <a href="#" title="TypeFamilies"
+		      >&lt;&gt;</a
+		      > (a :: <a href="#" title="Data.Kind"
+		      >Type</a
+		      >)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:if:-60--62-:-60--62-:2"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>TypeFamilies</a
+			></p
+		      > <div class="src"
+		      ><span class="keyword"
+			>type</span
+			> <a href="#" title="TypeFamilies"
+			>X</a
+			> <a href="#" title="TypeFamilies"
+			>&lt;&gt;</a
+			> (a :: <a href="#" title="Data.Kind"
+			>Type</a
+			>) = <a href="#" title="TypeFamilies"
+			>X</a
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:if:-60--62-:-60--62-:3"
+		      ></span
+		      > <span class="keyword"
+		      >type</span
+		      > <a href="#" title="TypeFamilies"
+		      >Y</a
+		      > <a href="#" title="TypeFamilies"
+		      >&lt;&gt;</a
+		      > (a :: <a href="#" title="Data.Kind"
+		      >Type</a
+		      >)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:if:-60--62-:-60--62-:3"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>TypeFamilies</a
+			></p
+		      > <div class="src"
+		      ><span class="keyword"
+			>type</span
+			> <a href="#" title="TypeFamilies"
+			>Y</a
+			> <a href="#" title="TypeFamilies"
+			>&lt;&gt;</a
+			> (a :: <a href="#" title="Data.Kind"
+			>Type</a
+			>) = a</div
+		      ></details
+		    ></td
+		  ></tr
+		></table
+	      ></details
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >class</span
+	    > (a :: k) <a id="t:-62--60-" class="def"
+	    >&gt;&lt;</a
+	    > (b :: k) <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs instances"
+	  ><h4 class="instances details-toggle-control details-toggle" data-details-id="i:-62--60-"
+	    >Instances</h4
+	    ><details id="i:-62--60-" open="open"
+	    ><summary class="hide-when-js-enabled"
+	      >Instances details</summary
+	      ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:ic:-62--60-:-62--60-:1"
+		      ></span
+		      > '<a href="#" title="TypeFamilies"
+		      >XX</a
+		      > <a href="#" title="TypeFamilies"
+		      >&gt;&lt;</a
+		      > '<a href="#" title="TypeFamilies"
+		      >XXX</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:ic:-62--60-:-62--60-:1"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>TypeFamilies</a
+			></p
+		      ></details
+		    ></td
+		  ></tr
+		></table
+	      ></details
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/TypeFamilies2.html b/html-test/ref/TypeFamilies2.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/TypeFamilies2.html
@@ -0,0 +1,400 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >TypeFamilies2</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>TypeFamilies2</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > <a href="#"
+	      >W</a
+	      ></li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >type family</span
+	      > <a href="#"
+	      >Foo</a
+	      > a</li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >data family</span
+	      > <a href="#"
+	      >Bar</a
+	      > a</li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:W" class="def"
+	    >W</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Exported type</p
+	    ></div
+	  ><div class="subs instances"
+	  ><h4 class="instances details-toggle-control details-toggle" data-details-id="i:W"
+	    >Instances</h4
+	    ><details id="i:W" open="open"
+	    ><summary class="hide-when-js-enabled"
+	      >Instances details</summary
+	      ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:W:Bar:1"
+		      ></span
+		      > <span class="keyword"
+		      >data</span
+		      > <a href="#" title="TypeFamilies2"
+		      >Bar</a
+		      > <a href="#" title="TypeFamilies2"
+		      >W</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    >Shown because BarX is still exported despite Z being hidden</p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:W:Bar:1"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>TypeFamilies2</a
+			></p
+		      > <div class="src"
+		      ><span class="keyword"
+			>data</span
+			> <a href="#" title="TypeFamilies2"
+			>Bar</a
+			> <a href="#" title="TypeFamilies2"
+			>W</a
+			> = <a id="v:BarX" class="def"
+			>BarX</a
+			> Z</div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:id:W:Foo:2"
+		      ></span
+		      > <span class="keyword"
+		      >type</span
+		      > <a href="#" title="TypeFamilies2"
+		      >Foo</a
+		      > <a href="#" title="TypeFamilies2"
+		      >W</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    >Should be visible, but with a hidden right hand side</p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:id:W:Foo:2"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>TypeFamilies2</a
+			></p
+		      > <div class="src"
+		      ><span class="keyword"
+			>type</span
+			> <a href="#" title="TypeFamilies2"
+			>Foo</a
+			> <a href="#" title="TypeFamilies2"
+			>W</a
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		></table
+	      ></details
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >type family</span
+	    > <a id="t:Foo" class="def"
+	    >Foo</a
+	    > a <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Exported type family</p
+	    ></div
+	  ><div class="subs instances"
+	  ><h4 class="instances details-toggle-control details-toggle" data-details-id="i:Foo"
+	    >Instances</h4
+	    ><details id="i:Foo" open="open"
+	    ><summary class="hide-when-js-enabled"
+	      >Instances details</summary
+	      ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:if:Foo:Foo:1"
+		      ></span
+		      > <span class="keyword"
+		      >type</span
+		      > <a href="#" title="TypeFamilies2"
+		      >Foo</a
+		      > <a href="#" title="TypeFamilies"
+		      >X</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    >External instance</p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:if:Foo:Foo:1"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>TypeFamilies</a
+			></p
+		      > <div class="src"
+		      ><span class="keyword"
+			>type</span
+			> <a href="#" title="TypeFamilies2"
+			>Foo</a
+			> <a href="#" title="TypeFamilies"
+			>X</a
+			> = <a href="#" title="TypeFamilies"
+			>Y</a
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:if:Foo:Foo:2"
+		      ></span
+		      > <span class="keyword"
+		      >type</span
+		      > <a href="#" title="TypeFamilies2"
+		      >Foo</a
+		      > <a href="#" title="TypeFamilies2"
+		      >W</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    >Should be visible, but with a hidden right hand side</p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:if:Foo:Foo:2"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>TypeFamilies2</a
+			></p
+		      > <div class="src"
+		      ><span class="keyword"
+			>type</span
+			> <a href="#" title="TypeFamilies2"
+			>Foo</a
+			> <a href="#" title="TypeFamilies2"
+			>W</a
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		></table
+	      ></details
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data family</span
+	    > <a id="t:Bar" class="def"
+	    >Bar</a
+	    > a <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Exported data family</p
+	    ></div
+	  ><div class="subs instances"
+	  ><h4 class="instances details-toggle-control details-toggle" data-details-id="i:Bar"
+	    >Instances</h4
+	    ><details id="i:Bar" open="open"
+	    ><summary class="hide-when-js-enabled"
+	      >Instances details</summary
+	      ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:if:Bar:Bar:1"
+		      ></span
+		      > <span class="keyword"
+		      >data</span
+		      > <a href="#" title="TypeFamilies2"
+		      >Bar</a
+		      > <a href="#" title="TypeFamilies"
+		      >Y</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:if:Bar:Bar:1"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>TypeFamilies</a
+			></p
+		      > <div class="src"
+		      ><span class="keyword"
+			>data</span
+			> <a href="#" title="TypeFamilies2"
+			>Bar</a
+			> <a href="#" title="TypeFamilies"
+			>Y</a
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:if:Bar:Bar:2"
+		      ></span
+		      > <span class="keyword"
+		      >data</span
+		      > <a href="#" title="TypeFamilies2"
+		      >Bar</a
+		      > <a href="#" title="TypeFamilies2"
+		      >W</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc"
+		  ><p
+		    >Shown because BarX is still exported despite Z being hidden</p
+		    ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:if:Bar:Bar:2"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>TypeFamilies2</a
+			></p
+		      > <div class="src"
+		      ><span class="keyword"
+			>data</span
+			> <a href="#" title="TypeFamilies2"
+			>Bar</a
+			> <a href="#" title="TypeFamilies2"
+			>W</a
+			> = <a id="v:BarX" class="def"
+			>BarX</a
+			> Z</div
+		      ></details
+		    ></td
+		  ></tr
+		></table
+	      ></details
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/TypeFamilies3.html b/html-test/ref/TypeFamilies3.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/TypeFamilies3.html
@@ -0,0 +1,368 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >TypeFamilies3</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>TypeFamilies3</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><span class="keyword"
+	      >type family</span
+	      > <a href="#"
+	      >Foo</a
+	      > a <span class="keyword"
+	      >where ...</span
+	      ></li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >type family</span
+	      > <a href="#"
+	      >Bar</a
+	      > a</li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >data family</span
+	      > <a href="#"
+	      >Baz</a
+	      > a</li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >type family</span
+	    > <a id="t:Foo" class="def"
+	    >Foo</a
+	    > a <span class="keyword"
+	    >where ...</span
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >A closed type family</p
+	    ></div
+	  ><div class="subs equations"
+	  ><p class="caption"
+	    >Equations</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a href="#" title="TypeFamilies3"
+		  >Foo</a
+		  > () = <a href="#" title="Data.Int"
+		  >Int</a
+		  ></td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ><tr
+	      ><td class="src"
+		><a href="#" title="TypeFamilies3"
+		  >Foo</a
+		  > _ = ()</td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >type family</span
+	    > <a id="t:Bar" class="def"
+	    >Bar</a
+	    > a <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >An open family</p
+	    ></div
+	  ><div class="subs instances"
+	  ><h4 class="instances details-toggle-control details-toggle" data-details-id="i:Bar"
+	    >Instances</h4
+	    ><details id="i:Bar" open="open"
+	    ><summary class="hide-when-js-enabled"
+	      >Instances details</summary
+	      ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:if:Bar:Bar:1"
+		      ></span
+		      > <span class="keyword"
+		      >type</span
+		      > <a href="#" title="TypeFamilies3"
+		      >Bar</a
+		      > ()</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:if:Bar:Bar:1"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>TypeFamilies3</a
+			></p
+		      > <div class="src"
+		      ><span class="keyword"
+			>type</span
+			> <a href="#" title="TypeFamilies3"
+			>Bar</a
+			> () = <a href="#" title="Data.Int"
+			>Int</a
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:if:Bar:Bar:2"
+		      ></span
+		      > <span class="keyword"
+		      >type</span
+		      > <a href="#" title="TypeFamilies3"
+		      >Bar</a
+		      > <a href="#" title="Data.Int"
+		      >Int</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:if:Bar:Bar:2"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>TypeFamilies3</a
+			></p
+		      > <div class="src"
+		      ><span class="keyword"
+			>type</span
+			> <a href="#" title="TypeFamilies3"
+			>Bar</a
+			> <a href="#" title="Data.Int"
+			>Int</a
+			> = ()</div
+		      ></details
+		    ></td
+		  ></tr
+		></table
+	      ></details
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data family</span
+	    > <a id="t:Baz" class="def"
+	    >Baz</a
+	    > a <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >A data family</p
+	    ></div
+	  ><div class="subs instances"
+	  ><h4 class="instances details-toggle-control details-toggle" data-details-id="i:Baz"
+	    >Instances</h4
+	    ><details id="i:Baz" open="open"
+	    ><summary class="hide-when-js-enabled"
+	      >Instances details</summary
+	      ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:if:Baz:Baz:1"
+		      ></span
+		      > <span class="keyword"
+		      >data</span
+		      > <a href="#" title="TypeFamilies3"
+		      >Baz</a
+		      > ()</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:if:Baz:Baz:1"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>TypeFamilies3</a
+			></p
+		      > <div class="src"
+		      ><span class="keyword"
+			>data</span
+			> <a href="#" title="TypeFamilies3"
+			>Baz</a
+			> () = <a id="v:Baz1" class="def"
+			>Baz1</a
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:if:Baz:Baz:2"
+		      ></span
+		      > <span class="keyword"
+		      >newtype</span
+		      > <a href="#" title="TypeFamilies3"
+		      >Baz</a
+		      > <a href="#" title="Prelude"
+		      >Double</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:if:Baz:Baz:2"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>TypeFamilies3</a
+			></p
+		      > <div class="src"
+		      ><span class="keyword"
+			>newtype</span
+			> <a href="#" title="TypeFamilies3"
+			>Baz</a
+			> <a href="#" title="Prelude"
+			>Double</a
+			> = <a id="v:Baz3" class="def"
+			>Baz3</a
+			> <a href="#" title="Prelude"
+			>Float</a
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span class="instance details-toggle-control details-toggle" data-details-id="i:if:Baz:Baz:3"
+		      ></span
+		      > <span class="keyword"
+		      >data</span
+		      > <a href="#" title="TypeFamilies3"
+		      >Baz</a
+		      > <a href="#" title="Data.Int"
+		      >Int</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  >&nbsp;</td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><details id="i:if:Baz:Baz:3"
+		    ><summary class="hide-when-js-enabled"
+		      >Instance details</summary
+		      ><p
+		      >Defined in <a href="#"
+			>TypeFamilies3</a
+			></p
+		      > <div class="src"
+		      ><span class="keyword"
+			>data</span
+			> <a href="#" title="TypeFamilies3"
+			>Baz</a
+			> <a href="#" title="Data.Int"
+			>Int</a
+			> = <a id="v:Baz2" class="def"
+			>Baz2</a
+			> <a href="#" title="Data.Bool"
+			>Bool</a
+			></div
+		      ></details
+		    ></td
+		  ></tr
+		></table
+	      ></details
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/TypeOperators.html b/html-test/ref/TypeOperators.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/TypeOperators.html
@@ -0,0 +1,200 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >TypeOperators</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>TypeOperators</p
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > a <a id="t::-45-:" class="def"
+	    >:-:</a
+	    > b <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > (a <a id="t::-43-:" class="def"
+	    >:+:</a
+	    > b) c <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:Op" class="def"
+	    >Op</a
+	    > a b <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >newtype</span
+	    > <a id="t:O" class="def"
+	    >O</a
+	    > g f a <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs constructors"
+	  ><p class="caption"
+	    >Constructors</p
+	    ><table
+	    ><tr
+	      ><td class="src"
+		><a id="v:O" class="def"
+		  >O</a
+		  ></td
+		><td class="doc empty"
+		>&nbsp;</td
+		></tr
+	      ><tr
+	      ><td colspan="2"
+		><div class="subs fields"
+		  ><p class="caption"
+		    >Fields</p
+		    ><ul
+		    ><li
+		      ><dfn class="src"
+			><a id="v:unO" class="def"
+			  >unO</a
+			  > :: g (f a)</dfn
+			><div class="doc empty"
+			>&nbsp;</div
+			></li
+		      ></ul
+		    ></div
+		  ></td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >class</span
+	    > a <a id="t:-60--61--62-" class="def"
+	    >&lt;=&gt;</a
+	    > b <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:biO" class="def"
+	    >biO</a
+	    > :: (g <a href="#" title="TypeOperators"
+	    >`O`</a
+	    > f) a <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:f" class="def"
+	    >f</a
+	    > :: a <a href="#" title="Data.Type.Equality"
+	    >~</a
+	    > b =&gt; a -&gt; b <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:g" class="def"
+	    >g</a
+	    > :: (a <a href="#" title="Data.Type.Equality"
+	    >~</a
+	    > b, b <a href="#" title="Data.Type.Equality"
+	    >~</a
+	    > c) =&gt; a -&gt; c <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:x" class="def"
+	    >x</a
+	    > :: (a <a href="#" title="TypeOperators"
+	    >:-:</a
+	    > a) <a href="#" title="TypeOperators"
+	    >&lt;=&gt;</a
+	    > (a <a href="#" title="TypeOperators"
+	    >`Op`</a
+	    > a) =&gt; a <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:y" class="def"
+	    >y</a
+	    > :: (a <a href="#" title="TypeOperators"
+	    >&lt;=&gt;</a
+	    > a, (a <a href="#" title="TypeOperators"
+	    >`Op`</a
+	    > a) <a href="#" title="TypeOperators"
+	    >&lt;=&gt;</a
+	    > a) =&gt; a <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/UnboxedStuff.html b/html-test/ref/UnboxedStuff.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/UnboxedStuff.html
@@ -0,0 +1,206 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >UnboxedStuff</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>UnboxedStuff</p
+	></div
+      ><div id="table-of-contents"
+      ><div id="contents-list"
+	><p class="caption" onclick="window.scrollTo(0,0)"
+	  >Contents</p
+	  ><ul
+	  ><li
+	    ><a href="#"
+	      >Unboxed type constructors</a
+	      ></li
+	    ></ul
+	  ></div
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > <a href="#"
+	      >X</a
+	      ></li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > <a href="#"
+	      >Y</a
+	      ></li
+	    ><li class="src short"
+	    ><span class="keyword"
+	      >data</span
+	      > <a href="#"
+	      >Z</a
+	      ></li
+	    ><li class="src short"
+	    ><a href="#"
+	      >unboxedUnit</a
+	      > :: (# #) -&gt; (# #)</li
+	    ><li class="src short"
+	    ><a href="#"
+	      >unboxedTuple</a
+	      > :: (# <a href="#" title="UnboxedStuff"
+	      >X</a
+	      >, <a href="#" title="UnboxedStuff"
+	      >Y</a
+	      > #) -&gt; (# <a href="#" title="UnboxedStuff"
+	      >X</a
+	      >, <a href="#" title="UnboxedStuff"
+	      >Y</a
+	      >, <a href="#" title="UnboxedStuff"
+	      >Z</a
+	      > #)</li
+	    ><li class="src short"
+	    ><a href="#"
+	      >unboxedSum</a
+	      > :: (# <a href="#" title="UnboxedStuff"
+	      >X</a
+	      > |  <a href="#" title="UnboxedStuff"
+	      >Y</a
+	      > #) -&gt; (# <a href="#" title="UnboxedStuff"
+	      >X</a
+	      > |  <a href="#" title="UnboxedStuff"
+	      >Y</a
+	      > |  <a href="#" title="UnboxedStuff"
+	      >Z</a
+	      > #)</li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:X" class="def"
+	    >X</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:Y" class="def"
+	    >Y</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:Z" class="def"
+	    >Z</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	><a href="#" id="g:1"
+	><h1
+	  >Unboxed type constructors</h1
+	  ></a
+	><div class="top"
+	><p class="src"
+	  ><a id="v:unboxedUnit" class="def"
+	    >unboxedUnit</a
+	    > :: (# #) -&gt; (# #) <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:unboxedTuple" class="def"
+	    >unboxedTuple</a
+	    > :: (# <a href="#" title="UnboxedStuff"
+	    >X</a
+	    >, <a href="#" title="UnboxedStuff"
+	    >Y</a
+	    > #) -&gt; (# <a href="#" title="UnboxedStuff"
+	    >X</a
+	    >, <a href="#" title="UnboxedStuff"
+	    >Y</a
+	    >, <a href="#" title="UnboxedStuff"
+	    >Z</a
+	    > #) <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><a id="v:unboxedSum" class="def"
+	    >unboxedSum</a
+	    > :: (# <a href="#" title="UnboxedStuff"
+	    >X</a
+	    > |  <a href="#" title="UnboxedStuff"
+	    >Y</a
+	    > #) -&gt; (# <a href="#" title="UnboxedStuff"
+	    >X</a
+	    > |  <a href="#" title="UnboxedStuff"
+	    >Y</a
+	    > |  <a href="#" title="UnboxedStuff"
+	    >Z</a
+	    > #) <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Unicode.html b/html-test/ref/Unicode.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Unicode.html
@@ -0,0 +1,86 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Unicode</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Unicode</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><a href="#"
+	      >x</a
+	      > :: <a href="#" title="Data.Int"
+	      >Int</a
+	      ></li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><a id="v:x" class="def"
+	    >x</a
+	    > :: <a href="#" title="Data.Int"
+	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >&#947;&#955;&#974;&#963;&#963;&#945;</p
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Unicode2.html b/html-test/ref/Unicode2.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Unicode2.html
@@ -0,0 +1,108 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Unicode2</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Unicode2</p
+	></div
+      ><div id="synopsis"
+      ><details id="syn"
+	><summary
+	  >Synopsis</summary
+	  ><ul class="details-toggle" data-details-id="syn"
+	  ><li class="src short"
+	    ><a href="#"
+	      >&#252;</a
+	      > :: ()</li
+	    ></ul
+	  ></details
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><a id="v:-252-" class="def"
+	    >&#252;</a
+	    > :: () <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >All of the following work with a unicode character &#252;:</p
+	    ><ul
+	    ><li
+	      >an italicized <em
+		>&#252;</em
+		></li
+	      ><li
+	      >inline code <code
+		>&#252;</code
+		></li
+	      ><li
+	      >a code block:</li
+	      ></ul
+	    ><pre
+	    >&#252;</pre
+	    ><ul
+	    ><li
+	      >a url <a href="#"
+		>https://www.google.com/search?q=&#252;</a
+		></li
+	      ><li
+	      >a link to <code
+		><a href="#" title="Unicode2"
+		  >&#252;</a
+		  ></code
+		></li
+	      ></ul
+	    ></div
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Visible.html b/html-test/ref/Visible.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/Visible.html
@@ -0,0 +1,70 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><meta name="viewport" content="width=device-width, initial-scale=1"
+     /><title
+    >Visible</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Linuwial"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><link rel="stylesheet" type="text/css" href="#"
+     /><script src="haddock-bundle.min.js" async="async" type="text/javascript"
+    ></script
+    ><script type="text/x-mathjax-config"
+    >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><span class="caption empty"
+      >&nbsp;</span
+      ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe-Inferred</td
+	    ></tr
+	  ><tr
+	  ><th
+	    >Language</th
+	    ><td
+	    >Haskell2010</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Visible</p
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><a id="v:visible" class="def"
+	    >visible</a
+	    > :: <a href="#" title="Data.Int"
+	    >Int</a
+	    > -&gt; <a href="#" title="Data.Int"
+	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_A.html b/html-test/ref/mini_A.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_A.html
@@ -0,0 +1,61 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >A</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >A</p
+      ></div
+    ><div id="interface"
+    ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >data</span
+	  > <a href="" target="main"
+	  >A</a
+	  ></p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >other</a
+	  ></p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >test2</a
+	  ></p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >data</span
+	  > <a href="" target="main"
+	  >X</a
+	  ></p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >reExport</a
+	  ></p
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_AdvanceTypes.html b/html-test/ref/mini_AdvanceTypes.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_AdvanceTypes.html
@@ -0,0 +1,35 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >AdvanceTypes</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >AdvanceTypes</p
+      ></div
+    ><div id="interface"
+    ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >data</span
+	  > <a href="" target="main"
+	  >Pattern</a
+	  ></p
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_B.html b/html-test/ref/mini_B.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_B.html
@@ -0,0 +1,47 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >B</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >B</p
+      ></div
+    ><div id="interface"
+    ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >test</a
+	  ></p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >reExport</a
+	  ></p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >data</span
+	  > <a href="" target="main"
+	  >X</a
+	  ></p
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_Bug1.html b/html-test/ref/mini_Bug1.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_Bug1.html
@@ -0,0 +1,35 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >Bug1</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >Bug1</p
+      ></div
+    ><div id="interface"
+    ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >data</span
+	  > <a href="" target="main"
+	  >T</a
+	  ></p
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_Bug2.html b/html-test/ref/mini_Bug2.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_Bug2.html
@@ -0,0 +1,33 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >Bug2</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >Bug2</p
+      ></div
+    ><div id="interface"
+    ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >x</a
+	  ></p
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_Bug3.html b/html-test/ref/mini_Bug3.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_Bug3.html
@@ -0,0 +1,33 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >Bug3</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >Bug3</p
+      ></div
+    ><div id="interface"
+    ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >foo</a
+	  ></p
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_Bug4.html b/html-test/ref/mini_Bug4.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_Bug4.html
@@ -0,0 +1,33 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >Bug4</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >Bug4</p
+      ></div
+    ><div id="interface"
+    ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >foo</a
+	  ></p
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_Bug6.html b/html-test/ref/mini_Bug6.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_Bug6.html
@@ -0,0 +1,67 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >Bug6</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >Bug6</p
+      ></div
+    ><div id="interface"
+    ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >data</span
+	  > <a href="" target="main"
+	  >A</a
+	  ></p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >data</span
+	  > <a href="" target="main"
+	  >B</a
+	  ></p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >data</span
+	  > <a href="" target="main"
+	  >C</a
+	  ></p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >data</span
+	  > <a href="" target="main"
+	  >D</a
+	  ></p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >data</span
+	  > <a href="" target="main"
+	  >E</a
+	  ></p
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_Bug7.html b/html-test/ref/mini_Bug7.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_Bug7.html
@@ -0,0 +1,43 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >Bug7</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >Bug7</p
+      ></div
+    ><div id="interface"
+    ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >data</span
+	  > <a href="" target="main"
+	  >Foo</a
+	  ></p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >class</span
+	  > <a href="" target="main"
+	  >Bar</a
+	  > x y</p
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_Bug8.html b/html-test/ref/mini_Bug8.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_Bug8.html
@@ -0,0 +1,65 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >Bug8</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >Bug8</p
+      ></div
+    ><div id="interface"
+    ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >data</span
+	  > <a href="" target="main"
+	  >Typ</a
+	  ></p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >(--&gt;)</a
+	  ></p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >(---&gt;)</a
+	  ></p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >s</a
+	  ></p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >t</a
+	  ></p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >main</a
+	  ></p
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_BugDeprecated.html b/html-test/ref/mini_BugDeprecated.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_BugDeprecated.html
@@ -0,0 +1,63 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >BugDeprecated</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >BugDeprecated</p
+      ></div
+    ><div id="interface"
+    ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >foo</a
+	  ></p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >bar</a
+	  ></p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >baz</a
+	  ></p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >one</a
+	  ></p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >two</a
+	  ></p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >three</a
+	  ></p
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_BugExportHeadings.html b/html-test/ref/mini_BugExportHeadings.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_BugExportHeadings.html
@@ -0,0 +1,75 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >BugExportHeadings</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >BugExportHeadings</p
+      ></div
+    ><div id="interface"
+    ><h1
+      >Foo</h1
+      ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >foo</a
+	  ></p
+	></div
+      ><h1
+      >Bar</h1
+      ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >bar</a
+	  ></p
+	></div
+      ><h1
+      >Baz</h1
+      ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >baz</a
+	  ></p
+	></div
+      ><h1
+      >One</h1
+      ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >one</a
+	  ></p
+	></div
+      ><h1
+      >Two</h1
+      ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >two</a
+	  ></p
+	></div
+      ><h1
+      >Three</h1
+      ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >three</a
+	  ></p
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_Bugs.html b/html-test/ref/mini_Bugs.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_Bugs.html
@@ -0,0 +1,35 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >Bugs</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >Bugs</p
+      ></div
+    ><div id="interface"
+    ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >data</span
+	  > <a href="" target="main"
+	  >A</a
+	  > a</p
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_CrossPackageDocs.html b/html-test/ref/mini_CrossPackageDocs.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_CrossPackageDocs.html
@@ -0,0 +1,45 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >CrossPackageDocs</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >CrossPackageDocs</p
+      ></div
+    ><div id="interface"
+    ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >map</a
+	  ></p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >class</span
+	  > <a href="" target="main"
+	  >IsString</a
+	  > a</p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >runInteractiveProcess</a
+	  ></p
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_DeprecatedClass.html b/html-test/ref/mini_DeprecatedClass.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_DeprecatedClass.html
@@ -0,0 +1,43 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >DeprecatedClass</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >DeprecatedClass</p
+      ></div
+    ><div id="interface"
+    ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >class</span
+	  > <a href="" target="main"
+	  >SomeClass</a
+	  > a</p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >class</span
+	  > <a href="" target="main"
+	  >SomeOtherClass</a
+	  > a</p
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_DeprecatedData.html b/html-test/ref/mini_DeprecatedData.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_DeprecatedData.html
@@ -0,0 +1,43 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >DeprecatedData</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >DeprecatedData</p
+      ></div
+    ><div id="interface"
+    ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >data</span
+	  > <a href="" target="main"
+	  >Foo</a
+	  ></p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >data</span
+	  > <a href="" target="main"
+	  >One</a
+	  ></p
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_DeprecatedFunction.html b/html-test/ref/mini_DeprecatedFunction.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_DeprecatedFunction.html
@@ -0,0 +1,39 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >DeprecatedFunction</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >DeprecatedFunction</p
+      ></div
+    ><div id="interface"
+    ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >foo</a
+	  ></p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >bar</a
+	  ></p
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_DeprecatedFunction2.html b/html-test/ref/mini_DeprecatedFunction2.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_DeprecatedFunction2.html
@@ -0,0 +1,33 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >DeprecatedFunction2</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >DeprecatedFunction2</p
+      ></div
+    ><div id="interface"
+    ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >foo</a
+	  ></p
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_DeprecatedFunction3.html b/html-test/ref/mini_DeprecatedFunction3.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_DeprecatedFunction3.html
@@ -0,0 +1,33 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >DeprecatedFunction3</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >DeprecatedFunction3</p
+      ></div
+    ><div id="interface"
+    ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >foo</a
+	  ></p
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_DeprecatedModule.html b/html-test/ref/mini_DeprecatedModule.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_DeprecatedModule.html
@@ -0,0 +1,33 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >DeprecatedModule</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >DeprecatedModule</p
+      ></div
+    ><div id="interface"
+    ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >foo</a
+	  ></p
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_DeprecatedModule2.html b/html-test/ref/mini_DeprecatedModule2.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_DeprecatedModule2.html
@@ -0,0 +1,33 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >DeprecatedModule2</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >DeprecatedModule2</p
+      ></div
+    ><div id="interface"
+    ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >foo</a
+	  ></p
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_DeprecatedNewtype.html b/html-test/ref/mini_DeprecatedNewtype.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_DeprecatedNewtype.html
@@ -0,0 +1,43 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >DeprecatedNewtype</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >DeprecatedNewtype</p
+      ></div
+    ><div id="interface"
+    ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >data</span
+	  > <a href="" target="main"
+	  >SomeNewType</a
+	  ></p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >data</span
+	  > <a href="" target="main"
+	  >SomeOtherNewType</a
+	  ></p
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_DeprecatedReExport.html b/html-test/ref/mini_DeprecatedReExport.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_DeprecatedReExport.html
@@ -0,0 +1,37 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >DeprecatedReExport</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >DeprecatedReExport</p
+      ></div
+    ><div id="interface"
+    ><h1
+      >Re-exported from an other module</h1
+      ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >foo</a
+	  ></p
+	></div
+      ><h1
+      >Re-exported from an other package</h1
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_DeprecatedRecord.html b/html-test/ref/mini_DeprecatedRecord.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_DeprecatedRecord.html
@@ -0,0 +1,35 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >DeprecatedRecord</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >DeprecatedRecord</p
+      ></div
+    ><div id="interface"
+    ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >data</span
+	  > <a href="" target="main"
+	  >Foo</a
+	  ></p
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_DeprecatedTypeFamily.html b/html-test/ref/mini_DeprecatedTypeFamily.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_DeprecatedTypeFamily.html
@@ -0,0 +1,43 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >DeprecatedTypeFamily</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >DeprecatedTypeFamily</p
+      ></div
+    ><div id="interface"
+    ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >data family</span
+	  > <a href=""
+	  >SomeTypeFamily</a
+	  > k :: * -&gt; *</p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >data family</span
+	  > <a href=""
+	  >SomeOtherTypeFamily</a
+	  > k :: * -&gt; *</p
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_DeprecatedTypeSynonym.html b/html-test/ref/mini_DeprecatedTypeSynonym.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_DeprecatedTypeSynonym.html
@@ -0,0 +1,43 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >DeprecatedTypeSynonym</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >DeprecatedTypeSynonym</p
+      ></div
+    ><div id="interface"
+    ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >type</span
+	  > <a href="" target="main"
+	  >TypeSyn</a
+	  ></p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >type</span
+	  > <a href="" target="main"
+	  >OtherTypeSyn</a
+	  ></p
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_Examples.html b/html-test/ref/mini_Examples.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_Examples.html
@@ -0,0 +1,33 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >Examples</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >Examples</p
+      ></div
+    ><div id="interface"
+    ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >fib</a
+	  ></p
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_FunArgs.html b/html-test/ref/mini_FunArgs.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_FunArgs.html
@@ -0,0 +1,57 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >FunArgs</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >FunArgs</p
+      ></div
+    ><div id="interface"
+    ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >f</a
+	  ></p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >g</a
+	  ></p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >h</a
+	  ></p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >i</a
+	  ></p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >j</a
+	  ></p
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_GADTRecords.html b/html-test/ref/mini_GADTRecords.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_GADTRecords.html
@@ -0,0 +1,35 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >GADTRecords</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >GADTRecords</p
+      ></div
+    ><div id="interface"
+    ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >data</span
+	  > <a href="" target="main"
+	  >H1</a
+	  > a b</p
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_Hash.html b/html-test/ref/mini_Hash.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_Hash.html
@@ -0,0 +1,73 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >Hash</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >Hash</p
+      ></div
+    ><div id="interface"
+    ><h1
+      >The <code
+	>HashTable</code
+	> type</h1
+      ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >data</span
+	  > <a href="" target="main"
+	  >HashTable</a
+	  > key val</p
+	></div
+      ><h2
+      >Operations on <code
+	>HashTable</code
+	>s</h2
+      ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >new</a
+	  ></p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >insert</a
+	  ></p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >lookup</a
+	  ></p
+	></div
+      ><h1
+      >The <code
+	>Hash</code
+	> class</h1
+      ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >class</span
+	  > <a href="" target="main"
+	  >Hash</a
+	  > a</p
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_HiddenInstances.html b/html-test/ref/mini_HiddenInstances.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_HiddenInstances.html
@@ -0,0 +1,43 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >HiddenInstances</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >HiddenInstances</p
+      ></div
+    ><div id="interface"
+    ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >class</span
+	  > <a href="" target="main"
+	  >VisibleClass</a
+	  > a</p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >data</span
+	  > <a href="" target="main"
+	  >VisibleData</a
+	  ></p
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_HiddenInstancesB.html b/html-test/ref/mini_HiddenInstancesB.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_HiddenInstancesB.html
@@ -0,0 +1,43 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >HiddenInstancesB</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >HiddenInstancesB</p
+      ></div
+    ><div id="interface"
+    ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >class</span
+	  > <a href="" target="main"
+	  >Foo</a
+	  > a</p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >data</span
+	  > <a href="" target="main"
+	  >Bar</a
+	  ></p
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_Hyperlinks.html b/html-test/ref/mini_Hyperlinks.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_Hyperlinks.html
@@ -0,0 +1,33 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >Hyperlinks</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >Hyperlinks</p
+      ></div
+    ><div id="interface"
+    ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >foo</a
+	  ></p
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_IgnoreExports.html b/html-test/ref/mini_IgnoreExports.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_IgnoreExports.html
@@ -0,0 +1,39 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >IgnoreExports</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >IgnoreExports</p
+      ></div
+    ><div id="interface"
+    ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >foo</a
+	  ></p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >bar</a
+	  ></p
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_Math.html b/html-test/ref/mini_Math.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_Math.html
@@ -0,0 +1,33 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >Math</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >Math</p
+      ></div
+    ><div id="interface"
+    ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >f</a
+	  ></p
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_ModuleWithWarning.html b/html-test/ref/mini_ModuleWithWarning.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_ModuleWithWarning.html
@@ -0,0 +1,33 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >ModuleWithWarning</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >ModuleWithWarning</p
+      ></div
+    ><div id="interface"
+    ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >foo</a
+	  ></p
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_NamedDoc.html b/html-test/ref/mini_NamedDoc.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_NamedDoc.html
@@ -0,0 +1,27 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >NamedDoc</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >NamedDoc</p
+      ></div
+    ><div id="interface"
+    ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_NoLayout.html b/html-test/ref/mini_NoLayout.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_NoLayout.html
@@ -0,0 +1,33 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >NoLayout</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >NoLayout</p
+      ></div
+    ><div id="interface"
+    ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >g</a
+	  ></p
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_NonGreedy.html b/html-test/ref/mini_NonGreedy.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_NonGreedy.html
@@ -0,0 +1,33 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >NonGreedy</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >NonGreedy</p
+      ></div
+    ><div id="interface"
+    ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >f</a
+	  ></p
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_Properties.html b/html-test/ref/mini_Properties.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_Properties.html
@@ -0,0 +1,33 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >Properties</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >Properties</p
+      ></div
+    ><div id="interface"
+    ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >fib</a
+	  ></p
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_PruneWithWarning.html b/html-test/ref/mini_PruneWithWarning.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_PruneWithWarning.html
@@ -0,0 +1,27 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >PruneWithWarning</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >PruneWithWarning</p
+      ></div
+    ><div id="interface"
+    ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_QuasiExpr.html b/html-test/ref/mini_QuasiExpr.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_QuasiExpr.html
@@ -0,0 +1,61 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >QuasiExpr</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >QuasiExpr</p
+      ></div
+    ><div id="interface"
+    ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >data</span
+	  > <a href="" target="main"
+	  >Expr</a
+	  ></p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >data</span
+	  > <a href="" target="main"
+	  >BinOp</a
+	  ></p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >eval</a
+	  ></p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >expr</a
+	  ></p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >parseExprExp</a
+	  ></p
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_QuasiQuote.html b/html-test/ref/mini_QuasiQuote.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_QuasiQuote.html
@@ -0,0 +1,33 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >QuasiQuote</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >QuasiQuote</p
+      ></div
+    ><div id="interface"
+    ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >val</a
+	  ></p
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_SpuriousSuperclassConstraints.html b/html-test/ref/mini_SpuriousSuperclassConstraints.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_SpuriousSuperclassConstraints.html
@@ -0,0 +1,35 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >SpuriousSuperclassConstraints</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >SpuriousSuperclassConstraints</p
+      ></div
+    ><div id="interface"
+    ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >data</span
+	  > <a href="" target="main"
+	  >SomeType</a
+	  > f a</p
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_TH.html b/html-test/ref/mini_TH.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_TH.html
@@ -0,0 +1,33 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >TH</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >TH</p
+      ></div
+    ><div id="interface"
+    ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >decl</a
+	  ></p
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_TH2.html b/html-test/ref/mini_TH2.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_TH2.html
@@ -0,0 +1,33 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >TH2</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >TH2</p
+      ></div
+    ><div id="interface"
+    ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >f</a
+	  ></p
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_Test.html b/html-test/ref/mini_Test.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_Test.html
@@ -0,0 +1,259 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >Test</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >Test</p
+      ></div
+    ><div id="interface"
+    ><h1
+      >Type declarations</h1
+      ><h2
+      >Data types</h2
+      ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >data</span
+	  > <a href="" target="main"
+	  >T</a
+	  > a b</p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >data</span
+	  > <a href="" target="main"
+	  >T2</a
+	  > a b</p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >data</span
+	  > <a href="" target="main"
+	  >T3</a
+	  > a b</p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >data</span
+	  > <a href="" target="main"
+	  >T4</a
+	  > a b</p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >data</span
+	  > <a href="" target="main"
+	  >T5</a
+	  > a b</p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >data</span
+	  > <a href="" target="main"
+	  >T6</a
+	  ></p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >data</span
+	  > <a href="" target="main"
+	  >N1</a
+	  > a</p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >data</span
+	  > <a href="" target="main"
+	  >N2</a
+	  > a b</p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >data</span
+	  > <a href="" target="main"
+	  >N3</a
+	  > a b</p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >data</span
+	  > <a href="" target="main"
+	  >N4</a
+	  > a b</p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >data</span
+	  > <a href="" target="main"
+	  >N5</a
+	  > a b</p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >data</span
+	  > <a href="" target="main"
+	  >N6</a
+	  > a b</p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >data</span
+	  > <a href="" target="main"
+	  >N7</a
+	  > a b</p
+	></div
+      ><h2
+      >Records</h2
+      ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >data</span
+	  > <a href="" target="main"
+	  >R</a
+	  ></p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >data</span
+	  > <a href="" target="main"
+	  >R1</a
+	  ></p
+	></div
+      ><h1
+      >Class declarations</h1
+      ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >class</span
+	  > <a href="" target="main"
+	  >C</a
+	  > a</p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >class</span
+	  > <a href="" target="main"
+	  >D</a
+	  > a</p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >class</span
+	  > <a href="" target="main"
+	  >E</a
+	  > a</p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >class</span
+	  > <a href="" target="main"
+	  >F</a
+	  > a</p
+	></div
+      ><h1
+      >Function types</h1
+      ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >f</a
+	  ></p
+	></div
+      ><h1
+      >Auxiliary stuff</h1
+      ><h1
+      >A hidden module</h1
+      ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >hidden</a
+	  ></p
+	></div
+      ><h1
+      >A visible module</h1
+      ><h1
+      >Existential / Universal types</h1
+      ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >data</span
+	  > <a href="" target="main"
+	  >Ex</a
+	  > a</p
+	></div
+      ><h1
+      >Type signatures with argument docs</h1
+      ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >k</a
+	  ></p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >l</a
+	  ></p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >m</a
+	  ></p
+	></div
+      ><h1
+      >A section</h1
+      ><h2
+      >A subsection</h2
+      ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >f'</a
+	  ></p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >withType</a
+	  ></p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >withoutType</a
+	  ></p
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_Ticket112.html b/html-test/ref/mini_Ticket112.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_Ticket112.html
@@ -0,0 +1,33 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >Ticket112</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >Ticket112</p
+      ></div
+    ><div id="interface"
+    ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >f</a
+	  ></p
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_Ticket253_1.html b/html-test/ref/mini_Ticket253_1.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_Ticket253_1.html
@@ -0,0 +1,31 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >Ticket253_1</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >Ticket253_1</p
+      ></div
+    ><div id="interface"
+    ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >foo</a
+	  ></p
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_Ticket253_2.html b/html-test/ref/mini_Ticket253_2.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_Ticket253_2.html
@@ -0,0 +1,39 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >Ticket253_2</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >Ticket253_2</p
+      ></div
+    ><div id="interface"
+    ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >bar</a
+	  ></p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >data</span
+	  > <a href="" target="main"
+	  >Baz</a
+	  ></p
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_Ticket61.html b/html-test/ref/mini_Ticket61.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_Ticket61.html
@@ -0,0 +1,35 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >Ticket61</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >Ticket61</p
+      ></div
+    ><div id="interface"
+    ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >class</span
+	  > <a href="" target="main"
+	  >C</a
+	  > a</p
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_Ticket75.html b/html-test/ref/mini_Ticket75.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_Ticket75.html
@@ -0,0 +1,41 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >Ticket75</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >Ticket75</p
+      ></div
+    ><div id="interface"
+    ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >data</span
+	  > a <a href="" target="main"
+	  >:-</a
+	  > b</p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >f</a
+	  ></p
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_TitledPicture.html b/html-test/ref/mini_TitledPicture.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_TitledPicture.html
@@ -0,0 +1,39 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >TitledPicture</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >TitledPicture</p
+      ></div
+    ><div id="interface"
+    ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >foo</a
+	  ></p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >bar</a
+	  ></p
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_TypeFamilies.html b/html-test/ref/mini_TypeFamilies.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_TypeFamilies.html
@@ -0,0 +1,107 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >TypeFamilies</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >TypeFamilies</p
+      ></div
+    ><div id="interface"
+    ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >data</span
+	  > <a href="" target="main"
+	  >X</a
+	  ></p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >data</span
+	  > <a href="" target="main"
+	  >Y</a
+	  ></p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >data</span
+	  > <a href="" target="main"
+	  >Z</a
+	  ></p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >class</span
+	  > <a href="" target="main"
+	  >Test</a
+	  > a</p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >type family</span
+	  > <a href=""
+	  >Foo</a
+	  > a :: k</p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >data family</span
+	  > <a href=""
+	  >Bat</a
+	  > a :: *</p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >class</span
+	  > <a href="" target="main"
+	  >Assoc</a
+	  > a</p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >type family</span
+	  > <a href=""
+	  >Bar</a
+	  > b</p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >type family</span
+	  > a <a href=""
+	  >&lt;&gt;</a
+	  > b :: k</p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >class</span
+	  > a <a href="" target="main"
+	  >&gt;&lt;</a
+	  > b</p
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_TypeOperators.html b/html-test/ref/mini_TypeOperators.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_TypeOperators.html
@@ -0,0 +1,97 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >TypeOperators</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >TypeOperators</p
+      ></div
+    ><div id="interface"
+    ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >data</span
+	  > a <a href="" target="main"
+	  >:-:</a
+	  > b</p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >data</span
+	  > (a <a href="" target="main"
+	  >:+:</a
+	  > b) c</p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >data</span
+	  > <a href="" target="main"
+	  >Op</a
+	  > a b</p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >data</span
+	  > <a href="" target="main"
+	  >O</a
+	  > g f a</p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><span class="keyword"
+	  >class</span
+	  > a <a href="" target="main"
+	  >&lt;=&gt;</a
+	  > b</p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >biO</a
+	  ></p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >f</a
+	  ></p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >g</a
+	  ></p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >x</a
+	  ></p
+	></div
+      ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >y</a
+	  ></p
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_Unicode.html b/html-test/ref/mini_Unicode.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_Unicode.html
@@ -0,0 +1,33 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >Unicode</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >Unicode</p
+      ></div
+    ><div id="interface"
+    ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >x</a
+	  ></p
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/mini_Visible.html b/html-test/ref/mini_Visible.html
new file mode 100644
--- /dev/null
+++ b/html-test/ref/mini_Visible.html
@@ -0,0 +1,33 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >Visible</title
+    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//<![CDATA[
+window.onload = function () {pageLoad();};
+//]]>
+</script
+    ></head
+  ><body id="mini"
+  ><div id="module-header"
+    ><p class="caption"
+      >Visible</p
+      ></div
+    ><div id="interface"
+    ><div class="top"
+      ><p class="src"
+	><a href="" target="main"
+	  >visible</a
+	  ></p
+	></div
+      ></div
+    ></body
+  ></html
+>
diff --git a/html-test/src/A.hs b/html-test/src/A.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/A.hs
@@ -0,0 +1,18 @@
+{-# LANGUAGE Haskell2010 #-}
+module A where
+
+data A = A
+
+other :: Int
+other = 2
+
+-- | Doc for test2
+test2 :: Bool
+test2 = False
+
+-- | Should show up on the page for both modules A and B
+data X = X -- ^ Doc for consructor
+
+-- | Should show up on the page for both modules A and B
+reExport :: Int
+reExport = 1
diff --git a/html-test/src/B.hs b/html-test/src/B.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/B.hs
@@ -0,0 +1,9 @@
+{-# LANGUAGE Haskell2010 #-}
+module B ( module A, test, reExport, X(..) ) where
+import A ( A(..), test2, reExport, X(..) )
+
+-- | This link shouldn't work: 'other'.
+--   These links should work: 'A.other', 'Data.List.sortBy', 'test2', 'A.test2', 'Data.Maybe.fromMaybe'.
+--   Module link: "Prelude".
+test :: Int
+test = 1
diff --git a/html-test/src/Bold.hs b/html-test/src/Bold.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Bold.hs
@@ -0,0 +1,10 @@
+{-# LANGUAGE Haskell2010 #-}
+module Bold where
+-- | Some __bold text__.
+--
+-- * __Bold__ in a list
+--
+-- [__bold in a definition__] list
+--
+-- @ bold __in__ a __code__ block @
+foo = undefined
diff --git a/html-test/src/Bug1.hs b/html-test/src/Bug1.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Bug1.hs
@@ -0,0 +1,7 @@
+{-# LANGUAGE Haskell2010 #-}
+module Bug1 where
+
+-- | We should have different anchors for constructors and types\/classes.  This
+-- hyperlink should point to the type constructor by default: 'T'.
+data T = T
+
diff --git a/html-test/src/Bug1004.hs b/html-test/src/Bug1004.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Bug1004.hs
@@ -0,0 +1,4 @@
+{-# LANGUAGE Haskell2010 #-}
+module Bug1004 (Product(..)) where
+
+import Data.Functor.Product
diff --git a/html-test/src/Bug1033.hs b/html-test/src/Bug1033.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Bug1033.hs
@@ -0,0 +1,12 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE DeriveGeneric #-}
+{-# LANGUAGE StandaloneDeriving #-}
+
+module Bug1033 where
+
+import GHC.Generics
+
+data Foo = Foo
+
+-- | This does some generic foos.
+deriving instance Generic Foo
diff --git a/html-test/src/Bug1035.hs b/html-test/src/Bug1035.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Bug1035.hs
@@ -0,0 +1,10 @@
+{-# LANGUAGE Haskell2010 #-}
+module Bug1035 where
+
+data Foo = Bar
+
+data Bar = Foo
+
+-- | A link to 'Bar'
+foo :: ()
+foo = ()
diff --git a/html-test/src/Bug1050.hs b/html-test/src/Bug1050.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Bug1050.hs
@@ -0,0 +1,12 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE GADTs #-}
+{-# LANGUAGE PolyKinds #-}
+{-# LANGUAGE RankNTypes #-}
+module Bug1050 where
+
+import Data.Kind
+
+newtype T :: (forall k. k -> Type) -> (forall k. k -> Type) where
+  MkT :: forall (f :: forall k. k -> Type) k (a :: k). f a -> T f a
+
+mkT = MkT
diff --git a/html-test/src/Bug1054.hs b/html-test/src/Bug1054.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Bug1054.hs
@@ -0,0 +1,6 @@
+{-# LANGUAGE Haskell2010 #-}
+module Bug1054 where
+
+-- * Header with 'foo' link
+
+foo = ()
diff --git a/html-test/src/Bug1063.hs b/html-test/src/Bug1063.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Bug1063.hs
@@ -0,0 +1,10 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE ConstraintKinds #-}
+{-# LANGUAGE FlexibleInstances #-}
+{-# LANGUAGE MultiParamTypeClasses #-}
+{-# LANGUAGE QuantifiedConstraints #-}
+{-# LANGUAGE UndecidableInstances #-}
+module Bug1063 where
+
+class    (c => d) => Implies c d
+instance (c => d) => Implies c d
diff --git a/html-test/src/Bug1067A.hs b/html-test/src/Bug1067A.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Bug1067A.hs
@@ -0,0 +1,10 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# language PatternSynonyms #-}
+module Bug1067A ( Foo(P) ) where
+
+-- | A foo
+data Foo = Foo
+
+-- | A pattern
+pattern P :: Foo
+pattern P = Foo
diff --git a/html-test/src/Bug1067B.hs b/html-test/src/Bug1067B.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Bug1067B.hs
@@ -0,0 +1,5 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# language PatternSynonyms #-}
+module Bug1067B ( pattern P ) where
+
+import Bug1067A
diff --git a/html-test/src/Bug1103.hs b/html-test/src/Bug1103.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Bug1103.hs
@@ -0,0 +1,25 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE DataKinds #-}
+{-# LANGUAGE GADTs #-}
+{-# LANGUAGE PolyKinds #-}
+{-# LANGUAGE TypeFamilies #-}
+module Bug1103 where
+
+import Data.Kind
+
+data family   Foo1 :: Type -> Type
+data instance Foo1 Bool = Foo1Bool
+data instance Foo1 (Maybe a)
+
+data family   Foo2 :: k -> Type
+data instance Foo2 Bool = Foo2Bool
+data instance Foo2 (Maybe a)
+data instance Foo2 :: Char -> Type
+data instance Foo2 :: (Char -> Char) -> Type where
+
+data family   Foo3 :: k
+data instance Foo3
+data instance Foo3 Bool = Foo3Bool
+data instance Foo3 (Maybe a)
+data instance Foo3 :: Char -> Type
+data instance Foo3 :: (Char -> Char) -> Type where
diff --git a/html-test/src/Bug195.hs b/html-test/src/Bug195.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Bug195.hs
@@ -0,0 +1,12 @@
+{-# LANGUAGE Haskell2010 #-}
+module Bug195 where
+
+data T = A { someField :: () -- ^ Doc for someField of A
+           , someOtherField :: () -- ^ Doc for someOtherField of A
+           }
+       | B { someField :: () -- ^ Doc for someField of B
+           , someOtherField :: () -- ^ Doc for someOtherField of B
+           }
+       | C { someField :: () -- ^ Doc for someField of C
+           , someOtherField :: () -- ^ Doc for someOtherField of C
+           }
diff --git a/html-test/src/Bug2.hs b/html-test/src/Bug2.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Bug2.hs
@@ -0,0 +1,5 @@
+{-# LANGUAGE Haskell2010 #-}
+module Bug2 ( x ) where
+import B
+x :: A
+x = A
diff --git a/html-test/src/Bug201.hs b/html-test/src/Bug201.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Bug201.hs
@@ -0,0 +1,29 @@
+{-# LANGUAGE Haskell2010 #-}
+-- We test that leading whitespace gets properly dropped (or not!)
+-- from codeblocks
+module Bug201 where
+
+-- |
+-- @
+-- This leading whitespace
+-- should be dropped
+-- @
+f :: ()
+f = ()
+
+{-|
+@
+ But this one
+ should not
+@
+
+> this should
+> be dropped
+
+@
+ and so should this
+ because there's a space before closing @
+ @
+-}
+g :: ()
+g = ()
diff --git a/html-test/src/Bug253.hs b/html-test/src/Bug253.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Bug253.hs
@@ -0,0 +1,11 @@
+{-# LANGUAGE Haskell2010 #-}
+-- | This module tests that if we're trying to link to a /qualified/
+-- identifier that's not in scope, we get an anchor as if it was a
+-- variable. Previous behaviour was to treat it as a type constructor
+-- so issue like #253 arose. Also see @rename@ function comments in
+-- source.
+module Bug253 where
+
+-- | This link should generate @#v@ anchor: 'DoesNotExist.fakeFakeFake'
+foo :: ()
+foo = ()
diff --git a/html-test/src/Bug26.hs b/html-test/src/Bug26.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Bug26.hs
@@ -0,0 +1,30 @@
+{-# LANGUAGE Haskell2010 #-}
+-- | This module tests the ‘@since …’ annotation.
+--
+-- @since 1.2.3
+module Bug26 where
+
+-- | Foo
+--
+-- @since 2.10.7
+--
+-- @since 2.10.8
+f :: ()
+f = ()
+
+-- | Bar
+g :: ()
+g = ()
+
+-- | Class
+--
+-- @since 1.0
+class C a where
+  -- | @since 1.2.3
+  c_f :: a
+
+-- | instance for ()
+--
+-- @since 0.7.8
+instance C () where
+  c_f = ()
diff --git a/html-test/src/Bug280.hs b/html-test/src/Bug280.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Bug280.hs
@@ -0,0 +1,12 @@
+{-# LANGUAGE Haskell2010 #-}
+{-|
+Copyright: Foo,
+           Bar,
+           Baz
+
+The module description
+-}
+-- The module header can start with newlines. They are not taken into account for the indentation level
+module Bug280 where
+
+x = ""
diff --git a/html-test/src/Bug294.hs b/html-test/src/Bug294.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Bug294.hs
@@ -0,0 +1,38 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE TypeFamilies, FlexibleInstances, GADTs #-}
+-- This tests that we are able to extract record selectors for
+-- associated types when the type itself is not exported. Making this
+-- bug exhibit is very simple: simply mention a record field defined
+-- inside of the associated type anywhere in the export list.
+--
+-- Note: ProblemCtor only shows up when T or A are exported but PolyCtor
+-- only shows up when the class is exported as well, since it's polymorphic.
+module Bug294 ( A, problemField, problemField', gadtField
+              , TP(ProblemCtor), DP(ProblemCtor'), TO'(PolyCtor)) where
+
+data A
+
+class T t where
+  data TO t :: *
+  data TP t :: *
+
+  t :: t
+
+instance T A where
+  data TO A = TA { problemField :: A }
+  data TP A = ProblemCtor A
+
+data family DO t :: *
+data family DP t :: *
+
+data instance DO A = DA { problemField' :: A }
+data instance DP A = ProblemCtor' A
+
+data GADT :: * -> * where
+  Ctor :: { gadtField :: A } -> GADT A
+
+class T' t where
+  data TO' t :: *
+
+instance T' a where
+  data TO' a = PolyCtor
diff --git a/html-test/src/Bug298.hs b/html-test/src/Bug298.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Bug298.hs
@@ -0,0 +1,23 @@
+{-# LANGUAGE Haskell2010 #-}
+-- We introduced a regression in 2.14.x where we don't consider
+-- identifiers with ^ as valid. We test that the regression goes away
+-- here. It's a silly typo in the parser, really. Same with ★ which is a valid
+-- symbol according to the 2010 report.
+module Bug298 where
+
+
+(<^>) :: (a -> a) -> a -> a
+x <^> y = x y
+
+(<^) :: a -> a -> a
+x <^ y = x
+
+(^>) :: a -> a -> a
+x ^> y = y
+
+(⋆^) :: a -> a -> a
+x ⋆^ y = y
+
+-- | Links to '<^>' and '^>', '<^' and '⋆^'.
+f :: ()
+f = ()
diff --git a/html-test/src/Bug3.hs b/html-test/src/Bug3.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Bug3.hs
@@ -0,0 +1,7 @@
+{-# LANGUAGE Haskell2010 #-}
+module Bug3 where
+
+-- | /multi-line
+-- emphasis/
+foo :: Int
+foo = undefined
diff --git a/html-test/src/Bug308.hs b/html-test/src/Bug308.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Bug308.hs
@@ -0,0 +1,22 @@
+{-# LANGUAGE Haskell2010 #-}
+-- From 2.14.x onwards we were forgetting to swallow ‘#’ as a special
+-- character resulting in broken anchors if they occurred
+-- mid-paragraph. Here we check that anchors get generated as
+-- expected.
+module Bug308 where
+
+-- | start#startAnchor# followed by middle#middleAnchor# and end#endAnchor#
+f :: ()
+f = ()
+
+{-|
+start "Bug308#startAnchor"
+
+startOldStyle "Bug308\#startAnchor"
+
+middle "Bug308#middleAnchor"
+
+end "Bug308#middleAnchor"
+-}
+g :: ()
+g = ()
diff --git a/html-test/src/Bug308CrossModule.hs b/html-test/src/Bug308CrossModule.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Bug308CrossModule.hs
@@ -0,0 +1,18 @@
+{-# LANGUAGE Haskell2010 #-}
+-- Just like Bug308 module but here we test that referring to anchors
+-- from other modules works.
+module Bug308CrossModule where
+
+import Bug308
+
+{-|
+start "Bug308#startAnchor"
+
+startOldStyle "Bug308\#startAnchor"
+
+middle "Bug308#middleAnchor"
+
+end "Bug308#middleAnchor"
+-}
+h :: ()
+h = ()
diff --git a/html-test/src/Bug310.hs b/html-test/src/Bug310.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Bug310.hs
@@ -0,0 +1,5 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE ExplicitNamespaces #-}
+module Bug310 ( type (+) ) where
+
+import GHC.TypeLits
diff --git a/html-test/src/Bug313.hs b/html-test/src/Bug313.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Bug313.hs
@@ -0,0 +1,38 @@
+{-# LANGUAGE Haskell2010 #-}
+-- | The first list is incorrectly numbered as 1. 2. 1.; the second example
+-- renders fine (1. 2. 3.).
+--
+-- See https://github.com/haskell/haddock/issues/313
+module Bug313 where
+
+{- |
+Some text.
+
+1. Item 1
+
+2. Item 2
+
+    > Some code
+
+3. Item 3
+
+Some more text.
+-}
+a :: a
+a = undefined
+
+{- |
+Some text.
+
+1. Item 1
+
+2. Item 2
+
+    > Some code
+
+3. Item 3
+
+-}
+-- | Some more text.
+b :: a
+b = undefined
diff --git a/html-test/src/Bug335.hs b/html-test/src/Bug335.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Bug335.hs
@@ -0,0 +1,27 @@
+{-# LANGUAGE Haskell2010 #-}
+-- Tests for collapsable headers
+module Bug335 where
+
+{-|
+=== __ExF:__
+abc
+-}
+f :: ()
+f = ()
+
+{-|
+=== __ExG:__
+>>> a
+b
+
+>>> c
+d
+
+==== Under ex
+foo
+
+== Out of Ex
+foo
+-}
+g :: ()
+g = ()
diff --git a/html-test/src/Bug4.hs b/html-test/src/Bug4.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Bug4.hs
@@ -0,0 +1,6 @@
+{-# LANGUAGE Haskell2010 #-}
+module Bug4 where
+-- | don't use apostrophe's in the wrong place's
+foo :: Int
+foo = undefined
+
diff --git a/html-test/src/Bug458.hs b/html-test/src/Bug458.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Bug458.hs
@@ -0,0 +1,7 @@
+{-# LANGUAGE Haskell2010 #-}
+module Bug458 where
+
+-- | See the defn of @'⊆'@.
+(⊆) :: () -> () -> ()
+_ ⊆ _ = ()
+
diff --git a/html-test/src/Bug466.hs b/html-test/src/Bug466.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Bug466.hs
@@ -0,0 +1,10 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE DataKinds, TypeFamilies, StarIsType #-}
+module Bug466 where
+
+class Cl a where
+  type Fam a :: [*]
+
+data X = X
+instance Cl X where
+  type Fam X = '[Char]
diff --git a/html-test/src/Bug546.hs b/html-test/src/Bug546.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Bug546.hs
@@ -0,0 +1,56 @@
+{-# LANGUAGE Haskell2010 #-}
+module Bug546 where
+
+-- |Test:
+--
+-- [@[code with square \\ brackets\]@] lorem ipsum
+x = 1
+
+-- |
+--
+-- [@[..\]@]  Matches any of the enclosed characters. Ranges of characters can
+--            be specified by separating the endpoints with a @\'-'@. @\'-'@ or
+--            @']'@ can be matched by including them as the first character(s)
+--            in the list. Never matches path separators: @[\/]@ matches
+--            nothing at all. Named character classes can also be matched:
+--            @[:x:]@ within @[]@ specifies the class named @x@, which matches
+--            certain predefined characters. See below for a full list.
+--
+-- [@[^..\]@ or @[!..\]@] Like @[..]@, but matches any character /not/ listed.
+--                        Note that @[^-x]@ is not the inverse of @[-x]@, but
+--                        the range @[^-x]@.
+--
+-- [@\<m-n>@] Matches any integer in the range m to n, inclusive. The range may
+--            be open-ended by leaving out either number: @\"\<->\"@, for
+--            instance, matches any integer.
+--
+-- [@**/@]    Matches any number of characters, including path separators,
+--            excluding the empty string.
+--
+-- Supported character classes:
+--
+-- [@[:alnum:\]@]  Equivalent to @\"0-9A-Za-z\"@.
+--
+-- [@[:alpha:\]@]  Equivalent to @\"A-Za-z\"@.
+--
+-- [@[:blank:\]@]  Equivalent to @\"\\t \"@.
+--
+-- [@[:cntrl:\]@]  Equivalent to @\"\\0-\\x1f\\x7f\"@.
+--
+-- [@[:digit:\]@]  Equivalent to @\"0-9\"@.
+--
+-- [@[:graph:\]@]  Equivalent to @\"!-~\"@.
+--
+-- [@[:lower:\]@]  Equivalent to @\"a-z\"@.
+--
+-- [@[:print:\]@]  Equivalent to @\" -~\"@.
+--
+-- [@[:punct:\]@]  Equivalent to @\"!-\/:-\@[-`{-~\"@.
+--
+-- [@[:space:\]@]  Equivalent to @\"\\t-\\r \"@.
+--
+-- [@[:upper:\]@]  Equivalent to @\"A-Z\"@.
+--
+-- [@[:xdigit:\]@] Equivalent to @\"0-9A-Fa-f\"@.
+compile :: String -> String
+compile = id
diff --git a/html-test/src/Bug548.hs b/html-test/src/Bug548.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Bug548.hs
@@ -0,0 +1,4 @@
+{-# LANGUAGE Haskell2010 #-}
+module Bug548 (WrappedArrow(..)) where
+
+import Control.Applicative
diff --git a/html-test/src/Bug6.hs b/html-test/src/Bug6.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Bug6.hs
@@ -0,0 +1,24 @@
+{-# LANGUAGE Haskell2010 #-}
+-- | Exporting records.
+module Bug6( A(A), B(B), b, C(C,c1,c2), D(D,d1), E(E) ) where
+
+-- |
+-- This record is exported without its field
+data A = A { a :: Int }
+
+-- |
+-- .. with its field, but the field is named separately in the export list
+-- (the field isn't documented separately since it is already documented here)
+data B = B { b :: Int }
+
+-- |
+-- .. with fields names as subordinate names in the export
+data C = C { c1 :: Int, c2 :: Int }
+
+-- |
+-- .. with only some of the fields exported (we can't handle this one -
+-- how do we render the declaration?)
+data D = D { d1 :: Int, d2 :: Int }
+
+-- | a newtype with a field
+newtype E = E { e :: Int }
diff --git a/html-test/src/Bug613.hs b/html-test/src/Bug613.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Bug613.hs
@@ -0,0 +1,17 @@
+{-# LANGUAGE Haskell2010 #-}
+module Bug613  where
+
+import Prelude (Either(Left, Right))
+
+class Functor f where
+  fmap :: (a -> b) -> f a -> f b
+
+instance Functor (Either a) where
+  fmap _ (Left x) = Left x
+  fmap f (Right y) = Right (f y)
+
+-- | Phantom type a0 is added to block the first renaming from a to a0. This ensures that the renamer doesn't create a new conflict
+data ThreeVars a0 a b = ThreeVars a b
+
+instance Functor (ThreeVars a0 a) where
+  fmap f (ThreeVars a b) = ThreeVars a (f b)
diff --git a/html-test/src/Bug647.hs b/html-test/src/Bug647.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Bug647.hs
@@ -0,0 +1,7 @@
+{-# LANGUAGE Haskell2010 #-}
+module Bug647 where
+
+class Bug647 a where
+	f :: a -- ^ doc for arg1
+	  -> a -- ^ doc for arg2
+	  -> a -- ^ doc for arg3
diff --git a/html-test/src/Bug679.hs b/html-test/src/Bug679.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Bug679.hs
@@ -0,0 +1,25 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE TemplateHaskell #-}
+
+module Bug679 where
+
+import Language.Haskell.TH
+
+data Bar a = Bar
+
+$(do
+   a <- newName "a"
+   
+   let classN = mkName "Foo"
+   let methodN = mkName "foo"
+
+   methodTy <- [t| $(varT a) -> $(varT a) |]
+   let cla = ClassD [] classN [PlainTV a ()] [] [SigD methodN methodTy]
+ 
+   -- Note that we are /reusing/ the same type variable 'a' as in the class
+   instanceHead <- [t| $(conT classN) (Bar $(varT a)) |]
+   idCall <- [e| id |]
+   let ins = InstanceD Nothing [] instanceHead [FunD methodN [Clause [] (NormalB idCall) []]]
+    
+   pure [cla,ins])
+
diff --git a/html-test/src/Bug7.hs b/html-test/src/Bug7.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Bug7.hs
@@ -0,0 +1,14 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE MultiParamTypeClasses #-}
+-- | This module caused a duplicate instance in the documentation for the Foo
+-- type.
+module Bug7  where
+
+-- | The Foo datatype
+data Foo = Foo
+
+-- | The Bar class
+class Bar x y
+
+-- | Just one instance
+instance Bar Foo Foo
diff --git a/html-test/src/Bug745.hs b/html-test/src/Bug745.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Bug745.hs
@@ -0,0 +1,9 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE TemplateHaskell, QuasiQuotes #-}
+
+module Bug574 where
+-- See https://github.com/haskell/haddock/issues/574
+
+-- | Something with a spliced type
+foo :: Int -> $(let i = [t| Int |] in [t| $i -> $i |])
+foo x y = x + y
diff --git a/html-test/src/Bug8.hs b/html-test/src/Bug8.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Bug8.hs
@@ -0,0 +1,16 @@
+{-# LANGUAGE Haskell2010 #-}
+module Bug8 where
+
+infix -->
+infix --->
+
+data Typ = Type (Typ,[Typ])
+         | TFree (Typ, [Typ])
+
+x --> y = Type(s,[s,t])
+(--->) :: (Foldable t0) => t0 t -> Typ -> Typ
+(--->) = flip $ foldr (-->)
+
+s = undefined
+t = undefined
+main = undefined
diff --git a/html-test/src/Bug85.hs b/html-test/src/Bug85.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Bug85.hs
@@ -0,0 +1,15 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE GADTs, KindSignatures #-}
+module Bug85 where
+
+-- explicitly stated non-trivial kind
+data Foo :: (* -> *) -> * -> * where
+  Bar :: f x -> Foo f (f x)
+
+-- Just kind * but explicitly written
+data Baz :: * where
+  Baz' :: Baz
+
+-- No kind signature written down at all
+data Qux where
+  Quux :: Qux
diff --git a/html-test/src/Bug865.hs b/html-test/src/Bug865.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Bug865.hs
@@ -0,0 +1,10 @@
+{-# LANGUAGE Haskell2010 #-}
+module Bug865 where
+
+-- | An emphasized link [yes /this/ is emphasized while this is
+-- @monospaced@](https://www.haskell.org/). And here is an image:
+--
+-- ![/emphasis/ stripped](https://www.haskell.org/static/img/haskell-logo.svg)
+--
+link :: ()
+link = ()
diff --git a/html-test/src/Bug923.hs b/html-test/src/Bug923.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Bug923.hs
@@ -0,0 +1,12 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE KindSignatures, FlexibleInstances, GADTs, DataKinds #-}
+module Bug923 where
+
+-- | A promoted tuple type
+data T :: (* -> (*,*)) -> * where
+  T :: a -> T ('(,) a)
+
+-- | A promoted tuple type in an instance
+instance Eq a => Eq (T ('(,) a)) where
+  T x == T y = x == y
+
diff --git a/html-test/src/Bug952.hs b/html-test/src/Bug952.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Bug952.hs
@@ -0,0 +1,6 @@
+{-# LANGUAGE Haskell2010 #-}
+module Bug952 where
+
+-- | See 'case', 'of', '--' compared to 'Q.case', 'Q.of', 'Q.--'
+foo :: ()
+foo = ()
diff --git a/html-test/src/Bug953.hs b/html-test/src/Bug953.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Bug953.hs
@@ -0,0 +1,18 @@
+{-# LANGUAGE Haskell2010 #-}
+module Bug953 where
+
+{- | A foo
+
+==== __Examples__
+
+Foo example body
+-}
+data Foo = Foo'
+
+{- | A bar
+
+==== __Examples__
+
+Bar example body
+-}
+data Bar = Bar'
diff --git a/html-test/src/Bug975.hs b/html-test/src/Bug975.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Bug975.hs
@@ -0,0 +1,16 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE ExplicitForAll #-}
+module Bug973 where
+
+showRead
+  :: forall a b. (Show a, Read b)
+  => a -- ^ this gets turned into a string...
+  -> b -- ^ ...from which this is read
+showRead = read . show
+
+-- | Same as 'showRead', but with type variable order flipped
+showRead'
+  :: forall b a. (Show a, Read b)
+  => a -- ^ this gets turned into a string...
+  -> b -- ^ ...from which this is read
+showRead' = read . show
diff --git a/html-test/src/BugDeprecated.hs b/html-test/src/BugDeprecated.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/BugDeprecated.hs
@@ -0,0 +1,27 @@
+{-# LANGUAGE Haskell2010 #-}
+module BugDeprecated where
+
+foo :: Int
+foo = 23
+
+bar :: Int
+bar = 23
+
+baz :: Int
+baz = 23
+{-# DEPRECATED foo "for foo" #-}
+{-# DEPRECATED bar "for bar" #-}
+{-# DEPRECATED baz "for baz" #-}
+
+-- | some documentation for one
+one :: Int
+one = 23
+
+two :: Int
+two = 23
+
+three :: Int
+three = 23
+{-# DEPRECATED one "for one" #-}
+{-# DEPRECATED two "for two" #-}
+{-# DEPRECATED three "for three" #-}
diff --git a/html-test/src/BugExportHeadings.hs b/html-test/src/BugExportHeadings.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/BugExportHeadings.hs
@@ -0,0 +1,30 @@
+{-# LANGUAGE Haskell2010 #-}
+-- test for #192
+module BugExportHeadings (
+-- * Foo
+  foo
+-- * Bar
+, bar
+-- * Baz
+, baz
+
+-- * One
+, one
+-- * Two
+, two
+-- * Three
+, three
+) where
+
+foo, bar, baz :: Int
+foo = 23
+bar = 23
+baz = 23
+
+one, two, three :: Int
+one = 23
+two = 23
+three = 23
+{-# DEPRECATED one "for one" #-}
+{-# DEPRECATED two "for two" #-}
+{-# DEPRECATED three "for three" #-}
diff --git a/html-test/src/Bugs.hs b/html-test/src/Bugs.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Bugs.hs
@@ -0,0 +1,4 @@
+{-# LANGUAGE Haskell2010 #-}
+module Bugs where
+
+data A a = A a (a -> Int)
diff --git a/html-test/src/BundledPatterns.hs b/html-test/src/BundledPatterns.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/BundledPatterns.hs
@@ -0,0 +1,111 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE DataKinds, GADTs, KindSignatures, PatternSynonyms, TypeOperators,
+             ViewPatterns #-}
+module BundledPatterns (Vec(Nil,(:>)), RTree (LR,BR)) where
+
+import GHC.TypeLits
+import Prelude hiding (head, tail)
+import Unsafe.Coerce
+
+-- | Fixed size vectors.
+--
+-- * Lists with their length encoded in their type
+-- * 'Vec'tor elements have an __ASCENDING__ subscript starting from 0 and
+--   ending at @'length' - 1@.
+data Vec :: Nat -> * -> * where
+  Nil  :: Vec 0 a
+  Cons :: a -> Vec n a -> Vec (n + 1) a
+
+infixr 5 `Cons`
+
+-- | Add an element to the head of a vector.
+--
+-- >>> 3:>4:>5:>Nil
+-- <3,4,5>
+-- >>> let x = 3:>4:>5:>Nil
+-- >>> :t x
+-- x :: Num a => Vec 3 a
+--
+-- Can be used as a pattern:
+--
+-- >>> let f (x :> y :> _) = x + y
+-- >>> :t f
+-- f :: Num a => Vec ((n + 1) + 1) a -> a
+-- >>> f (3:>4:>5:>6:>7:>Nil)
+-- 7
+--
+-- Also in conjunctions with (':<'):
+--
+-- >>> let g (a :> b :> (_ :< y :< x)) = a + b +  x + y
+-- >>> :t g
+-- g :: Num a => Vec ((((n + 1) + 1) + 1) + 1) a -> a
+-- >>> g (1:>2:>3:>4:>5:>Nil)
+-- 12
+pattern (:>) :: a -> Vec n a -> Vec (n + 1) a
+pattern (:>) x xs <- ((\ys -> (head ys,tail ys)) -> (x,xs))
+  where
+    (:>) x xs = Cons x xs
+
+infixr 5 :>
+
+head :: Vec (n + 1) a -> a
+head (x `Cons` _) = x
+
+tail :: Vec (n + 1) a -> Vec n a
+tail (_ `Cons` xs) = unsafeCoerce xs
+
+-- | Perfect depth binary tree.
+--
+-- * Only has elements at the leaf of the tree
+-- * A tree of depth /d/ has /2^d/ elements.
+data RTree :: Nat -> * -> * where
+  LR_ :: a -> RTree 0 a
+  BR_ :: RTree d a -> RTree d a -> RTree (d+1) a
+
+textract :: RTree 0 a -> a
+textract (LR_ x) = x
+{-# NOINLINE textract #-}
+
+tsplit :: RTree (d+1) a -> (RTree d a,RTree d a)
+tsplit (BR_ l r) = (unsafeCoerce l, unsafeCoerce r)
+{-# NOINLINE tsplit #-}
+
+-- | Leaf of a perfect depth tree
+--
+-- >>> LR 1
+-- 1
+-- >>> let x = LR 1
+-- >>> :t x
+-- x :: Num a => RTree 0 a
+--
+-- Can be used as a pattern:
+--
+-- >>> let f (LR a) (LR b) = a + b
+-- >>> :t f
+-- f :: Num a => RTree 0 a -> RTree 0 a -> a
+-- >>> f (LR 1) (LR 2)
+-- 3
+pattern LR :: a -> RTree 0 a
+pattern LR x <- (textract -> x)
+  where
+    LR x = LR_ x
+
+-- | Branch of a perfect depth tree
+--
+-- >>> BR (LR 1) (LR 2)
+-- <1,2>
+-- >>> let x = BR (LR 1) (LR 2)
+-- >>> :t x
+-- x :: Num a => RTree 1 a
+--
+-- Case be used a pattern:
+--
+-- >>> let f (BR (LR a) (LR b)) = LR (a + b)
+-- >>> :t f
+-- f :: Num a => RTree 1 a -> RTree 0 a
+-- >>> f (BR (LR 1) (LR 2))
+-- 3
+pattern BR :: RTree d a -> RTree d a -> RTree (d+1) a
+pattern BR l r <- ((\t -> (tsplit t)) -> (l,r))
+  where
+    BR l r = BR_ l r
diff --git a/html-test/src/BundledPatterns2.hs b/html-test/src/BundledPatterns2.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/BundledPatterns2.hs
@@ -0,0 +1,10 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE DataKinds, GADTs, KindSignatures, PatternSynonyms #-}
+module BundledPatterns2 (Vec((:>), Empty), RTree(..)) where
+
+import GHC.TypeLits
+
+import BundledPatterns
+
+pattern Empty :: Vec 0 a
+pattern Empty <- Nil
diff --git a/html-test/src/ConstructorArgs.hs b/html-test/src/ConstructorArgs.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/ConstructorArgs.hs
@@ -0,0 +1,57 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE GADTs, PatternSynonyms #-}
+
+module ConstructorArgs (Foo(..), Boo(Foo, Foa, Fo, Fo'), pattern Bo, pattern Bo') where
+
+data Foo
+  = Rec             -- ^ doc on a record
+     { x :: String  -- ^ doc on the `String` field of `Rec`
+     , y :: String  -- ^ doc on the `String` field of `Rec`
+     }
+   | Baz Int String  -- ^ old prefix doc style
+   | Boa             -- ^ doc on the `Boa` constrictor
+       !Int          -- ^ doc on the `Int` field of `Boa`
+       !String       -- ^ doc on the `String` field of `Boa`
+   | Int :| String   -- ^ old infix doc style
+   | Int             -- ^ doc on the `Int` field of the `:*` constructor
+       :*            -- ^ doc on the `:*` constructor
+     String          -- ^ doc on the `String` field of the `:*` constructor
+
+infixr 1 `Foo`
+infixr 2 `Boa`
+infixr 3 :*
+
+data Boo where
+  -- | Info about a 'Foo'
+  Foo :: Int    -- ^ `Int` field of `Foo`
+      -> String -- ^ `String` field of `Foo`
+      -> Boo    -- ^ Make a `Boo`
+
+  -- | no argument docs GADT
+  Foa :: Int -> Boo
+
+infixr 4 `Boo`
+
+-- | Info about bundled 'Fo'
+pattern Fo :: Int    -- ^ an 'Int'
+           -> String -- ^ a 'String'
+           -> Boo    -- ^ a 'Boo'
+pattern Fo x y = Foo x y
+
+-- | Bundled and no argument docs
+pattern Fo' :: Boo
+pattern Fo' = Foo 1 "hi"
+
+infixr 5 `Fo`
+
+-- | Info about not-bundled 'Bo'
+pattern Bo :: Int    -- ^ an 'Int'
+           -> String -- ^ a 'String'
+           -> Boo -- ^ a 'Boo' pattern
+pattern Bo x y = Foo x y
+
+-- | Not bundled and no argument docs
+pattern Bo' :: Int -> String -> Boo
+pattern Bo' x y = Foo x y
+
+infixr 6 `Bo`
diff --git a/html-test/src/ConstructorPatternExport.hs b/html-test/src/ConstructorPatternExport.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/ConstructorPatternExport.hs
@@ -0,0 +1,27 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE PatternSynonyms #-}
+{-# LANGUAGE ExistentialQuantification #-}
+{-# LANGUAGE GADTs #-}
+{-# LANGUAGE KindSignatures #-}
+
+module ConstructorPatternExport (
+    pattern FooCons
+  , pattern MyRecCons
+  , pattern (:+)
+  , pattern BlubCons
+  , pattern MyGADTCons
+  ) where
+
+data Foo a = FooCons String a
+
+data MyRec = MyRecCons { one :: Bool, two :: Int }
+
+data MyInfix a = String :+ a
+
+data Blub = forall b. Show b => BlubCons b
+
+data MyGADT :: * -> * where
+  MyGADTCons :: forall a. Eq a => a -> Int -> MyGADT (Maybe String)
+
+pattern MyGADTCons' :: () => forall a. Eq a => a -> Int -> MyGADT (Maybe String)
+pattern MyGADTCons' x y = MyGADTCons x y
diff --git a/html-test/src/DefaultAssociatedTypes.hs b/html-test/src/DefaultAssociatedTypes.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/DefaultAssociatedTypes.hs
@@ -0,0 +1,15 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE TypeFamilies #-}
+
+module DefaultAssociatedTypes where
+
+-- | Documentation for Foo.
+class Foo a where
+  -- | Documentation for bar and baz.
+  bar, baz :: a -> String
+
+  -- | Doc for Qux
+  type Qux a :: *
+
+  -- | Doc for default Qux
+  type Qux a = [a]
diff --git a/html-test/src/DefaultSignatures.hs b/html-test/src/DefaultSignatures.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/DefaultSignatures.hs
@@ -0,0 +1,20 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE DefaultSignatures #-}
+
+module DefaultSignatures where
+
+-- | Documentation for Foo.
+class Foo a where
+  -- | Documentation for bar and baz.
+  bar, baz :: a -> String
+
+  -- | Documentation for the default signature of bar.
+  default bar :: Show a => a -> String
+  bar = show
+
+  -- | Documentation for baz'.
+  baz' :: String -> a
+
+  -- | Documentation for the default signature of baz'.
+  default baz' :: Read a => String -> a
+  baz' = read
diff --git a/html-test/src/DeprecatedClass.hs b/html-test/src/DeprecatedClass.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/DeprecatedClass.hs
@@ -0,0 +1,16 @@
+{-# LANGUAGE Haskell2010 #-}
+module DeprecatedClass where
+
+-- | some class
+class SomeClass a where
+  -- | documentation for foo
+  foo :: a -> a
+
+{-# DEPRECATED SomeClass "SomeClass" #-}
+{-# DEPRECATED foo "foo" #-}
+
+class SomeOtherClass a where
+  bar :: a -> a
+
+{-# DEPRECATED SomeOtherClass "SomeOtherClass" #-}
+{-# DEPRECATED bar "bar" #-}
diff --git a/html-test/src/DeprecatedData.hs b/html-test/src/DeprecatedData.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/DeprecatedData.hs
@@ -0,0 +1,16 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE TypeFamilies #-}
+module DeprecatedData where
+
+-- | type Foo
+data Foo = Foo -- ^ constructor Foo
+         | Bar -- ^ constructor Bar
+
+{-# DEPRECATED Foo "Foo" #-}
+{-# DEPRECATED Bar "Bar" #-}
+
+data One = One
+         | Two
+
+{-# DEPRECATED One "One" #-}
+{-# DEPRECATED Two "Two" #-}
diff --git a/html-test/src/DeprecatedFunction.hs b/html-test/src/DeprecatedFunction.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/DeprecatedFunction.hs
@@ -0,0 +1,11 @@
+{-# LANGUAGE Haskell2010 #-}
+module DeprecatedFunction where
+
+-- | some documentation for foo
+foo :: Int
+foo = 23
+{-# DEPRECATED foo "use `bar` instead" #-}
+
+-- | some documentation for bar
+bar :: Int
+bar = 42
diff --git a/html-test/src/DeprecatedFunction2.hs b/html-test/src/DeprecatedFunction2.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/DeprecatedFunction2.hs
@@ -0,0 +1,7 @@
+{-# LANGUAGE Haskell2010 #-}
+module DeprecatedFunction2 where
+
+
+foo :: Int
+foo = 23
+{-# DEPRECATED foo "use bar instead" #-}
diff --git a/html-test/src/DeprecatedFunction3.hs b/html-test/src/DeprecatedFunction3.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/DeprecatedFunction3.hs
@@ -0,0 +1,7 @@
+{-# LANGUAGE Haskell2010 #-}
+module DeprecatedFunction3 where
+
+
+
+foo = 23
+{-# DEPRECATED foo "use bar instead" #-}
diff --git a/html-test/src/DeprecatedModule.hs b/html-test/src/DeprecatedModule.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/DeprecatedModule.hs
@@ -0,0 +1,6 @@
+{-# LANGUAGE Haskell2010 #-}
+-- | Documentation for "DeprecatedModule".
+module DeprecatedModule {-# DEPRECATED "Use \"Foo\" instead" #-} where
+
+foo :: Int
+foo = 23
diff --git a/html-test/src/DeprecatedModule2.hs b/html-test/src/DeprecatedModule2.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/DeprecatedModule2.hs
@@ -0,0 +1,5 @@
+{-# LANGUAGE Haskell2010 #-}
+module DeprecatedModule2 {-# DEPRECATED "Use Foo instead" #-} where
+
+foo :: Int
+foo = 23
diff --git a/html-test/src/DeprecatedNewtype.hs b/html-test/src/DeprecatedNewtype.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/DeprecatedNewtype.hs
@@ -0,0 +1,11 @@
+{-# LANGUAGE Haskell2010 #-}
+module DeprecatedNewtype where
+
+-- | some documentation
+newtype SomeNewType = SomeNewTypeConst String {- ^ constructor docu -}
+{-# DEPRECATED SomeNewType "SomeNewType" #-}
+{-# DEPRECATED SomeNewTypeConst "SomeNewTypeConst" #-}
+
+newtype SomeOtherNewType = SomeOtherNewTypeConst String
+{-# DEPRECATED SomeOtherNewType "SomeOtherNewType" #-}
+{-# DEPRECATED SomeOtherNewTypeConst "SomeOtherNewTypeConst" #-}
diff --git a/html-test/src/DeprecatedReExport.hs b/html-test/src/DeprecatedReExport.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/DeprecatedReExport.hs
@@ -0,0 +1,17 @@
+{-# LANGUAGE Haskell2010 #-}
+-- |
+-- What is tested here:
+--
+-- * Deprecation messages are shown for re-exported items.
+--
+module DeprecatedReExport (
+-- * Re-exported from an other module
+  foo
+-- * Re-exported from an other package
+-- | Not yet working, see <http://trac.haskell.org/haddock/ticket/223>
+-- , isEmptyChan
+,
+) where
+
+import DeprecatedFunction
+import Control.Concurrent.Chan
diff --git a/html-test/src/DeprecatedRecord.hs b/html-test/src/DeprecatedRecord.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/DeprecatedRecord.hs
@@ -0,0 +1,10 @@
+{-# LANGUAGE Haskell2010 #-}
+module DeprecatedRecord where
+
+-- | type Foo
+data Foo = Foo {
+  fooName  :: String -- ^ some name
+, fooValue :: Int    -- ^ some value
+}
+
+{-# DEPRECATED fooValue "do not use this" #-}
diff --git a/html-test/src/DeprecatedTypeFamily.hs b/html-test/src/DeprecatedTypeFamily.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/DeprecatedTypeFamily.hs
@@ -0,0 +1,10 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE TypeFamilies #-}
+module DeprecatedTypeFamily where
+
+-- | some documentation
+data family SomeTypeFamily k :: * -> *
+{-# DEPRECATED SomeTypeFamily "SomeTypeFamily" #-}
+
+data family SomeOtherTypeFamily k :: * -> *
+{-# DEPRECATED SomeOtherTypeFamily "SomeOtherTypeFamily" #-}
diff --git a/html-test/src/DeprecatedTypeSynonym.hs b/html-test/src/DeprecatedTypeSynonym.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/DeprecatedTypeSynonym.hs
@@ -0,0 +1,10 @@
+{-# LANGUAGE Haskell2010 #-}
+
+module DeprecatedTypeSynonym where
+
+-- | some documentation
+type TypeSyn = String
+{-# DEPRECATED TypeSyn "TypeSyn" #-}
+
+type OtherTypeSyn = String
+{-# DEPRECATED OtherTypeSyn "OtherTypeSyn" #-}
diff --git a/html-test/src/DuplicateRecordFields.hs b/html-test/src/DuplicateRecordFields.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/DuplicateRecordFields.hs
@@ -0,0 +1,26 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE DuplicateRecordFields #-}
+module DuplicateRecordFields (RawReplay(..)) where
+
+import Prelude hiding (Int)
+
+data Int = Int
+
+data RawReplay = RawReplay
+    { headerSize :: Int
+    -- ^ The byte size of the first section.
+    , headerCRC :: Int
+    -- ^ The CRC of the first section.
+    , header :: Int
+    -- ^ The first section.
+    , contentSize :: Int
+    -- ^ The byte size of the second section.
+    , contentCRC :: Int
+    -- ^ The CRC of the second section.
+    , content :: Int
+    -- ^ The second section.
+    , footer :: Int
+    -- ^ Arbitrary data after the second section. In replays generated by
+    -- Rocket League, this is always empty. However it is not technically
+    -- invalid to put something here.
+    }
diff --git a/html-test/src/Examples.hs b/html-test/src/Examples.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Examples.hs
@@ -0,0 +1,40 @@
+{-# LANGUAGE Haskell2010 #-}
+module Examples where
+
+-- | Fibonacci number of given 'Integer'.
+--
+-- Examples:
+--
+-- >>> fib 5
+-- 5
+-- >>> fib 10
+-- 55
+--
+-- >>> fib 10
+-- 55
+--
+-- One more Example:
+--
+-- >>> fib 5
+-- 5
+--
+-- One more Example:
+--
+-- >>> fib 5
+-- 5
+--
+-- Example with an import:
+--
+-- >>> import Data.Char
+-- >>> isSpace 'a'
+-- False
+--
+-- >>> putStrLn "foo\n\nbar"
+-- foo
+-- <BLANKLINE>
+-- bar
+--
+fib :: Integer -> Integer
+fib 0 = 0
+fib 1 = 1
+fib n = fib (n - 1) + fib (n - 2)
diff --git a/html-test/src/Extensions.hs b/html-test/src/Extensions.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Extensions.hs
@@ -0,0 +1,8 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE Haskell2010, ExplicitForAll, MonomorphismRestriction #-}
+{-# OPTIONS_HADDOCK show-extensions #-}
+module Extensions where
+
+-- | Bar
+foobar :: t
+foobar = undefined
diff --git a/html-test/src/FunArgs.hs b/html-test/src/FunArgs.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/FunArgs.hs
@@ -0,0 +1,39 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE RankNTypes, DataKinds, TypeFamilies #-}
+module FunArgs where
+
+f :: forall a. Ord a
+  => Int          -- ^ First argument
+  -> a            -- ^ Second argument
+  -> Bool         -- ^ Third argument
+  -> (a -> a)     -- ^ Fourth argument
+  -> ()           -- ^ Result
+f = undefined
+
+
+g :: a -- ^ First argument
+  -> b -- ^ Second argument
+  -> c -- ^ Third argument
+  -> d -- ^ Result
+g = undefined
+
+
+h :: forall a b c
+  .  a -- ^ First argument
+  -> b -- ^ Second argument
+  -> c -- ^ Third argument
+  -> forall d. d -- ^ Result
+h _ _ _ = undefined
+
+
+i :: forall a (b :: ()) d. (d ~ '())
+  => forall c
+  .  a b c d -- ^ abcd
+  -> ()      -- ^ Result
+i = undefined
+
+
+j :: forall proxy (a :: ()) b
+  .  proxy a -- ^ First argument
+  -> b       -- ^ Result
+j = undefined
diff --git a/html-test/src/GADTRecords.hs b/html-test/src/GADTRecords.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/GADTRecords.hs
@@ -0,0 +1,12 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE GADTs #-}
+module GADTRecords (H1(..)) where
+
+-- | h1
+data H1 a b where
+  C1 :: H1 a b
+  C2 :: Ord a => [a] -> H1 a a
+  C3 :: { field :: Int -- ^ hello docs
+        } -> H1 Int Int
+  C4 :: { field2 :: a -- ^ hello2 docs
+        } -> H1 Int a
diff --git a/html-test/src/GadtConstructorArgs.hs b/html-test/src/GadtConstructorArgs.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/GadtConstructorArgs.hs
@@ -0,0 +1,14 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE GADTs #-}
+
+module GadtConstructorArgs (Boo(..)) where
+
+data Boo where
+  Fot :: { x :: Int  -- ^ an 'x'
+         , y :: Int  -- ^ a 'y'
+         } -> Boo
+
+  -- | Record GADT with docs
+  Fob :: { w :: Int  -- ^ a 'w'
+         , z :: Int  -- ^ a 'z'
+         } -> Boo    -- ^ a 'Boo'
diff --git a/html-test/src/Hash.hs b/html-test/src/Hash.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Hash.hs
@@ -0,0 +1,52 @@
+{-# LANGUAGE Haskell2010 #-}
+{- |
+  Implementation of fixed-size hash tables, with a type
+  class for constructing hash values for structured types.
+-}
+module Hash (
+  -- * The @HashTable@ type
+  HashTable,
+
+  -- ** Operations on @HashTable@s
+  new, insert, lookup,
+
+  -- * The @Hash@ class
+  Hash(..),
+ ) where
+
+import Data.Array
+import Prelude hiding (lookup)
+
+-- | A hash table with keys of type @key@ and values of type @val@.
+-- The type @key@ should be an instance of 'Eq'.
+data HashTable key val = HashTable Int (Array Int [(key,val)])
+
+-- | Builds a new hash table with a given size
+new :: (Eq key, Hash key) => Int -> IO (HashTable key val)
+new = undefined
+
+-- | Inserts a new element into the hash table
+insert :: (Eq key, Hash key) => key -> val -> IO ()
+insert = undefined
+
+-- | Looks up a key in the hash table, returns @'Just' val@ if the key
+-- was found, or 'Nothing' otherwise.
+lookup :: Hash key => key -> IO (Maybe val)
+lookup = undefined
+
+-- | A class of types which can be hashed.
+class Hash a where
+   -- | hashes the value of type @a@ into an 'Int'
+   hash :: a -> Int
+
+instance Hash Int where
+   hash = id
+
+instance Hash Float where
+   hash = trunc
+
+instance (Hash a, Hash b) => Hash (a,b) where
+   hash (a,b) = hash a `xor` hash b
+
+trunc = undefined
+xor = undefined
diff --git a/html-test/src/Hidden.hs b/html-test/src/Hidden.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Hidden.hs
@@ -0,0 +1,7 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# OPTIONS_HADDOCK hide #-}
+
+module Hidden where
+
+hidden :: Int -> Int
+hidden a = a
diff --git a/html-test/src/HiddenInstances.hs b/html-test/src/HiddenInstances.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/HiddenInstances.hs
@@ -0,0 +1,36 @@
+{-# LANGUAGE Haskell2010 #-}
+-- http://trac.haskell.org/haddock/ticket/37
+module HiddenInstances (VisibleClass, VisibleData) where
+
+-- | Should be visible
+class VisibleClass a
+
+-- | Should *not* be visible
+class HiddenClass a
+
+-- | Should *not* be visible
+data HiddenData = HiddenData
+
+-- | Should be visible
+data VisibleData = VisibleData
+
+-- | Should be visible
+instance VisibleClass Int
+
+-- | Should be visible
+instance VisibleClass VisibleData
+
+-- | Should be visible
+instance Num VisibleData
+
+-- | Should *not* be visible
+instance VisibleClass HiddenData
+
+-- | Should *not* be visible
+instance HiddenClass Int
+
+-- | Should *not* be visible
+instance HiddenClass VisibleData
+
+-- | Should *not* be visible
+instance HiddenClass HiddenData
diff --git a/html-test/src/HiddenInstancesA.hs b/html-test/src/HiddenInstancesA.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/HiddenInstancesA.hs
@@ -0,0 +1,18 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# OPTIONS_HADDOCK hide #-}
+module HiddenInstancesA where
+
+-- | Should be visible
+class Foo a
+
+-- | Should be visible
+data Bar
+
+-- | Should be visible
+instance Foo Bar
+
+-- | Should *not* be visible
+data Baz
+
+-- | Should *not* be visible
+instance Foo Baz
diff --git a/html-test/src/HiddenInstancesB.hs b/html-test/src/HiddenInstancesB.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/HiddenInstancesB.hs
@@ -0,0 +1,3 @@
+{-# LANGUAGE Haskell2010 #-}
+module HiddenInstancesB (Foo, Bar) where
+import HiddenInstancesA
diff --git a/html-test/src/Hyperlinks.hs b/html-test/src/Hyperlinks.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Hyperlinks.hs
@@ -0,0 +1,9 @@
+{-# LANGUAGE Haskell2010 #-}
+module Hyperlinks where
+
+-- |
+-- A plain URL: <http://example.com/>
+--
+-- A URL with a label: <http://example.com/ some link>
+foo :: Int
+foo = 23
diff --git a/html-test/src/Identifiers.hs b/html-test/src/Identifiers.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Identifiers.hs
@@ -0,0 +1,36 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE TypeOperators #-}
+module Identifiers where
+
+import Data.List (elem, (++))
+
+data Id = Id
+data a :* b = a :* b
+
+{-|
+
+  * Unadorned:
+
+        - Unqualified: '++', 'elem'
+        - Qualified: 'Data.List.++', 'Data.Lis.elem'
+        - Namespaced: v'++', t'++', v'elem', t'elem', v'Id', t'Id', v':*', t':*'
+
+  * Parenthesized:
+
+        - Unqualified: @'(++)' [1,2,3] [4,5,6]@
+        - Qualified: @'(Data.List.++)' [1,2,3] [4,5,6]@
+        - Namespaced: v'(++)', t'++', v'(:*)', t'(:*)'
+
+  * Backticked:
+
+        - Unqualified: @1 '`elem`' [-3..3]@
+        - Qualified: @1 '`Data.List.elem`' [-3..3]@
+        - Namespaced: v'`elem`', t'`elem`', v'`Id`', t'`Id`'
+
+  * Edge cases:
+
+        - Tuples: '()', '(,,,)'
+
+-}
+foo :: ()
+foo = ()
diff --git a/html-test/src/IgnoreExports.hs b/html-test/src/IgnoreExports.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/IgnoreExports.hs
@@ -0,0 +1,14 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# OPTIONS_HADDOCK ignore-exports #-}
+module IgnoreExports (Foo, foo) where
+
+-- | documentation for Foo
+data Foo = Bar -- ^ Documentation for Bar
+
+-- | documentation for foo
+foo :: Int
+foo = 23
+
+-- | documentation for bar
+bar :: Int
+bar = 23
diff --git a/html-test/src/ImplicitParams.hs b/html-test/src/ImplicitParams.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/ImplicitParams.hs
@@ -0,0 +1,14 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE ImplicitParams, RankNTypes #-}
+module ImplicitParams where
+
+data X = X
+
+c :: (?x :: X) => X
+c = ?x
+
+d :: (?x :: X, ?y :: X) => (X, X)
+d = (?x, ?y)
+
+f :: ((?x :: X) => a) -> a
+f a = let ?x = X in a
diff --git a/html-test/src/Instances.hs b/html-test/src/Instances.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Instances.hs
@@ -0,0 +1,100 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE MultiParamTypeClasses #-}
+{-# LANGUAGE FlexibleInstances #-}
+{-# LANGUAGE FlexibleContexts #-}
+{-# LANGUAGE ImpredicativeTypes #-}
+{-# LANGUAGE TypeFamilies #-}
+{-# LANGUAGE TypeOperators #-}
+
+
+module Instances where
+
+
+newtype (<~~) a b = Xyzzy (b -> (a, a))
+
+
+class Foo f where
+
+    foo :: f Int -> a -> f a
+    foo' :: f (f a) -> Int -> f (f Int)
+
+    foo = undefined
+    foo' = undefined
+
+instance Foo Maybe
+instance Foo []
+instance (Eq a, Foo f) => Foo ((,) (f a))
+instance Foo (Either a)
+instance Foo ((,,) a a)
+instance Foo ((->) a)
+instance Foo ((<~~) a)
+
+
+class Foo f => Bar f a where
+
+    bar :: f a -> f Bool -> a
+    bar' :: f (f a) -> f (f (f b))
+    bar0, bar1 :: (f a, f a) -> (f b, f c)
+
+    bar = undefined
+    bar' = undefined
+    bar0 = undefined
+    bar1 = undefined
+
+
+instance Bar Maybe Bool
+instance Bar Maybe [a]
+instance Bar [] (a, a)
+instance Foo f => Bar (Either a) (f a)
+instance Foo ((,,) a b) => Bar ((,,) a b) (a, b, a)
+
+
+class Baz a where
+
+    baz :: a -> (forall a. a -> a) -> (b, forall c. c -> a) -> (b, c)
+    baz' :: b -> (forall b. b -> a) -> (forall b. b -> a) -> [(b, a)]
+    baz'' :: b -> (forall b. (forall b. b -> a) -> c) -> (forall c. c -> b)
+
+    baz = undefined
+    baz' = undefined
+    baz'' = undefined
+
+
+instance Baz (a -> b)
+instance Baz [c]
+instance Baz (a, b, c)
+instance Baz (a, [b], b, a)
+
+
+data Quux a b c = Qx a | Qux a b | Quux a b c
+
+instance Foo (Quux a b)
+instance Bar (Quux a c) (Quux a b c)
+instance Baz (Quux a b c)
+
+
+class Norf a b where
+
+    type Plugh a c b
+    data Thud a c
+
+    norf :: Plugh a c b -> a -> (a -> c) -> b
+
+    norf = undefined
+
+
+instance Norf Int Bool where
+
+    type Plugh Int [a] Bool = a
+    type Plugh Int (a, b) Bool = (a, [b])
+
+    data Thud Int (Quux a [a] c) = Thuud a | Thuuud Int Int
+    data Thud Int [a] = Thuuuud Bool
+
+
+instance Norf [a] [b] where
+
+    type Plugh [a] (Maybe a) [b] = a
+    type Plugh [a] [b] [b] = Quux a b (a, b)
+
+    data Thud [a] (a, a, a) = Thd a
diff --git a/html-test/src/LinearTypes.hs b/html-test/src/LinearTypes.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/LinearTypes.hs
@@ -0,0 +1,15 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE LinearTypes #-}
+module LinearTypes where
+
+-- | Does something unrestricted.
+unrestricted :: a -> b
+unrestricted = undefined
+
+-- | Does something linear.
+linear :: a %1 -> b
+linear = linear
+
+-- | Does something polymorphic.
+poly :: a %m -> b
+poly = poly
diff --git a/html-test/src/Math.hs b/html-test/src/Math.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Math.hs
@@ -0,0 +1,15 @@
+{-# LANGUAGE Haskell2010 #-}
+-- | Math (display) for 'normalDensity'
+--
+-- \[
+-- \int_{-\infty}^{\infty} e^{-x^2/2} = \sqrt{2\pi}
+-- \]
+--
+-- \(\int_{-\infty}^{\infty} e^{-x^2/2} = \sqrt{2\pi}\)
+
+module Math where
+
+-- | Math (inline) for 'normalDensity'
+-- \(\int_{-\infty}^{\infty} e^{-x^2/2} = \sqrt{2\pi}\)
+-- \[\int_{-\infty}^{\infty} e^{-x^2/2} = \sqrt{2\pi}\]
+f = 5
diff --git a/html-test/src/Minimal.hs b/html-test/src/Minimal.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Minimal.hs
@@ -0,0 +1,54 @@
+{-# LANGUAGE Haskell2010 #-}
+-- | This tests the new MINIMAL pragma present in GHC 7.8
+module Minimal
+  ( Foo(..)
+  , Weird(..)
+  , NoMins(..)
+  , FullMin(..)
+  , PartialMin(ccc)
+  , EmptyMin(..)
+  ) where
+
+class Foo a where
+  -- | Any two of these are required...
+  foo :: a
+  bar :: a
+  bat :: a
+
+  -- | .. or just this
+  fooBarBat :: (a,a,a)
+
+  {-# MINIMAL (foo, bar) | (bar, bat) | (foo, bat) | fooBarBat #-}
+
+class Weird a where
+  a :: a
+  b :: a
+  c :: a
+  d :: a
+  e :: a
+  f :: a
+  g :: a
+
+  {-# MINIMAL ((a, b), c | (d | (e, (f | g)))) #-}
+
+class NoMins a where
+  x :: a
+  y :: a
+  z :: a
+
+  -- | Has a default implementation!
+  z = x
+
+class FullMin a where
+  aaa :: a
+  bbb :: a
+
+class PartialMin a where
+  ccc :: a
+  ddd :: a
+
+class EmptyMin a where
+  eee :: a
+  fff :: a
+  eee = fff
+  fff = undefined
diff --git a/html-test/src/ModuleWithWarning.hs b/html-test/src/ModuleWithWarning.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/ModuleWithWarning.hs
@@ -0,0 +1,6 @@
+{-# LANGUAGE Haskell2010 #-}
+-- | Documentation for "ModuleWithWarning".
+module ModuleWithWarning {-# WARNING "This is an unstable interface.  Prefer functions from \"Prelude\" instead!" #-} where
+
+foo :: Int
+foo = 23
diff --git a/html-test/src/NamedDoc.hs b/html-test/src/NamedDoc.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/NamedDoc.hs
@@ -0,0 +1,5 @@
+{-# LANGUAGE Haskell2010 #-}
+module NamedDoc where
+
+-- $foo bar
+
diff --git a/html-test/src/NamespacedIdentifiers.hs b/html-test/src/NamespacedIdentifiers.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/NamespacedIdentifiers.hs
@@ -0,0 +1,14 @@
+{-# LANGUAGE Haskell2010 #-}
+module NamespacedIdentifiers where
+
+-- | A link to:
+--
+--   * the type t'Bar'
+--   * the constructor v'Bar'
+--   * the unimported but qualified type t'A.A'
+--   * the unimported but qualified value v'A.A'
+--
+data Foo = Bar
+
+-- | A link to the value v'Foo' (which shouldn't exist).
+data Bar
diff --git a/html-test/src/Nesting.hs b/html-test/src/Nesting.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Nesting.hs
@@ -0,0 +1,137 @@
+{-# LANGUAGE Haskell2010 #-}
+module Nesting where
+
+{-|
+* We can
+
+    * easily go back
+
+        1. some indentation
+
+    * levels
+
+1. @back at the top@
+
+-}
+d :: t
+d = undefined
+
+
+{-|
+* Beginning of list
+
+    * second list
+
+        * Some indented list but
+the presence of this text pushes it out of nesting back to the top.
+-}
+e :: t
+e = undefined
+
+
+{-|
+* Beginning of list
+
+    @
+    nested code
+        we preserve the space correctly
+    @
+-}
+f :: t
+f = undefined
+
+
+{-|
+* Beginning of list
+
+    * Nested list
+-}
+g :: t
+g = undefined
+
+{-|
+* Beginning of list
+
+    > nested
+    > bird
+    > tracks
+-}
+h :: t
+h = undefined
+
+{-|
+* Beginning of list
+This belongs to the list above!
+
+    > nested
+    > bird
+    > tracks
+    >
+    > another line
+    >   with indentation
+
+    >nested bird tracks
+    >  without leading space
+
+    * Next list
+    More of the indented list.
+
+        * Deeper
+
+            * Deeper
+
+                    * Even deeper!
+                    * No newline separation even in indented lists.
+-}
+i :: t
+i = undefined
+
+
+
+{-|
+[All this] Works for
+definition lists too.
+
+    > nested
+    > bird
+    > tracks
+
+    * Next list
+    with more of the indented list content.
+
+        Even more content on a new line.
+
+        1. Different type of list
+
+            (2) Deeper
+
+            >>> Here's an example in a list
+            example result
+
+                    [b] Even deeper!
+                    [c] No newline separation even in indented lists.
+                    We can have any paragraph level element that we normally
+                    can, like headers
+
+                    === Level 3 header
+                    with some content…
+
+                    * and even more lists inside
+-}
+j :: t
+j = undefined
+
+{-|
+      - list may start at arbitrary depth
+
+      - and consecutive items at that depth
+      belong to the same list
+
+      - of course we can still
+
+          * nest items like we are used to
+
+      - and then get back to initial list
+-}
+k :: t
+k = undefined
diff --git a/html-test/src/NoLayout.hs b/html-test/src/NoLayout.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/NoLayout.hs
@@ -0,0 +1,13 @@
+{-# LANGUAGE Haskell2010 #-}
+
+-- Haddock comments are parsed as separate declarations so we
+-- need to insert a ';' when using them with explicit layout.
+-- This should probably be changed.
+
+module NoLayout where {
+  -- | the function 'g'
+  ;
+  g :: Int;
+  g = undefined
+ }
+
diff --git a/html-test/src/NonGreedy.hs b/html-test/src/NonGreedy.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/NonGreedy.hs
@@ -0,0 +1,6 @@
+{-# LANGUAGE Haskell2010 #-}
+module NonGreedy where
+
+-- | <url1> <url2>
+f :: a
+f = undefined
diff --git a/html-test/src/Operators.hs b/html-test/src/Operators.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Operators.hs
@@ -0,0 +1,69 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE PatternSynonyms, TypeOperators, TypeFamilies, GADTs #-}
+{-# LANGUAGE FunctionalDependencies #-}
+
+-- | Test operators with or without fixity declarations
+module Operators where
+
+-- | Operator with no fixity
+(+-) :: a -> a -> a
+a +- _ = a
+
+-- | Operator with infixr 7
+(*/) :: a -> a -> a
+_ */ b = b
+infixr 7 */
+
+-- | Named function with infixl 3
+foo :: a -> a -> a
+foo a _ = a
+infixl 3 `foo`
+
+-- | Data type with operator constructors
+data Foo
+  = Foo `Bar` Foo -- ^ Has infixl 3
+  | Foo :- Foo  -- ^ Has infixr 5
+infixr 5 :-
+infixl 3 `Bar`
+
+-- | Pattern synonym, infixr 3
+pattern (:+) a b <- [a,b]
+infixr 3 :+
+
+-- | Type name, infixl 6 and GADT constructor
+data (a <-> b) where
+  (:<->) :: a -> b -> a <-> b
+infixl 6 <->
+infixr 6 :<->
+
+-- | Type family with fixity
+type family a ++ b
+infix 3 ++
+
+-- | Data family with fixity
+data family a ** b
+infix 9 **
+
+-- | Class with fixity, including associated types
+class a ><> b | a -> b where
+  -- Dec 2015: Added @a -> b@ functional dependency to clean up ambiguity
+  -- See GHC #11264
+  type a <>< b :: *
+  data a ><< b
+  (>><), (<<>) :: a -> b -> ()
+
+  -- | Multiple fixities
+  (**>), (**<), (>**), (<**) :: a -> a -> ()
+
+infixr 1 ><>
+infixl 2 <><
+infixl 3 ><<
+infixr 4 >><
+infixl 5 <<>
+
+infixr 8 **>, >**
+infixl 8 **<, <**
+
+-- | Type synonym with fixity
+type (a >-< b) = a <-> b
+infixl 6 >-<
diff --git a/html-test/src/OrphanInstances.hs b/html-test/src/OrphanInstances.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/OrphanInstances.hs
@@ -0,0 +1,9 @@
+{-# LANGUAGE Haskell2010 #-}
+module OrphanInstances where
+
+import OrphanInstancesType
+import OrphanInstancesClass
+
+-- | This is an orphan instance.
+instance AClass AType where
+  aClass (AType n) = n
diff --git a/html-test/src/OrphanInstancesClass.hs b/html-test/src/OrphanInstancesClass.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/OrphanInstancesClass.hs
@@ -0,0 +1,5 @@
+{-# LANGUAGE Haskell2010 #-}
+module OrphanInstancesClass (AClass(..)) where
+
+class AClass a where
+  aClass :: a -> Int
diff --git a/html-test/src/OrphanInstancesType.hs b/html-test/src/OrphanInstancesType.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/OrphanInstancesType.hs
@@ -0,0 +1,4 @@
+{-# LANGUAGE Haskell2010 #-}
+module OrphanInstancesType (AType(..)) where
+
+data AType = AType Int
diff --git a/html-test/src/PR643.hs b/html-test/src/PR643.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/PR643.hs
@@ -0,0 +1,4 @@
+{-# LANGUAGE Haskell2010 #-}
+module PR643 (test) where
+
+import PR643_1
diff --git a/html-test/src/PR643_1.hs b/html-test/src/PR643_1.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/PR643_1.hs
@@ -0,0 +1,8 @@
+{-# LANGUAGE Haskell2010 #-}
+module PR643_1 where
+
+infixr 5 `test`
+
+-- | Some big documentation
+test :: ()
+test = ()
diff --git a/html-test/src/PatternSyns.hs b/html-test/src/PatternSyns.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/PatternSyns.hs
@@ -0,0 +1,34 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE ExistentialQuantification, PatternSynonyms, PolyKinds, TypeOperators #-}
+
+-- | Testing some pattern synonyms
+module PatternSyns where
+
+-- | FooType doc
+data FooType x = FooCtor x
+
+-- | Pattern synonym for 'Foo' x
+pattern Foo x = FooCtor x
+
+-- | Pattern synonym for 'Bar' x
+pattern Bar x = FooCtor (Foo x)
+
+-- | Pattern synonym for (':<->')
+pattern x :<-> y = (Foo x, Bar y)
+
+-- | BlubType is existentially quantified
+data BlubType = forall x. Show x => BlubCtor x
+
+-- | Pattern synonym for 'Blub' x
+pattern Blub x = BlubCtor x
+
+-- | Doc for ('><')
+data (a :: *) >< b = Empty
+
+-- | Pattern for 'Empty'
+pattern E = Empty
+
+-- | Earlier ghc versions didn't allow explicit signatures
+-- on pattern synonyms.
+pattern PatWithExplicitSig :: Eq somex => somex -> FooType somex
+pattern PatWithExplicitSig x = FooCtor x
diff --git a/html-test/src/PromotedTypes.hs b/html-test/src/PromotedTypes.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/PromotedTypes.hs
@@ -0,0 +1,26 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE DataKinds #-}
+{-# LANGUAGE GADTs #-}
+{-# LANGUAGE KindSignatures #-}
+{-# LANGUAGE TypeOperators #-}
+
+
+module PromotedTypes where
+
+
+data RevList a = RNil | RevList a :> a
+
+
+data Pattern :: [*] -> * where
+  Nil :: Pattern '[]
+  Cons :: Maybe h -> Pattern t -> Pattern (h ': t)
+
+
+-- Unlike (:), (:>) does not have to be quoted on type level.
+data RevPattern :: RevList * -> * where
+    RevNil :: RevPattern RNil
+    RevCons :: Maybe h -> RevPattern t -> RevPattern (t :> h)
+
+
+data Tuple :: (*, *) -> * where
+    Tuple :: a -> b -> Tuple '(a, b)
diff --git a/html-test/src/Properties.hs b/html-test/src/Properties.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Properties.hs
@@ -0,0 +1,10 @@
+{-# LANGUAGE Haskell2010 #-}
+module Properties where
+
+-- | Fibonacci number of given 'Integer'.
+--
+-- prop> fib n <= fib (n + 1)
+fib :: Integer -> Integer
+fib 0 = 0
+fib 1 = 1
+fib n = fib (n - 1) + fib (n - 2)
diff --git a/html-test/src/PruneWithWarning.hs b/html-test/src/PruneWithWarning.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/PruneWithWarning.hs
@@ -0,0 +1,16 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# OPTIONS_HADDOCK prune #-}
+-- |
+-- What is tested here:
+--
+-- * If a binding has a deprecation message but no documentation, it is pruned
+--   when @OPTIONS_HADDOCK prune@ is used.
+--
+module PruneWithWarning (foo, bar) where
+
+foo :: Int
+foo = 23
+{-# DEPRECATED foo "use bar instead" #-}
+
+bar :: Int
+bar = 42
diff --git a/html-test/src/QuantifiedConstraints.hs b/html-test/src/QuantifiedConstraints.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/QuantifiedConstraints.hs
@@ -0,0 +1,12 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE QuantifiedConstraints #-}
+module QuantifiedConstraints where
+
+class Foo a where
+  fooed :: a
+
+needsParensAroundContext :: (forall x. Foo (f x)) => f Int
+needsParensAroundContext = fooed
+
+needsNoParensAroundContext :: Foo (f Int) => f Int
+needsNoParensAroundContext = fooed
diff --git a/html-test/src/QuasiExpr.hs b/html-test/src/QuasiExpr.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/QuasiExpr.hs
@@ -0,0 +1,35 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE TemplateHaskell #-}
+
+-- Used by QuasiQuote. Example taken from the GHC documentation.
+module QuasiExpr where
+
+import Language.Haskell.TH
+import Language.Haskell.TH.Quote
+
+data Expr  =  IntExpr Integer
+           |  AntiIntExpr String
+           |  BinopExpr BinOp Expr Expr
+           |  AntiExpr String
+    deriving Show
+
+data BinOp  =  AddOp
+            |  SubOp
+            |  MulOp
+            |  DivOp
+    deriving Show
+
+eval :: Expr -> Integer
+eval (IntExpr n)        = n
+eval (BinopExpr op x y) = (opToFun op) (eval x) (eval y)
+  where
+    opToFun AddOp = (+)
+    opToFun SubOp = (-)
+    opToFun MulOp = (*)
+    opToFun DivOp = div
+
+expr = QuasiQuoter parseExprExp undefined undefined undefined
+
+-- cheating...
+parseExprExp :: String -> Q Exp
+parseExprExp _ = [| BinopExpr AddOp (IntExpr 1) (IntExpr 2) |]
diff --git a/html-test/src/QuasiQuote.hs b/html-test/src/QuasiQuote.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/QuasiQuote.hs
@@ -0,0 +1,10 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE QuasiQuotes #-}
+
+-- example taken from the GHC documentation
+module QuasiQuote where
+
+import QuasiExpr
+
+val :: Integer
+val = eval [expr|1 + 2|]
diff --git a/html-test/src/SectionLabels.hs b/html-test/src/SectionLabels.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/SectionLabels.hs
@@ -0,0 +1,9 @@
+{-# LANGUAGE Haskell2010 #-}
+module SectionLabels
+  (
+    -- * Section heading#custom#
+    n
+  ) where
+
+n :: Int
+n = 3
diff --git a/html-test/src/SpuriousSuperclassConstraints.hs b/html-test/src/SpuriousSuperclassConstraints.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/SpuriousSuperclassConstraints.hs
@@ -0,0 +1,31 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE EmptyDataDecls, KindSignatures #-}
+-- |
+-- What is tested here:
+--
+-- Due to a change in GHC 7.6.1 we had a bug that superclass contraints were
+-- included in the instances list.  Edward K. repported it here:
+--
+--   <http://www.haskell.org/pipermail/haskell-cafe/2012-September/103600.html>
+--
+-- And here is the corresponding thread on glasgow-haskell-users:
+--
+--   <http://www.haskell.org/pipermail/glasgow-haskell-users/2012-September/022914.html>
+--
+-- It has been fixed in:
+--
+-- > 6ccf78e15a525282fef61bc4f58a279aa9c21771
+-- > Fix spurious superclass constraints bug.
+--
+module SpuriousSuperclassConstraints where
+
+import Control.Applicative
+
+data SomeType (f :: * -> *) a
+
+instance Functor (SomeType f) where
+  fmap = undefined
+
+instance Applicative f => Applicative (SomeType f) where
+  pure   = undefined
+  (<*>)  = undefined
diff --git a/html-test/src/TH.hs b/html-test/src/TH.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/TH.hs
@@ -0,0 +1,9 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE TemplateHaskell #-}
+
+module TH where
+
+import Language.Haskell.TH
+
+decl :: Q [Dec]
+decl = [d| f x = x|]
diff --git a/html-test/src/TH2.hs b/html-test/src/TH2.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/TH2.hs
@@ -0,0 +1,8 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE TemplateHaskell #-}
+
+module TH2 where
+
+import TH
+
+$( decl )
diff --git a/html-test/src/Table.hs b/html-test/src/Table.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Table.hs
@@ -0,0 +1,48 @@
+{-# LANGUAGE Haskell2010 #-}
+-- | This tests the table markup
+module Table
+  ( tableWithHeader
+  , tableWithoutHeader
+  , fancyTable
+  ) where
+
+-- | Table with header.
+--
+-- +------+--------------+------------------------------------------+
+-- | code | message      | description                              |
+-- +======+==============+==========================================+
+-- | 200  |   @OK@       | operation successful                     |
+-- +------+--------------+------------------------------------------+
+-- | 204  | @No Content@ | operation successful, no body returned   |
+-- +------+--------------+------------------------------------------+
+tableWithHeader :: a -> a
+tableWithHeader a = a
+
+-- | Table without header.
+--
+-- +------+--------------+------------------------------------------+
+-- | 200  |   @OK@       | operation successful                     |
+-- +------+--------------+------------------------------------------+
+-- | 204  | @No Content@ | operation successful, no body returned   |
+-- +------+--------------+------------------------------------------+
+-- | 404  | @Not Found@  | resource not found                       |
+-- +------+--------------+------------------------------------------+
+tableWithoutHeader :: a -> a
+tableWithoutHeader a = a
+
+-- | Fancy table.
+--
+-- +------------------------+------------+----------+----------+
+-- | Header row, column 1   | Header 2   | Header 3 | Header 4 |
+-- | (header rows optional) |            |          |          |
+-- +========================+============+==========+==========+
+-- | body row 1, column 1   | column 2   | column 3 | column 4 |
+-- +------------------------+------------+----------+----------+
+-- | 'tableWithHeader'      | Cells may span columns.          |
+-- +------------------------+------------+---------------------+
+-- | body row 3             | Cells may  | \[                  |
+-- +------------------------+ span rows. | f(n) = \sum_{i=1}   |
+-- | body row 4             |            | \]                  |
+-- +------------------------+------------+---------------------+
+fancyTable :: a -> a
+fancyTable x = x
diff --git a/html-test/src/Test.hs b/html-test/src/Test.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Test.hs
@@ -0,0 +1,424 @@
+{-# LANGUAGE Haskell2010 #-}
+-----------------------------------------------------------------------------
+-- |
+-- Module      :  Test
+-- Copyright   :  (c) Simon Marlow 2002
+-- License     :  BSD-style
+--
+-- Maintainer  :  libraries@haskell.org
+-- Stability   :  provisional
+-- Portability :  portable
+--
+-- This module illustrates & tests most of the features of Haddock.
+-- Testing references from the description: 'T', 'f', 'g', 'Visible.visible'.
+--
+-----------------------------------------------------------------------------
+
+-- This is plain comment, ignored by Haddock.
+{-# LANGUAGE Rank2Types, GADTs #-}
+module Test (
+
+	-- Section headings are introduced with '-- *':
+	-- * Type declarations
+
+	-- Subsection headings are introduced with '-- **' and so on.
+	-- ** Data types
+	T(..), T2, T3(..), T4(..), T5(..), T6(..),
+	N1(..), N2(..), N3(..), N4, N5(..), N6(..), N7(..),
+
+	-- ** Records
+	R(..), R1(..),
+
+	-- | test that we can export record selectors on their own:
+	p, q, u,
+
+	-- * Class declarations
+	C(a,b), D(..), E, F(..),
+
+	-- | Test that we can export a class method on its own:
+	a,
+
+	-- * Function types
+	f, g,
+
+	-- * Auxiliary stuff
+
+	-- $aux1
+
+	-- $aux2
+
+	-- $aux3
+
+	-- $aux4
+
+	-- $aux5
+
+	-- $aux6
+
+	-- $aux7
+
+	-- $aux8
+
+	-- $aux9
+
+	-- $aux10
+
+	-- $aux11
+
+	-- $aux12
+
+	-- | This is some inline documentation in the export list
+	--
+	-- > a code block using bird-tracks
+	-- > each line must begin with > (which isn't significant unless it
+	-- > is at the beginning of the line).
+
+	-- * A hidden module
+	module Hidden,
+
+	-- * A visible module
+	module Visible,
+
+	{-| nested-style doc comments -}
+
+	-- * Existential \/ Universal types
+	Ex(..),
+
+	-- * Type signatures with argument docs
+	k, l, m, o,
+
+	-- * A section
+	-- and without an intervening comma:
+	-- ** A subsection
+
+{-|
+ > a literal line
+
+ $ a non /literal/ line $
+-}
+
+	f',
+
+  withType, withoutType
+   ) where
+
+import Hidden
+import Visible
+import Data.Maybe
+
+bla = Nothing
+
+-- | This comment applies to the /following/ declaration
+-- and it continues until the next non-comment line
+data T a b
+ = A Int (Maybe Float) -- ^ This comment describes the 'A' constructor
+ | -- | This comment describes the 'B' constructor
+   B (T a b, T Int Float) -- ^
+
+-- | An abstract data declaration
+data T2 a b = T2 a b
+
+-- | A data declaration with no documentation annotations on the constructors
+data T3 a b = A1 a | B1 b
+
+-- A data declaration with no documentation annotations at all
+data T4 a b = A2 a | B2 b
+
+-- A data declaration documentation on the constructors only
+data T5 a b
+  = A3 a -- ^ documents 'A3'
+  | B3 b -- ^ documents 'B3'
+
+-- | Testing alternative comment styles
+data T6
+  -- | This is the doc for 'A4'
+  = A4
+  | B4
+  | -- ^ This is the doc for 'B4'
+
+    -- | This is the doc for 'C4'
+    C4
+
+-- | A newtype
+newtype N1 a = N1 a
+
+-- | A newtype with a fieldname
+newtype N2 a b = N2 {n :: a b}
+
+-- | A newtype with a fieldname, documentation on the field
+newtype N3 a b = N3 {n3 :: a b -- ^ this is the 'n3' field
+		    }
+
+-- | An abstract newtype - we show this one as data rather than newtype because
+-- the difference isn\'t visible to the programmer for an abstract type.
+newtype N4 a b = N4 a
+
+newtype N5 a b = N5 {n5 :: a b -- ^ no docs on the datatype or the constructor
+		    }
+
+newtype N6 a b = N6 {n6 :: a b
+		    }
+		 -- ^ docs on the constructor only
+
+-- | docs on the newtype and the constructor
+newtype N7 a b = N7 {n7 :: a b
+		    }
+		-- ^ The 'N7' constructor
+
+
+class (D a) => C a  where
+   -- |this is a description of the 'a' method
+   a :: IO a
+   b :: [a]
+   -- ^ this is a description of the 'b' method
+   c :: a -- c is hidden in the export list
+   c = undefined
+
+-- ^ This comment applies to the /previous/ declaration (the 'C' class)
+
+class D a where
+   d :: T a b
+   e :: (a,a)
+-- ^ This is a class declaration with no separate docs for the methods
+
+instance D Int where
+  d = undefined
+  e = undefined
+
+-- instance with a qualified class name
+instance Test.D Float where
+  d = undefined
+  e = undefined
+
+class E a where
+  ee :: a
+-- ^ This is a class declaration with no methods (or no methods exported)
+
+-- This is a class declaration with no documentation at all
+class F a where
+  ff :: a
+
+-- | This is the documentation for the 'R' record, which has four fields,
+-- 'p', 'q', 'r', and 's'.
+data R =
+  -- | This is the 'C1' record constructor, with the following fields:
+  C1 { p :: Int -- ^ This comment applies to the 'p' field
+     , q :: forall a . a->a  -- ^ This comment applies to the 'q' field
+     , -- | This comment applies to both 'r' and 's'
+       r,s :: Int
+     }
+  | C2 { t :: T1 -> (T2 Int Int)-> (T3 Bool Bool) -> (T4 Float Float) -> T5 () (),
+       u,v :: Int
+     }
+  -- ^ This is the 'C2' record constructor, also with some fields:
+
+-- | Testing different record commenting styles
+data R1
+  -- | This is the 'C3' record constructor
+  = C3 {
+	-- | The 's1' record selector
+	  s1 :: Int
+	-- | The 's2' record selector
+	, s2 :: Int
+	, s3 :: Int  -- NOTE: In the original examples/Test.hs in Haddock, there is an extra "," here.
+                     -- Since GHC doesn't allow that, I have removed it in this file.
+	-- ^ The 's3' record selector
+     }
+
+-- These section headers are only used when there is no export list to
+-- give the structure of the documentation:
+
+-- * This is a section header (level 1)
+-- ** This is a section header (level 2)
+-- *** This is a section header (level 3)
+
+{-|
+In a comment string we can refer to identifiers in scope with
+single quotes like this: 'T', and we can refer to modules by
+using double quotes: "Foo".  We can add emphasis /like this/.
+
+   * This is a bulleted list
+
+   - This is the next item (different kind of bullet)
+
+   (1) This is an ordered list
+
+   2. This is the next item (different kind of bullet)
+
+   [cat] a small, furry, domesticated mammal
+
+   [pineapple] a fruit grown in the tropics
+
+@
+     This is a block of code, which can include other markup: 'R'
+     formatting
+               is
+                 significant
+@
+
+> this is another block of code
+
+We can also include URLs in documentation: <http://www.haskell.org/>.
+-}
+
+f :: C a => a -> Int
+
+-- | we can export foreign declarations too
+foreign import ccall g :: Int -> IO CInt
+
+-- | this doc string has a parse error in it: \'
+h :: Int
+h = 42
+
+
+-- $aux1 This is some documentation that is attached to a name ($aux1)
+-- rather than a source declaration.  The documentation may be
+-- referred to in the export list using its name.
+--
+-- @ code block in named doc @
+
+-- $aux2 This is some documentation that is attached to a name ($aux2)
+
+-- $aux3
+-- @ code block on its own in named doc @
+
+-- $aux4
+--
+-- @ code block on its own in named doc (after newline) @
+
+{- $aux5 a nested, named doc comment
+
+   with a paragraph,
+
+   @ and a code block @
+-}
+
+-- some tests for various arrangements of code blocks:
+
+{- $aux6
+>test
+>test1
+
+@ test2
+  test3
+@
+-}
+
+{- $aux7
+@
+test1
+test2
+@
+-}
+
+{- $aux8
+>test3
+>test4
+-}
+
+{- $aux9
+@
+test1
+test2
+@
+
+>test3
+>test4
+-}
+
+{- $aux10
+>test3
+>test4
+
+@
+test1
+test2
+@
+-}
+
+-- This one is currently wrong (Haddock 0.4).  The @...@ part is
+-- interpreted as part of the bird-tracked code block.
+{- $aux11
+aux11:
+
+>test3
+>test4
+
+@
+test1
+test2
+@
+-}
+
+-- $aux12
+-- > foo
+--
+-- > bar
+--
+
+-- | A data-type using existential\/universal types
+data Ex a
+  = forall b . C b => Ex1 b
+  | forall b . Ex2 b
+  | forall b . C a => Ex3 b -- NOTE: I have added "forall b" here make GHC accept this file
+  | Ex4 (forall a . a -> a)
+
+-- | This is a function with documentation for each argument
+k :: T () () 	  -- ^ This argument has type 'T'
+  -> (T2 Int Int) -- ^ This argument has type 'T2 Int Int'
+  -> (T3 Bool Bool -> T4 Float Float) -- ^ This argument has type @T3 Bool Bool -> T4 Float Float@
+  -> T5 () ()	  -- ^ This argument has a very long description that should
+		  -- hopefully cause some wrapping to happen when it is finally
+		  -- rendered by Haddock in the generated HTML page.
+  -> IO ()	  -- ^ This is the result type
+
+-- This function has arg docs but no docs for the function itself
+l :: (Int, Int, Float) -- ^ takes a triple
+  -> Int -- ^ returns an 'Int'
+
+-- | This function has some arg docs
+m :: R
+  -> N1 ()	-- ^ one of the arguments
+  -> IO Int	-- ^ and the return value
+
+-- | This function has some arg docs but not a return value doc
+
+-- can't use the original name ('n') with GHC
+newn :: R		-- ^ one of the arguments, an 'R'
+     -> N1 ()		-- ^ one of the arguments
+     -> IO Int
+newn = undefined
+
+
+-- | A foreign import with argument docs
+foreign import ccall unsafe
+ o :: Float  -- ^ The input float
+   -> IO Float  -- ^ The output float
+
+-- | We should be able to escape this: \#\#\#
+
+-- p :: Int
+-- can't use the above original definition with GHC
+newp :: Int
+newp = undefined
+
+-- | a function with a prime can be referred to as 'f''
+-- but f' doesn't get link'd 'f\''
+f' :: Int
+
+-- | Comment on a definition without type signature
+withoutType = undefined
+
+-- | Comment on a definition with type signature
+withType :: Int
+withType = 1
+
+-- Add some definitions here so that this file can be compiled with GHC
+
+data T1
+f = undefined
+f' = undefined
+type CInt = Int
+k = undefined
+l = undefined
+m = undefined
diff --git a/html-test/src/Threaded.hs b/html-test/src/Threaded.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Threaded.hs
@@ -0,0 +1,11 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE TemplateHaskell #-}
+
+-- | Ensures haddock built with @-threaded@.
+module Threaded where
+
+import Threaded_TH
+
+-- | @$(forkTH)@ fails at compile time if haddock isn't using the
+-- threaded RTS.
+f = $(forkTH)
diff --git a/html-test/src/Threaded_TH.hs b/html-test/src/Threaded_TH.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Threaded_TH.hs
@@ -0,0 +1,14 @@
+{-# LANGUAGE Haskell2010 #-}
+-- | Imported by 'Threaded', since a TH splice can't be used in the
+-- module where it is defined.
+module Threaded_TH where
+
+import Control.Concurrent (forkOS)
+import Language.Haskell.TH.Syntax (Exp (LitE), Lit (IntegerL), Q, runIO)
+
+-- | forkOS requires the threaded RTS, so this TH fails if haddock was
+-- built without @-threaded@.
+forkTH :: Q Exp
+forkTH = do
+  _ <- runIO (forkOS (return ()))
+  return (LitE (IntegerL 0))
diff --git a/html-test/src/Ticket112.hs b/html-test/src/Ticket112.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Ticket112.hs
@@ -0,0 +1,10 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE MagicHash #-}
+
+module Ticket112 where
+
+import GHC.Prim
+
+-- | ...given a raw 'Addr#' to the string, and the length of the string.
+f :: a
+f = undefined
diff --git a/html-test/src/Ticket61.hs b/html-test/src/Ticket61.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Ticket61.hs
@@ -0,0 +1,4 @@
+{-# LANGUAGE Haskell2010 #-}
+module Ticket61 (module Ticket61_Hidden) where
+
+import Ticket61_Hidden
diff --git a/html-test/src/Ticket61_Hidden.hs b/html-test/src/Ticket61_Hidden.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Ticket61_Hidden.hs
@@ -0,0 +1,8 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# OPTIONS_HADDOCK hide #-}
+
+module Ticket61_Hidden where
+
+class C a where
+  -- | A comment about f
+  f :: a
diff --git a/html-test/src/Ticket75.hs b/html-test/src/Ticket75.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Ticket75.hs
@@ -0,0 +1,9 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE TypeOperators #-}
+module Ticket75 where
+
+data a :- b = Q
+
+-- | A reference to ':-'
+f :: Int
+f = undefined
diff --git a/html-test/src/TitledPicture.hs b/html-test/src/TitledPicture.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/TitledPicture.hs
@@ -0,0 +1,8 @@
+{-# LANGUAGE Haskell2010 #-}
+module TitledPicture where
+
+-- | Picture for 'foo' without a title <<bar>>
+foo = 5
+
+-- | Picture for 'bar' with title <<un∣∁∘ δ∈>>
+bar = 6
diff --git a/html-test/src/TypeFamilies.hs b/html-test/src/TypeFamilies.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/TypeFamilies.hs
@@ -0,0 +1,93 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE TypeFamilies, UndecidableInstances, PolyKinds, TypeOperators, DataKinds, MultiParamTypeClasses, GADTs #-}
+
+-- | Doc for: module TypeFamilies
+module TypeFamilies where
+
+import qualified TypeFamilies2 as TF
+
+-- | Doc for: data X
+data X
+  = X   -- ^ Doc for: X
+  | XX  -- ^ Doc for: XX
+  | XXX -- ^ Doc for: XXX
+
+-- | Doc for: data Y
+data Y
+
+-- | Doc for: data Z
+data Z = ZA | ZB
+
+-- | Doc for: class Test a
+class Test a
+
+-- | Doc for: instance Test X
+instance Test X
+-- | Doc for: instance Test Y
+instance Test Y
+
+-- | Doc for: type family Foo a
+type family Foo a :: k
+
+-- | Doc for: type instance Foo X = Y
+type instance Foo X = Y
+-- | Doc for: type instance Foo Y = X
+type instance Foo Y = X
+
+-- | Doc for: data family Bat a
+data family Bat (a :: k) :: *
+
+-- | Doc for: data instance Bat X
+data instance Bat X
+  = BatX X -- ^ Doc for: BatX X
+  | BatXX { aaa :: X , bbb :: Y } -- ^ Doc for: BatXX { ... }
+
+-- | Doc for: data instance Bat Y
+data instance Bat Y = BatY Y -- ^ Doc for: BatY Y
+
+-- | Doc for: data instance Bat Z
+data instance Bat (z :: Z) where
+  BatZ1 :: Z -> Bat ZA
+  BatZ2 :: { batx :: X, baty :: Y } -> Bat ZB
+
+-- | Doc for: class Assoc a
+class Assoc a where
+  -- | Doc for: data AssocD a
+  data AssocD a :: *
+  -- | Doc for: type AssocT a
+  type AssocT a :: *
+
+-- | Doc for: instance Assoc X
+instance Assoc X where
+  -- | Doc for: data AssocD X = AssocX
+  data AssocD X = AssocX -- ^ Doc for: AssocX
+  -- | Doc for: type AssocT X = Foo X
+  type AssocT X = Foo X
+
+-- | Doc for: instance Assoc Y
+instance Assoc Y where
+  -- | Doc for: data AssocD Y = AssocY
+  data AssocD Y = AssocY -- ^ Doc for: AssocY
+  -- | Doc for: type AssocT Y = Bat Y
+  type AssocT Y = Bat Y
+
+-- | Doc for: type family Bar b
+type family Bar b where
+  Bar X = X
+  Bar y = Y
+
+type family (<>) (a :: k) (b :: k) :: k
+
+type instance X <> a = X
+type instance Y <> a = a
+
+type instance XXX <> XX = 'X
+
+class (><) (a :: k) (b :: k)
+instance XX >< XXX
+
+-- | External instance
+
+type instance TF.Foo X = Y
+
+data instance TF.Bar Y
diff --git a/html-test/src/TypeFamilies2.hs b/html-test/src/TypeFamilies2.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/TypeFamilies2.hs
@@ -0,0 +1,40 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE TypeFamilies #-}
+-- This tests what happens if we have unexported types
+-- in type instances. The expected behaviour is
+-- that we get the instance, Y is not linked and
+-- Haddock shows a linking warning.
+--
+-- The other families and instances that are not exported should not
+-- show up at all
+module TypeFamilies2 (W, Foo, Bar) where
+
+-- | Exported type
+data W
+
+-- | Hidden type
+data Z
+
+-- | Exported type family
+type family Foo a
+
+-- | Should be visible, but with a hidden right hand side
+type instance Foo W = Z
+
+-- | Should be hidden
+type instance Foo Z = W
+
+-- | Exported data family
+data family Bar a
+
+-- | Shown because BarX is still exported despite Z being hidden
+data instance Bar W = BarX Z
+
+-- | Should be completely invisible, including instances
+type family Invisible a
+type instance Invisible W = Z
+type instance Invisible Z = W
+
+data family Invisible2 a
+data instance Invisible2 W = Invis  Z
+data instance Invisible2 Z = Invis' W
diff --git a/html-test/src/TypeFamilies3.hs b/html-test/src/TypeFamilies3.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/TypeFamilies3.hs
@@ -0,0 +1,22 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE TypeFamilies #-}
+
+module TypeFamilies3 where
+
+-- | A closed type family
+type family Foo a where
+  Foo () = Int
+  Foo _ = ()
+
+-- | An open family
+type family Bar a
+
+type instance Bar Int = ()
+type instance Bar () = Int
+
+-- | A data family
+data family Baz a
+
+data instance Baz () = Baz1
+data instance Baz Int = Baz2 Bool
+newtype instance Baz Double = Baz3 Float
diff --git a/html-test/src/TypeOperators.hs b/html-test/src/TypeOperators.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/TypeOperators.hs
@@ -0,0 +1,28 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE TypeOperators, GADTs, MultiParamTypeClasses, FlexibleContexts #-}
+module TypeOperators where
+
+data a :-: b
+
+data (a :+: b) c
+
+data a `Op` b
+
+newtype (g `O` f) a = O { unO :: g (f a) }
+
+class a <=> b
+
+biO :: (g `O` f) a
+biO = undefined
+
+f :: (a ~ b) => a -> b
+f = id
+
+g :: (a ~ b, b ~ c) => a -> c
+g = id
+
+x :: ((a :-: a) <=> (a `Op` a)) => a
+x = undefined
+
+y :: (a <=> a, (a `Op` a) <=> a) => a
+y = undefined
diff --git a/html-test/src/UnboxedStuff.hs b/html-test/src/UnboxedStuff.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/UnboxedStuff.hs
@@ -0,0 +1,19 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE UnboxedSums, UnboxedTuples #-}
+module UnboxedStuff where
+
+data X
+data Y
+data Z
+
+-- * Unboxed type constructors
+
+unboxedUnit :: (# #) -> (# #)
+unboxedUnit  = undefined
+
+unboxedTuple :: (# X, Y #) -> (# X, Y, Z #)
+unboxedTuple = undefined 
+
+unboxedSum :: (# X | Y #) -> (# X | Y | Z #)
+unboxedSum = undefined 
+
diff --git a/html-test/src/Unicode.hs b/html-test/src/Unicode.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Unicode.hs
@@ -0,0 +1,7 @@
+{-# LANGUAGE Haskell2010 #-}
+module Unicode where
+
+-- | γλώσσα
+x :: Int
+x = 1
+
diff --git a/html-test/src/Unicode2.hs b/html-test/src/Unicode2.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Unicode2.hs
@@ -0,0 +1,19 @@
+{-# LANGUAGE Haskell2010 #-}
+module Unicode2 where
+
+-- | All of the following work with a unicode character ü:
+--
+--   * an italicized /ü/
+--   
+--   * inline code @ü@
+--
+--   * a code block:
+--
+--   > ü
+--
+--   * a url <https://www.google.com/search?q=ü>
+-- 
+--   * a link to 'ü'
+--
+ü :: ()
+ü = ()
diff --git a/html-test/src/Visible.hs b/html-test/src/Visible.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Visible.hs
@@ -0,0 +1,4 @@
+{-# LANGUAGE Haskell2010 #-}
+module Visible where
+visible :: Int -> Int
+visible a = a
diff --git a/html/Classic.theme/haskell_icon.gif b/html/Classic.theme/haskell_icon.gif
deleted file mode 100644
Binary files a/html/Classic.theme/haskell_icon.gif and /dev/null differ
diff --git a/html/Classic.theme/minus.gif b/html/Classic.theme/minus.gif
deleted file mode 100644
Binary files a/html/Classic.theme/minus.gif and /dev/null differ
diff --git a/html/Classic.theme/plus.gif b/html/Classic.theme/plus.gif
deleted file mode 100644
Binary files a/html/Classic.theme/plus.gif and /dev/null differ
diff --git a/html/Classic.theme/xhaddock.css b/html/Classic.theme/xhaddock.css
deleted file mode 100644
--- a/html/Classic.theme/xhaddock.css
+++ /dev/null
@@ -1,487 +0,0 @@
-* {
-	margin: 0;
-	padding: 0;
-}
-
-body { 
-  	background-color: #ffffff;
-  	color: #000000;
-  	font-size: 100%;
-	font-family: sans-serif;
-	padding: 8px;
-}
-
-a:link    { color: #0000e0; text-decoration: none }
-a:visited { color: #0000a0; text-decoration: none }
-a:hover   { background-color: #e0e0ff; text-decoration: none }
-
-/* <tt> font is a little too small in MSIE */
-tt  { font-size: 100%; }
-pre { font-size: 100%; }
-.keyword { text-decoration: underline; }
-.caption {
-	font-weight: bold;
-	margin: 0;
-	padding: 0;
-}
-
-h1 {
-  padding-top: 15px;
-  font-weight: bold;
-  font-size: 150%;
-}
-
-h2 {
-  padding-top: 10px;
-  font-weight: bold;
-  font-size: 130%
-  }
-
-h3 {
-  padding-top: 5px;
-  font-weight: bold;
-  font-size: 110%
-  }
-
-h4, h5 {
-  font-weight: bold;
-  font-size: 100%
-  }
-
-h1, h2, h3, h4, h5 {
-	margin-top: 0.5em;
-	margin-bottom: 0.5em;
-}
-
-p  { 
-	padding-top: 2px;
-	padding-left: 10px;
-}
-
-ul, ol, dl {
-	padding-top: 2px;
-	padding-left: 10px;
-	margin-left: 2.5em;
-}
-
-pre  { 
-	padding-top: 2px;
-	padding-left: 20px;
-}
-
-* + p, * + pre {
-	margin-top: 1em;
-}
-.caption + p, .src + p {
-	margin-top: 0;
-}
-
-.def {
-	font-weight: bold;
-}
-
-ul.links {
-	list-style: none;
-	text-align: left;
-	float: right;
-	display: inline-table;
-	padding: 0;
-}
-
-ul.links li {
-	display: inline;
-	border-left-width: 1px;
-	border-left-color: #ffffff;
-	border-left-style: solid;
-	white-space: nowrap;
-	padding: 1px 5px;
-}
-
-.hide {	display: none; }
-.show { }
-.collapser {
-  background: url(minus.gif) no-repeat 0 0.3em;
-}
-.expander {
-  background: url(plus.gif) no-repeat 0 0.3em;
-}
-.collapser, .expander {
-  padding-left: 14px;
-  cursor: pointer;
-}
-
-#package-header {
-	color: #ffffff;
-	padding: 5px 5px 5px 31px;
-	margin: 0 0 1px;
-	background: #000099 url(haskell_icon.gif) no-repeat 5px 6px;
-	position: relative;
-}
-
-#package-header .caption {
-	font-weight: normal;
-	font-style: normal;
-}
-#package-header a:link    { color: #ffffff }
-#package-header a:visited { color: #ffff00 }
-#package-header a:hover   { background-color: #6060ff; }
-#package-header ul.links li:hover { background-color: #6060ff; }
-
-div#style-menu-holder {
-	position: relative;
-	z-index: 2;
-	display: inline;
-}
-
-#style-menu {
-	position: absolute;
-	z-index: 1;
-	overflow: visible;
-	background-color: #000099;
-	margin: 0;
-	width: 6em;
-	text-align: center;
-	right: 0;
-	padding: 2px 2px 1px;
-}
-
-#style-menu li {
-	display: list-item;
-	border-style: none;
-	margin: 0;
-	padding: 3px;
-	color: #000;
-	list-style-type: none;
-	border-top: 1px solid #ffffff;
-}
-
-#module-header {
-	background-color: #0077dd;
-	padding: 5px;
-}
-
-#module-header .caption {
-	font-size: 200%;
-	padding: .35em 0;
-	font-weight: normal;
-	font-style: normal;
-}
-
-table.info {
-	color: #ffffff;
-	display: block;
-	float: right;
-	max-width: 50%;
-}
-
-.info th, .info td {
-	text-align: left;
-	padding: 0 10px 0 0;
-}
-
-
-#table-of-contents {
-	margin-top: 1em;
-	margin-bottom: 2em;
-}
-
-#table-of-contents ul {
-	margin-top: 1em;
-	margin-bottom: 1em;
-	margin-left: 0;
-	list-style-type: none;
-	padding: 0;
-}
-
-#table-of-contents ul ul {
-	margin-left: 2.5em;
-}
-
-#description .caption,
-#synopsis .caption,
-#module-list .caption,
-#index .caption {
-  padding-top: 15px;
-  font-weight: bold;
-  font-size: 150%	
-}
-
-#synopsis {
-	margin-bottom: 2em;
-}
-
-#synopsis .expander,
-#synopsis .collapser {
-  background: none;
-  padding-left: inherit;
-}
-
-#synopsis .hide {
-  display: inherit;
-}
-
-#synopsis ul {
-	margin: 0;
-	padding-top: 0;
-	padding-left: 20px;
-	list-style-type: none;
-}
-
-#synopsis li {
-	margin-top: 8px;
-	margin-bottom: 8px;
-	padding: 3px;
-}
-
-#synopsis li li {
-	padding: 0;
-	margin-top: 0;
-	margin-bottom: 0;
-}
-
-
-div.top {
-	margin-top: 1em;
-	clear: left;
-	margin-bottom: 1em;
-}
-
-div.top h5 {
-	margin-left: 10px;
-}
-
-
-.src {
-	padding: 3px;
-	background-color: #f0f0f0;
-	font-family: monospace;
-	margin-bottom: 0;
-}
-
-
-.src a.link {
-	float: right;
-	border-left-width: 1px;
-	border-left-color: #000099;
-	border-left-style: solid;
-	white-space: nowrap;
-	font-size: small;
-	padding: 0 8px 2px 5px;
-	margin-right: -3px;
-	background-color: #f0f0f0;
-}
-
-div.subs {
-	margin-left: 10px;
-	clear: both;
-	margin-top: 2px;
-}
-
-.subs dl {
-	margin-left: 0;
-}
-
-.subs dl dl {
-	padding-left: 0;
-	padding-top: 4px;
-}
-
-.subs dd
-{
-  margin: 2px 0 9px 2em;
-}
-
-.subs dd.empty {
-  display: none;
-}
-
-.subs table {
-	margin-left: 10px;
-	border-spacing: 1px 1px;
-	margin-top: 4px;
-	margin-bottom: 4px;
-}
-
-.subs table table {
-	margin-left: 0;
-}
-
-.arguments .caption,
-.fields .caption {
-	display: none;
-}
-
-/* need extra .subs in the selector to make it override the rules for .subs and .subs table */
-
-.subs.arguments {
-	margin: 0;
-}
-
-.subs.arguments table {
-	border-spacing: 0;
-	margin-top: 0;
-	margin-bottom: 0;
-}
-
-.subs.arguments td.src {
-	white-space: nowrap;
-}
-
-.subs.arguments + p {
-	margin-top: 0;
-}
-
-.subs.associated-types,
-.subs.methods {
-	margin-left: 20px;
-}
-
-.subs.associated-types .caption,
-.subs.methods .caption {
-	margin-top: 0.5em;
-	margin-left: -10px;
-}
-
-.subs.associated-types .src + .src,
-.subs.methods .src + .src {
-	margin-top: 8px;
-}
-
-p.arg {
-	margin-bottom: 0;
-}
-p.arg span {
-  background-color: #f0f0f0; 
-  font-family: monospace;
-  white-space: nowrap;
-	float: none;
-}
-
-
-img.coll {
-	width : 0.75em; height: 0.75em; margin-bottom: 0; margin-right: 0.5em 
-}
-
-
-td.arg {
-  padding: 3px;
-  background-color: #f0f0f0;
-  font-family: monospace;
-  margin-bottom: 0;
-}
-
-td.rdoc p {
-	margin-bottom: 0;
-}
-
-
-
-#footer {
-  background-color: #000099;
-  color: #ffffff;
-  padding: 4px
-  }
-  
-#footer p {
-	padding: 1px;
-	margin: 0;
-}
-
-#footer  a:link {
-  color: #ffffff;
-  text-decoration: underline
-  }
-#footer  a:visited {
-  color: #ffff00
-  }
-#footer  a:hover {
-  background-color: #6060ff
-  }
-
-
-#module-list ul {
-	list-style: none;
-	padding-bottom: 15px;
-	padding-left: 2px;
-	margin: 0;
-}
-
-#module-list ul ul {
-	padding-bottom: 0;
-	padding-left: 20px;
-}
-
-#module-list li .package {
-	float: right;
-}
-#mini #module-list .caption {
-	display: none;
-}
-
-#index .caption {
-}
-
-#alphabet ul {
-	list-style: none;
-	padding: 0;
-	margin: 0.5em 0 0;
-}
-
-#alphabet li {
-	display: inline;
-	margin: 0 0.2em;
-}
-
-#index .src {
-	background: none;
-	font-family: inherit;
-}
-
-#index td.alt {
-	padding-left: 2em;
-}
-
-#index td {
-	padding-top: 2px;
-	padding-bottom: 1px;
-	padding-right: 1em;
-}
-
-
-#mini h1 { font-size: 130%; }
-#mini h2 { font-size: 110%; }
-#mini h3 { font-size: 100%; }
-#mini h1, #mini h2, #mini h3 {
-  margin-top: 0.5em;
-  margin-bottom: 0.25em;
-  padding: 0 0;
-}
-
-#mini h1 { border-bottom: 1px solid #ccc; }
-
-#mini #module-header {
-	margin: 0;
-	padding: 0;
-}
-#mini #module-header .caption {
-  font-size: 130%;
-  background: #0077dd;
-  padding: 0.25em;
-  height: inherit;
-  margin: 0;
-}
-
-#mini #interface .top {
-	margin: 0;
-	padding: 0;
-}
-#mini #interface .src {
-	margin: 0;
-	padding: 0;
-	font-family: inherit;
-	background: inherit;
-}
-
-
-
-
diff --git a/html/Ocean.std-theme/hslogo-16.png b/html/Ocean.std-theme/hslogo-16.png
deleted file mode 100644
Binary files a/html/Ocean.std-theme/hslogo-16.png and /dev/null differ
diff --git a/html/Ocean.std-theme/minus.gif b/html/Ocean.std-theme/minus.gif
deleted file mode 100644
Binary files a/html/Ocean.std-theme/minus.gif and /dev/null differ
diff --git a/html/Ocean.std-theme/ocean.css b/html/Ocean.std-theme/ocean.css
deleted file mode 100644
--- a/html/Ocean.std-theme/ocean.css
+++ /dev/null
@@ -1,542 +0,0 @@
-/* @group Fundamentals */
-
-* { margin: 0; padding: 0 }
-
-/* Is this portable? */
-html {
-  background-color: white;
-  width: 100%;
-  height: 100%;
-}
-
-body {
-  background: white;
-  color: black;
-  text-align: left;
-  min-height: 100%;
-  position: relative;
-}
-
-p {
-  margin: 0.8em 0;
-}
-
-ul, ol {
-  margin: 0.8em 0 0.8em 2em;
-}
-
-dl {
-  margin: 0.8em 0;
-}
-
-dt {
-  font-weight: bold;
-}
-dd {
-  margin-left: 2em;
-}
-
-a { text-decoration: none; }
-a[href]:link { color: rgb(196,69,29); }
-a[href]:visited { color: rgb(171,105,84); }
-a[href]:hover { text-decoration:underline; }
-
-/* @end */
-
-/* @group Fonts & Sizes */
-
-/* Basic technique & IE workarounds from YUI 3
-   For reasons, see:
-      http://yui.yahooapis.com/3.1.1/build/cssfonts/fonts.css
- */
- 
-body {
-	font:13px/1.4 sans-serif;
-	*font-size:small; /* for IE */
-	*font:x-small; /* for IE in quirks mode */
-}
-
-h1 { font-size: 146.5%; /* 19pt */ } 
-h2 { font-size: 131%;   /* 17pt */ }
-h3 { font-size: 116%;   /* 15pt */ }
-h4 { font-size: 100%;   /* 13pt */ }
-h5 { font-size: 100%;   /* 13pt */ }
-
-select, input, button, textarea {
-	font:99% sans-serif;
-}
-
-table {
-	font-size:inherit;
-	font:100%;
-}
-
-pre, code, kbd, samp, tt, .src {
-	font-family:monospace;
-	*font-size:108%;
-	line-height: 124%;
-}
-
-.links, .link {
-  font-size: 85%; /* 11pt */
-}
-
-#module-header .caption {
-  font-size: 182%; /* 24pt */
-}
-
-.info  {
-  font-size: 85%; /* 11pt */
-}
-
-#table-of-contents, #synopsis  {
-  /* font-size: 85%; /* 11pt */
-}
-
-
-/* @end */
-
-/* @group Common */
-
-.caption, h1, h2, h3, h4, h5, h6 { 
-  font-weight: bold;
-  color: rgb(78,98,114);
-  margin: 0.8em 0 0.4em;
-}
-
-* + h1, * + h2, * + h3, * + h4, * + h5, * + h6 {
-  margin-top: 2em;
-}
-
-h1 + h2, h2 + h3, h3 + h4, h4 + h5, h5 + h6 {
-  margin-top: inherit;
-}
-
-ul.links {
-  list-style: none;
-  text-align: left;
-  float: right;
-  display: inline-table;
-  margin: 0 0 0 1em;
-}
-
-ul.links li {
-  display: inline;
-  border-left: 1px solid #d5d5d5; 
-  white-space: nowrap;
-  padding: 0;
-}
-
-ul.links li a {
-  padding: 0.2em 0.5em;
-}
-
-.hide { display: none; }
-.show { display: inherit; }
-.clear { clear: both; }
-
-.collapser {
-  background-image: url(minus.gif);
-  background-repeat: no-repeat;
-}
-.expander {
-  background-image: url(plus.gif);
-  background-repeat: no-repeat;
-}
-p.caption.collapser,
-p.caption.expander {
-  background-position: 0 0.4em;
-}
-.collapser, .expander {
-  padding-left: 14px;
-  margin-left: -14px;
-  cursor: pointer;
-}
-
-pre {
-  padding: 0.25em;
-  margin: 0.8em 0;
-  background: rgb(229,237,244);
-  overflow: auto;
-  border-bottom: 0.25em solid white;
-  /* white border adds some space below the box to compensate
-     for visual extra space that paragraphs have between baseline
-     and the bounding box */
-}
-
-.src {
-  background: #f0f0f0;
-  padding: 0.2em 0.5em;
-}
-
-.keyword { font-weight: normal; }
-.def { font-weight: bold; }
-
-
-/* @end */
-
-/* @group Page Structure */
-
-#content {
-  margin: 0 auto;
-  padding: 0 2em 6em;
-}
-
-#package-header {
-  background: rgb(41,56,69);
-  border-top: 5px solid rgb(78,98,114);
-  color: #ddd;
-  padding: 0.2em;
-  position: relative;
-  text-align: left;
-}
-
-#package-header .caption {
-  background: url(hslogo-16.png) no-repeat 0em;
-  color: white;
-  margin: 0 2em;
-  font-weight: normal;
-  font-style: normal;
-  padding-left: 2em;
-}
-
-#package-header a:link, #package-header a:visited { color: white; }
-#package-header a:hover { background: rgb(78,98,114); }
-
-#module-header .caption {
-  color: rgb(78,98,114);
-  font-weight: bold;
-  border-bottom: 1px solid #ddd;
-}
-
-table.info {
-  float: right;
-  padding: 0.5em 1em;
-  border: 1px solid #ddd;
-  color: rgb(78,98,114);
-  background-color: #fff;
-  max-width: 40%;
-  border-spacing: 0;
-  position: relative;
-  top: -0.5em;
-  margin: 0 0 0 2em;
-}
-
-.info th {
-	padding: 0 1em 0 0;
-}
-
-div#style-menu-holder {
-  position: relative;
-  z-index: 2;
-  display: inline;
-}
-
-#style-menu {
-  position: absolute;
-  z-index: 1;
-  overflow: visible;
-  background: #374c5e;
-  margin: 0;
-  text-align: center;
-  right: 0;
-  padding: 0;
-  top: 1.25em;
-}
-
-#style-menu li {
-	display: list-item;
-	border-style: none;
-	margin: 0;
-	padding: 0;
-	color: #000;
-	list-style-type: none;
-}
-
-#style-menu li + li {
-	border-top: 1px solid #919191;
-}
-
-#style-menu a {
-  width: 6em;
-  padding: 3px;
-  display: block;
-}
-
-#footer {
-  background: #ddd;
-  border-top: 1px solid #aaa;
-  padding: 0.5em 0;
-  color: #666;
-  text-align: center;
-  position: absolute;
-  bottom: 0;
-  width: 100%;
-  height: 3em;
-}
-
-/* @end */
-
-/* @group Front Matter */
-
-#table-of-contents {
-  float: right;
-  clear: right;
-  background: #faf9dc;
-  border: 1px solid #d8d7ad;
-  padding: 0.5em 1em;
-  max-width: 20em;
-  margin: 0.5em 0 1em 1em;
-}
-
-#table-of-contents .caption {
-  text-align: center;
-  margin: 0;
-}
-
-#table-of-contents ul {
-  list-style: none;
-  margin: 0;
-}
-
-#table-of-contents ul ul {
-  margin-left: 2em;
-}
-
-#description .caption {
-  display: none;
-}
-
-#synopsis {
-  display: none;
-}
-
-.no-frame #synopsis {
-  display: block;
-  position: fixed;
-  right: 0;
-  height: 80%;
-  top: 10%;
-  padding: 0;
-}
-
-#synopsis .caption {
-  float: left;
-  width: 29px;
-  color: rgba(255,255,255,0);
-  height: 110px;
-  margin: 0;
-  font-size: 1px;
-  padding: 0;
-}
-
-#synopsis p.caption.collapser {
-  background: url(synopsis.png) no-repeat -64px -8px;
-}
-
-#synopsis p.caption.expander {
-  background: url(synopsis.png) no-repeat 0px -8px;
-}
-
-#synopsis ul {
-  height: 100%;
-  overflow: auto;
-  padding: 0.5em;
-  margin: 0;
-}
-
-#synopsis ul ul {
-  overflow: hidden;
-}
-
-#synopsis ul,
-#synopsis ul li.src {
-  background-color: #faf9dc;
-  white-space: nowrap;
-  list-style: none;
-  margin-left: 0;
-}
-
-/* @end */
-
-/* @group Main Content */
-
-#interface div.top { margin: 2em 0; }
-#interface h1 + div.top,
-#interface h2 + div.top,
-#interface h3 + div.top,
-#interface h4 + div.top,
-#interface h5 + div.top {
- 	margin-top: 1em;
-}
-#interface p.src .link {
-  float: right;
-  color: #919191;
-  border-left: 1px solid #919191;
-  background: #f0f0f0;
-  padding: 0 0.5em 0.2em;
-  margin: 0 -0.5em 0 0.5em;
-}
-
-#interface table { border-spacing: 2px; }
-#interface td {
-  vertical-align: top;
-  padding-left: 0.5em;
-}
-#interface td.src {
-  white-space: nowrap;
-}
-#interface td.doc p {
-  margin: 0;
-}
-#interface td.doc p + p {
-  margin-top: 0.8em;
-}
-
-.subs dl {
-  margin: 0;
-}
-
-.subs dt {
-  float: left;
-  clear: left;
-  display: block;
-  margin: 1px 0;
-}
-
-.subs dd {
-  float: right;
-  width: 90%;
-  display: block;
-  padding-left: 0.5em;
-  margin-bottom: 0.5em;
-}
-
-.subs dd.empty {
-  display: none;
-}
-
-.subs dd p {
-  margin: 0;
-}
-
-.top p.src {
-  border-top: 1px solid #ccc;
-}
-
-.subs, .doc {
-  /* use this selector for one level of indent */
-  padding-left: 2em;
-}
-
-.arguments {
-  margin-top: -0.4em;
-}
-.arguments .caption {
-  display: none;
-}
-
-.fields { padding-left: 1em; }
-
-.fields .caption { display: none; }
-
-.fields p { margin: 0 0; }
-
-/* this seems bulky to me
-.methods, .constructors {
-  background: #f8f8f8;
-  border: 1px solid #eee;
-}
-*/
-
-/* @end */
-
-/* @group Auxillary Pages */
-
-#mini {
-  margin: 0 auto;
-  padding: 0 1em 1em;
-}
-
-#mini > * {
-  font-size: 93%; /* 12pt */  
-}
-
-#mini #module-list .caption,
-#mini #module-header .caption {
-  font-size: 125%; /* 15pt */
-}
-
-#mini #interface h1,
-#mini #interface h2,
-#mini #interface h3,
-#mini #interface h4 {
-  font-size: 109%; /* 13pt */
-  margin: 1em 0 0;
-}
-
-#mini #interface .top,
-#mini #interface .src {
-  margin: 0;
-}
-
-#mini #module-list ul {
-  list-style: none;
-  margin: 0;
-}
-
-#alphabet ul {
-	list-style: none;
-	padding: 0;
-	margin: 0.5em 0 0;
-	text-align: center;
-}
-
-#alphabet li {
-	display: inline;
-	margin: 0 0.25em;
-}
-
-#alphabet a {
-	font-weight: bold;
-}
-
-#index .caption,
-#module-list .caption { font-size: 131%; /* 17pt */ }
-
-#index table {
-  margin-left: 2em;
-}
-
-#index .src {
-  font-weight: bold;
-}
-#index .alt {
-  font-size: 77%; /* 10pt */
-  font-style: italic;
-  padding-left: 2em;
-}
-
-#index td + td {
-  padding-left: 1em;
-}
-
-#module-list ul {
-  list-style: none;
-  margin: 0 0 0 2em;
-}
-
-#module-list li {
-  clear: right;
-}
-
-#module-list span.collapser,
-#module-list span.expander {
-  background-position: 0 0.3em;
-}
-
-#module-list .package {
-  float: right;
-}
-
-/* @end */
diff --git a/html/Ocean.std-theme/plus.gif b/html/Ocean.std-theme/plus.gif
deleted file mode 100644
Binary files a/html/Ocean.std-theme/plus.gif and /dev/null differ
diff --git a/html/Ocean.std-theme/synopsis.png b/html/Ocean.std-theme/synopsis.png
deleted file mode 100644
Binary files a/html/Ocean.std-theme/synopsis.png and /dev/null differ
diff --git a/html/frames.html b/html/frames.html
deleted file mode 100644
--- a/html/frames.html
+++ /dev/null
@@ -1,28 +0,0 @@
-<!DOCTYPE html 
-     PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
-     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml">
-<head>
-<script src="haddock-util.js" type="text/javascript"></script>
-<script type="text/javascript"><!--
-/*
-
-  The synopsis frame needs to be updated using javascript, so we hide
-  it by default and only show it if javascript is enabled.
-
-  TODO: provide some means to disable it.
-*/
-function load() {
-  var d = document.getElementById("inner-fs");
-  d.rows = "50%,50%";
-  postReframe();
-}
---></script>
-<frameset id="outer-fs" cols="25%,75%" onload="load()">
-  <frameset id="inner-fs" rows="100%,0%">
-    <frame src="index-frames.html" name="modules">
-    <frame src="" name="synopsis">
-  </frameset>
-  <frame src="index.html" name="main">
-</frameset>
-</html>
diff --git a/html/haddock-util.js b/html/haddock-util.js
deleted file mode 100644
--- a/html/haddock-util.js
+++ /dev/null
@@ -1,344 +0,0 @@
-// Haddock JavaScript utilities
-
-var rspace = /\s\s+/g,
-	  rtrim = /^\s+|\s+$/g;
-
-function spaced(s) { return (" " + s + " ").replace(rspace, " "); }
-function trim(s)   { return s.replace(rtrim, ""); }
-
-function hasClass(elem, value) {
-  var className = spaced(elem.className || "");
-  return className.indexOf( " " + value + " " ) >= 0;
-}
-
-function addClass(elem, value) {
-  var className = spaced(elem.className || "");
-  if ( className.indexOf( " " + value + " " ) < 0 ) {
-    elem.className = trim(className + " " + value);
-  }
-}
-
-function removeClass(elem, value) {
-  var className = spaced(elem.className || "");
-  className = className.replace(" " + value + " ", " ");
-  elem.className = trim(className);
-}
-
-function toggleClass(elem, valueOn, valueOff, bool) {
-  if (bool == null) { bool = ! hasClass(elem, valueOn); }
-  if (bool) {
-    removeClass(elem, valueOff);
-    addClass(elem, valueOn);
-  }
-  else {
-    removeClass(elem, valueOn);
-    addClass(elem, valueOff);
-  }
-  return bool;
-}
-
-
-function makeClassToggle(valueOn, valueOff)
-{
-  return function(elem, bool) {
-    return toggleClass(elem, valueOn, valueOff, bool);
-  }
-}
-
-toggleShow = makeClassToggle("show", "hide");
-toggleCollapser = makeClassToggle("collapser", "expander");
-
-function toggleSection(id)
-{
-  var b = toggleShow(document.getElementById("section." + id));
-  toggleCollapser(document.getElementById("control." + id), b);
-  rememberCollapsed(id, b);
-  return b;
-}
-
-var collapsed = {};
-function rememberCollapsed(id, b)
-{
-  if(b)
-    delete collapsed[id]
-  else
-    collapsed[id] = null;
-
-  var sections = [];
-  for(var i in collapsed)
-  {
-    if(collapsed.hasOwnProperty(i))
-      sections.push(i);
-  }
-  // cookie specific to this page; don't use setCookie which sets path=/
-  document.cookie = "collapsed=" + escape(sections.join('+'));
-}
-
-function restoreCollapsed()
-{
-  var cookie = getCookie("collapsed");
-  if(!cookie)
-    return;
-
-  var ids = cookie.split('+');
-  for(var i in ids)
-  {
-    if(document.getElementById("section." + ids[i]))
-      toggleSection(ids[i]);
-  }
-}
-
-function setCookie(name, value) {
-  document.cookie = name + "=" + escape(value) + ";path=/;";
-}
-
-function clearCookie(name) {
-  document.cookie = name + "=;path=/;expires=Thu, 01-Jan-1970 00:00:01 GMT;";
-}
-
-function getCookie(name) {
-  var nameEQ = name + "=";
-  var ca = document.cookie.split(';');
-  for(var i=0;i < ca.length;i++) {
-    var c = ca[i];
-    while (c.charAt(0)==' ') c = c.substring(1,c.length);
-    if (c.indexOf(nameEQ) == 0) {
-      return unescape(c.substring(nameEQ.length,c.length));
-    }
-  }
-  return null;
-}
-
-
-
-var max_results = 75; // 50 is not enough to search for map in the base libraries
-var shown_range = null;
-var last_search = null;
-
-function quick_search()
-{
-    perform_search(false);
-}
-
-function full_search()
-{
-    perform_search(true);
-}
-
-
-function perform_search(full)
-{
-    var text = document.getElementById("searchbox").value.toLowerCase();
-    if (text == last_search && !full) return;
-    last_search = text;
-    
-    var table = document.getElementById("indexlist");
-    var status = document.getElementById("searchmsg");
-    var children = table.firstChild.childNodes;
-    
-    // first figure out the first node with the prefix
-    var first = bisect(-1);
-    var last = (first == -1 ? -1 : bisect(1));
-
-    if (first == -1)
-    {
-        table.className = "";
-        status.innerHTML = "No results found, displaying all";
-    }
-    else if (first == 0 && last == children.length - 1)
-    {
-        table.className = "";
-        status.innerHTML = "";
-    }
-    else if (last - first >= max_results && !full)
-    {
-        table.className = "";
-        status.innerHTML = "More than " + max_results + ", press Search to display";
-    }
-    else
-    {
-        // decide what you need to clear/show
-        if (shown_range)
-            setclass(shown_range[0], shown_range[1], "indexrow");
-        setclass(first, last, "indexshow");
-        shown_range = [first, last];
-        table.className = "indexsearch";
-        status.innerHTML = "";
-    }
-
-    
-    function setclass(first, last, status)
-    {
-        for (var i = first; i <= last; i++)
-        {
-            children[i].className = status;
-        }
-    }
-    
-    
-    // do a binary search, treating 0 as ...
-    // return either -1 (no 0's found) or location of most far match
-    function bisect(dir)
-    {
-        var first = 0, finish = children.length - 1;
-        var mid, success = false;
-
-        while (finish - first > 3)
-        {
-            mid = Math.floor((finish + first) / 2);
-
-            var i = checkitem(mid);
-            if (i == 0) i = dir;
-            if (i == -1)
-                finish = mid;
-            else
-                first = mid;
-        }
-        var a = (dir == 1 ? first : finish);
-        var b = (dir == 1 ? finish : first);
-        for (var i = b; i != a - dir; i -= dir)
-        {
-            if (checkitem(i) == 0) return i;
-        }
-        return -1;
-    }    
-    
-    
-    // from an index, decide what the result is
-    // 0 = match, -1 is lower, 1 is higher
-    function checkitem(i)
-    {
-        var s = getitem(i).toLowerCase().substr(0, text.length);
-        if (s == text) return 0;
-        else return (s > text ? -1 : 1);
-    }
-    
-    
-    // from an index, get its string
-    // this abstracts over alternates
-    function getitem(i)
-    {
-        for ( ; i >= 0; i--)
-        {
-            var s = children[i].firstChild.firstChild.data;
-            if (s.indexOf(' ') == -1)
-                return s;
-        }
-        return ""; // should never be reached
-    }
-}
-
-function setSynopsis(filename) {
-    if (parent.window.synopsis) {
-        if (parent.window.synopsis.location.replace) {
-            // In Firefox this avoids adding the change to the history.
-            parent.window.synopsis.location.replace(filename);
-        } else {
-            parent.window.synopsis.location = filename;
-        }
-    }
-}
-
-function addMenuItem(html) {
-  var menu = document.getElementById("page-menu");
-  if (menu) {
-    var btn = menu.firstChild.cloneNode(false);
-    btn.innerHTML = html;
-    menu.appendChild(btn);
-  }
-}
-
-function adjustForFrames() {
-  var bodyCls;
-  
-  if (parent.location.href == window.location.href) {
-    // not in frames, so add Frames button
-    addMenuItem("<a href='#' onclick='reframe();return true;'>Frames</a>");
-    bodyCls = "no-frame";
-  }
-  else {
-    bodyCls = "in-frame";
-  }
-  addClass(document.body, bodyCls);
-}
-
-function reframe() {
-  setCookie("haddock-reframe", document.URL);
-  window.location = "frames.html";
-}
-
-function postReframe() {
-  var s = getCookie("haddock-reframe");
-  if (s) {
-    parent.window.main.location = s;
-    clearCookie("haddock-reframe");
-  }
-}
-
-function styles() {
-  var i, a, es = document.getElementsByTagName("link"), rs = [];
-  for (i = 0; a = es[i]; i++) {
-    if(a.rel.indexOf("style") != -1 && a.title) {
-      rs.push(a);
-    }
-  }
-  return rs;
-}
-
-function addStyleMenu() {
-  var as = styles();
-  var i, a, btns = "";
-  for(i=0; a = as[i]; i++) {
-    btns += "<li><a href='#' onclick=\"setActiveStyleSheet('"
-      + a.title + "'); return false;\">"
-      + a.title + "</a></li>"
-  }
-  if (as.length > 1) {
-    var h = "<div id='style-menu-holder'>"
-      + "<a href='#' onclick='styleMenu(); return false;'>Style &#9662;</a>"
-      + "<ul id='style-menu' class='hide'>" + btns + "</ul>"
-      + "</div>";
-    addMenuItem(h);
-  }
-}
-
-function setActiveStyleSheet(title) {
-  var as = styles();
-  var i, a, found;
-  for(i=0; a = as[i]; i++) {
-    a.disabled = true;
-          // need to do this always, some browsers are edge triggered
-    if(a.title == title) {
-      found = a;
-    }
-  }
-  if (found) {
-    found.disabled = false;
-    setCookie("haddock-style", title);
-  }
-  else {
-    as[0].disabled = false;
-    clearCookie("haddock-style");
-  }
-  styleMenu(false);
-}
-
-function resetStyle() {
-  var s = getCookie("haddock-style");
-  if (s) setActiveStyleSheet(s);
-}
-
-
-function styleMenu(show) {
-  var m = document.getElementById('style-menu');
-  if (m) toggleShow(m, show);
-}
-
-
-function pageLoad() {
-  addStyleMenu();
-  adjustForFrames();
-  resetStyle();
-  restoreCollapsed();
-}
-
diff --git a/hypsrc-test/Main.hs b/hypsrc-test/Main.hs
new file mode 100644
--- /dev/null
+++ b/hypsrc-test/Main.hs
@@ -0,0 +1,54 @@
+{-# LANGUAGE CPP #-}
+
+
+import Data.Char
+import Data.List (isPrefixOf)
+import Data.Function (on)
+
+import System.Environment
+import System.FilePath
+
+import Test.Haddock
+import Test.Haddock.Xhtml
+
+
+checkConfig :: CheckConfig Xml
+checkConfig = CheckConfig
+    { ccfgRead = parseXml
+    , ccfgClean = strip
+    , ccfgDump = dumpXml
+    , ccfgEqual = (==) `on` dumpXml
+    }
+  where
+    strip _ = stripAnchors' . stripLinks' . stripIds' . stripFooter
+    
+    stripLinks' = stripLinksWhen $ \href -> "#local-" `isPrefixOf` href
+    stripAnchors' = stripAnchorsWhen $ \name -> "local-" `isPrefixOf` name
+    stripIds' = stripIdsWhen $ \name -> "local-" `isPrefixOf` name
+
+
+dirConfig :: DirConfig
+dirConfig = (defaultDirConfig $ takeDirectory __FILE__)
+    { dcfgCheckIgnore = checkIgnore
+    }
+
+
+main :: IO ()
+main = do
+    cfg <- parseArgs checkConfig dirConfig =<< getArgs
+    runAndCheck $ cfg
+        { cfgHaddockArgs = cfgHaddockArgs cfg ++
+            [ "--pretty-html"
+            , "--hyperlinked-source"
+            ]
+        }
+
+
+checkIgnore :: FilePath -> Bool
+checkIgnore file
+    | and . map ($ file) $ [isHtmlFile, isSourceFile, isModuleFile] = False
+  where
+    isHtmlFile = (== ".html") . takeExtension
+    isSourceFile = (== "src") . takeDirectory
+    isModuleFile = isUpper . head . takeBaseName
+checkIgnore _ = True
diff --git a/hypsrc-test/ref/src/Bug1091.html b/hypsrc-test/ref/src/Bug1091.html
new file mode 100644
--- /dev/null
+++ b/hypsrc-test/ref/src/Bug1091.html
@@ -0,0 +1,41 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><link rel="stylesheet" type="text/css" href="style.css"
+     /><script type="text/javascript" src="highlight.js"
+    ></script
+    ></head
+  ><body
+  ><pre
+    ><span class="hs-pragma"
+      >{-# LANGUAGE Haskell2010 #-}</span
+      ><span
+      >
+</span
+      ><span id="line-2"
+      ></span
+      ><span class="hs-pragma"
+      >{-# LANGUAGE CPP #-}</span
+      ><span
+      >
+</span
+      ><span id="line-3"
+      ></span
+      ><span class="hs-keyword"
+      >module</span
+      ><span
+      > </span
+      ><span class="hs-identifier"
+      >Bug1091</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >where</span
+      ><span class="hs-cpp"
+      >
+
+#include &quot;Include1For1091.h&quot;
+</span
+      ></pre
+    ></body
+  ></html
+>
diff --git a/hypsrc-test/ref/src/CPP.html b/hypsrc-test/ref/src/CPP.html
new file mode 100644
--- /dev/null
+++ b/hypsrc-test/ref/src/CPP.html
@@ -0,0 +1,243 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><link rel="stylesheet" type="text/css" href="style.css"
+     /><script type="text/javascript" src="highlight.js"
+    ></script
+    ></head
+  ><body
+  ><pre
+    ><span class="hs-pragma"
+      >{-# LANGUAGE Haskell2010 #-}</span
+      ><span
+      >
+</span
+      ><span id="line-2"
+      ></span
+      ><span class="hs-pragma"
+      >{-# LANGUAGE CPP #-}</span
+      ><span
+      >
+</span
+      ><span id="line-3"
+      ></span
+      ><span class="hs-keyword"
+      >module</span
+      ><span
+      > </span
+      ><span class="hs-identifier"
+      >CPP</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >where</span
+      ><span class="hs-cpp"
+      >
+
+#define SOMETHING1
+</span
+      ><span
+      >
+</span
+      ><span id="line-7"
+      ></span
+      ><span class="annot"
+      ><a href="CPP.html#foo"
+	><span class="hs-identifier hs-type"
+	  >foo</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>String</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-8"
+      ></span
+      ><span id="foo"
+      ><span class="annot"
+	><span class="annottext"
+	  >foo :: String
+</span
+	  ><a href="CPP.html#foo"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >foo</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-comment"
+      >{-  &quot; single quotes are fine in block comments
+          {- nested block comments are fine -}
+       -}</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>String
+</span
+	><span class="hs-string"
+	>&quot;foo&quot;</span
+	></span
+      ><span class="hs-cpp"
+      >
+
+#define SOMETHING2
+</span
+      ><span
+      >
+</span
+      ><span id="line-14"
+      ></span
+      ><span class="annot"
+      ><a href="CPP.html#bar"
+	><span class="hs-identifier hs-type"
+	  >bar</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>String</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-15"
+      ></span
+      ><span id="bar"
+      ><span class="annot"
+	><span class="annottext"
+	  >bar :: String
+</span
+	  ><a href="CPP.html#bar"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >bar</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>String
+</span
+	><span class="hs-string"
+	>&quot;block comment in a string is not a comment {- &quot;</span
+	></span
+      ><span class="hs-cpp"
+      >
+
+#define SOMETHING3
+</span
+      ><span
+      >
+</span
+      ><span id="line-19"
+      ></span
+      ><span class="hs-comment"
+      >-- &quot; single quotes are fine in line comments</span
+      ><span
+      >
+</span
+      ><span id="line-20"
+      ></span
+      ><span class="hs-comment"
+      >-- {- unclosed block comments are fine in line comments</span
+      ><span
+      >
+</span
+      ><span id="line-21"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-22"
+      ></span
+      ><span class="hs-comment"
+      >-- Multiline CPP is also fine</span
+      ><span class="hs-cpp"
+      >
+#define FOO\
+  1
+</span
+      ><span
+      >
+</span
+      ><span id="line-26"
+      ></span
+      ><span class="annot"
+      ><a href="CPP.html#baz"
+	><span class="hs-identifier hs-type"
+	  >baz</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>String</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-27"
+      ></span
+      ><span id="baz"
+      ><span class="annot"
+	><span class="annottext"
+	  >baz :: String
+</span
+	  ><a href="CPP.html#baz"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >baz</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>String
+</span
+	><span class="hs-string"
+	>&quot;line comment in a string is not a comment --&quot;</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-28"
+      ></span
+      ></pre
+    ></body
+  ></html
+>
diff --git a/hypsrc-test/ref/src/CallingQuotes.html b/hypsrc-test/ref/src/CallingQuotes.html
new file mode 100644
--- /dev/null
+++ b/hypsrc-test/ref/src/CallingQuotes.html
@@ -0,0 +1,104 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><link rel="stylesheet" type="text/css" href="style.css"
+     /><script type="text/javascript" src="highlight.js"
+    ></script
+    ></head
+  ><body
+  ><pre
+    ><span class="hs-pragma"
+      >{-# LANGUAGE QuasiQuotes #-}</span
+      ><span
+      >
+</span
+      ><span id="line-2"
+      ></span
+      ><span class="hs-keyword"
+      >module</span
+      ><span
+      > </span
+      ><span class="hs-identifier"
+      >CallingQuotes</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >where</span
+      ><span
+      >
+</span
+      ><span id="line-3"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-4"
+      ></span
+      ><span class="hs-keyword"
+      >import</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Quasiquoter.html"
+	><span class="hs-identifier"
+	  >Quasiquoter</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-5"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-6"
+      ></span
+      ><span id="baz"
+      ><span class="annot"
+	><span class="annottext"
+	  >baz :: [Char]
+</span
+	  ><a href="CallingQuotes.html#baz"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >baz</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      >  </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class=""
+	>[string| foo bar |]</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>[Char] -&gt; [Char] -&gt; [Char]
+forall a. [a] -&gt; [a] -&gt; [a]
+</span
+	><span class="hs-operator hs-var"
+	>++</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class=""
+	>[string| some
+  mulitline
+  quasiquote
+|]</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-10"
+      ></span
+      ></pre
+    ></body
+  ></html
+>
diff --git a/hypsrc-test/ref/src/Classes.html b/hypsrc-test/ref/src/Classes.html
new file mode 100644
--- /dev/null
+++ b/hypsrc-test/ref/src/Classes.html
@@ -0,0 +1,1489 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><link rel="stylesheet" type="text/css" href="style.css"
+     /><script type="text/javascript" src="highlight.js"
+    ></script
+    ></head
+  ><body
+  ><pre
+    ><span class="hs-pragma"
+      >{-# LANGUAGE Haskell2010 #-}</span
+      ><span
+      >
+</span
+      ><span id="line-2"
+      ></span
+      ><span class="hs-keyword"
+      >module</span
+      ><span
+      > </span
+      ><span class="hs-identifier"
+      >Classes</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >where</span
+      ><span
+      >
+</span
+      ><span id="line-3"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-4"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-5"
+      ></span
+      ><span class="hs-keyword"
+      >class</span
+      ><span
+      > </span
+      ><span id="Foo"
+      ><span class="annot"
+	><a href="Classes.html#Foo"
+	  ><span class="hs-identifier hs-var"
+	    >Foo</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >a</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >where</span
+      ><span
+      >
+</span
+      ><span id="line-6"
+      ></span
+      ><span
+      >    </span
+      ><span id="bar"
+      ><span class="annot"
+	><a href="Classes.html#bar"
+	  ><span class="hs-identifier hs-type"
+	    >bar</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >a</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>Int</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-7"
+      ></span
+      ><span
+      >    </span
+      ><span id="baz"
+      ><span class="annot"
+	><a href="Classes.html#baz"
+	  ><span class="hs-identifier hs-type"
+	    >baz</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>Int</span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >a</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >a</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      >
+</span
+      ><span id="line-8"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-9"
+      ></span
+      ><span class="hs-keyword"
+      >instance</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Classes.html#Foo"
+	><span class="hs-identifier hs-type"
+	  >Foo</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>Int</span
+	></span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >where</span
+      ><span
+      >
+</span
+      ><span id="line-10"
+      ></span
+      ><span
+      >    </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >bar :: Int -&gt; Int
+</span
+	  ><a href="Classes.html#bar"
+	  ><span class="hs-identifier hs-var hs-var hs-var hs-var"
+	    >bar</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int -&gt; Int
+forall a. a -&gt; a
+</span
+	><span class="hs-identifier hs-var"
+	>id</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-11"
+      ></span
+      ><span
+      >    </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >baz :: Int -&gt; (Int, Int)
+</span
+	  ><a href="Classes.html#baz"
+	  ><span class="hs-identifier hs-var hs-var hs-var hs-var"
+	    >baz</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >Int
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >x</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >x</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >x</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      >
+</span
+      ><span id="line-12"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-13"
+      ></span
+      ><span class="hs-keyword"
+      >instance</span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><a href="Classes.html#Foo"
+	  ><span class="hs-identifier hs-type"
+	    >Foo</span
+	    ></a
+	  ></span
+	><span
+	> </span
+	><span class="hs-special"
+	>[</span
+	><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >a</span
+	    ></a
+	  ></span
+	><span class="hs-special"
+	>]</span
+	></span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >where</span
+      ><span
+      >
+</span
+      ><span id="line-14"
+      ></span
+      ><span
+      >    </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >bar :: [a] -&gt; Int
+</span
+	  ><a href="Classes.html#bar"
+	  ><span class="hs-identifier hs-var hs-var hs-var hs-var"
+	    >bar</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>[a] -&gt; Int
+forall a. [a] -&gt; Int
+forall (t :: * -&gt; *) a. Foldable t =&gt; t a -&gt; Int
+</span
+	><span class="hs-identifier hs-var"
+	>length</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-15"
+      ></span
+      ><span
+      >    </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >baz :: Int -&gt; ([a], [a])
+</span
+	  ><a href="Classes.html#baz"
+	  ><span class="hs-identifier hs-var hs-var hs-var hs-var"
+	    >baz</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><span class="hs-identifier"
+	>_</span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-special"
+      >[</span
+      ><span class="hs-special"
+      >]</span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >[</span
+      ><span class="hs-special"
+      >]</span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      >
+</span
+      ><span id="line-16"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-17"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-18"
+      ></span
+      ><span class="hs-keyword"
+      >class</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Classes.html#Foo"
+	><span class="hs-identifier hs-type"
+	  >Foo</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >a</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=&gt;</span
+      ><span
+      > </span
+      ><span id="Foo%27"
+      ><span class="annot"
+	><a href="Classes.html#Foo%27"
+	  ><span class="hs-identifier hs-var"
+	    >Foo'</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >a</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >where</span
+      ><span
+      >
+</span
+      ><span id="line-19"
+      ></span
+      ><span
+      >    </span
+      ><span id="quux"
+      ><span class="annot"
+	><a href="Classes.html#quux"
+	  ><span class="hs-identifier hs-type"
+	    >quux</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >a</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >a</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >a</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-20"
+      ></span
+      ><span
+      >    </span
+      ><span id=""
+      ><span class="annot"
+	><a href="Classes.html#quux"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >quux</span
+	    ></a
+	  ></span
+	><span
+	> </span
+	><span class="hs-special"
+	>(</span
+	><span id=""
+	><span class="annot"
+	  ><span class="annottext"
+	    >a
+</span
+	    ><a href="#"
+	    ><span class="hs-identifier hs-var"
+	      >x</span
+	      ></a
+	    ></span
+	  ></span
+	><span class="hs-special"
+	>,</span
+	><span
+	> </span
+	><span id=""
+	><span class="annot"
+	  ><span class="annottext"
+	    >a
+</span
+	    ><a href="#"
+	    ><span class="hs-identifier hs-var"
+	      >y</span
+	      ></a
+	    ></span
+	  ></span
+	><span class="hs-special"
+	>)</span
+	><span
+	> </span
+	><span class="hs-glyph"
+	>=</span
+	><span
+	> </span
+	><span class="annot"
+	><span class="annottext"
+	  >[a] -&gt; a
+forall a. Foo' a =&gt; [a] -&gt; a
+</span
+	  ><a href="Classes.html#norf"
+	  ><span class="hs-identifier hs-var"
+	    >norf</span
+	    ></a
+	  ></span
+	><span
+	> </span
+	><span class="hs-special"
+	>[</span
+	><span class="annot"
+	><span class="annottext"
+	  >a
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >x</span
+	    ></a
+	  ></span
+	><span class="hs-special"
+	>,</span
+	><span
+	> </span
+	><span class="annot"
+	><span class="annottext"
+	  >a
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >y</span
+	    ></a
+	  ></span
+	><span class="hs-special"
+	>]</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-21"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-22"
+      ></span
+      ><span
+      >    </span
+      ><span id="norf"
+      ><span class="annot"
+	><a href="Classes.html#norf"
+	  ><span class="hs-identifier hs-type"
+	    >norf</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >[</span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >a</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >]</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >a</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-23"
+      ></span
+      ><span
+      >    </span
+      ><span id=""
+      ><span class="annot"
+	><a href="Classes.html#norf"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >norf</span
+	    ></a
+	  ></span
+	><span
+	> </span
+	><span class="hs-glyph"
+	>=</span
+	><span
+	> </span
+	><span class="annot"
+	><span class="annottext"
+	  >(a, a) -&gt; a
+forall a. Foo' a =&gt; (a, a) -&gt; a
+</span
+	  ><a href="Classes.html#quux"
+	  ><span class="hs-identifier hs-var"
+	    >quux</span
+	    ></a
+	  ></span
+	><span
+	> </span
+	><span class="annot"
+	><span class="annottext"
+	  >((a, a) -&gt; a) -&gt; ([a] -&gt; (a, a)) -&gt; [a] -&gt; a
+forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
+</span
+	  ><span class="hs-operator hs-var"
+	  >.</span
+	  ></span
+	><span
+	> </span
+	><span class="annot"
+	><span class="annottext"
+	  >Int -&gt; (a, a)
+forall a. Foo a =&gt; Int -&gt; (a, a)
+</span
+	  ><a href="Classes.html#baz"
+	  ><span class="hs-identifier hs-var"
+	    >baz</span
+	    ></a
+	  ></span
+	><span
+	> </span
+	><span class="annot"
+	><span class="annottext"
+	  >(Int -&gt; (a, a)) -&gt; ([a] -&gt; Int) -&gt; [a] -&gt; (a, a)
+forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
+</span
+	  ><span class="hs-operator hs-var"
+	  >.</span
+	  ></span
+	><span
+	> </span
+	><span class="annot"
+	><span class="annottext"
+	  >[Int] -&gt; Int
+forall a. Num a =&gt; [a] -&gt; a
+forall (t :: * -&gt; *) a. (Foldable t, Num a) =&gt; t a -&gt; a
+</span
+	  ><span class="hs-identifier hs-var"
+	  >sum</span
+	  ></span
+	><span
+	> </span
+	><span class="annot"
+	><span class="annottext"
+	  >([Int] -&gt; Int) -&gt; ([a] -&gt; [Int]) -&gt; [a] -&gt; Int
+forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
+</span
+	  ><span class="hs-operator hs-var"
+	  >.</span
+	  ></span
+	><span
+	> </span
+	><span class="annot"
+	><span class="annottext"
+	  >(a -&gt; Int) -&gt; [a] -&gt; [Int]
+forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
+</span
+	  ><span class="hs-identifier hs-var"
+	  >map</span
+	  ></span
+	><span
+	> </span
+	><span class="annot"
+	><span class="annottext"
+	  >a -&gt; Int
+forall a. Foo a =&gt; a -&gt; Int
+</span
+	  ><a href="Classes.html#bar"
+	  ><span class="hs-identifier hs-var"
+	    >bar</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-24"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-25"
+      ></span
+      ><span class="hs-keyword"
+      >instance</span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><a href="Classes.html#Foo%27"
+	  ><span class="hs-identifier hs-type"
+	    >Foo'</span
+	    ></a
+	  ></span
+	><span
+	> </span
+	><span class="annot"
+	><span class="hs-identifier hs-type"
+	  >Int</span
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >where</span
+      ><span
+      >
+</span
+      ><span id="line-26"
+      ></span
+      ><span
+      >    </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >norf :: [Int] -&gt; Int
+</span
+	  ><a href="Classes.html#norf"
+	  ><span class="hs-identifier hs-var hs-var hs-var hs-var"
+	    >norf</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>[Int] -&gt; Int
+forall a. Num a =&gt; [a] -&gt; a
+forall (t :: * -&gt; *) a. (Foldable t, Num a) =&gt; t a -&gt; a
+</span
+	><span class="hs-identifier hs-var"
+	>sum</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-27"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-28"
+      ></span
+      ><span class="hs-keyword"
+      >instance</span
+      ><span
+      > </span
+      ><span id=""
+      ><span id=""
+	><span class="annot"
+	  ><a href="Classes.html#Foo%27"
+	    ><span class="hs-identifier hs-type"
+	      >Foo'</span
+	      ></a
+	    ></span
+	  ><span
+	  > </span
+	  ><span class="hs-special"
+	  >[</span
+	  ><span class="annot"
+	  ><a href="#"
+	    ><span class="hs-identifier hs-type"
+	      >a</span
+	      ></a
+	    ></span
+	  ><span class="hs-special"
+	  >]</span
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >where</span
+      ><span
+      >
+</span
+      ><span id="line-29"
+      ></span
+      ><span
+      >    </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >quux :: ([a], [a]) -&gt; [a]
+</span
+	  ><a href="Classes.html#quux"
+	  ><span class="hs-identifier hs-var hs-var hs-var hs-var"
+	    >quux</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>([a] -&gt; [a] -&gt; [a]) -&gt; ([a], [a]) -&gt; [a]
+forall a b c. (a -&gt; b -&gt; c) -&gt; (a, b) -&gt; c
+</span
+	><span class="hs-identifier hs-var"
+	>uncurry</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>[a] -&gt; [a] -&gt; [a]
+forall a. [a] -&gt; [a] -&gt; [a]
+</span
+	><span class="hs-operator hs-var"
+	>(++)</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-30"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-31"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-32"
+      ></span
+      ><span class="hs-keyword"
+      >class</span
+      ><span
+      > </span
+      ><span id="Plugh"
+      ><span class="annot"
+	><a href="Classes.html#Plugh"
+	  ><span class="hs-identifier hs-var"
+	    >Plugh</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >p</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >where</span
+      ><span
+      >
+</span
+      ><span id="line-33"
+      ></span
+      ><span
+      >    </span
+      ><span id="plugh"
+      ><span class="annot"
+	><a href="Classes.html#plugh"
+	  ><span class="hs-identifier hs-type"
+	    >plugh</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span id=""
+      ><span id=""
+	><span class="annot"
+	  ><a href="#"
+	    ><span class="hs-identifier hs-type"
+	      >p</span
+	      ></a
+	    ></span
+	  ><span
+	  > </span
+	  ><span class="annot"
+	  ><a href="#"
+	    ><span class="hs-identifier hs-type"
+	      >a</span
+	      ></a
+	    ></span
+	  ><span
+	  > </span
+	  ><span class="annot"
+	  ><a href="#"
+	    ><span class="hs-identifier hs-type"
+	      >a</span
+	      ></a
+	    ></span
+	  ><span
+	  > </span
+	  ><span class="hs-glyph"
+	  >-&gt;</span
+	  ><span
+	  > </span
+	  ><span class="annot"
+	  ><a href="#"
+	    ><span class="hs-identifier hs-type"
+	      >p</span
+	      ></a
+	    ></span
+	  ><span
+	  > </span
+	  ><span class="annot"
+	  ><a href="#"
+	    ><span class="hs-identifier hs-type"
+	      >b</span
+	      ></a
+	    ></span
+	  ><span
+	  > </span
+	  ><span class="annot"
+	  ><a href="#"
+	    ><span class="hs-identifier hs-type"
+	      >b</span
+	      ></a
+	    ></span
+	  ><span
+	  > </span
+	  ><span class="hs-glyph"
+	  >-&gt;</span
+	  ><span
+	  > </span
+	  ><span class="annot"
+	  ><a href="#"
+	    ><span class="hs-identifier hs-type"
+	      >p</span
+	      ></a
+	    ></span
+	  ><span
+	  > </span
+	  ><span class="hs-special"
+	  >(</span
+	  ><span class="annot"
+	  ><a href="#"
+	    ><span class="hs-identifier hs-type"
+	      >a</span
+	      ></a
+	    ></span
+	  ><span
+	  > </span
+	  ><span class="hs-glyph"
+	  >-&gt;</span
+	  ><span
+	  > </span
+	  ><span class="annot"
+	  ><a href="#"
+	    ><span class="hs-identifier hs-type"
+	      >b</span
+	      ></a
+	    ></span
+	  ><span class="hs-special"
+	  >)</span
+	  ><span
+	  > </span
+	  ><span class="hs-special"
+	  >(</span
+	  ><span class="annot"
+	  ><a href="#"
+	    ><span class="hs-identifier hs-type"
+	      >b</span
+	      ></a
+	    ></span
+	  ><span
+	  > </span
+	  ><span class="hs-glyph"
+	  >-&gt;</span
+	  ><span
+	  > </span
+	  ><span class="annot"
+	  ><a href="#"
+	    ><span class="hs-identifier hs-type"
+	      >a</span
+	      ></a
+	    ></span
+	  ><span class="hs-special"
+	  >)</span
+	  ></span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-34"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-35"
+      ></span
+      ><span class="hs-keyword"
+      >instance</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Classes.html#Plugh"
+	><span class="hs-identifier hs-type"
+	  >Plugh</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>Either</span
+	></span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >where</span
+      ><span
+      >
+</span
+      ><span id="line-36"
+      ></span
+      ><span
+      >    </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >plugh :: forall a b. Either a a -&gt; Either b b -&gt; Either (a -&gt; b) (b -&gt; a)
+</span
+	  ><a href="Classes.html#plugh"
+	  ><span class="hs-identifier hs-var hs-var hs-var hs-var"
+	    >plugh</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>Left</span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >a
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >a</span
+	    ></a
+	  ></span
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Either b b
+</span
+	><span class="hs-identifier"
+	>_</span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>(b -&gt; a) -&gt; Either (a -&gt; b) (b -&gt; a)
+forall a b. b -&gt; Either a b
+</span
+	><span class="hs-identifier hs-var"
+	>Right</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>((b -&gt; a) -&gt; Either (a -&gt; b) (b -&gt; a))
+-&gt; (b -&gt; a) -&gt; Either (a -&gt; b) (b -&gt; a)
+forall a b. (a -&gt; b) -&gt; a -&gt; b
+</span
+	><span class="hs-operator hs-var"
+	>$</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>a -&gt; b -&gt; a
+forall a b. a -&gt; b -&gt; a
+</span
+	><span class="hs-identifier hs-var"
+	>const</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>a
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >a</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-37"
+      ></span
+      ><span
+      >    </span
+      ><span class="annot"
+      ><a href="Classes.html#plugh"
+	><span class="hs-identifier hs-var"
+	  >plugh</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>Right</span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >a
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >a</span
+	    ></a
+	  ></span
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Either b b
+</span
+	><span class="hs-identifier"
+	>_</span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>(b -&gt; a) -&gt; Either (a -&gt; b) (b -&gt; a)
+forall a b. b -&gt; Either a b
+</span
+	><span class="hs-identifier hs-var"
+	>Right</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>((b -&gt; a) -&gt; Either (a -&gt; b) (b -&gt; a))
+-&gt; (b -&gt; a) -&gt; Either (a -&gt; b) (b -&gt; a)
+forall a b. (a -&gt; b) -&gt; a -&gt; b
+</span
+	><span class="hs-operator hs-var"
+	>$</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>a -&gt; b -&gt; a
+forall a b. a -&gt; b -&gt; a
+</span
+	><span class="hs-identifier hs-var"
+	>const</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>a
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >a</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-38"
+      ></span
+      ><span
+      >    </span
+      ><span class="annot"
+      ><a href="Classes.html#plugh"
+	><span class="hs-identifier hs-var"
+	  >plugh</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Either a a
+</span
+	><span class="hs-identifier"
+	>_</span
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>Left</span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >b
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >b</span
+	    ></a
+	  ></span
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>(a -&gt; b) -&gt; Either (a -&gt; b) (b -&gt; a)
+forall a b. a -&gt; Either a b
+</span
+	><span class="hs-identifier hs-var"
+	>Left</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>((a -&gt; b) -&gt; Either (a -&gt; b) (b -&gt; a))
+-&gt; (a -&gt; b) -&gt; Either (a -&gt; b) (b -&gt; a)
+forall a b. (a -&gt; b) -&gt; a -&gt; b
+</span
+	><span class="hs-operator hs-var"
+	>$</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>b -&gt; a -&gt; b
+forall a b. a -&gt; b -&gt; a
+</span
+	><span class="hs-identifier hs-var"
+	>const</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>b
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >b</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-39"
+      ></span
+      ><span
+      >    </span
+      ><span class="annot"
+      ><a href="Classes.html#plugh"
+	><span class="hs-identifier hs-var"
+	  >plugh</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Either a a
+</span
+	><span class="hs-identifier"
+	>_</span
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>Right</span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >b
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >b</span
+	    ></a
+	  ></span
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>(a -&gt; b) -&gt; Either (a -&gt; b) (b -&gt; a)
+forall a b. a -&gt; Either a b
+</span
+	><span class="hs-identifier hs-var"
+	>Left</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>((a -&gt; b) -&gt; Either (a -&gt; b) (b -&gt; a))
+-&gt; (a -&gt; b) -&gt; Either (a -&gt; b) (b -&gt; a)
+forall a b. (a -&gt; b) -&gt; a -&gt; b
+</span
+	><span class="hs-operator hs-var"
+	>$</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>b -&gt; a -&gt; b
+forall a b. a -&gt; b -&gt; a
+</span
+	><span class="hs-identifier hs-var"
+	>const</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>b
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >b</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-40"
+      ></span
+      ></pre
+    ></body
+  ></html
+>
diff --git a/hypsrc-test/ref/src/Constructors.html b/hypsrc-test/ref/src/Constructors.html
new file mode 100644
--- /dev/null
+++ b/hypsrc-test/ref/src/Constructors.html
@@ -0,0 +1,1399 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><link rel="stylesheet" type="text/css" href="style.css"
+     /><script type="text/javascript" src="highlight.js"
+    ></script
+    ></head
+  ><body
+  ><pre
+    ><span class="hs-pragma"
+      >{-# LANGUAGE Haskell2010 #-}</span
+      ><span
+      >
+</span
+      ><span id="line-2"
+      ></span
+      ><span class="hs-keyword"
+      >module</span
+      ><span
+      > </span
+      ><span class="hs-identifier"
+      >Constructors</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >where</span
+      ><span
+      >
+</span
+      ><span id="line-3"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-4"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-5"
+      ></span
+      ><span class="hs-keyword"
+      >data</span
+      ><span
+      > </span
+      ><span id="Foo"
+      ><span class="annot"
+	><a href="Constructors.html#Foo"
+	  ><span class="hs-identifier hs-var"
+	    >Foo</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-6"
+      ></span
+      ><span
+      >    </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span id="Bar"
+      ><span class="annot"
+	><a href="Constructors.html#Bar"
+	  ><span class="hs-identifier hs-var"
+	    >Bar</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-7"
+      ></span
+      ><span
+      >    </span
+      ><span class="hs-glyph"
+      >|</span
+      ><span
+      > </span
+      ><span id="Baz"
+      ><span class="annot"
+	><a href="Constructors.html#Baz"
+	  ><span class="hs-identifier hs-var"
+	    >Baz</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-8"
+      ></span
+      ><span
+      >    </span
+      ><span class="hs-glyph"
+      >|</span
+      ><span
+      > </span
+      ><span id="Quux"
+      ><span class="annot"
+	><a href="Constructors.html#Quux"
+	  ><span class="hs-identifier hs-var"
+	    >Quux</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Constructors.html#Foo"
+	><span class="hs-identifier hs-type"
+	  >Foo</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>Int</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-9"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-10"
+      ></span
+      ><span class="hs-keyword"
+      >newtype</span
+      ><span
+      > </span
+      ><span id="Norf"
+      ><span class="annot"
+	><a href="Constructors.html#Norf"
+	  ><span class="hs-identifier hs-var"
+	    >Norf</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span id="Norf"
+      ><span class="annot"
+	><a href="Constructors.html#Norf"
+	  ><span class="hs-identifier hs-var"
+	    >Norf</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><a href="Constructors.html#Foo"
+	><span class="hs-identifier hs-type"
+	  >Foo</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >[</span
+      ><span class="annot"
+      ><a href="Constructors.html#Foo"
+	><span class="hs-identifier hs-type"
+	  >Foo</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >]</span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Constructors.html#Foo"
+	><span class="hs-identifier hs-type"
+	  >Foo</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      >
+</span
+      ><span id="line-11"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-12"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-13"
+      ></span
+      ><span class="annot"
+      ><a href="Constructors.html#bar"
+	><span class="hs-identifier hs-type"
+	  >bar</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Constructors.html#baz"
+	><span class="hs-identifier hs-type"
+	  >baz</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Constructors.html#quux"
+	><span class="hs-identifier hs-type"
+	  >quux</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Constructors.html#Foo"
+	><span class="hs-identifier hs-type"
+	  >Foo</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-14"
+      ></span
+      ><span id="bar"
+      ><span class="annot"
+	><span class="annottext"
+	  >bar :: Foo
+</span
+	  ><a href="Constructors.html#bar"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >bar</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Foo
+</span
+	><a href="Constructors.html#Bar"
+	><span class="hs-identifier hs-var"
+	  >Bar</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-15"
+      ></span
+      ><span id="baz"
+      ><span class="annot"
+	><span class="annottext"
+	  >baz :: Foo
+</span
+	  ><a href="Constructors.html#baz"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >baz</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Foo
+</span
+	><a href="Constructors.html#Baz"
+	><span class="hs-identifier hs-var"
+	  >Baz</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-16"
+      ></span
+      ><span id="quux"
+      ><span class="annot"
+	><span class="annottext"
+	  >quux :: Foo
+</span
+	  ><a href="Constructors.html#quux"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >quux</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Foo -&gt; Int -&gt; Foo
+</span
+	><a href="Constructors.html#Quux"
+	><span class="hs-identifier hs-var"
+	  >Quux</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Foo
+</span
+	><a href="Constructors.html#quux"
+	><span class="hs-identifier hs-var"
+	  >quux</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><span class="hs-number"
+	>0</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-17"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-18"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-19"
+      ></span
+      ><span class="annot"
+      ><a href="Constructors.html#unfoo"
+	><span class="hs-identifier hs-type"
+	  >unfoo</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Constructors.html#Foo"
+	><span class="hs-identifier hs-type"
+	  >Foo</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>Int</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-20"
+      ></span
+      ><span id="unfoo"
+      ><span class="annot"
+	><span class="annottext"
+	  >unfoo :: Foo -&gt; Int
+</span
+	  ><a href="Constructors.html#unfoo"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >unfoo</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Foo
+</span
+	><a href="Constructors.html#Bar"
+	><span class="hs-identifier hs-var"
+	  >Bar</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><span class="hs-number"
+	>0</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-21"
+      ></span
+      ><span class="annot"
+      ><a href="Constructors.html#unfoo"
+	><span class="hs-identifier hs-var"
+	  >unfoo</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Foo
+</span
+	><a href="Constructors.html#Baz"
+	><span class="hs-identifier hs-var"
+	  >Baz</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><span class="hs-number"
+	>0</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-22"
+      ></span
+      ><span class="annot"
+      ><a href="Constructors.html#unfoo"
+	><span class="hs-identifier hs-var"
+	  >unfoo</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><a href="Constructors.html#Quux"
+	><span class="hs-identifier hs-type"
+	  >Quux</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >Foo
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >foo</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >Int
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >n</span
+	    ></a
+	  ></span
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><span class="hs-number"
+	>42</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int -&gt; Int -&gt; Int
+forall a. Num a =&gt; a -&gt; a -&gt; a
+</span
+	><span class="hs-operator hs-var"
+	>*</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >n</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int -&gt; Int -&gt; Int
+forall a. Num a =&gt; a -&gt; a -&gt; a
+</span
+	><span class="hs-operator hs-var"
+	>+</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Foo -&gt; Int
+</span
+	><a href="Constructors.html#unfoo"
+	><span class="hs-identifier hs-var"
+	  >unfoo</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Foo
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >foo</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-23"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-24"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-25"
+      ></span
+      ><span class="annot"
+      ><a href="Constructors.html#unnorf"
+	><span class="hs-identifier hs-type"
+	  >unnorf</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Constructors.html#Norf"
+	><span class="hs-identifier hs-type"
+	  >Norf</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >[</span
+      ><span class="annot"
+      ><a href="Constructors.html#Foo"
+	><span class="hs-identifier hs-type"
+	  >Foo</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >]</span
+      ><span
+      >
+</span
+      ><span id="line-26"
+      ></span
+      ><span id="unnorf"
+      ><span class="annot"
+	><span class="annottext"
+	  >unnorf :: Norf -&gt; [Foo]
+</span
+	  ><a href="Constructors.html#unnorf"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >unnorf</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><a href="Constructors.html#Norf"
+	><span class="hs-identifier hs-type"
+	  >Norf</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><span class="annottext"
+	>Foo
+</span
+	><a href="Constructors.html#Bar"
+	><span class="hs-identifier hs-var"
+	  >Bar</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >[Foo]
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >xs</span
+	    ></a
+	  ></span
+	></span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Foo
+</span
+	><a href="Constructors.html#Bar"
+	><span class="hs-identifier hs-var"
+	  >Bar</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>[Foo]
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >xs</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-27"
+      ></span
+      ><span class="annot"
+      ><a href="Constructors.html#unnorf"
+	><span class="hs-identifier hs-var"
+	  >unnorf</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><a href="Constructors.html#Norf"
+	><span class="hs-identifier hs-type"
+	  >Norf</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><span class="annottext"
+	>Foo
+</span
+	><a href="Constructors.html#Baz"
+	><span class="hs-identifier hs-var"
+	  >Baz</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >[Foo]
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >xs</span
+	    ></a
+	  ></span
+	></span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Foo
+</span
+	><a href="Constructors.html#Baz"
+	><span class="hs-identifier hs-var"
+	  >Baz</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>[Foo] -&gt; [Foo]
+forall a. [a] -&gt; [a]
+</span
+	><span class="hs-identifier hs-var"
+	>reverse</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>[Foo]
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >xs</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-28"
+      ></span
+      ><span class="annot"
+      ><a href="Constructors.html#unnorf"
+	><span class="hs-identifier hs-var"
+	  >unnorf</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Norf
+</span
+	><span class="hs-identifier"
+	>_</span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>[Foo]
+forall a. HasCallStack =&gt; a
+</span
+	><span class="hs-identifier hs-var"
+	>undefined</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-29"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-30"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-31"
+      ></span
+      ><span class="annot"
+      ><a href="Constructors.html#unnorf%27"
+	><span class="hs-identifier hs-type"
+	  >unnorf'</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Constructors.html#Norf"
+	><span class="hs-identifier hs-type"
+	  >Norf</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>Int</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-32"
+      ></span
+      ><span id="unnorf%27"
+      ><span class="annot"
+	><span class="annottext"
+	  >unnorf' :: Norf -&gt; Int
+</span
+	  ><a href="Constructors.html#unnorf%27"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >unnorf'</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >x :: Norf
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >x</span
+	    ></a
+	  ></span
+	></span
+      ><span class="hs-glyph"
+      >@</span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><a href="Constructors.html#Norf"
+	><span class="hs-identifier hs-type"
+	  >Norf</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >f1 :: Foo
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >f1</span
+	    ></a
+	  ></span
+	></span
+      ><span class="hs-glyph"
+      >@</span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><a href="Constructors.html#Quux"
+	><span class="hs-identifier hs-type"
+	  >Quux</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Foo
+</span
+	><span class="hs-identifier"
+	>_</span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >Int
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >n</span
+	    ></a
+	  ></span
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>[Foo]
+</span
+	><span class="hs-identifier"
+	>_</span
+	></span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >f2 :: Foo
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >f2</span
+	    ></a
+	  ></span
+	></span
+      ><span class="hs-glyph"
+      >@</span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><a href="Constructors.html#Quux"
+	><span class="hs-identifier hs-type"
+	  >Quux</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >Foo
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >f3</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><span class="hs-identifier"
+	>_</span
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span class="hs-special"
+      >)</span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      >
+</span
+      ><span id="line-33"
+      ></span
+      ><span
+      >    </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >x'</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int -&gt; Int -&gt; Int
+forall a. Num a =&gt; a -&gt; a -&gt; a
+</span
+	><span class="hs-operator hs-var"
+	>+</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >n</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int -&gt; Int -&gt; Int
+forall a. Num a =&gt; a -&gt; a -&gt; a
+</span
+	><span class="hs-operator hs-var"
+	>*</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Foo -&gt; Int
+</span
+	><a href="Constructors.html#unfoo"
+	><span class="hs-identifier hs-var"
+	  >unfoo</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Foo
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >f1</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int -&gt; Int -&gt; Int
+forall a. Num a =&gt; a -&gt; a -&gt; a
+</span
+	><span class="hs-operator hs-var"
+	>+</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Foo -&gt; Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >aux</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Foo
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >f3</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-34"
+      ></span
+      ><span
+      >  </span
+      ><span class="hs-keyword"
+      >where</span
+      ><span
+      >
+</span
+      ><span id="line-35"
+      ></span
+      ><span
+      >    </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >aux :: Foo -&gt; Int
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >aux</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >Foo
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >fx</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Foo -&gt; Int
+</span
+	><a href="Constructors.html#unfoo"
+	><span class="hs-identifier hs-var"
+	  >unfoo</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Foo
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >f2</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int -&gt; Int -&gt; Int
+forall a. Num a =&gt; a -&gt; a -&gt; a
+</span
+	><span class="hs-operator hs-var"
+	>*</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Foo -&gt; Int
+</span
+	><a href="Constructors.html#unfoo"
+	><span class="hs-identifier hs-var"
+	  >unfoo</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Foo
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >fx</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int -&gt; Int -&gt; Int
+forall a. Num a =&gt; a -&gt; a -&gt; a
+</span
+	><span class="hs-operator hs-var"
+	>*</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Foo -&gt; Int
+</span
+	><a href="Constructors.html#unfoo"
+	><span class="hs-identifier hs-var"
+	  >unfoo</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Foo
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >f3</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-36"
+      ></span
+      ><span
+      >    </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >x' :: Int
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >x'</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>[Int] -&gt; Int
+forall a. Num a =&gt; [a] -&gt; a
+forall (t :: * -&gt; *) a. (Foldable t, Num a) =&gt; t a -&gt; a
+</span
+	><span class="hs-identifier hs-var"
+	>sum</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>([Int] -&gt; Int) -&gt; (Norf -&gt; [Int]) -&gt; Norf -&gt; Int
+forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
+</span
+	><span class="hs-operator hs-var"
+	>.</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>(Foo -&gt; Int) -&gt; [Foo] -&gt; [Int]
+forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
+</span
+	><span class="hs-identifier hs-var"
+	>map</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Foo -&gt; Int
+</span
+	><a href="Constructors.html#unfoo"
+	><span class="hs-identifier hs-var"
+	  >unfoo</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>([Foo] -&gt; [Int]) -&gt; (Norf -&gt; [Foo]) -&gt; Norf -&gt; [Int]
+forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
+</span
+	><span class="hs-operator hs-var"
+	>.</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Norf -&gt; [Foo]
+</span
+	><a href="Constructors.html#unnorf"
+	><span class="hs-identifier hs-var"
+	  >unnorf</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>(Norf -&gt; Int) -&gt; Norf -&gt; Int
+forall a b. (a -&gt; b) -&gt; a -&gt; b
+</span
+	><span class="hs-operator hs-var"
+	>$</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Norf
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >x</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-37"
+      ></span
+      ></pre
+    ></body
+  ></html
+>
diff --git a/hypsrc-test/ref/src/Identifiers.html b/hypsrc-test/ref/src/Identifiers.html
new file mode 100644
--- /dev/null
+++ b/hypsrc-test/ref/src/Identifiers.html
@@ -0,0 +1,1510 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><link rel="stylesheet" type="text/css" href="style.css"
+     /><script type="text/javascript" src="highlight.js"
+    ></script
+    ></head
+  ><body
+  ><pre
+    ><span class="hs-pragma"
+      >{-# LANGUAGE Haskell2010 #-}</span
+      ><span
+      >
+</span
+      ><span id="line-2"
+      ></span
+      ><span class="hs-keyword"
+      >module</span
+      ><span
+      > </span
+      ><span class="hs-identifier"
+      >Identifiers</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >where</span
+      ><span
+      >
+</span
+      ><span id="line-3"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-4"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-5"
+      ></span
+      ><span class="annot"
+      ><a href="Identifiers.html#foo"
+	><span class="hs-identifier hs-type"
+	  >foo</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Identifiers.html#bar"
+	><span class="hs-identifier hs-type"
+	  >bar</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Identifiers.html#baz"
+	><span class="hs-identifier hs-type"
+	  >baz</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>Int</span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>Int</span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>Int</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-6"
+      ></span
+      ><span id="foo"
+      ><span class="annot"
+	><span class="annottext"
+	  >foo :: Int -&gt; Int -&gt; Int
+</span
+	  ><a href="Identifiers.html#foo"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >foo</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >Int
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >x</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >Int
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >y</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >x</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int -&gt; Int -&gt; Int
+forall a. Num a =&gt; a -&gt; a -&gt; a
+</span
+	><span class="hs-operator hs-var"
+	>+</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >x</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int -&gt; Int -&gt; Int
+forall a. Num a =&gt; a -&gt; a -&gt; a
+</span
+	><span class="hs-operator hs-var"
+	>*</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int -&gt; Int -&gt; Int
+</span
+	><a href="Identifiers.html#bar"
+	><span class="hs-identifier hs-var"
+	  >bar</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >y</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >x</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int -&gt; Int -&gt; Int
+forall a. Num a =&gt; a -&gt; a -&gt; a
+</span
+	><span class="hs-operator hs-var"
+	>*</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >y</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int -&gt; Int -&gt; Int
+forall a. Num a =&gt; a -&gt; a -&gt; a
+</span
+	><span class="hs-operator hs-var"
+	>+</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >y</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-7"
+      ></span
+      ><span id="bar"
+      ><span class="annot"
+	><span class="annottext"
+	  >bar :: Int -&gt; Int -&gt; Int
+</span
+	  ><a href="Identifiers.html#bar"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >bar</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >Int
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >x</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >Int
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >y</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >y</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int -&gt; Int -&gt; Int
+forall a. Num a =&gt; a -&gt; a -&gt; a
+</span
+	><span class="hs-operator hs-var"
+	>+</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >x</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int -&gt; Int -&gt; Int
+forall a. Num a =&gt; a -&gt; a -&gt; a
+</span
+	><span class="hs-glyph hs-var"
+	>-</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int -&gt; Int -&gt; Int
+</span
+	><a href="Identifiers.html#baz"
+	><span class="hs-identifier hs-var"
+	  >baz</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >x</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >y</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int -&gt; Int -&gt; Int
+forall a. Num a =&gt; a -&gt; a -&gt; a
+</span
+	><span class="hs-glyph hs-var"
+	>-</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >x</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int -&gt; Int -&gt; Int
+forall a. Num a =&gt; a -&gt; a -&gt; a
+</span
+	><span class="hs-operator hs-var"
+	>+</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >y</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-8"
+      ></span
+      ><span id="baz"
+      ><span class="annot"
+	><span class="annottext"
+	  >baz :: Int -&gt; Int -&gt; Int
+</span
+	  ><a href="Identifiers.html#baz"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >baz</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >Int
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >x</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >Int
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >y</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >x</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int -&gt; Int -&gt; Int
+forall a. Num a =&gt; a -&gt; a -&gt; a
+</span
+	><span class="hs-operator hs-var"
+	>*</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >y</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int -&gt; Int -&gt; Int
+forall a. Num a =&gt; a -&gt; a -&gt; a
+</span
+	><span class="hs-operator hs-var"
+	>*</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >y</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int -&gt; Int -&gt; Int
+forall a. Num a =&gt; a -&gt; a -&gt; a
+</span
+	><span class="hs-operator hs-var"
+	>*</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >y</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int -&gt; Int -&gt; Int
+forall a. Num a =&gt; a -&gt; a -&gt; a
+</span
+	><span class="hs-operator hs-var"
+	>*</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >x</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-9"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-10"
+      ></span
+      ><span class="annot"
+      ><a href="Identifiers.html#quux"
+	><span class="hs-identifier hs-type"
+	  >quux</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>Int</span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>Int</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-11"
+      ></span
+      ><span id="quux"
+      ><span class="annot"
+	><span class="annottext"
+	  >quux :: Int -&gt; Int
+</span
+	  ><a href="Identifiers.html#quux"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >quux</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >Int
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >x</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int -&gt; Int -&gt; Int
+</span
+	><a href="Identifiers.html#foo"
+	><span class="hs-identifier hs-var"
+	  >foo</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int -&gt; Int -&gt; Int
+</span
+	><a href="Identifiers.html#bar"
+	><span class="hs-identifier hs-var"
+	  >bar</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >x</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >x</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int -&gt; Int -&gt; Int
+</span
+	><a href="Identifiers.html#bar"
+	><span class="hs-identifier hs-var"
+	  >bar</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >x</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >x</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      >
+</span
+      ><span id="line-12"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-13"
+      ></span
+      ><span class="annot"
+      ><a href="Identifiers.html#norf"
+	><span class="hs-identifier hs-type"
+	  >norf</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>Int</span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>Int</span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>Int</span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>Int</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-14"
+      ></span
+      ><span id="norf"
+      ><span class="annot"
+	><span class="annottext"
+	  >norf :: Int -&gt; Int -&gt; Int -&gt; Int
+</span
+	  ><a href="Identifiers.html#norf"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >norf</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >Int
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >x</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >Int
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >y</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >Int
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >z</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-15"
+      ></span
+      ><span
+      >    </span
+      ><span class="hs-glyph"
+      >|</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >x</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int -&gt; Int -&gt; Bool
+forall a. Ord a =&gt; a -&gt; a -&gt; Bool
+</span
+	><span class="hs-operator hs-var"
+	>&lt;</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><span class="hs-number"
+	>0</span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int -&gt; Int
+</span
+	><a href="Identifiers.html#quux"
+	><span class="hs-identifier hs-var"
+	  >quux</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >x</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-16"
+      ></span
+      ><span
+      >    </span
+      ><span class="hs-glyph"
+      >|</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >y</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int -&gt; Int -&gt; Bool
+forall a. Ord a =&gt; a -&gt; a -&gt; Bool
+</span
+	><span class="hs-operator hs-var"
+	>&lt;</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><span class="hs-number"
+	>0</span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int -&gt; Int
+</span
+	><a href="Identifiers.html#quux"
+	><span class="hs-identifier hs-var"
+	  >quux</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >y</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-17"
+      ></span
+      ><span
+      >    </span
+      ><span class="hs-glyph"
+      >|</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >z</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int -&gt; Int -&gt; Bool
+forall a. Ord a =&gt; a -&gt; a -&gt; Bool
+</span
+	><span class="hs-operator hs-var"
+	>&lt;</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><span class="hs-number"
+	>0</span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int -&gt; Int
+</span
+	><a href="Identifiers.html#quux"
+	><span class="hs-identifier hs-var"
+	  >quux</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >z</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-18"
+      ></span
+      ><span
+      >    </span
+      ><span class="hs-glyph"
+      >|</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Bool
+</span
+	><span class="hs-identifier hs-var"
+	>otherwise</span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int -&gt; Int -&gt; Int -&gt; Int
+</span
+	><a href="Identifiers.html#norf"
+	><span class="hs-identifier hs-var"
+	  >norf</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-glyph"
+      >-</span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >x</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-glyph"
+      >-</span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >y</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-glyph"
+      >-</span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >z</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      >
+</span
+      ><span id="line-19"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-20"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-21"
+      ></span
+      ><span class="annot"
+      ><a href="Identifiers.html#main"
+	><span class="hs-identifier hs-type"
+	  >main</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>IO</span
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      >
+</span
+      ><span id="line-22"
+      ></span
+      ><span id="main"
+      ><span class="annot"
+	><span class="annottext"
+	  >main :: IO ()
+</span
+	  ><a href="Identifiers.html#main"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >main</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >do</span
+      ><span
+      >
+</span
+      ><span id="line-23"
+      ></span
+      ><span
+      >    </span
+      ><span class="annot"
+      ><span class="annottext"
+	>String -&gt; IO ()
+</span
+	><span class="hs-identifier hs-var"
+	>putStrLn</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>(String -&gt; IO ()) -&gt; (Int -&gt; String) -&gt; Int -&gt; IO ()
+forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
+</span
+	><span class="hs-operator hs-var"
+	>.</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int -&gt; String
+forall a. Show a =&gt; a -&gt; String
+</span
+	><span class="hs-identifier hs-var"
+	>show</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>(Int -&gt; IO ()) -&gt; Int -&gt; IO ()
+forall a b. (a -&gt; b) -&gt; a -&gt; b
+</span
+	><span class="hs-operator hs-var"
+	>$</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int -&gt; Int -&gt; Int
+</span
+	><a href="Identifiers.html#foo"
+	><span class="hs-identifier hs-var"
+	  >foo</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >x</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >y</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-24"
+      ></span
+      ><span
+      >    </span
+      ><span class="annot"
+      ><span class="annottext"
+	>String -&gt; IO ()
+</span
+	><span class="hs-identifier hs-var"
+	>putStrLn</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>(String -&gt; IO ()) -&gt; (Int -&gt; String) -&gt; Int -&gt; IO ()
+forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
+</span
+	><span class="hs-operator hs-var"
+	>.</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int -&gt; String
+forall a. Show a =&gt; a -&gt; String
+</span
+	><span class="hs-identifier hs-var"
+	>show</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>(Int -&gt; IO ()) -&gt; Int -&gt; IO ()
+forall a b. (a -&gt; b) -&gt; a -&gt; b
+</span
+	><span class="hs-operator hs-var"
+	>$</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int -&gt; Int
+</span
+	><a href="Identifiers.html#quux"
+	><span class="hs-identifier hs-var"
+	  >quux</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >z</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-25"
+      ></span
+      ><span
+      >    </span
+      ><span class="annot"
+      ><span class="annottext"
+	>String -&gt; IO ()
+</span
+	><span class="hs-identifier hs-var"
+	>putStrLn</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>(String -&gt; IO ()) -&gt; (Int -&gt; String) -&gt; Int -&gt; IO ()
+forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
+</span
+	><span class="hs-operator hs-var"
+	>.</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int -&gt; String
+forall a. Show a =&gt; a -&gt; String
+</span
+	><span class="hs-identifier hs-var"
+	>show</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>(Int -&gt; IO ()) -&gt; Int -&gt; IO ()
+forall a b. (a -&gt; b) -&gt; a -&gt; b
+</span
+	><span class="hs-operator hs-var"
+	>$</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int -&gt; Int -&gt; Int -&gt; Int
+</span
+	><a href="Identifiers.html#norf"
+	><span class="hs-identifier hs-var"
+	  >Identifiers.norf</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >x</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >y</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >z</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-26"
+      ></span
+      ><span
+      >  </span
+      ><span class="hs-keyword"
+      >where</span
+      ><span
+      >
+</span
+      ><span id="line-27"
+      ></span
+      ><span
+      >    </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >x :: Int
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >x</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><span class="hs-number"
+	>10</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-28"
+      ></span
+      ><span
+      >    </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >y :: Int
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >y</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><span class="hs-number"
+	>20</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-29"
+      ></span
+      ><span
+      >    </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >z :: Int
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >z</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><span class="hs-number"
+	>30</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-30"
+      ></span
+      ></pre
+    ></body
+  ></html
+>
diff --git a/hypsrc-test/ref/src/LinkingIdentifiers.html b/hypsrc-test/ref/src/LinkingIdentifiers.html
new file mode 100644
--- /dev/null
+++ b/hypsrc-test/ref/src/LinkingIdentifiers.html
@@ -0,0 +1,623 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><link rel="stylesheet" type="text/css" href="style.css"
+     /><script type="text/javascript" src="highlight.js"
+    ></script
+    ></head
+  ><body
+  ><pre
+    ><span class="hs-pragma"
+      >{-# LANGUAGE Haskell2010 #-}</span
+      ><span
+      >
+</span
+      ><span id="line-2"
+      ></span
+      ><span class="hs-comment"
+      >-- Tests that the identifiers/operators are properly linked even when:</span
+      ><span
+      >
+</span
+      ><span id="line-3"
+      ></span
+      ><span class="hs-comment"
+      >--</span
+      ><span
+      >
+</span
+      ><span id="line-4"
+      ></span
+      ><span class="hs-comment"
+      >--   * backquoted, parenthesized, vanilla</span
+      ><span
+      >
+</span
+      ><span id="line-5"
+      ></span
+      ><span class="hs-comment"
+      >--   * qualified, not-qualified</span
+      ><span
+      >
+</span
+      ><span id="line-6"
+      ></span
+      ><span class="hs-comment"
+      >--</span
+      ><span
+      >
+</span
+      ><span id="line-7"
+      ></span
+      ><span class="hs-keyword"
+      >module</span
+      ><span
+      > </span
+      ><span class="hs-identifier"
+      >LinkingIdentifiers</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >where</span
+      ><span
+      >
+</span
+      ><span id="line-8"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-9"
+      ></span
+      ><span class="annot"
+      ><a href="LinkingIdentifiers.html#ident"
+	><span class="hs-identifier hs-type"
+	  >ident</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>Int</span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>Int</span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>Int</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-10"
+      ></span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >Int
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >x</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id="ident"
+      ><span class="annot"
+	><span class="annottext"
+	  >ident :: Int -&gt; Int -&gt; Int
+</span
+	  ><a href="LinkingIdentifiers.html#ident"
+	  ><span class="hs-operator hs-var hs-var"
+	    >`ident`</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><span class="hs-number"
+	>2</span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >x</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int -&gt; Int -&gt; Int
+</span
+	><a href="LinkingIdentifiers.html#ident"
+	><span class="hs-operator hs-var"
+	  >`ident`</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><span class="hs-number"
+	>2</span
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int -&gt; Int -&gt; Int
+forall a. Num a =&gt; a -&gt; a -&gt; a
+</span
+	><span class="hs-operator hs-var"
+	>+</span
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >x</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int -&gt; Int -&gt; Int
+</span
+	><a href="LinkingIdentifiers.html#ident"
+	><span class="hs-operator hs-var"
+	  >`LinkingIdentifiers.ident`</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><span class="hs-number"
+	>2</span
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      >
+</span
+      ><span id="line-11"
+      ></span
+      ><span class="annot"
+      ><a href="LinkingIdentifiers.html#ident"
+	><span class="hs-identifier hs-var"
+	  >ident</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >Int
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >x</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><span class="hs-number"
+	>2</span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int -&gt; Int -&gt; Int
+</span
+	><a href="LinkingIdentifiers.html#ident"
+	><span class="hs-identifier hs-var"
+	  >ident</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >x</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><span class="hs-number"
+	>2</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int -&gt; Int -&gt; Int
+forall a. Num a =&gt; a -&gt; a -&gt; a
+</span
+	><span class="hs-operator hs-var"
+	>+</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int -&gt; Int -&gt; Int
+</span
+	><a href="LinkingIdentifiers.html#ident"
+	><span class="hs-identifier hs-var"
+	  >LinkingIdentifiers.ident</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >x</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><span class="hs-number"
+	>2</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-12"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-13"
+      ></span
+      ><span class="annot"
+      ><a href="LinkingIdentifiers.html#%2B%2B%3A%2B%2B"
+	><span class="hs-operator hs-type"
+	  >(++:++)</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>Int</span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>Int</span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>Int</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-14"
+      ></span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >Int
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >x</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id="%2B%2B%3A%2B%2B"
+      ><span class="annot"
+	><span class="annottext"
+	  >++:++ :: Int -&gt; Int -&gt; Int
+</span
+	  ><a href="LinkingIdentifiers.html#%2B%2B%3A%2B%2B"
+	  ><span class="hs-operator hs-var hs-var"
+	    >++:++</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><span class="hs-number"
+	>2</span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >x</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int -&gt; Int -&gt; Int
+</span
+	><a href="LinkingIdentifiers.html#%2B%2B%3A%2B%2B"
+	><span class="hs-operator hs-var"
+	  >++:++</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><span class="hs-number"
+	>2</span
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int -&gt; Int -&gt; Int
+forall a. Num a =&gt; a -&gt; a -&gt; a
+</span
+	><span class="hs-operator hs-var"
+	>+</span
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >x</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int -&gt; Int -&gt; Int
+</span
+	><a href="LinkingIdentifiers.html#%2B%2B%3A%2B%2B"
+	><span class="hs-operator hs-var"
+	  >LinkingIdentifiers.++:++</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><span class="hs-number"
+	>2</span
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      >
+</span
+      ><span id="line-15"
+      ></span
+      ><span class="annot"
+      ><a href="LinkingIdentifiers.html#%2B%2B%3A%2B%2B"
+	><span class="hs-operator hs-var"
+	  >(++:++)</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >Int
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >x</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><span class="hs-number"
+	>2</span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int -&gt; Int -&gt; Int
+</span
+	><a href="LinkingIdentifiers.html#%2B%2B%3A%2B%2B"
+	><span class="hs-operator hs-var"
+	  >(++:++)</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >x</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><span class="hs-number"
+	>2</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int -&gt; Int -&gt; Int
+forall a. Num a =&gt; a -&gt; a -&gt; a
+</span
+	><span class="hs-operator hs-var"
+	>+</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int -&gt; Int -&gt; Int
+</span
+	><a href="LinkingIdentifiers.html#%2B%2B%3A%2B%2B"
+	><span class="hs-operator hs-var"
+	  >(LinkingIdentifiers.++:++)</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >x</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><span class="hs-number"
+	>2</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-16"
+      ></span
+      ></pre
+    ></body
+  ></html
+>
diff --git a/hypsrc-test/ref/src/Literals.html b/hypsrc-test/ref/src/Literals.html
new file mode 100644
--- /dev/null
+++ b/hypsrc-test/ref/src/Literals.html
@@ -0,0 +1,560 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><link rel="stylesheet" type="text/css" href="style.css"
+     /><script type="text/javascript" src="highlight.js"
+    ></script
+    ></head
+  ><body
+  ><pre
+    ><span class="hs-pragma"
+      >{-# LANGUAGE Haskell2010 #-}</span
+      ><span
+      >
+</span
+      ><span id="line-2"
+      ></span
+      ><span class="hs-keyword"
+      >module</span
+      ><span
+      > </span
+      ><span class="hs-identifier"
+      >Literals</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >where</span
+      ><span
+      >
+</span
+      ><span id="line-3"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-4"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-5"
+      ></span
+      ><span class="annot"
+      ><a href="Literals.html#str"
+	><span class="hs-identifier hs-type"
+	  >str</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>String</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-6"
+      ></span
+      ><span id="str"
+      ><span class="annot"
+	><span class="annottext"
+	  >str :: String
+</span
+	  ><a href="Literals.html#str"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >str</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>String
+</span
+	><span class="hs-string"
+	>&quot;str literal&quot;</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-7"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-8"
+      ></span
+      ><span id=""
+      ><span class="annot"
+	><a href="Literals.html#num"
+	  ><span class="hs-identifier hs-type"
+	    >num</span
+	    ></a
+	  ></span
+	><span
+	> </span
+	><span class="hs-glyph"
+	>::</span
+	><span
+	> </span
+	><span class="annot"
+	><span class="hs-identifier hs-type"
+	  >Num</span
+	  ></span
+	><span
+	> </span
+	><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >a</span
+	    ></a
+	  ></span
+	><span
+	> </span
+	><span class="hs-glyph"
+	>=&gt;</span
+	><span
+	> </span
+	><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >a</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-9"
+      ></span
+      ><span id="num"
+      ><span class="annot"
+	><span class="annottext"
+	  >num :: forall a. Num a =&gt; a
+</span
+	  ><a href="Literals.html#num"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >num</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>a
+</span
+	><span class="hs-number"
+	>0</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>a -&gt; a -&gt; a
+forall a. Num a =&gt; a -&gt; a -&gt; a
+</span
+	><span class="hs-operator hs-var"
+	>+</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>a
+</span
+	><span class="hs-number"
+	>1</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>a -&gt; a -&gt; a
+forall a. Num a =&gt; a -&gt; a -&gt; a
+</span
+	><span class="hs-operator hs-var"
+	>+</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>a
+</span
+	><span class="hs-number"
+	>1010011</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>a -&gt; a -&gt; a
+forall a. Num a =&gt; a -&gt; a -&gt; a
+</span
+	><span class="hs-operator hs-var"
+	>*</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>a
+</span
+	><span class="hs-number"
+	>41231</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>a -&gt; a -&gt; a
+forall a. Num a =&gt; a -&gt; a -&gt; a
+</span
+	><span class="hs-operator hs-var"
+	>+</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>a
+</span
+	><span class="hs-number"
+	>12131</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-10"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-11"
+      ></span
+      ><span id=""
+      ><span class="annot"
+	><a href="Literals.html#frac"
+	  ><span class="hs-identifier hs-type"
+	    >frac</span
+	    ></a
+	  ></span
+	><span
+	> </span
+	><span class="hs-glyph"
+	>::</span
+	><span
+	> </span
+	><span class="annot"
+	><span class="hs-identifier hs-type"
+	  >Fractional</span
+	  ></span
+	><span
+	> </span
+	><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >a</span
+	    ></a
+	  ></span
+	><span
+	> </span
+	><span class="hs-glyph"
+	>=&gt;</span
+	><span
+	> </span
+	><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >a</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-12"
+      ></span
+      ><span id="frac"
+      ><span class="annot"
+	><span class="annottext"
+	  >frac :: forall a. Fractional a =&gt; a
+</span
+	  ><a href="Literals.html#frac"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >frac</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>a
+</span
+	><span class="hs-number"
+	>42.0000001</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-13"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-14"
+      ></span
+      ><span id=""
+      ><span class="annot"
+	><a href="Literals.html#list"
+	  ><span class="hs-identifier hs-type"
+	    >list</span
+	    ></a
+	  ></span
+	><span
+	> </span
+	><span class="hs-glyph"
+	>::</span
+	><span
+	> </span
+	><span class="hs-special"
+	>[</span
+	><span class="hs-special"
+	>[</span
+	><span class="hs-special"
+	>[</span
+	><span class="hs-special"
+	>[</span
+	><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >a</span
+	    ></a
+	  ></span
+	><span class="hs-special"
+	>]</span
+	><span class="hs-special"
+	>]</span
+	><span class="hs-special"
+	>]</span
+	><span class="hs-special"
+	>]</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-15"
+      ></span
+      ><span id="list"
+      ><span class="annot"
+	><span class="annottext"
+	  >list :: forall a. [[[[a]]]]
+</span
+	  ><a href="Literals.html#list"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >list</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >[</span
+      ><span class="hs-special"
+      >[</span
+      ><span class="hs-special"
+      >]</span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >[</span
+      ><span class="hs-special"
+      >[</span
+      ><span class="hs-special"
+      >]</span
+      ><span class="hs-special"
+      >]</span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >[</span
+      ><span class="hs-special"
+      >[</span
+      ><span class="hs-special"
+      >[</span
+      ><span class="hs-special"
+      >]</span
+      ><span class="hs-special"
+      >]</span
+      ><span class="hs-special"
+      >]</span
+      ><span class="hs-special"
+      >]</span
+      ><span
+      >
+</span
+      ><span id="line-16"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-17"
+      ></span
+      ><span class="annot"
+      ><a href="Literals.html#pair"
+	><span class="hs-identifier hs-type"
+	  >pair</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-special"
+      >)</span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-special"
+      >)</span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-special"
+      >)</span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-special"
+      >)</span
+      ><span class="hs-special"
+      >)</span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-special"
+      >)</span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      >
+</span
+      ><span id="line-18"
+      ></span
+      ><span id="pair"
+      ><span class="annot"
+	><span class="annottext"
+	  >pair :: ((), ((), (), ()), ())
+</span
+	  ><a href="Literals.html#pair"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >pair</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-special"
+      >)</span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-special"
+      >)</span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-special"
+      >)</span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-special"
+      >)</span
+      ><span class="hs-special"
+      >)</span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-special"
+      >)</span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      >
+</span
+      ><span id="line-19"
+      ></span
+      ></pre
+    ></body
+  ></html
+>
diff --git a/hypsrc-test/ref/src/Operators.html b/hypsrc-test/ref/src/Operators.html
new file mode 100644
--- /dev/null
+++ b/hypsrc-test/ref/src/Operators.html
@@ -0,0 +1,1136 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><link rel="stylesheet" type="text/css" href="style.css"
+     /><script type="text/javascript" src="highlight.js"
+    ></script
+    ></head
+  ><body
+  ><pre
+    ><span class="hs-pragma"
+      >{-# LANGUAGE Haskell2010 #-}</span
+      ><span
+      >
+</span
+      ><span id="line-2"
+      ></span
+      ><span class="hs-keyword"
+      >module</span
+      ><span
+      > </span
+      ><span class="hs-identifier"
+      >Operators</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >where</span
+      ><span
+      >
+</span
+      ><span id="line-3"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-4"
+      ></span
+      ><span id=""
+      ><span class="annot"
+	><a href="Operators.html#%2B%2B%2B"
+	  ><span class="hs-operator hs-type"
+	    >(+++)</span
+	    ></a
+	  ></span
+	><span
+	> </span
+	><span class="hs-glyph"
+	>::</span
+	><span
+	> </span
+	><span class="hs-special"
+	>[</span
+	><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >a</span
+	    ></a
+	  ></span
+	><span class="hs-special"
+	>]</span
+	><span
+	> </span
+	><span class="hs-glyph"
+	>-&gt;</span
+	><span
+	> </span
+	><span class="hs-special"
+	>[</span
+	><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >a</span
+	    ></a
+	  ></span
+	><span class="hs-special"
+	>]</span
+	><span
+	> </span
+	><span class="hs-glyph"
+	>-&gt;</span
+	><span
+	> </span
+	><span class="hs-special"
+	>[</span
+	><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >a</span
+	    ></a
+	  ></span
+	><span class="hs-special"
+	>]</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-5"
+      ></span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >[a]
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >a</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id="%2B%2B%2B"
+      ><span class="annot"
+	><span class="annottext"
+	  >+++ :: forall a. [a] -&gt; [a] -&gt; [a]
+</span
+	  ><a href="Operators.html#%2B%2B%2B"
+	  ><span class="hs-operator hs-var hs-var"
+	    >+++</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >[a]
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >b</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>[a]
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >a</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>[a] -&gt; [a] -&gt; [a]
+forall a. [a] -&gt; [a] -&gt; [a]
+</span
+	><span class="hs-operator hs-var"
+	>++</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>[a]
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >b</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>[a] -&gt; [a] -&gt; [a]
+forall a. [a] -&gt; [a] -&gt; [a]
+</span
+	><span class="hs-operator hs-var"
+	>++</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>[a]
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >a</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-6"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-7"
+      ></span
+      ><span id=""
+      ><span class="annot"
+	><a href="Operators.html#%24%24%24"
+	  ><span class="hs-operator hs-type"
+	    >($$$)</span
+	    ></a
+	  ></span
+	><span
+	> </span
+	><span class="hs-glyph"
+	>::</span
+	><span
+	> </span
+	><span class="hs-special"
+	>[</span
+	><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >a</span
+	    ></a
+	  ></span
+	><span class="hs-special"
+	>]</span
+	><span
+	> </span
+	><span class="hs-glyph"
+	>-&gt;</span
+	><span
+	> </span
+	><span class="hs-special"
+	>[</span
+	><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >a</span
+	    ></a
+	  ></span
+	><span class="hs-special"
+	>]</span
+	><span
+	> </span
+	><span class="hs-glyph"
+	>-&gt;</span
+	><span
+	> </span
+	><span class="hs-special"
+	>[</span
+	><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >a</span
+	    ></a
+	  ></span
+	><span class="hs-special"
+	>]</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-8"
+      ></span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >[a]
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >a</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id="%24%24%24"
+      ><span class="annot"
+	><span class="annottext"
+	  >$$$ :: forall a. [a] -&gt; [a] -&gt; [a]
+</span
+	  ><a href="Operators.html#%24%24%24"
+	  ><span class="hs-operator hs-var hs-var"
+	    >$$$</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >[a]
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >b</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>[a]
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >b</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>[a] -&gt; [a] -&gt; [a]
+forall a. [a] -&gt; [a] -&gt; [a]
+</span
+	><a href="Operators.html#%2B%2B%2B"
+	><span class="hs-operator hs-var"
+	  >+++</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>[a]
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >a</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-9"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-10"
+      ></span
+      ><span id=""
+      ><span class="annot"
+	><a href="Operators.html#%2A%2A%2A"
+	  ><span class="hs-operator hs-type"
+	    >(***)</span
+	    ></a
+	  ></span
+	><span
+	> </span
+	><span class="hs-glyph"
+	>::</span
+	><span
+	> </span
+	><span class="hs-special"
+	>[</span
+	><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >a</span
+	    ></a
+	  ></span
+	><span class="hs-special"
+	>]</span
+	><span
+	> </span
+	><span class="hs-glyph"
+	>-&gt;</span
+	><span
+	> </span
+	><span class="hs-special"
+	>[</span
+	><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >a</span
+	    ></a
+	  ></span
+	><span class="hs-special"
+	>]</span
+	><span
+	> </span
+	><span class="hs-glyph"
+	>-&gt;</span
+	><span
+	> </span
+	><span class="hs-special"
+	>[</span
+	><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >a</span
+	    ></a
+	  ></span
+	><span class="hs-special"
+	>]</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-11"
+      ></span
+      ><span id="%2A%2A%2A"
+      ><span class="annot"
+	><span class="annottext"
+	  >*** :: forall a. [a] -&gt; [a] -&gt; [a]
+</span
+	  ><a href="Operators.html#%2A%2A%2A"
+	  ><span class="hs-operator hs-var hs-var"
+	    >(***)</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >[a]
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >a</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >[</span
+      ><span class="hs-special"
+      >]</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>[a]
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >a</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-12"
+      ></span
+      ><span class="annot"
+      ><a href="Operators.html#%2A%2A%2A"
+	><span class="hs-operator hs-var"
+	  >(***)</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >[a]
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >a</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><span class="annottext"
+	>a
+</span
+	><span class="hs-identifier"
+	>_</span
+	></span
+      ><span class="annot"
+      ><span class="hs-glyph hs-type"
+	>:</span
+	></span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >[a]
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >b</span
+	    ></a
+	  ></span
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>[a]
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >a</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>[a] -&gt; [a] -&gt; [a]
+forall a. [a] -&gt; [a] -&gt; [a]
+</span
+	><a href="Operators.html#%2B%2B%2B"
+	><span class="hs-operator hs-var"
+	  >+++</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><span class="annottext"
+	>[a]
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >a</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>[a] -&gt; [a] -&gt; [a]
+forall a. [a] -&gt; [a] -&gt; [a]
+</span
+	><a href="Operators.html#%2A%2A%2A"
+	><span class="hs-operator hs-var"
+	  >***</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>[a]
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >b</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      >
+</span
+      ><span id="line-13"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-14"
+      ></span
+      ><span id=""
+      ><span class="annot"
+	><a href="Operators.html#%2A%2F%5C%2A"
+	  ><span class="hs-operator hs-type"
+	    >(*/\*)</span
+	    ></a
+	  ></span
+	><span
+	> </span
+	><span class="hs-glyph"
+	>::</span
+	><span
+	> </span
+	><span class="hs-special"
+	>[</span
+	><span class="hs-special"
+	>[</span
+	><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >a</span
+	    ></a
+	  ></span
+	><span class="hs-special"
+	>]</span
+	><span class="hs-special"
+	>]</span
+	><span
+	> </span
+	><span class="hs-glyph"
+	>-&gt;</span
+	><span
+	> </span
+	><span class="hs-special"
+	>[</span
+	><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >a</span
+	    ></a
+	  ></span
+	><span class="hs-special"
+	>]</span
+	><span
+	> </span
+	><span class="hs-glyph"
+	>-&gt;</span
+	><span
+	> </span
+	><span class="hs-special"
+	>[</span
+	><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >a</span
+	    ></a
+	  ></span
+	><span class="hs-special"
+	>]</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-15"
+      ></span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >[[a]]
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >a</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id="%2A%2F%5C%2A"
+      ><span class="annot"
+	><span class="annottext"
+	  >*/\* :: forall a. [[a]] -&gt; [a] -&gt; [a]
+</span
+	  ><a href="Operators.html#%2A%2F%5C%2A"
+	  ><span class="hs-operator hs-var hs-var"
+	    >*/\*</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >[a]
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >b</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>([a] -&gt; [a]) -&gt; [[a]] -&gt; [a]
+forall (t :: * -&gt; *) a b. Foldable t =&gt; (a -&gt; [b]) -&gt; t a -&gt; [b]
+</span
+	><span class="hs-identifier hs-var"
+	>concatMap</span
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><span class="annottext"
+	>[a] -&gt; [a] -&gt; [a]
+forall a. [a] -&gt; [a] -&gt; [a]
+</span
+	><a href="Operators.html#%2A%2A%2A"
+	><span class="hs-operator hs-var"
+	  >***</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>[a]
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >b</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>[[a]]
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >a</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-16"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-17"
+      ></span
+      ><span id=""
+      ><span class="annot"
+	><a href="Operators.html#%2A%2A%2F%5C%2A%2A"
+	  ><span class="hs-operator hs-type"
+	    >(**/\**)</span
+	    ></a
+	  ></span
+	><span
+	> </span
+	><span class="hs-glyph"
+	>::</span
+	><span
+	> </span
+	><span class="hs-special"
+	>[</span
+	><span class="hs-special"
+	>[</span
+	><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >a</span
+	    ></a
+	  ></span
+	><span class="hs-special"
+	>]</span
+	><span class="hs-special"
+	>]</span
+	><span
+	> </span
+	><span class="hs-glyph"
+	>-&gt;</span
+	><span
+	> </span
+	><span class="hs-special"
+	>[</span
+	><span class="hs-special"
+	>[</span
+	><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >a</span
+	    ></a
+	  ></span
+	><span class="hs-special"
+	>]</span
+	><span class="hs-special"
+	>]</span
+	><span
+	> </span
+	><span class="hs-glyph"
+	>-&gt;</span
+	><span
+	> </span
+	><span class="hs-special"
+	>[</span
+	><span class="hs-special"
+	>[</span
+	><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >a</span
+	    ></a
+	  ></span
+	><span class="hs-special"
+	>]</span
+	><span class="hs-special"
+	>]</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-18"
+      ></span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >[[a]]
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >a</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id="%2A%2A%2F%5C%2A%2A"
+      ><span class="annot"
+	><span class="annottext"
+	  >**/\** :: forall a. [[a]] -&gt; [[a]] -&gt; [[a]]
+</span
+	  ><a href="Operators.html#%2A%2A%2F%5C%2A%2A"
+	  ><span class="hs-operator hs-var hs-var"
+	    >**/\**</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >[[a]]
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >b</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>([[a]] -&gt; [a] -&gt; [a]) -&gt; [[[a]]] -&gt; [[a]] -&gt; [[a]]
+forall a b c. (a -&gt; b -&gt; c) -&gt; [a] -&gt; [b] -&gt; [c]
+</span
+	><span class="hs-identifier hs-var"
+	>zipWith</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>[[a]] -&gt; [a] -&gt; [a]
+forall a. [[a]] -&gt; [a] -&gt; [a]
+</span
+	><a href="Operators.html#%2A%2F%5C%2A"
+	><span class="hs-operator hs-var"
+	  >(*/\*)</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >[</span
+      ><span class="annot"
+      ><span class="annottext"
+	>[[a]]
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >a</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>[[a]] -&gt; [[a]] -&gt; [[a]]
+forall a. [a] -&gt; [a] -&gt; [a]
+</span
+	><a href="Operators.html#%2B%2B%2B"
+	><span class="hs-operator hs-var"
+	  >+++</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>[[a]]
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >b</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >]</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><span class="annottext"
+	>[[a]]
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >a</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>[[a]] -&gt; [[a]] -&gt; [[a]]
+forall a. [a] -&gt; [a] -&gt; [a]
+</span
+	><a href="Operators.html#%24%24%24"
+	><span class="hs-operator hs-var"
+	  >$$$</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>[[a]]
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >b</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      >
+</span
+      ><span id="line-19"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-20"
+      ></span
+      ><span id=""
+      ><span id=""
+	><span id=""
+	  ><span class="annot"
+	    ><a href="Operators.html#%23.%23"
+	      ><span class="hs-operator hs-type"
+		>(#.#)</span
+		></a
+	      ></span
+	    ><span
+	    > </span
+	    ><span class="hs-glyph"
+	    >::</span
+	    ><span
+	    > </span
+	    ><span class="annot"
+	    ><a href="#"
+	      ><span class="hs-identifier hs-type"
+		>a</span
+		></a
+	      ></span
+	    ><span
+	    > </span
+	    ><span class="hs-glyph"
+	    >-&gt;</span
+	    ><span
+	    > </span
+	    ><span class="annot"
+	    ><a href="#"
+	      ><span class="hs-identifier hs-type"
+		>b</span
+		></a
+	      ></span
+	    ><span
+	    > </span
+	    ><span class="hs-glyph"
+	    >-&gt;</span
+	    ><span
+	    > </span
+	    ><span class="hs-special"
+	    >(</span
+	    ><span class="annot"
+	    ><a href="#"
+	      ><span class="hs-identifier hs-type"
+		>c</span
+		></a
+	      ></span
+	    ><span
+	    > </span
+	    ><span class="hs-glyph"
+	    >-&gt;</span
+	    ><span
+	    > </span
+	    ><span class="hs-special"
+	    >(</span
+	    ><span class="annot"
+	    ><a href="#"
+	      ><span class="hs-identifier hs-type"
+		>a</span
+		></a
+	      ></span
+	    ><span class="hs-special"
+	    >,</span
+	    ><span
+	    > </span
+	    ><span class="annot"
+	    ><a href="#"
+	      ><span class="hs-identifier hs-type"
+		>b</span
+		></a
+	      ></span
+	    ><span class="hs-special"
+	    >)</span
+	    ><span class="hs-special"
+	    >)</span
+	    ></span
+	  ></span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-21"
+      ></span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >a
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >a</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id="%23.%23"
+      ><span class="annot"
+	><span class="annottext"
+	  >#.# :: forall a b c. a -&gt; b -&gt; c -&gt; (a, b)
+</span
+	  ><a href="Operators.html#%23.%23"
+	  ><span class="hs-operator hs-var hs-var"
+	    >#.#</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >b
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >b</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>(a, b) -&gt; c -&gt; (a, b)
+forall a b. a -&gt; b -&gt; a
+</span
+	><span class="hs-identifier hs-var"
+	>const</span
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><span class="annottext"
+	>a
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >a</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>b
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >b</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      >
+</span
+      ><span id="line-22"
+      ></span
+      ></pre
+    ></body
+  ></html
+>
diff --git a/hypsrc-test/ref/src/Polymorphism.html b/hypsrc-test/ref/src/Polymorphism.html
new file mode 100644
--- /dev/null
+++ b/hypsrc-test/ref/src/Polymorphism.html
@@ -0,0 +1,2656 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><link rel="stylesheet" type="text/css" href="style.css"
+     /><script type="text/javascript" src="highlight.js"
+    ></script
+    ></head
+  ><body
+  ><pre
+    ><span class="hs-pragma"
+      >{-# LANGUAGE Haskell2010 #-}</span
+      ><span
+      >
+</span
+      ><span id="line-2"
+      ></span
+      ><span class="hs-pragma"
+      >{-# LANGUAGE RankNTypes #-}</span
+      ><span
+      >
+</span
+      ><span id="line-3"
+      ></span
+      ><span class="hs-pragma"
+      >{-# LANGUAGE ScopedTypeVariables #-}</span
+      ><span
+      >
+</span
+      ><span id="line-4"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-5"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-6"
+      ></span
+      ><span class="hs-keyword"
+      >module</span
+      ><span
+      > </span
+      ><span class="hs-identifier"
+      >Polymorphism</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >where</span
+      ><span
+      >
+</span
+      ><span id="line-7"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-8"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-9"
+      ></span
+      ><span id=""
+      ><span class="annot"
+	><a href="Polymorphism.html#foo"
+	  ><span class="hs-identifier hs-type"
+	    >foo</span
+	    ></a
+	  ></span
+	><span
+	> </span
+	><span class="hs-glyph"
+	>::</span
+	><span
+	> </span
+	><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >a</span
+	    ></a
+	  ></span
+	><span
+	> </span
+	><span class="hs-glyph"
+	>-&gt;</span
+	><span
+	> </span
+	><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >a</span
+	    ></a
+	  ></span
+	><span
+	> </span
+	><span class="hs-glyph"
+	>-&gt;</span
+	><span
+	> </span
+	><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >a</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-10"
+      ></span
+      ><span id="foo"
+      ><span class="annot"
+	><span class="annottext"
+	  >foo :: forall a. a -&gt; a -&gt; a
+</span
+	  ><a href="Polymorphism.html#foo"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >foo</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>a -&gt; a -&gt; a
+forall a. HasCallStack =&gt; a
+</span
+	><span class="hs-identifier hs-var"
+	>undefined</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-11"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-12"
+      ></span
+      ><span class="annot"
+      ><a href="Polymorphism.html#foo%27"
+	><span class="hs-identifier hs-type"
+	  >foo'</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >forall</span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >a</span
+	    ></a
+	  ></span
+	></span
+      ><span class="hs-operator"
+      >.</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >a</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >a</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >a</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-13"
+      ></span
+      ><span id="foo%27"
+      ><span class="annot"
+	><span class="annottext"
+	  >foo' :: forall a. a -&gt; a -&gt; a
+</span
+	  ><a href="Polymorphism.html#foo%27"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >foo'</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>a -&gt; a -&gt; a
+forall a. HasCallStack =&gt; a
+</span
+	><span class="hs-identifier hs-var"
+	>undefined</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-14"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-15"
+      ></span
+      ><span id=""
+      ><span id=""
+	><span class="annot"
+	  ><a href="Polymorphism.html#bar"
+	    ><span class="hs-identifier hs-type"
+	      >bar</span
+	      ></a
+	    ></span
+	  ><span
+	  > </span
+	  ><span class="hs-glyph"
+	  >::</span
+	  ><span
+	  > </span
+	  ><span class="annot"
+	  ><a href="#"
+	    ><span class="hs-identifier hs-type"
+	      >a</span
+	      ></a
+	    ></span
+	  ><span
+	  > </span
+	  ><span class="hs-glyph"
+	  >-&gt;</span
+	  ><span
+	  > </span
+	  ><span class="annot"
+	  ><a href="#"
+	    ><span class="hs-identifier hs-type"
+	      >b</span
+	      ></a
+	    ></span
+	  ><span
+	  > </span
+	  ><span class="hs-glyph"
+	  >-&gt;</span
+	  ><span
+	  > </span
+	  ><span class="hs-special"
+	  >(</span
+	  ><span class="annot"
+	  ><a href="#"
+	    ><span class="hs-identifier hs-type"
+	      >a</span
+	      ></a
+	    ></span
+	  ><span class="hs-special"
+	  >,</span
+	  ><span
+	  > </span
+	  ><span class="annot"
+	  ><a href="#"
+	    ><span class="hs-identifier hs-type"
+	      >b</span
+	      ></a
+	    ></span
+	  ><span class="hs-special"
+	  >)</span
+	  ></span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-16"
+      ></span
+      ><span id="bar"
+      ><span class="annot"
+	><span class="annottext"
+	  >bar :: forall a b. a -&gt; b -&gt; (a, b)
+</span
+	  ><a href="Polymorphism.html#bar"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >bar</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>a -&gt; b -&gt; (a, b)
+forall a. HasCallStack =&gt; a
+</span
+	><span class="hs-identifier hs-var"
+	>undefined</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-17"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-18"
+      ></span
+      ><span class="annot"
+      ><a href="Polymorphism.html#bar%27"
+	><span class="hs-identifier hs-type"
+	  >bar'</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >forall</span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >a</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >b</span
+	    ></a
+	  ></span
+	></span
+      ><span class="hs-operator"
+      >.</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >a</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >b</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >a</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >b</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      >
+</span
+      ><span id="line-19"
+      ></span
+      ><span id="bar%27"
+      ><span class="annot"
+	><span class="annottext"
+	  >bar' :: forall a b. a -&gt; b -&gt; (a, b)
+</span
+	  ><a href="Polymorphism.html#bar%27"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >bar'</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>a -&gt; b -&gt; (a, b)
+forall a. HasCallStack =&gt; a
+</span
+	><span class="hs-identifier hs-var"
+	>undefined</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-20"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-21"
+      ></span
+      ><span id=""
+      ><span id=""
+	><span class="annot"
+	  ><a href="Polymorphism.html#baz"
+	    ><span class="hs-identifier hs-type"
+	      >baz</span
+	      ></a
+	    ></span
+	  ><span
+	  > </span
+	  ><span class="hs-glyph"
+	  >::</span
+	  ><span
+	  > </span
+	  ><span class="annot"
+	  ><a href="#"
+	    ><span class="hs-identifier hs-type"
+	      >a</span
+	      ></a
+	    ></span
+	  ><span
+	  > </span
+	  ><span class="hs-glyph"
+	  >-&gt;</span
+	  ><span
+	  > </span
+	  ><span class="hs-special"
+	  >(</span
+	  ><span class="annot"
+	  ><a href="#"
+	    ><span class="hs-identifier hs-type"
+	      >a</span
+	      ></a
+	    ></span
+	  ><span
+	  > </span
+	  ><span class="hs-glyph"
+	  >-&gt;</span
+	  ><span
+	  > </span
+	  ><span class="hs-special"
+	  >[</span
+	  ><span class="annot"
+	  ><a href="#"
+	    ><span class="hs-identifier hs-type"
+	      >a</span
+	      ></a
+	    ></span
+	  ><span
+	  > </span
+	  ><span class="hs-glyph"
+	  >-&gt;</span
+	  ><span
+	  > </span
+	  ><span class="annot"
+	  ><a href="#"
+	    ><span class="hs-identifier hs-type"
+	      >a</span
+	      ></a
+	    ></span
+	  ><span class="hs-special"
+	  >]</span
+	  ><span
+	  > </span
+	  ><span class="hs-glyph"
+	  >-&gt;</span
+	  ><span
+	  > </span
+	  ><span class="annot"
+	  ><a href="#"
+	    ><span class="hs-identifier hs-type"
+	      >b</span
+	      ></a
+	    ></span
+	  ><span class="hs-special"
+	  >)</span
+	  ><span
+	  > </span
+	  ><span class="hs-glyph"
+	  >-&gt;</span
+	  ><span
+	  > </span
+	  ><span class="annot"
+	  ><a href="#"
+	    ><span class="hs-identifier hs-type"
+	      >b</span
+	      ></a
+	    ></span
+	  ></span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-22"
+      ></span
+      ><span id="baz"
+      ><span class="annot"
+	><span class="annottext"
+	  >baz :: forall a b. a -&gt; (a -&gt; [a -&gt; a] -&gt; b) -&gt; b
+</span
+	  ><a href="Polymorphism.html#baz"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >baz</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>a -&gt; (a -&gt; [a -&gt; a] -&gt; b) -&gt; b
+forall a. HasCallStack =&gt; a
+</span
+	><span class="hs-identifier hs-var"
+	>undefined</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-23"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-24"
+      ></span
+      ><span class="annot"
+      ><a href="Polymorphism.html#baz%27"
+	><span class="hs-identifier hs-type"
+	  >baz'</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >forall</span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >a</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >b</span
+	    ></a
+	  ></span
+	></span
+      ><span class="hs-operator"
+      >.</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >a</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >a</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >[</span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >a</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >a</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >]</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >b</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >b</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-25"
+      ></span
+      ><span id="baz%27"
+      ><span class="annot"
+	><span class="annottext"
+	  >baz' :: forall a b. a -&gt; (a -&gt; [a -&gt; a] -&gt; b) -&gt; b
+</span
+	  ><a href="Polymorphism.html#baz%27"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >baz'</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>a -&gt; (a -&gt; [a -&gt; a] -&gt; b) -&gt; b
+forall a. HasCallStack =&gt; a
+</span
+	><span class="hs-identifier hs-var"
+	>undefined</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-26"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-27"
+      ></span
+      ><span id=""
+      ><span class="annot"
+	><a href="Polymorphism.html#quux"
+	  ><span class="hs-identifier hs-type"
+	    >quux</span
+	    ></a
+	  ></span
+	><span
+	> </span
+	><span class="hs-glyph"
+	>::</span
+	><span
+	> </span
+	><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >a</span
+	    ></a
+	  ></span
+	><span
+	> </span
+	><span class="hs-glyph"
+	>-&gt;</span
+	><span
+	> </span
+	><span class="hs-special"
+	>(</span
+	><span class="hs-keyword"
+	>forall</span
+	><span
+	> </span
+	><span id=""
+	><span class="annot"
+	  ><a href="#"
+	    ><span class="hs-identifier hs-type"
+	      >a</span
+	      ></a
+	    ></span
+	  ></span
+	><span class="hs-operator"
+	>.</span
+	><span
+	> </span
+	><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >a</span
+	    ></a
+	  ></span
+	><span
+	> </span
+	><span class="hs-glyph"
+	>-&gt;</span
+	><span
+	> </span
+	><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >a</span
+	    ></a
+	  ></span
+	><span class="hs-special"
+	>)</span
+	><span
+	> </span
+	><span class="hs-glyph"
+	>-&gt;</span
+	><span
+	> </span
+	><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >a</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-28"
+      ></span
+      ><span id="quux"
+      ><span class="annot"
+	><span class="annottext"
+	  >quux :: forall a. a -&gt; (forall a. a -&gt; a) -&gt; a
+</span
+	  ><a href="Polymorphism.html#quux"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >quux</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >a
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >x</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >forall a. a -&gt; a
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >f</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>a -&gt; a
+forall a. a -&gt; a
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >f</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>a
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >x</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-29"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-30"
+      ></span
+      ><span class="annot"
+      ><a href="Polymorphism.html#quux%27"
+	><span class="hs-identifier hs-type"
+	  >quux'</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >forall</span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >a</span
+	    ></a
+	  ></span
+	></span
+      ><span class="hs-operator"
+      >.</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >a</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-keyword"
+      >forall</span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >a</span
+	    ></a
+	  ></span
+	></span
+      ><span class="hs-operator"
+      >.</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >a</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >a</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >a</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-31"
+      ></span
+      ><span id="quux%27"
+      ><span class="annot"
+	><span class="annottext"
+	  >quux' :: forall a. a -&gt; (forall a. a -&gt; a) -&gt; a
+</span
+	  ><a href="Polymorphism.html#quux%27"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >quux'</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >a
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >x</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >forall a. a -&gt; a
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >f</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>a -&gt; a
+forall a. a -&gt; a
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >f</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>a
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >x</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-32"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-33"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-34"
+      ></span
+      ><span id=""
+      ><span class="annot"
+	><a href="Polymorphism.html#num"
+	  ><span class="hs-identifier hs-type"
+	    >num</span
+	    ></a
+	  ></span
+	><span
+	> </span
+	><span class="hs-glyph"
+	>::</span
+	><span
+	> </span
+	><span class="annot"
+	><span class="hs-identifier hs-type"
+	  >Num</span
+	  ></span
+	><span
+	> </span
+	><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >a</span
+	    ></a
+	  ></span
+	><span
+	> </span
+	><span class="hs-glyph"
+	>=&gt;</span
+	><span
+	> </span
+	><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >a</span
+	    ></a
+	  ></span
+	><span
+	> </span
+	><span class="hs-glyph"
+	>-&gt;</span
+	><span
+	> </span
+	><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >a</span
+	    ></a
+	  ></span
+	><span
+	> </span
+	><span class="hs-glyph"
+	>-&gt;</span
+	><span
+	> </span
+	><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >a</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-35"
+      ></span
+      ><span id="num"
+      ><span class="annot"
+	><span class="annottext"
+	  >num :: forall a. Num a =&gt; a -&gt; a -&gt; a
+</span
+	  ><a href="Polymorphism.html#num"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >num</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>a -&gt; a -&gt; a
+forall a. HasCallStack =&gt; a
+</span
+	><span class="hs-identifier hs-var"
+	>undefined</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-36"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-37"
+      ></span
+      ><span class="annot"
+      ><a href="Polymorphism.html#num%27"
+	><span class="hs-identifier hs-type"
+	  >num'</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >forall</span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >a</span
+	    ></a
+	  ></span
+	></span
+      ><span class="hs-operator"
+      >.</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>Num</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >a</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=&gt;</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >a</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >a</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >a</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-38"
+      ></span
+      ><span id="num%27"
+      ><span class="annot"
+	><span class="annottext"
+	  >num' :: forall a. Num a =&gt; a -&gt; a -&gt; a
+</span
+	  ><a href="Polymorphism.html#num%27"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >num'</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>a -&gt; a -&gt; a
+forall a. HasCallStack =&gt; a
+</span
+	><span class="hs-identifier hs-var"
+	>undefined</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-39"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-40"
+      ></span
+      ><span id=""
+      ><span id=""
+	><span class="annot"
+	  ><a href="Polymorphism.html#eq"
+	    ><span class="hs-identifier hs-type"
+	      >eq</span
+	      ></a
+	    ></span
+	  ><span
+	  > </span
+	  ><span class="hs-glyph"
+	  >::</span
+	  ><span
+	  > </span
+	  ><span class="hs-special"
+	  >(</span
+	  ><span class="annot"
+	  ><span class="hs-identifier hs-type"
+	    >Eq</span
+	    ></span
+	  ><span
+	  > </span
+	  ><span class="annot"
+	  ><a href="#"
+	    ><span class="hs-identifier hs-type"
+	      >a</span
+	      ></a
+	    ></span
+	  ><span class="hs-special"
+	  >,</span
+	  ><span
+	  > </span
+	  ><span class="annot"
+	  ><span class="hs-identifier hs-type"
+	    >Eq</span
+	    ></span
+	  ><span
+	  > </span
+	  ><span class="annot"
+	  ><a href="#"
+	    ><span class="hs-identifier hs-type"
+	      >b</span
+	      ></a
+	    ></span
+	  ><span class="hs-special"
+	  >)</span
+	  ><span
+	  > </span
+	  ><span class="hs-glyph"
+	  >=&gt;</span
+	  ><span
+	  > </span
+	  ><span class="hs-special"
+	  >[</span
+	  ><span class="annot"
+	  ><a href="#"
+	    ><span class="hs-identifier hs-type"
+	      >a</span
+	      ></a
+	    ></span
+	  ><span class="hs-special"
+	  >]</span
+	  ><span
+	  > </span
+	  ><span class="hs-glyph"
+	  >-&gt;</span
+	  ><span
+	  > </span
+	  ><span class="hs-special"
+	  >[</span
+	  ><span class="annot"
+	  ><a href="#"
+	    ><span class="hs-identifier hs-type"
+	      >b</span
+	      ></a
+	    ></span
+	  ><span class="hs-special"
+	  >]</span
+	  ><span
+	  > </span
+	  ><span class="hs-glyph"
+	  >-&gt;</span
+	  ><span
+	  > </span
+	  ><span class="hs-special"
+	  >(</span
+	  ><span class="annot"
+	  ><a href="#"
+	    ><span class="hs-identifier hs-type"
+	      >a</span
+	      ></a
+	    ></span
+	  ><span class="hs-special"
+	  >,</span
+	  ><span
+	  > </span
+	  ><span class="annot"
+	  ><a href="#"
+	    ><span class="hs-identifier hs-type"
+	      >b</span
+	      ></a
+	    ></span
+	  ><span class="hs-special"
+	  >)</span
+	  ></span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-41"
+      ></span
+      ><span id="eq"
+      ><span class="annot"
+	><span class="annottext"
+	  >eq :: forall a b. (Eq a, Eq b) =&gt; [a] -&gt; [b] -&gt; (a, b)
+</span
+	  ><a href="Polymorphism.html#eq"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >eq</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>[a] -&gt; [b] -&gt; (a, b)
+forall a. HasCallStack =&gt; a
+</span
+	><span class="hs-identifier hs-var"
+	>undefined</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-42"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-43"
+      ></span
+      ><span class="annot"
+      ><a href="Polymorphism.html#eq%27"
+	><span class="hs-identifier hs-type"
+	  >eq'</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >forall</span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >a</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >b</span
+	    ></a
+	  ></span
+	></span
+      ><span class="hs-operator"
+      >.</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>Eq</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >a</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>Eq</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >b</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=&gt;</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >[</span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >a</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >]</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >[</span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >b</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >]</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >a</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >b</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      >
+</span
+      ><span id="line-44"
+      ></span
+      ><span id="eq%27"
+      ><span class="annot"
+	><span class="annottext"
+	  >eq' :: forall a b. (Eq a, Eq b) =&gt; [a] -&gt; [b] -&gt; (a, b)
+</span
+	  ><a href="Polymorphism.html#eq%27"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >eq'</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>[a] -&gt; [b] -&gt; (a, b)
+forall a. HasCallStack =&gt; a
+</span
+	><span class="hs-identifier hs-var"
+	>undefined</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-45"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-46"
+      ></span
+      ><span id=""
+      ><span id=""
+	><span class="annot"
+	  ><a href="Polymorphism.html#mon"
+	    ><span class="hs-identifier hs-type"
+	      >mon</span
+	      ></a
+	    ></span
+	  ><span
+	  > </span
+	  ><span class="hs-glyph"
+	  >::</span
+	  ><span
+	  > </span
+	  ><span class="annot"
+	  ><span class="hs-identifier hs-type"
+	    >Monad</span
+	    ></span
+	  ><span
+	  > </span
+	  ><span class="annot"
+	  ><a href="#"
+	    ><span class="hs-identifier hs-type"
+	      >m</span
+	      ></a
+	    ></span
+	  ><span
+	  > </span
+	  ><span class="hs-glyph"
+	  >=&gt;</span
+	  ><span
+	  > </span
+	  ><span class="hs-special"
+	  >(</span
+	  ><span class="annot"
+	  ><a href="#"
+	    ><span class="hs-identifier hs-type"
+	      >a</span
+	      ></a
+	    ></span
+	  ><span
+	  > </span
+	  ><span class="hs-glyph"
+	  >-&gt;</span
+	  ><span
+	  > </span
+	  ><span class="annot"
+	  ><a href="#"
+	    ><span class="hs-identifier hs-type"
+	      >m</span
+	      ></a
+	    ></span
+	  ><span
+	  > </span
+	  ><span class="annot"
+	  ><a href="#"
+	    ><span class="hs-identifier hs-type"
+	      >a</span
+	      ></a
+	    ></span
+	  ><span class="hs-special"
+	  >)</span
+	  ><span
+	  > </span
+	  ><span class="hs-glyph"
+	  >-&gt;</span
+	  ><span
+	  > </span
+	  ><span class="annot"
+	  ><a href="#"
+	    ><span class="hs-identifier hs-type"
+	      >m</span
+	      ></a
+	    ></span
+	  ><span
+	  > </span
+	  ><span class="annot"
+	  ><a href="#"
+	    ><span class="hs-identifier hs-type"
+	      >a</span
+	      ></a
+	    ></span
+	  ></span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-47"
+      ></span
+      ><span id="mon"
+      ><span class="annot"
+	><span class="annottext"
+	  >mon :: forall (m :: * -&gt; *) a. Monad m =&gt; (a -&gt; m a) -&gt; m a
+</span
+	  ><a href="Polymorphism.html#mon"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >mon</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>(a -&gt; m a) -&gt; m a
+forall a. HasCallStack =&gt; a
+</span
+	><span class="hs-identifier hs-var"
+	>undefined</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-48"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-49"
+      ></span
+      ><span class="annot"
+      ><a href="Polymorphism.html#mon%27"
+	><span class="hs-identifier hs-type"
+	  >mon'</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >forall</span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >m</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >a</span
+	    ></a
+	  ></span
+	></span
+      ><span class="hs-operator"
+      >.</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>Monad</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >m</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=&gt;</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >a</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >m</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >a</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >m</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >a</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-50"
+      ></span
+      ><span id="mon%27"
+      ><span class="annot"
+	><span class="annottext"
+	  >mon' :: forall (m :: * -&gt; *) a. Monad m =&gt; (a -&gt; m a) -&gt; m a
+</span
+	  ><a href="Polymorphism.html#mon%27"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >mon'</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>(a -&gt; m a) -&gt; m a
+forall a. HasCallStack =&gt; a
+</span
+	><span class="hs-identifier hs-var"
+	>undefined</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-51"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-52"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-53"
+      ></span
+      ><span id=""
+      ><span class="annot"
+	><a href="Polymorphism.html#norf"
+	  ><span class="hs-identifier hs-type"
+	    >norf</span
+	    ></a
+	  ></span
+	><span
+	> </span
+	><span class="hs-glyph"
+	>::</span
+	><span
+	> </span
+	><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >a</span
+	    ></a
+	  ></span
+	><span
+	> </span
+	><span class="hs-glyph"
+	>-&gt;</span
+	><span
+	> </span
+	><span class="hs-special"
+	>(</span
+	><span class="hs-keyword"
+	>forall</span
+	><span
+	> </span
+	><span id=""
+	><span class="annot"
+	  ><a href="#"
+	    ><span class="hs-identifier hs-type"
+	      >a</span
+	      ></a
+	    ></span
+	  ></span
+	><span class="hs-operator"
+	>.</span
+	><span
+	> </span
+	><span class="annot"
+	><span class="hs-identifier hs-type"
+	  >Ord</span
+	  ></span
+	><span
+	> </span
+	><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >a</span
+	    ></a
+	  ></span
+	><span
+	> </span
+	><span class="hs-glyph"
+	>=&gt;</span
+	><span
+	> </span
+	><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >a</span
+	    ></a
+	  ></span
+	><span
+	> </span
+	><span class="hs-glyph"
+	>-&gt;</span
+	><span
+	> </span
+	><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >a</span
+	    ></a
+	  ></span
+	><span class="hs-special"
+	>)</span
+	><span
+	> </span
+	><span class="hs-glyph"
+	>-&gt;</span
+	><span
+	> </span
+	><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >a</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-54"
+      ></span
+      ><span id="norf"
+      ><span class="annot"
+	><span class="annottext"
+	  >norf :: forall a. a -&gt; (forall a. Ord a =&gt; a -&gt; a) -&gt; a
+</span
+	  ><a href="Polymorphism.html#norf"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >norf</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >a
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >x</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >forall a. Ord a =&gt; a -&gt; a
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >f</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>a
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >x</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-55"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-56"
+      ></span
+      ><span class="annot"
+      ><a href="Polymorphism.html#norf%27"
+	><span class="hs-identifier hs-type"
+	  >norf'</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >forall</span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >a</span
+	    ></a
+	  ></span
+	></span
+      ><span class="hs-operator"
+      >.</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >a</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-keyword"
+      >forall</span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >a</span
+	    ></a
+	  ></span
+	></span
+      ><span class="hs-operator"
+      >.</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>Ord</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >a</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=&gt;</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >a</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >a</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >a</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-57"
+      ></span
+      ><span id="norf%27"
+      ><span class="annot"
+	><span class="annottext"
+	  >norf' :: forall a. a -&gt; (forall a. Ord a =&gt; a -&gt; a) -&gt; a
+</span
+	  ><a href="Polymorphism.html#norf%27"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >norf'</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >a
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >x</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >forall a. Ord a =&gt; a -&gt; a
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >f</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>a
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >x</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-58"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-59"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-60"
+      ></span
+      ><span class="annot"
+      ><a href="Polymorphism.html#plugh"
+	><span class="hs-identifier hs-type"
+	  >plugh</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >forall</span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >a</span
+	    ></a
+	  ></span
+	></span
+      ><span class="hs-operator"
+      >.</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >a</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >a</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-61"
+      ></span
+      ><span id="plugh"
+      ><span class="annot"
+	><span class="annottext"
+	  >plugh :: forall a. a -&gt; a
+</span
+	  ><a href="Polymorphism.html#plugh"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >plugh</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >a
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >x</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>a
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >x</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >a</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-62"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-63"
+      ></span
+      ><span class="annot"
+      ><a href="Polymorphism.html#thud"
+	><span class="hs-identifier hs-type"
+	  >thud</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >forall</span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >a</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >b</span
+	    ></a
+	  ></span
+	></span
+      ><span class="hs-operator"
+      >.</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >a</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >b</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >a</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >a</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >b</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      >
+</span
+      ><span id="line-64"
+      ></span
+      ><span id="thud"
+      ><span class="annot"
+	><span class="annottext"
+	  >thud :: forall a b. (a -&gt; b) -&gt; a -&gt; (a, b)
+</span
+	  ><a href="Polymorphism.html#thud"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >thud</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >a -&gt; b
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >f</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >a
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >x</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      >
+</span
+      ><span id="line-65"
+      ></span
+      ><span
+      >    </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><span class="annottext"
+	>a
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >x</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >a</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>b
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >y</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >a</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >b</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      >
+</span
+      ><span id="line-66"
+      ></span
+      ><span
+      >  </span
+      ><span class="hs-keyword"
+      >where</span
+      ><span
+      >
+</span
+      ><span id="line-67"
+      ></span
+      ><span
+      >    </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >y :: b
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >y</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><span class="annottext"
+	>a -&gt; b
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >f</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >a</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >b</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>a
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >x</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >b</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-68"
+      ></span
+      ></pre
+    ></body
+  ></html
+>
diff --git a/hypsrc-test/ref/src/PositionPragmas.html b/hypsrc-test/ref/src/PositionPragmas.html
new file mode 100644
--- /dev/null
+++ b/hypsrc-test/ref/src/PositionPragmas.html
@@ -0,0 +1,179 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><link rel="stylesheet" type="text/css" href="style.css"
+     /><script type="text/javascript" src="highlight.js"
+    ></script
+    ></head
+  ><body
+  ><pre
+    ><span class="hs-pragma"
+      >{-# LANGUAGE Haskell2010 #-}</span
+      ><span
+      >
+</span
+      ><span id="line-2"
+      ></span
+      ><span class="hs-keyword"
+      >module</span
+      ><span
+      > </span
+      ><span class="hs-identifier"
+      >PositionPragmas</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >where</span
+      ><span
+      >
+</span
+      ><span id="line-3"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-4"
+      ></span
+      ><span class="hs-pragma"
+      >{-# LINE 8 &quot;hypsrc-test/src/PositionPragmas.hs&quot; #-}</span
+      ><span
+      >
+</span
+      ><span id="line-8"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-9"
+      ></span
+      ><span class="annot"
+      ><a href="PositionPragmas.html#foo"
+	><span class="hs-identifier hs-type"
+	  >foo</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>String</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-10"
+      ></span
+      ><span id="foo"
+      ><span class="annot"
+	><span class="annottext"
+	  >foo :: String
+</span
+	  ><a href="PositionPragmas.html#foo"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >foo</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>String
+</span
+	><a href="PositionPragmas.html#bar"
+	><span class="hs-identifier hs-var"
+	  >bar</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-11"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-12"
+      ></span
+      ><span class="hs-pragma"
+      >{-# LINE 23 &quot;hypsrc-test/src/PositionPragmas.hs&quot; #-}</span
+      ><span
+      >
+</span
+      ><span id="line-23"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-24"
+      ></span
+      ><span class="annot"
+      ><a href="PositionPragmas.html#bar"
+	><span class="hs-identifier hs-type"
+	  >bar</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>String</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-25"
+      ></span
+      ><span id="bar"
+      ><span class="annot"
+	><span class="annottext"
+	  >bar :: String
+</span
+	  ><a href="PositionPragmas.html#bar"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >bar</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>String
+</span
+	><a href="PositionPragmas.html#foo"
+	><span class="hs-identifier hs-var"
+	  >foo</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span
+      >
+</span
+      ><span id="line-26"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-27"
+      ></span
+      ></pre
+    ></body
+  ></html
+>
diff --git a/hypsrc-test/ref/src/Quasiquoter.html b/hypsrc-test/ref/src/Quasiquoter.html
new file mode 100644
--- /dev/null
+++ b/hypsrc-test/ref/src/Quasiquoter.html
@@ -0,0 +1,427 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><link rel="stylesheet" type="text/css" href="style.css"
+     /><script type="text/javascript" src="highlight.js"
+    ></script
+    ></head
+  ><body
+  ><pre
+    ><span class="hs-pragma"
+      >{-# LANGUAGE Haskell2010 #-}</span
+      ><span
+      >
+</span
+      ><span id="line-2"
+      ></span
+      ><span class="hs-keyword"
+      >module</span
+      ><span
+      > </span
+      ><span class="hs-identifier"
+      >Quasiquoter</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Quasiquoter.html#string"
+	><span class="hs-identifier"
+	  >string</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >where</span
+      ><span
+      >
+</span
+      ><span id="line-3"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-4"
+      ></span
+      ><span class="hs-keyword"
+      >import</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier"
+	>Language.Haskell.TH.Quote</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-5"
+      ></span
+      ><span class="hs-keyword"
+      >import</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier"
+	>Language.Haskell.TH.Syntax</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-6"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-7"
+      ></span
+      ><span class="annot"
+      ><span class="hs-comment"
+	>-- | Quoter for constructing multiline string literals</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-8"
+      ></span
+      ><span class="annot"
+      ><a href="Quasiquoter.html#string"
+	><span class="hs-identifier hs-type"
+	  >string</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>QuasiQuoter</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-9"
+      ></span
+      ><span id="string"
+      ><span class="annot"
+	><span class="annottext"
+	  >string :: QuasiQuoter
+</span
+	  ><a href="Quasiquoter.html#string"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >string</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>QuasiQuoter</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-10"
+      ></span
+      ><span
+      >  </span
+      ><span class="hs-special"
+      >{</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>quoteExp :: String -&gt; Q Exp
+</span
+	><span class="hs-identifier hs-var"
+	>quoteExp</span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Exp -&gt; Q Exp
+forall a. a -&gt; Q a
+forall (f :: * -&gt; *) a. Applicative f =&gt; a -&gt; f a
+</span
+	><span class="hs-identifier hs-var"
+	>pure</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>(Exp -&gt; Q Exp) -&gt; (String -&gt; Exp) -&gt; String -&gt; Q Exp
+forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
+</span
+	><span class="hs-operator hs-var"
+	>.</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Lit -&gt; Exp
+</span
+	><span class="hs-identifier hs-var"
+	>LitE</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>(Lit -&gt; Exp) -&gt; (String -&gt; Lit) -&gt; String -&gt; Exp
+forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
+</span
+	><span class="hs-operator hs-var"
+	>.</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>String -&gt; Lit
+</span
+	><span class="hs-identifier hs-var"
+	>StringL</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-11"
+      ></span
+      ><span
+      >  </span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>quotePat :: String -&gt; Q Pat
+</span
+	><span class="hs-identifier hs-var"
+	>quotePat</span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>String -&gt; Q Pat
+forall a. String -&gt; Q a
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >invalidDomain</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-12"
+      ></span
+      ><span
+      >  </span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>quoteType :: String -&gt; Q Type
+</span
+	><span class="hs-identifier hs-var"
+	>quoteType</span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>String -&gt; Q Type
+forall a. String -&gt; Q a
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >invalidDomain</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-13"
+      ></span
+      ><span
+      >  </span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>quoteDec :: String -&gt; Q [Dec]
+</span
+	><span class="hs-identifier hs-var"
+	>quoteDec</span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>String -&gt; Q [Dec]
+forall a. String -&gt; Q a
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >invalidDomain</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-14"
+      ></span
+      ><span
+      >  </span
+      ><span class="hs-special"
+      >}</span
+      ><span
+      >
+</span
+      ><span id="line-15"
+      ></span
+      ><span
+      >  </span
+      ><span class="hs-keyword"
+      >where</span
+      ><span
+      >
+</span
+      ><span id="line-16"
+      ></span
+      ><span
+      >    </span
+      ><span id=""
+      ><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >invalidDomain</span
+	    ></a
+	  ></span
+	><span
+	> </span
+	><span class="hs-glyph"
+	>::</span
+	><span
+	> </span
+	><span class="annot"
+	><span class="hs-identifier hs-type"
+	  >String</span
+	  ></span
+	><span
+	> </span
+	><span class="hs-glyph"
+	>-&gt;</span
+	><span
+	> </span
+	><span class="annot"
+	><span class="hs-identifier hs-type"
+	  >Q</span
+	  ></span
+	><span
+	> </span
+	><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >a</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-17"
+      ></span
+      ><span
+      >    </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >invalidDomain :: forall a. String -&gt; Q a
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >invalidDomain</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>String
+</span
+	><span class="hs-identifier"
+	>_</span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>String -&gt; Q a
+forall a. String -&gt; Q a
+forall (m :: * -&gt; *) a. MonadFail m =&gt; String -&gt; m a
+</span
+	><span class="hs-identifier hs-var"
+	>fail</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>String
+</span
+	><span class="hs-string"
+	>&quot;stringQuoter: only valid in expression context&quot;</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-18"
+      ></span
+      ></pre
+    ></body
+  ></html
+>
diff --git a/hypsrc-test/ref/src/Records.html b/hypsrc-test/ref/src/Records.html
new file mode 100644
--- /dev/null
+++ b/hypsrc-test/ref/src/Records.html
@@ -0,0 +1,1387 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><link rel="stylesheet" type="text/css" href="style.css"
+     /><script type="text/javascript" src="highlight.js"
+    ></script
+    ></head
+  ><body
+  ><pre
+    ><span class="hs-pragma"
+      >{-# LANGUAGE Haskell2010 #-}</span
+      ><span
+      >
+</span
+      ><span id="line-2"
+      ></span
+      ><span class="hs-pragma"
+      >{-# LANGUAGE NamedFieldPuns #-}</span
+      ><span
+      >
+</span
+      ><span id="line-3"
+      ></span
+      ><span class="hs-pragma"
+      >{-# LANGUAGE RecordWildCards #-}</span
+      ><span
+      >
+</span
+      ><span id="line-4"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-5"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-6"
+      ></span
+      ><span class="hs-keyword"
+      >module</span
+      ><span
+      > </span
+      ><span class="hs-identifier"
+      >Records</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >where</span
+      ><span
+      >
+</span
+      ><span id="line-7"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-8"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-9"
+      ></span
+      ><span class="hs-keyword"
+      >data</span
+      ><span
+      > </span
+      ><span id="Point"
+      ><span class="annot"
+	><a href="Records.html#Point"
+	  ><span class="hs-identifier hs-var"
+	    >Point</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span id="Point"
+      ><span class="annot"
+	><a href="Records.html#Point"
+	  ><span class="hs-identifier hs-var"
+	    >Point</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-10"
+      ></span
+      ><span
+      >    </span
+      ><span class="hs-special"
+      >{</span
+      ><span
+      > </span
+      ><span id="x"
+      ><span class="annot"
+	><span class="annottext"
+	  >Point -&gt; Int
+</span
+	  ><a href="Records.html#x"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >x</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >!</span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>Int</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-11"
+      ></span
+      ><span
+      >    </span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span id="y"
+      ><span class="annot"
+	><span class="annottext"
+	  >Point -&gt; Int
+</span
+	  ><a href="Records.html#y"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >y</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >!</span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>Int</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-12"
+      ></span
+      ><span
+      >    </span
+      ><span class="hs-special"
+      >}</span
+      ><span
+      >
+</span
+      ><span id="line-13"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-14"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-15"
+      ></span
+      ><span class="annot"
+      ><a href="Records.html#point"
+	><span class="hs-identifier hs-type"
+	  >point</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>Int</span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>Int</span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Records.html#Point"
+	><span class="hs-identifier hs-type"
+	  >Point</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-16"
+      ></span
+      ><span id="point"
+      ><span class="annot"
+	><span class="annottext"
+	  >point :: Int -&gt; Int -&gt; Point
+</span
+	  ><a href="Records.html#point"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >point</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >Int
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >x</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >Int
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >y</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Records.html#Point"
+	><span class="hs-identifier hs-type"
+	  >Point</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >{</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>x :: Int
+</span
+	><a href="Records.html#x"
+	><span class="hs-identifier hs-var"
+	  >x</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >x</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>y :: Int
+</span
+	><a href="Records.html#y"
+	><span class="hs-identifier hs-var"
+	  >y</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >y</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >}</span
+      ><span
+      >
+</span
+      ><span id="line-17"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-18"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-19"
+      ></span
+      ><span class="annot"
+      ><a href="Records.html#lengthSqr"
+	><span class="hs-identifier hs-type"
+	  >lengthSqr</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Records.html#Point"
+	><span class="hs-identifier hs-type"
+	  >Point</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>Int</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-20"
+      ></span
+      ><span id="lengthSqr"
+      ><span class="annot"
+	><span class="annottext"
+	  >lengthSqr :: Point -&gt; Int
+</span
+	  ><a href="Records.html#lengthSqr"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >lengthSqr</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><a href="Records.html#Point"
+	><span class="hs-identifier hs-type"
+	  >Point</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >{</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>x :: Point -&gt; Int
+</span
+	><a href="Records.html#x"
+	><span class="hs-identifier hs-var"
+	  >x</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >Int
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >x</span
+	    ></a
+	  ></span
+	></span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>y :: Point -&gt; Int
+</span
+	><a href="Records.html#y"
+	><span class="hs-identifier hs-var"
+	  >y</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >Int
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >y</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >}</span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >x</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int -&gt; Int -&gt; Int
+forall a. Num a =&gt; a -&gt; a -&gt; a
+</span
+	><span class="hs-operator hs-var"
+	>*</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >x</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int -&gt; Int -&gt; Int
+forall a. Num a =&gt; a -&gt; a -&gt; a
+</span
+	><span class="hs-operator hs-var"
+	>+</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >y</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int -&gt; Int -&gt; Int
+forall a. Num a =&gt; a -&gt; a -&gt; a
+</span
+	><span class="hs-operator hs-var"
+	>*</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >y</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-21"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-22"
+      ></span
+      ><span class="annot"
+      ><a href="Records.html#lengthSqr%27"
+	><span class="hs-identifier hs-type"
+	  >lengthSqr'</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Records.html#Point"
+	><span class="hs-identifier hs-type"
+	  >Point</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>Int</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-23"
+      ></span
+      ><span id="lengthSqr%27"
+      ><span class="annot"
+	><span class="annottext"
+	  >lengthSqr' :: Point -&gt; Int
+</span
+	  ><a href="Records.html#lengthSqr%27"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >lengthSqr'</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><a href="Records.html#Point"
+	><span class="hs-identifier hs-type"
+	  >Point</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >{</span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >Int
+x :: Point -&gt; Int
+x :: Int
+</span
+	  ><a href="Records.html#x"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >x</span
+	    ></a
+	  ></span
+	></span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >Int
+y :: Point -&gt; Int
+y :: Int
+</span
+	  ><a href="Records.html#y"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >y</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >}</span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >y</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int -&gt; Int -&gt; Int
+forall a. Num a =&gt; a -&gt; a -&gt; a
+</span
+	><span class="hs-operator hs-var"
+	>*</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >y</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int -&gt; Int -&gt; Int
+forall a. Num a =&gt; a -&gt; a -&gt; a
+</span
+	><span class="hs-operator hs-var"
+	>+</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >x</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int -&gt; Int -&gt; Int
+forall a. Num a =&gt; a -&gt; a -&gt; a
+</span
+	><span class="hs-operator hs-var"
+	>*</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >x</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-24"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-25"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-26"
+      ></span
+      ><span class="annot"
+      ><a href="Records.html#translateX"
+	><span class="hs-identifier hs-type"
+	  >translateX</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Records.html#translateY"
+	><span class="hs-identifier hs-type"
+	  >translateY</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Records.html#Point"
+	><span class="hs-identifier hs-type"
+	  >Point</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>Int</span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Records.html#Point"
+	><span class="hs-identifier hs-type"
+	  >Point</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-27"
+      ></span
+      ><span id="translateX"
+      ><span class="annot"
+	><span class="annottext"
+	  >translateX :: Point -&gt; Int -&gt; Point
+</span
+	  ><a href="Records.html#translateX"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >translateX</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >Point
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >p</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >Int
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >d</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Point
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >p</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >{</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Records.html#x"
+	><span class="hs-identifier hs-var"
+	  >x</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Records.html#x"
+	><span class="hs-identifier hs-var"
+	  >x</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >p</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-operator hs-type"
+	>+</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >d</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >}</span
+      ><span
+      >
+</span
+      ><span id="line-28"
+      ></span
+      ><span id="translateY"
+      ><span class="annot"
+	><span class="annottext"
+	  >translateY :: Point -&gt; Int -&gt; Point
+</span
+	  ><a href="Records.html#translateY"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >translateY</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >Point
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >p</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >Int
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >d</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Point
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >p</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >{</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Records.html#y"
+	><span class="hs-identifier hs-var"
+	  >y</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Records.html#y"
+	><span class="hs-identifier hs-var"
+	  >y</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >p</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-operator hs-type"
+	>+</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >d</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >}</span
+      ><span
+      >
+</span
+      ><span id="line-29"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-30"
+      ></span
+      ><span class="annot"
+      ><a href="Records.html#translate"
+	><span class="hs-identifier hs-type"
+	  >translate</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>Int</span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>Int</span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Records.html#Point"
+	><span class="hs-identifier hs-type"
+	  >Point</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Records.html#Point"
+	><span class="hs-identifier hs-type"
+	  >Point</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-31"
+      ></span
+      ><span id="translate"
+      ><span class="annot"
+	><span class="annottext"
+	  >translate :: Int -&gt; Int -&gt; Point -&gt; Point
+</span
+	  ><a href="Records.html#translate"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >translate</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >Int
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >x</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >Int
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >y</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >Point
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >p</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      >
+</span
+      ><span id="line-32"
+      ></span
+      ><span
+      >    </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Point -&gt; Point
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >aux</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Point
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >p</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-33"
+      ></span
+      ><span
+      >  </span
+      ><span class="hs-keyword"
+      >where</span
+      ><span
+      >
+</span
+      ><span id="line-34"
+      ></span
+      ><span
+      >    </span
+      ><span class="hs-special"
+      >(</span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >Int
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >dx</span
+	    ></a
+	  ></span
+	></span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >Int
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >dy</span
+	    ></a
+	  ></span
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >x</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >y</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      >
+</span
+      ><span id="line-35"
+      ></span
+      ><span
+      >    </span
+      ><span id=""
+      ><span class="annot"
+	><span class="annottext"
+	  >aux :: Point -&gt; Point
+</span
+	  ><a href="#"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >aux</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Records.html#Point"
+	><span class="hs-identifier hs-type"
+	  >Point</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >{</span
+      ><span id=""
+      ><span id=""
+	><span class="annot"
+	  ><span class="annottext"
+	    >Int
+x :: Point -&gt; Int
+y :: Point -&gt; Int
+x :: Int
+y :: Int
+</span
+	    ><a href="Records.html#x"
+	    ><span class="hs-glyph hs-var hs-var hs-var hs-var"
+	      >..</span
+	      ></a
+	    ></span
+	  ></span
+	></span
+      ><span class="hs-special"
+      >}</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Point
+</span
+	><a href="#"
+	><span class="hs-identifier hs-var"
+	  >p</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >{</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Records.html#x"
+	><span class="hs-identifier hs-var"
+	  >x</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >x</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-operator hs-type"
+	>+</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >dx</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Records.html#y"
+	><span class="hs-identifier hs-var"
+	  >y</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >y</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-operator hs-type"
+	>+</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >dy</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >}</span
+      ><span
+      >
+</span
+      ><span id="line-36"
+      ></span
+      ></pre
+    ></body
+  ></html
+>
diff --git a/hypsrc-test/ref/src/TemplateHaskellQuasiquotes.html b/hypsrc-test/ref/src/TemplateHaskellQuasiquotes.html
new file mode 100644
--- /dev/null
+++ b/hypsrc-test/ref/src/TemplateHaskellQuasiquotes.html
@@ -0,0 +1,946 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><link rel="stylesheet" type="text/css" href="style.css"
+     /><script type="text/javascript" src="highlight.js"
+    ></script
+    ></head
+  ><body
+  ><pre
+    ><span class="hs-pragma"
+      >{-# LANGUAGE Haskell2010 #-}</span
+      ><span
+      >
+</span
+      ><span id="line-2"
+      ></span
+      ><span class="hs-pragma"
+      >{-# LANGUAGE TemplateHaskell #-}</span
+      ><span
+      >
+</span
+      ><span id="line-3"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-4"
+      ></span
+      ><span class="hs-keyword"
+      >module</span
+      ><span
+      > </span
+      ><span class="hs-identifier"
+      >TemplateHaskellQuasiquotes</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >where</span
+      ><span
+      >
+</span
+      ><span id="line-5"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-6"
+      ></span
+      ><span class="hs-keyword"
+      >import</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier"
+	>Language.Haskell.TH</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-7"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-8"
+      ></span
+      ><span class="annot"
+      ><a href="TemplateHaskellQuasiquotes.html#aDecl"
+	><span class="hs-identifier hs-type"
+	  >aDecl</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>DecsQ</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-9"
+      ></span
+      ><span id="aDecl"
+      ><span class="annot"
+	><span class="annottext"
+	  >aDecl :: DecsQ
+</span
+	  ><a href="TemplateHaskellQuasiquotes.html#aDecl"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >aDecl</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >[d|</span
+      ><span
+      >
+</span
+      ><span id="line-10"
+      ></span
+      ><span
+      >    </span
+      ><span class="annot"
+      ><a href="#"
+	><span class="hs-identifier hs-type"
+	  >bar</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >$</span
+      ><span class="annot"
+      ><span class="annottext"
+	>TypeQ
+</span
+	><a href="TemplateHaskellQuasiquotes.html#aType"
+	><span class="hs-identifier hs-var"
+	  >aType</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >[</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>Int</span
+	></span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>String</span
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >]</span
+      ><span
+      >
+</span
+      ><span id="line-11"
+      ></span
+      ><span
+      >    </span
+      ><span id=""
+      ><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >bar</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >$</span
+      ><span class="annot"
+      ><span class="annottext"
+	>PatQ
+</span
+	><a href="TemplateHaskellQuasiquotes.html#aPattern"
+	><span class="hs-identifier hs-var"
+	  >aPattern</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >$</span
+      ><span class="annot"
+      ><span class="annottext"
+	>ExpQ
+</span
+	><a href="TemplateHaskellQuasiquotes.html#anExpression"
+	><span class="hs-identifier hs-var"
+	  >anExpression</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-12"
+      ></span
+      ><span
+      >  </span
+      ><span class="hs-special"
+      >|]</span
+      ><span
+      >
+</span
+      ><span id="line-13"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-14"
+      ></span
+      ><span class="annot"
+      ><a href="TemplateHaskellQuasiquotes.html#aPattern"
+	><span class="hs-identifier hs-type"
+	  >aPattern</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>PatQ</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-15"
+      ></span
+      ><span id="aPattern"
+      ><span class="annot"
+	><span class="annottext"
+	  >aPattern :: PatQ
+</span
+	  ><a href="TemplateHaskellQuasiquotes.html#aPattern"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >aPattern</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >[p|</span
+      ><span
+      >
+</span
+      ><span id="line-16"
+      ></span
+      ><span
+      >    </span
+      ><span class="hs-special"
+      >[</span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >aCrazyLongVariableName</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-17"
+      ></span
+      ><span
+      >    </span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >_unused</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-18"
+      ></span
+      ><span
+      >    </span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span id=""
+      ><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >y</span
+	    ></a
+	  ></span
+	></span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >z</span
+	    ></a
+	  ></span
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      >
+</span
+      ><span id="line-19"
+      ></span
+      ><span
+      >    </span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >$</span
+      ><span class="annot"
+      ><span class="annottext"
+	>PatQ
+</span
+	><a href="TemplateHaskellQuasiquotes.html#aNumberPattern"
+	><span class="hs-identifier hs-var"
+	  >aNumberPattern</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-string"
+	>&quot;hello&quot;</span
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      >
+</span
+      ><span id="line-20"
+      ></span
+      ><span
+      >    </span
+      ><span class="hs-special"
+      >]</span
+      ><span
+      >
+</span
+      ><span id="line-21"
+      ></span
+      ><span
+      >  </span
+      ><span class="hs-special"
+      >|]</span
+      ><span
+      >
+</span
+      ><span id="line-22"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-23"
+      ></span
+      ><span class="annot"
+      ><a href="TemplateHaskellQuasiquotes.html#aNumberPattern"
+	><span class="hs-identifier hs-type"
+	  >aNumberPattern</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>PatQ</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-24"
+      ></span
+      ><span id="aNumberPattern"
+      ><span class="annot"
+	><span class="annottext"
+	  >aNumberPattern :: PatQ
+</span
+	  ><a href="TemplateHaskellQuasiquotes.html#aNumberPattern"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >aNumberPattern</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >[p|</span
+      ><span
+      >
+</span
+      ><span id="line-25"
+      ></span
+      ><span
+      >    </span
+      ><span id=""
+      ><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >w</span
+	    ></a
+	  ></span
+	></span
+      ><span class="hs-glyph"
+      >@</span
+      ><span id=""
+      ><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-var"
+	    >v</span
+	    ></a
+	  ></span
+	></span
+      ><span class="hs-glyph"
+      >@</span
+      ><span class="annot"
+      ><span class="hs-number"
+	>4.5</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-26"
+      ></span
+      ><span
+      >  </span
+      ><span class="hs-special"
+      >|]</span
+      ><span
+      >
+</span
+      ><span id="line-27"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-28"
+      ></span
+      ><span class="annot"
+      ><a href="TemplateHaskellQuasiquotes.html#anExpression"
+	><span class="hs-identifier hs-type"
+	  >anExpression</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="TemplateHaskellQuasiquotes.html#anExpression2"
+	><span class="hs-identifier hs-type"
+	  >anExpression2</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>ExpQ</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-29"
+      ></span
+      ><span id="anExpression"
+      ><span class="annot"
+	><span class="annottext"
+	  >anExpression :: ExpQ
+</span
+	  ><a href="TemplateHaskellQuasiquotes.html#anExpression"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >anExpression</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >[e|</span
+      ><span
+      >
+</span
+      ><span id="line-30"
+      ></span
+      ><span
+      >    </span
+      ><span class="hs-special"
+      >[</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><span class="hs-number"
+	>1</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-operator hs-type"
+	>+</span
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >$</span
+      ><span class="annot"
+      ><span class="annottext"
+	>ExpQ
+</span
+	><a href="TemplateHaskellQuasiquotes.html#anExpression2"
+	><span class="hs-identifier hs-var"
+	  >anExpression2</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-string"
+	>&quot;world&quot;</span
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >]</span
+      ><span
+      >
+</span
+      ><span id="line-31"
+      ></span
+      ><span
+      >  </span
+      ><span class="hs-special"
+      >|]</span
+      ><span
+      >
+</span
+      ><span id="line-32"
+      ></span
+      ><span id="anExpression2"
+      ><span class="annot"
+	><span class="annottext"
+	  >anExpression2 :: ExpQ
+</span
+	  ><a href="TemplateHaskellQuasiquotes.html#anExpression2"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >anExpression2</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >[|</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><span class="hs-number"
+	>1</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-operator hs-type"
+	>+</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>round</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>pi</span
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >|]</span
+      ><span
+      >
+</span
+      ><span id="line-33"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-34"
+      ></span
+      ><span class="annot"
+      ><a href="TemplateHaskellQuasiquotes.html#aType"
+	><span class="hs-identifier hs-type"
+	  >aType</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>TypeQ</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-35"
+      ></span
+      ><span id="aType"
+      ><span class="annot"
+	><span class="annottext"
+	  >aType :: TypeQ
+</span
+	  ><a href="TemplateHaskellQuasiquotes.html#aType"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >aType</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >[t|</span
+      ><span
+      >
+</span
+      ><span id="line-36"
+      ></span
+      ><span
+      >    </span
+      ><span class="hs-special"
+      >[</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>Double</span
+	></span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>String</span
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >]</span
+      ><span
+      >
+</span
+      ><span id="line-37"
+      ></span
+      ><span
+      >  </span
+      ><span class="hs-special"
+      >|]</span
+      ><span
+      >
+</span
+      ><span id="line-38"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-39"
+      ></span
+      ><span class="annot"
+      ><a href="TemplateHaskellQuasiquotes.html#typedExpr1"
+	><span class="hs-identifier hs-type"
+	  >typedExpr1</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>Code</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>Q</span
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      >
+</span
+      ><span id="line-40"
+      ></span
+      ><span id="typedExpr1"
+      ><span class="annot"
+	><span class="annottext"
+	  >typedExpr1 :: Code Q ()
+</span
+	  ><a href="TemplateHaskellQuasiquotes.html#typedExpr1"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >typedExpr1</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >[||</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >||]</span
+      ><span
+      >
+</span
+      ><span id="line-41"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-42"
+      ></span
+      ><span class="annot"
+      ><a href="TemplateHaskellQuasiquotes.html#typedExpr"
+	><span class="hs-identifier hs-type"
+	  >typedExpr</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>Code</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>Q</span
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      >
+</span
+      ><span id="line-43"
+      ></span
+      ><span id="typedExpr"
+      ><span class="annot"
+	><span class="annottext"
+	  >typedExpr :: Code Q ()
+</span
+	  ><a href="TemplateHaskellQuasiquotes.html#typedExpr"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >typedExpr</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >[||</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>a -&gt; b -&gt; a
+forall a b. a -&gt; b -&gt; a
+</span
+	><span class="hs-identifier hs-var"
+	>const</span
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >$$</span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><span class="annottext"
+	>Code Q ()
+</span
+	><a href="TemplateHaskellQuasiquotes.html#typedExpr1"
+	><span class="hs-identifier hs-var"
+	  >typedExpr1</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >||]</span
+      ><span
+      >
+</span
+      ><span id="line-44"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-45"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-46"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-47"
+      ></span
+      ></pre
+    ></body
+  ></html
+>
diff --git a/hypsrc-test/ref/src/TemplateHaskellSplices.html b/hypsrc-test/ref/src/TemplateHaskellSplices.html
new file mode 100644
--- /dev/null
+++ b/hypsrc-test/ref/src/TemplateHaskellSplices.html
@@ -0,0 +1,236 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><link rel="stylesheet" type="text/css" href="style.css"
+     /><script type="text/javascript" src="highlight.js"
+    ></script
+    ></head
+  ><body
+  ><pre
+    ><span class="hs-pragma"
+      >{-# LANGUAGE Haskell2010 #-}</span
+      ><span
+      >
+</span
+      ><span id="line-2"
+      ></span
+      ><span class="hs-pragma"
+      >{-# LANGUAGE TemplateHaskell #-}</span
+      ><span
+      >
+</span
+      ><span id="line-3"
+      ></span
+      ><span class="hs-keyword"
+      >module</span
+      ><span
+      > </span
+      ><span class="hs-identifier"
+      >TemplateHaskellSplices</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >where</span
+      ><span
+      >
+</span
+      ><span id="line-4"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-5"
+      ></span
+      ><span class="hs-keyword"
+      >import</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="TemplateHaskellQuasiquotes.html"
+	><span class="hs-identifier"
+	  >TemplateHaskellQuasiquotes</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-6"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-7"
+      ></span
+      ><span class="hs-special"
+      >$</span
+      ><span id="bar"
+      ><span class="hs-special"
+	>(</span
+	><span class="hs-identifier"
+	>aDecl</span
+	><span class="hs-special"
+	>)</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-8"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-9"
+      ></span
+      ><span id="foo"
+      ><span class="annot"
+	><span class="annottext"
+	  >foo :: Integer
+</span
+	  ><a href="TemplateHaskellSplices.html#foo"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >foo</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Integer -&gt; Integer
+forall a. a -&gt; a
+</span
+	><span class="hs-identifier hs-var"
+	>id</span
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >$</span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><a href="TemplateHaskellQuasiquotes.html#anExpression2"
+	><span class="hs-identifier hs-type"
+	  >anExpression2</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      >
+</span
+      ><span id="line-10"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-11"
+      ></span
+      ><span id="pat"
+      ><span class="annot"
+	><span class="annottext"
+	  >pat :: [(a, String)] -&gt; ()
+</span
+	  ><a href="TemplateHaskellSplices.html#pat"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >pat</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >$</span
+      ><span id=""
+      ><span id=""
+	><span id=""
+	  ><span id=""
+	    ><span id=""
+	      ><span id=""
+		><span class="hs-special"
+		  >(</span
+		  ><span class="annot"
+		  ><a href="TemplateHaskellQuasiquotes.html#aPattern"
+		    ><span class="hs-identifier hs-type"
+		      >aPattern</span
+		      ></a
+		    ></span
+		  ><span class="hs-special"
+		  >)</span
+		  ></span
+		></span
+	      ></span
+	    ></span
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      >
+</span
+      ><span id="line-12"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-13"
+      ></span
+      ><span id="qux"
+      ><span class="annot"
+	><span class="annottext"
+	  >qux :: ()
+</span
+	  ><a href="TemplateHaskellSplices.html#qux"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >qux</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>() -&gt; ()
+forall a. a -&gt; a
+</span
+	><span class="hs-identifier hs-var"
+	>id</span
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >$$</span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><a href="TemplateHaskellQuasiquotes.html#typedExpr"
+	><span class="hs-identifier hs-type"
+	  >typedExpr</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      >
+</span
+      ><span id="line-14"
+      ></span
+      ></pre
+    ></body
+  ></html
+>
diff --git a/hypsrc-test/ref/src/Types.html b/hypsrc-test/ref/src/Types.html
new file mode 100644
--- /dev/null
+++ b/hypsrc-test/ref/src/Types.html
@@ -0,0 +1,1337 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><link rel="stylesheet" type="text/css" href="style.css"
+     /><script type="text/javascript" src="highlight.js"
+    ></script
+    ></head
+  ><body
+  ><pre
+    ><span class="hs-pragma"
+      >{-# LANGUAGE Haskell2010 #-}</span
+      ><span
+      >
+</span
+      ><span id="line-2"
+      ></span
+      ><span class="hs-pragma"
+      >{-# LANGUAGE TypeFamilies #-}</span
+      ><span
+      >
+</span
+      ><span id="line-3"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-4"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-5"
+      ></span
+      ><span class="hs-keyword"
+      >module</span
+      ><span
+      > </span
+      ><span class="hs-identifier"
+      >Types</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >where</span
+      ><span
+      >
+</span
+      ><span id="line-6"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-7"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-8"
+      ></span
+      ><span class="hs-keyword"
+      >data</span
+      ><span
+      > </span
+      ><span id="Quux"
+      ><span class="annot"
+	><a href="Types.html#Quux"
+	  ><span class="hs-identifier hs-var"
+	    >Quux</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span id="Bar"
+      ><span class="annot"
+	><a href="Types.html#Bar"
+	  ><span class="hs-identifier hs-var"
+	    >Bar</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >|</span
+      ><span
+      > </span
+      ><span id="Baz"
+      ><span class="annot"
+	><a href="Types.html#Baz"
+	  ><span class="hs-identifier hs-var"
+	    >Baz</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-9"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-10"
+      ></span
+      ><span class="hs-keyword"
+      >newtype</span
+      ><span
+      > </span
+      ><span id="Foo"
+      ><span class="annot"
+	><a href="Types.html#Foo"
+	  ><span class="hs-identifier hs-var"
+	    >Foo</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span id="Foo"
+      ><span class="annot"
+	><a href="Types.html#Foo"
+	  ><span class="hs-identifier hs-var"
+	    >Foo</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      >
+</span
+      ><span id="line-11"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-12"
+      ></span
+      ><span class="hs-keyword"
+      >type</span
+      ><span
+      > </span
+      ><span id="FooQuux"
+      ><span class="annot"
+	><a href="Types.html#FooQuux"
+	  ><span class="hs-identifier hs-var"
+	    >FooQuux</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><a href="Types.html#Foo"
+	><span class="hs-identifier hs-type"
+	  >Foo</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Types.html#Quux"
+	><span class="hs-identifier hs-type"
+	  >Quux</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      >
+</span
+      ><span id="line-13"
+      ></span
+      ><span class="hs-keyword"
+      >type</span
+      ><span
+      > </span
+      ><span id="QuuxFoo"
+      ><span class="annot"
+	><a href="Types.html#QuuxFoo"
+	  ><span class="hs-identifier hs-var"
+	    >QuuxFoo</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><a href="Types.html#Quux"
+	><span class="hs-identifier hs-type"
+	  >Quux</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Types.html#Foo"
+	><span class="hs-identifier hs-type"
+	  >Foo</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      >
+</span
+      ><span id="line-14"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-15"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-16"
+      ></span
+      ><span class="hs-keyword"
+      >data</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >family</span
+      ><span
+      > </span
+      ><span id="Norf"
+      ><span class="annot"
+	><a href="Types.html#Norf"
+	  ><span class="hs-identifier hs-var"
+	    >Norf</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >a</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >b</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-17"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-18"
+      ></span
+      ><span class="hs-keyword"
+      >data</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >instance</span
+      ><span
+      > </span
+      ><span id="Norf"
+      ><span class="annot"
+	><a href="Types.html#Norf"
+	  ><span class="hs-identifier hs-var"
+	    >Norf</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Types.html#Foo"
+	><span class="hs-identifier hs-type"
+	  >Foo</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Types.html#Quux"
+	><span class="hs-identifier hs-type"
+	  >Quux</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span id="NFQ"
+      ><span class="annot"
+	><a href="Types.html#NFQ"
+	  ><span class="hs-identifier hs-var"
+	    >NFQ</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Types.html#Foo"
+	><span class="hs-identifier hs-type"
+	  >Foo</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Types.html#Quux"
+	><span class="hs-identifier hs-type"
+	  >Quux</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-19"
+      ></span
+      ><span class="hs-keyword"
+      >data</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >instance</span
+      ><span
+      > </span
+      ><span id="Norf"
+      ><span class="annot"
+	><a href="Types.html#Norf"
+	  ><span class="hs-identifier hs-var"
+	    >Norf</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Types.html#Quux"
+	><span class="hs-identifier hs-type"
+	  >Quux</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Types.html#Foo"
+	><span class="hs-identifier hs-type"
+	  >Foo</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span id="NQF"
+      ><span class="annot"
+	><a href="Types.html#NQF"
+	  ><span class="hs-identifier hs-var"
+	    >NQF</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Types.html#Quux"
+	><span class="hs-identifier hs-type"
+	  >Quux</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Types.html#Foo"
+	><span class="hs-identifier hs-type"
+	  >Foo</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-20"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-21"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-22"
+      ></span
+      ><span class="hs-keyword"
+      >type</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >family</span
+      ><span
+      > </span
+      ><span id="Norf%27"
+      ><span class="annot"
+	><a href="Types.html#Norf%27"
+	  ><span class="hs-identifier hs-var"
+	    >Norf'</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >a</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span id=""
+      ><span class="annot"
+	><a href="#"
+	  ><span class="hs-identifier hs-type"
+	    >b</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-23"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-24"
+      ></span
+      ><span class="hs-keyword"
+      >type</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >instance</span
+      ><span
+      > </span
+      ><span id="Norf%27"
+      ><span class="annot"
+	><a href="Types.html#Norf%27"
+	  ><span class="hs-identifier hs-var"
+	    >Norf'</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Types.html#Foo"
+	><span class="hs-identifier hs-type"
+	  >Foo</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Types.html#Quux"
+	><span class="hs-identifier hs-type"
+	  >Quux</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><a href="Types.html#Foo"
+	><span class="hs-identifier hs-type"
+	  >Foo</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Types.html#Quux"
+	><span class="hs-identifier hs-type"
+	  >Quux</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      >
+</span
+      ><span id="line-25"
+      ></span
+      ><span class="hs-keyword"
+      >type</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >instance</span
+      ><span
+      > </span
+      ><span id="Norf%27"
+      ><span class="annot"
+	><a href="Types.html#Norf%27"
+	  ><span class="hs-identifier hs-var"
+	    >Norf'</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Types.html#Quux"
+	><span class="hs-identifier hs-type"
+	  >Quux</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Types.html#Foo"
+	><span class="hs-identifier hs-type"
+	  >Foo</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><a href="Types.html#Quux"
+	><span class="hs-identifier hs-type"
+	  >Quux</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Types.html#Foo"
+	><span class="hs-identifier hs-type"
+	  >Foo</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      >
+</span
+      ><span id="line-26"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-27"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-28"
+      ></span
+      ><span class="annot"
+      ><a href="Types.html#norf1"
+	><span class="hs-identifier hs-type"
+	  >norf1</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Types.html#Norf"
+	><span class="hs-identifier hs-type"
+	  >Norf</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Types.html#Foo"
+	><span class="hs-identifier hs-type"
+	  >Foo</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Types.html#Quux"
+	><span class="hs-identifier hs-type"
+	  >Quux</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>Int</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-29"
+      ></span
+      ><span id="norf1"
+      ><span class="annot"
+	><span class="annottext"
+	  >norf1 :: Norf Foo Quux -&gt; Int
+</span
+	  ><a href="Types.html#norf1"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >norf1</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><a href="Types.html#NFQ"
+	><span class="hs-identifier hs-type"
+	  >NFQ</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><a href="Types.html#Foo"
+	><span class="hs-identifier hs-type"
+	  >Foo</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-special"
+      >)</span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Quux
+</span
+	><a href="Types.html#Bar"
+	><span class="hs-identifier hs-var"
+	  >Bar</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><span class="hs-number"
+	>0</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-30"
+      ></span
+      ><span class="annot"
+      ><a href="Types.html#norf1"
+	><span class="hs-identifier hs-var"
+	  >norf1</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><a href="Types.html#NFQ"
+	><span class="hs-identifier hs-type"
+	  >NFQ</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><a href="Types.html#Foo"
+	><span class="hs-identifier hs-type"
+	  >Foo</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-special"
+      >)</span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Quux
+</span
+	><a href="Types.html#Baz"
+	><span class="hs-identifier hs-var"
+	  >Baz</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><span class="hs-number"
+	>1</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-31"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-32"
+      ></span
+      ><span class="annot"
+      ><a href="Types.html#norf2"
+	><span class="hs-identifier hs-type"
+	  >norf2</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Types.html#Norf"
+	><span class="hs-identifier hs-type"
+	  >Norf</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Types.html#Quux"
+	><span class="hs-identifier hs-type"
+	  >Quux</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Types.html#Foo"
+	><span class="hs-identifier hs-type"
+	  >Foo</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>Int</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-33"
+      ></span
+      ><span id="norf2"
+      ><span class="annot"
+	><span class="annottext"
+	  >norf2 :: Norf Quux Foo -&gt; Int
+</span
+	  ><a href="Types.html#norf2"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >norf2</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><a href="Types.html#NQF"
+	><span class="hs-identifier hs-type"
+	  >NQF</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Quux
+</span
+	><a href="Types.html#Bar"
+	><span class="hs-identifier hs-var"
+	  >Bar</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><a href="Types.html#Foo"
+	><span class="hs-identifier hs-type"
+	  >Foo</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-special"
+      >)</span
+      ><span class="hs-special"
+      >)</span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><span class="hs-number"
+	>0</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-34"
+      ></span
+      ><span class="annot"
+      ><a href="Types.html#norf2"
+	><span class="hs-identifier hs-var"
+	  >norf2</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><a href="Types.html#NQF"
+	><span class="hs-identifier hs-type"
+	  >NQF</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Quux
+</span
+	><a href="Types.html#Baz"
+	><span class="hs-identifier hs-var"
+	  >Baz</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><a href="Types.html#Foo"
+	><span class="hs-identifier hs-type"
+	  >Foo</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-special"
+      >)</span
+      ><span class="hs-special"
+      >)</span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><span class="hs-number"
+	>1</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-35"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-36"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-37"
+      ></span
+      ><span class="annot"
+      ><a href="Types.html#norf1%27"
+	><span class="hs-identifier hs-type"
+	  >norf1'</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Types.html#Norf%27"
+	><span class="hs-identifier hs-type"
+	  >Norf'</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Types.html#Foo"
+	><span class="hs-identifier hs-type"
+	  >Foo</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Types.html#Quux"
+	><span class="hs-identifier hs-type"
+	  >Quux</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>Int</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-38"
+      ></span
+      ><span id="norf1%27"
+      ><span class="annot"
+	><span class="annottext"
+	  >norf1' :: Norf' Foo Quux -&gt; Int
+</span
+	  ><a href="Types.html#norf1%27"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >norf1'</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><a href="Types.html#Foo"
+	><span class="hs-identifier hs-type"
+	  >Foo</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-special"
+      >)</span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Quux
+</span
+	><a href="Types.html#Bar"
+	><span class="hs-identifier hs-var"
+	  >Bar</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><span class="hs-number"
+	>0</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-39"
+      ></span
+      ><span class="annot"
+      ><a href="Types.html#norf1%27"
+	><span class="hs-identifier hs-var"
+	  >norf1'</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><a href="Types.html#Foo"
+	><span class="hs-identifier hs-type"
+	  >Foo</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-special"
+      >)</span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Quux
+</span
+	><a href="Types.html#Baz"
+	><span class="hs-identifier hs-var"
+	  >Baz</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><span class="hs-number"
+	>1</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-40"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-41"
+      ></span
+      ><span class="annot"
+      ><a href="Types.html#norf2%27"
+	><span class="hs-identifier hs-type"
+	  >norf2'</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Types.html#Norf%27"
+	><span class="hs-identifier hs-type"
+	  >Norf'</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Types.html#Quux"
+	><span class="hs-identifier hs-type"
+	  >Quux</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Types.html#Foo"
+	><span class="hs-identifier hs-type"
+	  >Foo</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="hs-identifier hs-type"
+	>Int</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-42"
+      ></span
+      ><span id="norf2%27"
+      ><span class="annot"
+	><span class="annottext"
+	  >norf2' :: Norf' Quux Foo -&gt; Int
+</span
+	  ><a href="Types.html#norf2%27"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >norf2'</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><span class="annottext"
+	>Quux
+</span
+	><a href="Types.html#Bar"
+	><span class="hs-identifier hs-var"
+	  >Bar</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Types.html#Foo"
+	><span class="hs-identifier hs-type"
+	  >Foo</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-special"
+      >)</span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><span class="hs-number"
+	>0</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-43"
+      ></span
+      ><span class="annot"
+      ><a href="Types.html#norf2%27"
+	><span class="hs-identifier hs-var"
+	  >norf2'</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="annot"
+      ><span class="annottext"
+	>Quux
+</span
+	><a href="Types.html#Baz"
+	><span class="hs-identifier hs-var"
+	  >Baz</span
+	  ></a
+	></span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Types.html#Foo"
+	><span class="hs-identifier hs-type"
+	  >Foo</span
+	  ></a
+	></span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-special"
+      >)</span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>Int
+</span
+	><span class="hs-number"
+	>1</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-44"
+      ></span
+      ></pre
+    ></body
+  ></html
+>
diff --git a/hypsrc-test/ref/src/UsingQuasiquotes.html b/hypsrc-test/ref/src/UsingQuasiquotes.html
new file mode 100644
--- /dev/null
+++ b/hypsrc-test/ref/src/UsingQuasiquotes.html
@@ -0,0 +1,117 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><link rel="stylesheet" type="text/css" href="style.css"
+     /><script type="text/javascript" src="highlight.js"
+    ></script
+    ></head
+  ><body
+  ><pre
+    ><span class="hs-pragma"
+      >{-# LANGUAGE Haskell2010 #-}</span
+      ><span
+      >
+</span
+      ><span id="line-2"
+      ></span
+      ><span class="hs-pragma"
+      >{-# LANGUAGE QuasiQuotes #-}</span
+      ><span
+      >
+</span
+      ><span id="line-3"
+      ></span
+      ><span class="hs-keyword"
+      >module</span
+      ><span
+      > </span
+      ><span class="hs-identifier"
+      >UsingQuasiquotes</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >where</span
+      ><span
+      >
+</span
+      ><span id="line-4"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-5"
+      ></span
+      ><span class="hs-keyword"
+      >import</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><a href="Quasiquoter.html"
+	><span class="hs-identifier"
+	  >Quasiquoter</span
+	  ></a
+	></span
+      ><span
+      >
+</span
+      ><span id="line-6"
+      ></span
+      ><span
+      >
+</span
+      ><span id="line-7"
+      ></span
+      ><span id="baz"
+      ><span class="annot"
+	><span class="annottext"
+	  >baz :: [Char]
+</span
+	  ><a href="UsingQuasiquotes.html#baz"
+	  ><span class="hs-identifier hs-var hs-var"
+	    >baz</span
+	    ></a
+	  ></span
+	></span
+      ><span
+      >  </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>[Char]
+</span
+	><span class=""
+	>[string| foo bar |]</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>[Char] -&gt; [Char] -&gt; [Char]
+forall a. [a] -&gt; [a] -&gt; [a]
+</span
+	><span class="hs-operator hs-var"
+	>++</span
+	></span
+      ><span
+      > </span
+      ><span class="annot"
+      ><span class="annottext"
+	>[Char]
+</span
+	><span class=""
+	>[string| some
+  mulitline
+  quasiquote
+|]</span
+	></span
+      ><span
+      >
+</span
+      ><span id="line-11"
+      ></span
+      ></pre
+    ></body
+  ></html
+>
diff --git a/hypsrc-test/src/Bug1091.hs b/hypsrc-test/src/Bug1091.hs
new file mode 100644
--- /dev/null
+++ b/hypsrc-test/src/Bug1091.hs
@@ -0,0 +1,5 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE CPP #-}
+module Bug1091 where
+
+#include "Include1For1091.h"
diff --git a/hypsrc-test/src/CPP.hs b/hypsrc-test/src/CPP.hs
new file mode 100644
--- /dev/null
+++ b/hypsrc-test/src/CPP.hs
@@ -0,0 +1,27 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE CPP #-}
+module CPP where
+
+#define SOMETHING1
+
+foo :: String
+foo = {-  " single quotes are fine in block comments
+          {- nested block comments are fine -}
+       -} "foo"
+
+#define SOMETHING2
+
+bar :: String
+bar = "block comment in a string is not a comment {- "
+
+#define SOMETHING3
+
+-- " single quotes are fine in line comments
+-- {- unclosed block comments are fine in line comments
+
+-- Multiline CPP is also fine
+#define FOO\
+  1
+
+baz :: String
+baz = "line comment in a string is not a comment --"
diff --git a/hypsrc-test/src/Classes.hs b/hypsrc-test/src/Classes.hs
new file mode 100644
--- /dev/null
+++ b/hypsrc-test/src/Classes.hs
@@ -0,0 +1,39 @@
+{-# LANGUAGE Haskell2010 #-}
+module Classes where
+
+
+class Foo a where
+    bar :: a -> Int
+    baz :: Int -> (a, a)
+
+instance Foo Int where
+    bar = id
+    baz x = (x, x)
+
+instance Foo [a] where
+    bar = length
+    baz _ = ([], [])
+
+
+class Foo a => Foo' a where
+    quux :: (a, a) -> a
+    quux (x, y) = norf [x, y]
+
+    norf :: [a] -> a
+    norf = quux . baz . sum . map bar
+
+instance Foo' Int where
+    norf = sum
+
+instance Foo' [a] where
+    quux = uncurry (++)
+
+
+class Plugh p where
+    plugh :: p a a -> p b b -> p (a -> b) (b -> a)
+
+instance Plugh Either where
+    plugh (Left a) _ = Right $ const a
+    plugh (Right a) _ = Right $ const a
+    plugh _ (Left b) = Left $ const b
+    plugh _ (Right b) = Left $ const b
diff --git a/hypsrc-test/src/Constructors.hs b/hypsrc-test/src/Constructors.hs
new file mode 100644
--- /dev/null
+++ b/hypsrc-test/src/Constructors.hs
@@ -0,0 +1,36 @@
+{-# LANGUAGE Haskell2010 #-}
+module Constructors where
+
+
+data Foo
+    = Bar
+    | Baz
+    | Quux Foo Int
+
+newtype Norf = Norf (Foo, [Foo], Foo)
+
+
+bar, baz, quux :: Foo
+bar = Bar
+baz = Baz
+quux = Quux quux 0
+
+
+unfoo :: Foo -> Int
+unfoo Bar = 0
+unfoo Baz = 0
+unfoo (Quux foo n) = 42 * n + unfoo foo
+
+
+unnorf :: Norf -> [Foo]
+unnorf (Norf (Bar, xs, Bar)) = xs
+unnorf (Norf (Baz, xs, Baz)) = reverse xs
+unnorf _ = undefined
+
+
+unnorf' :: Norf -> Int
+unnorf' x@(Norf (f1@(Quux _ n), _, f2@(Quux f3 _))) =
+    x' + n * unfoo f1 + aux f3
+  where
+    aux fx = unfoo f2 * unfoo fx * unfoo f3
+    x' = sum . map unfoo . unnorf $ x
diff --git a/hypsrc-test/src/Identifiers.hs b/hypsrc-test/src/Identifiers.hs
new file mode 100644
--- /dev/null
+++ b/hypsrc-test/src/Identifiers.hs
@@ -0,0 +1,29 @@
+{-# LANGUAGE Haskell2010 #-}
+module Identifiers where
+
+
+foo, bar, baz :: Int -> Int -> Int
+foo x y = x + x * bar y x * y + y
+bar x y = y + x - baz x y - x + y
+baz x y = x * y * y * y * x
+
+quux :: Int -> Int
+quux x = foo (bar x x) (bar x x)
+
+norf :: Int -> Int -> Int -> Int
+norf x y z
+    | x < 0 = quux x
+    | y < 0 = quux y
+    | z < 0 = quux z
+    | otherwise = norf (-x) (-y) (-z)
+
+
+main :: IO ()
+main = do
+    putStrLn . show $ foo x y
+    putStrLn . show $ quux z
+    putStrLn . show $ Identifiers.norf x y z
+  where
+    x = 10
+    y = 20
+    z = 30
diff --git a/hypsrc-test/src/Include1For1091.h b/hypsrc-test/src/Include1For1091.h
new file mode 100644
--- /dev/null
+++ b/hypsrc-test/src/Include1For1091.h
@@ -0,0 +1,6 @@
+/* Include1For1091.h */
+
+foo :: Int
+foo = 42
+
+#include "Include2For1091.h"
diff --git a/hypsrc-test/src/Include2For1091.h b/hypsrc-test/src/Include2For1091.h
new file mode 100644
--- /dev/null
+++ b/hypsrc-test/src/Include2For1091.h
@@ -0,0 +1,4 @@
+/* Include2For1091.h */
+
+bar :: Int
+bar = 27
diff --git a/hypsrc-test/src/LinkingIdentifiers.hs b/hypsrc-test/src/LinkingIdentifiers.hs
new file mode 100644
--- /dev/null
+++ b/hypsrc-test/src/LinkingIdentifiers.hs
@@ -0,0 +1,15 @@
+{-# LANGUAGE Haskell2010 #-}
+-- Tests that the identifiers/operators are properly linked even when:
+--
+--   * backquoted, parenthesized, vanilla
+--   * qualified, not-qualified
+--
+module LinkingIdentifiers where
+
+ident :: Int -> Int -> Int
+x `ident` 2 = (x `ident` 2) + (x `LinkingIdentifiers.ident` 2)
+ident x 2 = ident x 2 + LinkingIdentifiers.ident x 2
+
+(++:++) :: Int -> Int -> Int
+x ++:++ 2 = (x ++:++ 2) + (x LinkingIdentifiers.++:++ 2)
+(++:++) x 2 = (++:++) x 2 + (LinkingIdentifiers.++:++) x 2
diff --git a/hypsrc-test/src/Literals.hs b/hypsrc-test/src/Literals.hs
new file mode 100644
--- /dev/null
+++ b/hypsrc-test/src/Literals.hs
@@ -0,0 +1,18 @@
+{-# LANGUAGE Haskell2010 #-}
+module Literals where
+
+
+str :: String
+str = "str literal"
+
+num :: Num a => a
+num = 0 + 1 + 1010011 * 41231 + 12131
+
+frac :: Fractional a => a
+frac = 42.0000001
+
+list :: [[[[a]]]]
+list = [[], [[]], [[[]]]]
+
+pair :: ((), ((), (), ()), ())
+pair = ((), ((), (), ()), ())
diff --git a/hypsrc-test/src/Operators.hs b/hypsrc-test/src/Operators.hs
new file mode 100644
--- /dev/null
+++ b/hypsrc-test/src/Operators.hs
@@ -0,0 +1,21 @@
+{-# LANGUAGE Haskell2010 #-}
+module Operators where
+
+(+++) :: [a] -> [a] -> [a]
+a +++ b = a ++ b ++ a
+
+($$$) :: [a] -> [a] -> [a]
+a $$$ b = b +++ a
+
+(***) :: [a] -> [a] -> [a]
+(***) a [] = a
+(***) a (_:b) = a +++ (a *** b)
+
+(*/\*) :: [[a]] -> [a] -> [a]
+a */\* b = concatMap (*** b) a
+
+(**/\**) :: [[a]] -> [[a]] -> [[a]]
+a **/\** b = zipWith (*/\*) [a +++ b] (a $$$ b)
+
+(#.#) :: a -> b -> (c -> (a, b))
+a #.# b = const (a, b)
diff --git a/hypsrc-test/src/Polymorphism.hs b/hypsrc-test/src/Polymorphism.hs
new file mode 100644
--- /dev/null
+++ b/hypsrc-test/src/Polymorphism.hs
@@ -0,0 +1,67 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE RankNTypes #-}
+{-# LANGUAGE ScopedTypeVariables #-}
+
+
+module Polymorphism where
+
+
+foo :: a -> a -> a
+foo = undefined
+
+foo' :: forall a. a -> a -> a
+foo' = undefined
+
+bar :: a -> b -> (a, b)
+bar = undefined
+
+bar' :: forall a b. a -> b -> (a, b)
+bar' = undefined
+
+baz :: a -> (a -> [a -> a] -> b) -> b
+baz = undefined
+
+baz' :: forall a b. a -> (a -> [a -> a] -> b) -> b
+baz' = undefined
+
+quux :: a -> (forall a. a -> a) -> a
+quux x f = f x
+
+quux' :: forall a. a -> (forall a. a -> a) -> a
+quux' x f = f x
+
+
+num :: Num a => a -> a -> a
+num = undefined
+
+num' :: forall a. Num a => a -> a -> a
+num' = undefined
+
+eq :: (Eq a, Eq b) => [a] -> [b] -> (a, b)
+eq = undefined
+
+eq' :: forall a b. (Eq a, Eq b) => [a] -> [b] -> (a, b)
+eq' = undefined
+
+mon :: Monad m => (a -> m a) -> m a
+mon = undefined
+
+mon' :: forall m a. Monad m => (a -> m a) -> m a
+mon' = undefined
+
+
+norf :: a -> (forall a. Ord a => a -> a) -> a
+norf x f = x
+
+norf' :: forall a. a -> (forall a. Ord a => a -> a) -> a
+norf' x f = x
+
+
+plugh :: forall a. a -> a
+plugh x = x :: a
+
+thud :: forall a b. (a -> b) -> a -> (a, b)
+thud f x =
+    (x :: a, y) :: (a, b)
+  where
+    y = (f :: a -> b) x :: b
diff --git a/hypsrc-test/src/PositionPragmas.hs b/hypsrc-test/src/PositionPragmas.hs
new file mode 100644
--- /dev/null
+++ b/hypsrc-test/src/PositionPragmas.hs
@@ -0,0 +1,13 @@
+{-# LANGUAGE Haskell2010 #-}
+module PositionPragmas where
+
+{-# LINE 8 "hypsrc-test/src/PositionPragmas.hs" #-}
+
+foo :: String
+foo = bar
+
+{-# LINE 23 "hypsrc-test/src/PositionPragmas.hs" #-}
+
+bar :: String
+bar = foo 
+
diff --git a/hypsrc-test/src/Quasiquoter.hs b/hypsrc-test/src/Quasiquoter.hs
new file mode 100644
--- /dev/null
+++ b/hypsrc-test/src/Quasiquoter.hs
@@ -0,0 +1,17 @@
+{-# LANGUAGE Haskell2010 #-}
+module Quasiquoter ( string ) where
+
+import Language.Haskell.TH.Quote
+import Language.Haskell.TH.Syntax
+
+-- | Quoter for constructing multiline string literals
+string :: QuasiQuoter
+string = QuasiQuoter
+  { quoteExp = pure . LitE . StringL
+  , quotePat = invalidDomain
+  , quoteType = invalidDomain
+  , quoteDec = invalidDomain
+  }
+  where
+    invalidDomain :: String -> Q a
+    invalidDomain _ = fail "stringQuoter: only valid in expression context"
diff --git a/hypsrc-test/src/Records.hs b/hypsrc-test/src/Records.hs
new file mode 100644
--- /dev/null
+++ b/hypsrc-test/src/Records.hs
@@ -0,0 +1,35 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE NamedFieldPuns #-}
+{-# LANGUAGE RecordWildCards #-}
+
+
+module Records where
+
+
+data Point = Point
+    { x :: !Int
+    , y :: !Int
+    }
+
+
+point :: Int -> Int -> Point
+point x y = Point { x = x, y = y }
+
+
+lengthSqr :: Point -> Int
+lengthSqr (Point { x = x, y = y }) = x * x + y * y
+
+lengthSqr' :: Point -> Int
+lengthSqr' (Point { x, y }) = y * y + x * x
+
+
+translateX, translateY :: Point -> Int -> Point
+translateX p d = p { x = x p + d }
+translateY p d = p { y = y p + d }
+
+translate :: Int -> Int -> Point -> Point
+translate x y p =
+    aux p
+  where
+    (dx, dy) = (x, y)
+    aux Point{..} = p { x = x + dx, y = y + dy }
diff --git a/hypsrc-test/src/TemplateHaskellQuasiquotes.hs b/hypsrc-test/src/TemplateHaskellQuasiquotes.hs
new file mode 100644
--- /dev/null
+++ b/hypsrc-test/src/TemplateHaskellQuasiquotes.hs
@@ -0,0 +1,46 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE TemplateHaskell #-}
+
+module TemplateHaskellQuasiquotes where
+
+import Language.Haskell.TH
+
+aDecl :: DecsQ
+aDecl = [d|
+    bar :: $aType -> [ (Int, String) ]
+    bar $aPattern = $anExpression
+  |]
+
+aPattern :: PatQ
+aPattern = [p|
+    [ aCrazyLongVariableName
+    , _unused
+    , (y, z)
+    , ( $aNumberPattern, "hello")
+    ]
+  |]
+
+aNumberPattern :: PatQ
+aNumberPattern = [p|
+    w@v@4.5
+  |]
+
+anExpression, anExpression2 :: ExpQ
+anExpression = [e|
+    [ (1 + $anExpression2, "world") ]
+  |]
+anExpression2 = [| (1 + round pi) |]
+
+aType :: TypeQ
+aType = [t|
+    [ (Double, String) ]
+  |]
+
+typedExpr1 :: Code Q ()
+typedExpr1 = [|| () ||]
+
+typedExpr :: Code Q ()
+typedExpr = [|| const $$(typedExpr1) () ||]
+
+
+
diff --git a/hypsrc-test/src/TemplateHaskellSplices.hs b/hypsrc-test/src/TemplateHaskellSplices.hs
new file mode 100644
--- /dev/null
+++ b/hypsrc-test/src/TemplateHaskellSplices.hs
@@ -0,0 +1,13 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE TemplateHaskell #-}
+module TemplateHaskellSplices where
+
+import TemplateHaskellQuasiquotes
+
+$(aDecl)
+
+foo = id $(anExpression2)
+
+pat $(aPattern) = ()
+
+qux = id $$(typedExpr)
diff --git a/hypsrc-test/src/Types.hs b/hypsrc-test/src/Types.hs
new file mode 100644
--- /dev/null
+++ b/hypsrc-test/src/Types.hs
@@ -0,0 +1,43 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE TypeFamilies #-}
+
+
+module Types where
+
+
+data Quux = Bar | Baz
+
+newtype Foo = Foo ()
+
+type FooQuux = (Foo, Quux)
+type QuuxFoo = (Quux, Foo)
+
+
+data family Norf a b
+
+data instance Norf Foo Quux = NFQ Foo Quux
+data instance Norf Quux Foo = NQF Quux Foo
+
+
+type family Norf' a b
+
+type instance Norf' Foo Quux = (Foo, Quux)
+type instance Norf' Quux Foo = (Quux, Foo)
+
+
+norf1 :: Norf Foo Quux -> Int
+norf1 (NFQ (Foo ()) Bar) = 0
+norf1 (NFQ (Foo ()) Baz) = 1
+
+norf2 :: Norf Quux Foo -> Int
+norf2 (NQF Bar (Foo ())) = 0
+norf2 (NQF Baz (Foo ())) = 1
+
+
+norf1' :: Norf' Foo Quux -> Int
+norf1' (Foo (), Bar) = 0
+norf1' (Foo (), Baz) = 1
+
+norf2' :: Norf' Quux Foo -> Int
+norf2' (Bar, Foo ()) = 0
+norf2' (Baz, Foo ()) = 1
diff --git a/hypsrc-test/src/UsingQuasiquotes.hs b/hypsrc-test/src/UsingQuasiquotes.hs
new file mode 100644
--- /dev/null
+++ b/hypsrc-test/src/UsingQuasiquotes.hs
@@ -0,0 +1,10 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE QuasiQuotes #-}
+module UsingQuasiquotes where
+
+import Quasiquoter
+
+baz  = [string| foo bar |] ++ [string| some
+  mulitline
+  quasiquote
+|]
diff --git a/latex-test/Main.hs b/latex-test/Main.hs
new file mode 100644
--- /dev/null
+++ b/latex-test/Main.hs
@@ -0,0 +1,32 @@
+{-# LANGUAGE CPP #-}
+
+
+import Data.Function
+import System.Environment
+import System.FilePath
+
+import Test.Haddock
+import Test.Haddock.Utils
+
+
+checkConfig :: CheckConfig String
+checkConfig = CheckConfig
+    { ccfgRead = Just
+    , ccfgClean = \_ -> id
+    , ccfgDump = id
+    , ccfgEqual = (==) `on` crlfToLf
+    }
+
+
+dirConfig :: DirConfig
+dirConfig = (defaultDirConfig $ takeDirectory __FILE__)
+  { dcfgCheckIgnore = (`elem` ["haddock.sty", "main.tex"]) . takeFileName
+  }
+
+
+main :: IO ()
+main = do
+    cfg <- parseArgs checkConfig dirConfig =<< getArgs
+    runAndCheck $ cfg
+        { cfgHaddockArgs = cfgHaddockArgs cfg ++ ["--latex"]
+        }
diff --git a/latex-test/ref/ConstructorArgs/ConstructorArgs.tex b/latex-test/ref/ConstructorArgs/ConstructorArgs.tex
new file mode 100644
--- /dev/null
+++ b/latex-test/ref/ConstructorArgs/ConstructorArgs.tex
@@ -0,0 +1,71 @@
+\haddockmoduleheading{ConstructorArgs}
+\label{module:ConstructorArgs}
+\haddockbeginheader
+{\haddockverb\begin{verbatim}
+module ConstructorArgs (
+    Foo((:|), Rec, Baz, Boa, (:*), x, y), Boo(Foo, Foa, Fo, Fo'), pattern Bo,
+    pattern Bo'
+  ) where\end{verbatim}}
+\haddockendheader
+
+\begin{haddockdesc}
+\item[\begin{tabular}{@{}l}
+data Foo
+\end{tabular}]
+{\haddockbegindoc
+\enspace \emph{Constructors}\par
+\haddockbeginconstrs
+\haddockdecltt{=} & \haddockdecltt{Rec} & doc on a record \\
+                                          & \haddocktt{\qquad \{} \haddockdecltt{x :: String} & doc on the \haddockid{String} field of \haddockid{Rec} \\
+                                          & \haddocktt{\qquad ,} \haddockdecltt{y :: String} & doc on the \haddockid{String} field of \haddockid{Rec} \\ & \haddocktt{\qquad \}} \\
+\haddockdecltt{|} & \haddockdecltt{Baz Int String} & old prefix doc style \\
+\haddockdecltt{|} & \haddockdecltt{Boa} & doc on the \haddockid{Boa} constrictor \\
+                                          & \qquad \haddockdecltt{!Int} & doc on the \haddockid{Int} field of \haddockid{Boa} \\
+                                          & \qquad \haddockdecltt{!String} & doc on the \haddockid{String} field of \haddockid{Boa} \\
+\haddockdecltt{|} & \haddockdecltt{Int :| String} & old infix doc style \\
+\haddockdecltt{|} & \haddockdecltt{(:*)} & doc on the \haddockid{:*} constructor \\
+                                           & \qquad \haddockdecltt{Int} & doc on the \haddockid{Int} field of the \haddockid{:*} constructor \\
+                                           & \qquad \haddockdecltt{String} & doc on the \haddockid{String} field of the \haddockid{:*} constructor \\
+\end{tabulary}\par}
+\end{haddockdesc}
+\begin{haddockdesc}
+\item[\begin{tabular}{@{}l}
+data Boo where
+\end{tabular}]
+{\haddockbegindoc
+\enspace \emph{Constructors}\par
+\haddockbeginconstrs
+& \haddockdecltt{Foo} & Info about a \haddockid{Foo} \\
+                        & \qquad \haddockdecltt{::} \enspace \haddockdecltt{Int} & \haddockid{Int} field of \haddockid{Foo} \\
+                        & \qquad \haddockdecltt{->} \enspace \haddockdecltt{String} & \haddockid{String} field of \haddockid{Foo} \\
+                        & \qquad \haddockdecltt{->} \enspace \haddockdecltt{Boo} & Make a \haddockid{Boo} \\
+& \haddockdecltt{Foa :: Int -> Boo} & no argument docs GADT \\
+\end{tabulary}\par
+\enspace \emph{Bundled Patterns}\par
+\haddockbeginconstrs
+& \haddockdecltt{pattern Fo} & Info about bundled \haddockid{Fo} \\
+                               & \qquad \haddockdecltt{::} \enspace \haddockdecltt{Int} & an \haddockid{Int} \\
+                               & \qquad \haddockdecltt{->} \enspace \haddockdecltt{String} & a \haddockid{String} \\
+                               & \qquad \haddockdecltt{->} \enspace \haddockdecltt{Boo} & a \haddockid{Boo} \\
+& \haddockdecltt{pattern Fo' :: Boo} & Bundled and no argument docs \\
+\end{tabulary}\par}
+\end{haddockdesc}
+\begin{haddockdesc}
+\item[\begin{tabular}{@{}l}
+pattern Bo
+\end{tabular}]
+{\haddockbegindoc
+\haddockbeginargs
+\haddockdecltt{::} & \haddockdecltt{Int} & an \haddockid{Int} \\
+\haddockdecltt{->} & \haddockdecltt{String} & a \haddockid{String} \\
+\haddockdecltt{->} & \haddockdecltt{Boo} & a \haddockid{Boo} pattern \\
+\end{tabulary}\par
+Info about not-bundled \haddockid{Bo}\par}
+\end{haddockdesc}
+\begin{haddockdesc}
+\item[\begin{tabular}{@{}l}
+pattern Bo' :: Int -> String -> Boo
+\end{tabular}]
+{\haddockbegindoc
+Not bunded and no argument docs\par}
+\end{haddockdesc}
diff --git a/latex-test/ref/DefaultSignatures/DefaultSignatures.tex b/latex-test/ref/DefaultSignatures/DefaultSignatures.tex
new file mode 100644
--- /dev/null
+++ b/latex-test/ref/DefaultSignatures/DefaultSignatures.tex
@@ -0,0 +1,41 @@
+\haddockmoduleheading{DefaultSignatures}
+\label{module:DefaultSignatures}
+\haddockbeginheader
+{\haddockverb\begin{verbatim}
+module DefaultSignatures (
+    Foo(baz', baz, bar)
+  ) where\end{verbatim}}
+\haddockendheader
+
+\begin{haddockdesc}
+\item[\begin{tabular}{@{}l}
+class Foo a where
+\end{tabular}]
+{\haddockbegindoc
+Documentation for Foo.\par
+\haddockpremethods{}\emph{Methods}
+\begin{haddockdesc}
+\item[\begin{tabular}{@{}l}
+bar, baz :: a -> String
+\end{tabular}]
+{\haddockbegindoc
+Documentation for bar and baz.\par}
+\end{haddockdesc}
+\begin{haddockdesc}
+\item[\begin{tabular}{@{}l}
+default bar :: Show a => a -> String
+\end{tabular}]
+\end{haddockdesc}
+\begin{haddockdesc}
+\item[\begin{tabular}{@{}l}
+baz' :: String -> a
+\end{tabular}]
+{\haddockbegindoc
+Documentation for baz'.\par}
+\end{haddockdesc}
+\begin{haddockdesc}
+\item[\begin{tabular}{@{}l}
+default baz' :: Read a => String -> a
+\end{tabular}]
+\end{haddockdesc}}
+\end{haddockdesc}
diff --git a/latex-test/ref/Deprecated/Deprecated.tex b/latex-test/ref/Deprecated/Deprecated.tex
new file mode 100644
--- /dev/null
+++ b/latex-test/ref/Deprecated/Deprecated.tex
@@ -0,0 +1,17 @@
+\haddockmoduleheading{Deprecated}
+\label{module:Deprecated}
+\haddockbeginheader
+{\haddockverb\begin{verbatim}
+module Deprecated (
+    deprecated
+  ) where\end{verbatim}}
+\haddockendheader
+
+\begin{haddockdesc}
+\item[\begin{tabular}{@{}l}
+deprecated :: Int
+\end{tabular}]
+{\haddockbegindoc
+Deprecated: Don't use this\par
+Docs for something deprecated\par}
+\end{haddockdesc}
diff --git a/latex-test/ref/Example/Example.tex b/latex-test/ref/Example/Example.tex
new file mode 100644
--- /dev/null
+++ b/latex-test/ref/Example/Example.tex
@@ -0,0 +1,30 @@
+\haddockmoduleheading{Example}
+\label{module:Example}
+\haddockbeginheader
+{\haddockverb\begin{verbatim}
+module Example (
+    split
+  ) where\end{verbatim}}
+\haddockendheader
+
+\begin{haddockdesc}
+\item[\begin{tabular}{@{}l}
+split :: Int -> ()
+\end{tabular}]
+{\haddockbegindoc
+Example use.\par
+\begin{quote}
+{\haddockverb\begin{verbatim}
+>>> split 1
+()
+
+\end{verbatim}}
+\end{quote}
+\begin{quote}
+{\haddockverb\begin{verbatim}
+>>> split 2
+()
+
+\end{verbatim}}
+\end{quote}}
+\end{haddockdesc}
diff --git a/latex-test/ref/GadtConstructorArgs/GadtConstructorArgs.tex b/latex-test/ref/GadtConstructorArgs/GadtConstructorArgs.tex
new file mode 100644
--- /dev/null
+++ b/latex-test/ref/GadtConstructorArgs/GadtConstructorArgs.tex
@@ -0,0 +1,26 @@
+\haddockmoduleheading{GadtConstructorArgs}
+\label{module:GadtConstructorArgs}
+\haddockbeginheader
+{\haddockverb\begin{verbatim}
+module GadtConstructorArgs (
+    Boo(Fot, Fob, x, y, w, z)
+  ) where\end{verbatim}}
+\haddockendheader
+
+\begin{haddockdesc}
+\item[\begin{tabular}{@{}l}
+data Boo where
+\end{tabular}]
+{\haddockbegindoc
+\enspace \emph{Constructors}\par
+\haddockbeginconstrs
+& \haddockdecltt{Fot} & \\
+                        & \qquad \haddockdecltt{:: {\char '173}} \enspace \haddockdecltt{x :: Int} & an \haddockid{x} \\
+                        & \qquad \haddockdecltt{\ \ \ \ ,} \enspace \haddockdecltt{y :: Int} & a \haddockid{y} \\
+                        & \qquad \haddockdecltt{\ \ \ \ {\char '175} ->} \enspace \haddockdecltt{Boo} & \\
+& \haddockdecltt{Fob} & Record GADT with docs \\
+                        & \qquad \haddockdecltt{:: {\char '173}} \enspace \haddockdecltt{w :: Int} & a \haddockid{w} \\
+                        & \qquad \haddockdecltt{\ \ \ \ ,} \enspace \haddockdecltt{z :: Int} & a \haddockid{z} \\
+                        & \qquad \haddockdecltt{\ \ \ \ {\char '175} ->} \enspace \haddockdecltt{Boo} & a \haddockid{Boo} \\
+\end{tabulary}\par}
+\end{haddockdesc}
diff --git a/latex-test/ref/LinearTypes/LinearTypes.tex b/latex-test/ref/LinearTypes/LinearTypes.tex
new file mode 100644
--- /dev/null
+++ b/latex-test/ref/LinearTypes/LinearTypes.tex
@@ -0,0 +1,30 @@
+\haddockmoduleheading{LinearTypes}
+\label{module:LinearTypes}
+\haddockbeginheader
+{\haddockverb\begin{verbatim}
+module LinearTypes (
+    unrestricted, linear, poly
+  ) where\end{verbatim}}
+\haddockendheader
+
+\begin{haddockdesc}
+\item[\begin{tabular}{@{}l}
+unrestricted :: a -> b
+\end{tabular}]
+{\haddockbegindoc
+Does something unrestricted.\par}
+\end{haddockdesc}
+\begin{haddockdesc}
+\item[\begin{tabular}{@{}l}
+linear :: a {\char '45}1 -> b
+\end{tabular}]
+{\haddockbegindoc
+Does something linear.\par}
+\end{haddockdesc}
+\begin{haddockdesc}
+\item[\begin{tabular}{@{}l}
+poly :: a {\char '45}m -> b
+\end{tabular}]
+{\haddockbegindoc
+Does something polymorphic.\par}
+\end{haddockdesc}
diff --git a/latex-test/ref/LinearTypes/main.tex b/latex-test/ref/LinearTypes/main.tex
new file mode 100644
--- /dev/null
+++ b/latex-test/ref/LinearTypes/main.tex
@@ -0,0 +1,11 @@
+\documentclass{book}
+\usepackage{haddock}
+\begin{document}
+\begin{titlepage}
+\begin{haddocktitle}
+
+\end{haddocktitle}
+\end{titlepage}
+\tableofcontents
+\input{LinearTypes}
+\end{document}
diff --git a/latex-test/ref/NamespacedIdentifier/NamespacedIdentifiers.tex b/latex-test/ref/NamespacedIdentifier/NamespacedIdentifiers.tex
new file mode 100644
--- /dev/null
+++ b/latex-test/ref/NamespacedIdentifier/NamespacedIdentifiers.tex
@@ -0,0 +1,37 @@
+\haddockmoduleheading{NamespacedIdentifiers}
+\label{module:NamespacedIdentifiers}
+\haddockbeginheader
+{\haddockverb\begin{verbatim}
+module NamespacedIdentifiers (
+    Foo(Bar), Bar
+  ) where\end{verbatim}}
+\haddockendheader
+
+\begin{haddockdesc}
+\item[\begin{tabular}{@{}l}
+data Foo
+\end{tabular}]
+{\haddockbegindoc
+A link to:\par
+\vbox{\begin{itemize}
+\item
+the type \haddockid{Bar}\par
+\item
+the constructor \haddockid{Bar}\par
+\item
+the unimported but qualified type \haddockid{A}\par
+\item
+the unimported but qualified value \haddockid{A}\par
+\end{itemize}}
+\enspace \emph{Constructors}\par
+\haddockbeginconstrs
+\haddockdecltt{=} & \haddockdecltt{Bar} & \\
+\end{tabulary}\par}
+\end{haddockdesc}
+\begin{haddockdesc}
+\item[\begin{tabular}{@{}l}
+data Bar
+\end{tabular}]
+{\haddockbegindoc
+A link to the value \haddocktt{Foo} (which shouldn't exist).\par}
+\end{haddockdesc}
diff --git a/latex-test/ref/Simple/Simple.tex b/latex-test/ref/Simple/Simple.tex
new file mode 100644
--- /dev/null
+++ b/latex-test/ref/Simple/Simple.tex
@@ -0,0 +1,16 @@
+\haddockmoduleheading{Simple}
+\label{module:Simple}
+\haddockbeginheader
+{\haddockverb\begin{verbatim}
+module Simple (
+    foo
+  ) where\end{verbatim}}
+\haddockendheader
+
+\begin{haddockdesc}
+\item[\begin{tabular}{@{}l}
+foo :: t
+\end{tabular}]
+{\haddockbegindoc
+This is foo.\par}
+\end{haddockdesc}
diff --git a/latex-test/ref/TypeFamilies3/TypeFamilies3.tex b/latex-test/ref/TypeFamilies3/TypeFamilies3.tex
new file mode 100644
--- /dev/null
+++ b/latex-test/ref/TypeFamilies3/TypeFamilies3.tex
@@ -0,0 +1,44 @@
+\haddockmoduleheading{TypeFamilies3}
+\label{module:TypeFamilies3}
+\haddockbeginheader
+{\haddockverb\begin{verbatim}
+module TypeFamilies3 (
+    Foo, Bar, Baz(Baz3, Baz2, Baz1)
+  ) where\end{verbatim}}
+\haddockendheader
+
+\begin{haddockdesc}
+\item[\begin{tabular}{@{}l}
+type family Foo a where
+\end{tabular}]
+{\haddockbegindoc
+\haddockbeginargs
+\haddockdecltt{Foo () = Int} \\
+\haddockdecltt{Foo {\char '137} = ()} \\
+\end{tabulary}\par
+A closed type family\par}
+\end{haddockdesc}
+\begin{haddockdesc}
+\item[\begin{tabular}{@{}l}
+type family Bar a
+\end{tabular}]
+{\haddockbegindoc
+An open family\par}
+\end{haddockdesc}
+\begin{haddockdesc}
+\item[\begin{tabular}{@{}l}
+type instance Bar () = Int\\type instance Bar Int = ()
+\end{tabular}]
+\end{haddockdesc}
+\begin{haddockdesc}
+\item[\begin{tabular}{@{}l}
+data family Baz a
+\end{tabular}]
+{\haddockbegindoc
+A data family\par}
+\end{haddockdesc}
+\begin{haddockdesc}
+\item[\begin{tabular}{@{}l}
+data instance Baz ()\\newtype instance Baz Double\\data instance Baz Int
+\end{tabular}]
+\end{haddockdesc}
diff --git a/latex-test/ref/UnboxedStuff/UnboxedStuff.tex b/latex-test/ref/UnboxedStuff/UnboxedStuff.tex
new file mode 100644
--- /dev/null
+++ b/latex-test/ref/UnboxedStuff/UnboxedStuff.tex
@@ -0,0 +1,36 @@
+\haddockmoduleheading{UnboxedStuff}
+\label{module:UnboxedStuff}
+\haddockbeginheader
+{\haddockverb\begin{verbatim}
+module UnboxedStuff (
+    X, Y, Z, unboxedUnit, unboxedTuple, unboxedSum
+  ) where\end{verbatim}}
+\haddockendheader
+
+\begin{haddockdesc}
+\item[\begin{tabular}{@{}l}
+data X
+\end{tabular}]
+\end{haddockdesc}
+\begin{haddockdesc}
+\item[\begin{tabular}{@{}l}
+data Y
+\end{tabular}]
+\end{haddockdesc}
+\begin{haddockdesc}
+\item[\begin{tabular}{@{}l}
+data Z
+\end{tabular}]
+\end{haddockdesc}
+\section{Unboxed type constructors}
+\begin{haddockdesc}
+\item[\begin{tabular}{@{}l}
+unboxedUnit :: ({\char '43} {\char '43}) -> ({\char '43} {\char '43})
+\end{tabular}]
+\item[\begin{tabular}{@{}l}
+unboxedTuple :: ({\char '43} X, Y {\char '43}) -> ({\char '43} X, Y, Z {\char '43})
+\end{tabular}]
+\item[\begin{tabular}{@{}l}
+unboxedSum :: ({\char '43} X | Y {\char '43}) -> ({\char '43} X | Y | Z {\char '43})
+\end{tabular}]
+\end{haddockdesc}
diff --git a/latex-test/src/ConstructorArgs/ConstructorArgs.hs b/latex-test/src/ConstructorArgs/ConstructorArgs.hs
new file mode 100644
--- /dev/null
+++ b/latex-test/src/ConstructorArgs/ConstructorArgs.hs
@@ -0,0 +1,57 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE GADTs, PatternSynonyms #-}
+
+module ConstructorArgs (Foo(..), Boo(Foo, Foa, Fo, Fo'), pattern Bo, pattern Bo') where
+
+data Foo
+  = Rec             -- ^ doc on a record
+     { x :: String  -- ^ doc on the `String` field of `Rec`
+     , y :: String  -- ^ doc on the `String` field of `Rec`
+     }
+   | Baz Int String  -- ^ old prefix doc style
+   | Boa             -- ^ doc on the `Boa` constrictor
+       !Int          -- ^ doc on the `Int` field of `Boa`
+       !String       -- ^ doc on the `String` field of `Boa`
+   | Int :| String   -- ^ old infix doc style
+   | Int             -- ^ doc on the `Int` field of the `:*` constructor
+       :*            -- ^ doc on the `:*` constructor
+     String          -- ^ doc on the `String` field of the `:*` constructor
+
+infixr 1 `Foo`
+infixr 2 `Boa`
+infixr 3 :*
+
+data Boo where
+  -- | Info about a 'Foo'
+  Foo :: Int    -- ^ `Int` field of `Foo`
+      -> String -- ^ `String` field of `Foo`
+      -> Boo    -- ^ Make a `Boo`
+
+  -- | no argument docs GADT
+  Foa :: Int -> Boo
+
+infixr 4 `Boo`
+
+-- | Info about bundled 'Fo'
+pattern Fo :: Int    -- ^ an 'Int'
+           -> String -- ^ a 'String'
+           -> Boo    -- ^ a 'Boo'
+pattern Fo x y = Foo x y
+
+-- | Bundled and no argument docs
+pattern Fo' :: Boo
+pattern Fo' = Foo 1 "hi"
+
+infixr 5 `Fo`
+
+-- | Info about not-bundled 'Bo'
+pattern Bo :: Int    -- ^ an 'Int'
+           -> String -- ^ a 'String'
+           -> Boo -- ^ a 'Boo' pattern
+pattern Bo x y = Foo x y
+
+-- | Not bunded and no argument docs
+pattern Bo' :: Int -> String -> Boo
+pattern Bo' x y = Foo x y
+
+infixr 6 `Bo`
diff --git a/latex-test/src/DefaultSignatures/DefaultSignatures.hs b/latex-test/src/DefaultSignatures/DefaultSignatures.hs
new file mode 100644
--- /dev/null
+++ b/latex-test/src/DefaultSignatures/DefaultSignatures.hs
@@ -0,0 +1,20 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE DefaultSignatures #-}
+
+module DefaultSignatures where
+
+-- | Documentation for Foo.
+class Foo a where
+  -- | Documentation for bar and baz.
+  bar, baz :: a -> String
+
+  -- | Documentation for the default signature of bar.
+  default bar :: Show a => a -> String
+  bar = show
+
+  -- | Documentation for baz'.
+  baz' :: String -> a
+
+  -- | Documentation for the default signature of baz'.
+  default baz' :: Read a => String -> a
+  baz' = read
diff --git a/latex-test/src/Deprecated/Deprecated.hs b/latex-test/src/Deprecated/Deprecated.hs
new file mode 100644
--- /dev/null
+++ b/latex-test/src/Deprecated/Deprecated.hs
@@ -0,0 +1,8 @@
+{-# LANGUAGE Haskell2010 #-}
+module Deprecated where
+
+-- | Docs for something deprecated
+deprecated :: Int
+deprecated = 1
+
+{-# DEPRECATED deprecated "Don't use this" #-}
diff --git a/latex-test/src/Example/Example.hs b/latex-test/src/Example/Example.hs
new file mode 100644
--- /dev/null
+++ b/latex-test/src/Example/Example.hs
@@ -0,0 +1,12 @@
+{-# LANGUAGE Haskell2010 #-}
+module Example where
+
+-- | Example use.
+--
+-- >>> split 1
+-- ()
+--
+-- >>> split 2
+-- ()
+split :: Int -> ()
+split _ = ()
diff --git a/latex-test/src/GadtConstructorArgs/GadtConstructorArgs.hs b/latex-test/src/GadtConstructorArgs/GadtConstructorArgs.hs
new file mode 100644
--- /dev/null
+++ b/latex-test/src/GadtConstructorArgs/GadtConstructorArgs.hs
@@ -0,0 +1,14 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE GADTs #-}
+
+module GadtConstructorArgs (Boo(..)) where
+
+data Boo where
+  Fot :: { x :: Int  -- ^ an 'x'
+         , y :: Int  -- ^ a 'y'
+         } -> Boo
+
+  -- | Record GADT with docs
+  Fob :: { w :: Int  -- ^ a 'w'
+         , z :: Int  -- ^ a 'z'
+         } -> Boo    -- ^ a 'Boo'
diff --git a/latex-test/src/LinearTypes/LinearTypes.hs b/latex-test/src/LinearTypes/LinearTypes.hs
new file mode 100644
--- /dev/null
+++ b/latex-test/src/LinearTypes/LinearTypes.hs
@@ -0,0 +1,15 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE LinearTypes #-}
+module LinearTypes where
+
+-- | Does something unrestricted.
+unrestricted :: a -> b
+unrestricted = undefined
+
+-- | Does something linear.
+linear :: a %1 -> b
+linear = linear
+
+-- | Does something polymorphic.
+poly :: a %m -> b
+poly = poly
diff --git a/latex-test/src/NamespacedIdentifier/NamespacedIdentifier.hs b/latex-test/src/NamespacedIdentifier/NamespacedIdentifier.hs
new file mode 100644
--- /dev/null
+++ b/latex-test/src/NamespacedIdentifier/NamespacedIdentifier.hs
@@ -0,0 +1,14 @@
+{-# LANGUAGE Haskell2010 #-}
+module NamespacedIdentifiers where
+
+-- | A link to:
+--
+--   * the type t'Bar'
+--   * the constructor v'Bar'
+--   * the unimported but qualified type t'A.A'
+--   * the unimported but qualified value v'A.A'
+--
+data Foo = Bar
+
+-- | A link to the value v'Foo' (which shouldn't exist).
+data Bar
diff --git a/latex-test/src/Simple/Simple.hs b/latex-test/src/Simple/Simple.hs
new file mode 100644
--- /dev/null
+++ b/latex-test/src/Simple/Simple.hs
@@ -0,0 +1,6 @@
+{-# LANGUAGE Haskell2010 #-}
+module Simple (foo) where
+
+-- | This is foo.
+foo :: t
+foo = undefined
diff --git a/latex-test/src/TypeFamilies3/TypeFamilies3.hs b/latex-test/src/TypeFamilies3/TypeFamilies3.hs
new file mode 100644
--- /dev/null
+++ b/latex-test/src/TypeFamilies3/TypeFamilies3.hs
@@ -0,0 +1,22 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE TypeFamilies #-}
+
+module TypeFamilies3 where
+
+-- | A closed type family
+type family Foo a where
+  Foo () = Int
+  Foo _ = ()
+
+-- | An open family
+type family Bar a
+
+type instance Bar Int = ()
+type instance Bar () = Int
+
+-- | A data family
+data family Baz a
+
+data instance Baz () = Baz1
+data instance Baz Int = Baz2 Bool
+newtype instance Baz Double = Baz3 Float
diff --git a/latex-test/src/UnboxedStuff/UnboxedStuff.hs b/latex-test/src/UnboxedStuff/UnboxedStuff.hs
new file mode 100644
--- /dev/null
+++ b/latex-test/src/UnboxedStuff/UnboxedStuff.hs
@@ -0,0 +1,19 @@
+{-# LANGUAGE Haskell2010 #-}
+{-# LANGUAGE UnboxedSums, UnboxedTuples #-}
+module UnboxedStuff where
+
+data X
+data Y
+data Z
+
+-- * Unboxed type constructors
+
+unboxedUnit :: (# #) -> (# #)
+unboxedUnit  = undefined
+
+unboxedTuple :: (# X, Y #) -> (# X, Y, Z #)
+unboxedTuple = undefined 
+
+unboxedSum :: (# X | Y #) -> (# X | Y | Z #)
+unboxedSum = undefined 
+
diff --git a/latex/haddock.sty b/latex/haddock.sty
deleted file mode 100644
--- a/latex/haddock.sty
+++ /dev/null
@@ -1,57 +0,0 @@
-% Default Haddock style definitions.  To use your own style, invoke
-% Haddock with the option --latex-style=mystyle.
-
-\usepackage{tabulary} % see below
-
-% make hyperlinks in the PDF, and add an expandabale index
-\usepackage[pdftex,bookmarks=true]{hyperref}
-
-\newenvironment{haddocktitle}
-  {\begin{center}\bgroup\large\bfseries}
-  {\egroup\end{center}}
-\newenvironment{haddockprologue}{\vspace{1in}}{}
-
-\newcommand{\haddockmoduleheading}[1]{\chapter{\texttt{#1}}}
-
-\newcommand{\haddockbeginheader}{\hrulefill}
-\newcommand{\haddockendheader}{\noindent\hrulefill}
-
-% a little gap before the ``Methods'' header
-\newcommand{\haddockpremethods}{\vspace{2ex}}
-
-% inserted before \\begin{verbatim}
-\newcommand{\haddockverb}{\small}
-
-% an identifier: add an index entry
-\newcommand{\haddockid}[1]{\haddocktt{#1}\index{#1@\texttt{#1}}}
-
-% The tabulary environment lets us have a column that takes up ``the
-% rest of the space''.  Unfortunately it doesn't allow
-% the \end{tabulary} to be in the expansion of a macro, it must appear
-% literally in the document text, so Haddock inserts
-% the \end{tabulary} itself.
-\newcommand{\haddockbeginconstrs}{\begin{tabulary}{\linewidth}{@{}llJ@{}}}
-\newcommand{\haddockbeginargs}{\begin{tabulary}{\linewidth}{@{}llJ@{}}}
-
-\newcommand{\haddocktt}[1]{{\small \texttt{#1}}}
-\newcommand{\haddockdecltt}[1]{{\small\bfseries \texttt{#1}}}
-
-\makeatletter
-\newenvironment{haddockdesc}
-               {\list{}{\labelwidth\z@ \itemindent-\leftmargin
-                        \let\makelabel\haddocklabel}}
-               {\endlist}
-\newcommand*\haddocklabel[1]{\hspace\labelsep\haddockdecltt{#1}}
-\makeatother
-
-% after a declaration, start a new line for the documentation.
-% Otherwise, the documentation starts right after the declaration,
-% because we're using the list environment and the declaration is the
-% ``label''.  I tried making this newline part of the label, but
-% couldn't get that to work reliably (the space seemed to stretch
-% sometimes).
-\newcommand{\haddockbegindoc}{\hfill\\[1ex]}
-
-% spacing between paragraphs and no \parindent looks better
-\parskip=10pt plus2pt minus2pt
-\setlength{\parindent}{0cm}
diff --git a/src/Documentation/Haddock.hs b/src/Documentation/Haddock.hs
deleted file mode 100644
--- a/src/Documentation/Haddock.hs
+++ /dev/null
@@ -1,77 +0,0 @@
------------------------------------------------------------------------------
--- |
--- Module      :  Documentation.Haddock
--- Copyright   :  (c) David Waern 2010
--- License     :  BSD-like
---
--- Maintainer  :  haddock@projects.haskellorg
--- Stability   :  experimental
--- Portability :  portable
---
--- The Haddock API: A rudimentory, highly experimental API exposing some of
--- the internals of Haddock. Don't expect it to be stable.
------------------------------------------------------------------------------
-module Documentation.Haddock (
-
-  -- * Interface
-  Interface(..),
-  InstalledInterface(..),
-  createInterfaces,
-  processModules,
-
-  -- * Export items & declarations
-  ExportItem(..),
-  Decl,
-  DeclInfo,
-  DocForDecl,
-  FnArgsDoc,
-
-  -- * Cross-referencing
-  LinkEnv,
-  DocName(..),
-
-  -- * Instances
-  DocInstance,
-  InstHead,
-
-  -- * Documentation comments
-  Doc(..),
-  Example(..),
-  DocMarkup(..),
-  HaddockModInfo(..),
-  markup,
-
-  -- * Interface files
-  InterfaceFile(..),
-  readInterfaceFile,
-  nameCacheFromGhc,
-  freshNameCache,
-  NameCacheAccessor,
-
-  -- * Flags and options
-  Flag(..),
-  DocOption(..)
-
-) where
-
-
-import Haddock.InterfaceFile
-import Haddock.Interface
-import Haddock.Types
-import Haddock.Options
-import Haddock.Utils
-import Main
-
-
--- | Create 'Interface' structures from a given list of Haddock command-line
--- flags and file or module names (as accepted by 'haddock' executable).  Flags
--- that control documentation generation or show help or version information
--- are ignored.
-createInterfaces
-  :: [Flag]         -- ^ A list of command-line flags
-  -> [String]       -- ^ File or module names
-  -> IO [Interface] -- ^ Resulting list of interfaces
-createInterfaces flags modules = do
-  (_, ifaces, _) <- readPackagesAndProcessModules flags modules
-  return ifaces
-
diff --git a/src/Haddock/Backends/HaddockDB.hs b/src/Haddock/Backends/HaddockDB.hs
deleted file mode 100644
--- a/src/Haddock/Backends/HaddockDB.hs
+++ /dev/null
@@ -1,170 +0,0 @@
------------------------------------------------------------------------------
--- |
--- Module      :  Haddock.Backends.HaddockDB
--- Copyright   :  (c) Simon Marlow 2003
--- License     :  BSD-like
---
--- Maintainer  :  haddock@projects.haskell.org
--- Stability   :  experimental
--- Portability :  portable
------------------------------------------------------------------------------
-module Haddock.Backends.HaddockDB (ppDocBook) where
-
-{-
-import HaddockTypes
-import HaddockUtil
-import HsSyn2
-
-import Text.PrettyPrint
--}
-
------------------------------------------------------------------------------
--- Printing the results in DocBook format
-
-ppDocBook :: a
-ppDocBook = error "not working"
-{-
-ppDocBook :: FilePath -> [(Module, Interface)] -> String
-ppDocBook odir mods = render (ppIfaces mods)
-
-ppIfaces mods
-  =  text "<!DOCTYPE BOOK PUBLIC \"-//OASIS//DTD DocBook V3.1//EN\" ["
-  $$ text "]>"
-  $$ text "<book>"
-  $$ text "<bookinfo>"
-  $$ text "<author><othername>HaskellDoc version 0.0</othername></author>"
-  $$ text "</bookinfo>"
-  $$ text "<article>"
-  $$ vcat (map do_mod mods)
-  $$ text "</article></book>"
-  where
-     do_mod (Module mod, iface)
-        =  text "<sect1 id=\"sec-" <> text mod <> text "\">"
-        $$ text "<title><literal>" 
-	   <> text mod
-	   <> text "</literal></title>"
-	$$ text "<indexterm><primary><literal>"
-	   <> text mod
-	   <> text "</literal></primary></indexterm>"
-	$$ text "<variablelist>"
-	$$ vcat (map (do_export mod) (eltsFM (iface_decls iface)))
-	$$ text "</variablelist>"
-	$$ text "</sect1>"
- 
-     do_export mod decl | (nm:_) <- declBinders decl
-	=  text "<varlistentry id=" <> ppLinkId mod nm <> char '>'
-	$$ text "<term><literal>" 
-		<> do_decl decl
-		<> text "</literal></term>"
-	$$ text "<listitem>"
-	$$ text "<para>"
-	$$ text "</para>"
-	$$ text "</listitem>"
-	$$ text "</varlistentry>"
-     do_export _ _ = empty
-
-     do_decl (HsTypeSig _ [nm] ty _) 
-	=  ppHsName nm <> text " :: " <> ppHsType ty
-     do_decl (HsTypeDecl _ nm args ty _)
-	=  hsep ([text "type", ppHsName nm ]
-		 ++ map ppHsName args 
-		 ++ [equals, ppHsType ty])
-     do_decl (HsNewTypeDecl loc ctx nm args con drv _)
-	= hsep ([text "data", ppHsName nm] -- data, not newtype
-		++ map ppHsName args
-		) <+> equals <+> ppHsConstr con -- ToDo: derivings
-     do_decl (HsDataDecl loc ctx nm args cons drv _)
-	= hsep ([text "data", {-ToDo: context-}ppHsName nm]
-	        ++ map ppHsName args)
-            <+> vcat (zipWith (<+>) (equals : repeat (char '|'))
-                                    (map ppHsConstr cons))
-     do_decl (HsClassDecl loc ty fds decl _)
-	= hsep [text "class", ppHsType ty]
-     do_decl decl
-	= empty
-
-ppHsConstr :: HsConDecl -> Doc
-ppHsConstr (HsRecDecl pos name tvs ctxt fieldList maybe_doc) =
-	 ppHsName name
-	 <> (braces . hsep . punctuate comma . map ppField $ fieldList)
-ppHsConstr (HsConDecl pos name tvs ctxt typeList maybe_doc) = 
-	 hsep (ppHsName name : map ppHsBangType typeList)
-
-ppField (HsFieldDecl ns ty doc)
-   = hsep (punctuate comma (map ppHsName ns) ++
-	 	[text "::", ppHsBangType ty])
-
-ppHsBangType :: HsBangType -> Doc
-ppHsBangType (HsBangedTy ty) = char '!' <> ppHsType ty
-ppHsBangType (HsUnBangedTy ty) = ppHsType ty
-
-ppHsContext :: HsContext -> Doc
-ppHsContext []      = empty
-ppHsContext context = parenList (map (\ (a,b) -> ppHsQName a <+> 
-					 hsep (map ppHsAType b)) context)
-
-ppHsType :: HsType -> Doc
-ppHsType (HsForAllType Nothing context htype) =
-     hsep [ ppHsContext context, text "=>", ppHsType htype]
-ppHsType (HsForAllType (Just tvs) [] htype) =
-     hsep (text "forall" : map ppHsName tvs ++ text "." : [ppHsType htype])
-ppHsType (HsForAllType (Just tvs) context htype) =
-     hsep (text "forall" : map ppHsName tvs ++ text "." : 
-	   ppHsContext context : text "=>" : [ppHsType htype])
-ppHsType (HsTyFun a b) = fsep [ppHsBType a, text "-&gt;", ppHsType b]
-ppHsType (HsTyIP n t)  = fsep [(char '?' <> ppHsName n), text "::", ppHsType t]
-ppHsType t = ppHsBType t
-
-ppHsBType (HsTyApp (HsTyCon (Qual (Module "Prelude") (HsTyClsName (HsSpecial "[]")))) b )
-  = brackets $ ppHsType b
-ppHsBType (HsTyApp a b) = fsep [ppHsBType a, ppHsAType b]
-ppHsBType t = ppHsAType t
-
-ppHsAType :: HsType -> Doc
-ppHsAType (HsTyTuple True l)  = parenList . map ppHsType $ l
-ppHsAType (HsTyTuple False l) = ubxParenList . map ppHsType $ l
--- special case
-ppHsAType (HsTyApp (HsTyCon (Qual (Module "Prelude") (HsTyClsName (HsSpecial "[]")))) b )
-  = brackets $ ppHsType b
-ppHsAType (HsTyVar name) = ppHsName name
-ppHsAType (HsTyCon name) = ppHsQName name
-ppHsAType t = parens $ ppHsType t
-
-ppHsQName :: HsQName -> Doc
-ppHsQName (UnQual str)			= ppHsName str
-ppHsQName n@(Qual (Module mod) str)
-	 | n == unit_con_name		= ppHsName str
-	 | isSpecial str 		= ppHsName str
-	 | otherwise 
-		=  text "<link linkend=" <> ppLinkId mod str <> char '>'
-		<> ppHsName str
-		<> text "</link>"
-
-isSpecial (HsTyClsName id) | HsSpecial _ <- id = True
-isSpecial (HsVarName id) | HsSpecial _ <- id = True
-isSpecial _ = False
-
-ppHsName :: HsName -> Doc
-ppHsName (HsTyClsName id) = ppHsIdentifier id
-ppHsName (HsVarName id) = ppHsIdentifier id
-
-ppHsIdentifier :: HsIdentifier -> Doc
-ppHsIdentifier (HsIdent str)	= text str
-ppHsIdentifier (HsSymbol str) = text str
-ppHsIdentifier (HsSpecial str) = text str
-
-ppLinkId :: String -> HsName -> Doc
-ppLinkId mod str
-  = hcat [char '\"', text mod, char '.', ppHsName str, char '\"']
-
--- -----------------------------------------------------------------------------
--- * Misc
-
-parenList :: [Doc] -> Doc
-parenList = parens . fsep . punctuate comma
-
-ubxParenList :: [Doc] -> Doc
-ubxParenList = ubxparens . fsep . punctuate comma
-
-ubxparens p = text "(#" <> p <> text "#)"
--}
diff --git a/src/Haddock/Backends/Hoogle.hs b/src/Haddock/Backends/Hoogle.hs
deleted file mode 100644
--- a/src/Haddock/Backends/Hoogle.hs
+++ /dev/null
@@ -1,312 +0,0 @@
------------------------------------------------------------------------------
--- |
--- Module      :  Haddock.Backends.Hoogle
--- Copyright   :  (c) Neil Mitchell 2006-2008
--- License     :  BSD-like
---
--- Maintainer  :  haddock@projects.haskell.org
--- Stability   :  experimental
--- Portability :  portable
---
--- Write out Hoogle compatible documentation
--- http://www.haskell.org/hoogle/
------------------------------------------------------------------------------
-module Haddock.Backends.Hoogle ( 
-    ppHoogle
-  ) where
-
-
-import Haddock.GhcUtils
-import Haddock.Types
-import Haddock.Utils hiding (out)
-import GHC
-import Outputable
-
-import Data.Char
-import Data.List
-import Data.Maybe
-import System.FilePath
-import System.IO
-
-prefix :: [String]
-prefix = ["-- Hoogle documentation, generated by Haddock"
-         ,"-- See Hoogle, http://www.haskell.org/hoogle/"
-         ,""]
-
-
-ppHoogle :: String -> String -> String -> Maybe (Doc RdrName) -> [Interface] -> FilePath -> IO ()
-ppHoogle package version synopsis prologue ifaces odir = do
-    let filename = package ++ ".txt"
-        contents = prefix ++
-                   docWith (drop 2 $ dropWhile (/= ':') synopsis) prologue ++
-                   ["@package " ++ package] ++
-                   ["@version " ++ version | version /= ""] ++
-                   concat [ppModule i | i <- ifaces, OptHide `notElem` ifaceOptions i]
-    h <- openFile (odir </> filename) WriteMode
-    hSetEncoding h utf8
-    hPutStr h (unlines contents)
-    hClose h
-
-ppModule :: Interface -> [String]
-ppModule iface = "" : doc (ifaceDoc iface) ++
-                 ["module " ++ moduleString (ifaceMod iface)] ++
-                 concatMap ppExport (ifaceExportItems iface) ++
-                 concatMap ppInstance (ifaceInstances iface)
-
-
----------------------------------------------------------------------
--- Utility functions
-
-dropHsDocTy :: HsType a -> HsType a
-dropHsDocTy = f
-    where
-        g (L src x) = L src (f x)
-        f (HsForAllTy a b c d) = HsForAllTy a b c (g d)
-        f (HsBangTy a b) = HsBangTy a (g b)
-        f (HsAppTy a b) = HsAppTy (g a) (g b)
-        f (HsFunTy a b) = HsFunTy (g a) (g b)
-        f (HsListTy a) = HsListTy (g a)
-        f (HsPArrTy a) = HsPArrTy (g a)
-        f (HsTupleTy a b) = HsTupleTy a (map g b)
-        f (HsOpTy a b c) = HsOpTy (g a) b (g c)
-        f (HsParTy a) = HsParTy (g a)
-        f (HsKindSig a b) = HsKindSig (g a) b
-        f (HsDocTy a _) = f $ unL a
-        f x = x
-
-outHsType :: OutputableBndr a => HsType a -> String
-outHsType = out . dropHsDocTy
-
-
-makeExplicit :: HsType a -> HsType a
-makeExplicit (HsForAllTy _ a b c) = HsForAllTy Explicit a b c
-makeExplicit x = x
-
-makeExplicitL :: LHsType a -> LHsType a
-makeExplicitL (L src x) = L src (makeExplicit x)
-
-
-dropComment :: String -> String
-dropComment (' ':'-':'-':' ':_) = []
-dropComment (x:xs) = x : dropComment xs
-dropComment [] = []
-
-
-out :: Outputable a => a -> String
-out = f . unwords . map (dropWhile isSpace) . lines . showSDocUnqual . ppr
-    where
-        f xs | " <document comment>" `isPrefixOf` xs = f $ drop 19 xs
-        f (x:xs) = x : f xs
-        f [] = []
-
-
-operator :: String -> String
-operator (x:xs) | not (isAlphaNum x) && x `notElem` "_' ([{" = "(" ++ x:xs ++ ")"
-operator x = x
-
-
----------------------------------------------------------------------
--- How to print each export
-
-ppExport :: ExportItem Name -> [String]
-ppExport (ExportDecl decl dc subdocs _) = doc (fst dc) ++ f (unL decl)
-    where
-        f (TyClD d@TyData{}) = ppData d subdocs
-        f (TyClD d@ClassDecl{}) = ppClass d
-        f (TyClD d@TySynonym{}) = ppSynonym d
-        f (ForD (ForeignImport name typ _)) = ppSig $ TypeSig [name] typ
-        f (ForD (ForeignExport name typ _)) = ppSig $ TypeSig [name] typ
-        f (SigD sig) = ppSig sig
-        f _ = []
-ppExport _ = []
-
-
-ppSig :: Sig Name -> [String]
-ppSig (TypeSig names sig) = [operator prettyNames ++ " :: " ++ outHsType typ]
-    where
-        prettyNames = concat . intersperse ", " $ map out names
-        typ = case unL sig of
-                   HsForAllTy Explicit a b c -> HsForAllTy Implicit a b c
-                   x -> x
-ppSig _ = []
-
-
-ppSynonym :: TyClDecl Name -> [String]
-ppSynonym x = [out x]
-
-
--- note: does not yet output documentation for class methods
-ppClass :: TyClDecl Name -> [String]
-ppClass x = out x{tcdSigs=[]} :
-            concatMap (ppSig . addContext . unL) (tcdSigs x)
-    where
-        addContext (TypeSig name (L l sig)) = TypeSig name (L l $ f sig)
-        addContext _ = error "expected TypeSig"
-
-        f (HsForAllTy a b con d) = HsForAllTy a b (reL $ context : unL con) d
-        f t = HsForAllTy Implicit [] (reL [context]) (reL t)
-
-        context = reL $ HsClassP (unL $ tcdLName x)
-            (map (reL . HsTyVar . hsTyVarName . unL) (tcdTyVars x))
-
-
-ppInstance :: Instance -> [String]
-ppInstance x = [dropComment $ out x]
-
-
-ppData :: TyClDecl Name -> [(Name, DocForDecl Name)] -> [String]
-ppData x subdocs = showData x{tcdCons=[],tcdDerivs=Nothing} :
-                   concatMap (ppCtor x subdocs . unL) (tcdCons x)
-    where
-        -- GHC gives out "data Bar =", we want to delete the equals
-        -- also writes data : a b, when we want data (:) a b
-        showData d = unwords $ map f $ if last xs == "=" then init xs else xs
-            where
-                xs = words $ out d
-                nam = out $ tcdLName d
-                f w = if w == nam then operator nam else w
-
--- | for constructors, and named-fields...
-lookupCon :: [(Name, DocForDecl Name)] -> Located Name -> Maybe (Doc Name)
-lookupCon subdocs (L _ name) = case lookup name subdocs of
-  Just (d, _) -> d
-  _ -> Nothing
-
-ppCtor :: TyClDecl Name -> [(Name, DocForDecl Name)] -> ConDecl Name -> [String]
-ppCtor dat subdocs con = doc (lookupCon subdocs (con_name con))
-                         ++ f (con_details con)
-    where
-        f (PrefixCon args) = [typeSig name $ args ++ [resType]]
-        f (InfixCon a1 a2) = f $ PrefixCon [a1,a2]
-        f (RecCon recs) = f (PrefixCon $ map cd_fld_type recs) ++ concat
-                          [doc (lookupCon subdocs (cd_fld_name r)) ++
-                           [out (unL $ cd_fld_name r) `typeSig` [resType, cd_fld_type r]]
-                          | r <- recs]
-
-        funs = foldr1 (\x y -> reL $ HsFunTy (makeExplicitL x) (makeExplicitL y))
-        apps = foldl1 (\x y -> reL $ HsAppTy x y)
-
-        typeSig nm flds = operator nm ++ " :: " ++ outHsType (makeExplicit $ unL $ funs flds)
-        name = out $ unL $ con_name con
-
-        resType = case con_res con of
-            ResTyH98 -> apps $ map (reL . HsTyVar) $ unL (tcdLName dat) : [hsTyVarName v | v@UserTyVar {} <- map unL $ tcdTyVars dat]
-            ResTyGADT x -> x
-
-
----------------------------------------------------------------------
--- DOCUMENTATION
-
-doc :: Outputable o => Maybe (Doc o) -> [String]
-doc = docWith ""
-
-
-docWith :: Outputable o => String -> Maybe (Doc o) -> [String]
-docWith [] Nothing = []
-docWith header d = ("":) $ zipWith (++) ("-- | " : repeat "--   ") $
-    [header | header /= ""] ++ ["" | header /= "" && isJust d] ++
-    maybe [] (showTags . markup markupTag) d
-
-
-data Tag = TagL Char [Tags] | TagP Tags | TagPre Tags | TagInline String Tags | Str String
-           deriving Show
-
-type Tags = [Tag]
-
-box :: (a -> b) -> a -> [b]
-box f x = [f x]
-
-str :: String -> [Tag]
-str a = [Str a]
-
--- want things like paragraph, pre etc to be handled by blank lines in the source document
--- and things like \n and \t converted away
--- much like blogger in HTML mode
--- everything else wants to be included as tags, neatly nested for some (ul,li,ol)
--- or inlne for others (a,i,tt)
--- entities (&,>,<) should always be appropriately escaped
-
-markupTag :: Outputable o => DocMarkup o [Tag]
-markupTag = Markup {
-  markupParagraph     = box TagP,
-  markupEmpty         = str "",
-  markupString        = str,
-  markupAppend        = (++),
-  markupIdentifier    = box (TagInline "a") . str . out . head,
-  markupModule        = box (TagInline "a") . str,
-  markupEmphasis      = box (TagInline "i"),
-  markupMonospaced    = box (TagInline "tt"),
-  markupPic           = const $ str " ",
-  markupUnorderedList = box (TagL 'u'),
-  markupOrderedList   = box (TagL 'o'),
-  markupDefList       = box (TagL 'u') . map (\(a,b) -> TagInline "i" a : Str " " : b),
-  markupCodeBlock     = box TagPre,
-  markupURL           = box (TagInline "a") . str,
-  markupAName         = const $ str "",
-  markupExample       = box TagPre . str . unlines . map exampleToString
-  }
-
-
-showTags :: [Tag] -> [String]
-showTags = intercalate [""] . map showBlock
-
-
-showBlock :: Tag -> [String]
-showBlock (TagP xs) = showInline xs
-showBlock (TagL t xs) = ['<':t:"l>"] ++ mid ++ ['<':'/':t:"l>"]
-    where mid = concatMap (showInline . box (TagInline "li")) xs
-showBlock (TagPre xs) = ["<pre>"] ++ showPre xs ++ ["</pre>"]
-showBlock x = showInline [x]
-
-
-asInline :: Tag -> Tags
-asInline (TagP xs) = xs
-asInline (TagPre xs) = [TagInline "pre" xs]
-asInline (TagL t xs) = [TagInline (t:"l") $ map (TagInline "li") xs]
-asInline x = [x]
-
-
-showInline :: [Tag] -> [String]
-showInline = unwordsWrap 70 . words . concatMap f
-    where
-        fs = concatMap f
-        f (Str x) = escape x
-        f (TagInline s xs) = "<"++s++">" ++ (if s == "li" then trim else id) (fs xs) ++ "</"++s++">"
-        f x = fs $ asInline x
-
-        trim = dropWhile isSpace . reverse . dropWhile isSpace . reverse
-
-
-showPre :: [Tag] -> [String]
-showPre = trimFront . trimLines . lines . concatMap f
-    where
-        trimLines = dropWhile null . reverse . dropWhile null . reverse
-        trimFront xs = map (drop i) xs
-            where
-                ns = [length a | x <- xs, let (a,b) = span isSpace x, b /= ""]
-                i = if null ns then 0 else minimum ns
-
-        fs = concatMap f
-        f (Str x) = escape x
-        f (TagInline s xs) = "<"++s++">" ++ fs xs ++ "</"++s++">"
-        f x = fs $ asInline x
-
-
-unwordsWrap :: Int -> [String] -> [String]
-unwordsWrap n = f n []
-    where
-        f _ s [] = [g s | s /= []]
-        f i s (x:xs) | nx > i = g s : f (n - nx - 1) [x] xs
-                     | otherwise = f (i - nx - 1) (x:s) xs
-            where nx = length x
-
-        g = unwords . reverse
-
-
-escape :: String -> String
-escape = concatMap f
-    where
-        f '<' = "&lt;"
-        f '>' = "&gt;"
-        f '&' = "&amp;"
-        f x = [x]
diff --git a/src/Haddock/Backends/LaTeX.hs b/src/Haddock/Backends/LaTeX.hs
deleted file mode 100644
--- a/src/Haddock/Backends/LaTeX.hs
+++ /dev/null
@@ -1,1163 +0,0 @@
-{-# OPTIONS_GHC -fno-warn-name-shadowing #-}
------------------------------------------------------------------------------
--- |
--- Module      :  Haddock.Backends.LaTeX
--- Copyright   :  (c) Simon Marlow 2010
--- License     :  BSD-like
---
--- Maintainer  :  haddock@projects.haskell.org
--- Stability   :  experimental
--- Portability :  portable
------------------------------------------------------------------------------
-module Haddock.Backends.LaTeX (
-  ppLaTeX
-) where
-
-
-import Haddock.Types
-import Haddock.Utils
-import Haddock.GhcUtils
-import Pretty hiding (Doc)
-import qualified Pretty
-
-import GHC
-import OccName
-import Name                 ( isTyConName, nameOccName )
-import RdrName              ( rdrNameOcc, isRdrTc )
-import BasicTypes           ( IPName(..), Boxity(..) )
-import Outputable           ( Outputable, ppr, showSDoc )
-import FastString           ( unpackFS, unpackLitString )
-
-import qualified Data.Map as Map
-import System.Directory
-import System.FilePath
-import Data.Char
-import Control.Monad
-import Data.Maybe
-import Data.List
--- import Debug.Trace
-
-{- SAMPLE OUTPUT
-
-\haddockmoduleheading{\texttt{Data.List}}
-\hrulefill
-{\haddockverb\begin{verbatim}
-module Data.List (
-    (++),  head,  last,  tail,  init,  null,  length,  map,  reverse,
-  ) where\end{verbatim}}
-\hrulefill
-
-\section{Basic functions}
-\begin{haddockdesc}
-\item[\begin{tabular}{@{}l}
-head\ ::\ {\char 91}a{\char 93}\ ->\ a
-\end{tabular}]\haddockbegindoc
-Extract the first element of a list, which must be non-empty.
-\par
-
-\end{haddockdesc}
-\begin{haddockdesc}
-\item[\begin{tabular}{@{}l}
-last\ ::\ {\char 91}a{\char 93}\ ->\ a
-\end{tabular}]\haddockbegindoc
-Extract the last element of a list, which must be finite and non-empty.
-\par
-
-\end{haddockdesc}
--}
-
-
-{- TODO
- * don't forget fixity!!
--}
-
-ppLaTeX :: String                       -- Title
-        -> Maybe String                 -- Package name
-        -> [Interface]
-        -> FilePath                     -- destination directory
-        -> Maybe (Doc GHC.RdrName)      -- prologue text, maybe
-        -> Maybe String                 -- style file
-        -> FilePath
-        -> IO ()
-
-ppLaTeX title packageStr visible_ifaces odir prologue maybe_style libdir
- = do
-   createDirectoryIfMissing True odir
-   when (isNothing maybe_style) $
-     copyFile (libdir </> "latex" </> haddockSty) (odir </> haddockSty)
-   ppLaTeXTop title packageStr odir prologue maybe_style visible_ifaces
-   mapM_ (ppLaTeXModule title odir) visible_ifaces
-
-
-haddockSty :: FilePath
-haddockSty = "haddock.sty"
-
-
-type LaTeX = Pretty.Doc
-
-
-ppLaTeXTop
-   :: String
-   -> Maybe String
-   -> FilePath
-   -> Maybe (Doc GHC.RdrName)
-   -> Maybe String
-   -> [Interface]
-   -> IO ()
-
-ppLaTeXTop doctitle packageStr odir prologue maybe_style ifaces = do
-
-  let tex = vcat [
-        text "\\documentclass{book}",
-        text "\\usepackage" <> braces (maybe (text "haddock") text maybe_style),
-        text "\\begin{document}",
-        text "\\begin{titlepage}",
-        text "\\begin{haddocktitle}",
-        text doctitle,
-        text "\\end{haddocktitle}",
-        case prologue of
-           Nothing -> empty
-           Just d  -> vcat [text "\\begin{haddockprologue}",
-                            rdrDocToLaTeX d,
-                            text "\\end{haddockprologue}"],
-        text "\\end{titlepage}",
-        text "\\tableofcontents",
-        vcat [ text "\\input" <> braces (text mdl) | mdl <- mods ],
-        text "\\end{document}"
-        ]
-
-      mods = sort (map (moduleBasename.ifaceMod) ifaces)
-
-      filename = odir </> (fromMaybe "haddock" packageStr <.> "tex")
-
-  writeFile filename (render tex)
-
-
-ppLaTeXModule :: String -> FilePath -> Interface -> IO ()
-ppLaTeXModule _title odir iface = do
-  createDirectoryIfMissing True odir
-  let
-      mdl = ifaceMod iface
-      mdl_str = moduleString mdl
-
-      exports = ifaceRnExportItems iface
-
-      tex = vcat [
-        text "\\haddockmoduleheading" <> braces (text mdl_str),
-        text "\\label{module:" <> text mdl_str <> char '}',
-        text "\\haddockbeginheader",
-        verb $ vcat [
-           text "module" <+> text mdl_str <+> lparen,
-           text "    " <> fsep (punctuate (text ", ") $
-                               map exportListItem $
-                               filter forSummary exports),
-           text "  ) where"
-         ],
-        text "\\haddockendheader" $$ text "",
-        description,
-        body
-       ]
-
-      description
-          = case ifaceRnDoc iface of
-              Nothing -> empty
-              Just doc -> docToLaTeX doc
-
-      body = processExports exports
-  --
-  writeFile (odir </> moduleLaTeXFile mdl) (fullRender PageMode 80 1 string_txt "" tex)
-
-
-string_txt :: TextDetails -> String -> String
-string_txt (Chr c)   s  = c:s
-string_txt (Str s1)  s2 = s1 ++ s2
-string_txt (PStr s1) s2 = unpackFS s1 ++ s2
-string_txt (LStr s1 _) s2 = unpackLitString s1 ++ s2
-
-
-exportListItem :: ExportItem DocName -> LaTeX
-exportListItem (ExportDecl decl _doc subdocs _insts)
-  = sep (punctuate comma . map ppDocBinder $ declNames decl) <>
-     case subdocs of
-       [] -> empty
-       _  -> parens (sep (punctuate comma (map (ppDocBinder . fst) subdocs)))
-exportListItem (ExportNoDecl y [])
-  = ppDocBinder y
-exportListItem (ExportNoDecl y subs)
-  = ppDocBinder y <> parens (sep (punctuate comma (map ppDocBinder subs)))
-exportListItem (ExportModule mdl)
-  = text "module" <+> text (moduleString mdl)
-exportListItem _
-  = error "exportListItem"
-
-
--- Deal with a group of undocumented exports together, to avoid lots
--- of blank vertical space between them.
-processExports :: [ExportItem DocName] -> LaTeX
-processExports [] = empty
-processExports (decl : es)
-  | Just sig <- isSimpleSig decl
-  = multiDecl [ ppTypeSig (map getName names) typ False
-              | (names,typ) <- sig:sigs ] $$
-    processExports es'
-  where (sigs, es') = spanWith isSimpleSig es
-processExports (ExportModule mdl : es)
-  = declWithDoc (vcat [ text "module" <+> text (moduleString m) | m <- mdl:mdls ]) Nothing $$
-    processExports es'
-  where (mdls, es') = spanWith isExportModule es
-processExports (e : es) =
-  processExport e $$ processExports es
-
-
-isSimpleSig :: ExportItem DocName -> Maybe ([DocName], HsType DocName)
-isSimpleSig (ExportDecl (L _ (SigD (TypeSig lnames (L _ t))))
-                        (Nothing, argDocs) _ _)
-  | Map.null argDocs = Just (map unLoc lnames, t)
-isSimpleSig _ = Nothing
-
-
-isExportModule :: ExportItem DocName -> Maybe Module
-isExportModule (ExportModule m) = Just m
-isExportModule _ = Nothing
-
-
-processExport :: ExportItem DocName -> LaTeX
-processExport (ExportGroup lev _id0 doc)
-  = ppDocGroup lev (docToLaTeX doc)
-processExport (ExportDecl decl doc subdocs insts)
-  = ppDecl decl doc insts subdocs
-processExport (ExportNoDecl y [])
-  = ppDocName y
-processExport (ExportNoDecl y subs)
-  = ppDocName y <> parens (sep (punctuate comma (map ppDocName subs)))
-processExport (ExportModule mdl)
-  = declWithDoc (text "module" <+> text (moduleString mdl)) Nothing
-processExport (ExportDoc doc)
-  = docToLaTeX doc
-
-
-ppDocGroup :: Int -> LaTeX -> LaTeX
-ppDocGroup lev doc = sec lev <> braces doc
-  where sec 1 = text "\\section"
-        sec 2 = text "\\subsection"
-        sec 3 = text "\\subsubsection"
-        sec _ = text "\\paragraph"
-
-
-declNames :: LHsDecl DocName -> [DocName]
-declNames (L _ decl) = case decl of
-  TyClD d  -> [unLoc $ tcdLName d]
-  SigD (TypeSig lnames _) -> map unLoc lnames
-  _ -> error "declaration not supported by declNames"
-
-
-forSummary :: (ExportItem DocName) -> Bool
-forSummary (ExportGroup _ _ _) = False
-forSummary (ExportDoc _)       = False
-forSummary _                    = True
-
-
-moduleLaTeXFile :: Module -> FilePath
-moduleLaTeXFile mdl = moduleBasename mdl ++ ".tex"
-
-
-moduleBasename :: Module -> FilePath
-moduleBasename mdl = map (\c -> if c == '.' then '-' else c)
-                         (moduleNameString (moduleName mdl))
-
-
--------------------------------------------------------------------------------
--- * Decls
--------------------------------------------------------------------------------
-
-
-ppDecl :: LHsDecl DocName
-       -> DocForDecl DocName
-       -> [DocInstance DocName]
-       -> [(DocName, DocForDecl DocName)]
-       -> LaTeX
-
-ppDecl (L loc decl) (mbDoc, fnArgsDoc) instances subdocs = case decl of
-  TyClD d@(TyFamily {})          -> ppTyFam False loc mbDoc d unicode
-  TyClD d@(TyData {})
-    | Nothing <- tcdTyPats d     -> ppDataDecl instances subdocs loc mbDoc d unicode
-    | Just _  <- tcdTyPats d     -> ppDataInst loc mbDoc d
-  TyClD d@(TySynonym {})
-    | Nothing <- tcdTyPats d     -> ppTySyn loc (mbDoc, fnArgsDoc) d unicode
-    | Just _  <- tcdTyPats d     -> ppTyInst False loc mbDoc d unicode
-  TyClD d@(ClassDecl {})         -> ppClassDecl instances loc mbDoc subdocs d unicode
-  SigD (TypeSig lnames (L _ t))  -> ppFunSig loc (mbDoc, fnArgsDoc) (map unLoc lnames) t unicode
-  ForD d                         -> ppFor loc (mbDoc, fnArgsDoc) d unicode
-  InstD _                        -> empty
-  _                              -> error "declaration not supported by ppDecl"
-  where
-    unicode = False
-
-
-ppTyFam :: Bool -> SrcSpan -> Maybe (Doc DocName) ->
-              TyClDecl DocName -> Bool -> LaTeX
-ppTyFam _ _ _ _ _ =
-  error "type family declarations are currently not supported by --latex"
-
-
-ppDataInst :: a
-ppDataInst =
-  error "data instance declarations are currently not supported by --latex"
-
-
-ppTyInst :: Bool -> SrcSpan -> Maybe (Doc DocName) ->
-            TyClDecl DocName -> Bool -> LaTeX
-ppTyInst _ _ _ _ _ =
-  error "type instance declarations are currently not supported by --latex"
-
-
-ppFor :: SrcSpan -> DocForDecl DocName -> ForeignDecl DocName -> Bool -> LaTeX
-ppFor _ _ _ _ =
-  error "foreign declarations are currently not supported by --latex"
-
-
--------------------------------------------------------------------------------
--- * Type Synonyms
--------------------------------------------------------------------------------
-
-
--- we skip type patterns for now
-ppTySyn :: SrcSpan -> DocForDecl DocName -> TyClDecl DocName -> Bool -> LaTeX
-
-ppTySyn loc doc (TySynonym (L _ name) ltyvars _ ltype) unicode
-  = ppTypeOrFunSig loc [name] (unLoc ltype) doc (full, hdr, char '=') unicode
-  where
-    hdr  = hsep (keyword "type" : ppDocBinder name : ppTyVars ltyvars)
-    full = hdr <+> char '=' <+> ppLType unicode ltype
-
-ppTySyn _ _ _ _ = error "declaration not supported by ppTySyn"
-
-
--------------------------------------------------------------------------------
--- * Function signatures
--------------------------------------------------------------------------------
-
-
-ppFunSig :: SrcSpan -> DocForDecl DocName -> [DocName] -> HsType DocName
-         -> Bool -> LaTeX
-ppFunSig loc doc docnames typ unicode =
-  ppTypeOrFunSig loc docnames typ doc
-    ( ppTypeSig names typ False
-    , hsep . punctuate comma $ map ppSymName names
-    , dcolon unicode)
-    unicode
- where
-   names = map getName docnames
-
-
-ppTypeOrFunSig :: SrcSpan -> [DocName] -> HsType DocName
-               -> DocForDecl DocName -> (LaTeX, LaTeX, LaTeX)
-               -> Bool -> LaTeX
-ppTypeOrFunSig _ _ typ (doc, argDocs) (pref1, pref2, sep0)
-               unicode
-  | Map.null argDocs =
-      declWithDoc pref1 (fmap docToLaTeX doc)
-  | otherwise        =
-      declWithDoc pref2 $ Just $
-        text "\\haddockbeginargs" $$
-        do_args 0 sep0 typ $$
-        text "\\end{tabulary}\\par" $$
-        maybe empty docToLaTeX doc
-  where
-     do_largs n leader (L _ t) = do_args n leader t
-
-     arg_doc n = rDoc (Map.lookup n argDocs)
-
-     do_args :: Int -> LaTeX -> (HsType DocName) -> LaTeX
-     do_args n leader (HsForAllTy Explicit tvs lctxt ltype)
-       = decltt leader <->
-             decltt (hsep (forallSymbol unicode : ppTyVars tvs ++ [dot]) <+>
-                ppLContextNoArrow lctxt unicode) <+> nl $$
-         do_largs n (darrow unicode) ltype
-
-     do_args n leader (HsForAllTy Implicit _ lctxt ltype)
-       | not (null (unLoc lctxt))
-       = decltt leader <-> decltt (ppLContextNoArrow lctxt unicode) <+> nl $$
-         do_largs n (darrow unicode) ltype
-         -- if we're not showing any 'forall' or class constraints or
-         -- anything, skip having an empty line for the context.
-       | otherwise
-       = do_largs n leader ltype
-     do_args n leader (HsFunTy lt r)
-       = decltt leader <-> decltt (ppLFunLhType unicode lt) <-> arg_doc n <+> nl $$
-         do_largs (n+1) (arrow unicode) r
-     do_args n leader t
-       = decltt leader <-> decltt (ppType unicode t) <-> arg_doc n <+> nl
-
-
-ppTypeSig :: [Name] -> HsType DocName  -> Bool -> LaTeX
-ppTypeSig nms ty unicode =
-  hsep (punctuate comma $ map ppSymName nms)
-    <+> dcolon unicode
-    <+> ppType unicode ty
-
-
-ppTyVars :: [LHsTyVarBndr DocName] -> [LaTeX]
-ppTyVars tvs = map ppSymName (tyvarNames tvs)
-
-
-tyvarNames :: [LHsTyVarBndr DocName] -> [Name]
-tyvarNames = map (getName . hsTyVarName . unLoc)
-
-
-declWithDoc :: LaTeX -> Maybe LaTeX -> LaTeX
-declWithDoc decl doc =
-   text "\\begin{haddockdesc}" $$
-   text "\\item[\\begin{tabular}{@{}l}" $$
-   text (latexMonoFilter (render decl)) $$
-   text "\\end{tabular}]" <>
-       (if isNothing doc then empty else text "\\haddockbegindoc") $$
-   maybe empty id doc $$
-   text "\\end{haddockdesc}"
-
-
--- in a group of decls, we don't put them all in the same tabular,
--- because that would prevent the group being broken over a page
--- boundary (breaks Foreign.C.Error for example).
-multiDecl :: [LaTeX] -> LaTeX
-multiDecl decls =
-   text "\\begin{haddockdesc}" $$
-   vcat [
-      text "\\item[" $$
-      text (latexMonoFilter (render decl)) $$
-      text "]"
-      | decl <- decls ] $$
-   text "\\end{haddockdesc}"
-
-
--------------------------------------------------------------------------------
--- * Rendering Doc
--------------------------------------------------------------------------------
-
-
-maybeDoc :: Maybe (Doc DocName) -> LaTeX
-maybeDoc = maybe empty docToLaTeX
-
-
--- for table cells, we strip paragraphs out to avoid extra vertical space
--- and don't add a quote environment.
-rDoc  :: Maybe (Doc DocName) -> LaTeX
-rDoc = maybeDoc . fmap latexStripTrailingWhitespace
-
-
--------------------------------------------------------------------------------
--- * Class declarations
--------------------------------------------------------------------------------
-
-
-ppClassHdr :: Bool -> Located [LHsPred DocName] -> DocName
-           -> [Located (HsTyVarBndr DocName)] -> [Located ([DocName], [DocName])]
-           -> Bool -> LaTeX
-ppClassHdr summ lctxt n tvs fds unicode =
-  keyword "class"
-  <+> (if not . null . unLoc $ lctxt then ppLContext lctxt unicode else empty)
-  <+> ppAppDocNameNames summ n (tyvarNames $ tvs)
-  <+> ppFds fds unicode
-
-
-ppFds :: [Located ([DocName], [DocName])] -> Bool -> LaTeX
-ppFds fds unicode =
-  if null fds then empty else
-    char '|' <+> hsep (punctuate comma (map (fundep . unLoc) fds))
-  where
-    fundep (vars1,vars2) = hsep (map ppDocName vars1) <+> arrow unicode <+>
-                           hsep (map ppDocName vars2)
-
-
-ppClassDecl :: [DocInstance DocName] -> SrcSpan
-            -> Maybe (Doc DocName) -> [(DocName, DocForDecl DocName)]
-            -> TyClDecl DocName -> Bool -> LaTeX
-ppClassDecl instances loc mbDoc subdocs
-  (ClassDecl lctxt lname ltyvars lfds lsigs _ ats _) unicode
-  = declWithDoc classheader (if null body then Nothing else Just (vcat body)) $$
-    instancesBit
-  where
-    classheader
-      | null lsigs = hdr unicode
-      | otherwise  = hdr unicode <+> keyword "where"
-
-    hdr = ppClassHdr False lctxt (unLoc lname) ltyvars lfds
-
-    body = catMaybes [fmap docToLaTeX mbDoc, body_]
-
-    body_
-      | null lsigs, null ats = Nothing
-      | null ats  = Just methodTable
----     | otherwise = atTable $$ methodTable
-      | otherwise = error "LaTeX.ppClassDecl"
-
-    methodTable =
-      text "\\haddockpremethods{}\\textbf{Methods}" $$
-      vcat  [ ppFunSig loc doc names typ unicode
-            | L _ (TypeSig lnames (L _ typ)) <- lsigs
-            , let doc = lookupAnySubdoc (head names) subdocs
-                  names = map unLoc lnames ]
-              -- FIXME: is taking just the first name ok? Is it possible that
-              -- there are different subdocs for different names in a single
-              -- type signature?
-
-    instancesBit = ppDocInstances unicode instances
-
-ppClassDecl _ _ _ _ _ _ = error "declaration type not supported by ppShortClassDecl"
-
-ppDocInstances :: Bool -> [DocInstance DocName] -> LaTeX
-ppDocInstances _unicode [] = empty
-ppDocInstances unicode (i : rest)
-  | Just ihead <- isUndocdInstance i
-  = declWithDoc (vcat (map (ppInstDecl unicode) (ihead:is))) Nothing $$
-    ppDocInstances unicode rest'
-  | otherwise 
-  = ppDocInstance unicode i $$ ppDocInstances unicode rest
-  where
-    (is, rest') = spanWith isUndocdInstance rest
-
-isUndocdInstance :: DocInstance a -> Maybe (InstHead a)
-isUndocdInstance (i,Nothing) = Just i
-isUndocdInstance _ = Nothing
-
--- | Print a possibly commented instance. The instance header is printed inside
--- an 'argBox'. The comment is printed to the right of the box in normal comment
--- style.
-ppDocInstance :: Bool -> DocInstance DocName -> LaTeX
-ppDocInstance unicode (instHead, mbDoc) =
-  declWithDoc (ppInstDecl unicode instHead) (fmap docToLaTeX mbDoc)
-
-
-ppInstDecl :: Bool -> InstHead DocName -> LaTeX
-ppInstDecl unicode instHead = keyword "instance" <+> ppInstHead unicode instHead
-
-
-ppInstHead :: Bool -> InstHead DocName -> LaTeX
-ppInstHead unicode ([],   n, ts) = ppAppNameTypes n ts unicode
-ppInstHead unicode (ctxt, n, ts) = ppContextNoLocs ctxt unicode <+> ppAppNameTypes n ts unicode
-
-
-lookupAnySubdoc :: (Eq name1) =>
-                   name1 -> [(name1, DocForDecl name2)] -> DocForDecl name2
-lookupAnySubdoc n subdocs = case lookup n subdocs of
-  Nothing -> noDocForDecl
-  Just docs -> docs
-
-
--------------------------------------------------------------------------------
--- * Data & newtype declarations
--------------------------------------------------------------------------------
-
-
-ppDataDecl :: [DocInstance DocName] ->
-              [(DocName, DocForDecl DocName)] ->
-              SrcSpan -> Maybe (Doc DocName) -> TyClDecl DocName -> Bool ->
-              LaTeX
-ppDataDecl instances subdocs _loc mbDoc dataDecl unicode
-
-   =  declWithDoc (ppDataHeader dataDecl unicode <+> whereBit)
-                  (if null body then Nothing else Just (vcat body))
-   $$ instancesBit
-
-  where
-    cons      = tcdCons dataDecl
-    resTy     = (con_res . unLoc . head) cons
-
-    body = catMaybes [constrBit, fmap docToLaTeX mbDoc]
-
-    (whereBit, leaders)
-      | null cons = (empty,[])
-      | otherwise = case resTy of
-        ResTyGADT _ -> (decltt (keyword "where"), repeat empty)
-        _           -> (empty, (decltt (text "=") : repeat (decltt (text "|"))))
-
-    constrBit
-      | null cons = Nothing
-      | otherwise = Just $
-          text "\\haddockbeginconstrs" $$
-          vcat (zipWith (ppSideBySideConstr subdocs unicode) leaders cons) $$
-          text "\\end{tabulary}\\par"
-
-    instancesBit = ppDocInstances unicode instances
-
-
--- ppConstrHdr is for (non-GADT) existentials constructors' syntax
-ppConstrHdr :: HsExplicitFlag -> [Name] -> HsContext DocName -> Bool -> LaTeX
-ppConstrHdr forall tvs ctxt unicode
- = (if null tvs then empty else ppForall)
-   <+>
-   (if null ctxt then empty else ppContextNoArrow ctxt unicode <+> darrow unicode <+> text " ")
-  where
-    ppForall = case forall of
-      Explicit -> forallSymbol unicode <+> hsep (map ppName tvs) <+> text ". "
-      Implicit -> empty
-
-
-ppSideBySideConstr :: [(DocName, DocForDecl DocName)] -> Bool -> LaTeX
-                   -> LConDecl DocName -> LaTeX
-ppSideBySideConstr subdocs unicode leader (L _ con) =
-  leader <->
-  case con_res con of
-  ResTyH98 -> case con_details con of
-
-    PrefixCon args ->
-      decltt (hsep ((header_ unicode <+> ppBinder occ) :
-                 map (ppLParendType unicode) args))
-      <-> rDoc mbDoc <+> nl
-
-    RecCon fields ->
-      (decltt (header_ unicode <+> ppBinder occ)
-        <-> rDoc mbDoc <+> nl)
-      $$
-      doRecordFields fields
-
-    InfixCon arg1 arg2 ->
-      decltt (hsep [ header_ unicode <+> ppLParendType unicode arg1,
-                 ppBinder occ,
-                 ppLParendType unicode arg2 ])
-      <-> rDoc mbDoc <+> nl
-
-  ResTyGADT resTy -> case con_details con of
-    -- prefix & infix could also use hsConDeclArgTys if it seemed to
-    -- simplify the code.
-    PrefixCon args -> doGADTCon args resTy
-    cd@(RecCon fields) -> doGADTCon (hsConDeclArgTys cd) resTy <+> nl $$
-                                     doRecordFields fields
-    InfixCon arg1 arg2 -> doGADTCon [arg1, arg2] resTy
-
- where
-    doRecordFields fields =
-        vcat (map (ppSideBySideField subdocs unicode) fields)
-
-    doGADTCon args resTy = decltt (ppBinder occ <+> dcolon unicode <+> hsep [
-                               ppForAll forall ltvs (con_cxt con) unicode,
-                               ppLType unicode (foldr mkFunTy resTy args) ]
-                            ) <-> rDoc mbDoc
-
-
-    header_ = ppConstrHdr forall tyVars context
-    occ     = nameOccName . getName . unLoc . con_name $ con
-    ltvs    = con_qvars con
-    tyVars  = tyvarNames (con_qvars con)
-    context = unLoc (con_cxt con)
-    forall  = con_explicit con
-    -- don't use "con_doc con", in case it's reconstructed from a .hi file,
-    -- or also because we want Haddock to do the doc-parsing, not GHC.
-    -- 'join' is in Maybe.
-    mbDoc = join $ fmap fst $ lookup (unLoc $ con_name con) subdocs
-    mkFunTy a b = noLoc (HsFunTy a b)
-
-
-ppSideBySideField :: [(DocName, DocForDecl DocName)] -> Bool -> ConDeclField DocName ->  LaTeX
-ppSideBySideField subdocs unicode (ConDeclField (L _ name) ltype _) =
-  decltt (ppBinder (nameOccName . getName $ name)
-    <+> dcolon unicode <+> ppLType unicode ltype) <-> rDoc mbDoc
-  where
-    -- don't use cd_fld_doc for same reason we don't use con_doc above
-    mbDoc = join $ fmap fst $ lookup name subdocs
-
--- {-
--- ppHsFullConstr :: HsConDecl -> LaTeX
--- ppHsFullConstr (HsConDecl _ nm tvs ctxt typeList doc) = 
---      declWithDoc False doc (
--- 	hsep ((ppHsConstrHdr tvs ctxt +++ 
--- 		ppHsBinder False nm) : map ppHsBangType typeList)
---       )
--- ppHsFullConstr (HsRecDecl _ nm tvs ctxt fields doc) =
---    td << vanillaTable << (
---      case doc of
---        Nothing -> aboves [hdr, fields_html]
---        Just _  -> aboves [hdr, constr_doc, fields_html]
---    )
--- 
---   where hdr = declBox (ppHsConstrHdr tvs ctxt +++ ppHsBinder False nm)
--- 
--- 	constr_doc	
--- 	  | isJust doc = docBox (docToLaTeX (fromJust doc))
--- 	  | otherwise  = LaTeX.emptyTable
--- 
--- 	fields_html = 
--- 	   td << 
--- 	      table ! [width "100%", cellpadding 0, cellspacing 8] << (
--- 		   aboves (map ppFullField (concat (map expandField fields)))
--- 		)
--- -}
--- 
--- ppShortField :: Bool -> Bool -> ConDeclField DocName -> LaTeX
--- ppShortField summary unicode (ConDeclField (L _ name) ltype _)
---   = tda [theclass "recfield"] << (
---       ppBinder summary (docNameOcc name)
---       <+> dcolon unicode <+> ppLType unicode ltype
---     )
--- 
--- {-
--- ppFullField :: HsFieldDecl -> LaTeX
--- ppFullField (HsFieldDecl [n] ty doc) 
---   = declWithDoc False doc (
--- 	ppHsBinder False n <+> dcolon <+> ppHsBangType ty
---     )
--- ppFullField _ = error "ppFullField"
--- 
--- expandField :: HsFieldDecl -> [HsFieldDecl]
--- expandField (HsFieldDecl ns ty doc) = [ HsFieldDecl [n] ty doc | n <- ns ]
--- -}
-
-
--- | Print the LHS of a data\/newtype declaration.
--- Currently doesn't handle 'data instance' decls or kind signatures
-ppDataHeader :: TyClDecl DocName -> Bool -> LaTeX
-ppDataHeader decl unicode
-  | not (isDataDecl decl) = error "ppDataHeader: illegal argument"
-  | otherwise =
-    -- newtype or data
-    (if tcdND decl == NewType then keyword "newtype" else keyword "data") <+>
-    -- context
-    ppLContext (tcdCtxt decl) unicode <+>
-    -- T a b c ..., or a :+: b
-    ppTyClBinderWithVars False decl
-
-
---------------------------------------------------------------------------------
--- * TyClDecl helpers
---------------------------------------------------------------------------------
-
-
--- | Print a type family / newtype / data / class binder and its variables 
-ppTyClBinderWithVars :: Bool -> TyClDecl DocName -> LaTeX
-ppTyClBinderWithVars summ decl =
-  ppAppDocNameNames summ (unLoc $ tcdLName decl) (tyvarNames $ tcdTyVars decl)
-
-
---------------------------------------------------------------------------------
--- * Type applications
---------------------------------------------------------------------------------
-
-
--- | Print an application of a DocName and a list of HsTypes
-ppAppNameTypes :: DocName -> [HsType DocName] -> Bool -> LaTeX
-ppAppNameTypes n ts unicode = ppTypeApp n ts ppDocName (ppParendType unicode)
-
-
--- | Print an application of a DocName and a list of Names 
-ppAppDocNameNames :: Bool -> DocName -> [Name] -> LaTeX
-ppAppDocNameNames _summ n ns =
-  ppTypeApp n ns (ppBinder . nameOccName . getName) ppSymName
-
-
--- | General printing of type applications
-ppTypeApp :: DocName -> [a] -> (DocName -> LaTeX) -> (a -> LaTeX) -> LaTeX
-ppTypeApp n (t1:t2:rest) ppDN ppT
-  | operator, not . null $ rest = parens opApp <+> hsep (map ppT rest)
-  | operator                    = opApp
-  where
-    operator = isNameSym . getName $ n
-    opApp = ppT t1 <+> ppDN n <+> ppT t2
-
-ppTypeApp n ts ppDN ppT = ppDN n <+> hsep (map ppT ts)
-
-
--------------------------------------------------------------------------------
--- * Contexts
--------------------------------------------------------------------------------
-
-
-ppLContext, ppLContextNoArrow :: Located (HsContext DocName) -> Bool -> LaTeX
-ppLContext        = ppContext        . unLoc
-ppLContextNoArrow = ppContextNoArrow . unLoc
-
-
-ppContextNoArrow :: HsContext DocName -> Bool -> LaTeX
-ppContextNoArrow []  _ = empty
-ppContextNoArrow cxt unicode = pp_hs_context (map unLoc cxt) unicode
-
-
-ppContextNoLocs :: [HsPred DocName] -> Bool -> LaTeX
-ppContextNoLocs []  _ = empty
-ppContextNoLocs cxt unicode = pp_hs_context cxt unicode <+> darrow unicode
-
-
-ppContext :: HsContext DocName -> Bool -> LaTeX
-ppContext cxt unicode = ppContextNoLocs (map unLoc cxt) unicode
-
-
-pp_hs_context :: [HsPred DocName] -> Bool -> LaTeX
-pp_hs_context []  _       = empty
-pp_hs_context [p] unicode = ppPred unicode p
-pp_hs_context cxt unicode = parenList (map (ppPred unicode) cxt)
-
-
-ppPred :: Bool -> HsPred DocName -> LaTeX
-ppPred unicode (HsClassP n ts) = ppAppNameTypes n (map unLoc ts) unicode
-ppPred unicode (HsEqualP t1 t2) = ppLType unicode t1 <> text "~" <> ppLType unicode t2
-ppPred unicode (HsIParam (IPName n) t)
-  = char '?' <> ppDocName n <> dcolon unicode <> ppLType unicode t
-
-
--------------------------------------------------------------------------------
--- * Types and contexts
--------------------------------------------------------------------------------
-
-
-ppKind :: Outputable a => a -> LaTeX
-ppKind k = text (showSDoc (ppr k))
-
-
-ppBang :: HsBang -> LaTeX
-ppBang HsNoBang = empty
-ppBang _        = char '!' -- Unpacked args is an implementation detail,
-
-
-tupleParens :: Boxity -> [LaTeX] -> LaTeX
-tupleParens Boxed   = parenList
-tupleParens Unboxed = ubxParenList
-
-
--------------------------------------------------------------------------------
--- * Rendering of HsType
---
--- Stolen from Html and tweaked for LaTeX generation
--------------------------------------------------------------------------------
-
-
-pREC_TOP, pREC_FUN, pREC_OP, pREC_CON :: Int
-
-pREC_TOP = (0 :: Int)   -- type in ParseIface.y in GHC
-pREC_FUN = (1 :: Int)   -- btype in ParseIface.y in GHC
-                        -- Used for LH arg of (->)
-pREC_OP  = (2 :: Int)   -- Used for arg of any infix operator
-                        -- (we don't keep their fixities around)
-pREC_CON = (3 :: Int)   -- Used for arg of type applicn:
-                        -- always parenthesise unless atomic
-
-maybeParen :: Int           -- Precedence of context
-           -> Int           -- Precedence of top-level operator
-           -> LaTeX -> LaTeX  -- Wrap in parens if (ctxt >= op)
-maybeParen ctxt_prec op_prec p | ctxt_prec >= op_prec = parens p
-                               | otherwise            = p
-
-
-ppLType, ppLParendType, ppLFunLhType :: Bool -> Located (HsType DocName) -> LaTeX
-ppLType       unicode y = ppType unicode (unLoc y)
-ppLParendType unicode y = ppParendType unicode (unLoc y)
-ppLFunLhType  unicode y = ppFunLhType unicode (unLoc y)
-
-
-ppType, ppParendType, ppFunLhType :: Bool -> HsType DocName -> LaTeX
-ppType       unicode ty = ppr_mono_ty pREC_TOP ty unicode
-ppParendType unicode ty = ppr_mono_ty pREC_CON ty unicode
-ppFunLhType  unicode ty = ppr_mono_ty pREC_FUN ty unicode
-
-
--- Drop top-level for-all type variables in user style
--- since they are implicit in Haskell
-
-ppForAll :: HsExplicitFlag -> [Located (HsTyVarBndr DocName)]
-         -> Located (HsContext DocName) -> Bool -> LaTeX
-ppForAll expl tvs cxt unicode
-  | show_forall = forall_part <+> ppLContext cxt unicode
-  | otherwise   = ppLContext cxt unicode
-  where
-    show_forall = not (null tvs) && is_explicit
-    is_explicit = case expl of {Explicit -> True; Implicit -> False}
-    forall_part = hsep (forallSymbol unicode : ppTyVars tvs) <> dot
-
-
-ppr_mono_lty :: Int -> LHsType DocName -> Bool -> LaTeX
-ppr_mono_lty ctxt_prec ty unicode = ppr_mono_ty ctxt_prec (unLoc ty) unicode
-
-
-ppr_mono_ty :: Int -> HsType DocName -> Bool -> LaTeX
-ppr_mono_ty ctxt_prec (HsForAllTy expl tvs ctxt ty) unicode
-  = maybeParen ctxt_prec pREC_FUN $
-    hsep [ppForAll expl tvs ctxt unicode, ppr_mono_lty pREC_TOP ty unicode]
-
-ppr_mono_ty _         (HsBangTy b ty)     u = ppBang b <> ppLParendType u ty
-ppr_mono_ty _         (HsTyVar name)      _ = ppDocName name
-ppr_mono_ty ctxt_prec (HsFunTy ty1 ty2)   u = ppr_fun_ty ctxt_prec ty1 ty2 u
-ppr_mono_ty _         (HsTupleTy con tys) u = tupleParens con (map (ppLType u) tys)
-ppr_mono_ty _         (HsKindSig ty kind) u = parens (ppr_mono_lty pREC_TOP ty u <+> dcolon u <+> ppKind kind)
-ppr_mono_ty _         (HsListTy ty)       u = brackets (ppr_mono_lty pREC_TOP ty u)
-ppr_mono_ty _         (HsPArrTy ty)       u = pabrackets (ppr_mono_lty pREC_TOP ty u)
-ppr_mono_ty _         (HsPredTy p)        u = parens (ppPred u p)
-ppr_mono_ty _         (HsSpliceTy {})     _ = error "ppr_mono_ty HsSpliceTy"
-ppr_mono_ty _         (HsQuasiQuoteTy {}) _ = error "ppr_mono_ty HsQuasiQuoteTy"
-ppr_mono_ty _         (HsRecTy {})        _ = error "ppr_mono_ty HsRecTy"
-ppr_mono_ty _         (HsCoreTy {})       _ = error "ppr_mono_ty HsCoreTy"
-
-ppr_mono_ty ctxt_prec (HsAppTy fun_ty arg_ty) unicode
-  = maybeParen ctxt_prec pREC_CON $
-    hsep [ppr_mono_lty pREC_FUN fun_ty unicode, ppr_mono_lty pREC_CON arg_ty unicode]
-
-ppr_mono_ty ctxt_prec (HsOpTy ty1 op ty2) unicode
-  = maybeParen ctxt_prec pREC_FUN $
-    ppr_mono_lty pREC_OP ty1 unicode <+> ppr_op <+> ppr_mono_lty pREC_OP ty2 unicode
-  where
-    ppr_op = if not (isSymOcc occName) then char '`' <> ppLDocName op <> char '`' else ppLDocName op
-    occName = nameOccName . getName . unLoc $ op
-
-ppr_mono_ty ctxt_prec (HsParTy ty) unicode
---  = parens (ppr_mono_lty pREC_TOP ty)
-  = ppr_mono_lty ctxt_prec ty unicode
-
-ppr_mono_ty ctxt_prec (HsDocTy ty _) unicode
-  = ppr_mono_lty ctxt_prec ty unicode
-
-
-ppr_fun_ty :: Int -> LHsType DocName -> LHsType DocName -> Bool -> LaTeX
-ppr_fun_ty ctxt_prec ty1 ty2 unicode
-  = let p1 = ppr_mono_lty pREC_FUN ty1 unicode
-        p2 = ppr_mono_lty pREC_TOP ty2 unicode
-    in
-    maybeParen ctxt_prec pREC_FUN $
-    sep [p1, arrow unicode <+> p2]
-
-
--------------------------------------------------------------------------------
--- * Names
--------------------------------------------------------------------------------
-
-
-ppBinder :: OccName -> LaTeX
-ppBinder n
-  | isVarSym n = parens $ ppOccName n
-  | otherwise  = ppOccName n
-
-
-ppSymName :: Name -> LaTeX
-ppSymName name
-  | isNameSym name = parens $ ppName name
-  | otherwise = ppName name
-
-
-ppVerbOccName :: OccName -> LaTeX
-ppVerbOccName = text . latexFilter . occNameString
-
-
-ppOccName :: OccName -> LaTeX
-ppOccName = text . occNameString
-
-
-ppVerbDocName :: DocName -> LaTeX
-ppVerbDocName = ppVerbOccName . nameOccName . getName
-
-
-ppVerbRdrName :: RdrName -> LaTeX
-ppVerbRdrName = ppVerbOccName . rdrNameOcc
-
-
-ppDocName :: DocName -> LaTeX
-ppDocName = ppOccName . nameOccName . getName
-
-
-ppLDocName :: Located DocName -> LaTeX
-ppLDocName (L _ d) = ppDocName d
-
-
-ppDocBinder :: DocName -> LaTeX
-ppDocBinder = ppBinder . nameOccName . getName
-
-
-ppName :: Name -> LaTeX
-ppName = ppOccName . nameOccName
-
-
-latexFilter :: String -> String
-latexFilter = foldr latexMunge ""
-
-
-latexMonoFilter :: String -> String
-latexMonoFilter = foldr latexMonoMunge ""
-
-
-latexMunge :: Char -> String -> String
-latexMunge '#'  s = "{\\char '43}" ++ s
-latexMunge '$'  s = "{\\char '44}" ++ s
-latexMunge '%'  s = "{\\char '45}" ++ s
-latexMunge '&'  s = "{\\char '46}" ++ s
-latexMunge '~'  s = "{\\char '176}" ++ s
-latexMunge '_'  s = "{\\char '137}" ++ s
-latexMunge '^'  s = "{\\char '136}" ++ s
-latexMunge '\\' s = "{\\char '134}" ++ s
-latexMunge '{'  s = "{\\char '173}" ++ s
-latexMunge '}'  s = "{\\char '175}" ++ s
-latexMunge '['  s = "{\\char 91}" ++ s
-latexMunge ']'  s = "{\\char 93}" ++ s
-latexMunge c    s = c : s
-
-
-latexMonoMunge :: Char -> String -> String
-latexMonoMunge ' ' s = '\\' : ' ' : s
-latexMonoMunge '\n' s = '\\' : '\\' : s
-latexMonoMunge c   s = latexMunge c s
-
-
--------------------------------------------------------------------------------
--- * Doc Markup
--------------------------------------------------------------------------------
-
-
-parLatexMarkup :: (a -> LaTeX) -> (a -> Bool)
-               -> DocMarkup a (StringContext -> LaTeX)
-parLatexMarkup ppId isTyCon = Markup {
-  markupParagraph     = \p v -> p v <> text "\\par" $$ text "",
-  markupEmpty         = \_ -> empty,
-  markupString        = \s v -> text (fixString v s),
-  markupAppend        = \l r v -> l v <> r v,
-  markupIdentifier    = markupId,
-  markupModule        = \m _ -> let (mdl,_ref) = break (=='#') m in tt (text mdl),
-  markupEmphasis      = \p v -> emph (p v),
-  markupMonospaced    = \p _ -> tt (p Mono),
-  markupUnorderedList = \p v -> itemizedList (map ($v) p) $$ text "",
-  markupPic           = \path _ -> parens (text "image: " <> text path),
-  markupOrderedList   = \p v -> enumeratedList (map ($v) p) $$ text "",
-  markupDefList       = \l v -> descriptionList (map (\(a,b) -> (a v, b v)) l),
-  markupCodeBlock     = \p _ -> quote (verb (p Verb)) $$ text "",
-  markupURL           = \u _ -> text "\\url" <> braces (text u),
-  markupAName         = \_ _ -> empty,
-  markupExample       = \e _ -> quote $ verb $ text $ unlines $ map exampleToString e
-  }
-  where
-    fixString Plain s = latexFilter s
-    fixString Verb  s = s
-    fixString Mono  s = latexMonoFilter s
-
-    markupId id v =
-      case v of
-        Verb  -> theid
-        Mono  -> theid
-        Plain -> text "\\haddockid" <> braces theid
-      where theid = ppId (choose id)
-
-    -- If an id can refer to multiple things, we give precedence to type
-    -- constructors.  This should ideally be done during renaming from RdrName
-    -- to Name, but since we will move this process from GHC into Haddock in
-    -- the future, we fix it here in the meantime.
-    -- TODO: mention this rule in the documentation.
-    choose [] = error "empty identifier list in HsDoc"
-    choose [x] = x
-    choose (x:y:_)
-      | isTyCon x = x
-      | otherwise = y
-
-
-latexMarkup :: DocMarkup DocName (StringContext -> LaTeX)
-latexMarkup = parLatexMarkup ppVerbDocName (isTyConName . getName)
-
-
-rdrLatexMarkup :: DocMarkup RdrName (StringContext -> LaTeX)
-rdrLatexMarkup = parLatexMarkup ppVerbRdrName isRdrTc
-
-
-docToLaTeX :: Doc DocName -> LaTeX
-docToLaTeX doc = markup latexMarkup doc Plain
-
-
-rdrDocToLaTeX :: Doc RdrName -> LaTeX
-rdrDocToLaTeX doc = markup rdrLatexMarkup doc Plain
-
-
-data StringContext = Plain | Verb | Mono
-
-
-latexStripTrailingWhitespace :: Doc a -> Doc a
-latexStripTrailingWhitespace (DocString s)
-  | null s'   = DocEmpty
-  | otherwise = DocString s
-  where s' = reverse (dropWhile isSpace (reverse s))
-latexStripTrailingWhitespace (DocAppend l r)
-  | DocEmpty <- r' = latexStripTrailingWhitespace l
-  | otherwise      = DocAppend l r'
-  where
-    r' = latexStripTrailingWhitespace r
-latexStripTrailingWhitespace (DocParagraph p) =
-  latexStripTrailingWhitespace p
-latexStripTrailingWhitespace other = other
-
-
--------------------------------------------------------------------------------
--- * LaTeX utils
--------------------------------------------------------------------------------
-
-
-itemizedList :: [LaTeX] -> LaTeX
-itemizedList items =
-  text "\\begin{itemize}" $$
-  vcat (map (text "\\item" $$) items) $$
-  text "\\end{itemize}"
-
-
-enumeratedList :: [LaTeX] -> LaTeX
-enumeratedList items =
-  text "\\begin{enumerate}" $$
-  vcat (map (text "\\item " $$) items) $$
-  text "\\end{enumerate}"
-
-
-descriptionList :: [(LaTeX,LaTeX)] -> LaTeX
-descriptionList items =
-  text "\\begin{description}" $$
-  vcat (map (\(a,b) -> text "\\item" <> brackets a <+> b) items) $$
-  text "\\end{description}"
-
-
-tt :: LaTeX -> LaTeX
-tt ltx = text "\\haddocktt" <> braces ltx
-
-
-decltt :: LaTeX -> LaTeX
-decltt ltx = text "\\haddockdecltt" <> braces ltx
-
-
-emph :: LaTeX -> LaTeX
-emph ltx = text "\\emph" <> braces ltx
-
-
-verb :: LaTeX -> LaTeX
-verb doc = text "{\\haddockverb\\begin{verbatim}" $$ doc <> text "\\end{verbatim}}"
-   -- NB. swallow a trailing \n in the verbatim text by appending the
-   -- \end{verbatim} directly, otherwise we get spurious blank lines at the
-   -- end of code blocks.
-
-
-quote :: LaTeX -> LaTeX
-quote doc = text "\\begin{quote}" $$ doc $$ text "\\end{quote}"
-
-
-dcolon, arrow, darrow, forallSymbol :: Bool -> LaTeX
-dcolon unicode = text (if unicode then "∷" else "::")
-arrow  unicode = text (if unicode then "→" else "->")
-darrow unicode = text (if unicode then "⇒" else "=>")
-forallSymbol unicode = text (if unicode then "∀" else "forall")
-
-
-dot :: LaTeX
-dot = char '.'
-
-
-parenList :: [LaTeX] -> LaTeX
-parenList = parens . hsep . punctuate comma
-
-
-ubxParenList :: [LaTeX] -> LaTeX
-ubxParenList = ubxparens . hsep . punctuate comma
-
-
-ubxparens :: LaTeX -> LaTeX
-ubxparens h = text "(#" <> h <> text "#)"
-
-
-pabrackets :: LaTeX -> LaTeX
-pabrackets h = text "[:" <> h <> text ":]"
-
-
-nl :: LaTeX
-nl = text "\\\\"
-
-
-keyword :: String -> LaTeX
-keyword = text
-
-
-infixr 4 <->  -- combining table cells
-(<->) :: LaTeX -> LaTeX -> LaTeX
-a <-> b = a <+> char '&' <+> b
diff --git a/src/Haddock/Backends/Xhtml.hs b/src/Haddock/Backends/Xhtml.hs
deleted file mode 100644
--- a/src/Haddock/Backends/Xhtml.hs
+++ /dev/null
@@ -1,673 +0,0 @@
------------------------------------------------------------------------------
--- |
--- Module      :  Haddock.Backends.Html
--- Copyright   :  (c) Simon Marlow   2003-2006,
---                    David Waern    2006-2009,
---                    Mark Lentczner 2010
--- License     :  BSD-like
---
--- Maintainer  :  haddock@projects.haskell.org
--- Stability   :  experimental
--- Portability :  portable
------------------------------------------------------------------------------
-module Haddock.Backends.Xhtml (
-  ppHtml, copyHtmlBits,
-  ppHtmlIndex, ppHtmlContents,
-) where
-
-
-import Prelude hiding (div)
-
-import Haddock.Backends.Xhtml.Decl
-import Haddock.Backends.Xhtml.DocMarkup
-import Haddock.Backends.Xhtml.Layout
-import Haddock.Backends.Xhtml.Names
-import Haddock.Backends.Xhtml.Themes
-import Haddock.Backends.Xhtml.Types
-import Haddock.Backends.Xhtml.Utils
-import Haddock.ModuleTree
-import Haddock.Types
-import Haddock.Version
-import Haddock.Utils
-import Text.XHtml hiding ( name, title, p, quote )
-import Haddock.GhcUtils
-
-import Control.Monad         ( when, unless )
-import Control.Monad.Instances ( ) -- for Functor Either a
-import Data.Char             ( toUpper )
-import Data.List             ( sortBy, groupBy, intercalate )
-import Data.Maybe
-import System.FilePath hiding ( (</>) )
-import System.Directory
-import Data.Map              ( Map )
-import qualified Data.Map as Map hiding ( Map )
-import qualified Data.Set as Set hiding ( Set )
-import Data.Function
-import Data.Ord              ( comparing )
-
-import GHC hiding ( NoLink, moduleInfo )
-import Name
-import Module
-
-
---------------------------------------------------------------------------------
--- * Generating HTML documentation
---------------------------------------------------------------------------------
-
-
-ppHtml :: String
-       -> Maybe String                 -- ^ Package
-       -> [Interface]
-       -> FilePath                     -- ^ Destination directory
-       -> Maybe (Doc GHC.RdrName)      -- ^ Prologue text, maybe
-       -> Themes                       -- ^ Themes
-       -> SourceURLs                   -- ^ The source URL (--source)
-       -> WikiURLs                     -- ^ The wiki URL (--wiki)
-       -> Maybe String                 -- ^ The contents URL (--use-contents)
-       -> Maybe String                 -- ^ The index URL (--use-index)
-       -> Bool                         -- ^ Whether to use unicode in output (--use-unicode)
-       -> Qualification                -- ^ How to qualify names
-       -> Bool                         -- ^ Output pretty html (newlines and indenting)
-       -> IO ()
-
-ppHtml doctitle maybe_package ifaces odir prologue
-        themes maybe_source_url maybe_wiki_url
-        maybe_contents_url maybe_index_url unicode
-        qual debug =  do
-  let
-    visible_ifaces = filter visible ifaces
-    visible i = OptHide `notElem` ifaceOptions i
-
-  when (isNothing maybe_contents_url) $
-    ppHtmlContents odir doctitle maybe_package
-        themes maybe_index_url maybe_source_url maybe_wiki_url
-        (map toInstalledIface visible_ifaces)
-        False -- we don't want to display the packages in a single-package contents
-        prologue
-        debug
-
-  when (isNothing maybe_index_url) $
-    ppHtmlIndex odir doctitle maybe_package
-      themes maybe_contents_url maybe_source_url maybe_wiki_url
-      (map toInstalledIface visible_ifaces) debug
-
-  mapM_ (ppHtmlModule odir doctitle themes
-           maybe_source_url maybe_wiki_url
-           maybe_contents_url maybe_index_url unicode qual debug) visible_ifaces
-
-
-copyHtmlBits :: FilePath -> FilePath -> Themes -> IO ()
-copyHtmlBits odir libdir themes = do
-  let
-    libhtmldir = joinPath [libdir, "html"]
-    copyCssFile f = copyFile f (combine odir (takeFileName f))
-    copyLibFile f = copyFile (joinPath [libhtmldir, f]) (joinPath [odir, f])
-  mapM_ copyCssFile (cssFiles themes)
-  mapM_ copyLibFile [ jsFile, framesFile ]
-
-
-headHtml :: String -> Maybe String -> Themes -> Html
-headHtml docTitle miniPage themes =
-  header << [
-    meta ! [httpequiv "Content-Type", content "text/html; charset=UTF-8"],
-    thetitle << docTitle,
-    styleSheet themes,
-    script ! [src jsFile, thetype "text/javascript"] << noHtml,
-    script ! [thetype "text/javascript"]
-        -- NB: Within XHTML, the content of script tags needs to be
-        -- a <![CDATA[ section. Will break if the miniPage name could
-        -- have "]]>" in it!
-      << primHtml (
-          "//<![CDATA[\nwindow.onload = function () {pageLoad();"
-          ++ setSynopsis ++ "};\n//]]>\n")
-    ]
-  where
-    setSynopsis = maybe "" (\p -> "setSynopsis(\"" ++ p ++ "\");") miniPage
-
-
-srcButton :: SourceURLs -> Maybe Interface -> Maybe Html
-srcButton (Just src_base_url, _, _) Nothing =
-  Just (anchor ! [href src_base_url] << "Source")
-srcButton (_, Just src_module_url, _) (Just iface) =
-  let url = spliceURL (Just $ ifaceOrigFilename iface)
-                      (Just $ ifaceMod iface) Nothing Nothing src_module_url
-   in Just (anchor ! [href url] << "Source")
-srcButton _ _ =
-  Nothing
-
-
-wikiButton :: WikiURLs -> Maybe Module -> Maybe Html
-wikiButton (Just wiki_base_url, _, _) Nothing =
-  Just (anchor ! [href wiki_base_url] << "User Comments")
-
-wikiButton (_, Just wiki_module_url, _) (Just mdl) =
-  let url = spliceURL Nothing (Just mdl) Nothing Nothing wiki_module_url
-   in Just (anchor ! [href url] << "User Comments")
-
-wikiButton _ _ =
-  Nothing
-
-
-contentsButton :: Maybe String -> Maybe Html
-contentsButton maybe_contents_url
-  = Just (anchor ! [href url] << "Contents")
-  where url = fromMaybe contentsHtmlFile maybe_contents_url
-
-
-indexButton :: Maybe String -> Maybe Html
-indexButton maybe_index_url
-  = Just (anchor ! [href url] << "Index")
-  where url = fromMaybe indexHtmlFile maybe_index_url
-
-
-bodyHtml :: String -> Maybe Interface
-    -> SourceURLs -> WikiURLs
-    -> Maybe String -> Maybe String
-    -> Html -> Html
-bodyHtml doctitle iface
-           maybe_source_url maybe_wiki_url
-           maybe_contents_url maybe_index_url
-           pageContent =
-  body << [
-    divPackageHeader << [
-      unordList (catMaybes [
-        srcButton maybe_source_url iface,
-        wikiButton maybe_wiki_url (ifaceMod `fmap` iface),
-        contentsButton maybe_contents_url,
-        indexButton maybe_index_url])
-            ! [theclass "links", identifier "page-menu"],
-      nonEmpty sectionName << doctitle
-      ],
-    divContent << pageContent,
-    divFooter << paragraph << (
-      "Produced by " +++
-      (anchor ! [href projectUrl] << toHtml projectName) +++
-      (" version " ++ projectVersion)
-      )
-    ]
-
-
-moduleInfo :: Interface -> Html
-moduleInfo iface =
-   let
-      info = ifaceInfo iface
-
-      doOneEntry :: (String, HaddockModInfo GHC.Name -> Maybe String) -> Maybe HtmlTable
-      doOneEntry (fieldName, field) =
-        field info >>= \a -> return (th << fieldName <-> td << a)
-
-      entries :: [HtmlTable]
-      entries = mapMaybe doOneEntry [
-         ("Portability",hmi_portability),
-         ("Stability",hmi_stability),
-         ("Maintainer",hmi_maintainer)
-         ]
-   in
-      case entries of
-         [] -> noHtml
-         _ -> table ! [theclass "info"] << aboves entries
-
-
---------------------------------------------------------------------------------
--- * Generate the module contents
---------------------------------------------------------------------------------
-
-
-ppHtmlContents
-   :: FilePath
-   -> String
-   -> Maybe String
-   -> Themes
-   -> Maybe String
-   -> SourceURLs
-   -> WikiURLs
-   -> [InstalledInterface] -> Bool -> Maybe (Doc GHC.RdrName)
-   -> Bool
-   -> IO ()
-ppHtmlContents odir doctitle _maybe_package
-  themes maybe_index_url
-  maybe_source_url maybe_wiki_url ifaces showPkgs prologue debug = do
-  let tree = mkModuleTree showPkgs
-         [(instMod iface, toInstalledDescription iface) | iface <- ifaces]
-      html =
-        headHtml doctitle Nothing themes +++
-        bodyHtml doctitle Nothing
-          maybe_source_url maybe_wiki_url
-          Nothing maybe_index_url << [
-            ppPrologue doctitle prologue,
-            ppModuleTree tree
-          ]
-  createDirectoryIfMissing True odir
-  writeFile (joinPath [odir, contentsHtmlFile]) (renderToString debug html)
-
-  -- XXX: think of a better place for this?
-  ppHtmlContentsFrame odir doctitle themes ifaces debug
-
-
-ppPrologue :: String -> Maybe (Doc GHC.RdrName) -> Html
-ppPrologue _ Nothing = noHtml
-ppPrologue title (Just doc) =
-  divDescription << (h1 << title +++ docElement thediv (rdrDocToHtml doc))
-
-
-ppModuleTree :: [ModuleTree] -> Html
-ppModuleTree ts =
-  divModuleList << (sectionName << "Modules" +++ mkNodeList [] "n" ts)
-
-
-mkNodeList :: [String] -> String -> [ModuleTree] -> Html
-mkNodeList ss p ts = case ts of
-  [] -> noHtml
-  _ -> unordList (zipWith (mkNode ss) ps ts)
-  where
-    ps = [ p ++ '.' : show i | i <- [(1::Int)..]]
-
-
-mkNode :: [String] -> String -> ModuleTree -> Html
-mkNode ss p (Node s leaf pkg short ts) =
-  htmlModule +++ shortDescr +++ htmlPkg +++ subtree
-  where
-    modAttrs = case (ts, leaf) of
-      (_:_, False) -> collapseControl p True "module"
-      (_,   _    ) -> [theclass "module"]
-
-    cBtn = case (ts, leaf) of
-      (_:_, True) -> thespan ! collapseControl p True "" << spaceHtml
-      (_,   _   ) -> noHtml
-      -- We only need an explicit collapser button when the module name
-      -- is also a leaf, and so is a link to a module page. Indeed, the
-      -- spaceHtml is a minor hack and does upset the layout a fraction.
-      
-    htmlModule = thespan ! modAttrs << (cBtn +++
-      if leaf
-        then ppModule (mkModule (stringToPackageId (fromMaybe "" pkg))
-                                       (mkModuleName mdl))
-        else toHtml s
-      )
-
-    mdl = intercalate "." (reverse (s:ss))
-
-    shortDescr = maybe noHtml origDocToHtml short
-    htmlPkg = maybe noHtml (thespan ! [theclass "package"] <<) pkg
-
-    subtree = mkNodeList (s:ss) p ts ! collapseSection p True ""
-
-
--- | Turn a module tree into a flat list of full module names.  E.g.,
--- @
---  A
---  +-B
---  +-C
--- @
--- becomes
--- @["A", "A.B", "A.B.C"]@
-flatModuleTree :: [InstalledInterface] -> [Html]
-flatModuleTree ifaces =
-    map (uncurry ppModule' . head)
-            . groupBy ((==) `on` fst)
-            . sortBy (comparing fst)
-            $ mods
-  where
-    mods = [ (moduleString mdl, mdl) | mdl <- map instMod ifaces ]
-    ppModule' txt mdl =
-      anchor ! [href (moduleHtmlFile mdl), target mainFrameName]
-        << toHtml txt
-
-
-ppHtmlContentsFrame :: FilePath -> String -> Themes
-  -> [InstalledInterface] -> Bool -> IO ()
-ppHtmlContentsFrame odir doctitle themes ifaces debug = do
-  let mods = flatModuleTree ifaces
-      html =
-        headHtml doctitle Nothing themes +++
-        miniBody << divModuleList <<
-          (sectionName << "Modules" +++
-           ulist << [ li ! [theclass "module"] << m | m <- mods ])
-  createDirectoryIfMissing True odir
-  writeFile (joinPath [odir, frameIndexHtmlFile]) (renderToString debug html)
-
-
---------------------------------------------------------------------------------
--- * Generate the index
---------------------------------------------------------------------------------
-
-
-ppHtmlIndex :: FilePath
-            -> String
-            -> Maybe String
-            -> Themes
-            -> Maybe String
-            -> SourceURLs
-            -> WikiURLs
-            -> [InstalledInterface]
-            -> Bool
-            -> IO ()
-ppHtmlIndex odir doctitle _maybe_package themes
-  maybe_contents_url maybe_source_url maybe_wiki_url ifaces debug = do
-  let html = indexPage split_indices Nothing
-              (if split_indices then [] else index)
-
-  createDirectoryIfMissing True odir
-
-  when split_indices $ do
-    mapM_ (do_sub_index index) initialChars
-    -- Let's add a single large index as well for those who don't know exactly what they're looking for:
-    let mergedhtml = indexPage False Nothing index
-    writeFile (joinPath [odir, subIndexHtmlFile merged_name]) (renderToString debug mergedhtml)
-
-  writeFile (joinPath [odir, indexHtmlFile]) (renderToString debug html)
-
-  where
-    indexPage showLetters ch items =
-      headHtml (doctitle ++ " (" ++ indexName ch ++ ")") Nothing themes +++
-      bodyHtml doctitle Nothing
-        maybe_source_url maybe_wiki_url
-        maybe_contents_url Nothing << [
-          if showLetters then indexInitialLetterLinks else noHtml,
-          if null items then noHtml else
-            divIndex << [sectionName << indexName ch, buildIndex items]
-          ]
-
-    indexName ch = "Index" ++ maybe "" (\c -> " - " ++ [c]) ch
-    merged_name = "All"
-
-    buildIndex items = table << aboves (map indexElt items)
-
-    -- an arbitrary heuristic:
-    -- too large, and a single-page will be slow to load
-    -- too small, and we'll have lots of letter-indexes with only one
-    --   or two members in them, which seems inefficient or
-    --   unnecessarily hard to use.
-    split_indices = length index > 150
-
-    indexInitialLetterLinks =
-      divAlphabet <<
-         unordList (map (\str -> anchor ! [href (subIndexHtmlFile str)] << str) $
-                        [ [c] | c <- initialChars
-                              , any ((==c) . toUpper . head . fst) index ] ++
-                        [merged_name])
-
-    -- todo: what about names/operators that start with Unicode
-    -- characters?
-    -- Exports beginning with '_' can be listed near the end,
-    -- presumably they're not as important... but would be listed
-    -- with non-split index!
-    initialChars = [ 'A'..'Z' ] ++ ":!#$%&*+./<=>?@\\^|-~" ++ "_"
-
-    do_sub_index this_ix c
-      = unless (null index_part) $
-          writeFile (joinPath [odir, subIndexHtmlFile [c]]) (renderToString debug html)
-      where
-        html = indexPage True (Just c) index_part
-        index_part = [(n,stuff) | (n,stuff) <- this_ix, toUpper (head n) == c]
-
-
-    index :: [(String, Map GHC.Name [(Module,Bool)])]
-    index = sortBy cmp (Map.toAscList full_index)
-      where cmp (n1,_) (n2,_) = comparing (map toUpper) n1 n2
-
-    -- for each name (a plain string), we have a number of original HsNames that
-    -- it can refer to, and for each of those we have a list of modules
-    -- that export that entity.  Each of the modules exports the entity
-    -- in a visible or invisible way (hence the Bool).
-    full_index :: Map String (Map GHC.Name [(Module,Bool)])
-    full_index = Map.fromListWith (flip (Map.unionWith (++)))
-                 (concatMap getIfaceIndex ifaces)
-
-    getIfaceIndex iface =
-      [ (getOccString name
-         , Map.fromList [(name, [(mdl, name `Set.member` visible)])])
-         | name <- instExports iface ]
-      where
-        mdl = instMod iface
-        visible = Set.fromList (instVisibleExports iface)
-
-    indexElt :: (String, Map GHC.Name [(Module,Bool)]) -> HtmlTable
-    indexElt (str, entities) =
-       case Map.toAscList entities of
-          [(nm,entries)] ->
-              td ! [ theclass "src" ] << toHtml str <->
-                          indexLinks nm entries
-          many_entities ->
-              td ! [ theclass "src" ] << toHtml str <-> td << spaceHtml </>
-                  aboves (map doAnnotatedEntity (zip [1..] many_entities))
-
-    doAnnotatedEntity :: (Integer, (Name, [(Module, Bool)])) -> HtmlTable
-    doAnnotatedEntity (j,(nm,entries))
-          = td ! [ theclass "alt" ] <<
-                  toHtml (show j) <+> parens (ppAnnot (nameOccName nm)) <->
-                   indexLinks nm entries
-
-    ppAnnot n | not (isValOcc n) = toHtml "Type/Class"
-              | isDataOcc n      = toHtml "Data Constructor"
-              | otherwise        = toHtml "Function"
-
-    indexLinks nm entries =
-       td ! [ theclass "module" ] <<
-          hsep (punctuate comma
-          [ if visible then
-               linkId mdl (Just nm) << toHtml (moduleString mdl)
-            else
-               toHtml (moduleString mdl)
-          | (mdl, visible) <- entries ])
-
-
---------------------------------------------------------------------------------
--- * Generate the HTML page for a module
---------------------------------------------------------------------------------
-
-
-ppHtmlModule
-        :: FilePath -> String -> Themes
-        -> SourceURLs -> WikiURLs
-        -> Maybe String -> Maybe String -> Bool -> Qualification
-        -> Bool -> Interface -> IO ()
-ppHtmlModule odir doctitle themes
-  maybe_source_url maybe_wiki_url
-  maybe_contents_url maybe_index_url unicode qual debug iface = do
-  let
-      mdl = ifaceMod iface
-      mdl_str = moduleString mdl
-      real_qual = case qual of
-          LocalQual Nothing    -> LocalQual (Just mdl)
-          RelativeQual Nothing -> RelativeQual (Just mdl)
-          _                     -> qual
-      html =
-        headHtml mdl_str (Just $ "mini_" ++ moduleHtmlFile mdl) themes +++
-        bodyHtml doctitle (Just iface)
-          maybe_source_url maybe_wiki_url
-          maybe_contents_url maybe_index_url << [
-            divModuleHeader << (moduleInfo iface +++ (sectionName << mdl_str)),
-            ifaceToHtml maybe_source_url maybe_wiki_url iface unicode real_qual
-          ]
-
-  createDirectoryIfMissing True odir
-  writeFile (joinPath [odir, moduleHtmlFile mdl]) (renderToString debug html)
-  ppHtmlModuleMiniSynopsis odir doctitle themes iface unicode qual debug
-
-
-ppHtmlModuleMiniSynopsis :: FilePath -> String -> Themes
-  -> Interface -> Bool -> Qualification -> Bool -> IO ()
-ppHtmlModuleMiniSynopsis odir _doctitle themes iface unicode qual debug = do
-  let mdl = ifaceMod iface
-      html =
-        headHtml (moduleString mdl) Nothing themes +++
-        miniBody <<
-          (divModuleHeader << sectionName << moduleString mdl +++
-           miniSynopsis mdl iface unicode qual)
-  createDirectoryIfMissing True odir
-  writeFile (joinPath [odir, "mini_" ++ moduleHtmlFile mdl]) (renderToString debug html)
-
-
-ifaceToHtml :: SourceURLs -> WikiURLs -> Interface -> Bool -> Qualification -> Html
-ifaceToHtml maybe_source_url maybe_wiki_url iface unicode qual
-  = ppModuleContents qual exports +++
-    description +++
-    synopsis +++
-    divInterface (maybe_doc_hdr +++ bdy)
-  where
-    exports = numberSectionHeadings (ifaceRnExportItems iface)
-
-    -- todo: if something has only sub-docs, or fn-args-docs, should
-    -- it be measured here and thus prevent omitting the synopsis?
-    has_doc (ExportDecl _ doc _ _) = isJust (fst doc)
-    has_doc (ExportNoDecl _ _) = False
-    has_doc (ExportModule _) = False
-    has_doc _ = True
-
-    no_doc_at_all = not (any has_doc exports)
-
-    description
-          = case ifaceRnDoc iface of
-              Nothing -> noHtml
-              Just doc -> divDescription $
-                            sectionName << "Description" +++ docSection qual doc
-
-        -- omit the synopsis if there are no documentation annotations at all
-    synopsis
-      | no_doc_at_all = noHtml
-      | otherwise
-      = divSynposis $
-            paragraph ! collapseControl "syn" False "caption" << "Synopsis" +++ 
-            shortDeclList (
-                mapMaybe (processExport True linksInfo unicode qual) exports
-            ) ! (collapseSection "syn" False "" ++ collapseToggle "syn")
-
-        -- if the documentation doesn't begin with a section header, then
-        -- add one ("Documentation").
-    maybe_doc_hdr
-      = case exports of
-          [] -> noHtml
-          ExportGroup _ _ _ : _ -> noHtml
-          _ -> h1 << "Documentation"
-
-    bdy =
-      foldr (+++) noHtml $
-        mapMaybe (processExport False linksInfo unicode qual) exports
-
-    linksInfo = (maybe_source_url, maybe_wiki_url)
-
-
-miniSynopsis :: Module -> Interface -> Bool -> Qualification -> Html
-miniSynopsis mdl iface unicode qual =
-    divInterface << concatMap (processForMiniSynopsis mdl unicode qual) exports
-  where
-    exports = numberSectionHeadings (ifaceRnExportItems iface)
-
-
-processForMiniSynopsis :: Module -> Bool -> Qualification -> ExportItem DocName
-                       -> [Html]
-processForMiniSynopsis mdl unicode _ (ExportDecl (L _loc decl0) _doc _ _insts) =
-  ((divTopDecl <<).(declElem <<)) `fmap` case decl0 of
-    TyClD d -> let b = ppTyClBinderWithVarsMini mdl d in case d of
-        (TyFamily{}) -> [ppTyFamHeader True False d unicode]
-        (TyData{tcdTyPats = ps})
-          | Nothing <- ps -> [keyword "data" <+> b]
-          | Just _ <- ps  -> [keyword "data" <+> keyword "instance" <+> b]
-        (TySynonym{tcdTyPats = ps})
-          | Nothing <- ps -> [keyword "type" <+> b]
-          | Just _ <- ps  -> [keyword "type" <+> keyword "instance" <+> b]
-        (ClassDecl {})    -> [keyword "class" <+> b]
-        _ -> []
-    SigD (TypeSig lnames (L _ _)) ->
-      map (ppNameMini mdl . nameOccName . getName . unLoc) lnames
-    _ -> []
-processForMiniSynopsis _ _ qual (ExportGroup lvl _id txt) =
-  [groupTag lvl << docToHtml qual txt]
-processForMiniSynopsis _ _ _ _ = []
-
-
-ppNameMini :: Module -> OccName -> Html
-ppNameMini mdl nm =
-    anchor ! [ href (moduleNameUrl mdl nm)
-             , target mainFrameName ]
-      << ppBinder' nm
-
-
-ppTyClBinderWithVarsMini :: Module -> TyClDecl DocName -> Html
-ppTyClBinderWithVarsMini mdl decl =
-  let n = unLoc $ tcdLName decl
-      ns = tyvarNames $ tcdTyVars decl
-  in ppTypeApp n ns (ppNameMini mdl . nameOccName . getName) ppTyName
-
-
-ppModuleContents :: Qualification -> [ExportItem DocName] -> Html
-ppModuleContents qual exports
-  | null sections = noHtml
-  | otherwise     = contentsDiv
- where
-  contentsDiv = divTableOfContents << (
-    sectionName << "Contents" +++
-    unordList sections)
-
-  (sections, _leftovers{-should be []-}) = process 0 exports
-
-  process :: Int -> [ExportItem DocName] -> ([Html],[ExportItem DocName])
-  process _ [] = ([], [])
-  process n items@(ExportGroup lev id0 doc : rest)
-    | lev <= n  = ( [], items )
-    | otherwise = ( html:secs, rest2 )
-    where
-        html = linkedAnchor (groupId id0) << docToHtml qual doc +++ mk_subsections ssecs
-        (ssecs, rest1) = process lev rest
-        (secs,  rest2) = process n   rest1
-  process n (_ : rest) = process n rest
-
-  mk_subsections [] = noHtml
-  mk_subsections ss = unordList ss
-
-
--- we need to assign a unique id to each section heading so we can hyperlink
--- them from the contents:
-numberSectionHeadings :: [ExportItem DocName] -> [ExportItem DocName]
-numberSectionHeadings exports = go 1 exports
-  where go :: Int -> [ExportItem DocName] -> [ExportItem DocName]
-        go _ [] = []
-        go n (ExportGroup lev _ doc : es)
-          = ExportGroup lev (show n) doc : go (n+1) es
-        go n (other:es)
-          = other : go n es
-
-
-processExport :: Bool -> LinksInfo -> Bool -> Qualification
-              -> ExportItem DocName -> Maybe Html
-processExport summary _ _ qual (ExportGroup lev id0 doc)
-  = nothingIf summary $ groupHeading lev id0 << docToHtml qual doc
-processExport summary links unicode qual (ExportDecl decl doc subdocs insts)
-  = processDecl summary $ ppDecl summary links decl doc insts subdocs unicode qual
-processExport summary _ _ qual (ExportNoDecl y [])
-  = processDeclOneLiner summary $ ppDocName qual y
-processExport summary _ _ qual (ExportNoDecl y subs)
-  = processDeclOneLiner summary $
-      ppDocName qual y +++ parenList (map (ppDocName qual) subs)
-processExport summary _ _ qual (ExportDoc doc)
-  = nothingIf summary $ docSection qual doc
-processExport summary _ _ _ (ExportModule mdl)
-  = processDeclOneLiner summary $ toHtml "module" <+> ppModule mdl
-
-
-nothingIf :: Bool -> a -> Maybe a
-nothingIf True _ = Nothing
-nothingIf False a = Just a
-
-
-processDecl :: Bool -> Html -> Maybe Html
-processDecl True = Just
-processDecl False = Just . divTopDecl
-
-
-processDeclOneLiner :: Bool -> Html -> Maybe Html
-processDeclOneLiner True = Just
-processDeclOneLiner False = Just . divTopDecl . declElem
-
-groupHeading :: Int -> String -> Html -> Html
-groupHeading lev id0 = groupTag lev ! [identifier (groupId id0)]
-
-groupTag :: Int -> Html -> Html
-groupTag lev
-  | lev == 1  = h1
-  | lev == 2  = h2
-  | lev == 3  = h3
-  | otherwise = h4
-
-
diff --git a/src/Haddock/Backends/Xhtml/Decl.hs b/src/Haddock/Backends/Xhtml/Decl.hs
deleted file mode 100644
--- a/src/Haddock/Backends/Xhtml/Decl.hs
+++ /dev/null
@@ -1,764 +0,0 @@
------------------------------------------------------------------------------
--- |
--- Module      :  Haddock.Backends.Html.Decl
--- Copyright   :  (c) Simon Marlow   2003-2006,
---                    David Waern    2006-2009,
---                    Mark Lentczner 2010
--- License     :  BSD-like
---
--- Maintainer  :  haddock@projects.haskell.org
--- Stability   :  experimental
--- Portability :  portable
------------------------------------------------------------------------------
-module Haddock.Backends.Xhtml.Decl (
-  ppDecl,
-
-  ppTyName, ppTyFamHeader, ppTypeApp,
-  tyvarNames
-) where
-
-
-import Haddock.Backends.Xhtml.DocMarkup
-import Haddock.Backends.Xhtml.Layout
-import Haddock.Backends.Xhtml.Names
-import Haddock.Backends.Xhtml.Types
-import Haddock.Backends.Xhtml.Utils
-import Haddock.GhcUtils
-import Haddock.Types
-
-import           Control.Monad         ( join )
-import           Data.List             ( intersperse )
-import qualified Data.Map as Map
-import           Data.Maybe
-import           Text.XHtml hiding     ( name, title, p, quote )
-
-import BasicTypes            ( IPName(..), Boxity(..) )
-import GHC
-import Name
-import Outputable            ( ppr, showSDoc, Outputable )
-
-
--- TODO: use DeclInfo DocName or something
-ppDecl :: Bool -> LinksInfo -> LHsDecl DocName ->
-          DocForDecl DocName -> [DocInstance DocName] -> [(DocName, DocForDecl DocName)] ->
-          Bool -> Qualification -> Html
-ppDecl summ links (L loc decl) (mbDoc, fnArgsDoc) instances subdocs unicode qual = case decl of
-  TyClD d@(TyFamily {})          -> ppTyFam summ False links loc mbDoc d unicode qual
-  TyClD d@(TyData {})
-    | Nothing <- tcdTyPats d     -> ppDataDecl summ links instances subdocs loc mbDoc d unicode qual
-    | Just _  <- tcdTyPats d     -> ppDataInst summ links loc mbDoc d
-  TyClD d@(TySynonym {})
-    | Nothing <- tcdTyPats d     -> ppTySyn summ links loc (mbDoc, fnArgsDoc) d unicode qual
-    | Just _  <- tcdTyPats d     -> ppTyInst summ False links loc mbDoc d unicode qual
-  TyClD d@(ClassDecl {})         -> ppClassDecl summ links instances loc mbDoc subdocs d unicode qual
-  SigD (TypeSig lnames (L _ t))  -> ppFunSig summ links loc (mbDoc, fnArgsDoc) (map unLoc lnames) t unicode qual
-  ForD d                         -> ppFor summ links loc (mbDoc, fnArgsDoc) d unicode qual
-  InstD _                        -> noHtml
-  _                              -> error "declaration not supported by ppDecl"
-
-
-ppFunSig :: Bool -> LinksInfo -> SrcSpan -> DocForDecl DocName ->
-            [DocName] -> HsType DocName -> Bool -> Qualification -> Html
-ppFunSig summary links loc doc docnames typ unicode qual =
-  ppTypeOrFunSig summary links loc docnames typ doc
-    ( ppTypeSig summary occnames typ unicode qual
-    , concatHtml . punctuate comma $ map (ppBinder False) occnames
-    , dcolon unicode
-    )
-    unicode qual
-  where
-    occnames = map (nameOccName . getName) docnames
-
-
-ppTypeOrFunSig :: Bool -> LinksInfo -> SrcSpan -> [DocName] -> HsType DocName
-               -> DocForDecl DocName -> (Html, Html, Html) -> Bool -> Qualification -> Html
-ppTypeOrFunSig summary links loc docnames typ (doc, argDocs) (pref1, pref2, sep) unicode qual
-  | summary = pref1
-  | Map.null argDocs = topDeclElem links loc docnames pref1 +++ maybeDocSection qual doc
-  | otherwise = topDeclElem links loc docnames pref2 +++
-      subArguments qual (do_args 0 sep typ) +++ maybeDocSection qual doc
-  where
-    argDoc n = Map.lookup n argDocs
-
-    do_largs n leader (L _ t) = do_args n leader t
-    do_args :: Int -> Html -> (HsType DocName) -> [SubDecl]
-    do_args n leader (HsForAllTy Explicit tvs lctxt ltype)
-      = (leader <+>
-          hsep (forallSymbol unicode : ppTyVars tvs ++ [dot]) <+>
-          ppLContextNoArrow lctxt unicode qual,
-          Nothing, [])
-        : do_largs n (darrow unicode) ltype
-    do_args n leader (HsForAllTy Implicit _ lctxt ltype)
-      | not (null (unLoc lctxt))
-      = (leader <+> ppLContextNoArrow lctxt unicode qual,
-          Nothing, [])
-        : do_largs n (darrow unicode) ltype
-      -- if we're not showing any 'forall' or class constraints or
-      -- anything, skip having an empty line for the context.
-      | otherwise
-      = do_largs n leader ltype
-    do_args n leader (HsFunTy lt r)
-      = (leader <+> ppLFunLhType unicode qual lt, argDoc n, [])
-        : do_largs (n+1) (arrow unicode) r
-    do_args n leader t
-      = (leader <+> ppType unicode qual t, argDoc n, []) : []
-
-
-ppTyVars :: [LHsTyVarBndr DocName] -> [Html]
-ppTyVars tvs = map ppTyName (tyvarNames tvs)
-
-
-tyvarNames :: [LHsTyVarBndr DocName] -> [Name]
-tyvarNames = map (getName . hsTyVarName . unLoc)
-
-
-ppFor :: Bool -> LinksInfo -> SrcSpan -> DocForDecl DocName
-      -> ForeignDecl DocName -> Bool -> Qualification -> Html
-ppFor summary links loc doc (ForeignImport (L _ name) (L _ typ) _) unicode qual
-  = ppFunSig summary links loc doc [name] typ unicode qual
-ppFor _ _ _ _ _ _ _ = error "ppFor"
-
-
--- we skip type patterns for now
-ppTySyn :: Bool -> LinksInfo -> SrcSpan -> DocForDecl DocName -> TyClDecl DocName -> Bool
-        -> Qualification -> Html
-ppTySyn summary links loc doc (TySynonym (L _ name) ltyvars _ ltype) unicode qual
-  = ppTypeOrFunSig summary links loc [name] (unLoc ltype) doc
-                   (full, hdr, spaceHtml +++ equals) unicode qual
-  where
-    hdr  = hsep ([keyword "type", ppBinder summary occ] ++ ppTyVars ltyvars)
-    full = hdr <+> equals <+> ppLType unicode qual ltype
-    occ  = nameOccName . getName $ name
-ppTySyn _ _ _ _ _ _ _ = error "declaration not supported by ppTySyn"
-
-
-ppTypeSig :: Bool -> [OccName] -> HsType DocName  -> Bool -> Qualification -> Html
-ppTypeSig summary nms ty unicode qual =
-  concatHtml htmlNames <+> dcolon unicode <+> ppType unicode qual ty
-  where
-    htmlNames = intersperse (stringToHtml ", ") $ map (ppBinder summary) nms
-
-
-ppTyName :: Name -> Html
-ppTyName name
-  | isNameSym name = parens (ppName name)
-  | otherwise = ppName name
-
-
---------------------------------------------------------------------------------
--- * Type families
---------------------------------------------------------------------------------
-
-
-ppTyFamHeader :: Bool -> Bool -> TyClDecl DocName -> Bool -> Html
-ppTyFamHeader summary associated decl unicode =
-
-  (case tcdFlavour decl of
-     TypeFamily
-       | associated -> keyword "type"
-       | otherwise  -> keyword "type family"
-     DataFamily
-       | associated -> keyword "data"
-       | otherwise  -> keyword "data family"
-  ) <+>
-
-  ppTyClBinderWithVars summary decl <+>
-
-  case tcdKind decl of
-    Just kind -> dcolon unicode  <+> ppKind kind
-    Nothing -> noHtml
-
-
-ppTyFam :: Bool -> Bool -> LinksInfo -> SrcSpan -> Maybe (Doc DocName) ->
-              TyClDecl DocName -> Bool -> Qualification -> Html
-ppTyFam summary associated links loc mbDoc decl unicode qual
-
-  | summary   = ppTyFamHeader True associated decl unicode
-  | otherwise = header_ +++ maybeDocSection qual mbDoc +++ instancesBit
-
-  where
-    docname = tcdName decl
-
-    header_ = topDeclElem links loc [docname] (ppTyFamHeader summary associated decl unicode)
-
-    instancesBit = ppInstances instances docname unicode qual
-
-    -- TODO: get the instances
-    instances = []
-
-
---------------------------------------------------------------------------------
--- * Indexed data types
---------------------------------------------------------------------------------
-
-
-ppDataInst :: a
-ppDataInst = undefined
-
-
---------------------------------------------------------------------------------
--- * Indexed newtypes
---------------------------------------------------------------------------------
-
--- TODO
--- ppNewTyInst = undefined
-
-
---------------------------------------------------------------------------------
--- * Indexed types
---------------------------------------------------------------------------------
-
-
-ppTyInst :: Bool -> Bool -> LinksInfo -> SrcSpan -> Maybe (Doc DocName) ->
-            TyClDecl DocName -> Bool -> Qualification -> Html
-ppTyInst summary associated links loc mbDoc decl unicode qual
-
-  | summary   = ppTyInstHeader True associated decl unicode qual
-  | otherwise = header_ +++ maybeDocSection qual mbDoc
-
-  where
-    docname = tcdName decl
-
-    header_ = topDeclElem links loc [docname]
-                (ppTyInstHeader summary associated decl unicode qual)
-
-
-ppTyInstHeader :: Bool -> Bool -> TyClDecl DocName -> Bool -> Qualification -> Html
-ppTyInstHeader _ _ decl unicode qual =
-  keyword "type instance" <+>
-  ppAppNameTypes (tcdName decl) typeArgs unicode qual
-  where
-    typeArgs = map unLoc . fromJust . tcdTyPats $ decl
-
-
---------------------------------------------------------------------------------
--- * Associated Types
---------------------------------------------------------------------------------
-
-
-ppAssocType :: Bool -> LinksInfo -> DocForDecl DocName -> LTyClDecl DocName -> Bool
-            -> Qualification -> Html
-ppAssocType summ links doc (L loc decl) unicode qual =
-  case decl of
-    TyFamily  {} -> ppTyFam summ True links loc (fst doc) decl unicode qual
-    TySynonym {} -> ppTySyn summ links loc doc decl unicode qual
-    _            -> error "declaration type not supported by ppAssocType"
-
-
---------------------------------------------------------------------------------
--- * TyClDecl helpers
---------------------------------------------------------------------------------
-
-
--- | Print a type family / newtype / data / class binder and its variables 
-ppTyClBinderWithVars :: Bool -> TyClDecl DocName -> Html
-ppTyClBinderWithVars summ decl =
-  ppAppDocNameNames summ (unLoc $ tcdLName decl) (tyvarNames $ tcdTyVars decl)
-
-
---------------------------------------------------------------------------------
--- * Type applications
---------------------------------------------------------------------------------
-
-
--- | Print an application of a DocName and a list of HsTypes
-ppAppNameTypes :: DocName -> [HsType DocName] -> Bool -> Qualification -> Html
-ppAppNameTypes n ts unicode qual =
-    ppTypeApp n ts (ppDocName qual) (ppParendType unicode qual)
-
-
--- | Print an application of a DocName and a list of Names 
-ppAppDocNameNames :: Bool -> DocName -> [Name] -> Html
-ppAppDocNameNames summ n ns =
-  ppTypeApp n ns (ppBinder summ . nameOccName . getName) ppTyName
-
-
--- | General printing of type applications
-ppTypeApp :: DocName -> [a] -> (DocName -> Html) -> (a -> Html) -> Html
-ppTypeApp n (t1:t2:rest) ppDN ppT
-  | operator, not . null $ rest = parens opApp <+> hsep (map ppT rest)
-  | operator                    = opApp
-  where
-    operator = isNameSym . getName $ n
-    opApp = ppT t1 <+> ppDN n <+> ppT t2
-
-ppTypeApp n ts ppDN ppT = ppDN n <+> hsep (map ppT ts)
-
-
--------------------------------------------------------------------------------
--- * Contexts
--------------------------------------------------------------------------------
-
-
-ppLContext, ppLContextNoArrow :: Located (HsContext DocName) -> Bool
-                              -> Qualification -> Html
-ppLContext        = ppContext        . unLoc
-ppLContextNoArrow = ppContextNoArrow . unLoc
-
-
-ppContextNoArrow :: HsContext DocName -> Bool -> Qualification -> Html
-ppContextNoArrow []  _       _     = noHtml
-ppContextNoArrow cxt unicode qual = pp_hs_context (map unLoc cxt) unicode qual
-
-
-ppContextNoLocs :: [HsPred DocName] -> Bool -> Qualification -> Html
-ppContextNoLocs []  _       _     = noHtml
-ppContextNoLocs cxt unicode qual = pp_hs_context cxt unicode qual 
-    <+> darrow unicode
-
-
-ppContext :: HsContext DocName -> Bool -> Qualification -> Html
-ppContext cxt unicode qual = ppContextNoLocs (map unLoc cxt) unicode qual
-
-
-pp_hs_context :: [HsPred DocName] -> Bool -> Qualification-> Html
-pp_hs_context []  _       _     = noHtml
-pp_hs_context [p] unicode qual = ppPred unicode qual p
-pp_hs_context cxt unicode qual = parenList (map (ppPred unicode qual) cxt)
-
-
-ppPred :: Bool -> Qualification -> HsPred DocName -> Html
-ppPred unicode qual (HsClassP n ts) = ppAppNameTypes n (map unLoc ts) unicode qual
-ppPred unicode qual (HsEqualP t1 t2) = ppLType unicode qual t1 <+> toHtml "~"
-    <+> ppLType unicode qual t2
-ppPred unicode qual (HsIParam (IPName n) t)
-  = toHtml "?" +++ ppDocName qual n <+> dcolon unicode <+> ppLType unicode qual t
-
-
--------------------------------------------------------------------------------
--- * Class declarations
--------------------------------------------------------------------------------
-
-
-ppClassHdr :: Bool -> Located [LHsPred DocName] -> DocName
-           -> [Located (HsTyVarBndr DocName)] -> [Located ([DocName], [DocName])]
-           -> Bool -> Qualification -> Html
-ppClassHdr summ lctxt n tvs fds unicode qual =
-  keyword "class"
-  <+> (if not . null . unLoc $ lctxt then ppLContext lctxt unicode qual else noHtml)
-  <+> ppAppDocNameNames summ n (tyvarNames $ tvs)
-        <+> ppFds fds unicode qual
-
-
-ppFds :: [Located ([DocName], [DocName])] -> Bool -> Qualification -> Html
-ppFds fds unicode qual =
-  if null fds then noHtml else
-        char '|' <+> hsep (punctuate comma (map (fundep . unLoc) fds))
-  where
-        fundep (vars1,vars2) = hsep (map (ppDocName qual) vars1) <+> arrow unicode <+>
-                               hsep (map (ppDocName qual) vars2)
-
-
-ppShortClassDecl :: Bool -> LinksInfo -> TyClDecl DocName -> SrcSpan
-                 -> [(DocName, DocForDecl DocName)] -> Bool -> Qualification
-                 -> Html
-ppShortClassDecl summary links (ClassDecl lctxt lname tvs fds sigs _ ats _) loc
-    subdocs unicode qual = 
-  if null sigs && null ats
-    then (if summary then id else topDeclElem links loc [nm]) hdr
-    else (if summary then id else topDeclElem links loc [nm]) (hdr <+> keyword "where")
-      +++ shortSubDecls
-          (
-            [ ppAssocType summary links doc at unicode qual | at <- ats
-              , let doc = lookupAnySubdoc (tcdName $ unL at) subdocs ]  ++
-
-            [ ppFunSig summary links loc doc names typ unicode qual
-              | L _ (TypeSig lnames (L _ typ)) <- sigs
-              , let doc = lookupAnySubdoc (head names) subdocs
-                    names = map unLoc lnames ]
-              -- FIXME: is taking just the first name ok? Is it possible that
-              -- there are different subdocs for different names in a single
-              -- type signature?
-          )
-  where
-    hdr = ppClassHdr summary lctxt (unLoc lname) tvs fds unicode qual
-    nm  = unLoc lname
-ppShortClassDecl _ _ _ _ _ _ _ = error "declaration type not supported by ppShortClassDecl"
-
-
-
-ppClassDecl :: Bool -> LinksInfo -> [DocInstance DocName] -> SrcSpan
-            -> Maybe (Doc DocName) -> [(DocName, DocForDecl DocName)]
-            -> TyClDecl DocName -> Bool -> Qualification -> Html
-ppClassDecl summary links instances loc mbDoc subdocs
-        decl@(ClassDecl lctxt lname ltyvars lfds lsigs _ ats _) unicode qual
-  | summary = ppShortClassDecl summary links decl loc subdocs unicode qual
-  | otherwise = classheader +++ maybeDocSection qual mbDoc
-                  +++ atBit +++ methodBit  +++ instancesBit
-  where
-    classheader
-      | null lsigs = topDeclElem links loc [nm] (hdr unicode qual)
-      | otherwise  = topDeclElem links loc [nm] (hdr unicode qual <+> keyword "where")
-
-    nm   = unLoc $ tcdLName decl
-
-    hdr = ppClassHdr summary lctxt (unLoc lname) ltyvars lfds
-
-    atBit = subAssociatedTypes [ ppAssocType summary links doc at unicode qual
-                      | at <- ats
-                      , let doc = lookupAnySubdoc (tcdName $ unL at) subdocs ]
-
-    methodBit = subMethods [ ppFunSig summary links loc doc names typ unicode qual
-                           | L _ (TypeSig lnames (L _ typ)) <- lsigs
-                           , let doc = lookupAnySubdoc (head names) subdocs
-                                 names = map unLoc lnames ]
-                           -- FIXME: is taking just the first name ok? Is it possible that
-                           -- there are different subdocs for different names in a single
-                           -- type signature?
-
-    instancesBit = ppInstances instances nm unicode qual 
-
-ppClassDecl _ _ _ _ _ _ _ _ _ = error "declaration type not supported by ppShortClassDecl"
-
-
-ppInstances :: [DocInstance DocName] -> DocName -> Bool -> Qualification -> Html
-ppInstances instances baseName unicode qual
-  = subInstances qual instName (map instDecl instances)
-  where
-    instName = getOccString $ getName baseName
-    instDecl :: DocInstance DocName -> SubDecl
-    instDecl (inst, maybeDoc) = (instHead inst, maybeDoc, [])
-    instHead ([],   n, ts) = ppAppNameTypes n ts unicode qual
-    instHead (ctxt, n, ts) = ppContextNoLocs ctxt unicode qual
-        <+> ppAppNameTypes n ts unicode qual
-
-
-lookupAnySubdoc :: (Eq name1) =>
-                   name1 -> [(name1, DocForDecl name2)] -> DocForDecl name2
-lookupAnySubdoc n subdocs = case lookup n subdocs of
-  Nothing -> noDocForDecl
-  Just docs -> docs
-
-
--------------------------------------------------------------------------------
--- * Data & newtype declarations
--------------------------------------------------------------------------------
-
-
--- TODO: print contexts
-ppShortDataDecl :: Bool -> LinksInfo -> SrcSpan -> TyClDecl DocName -> Bool
-                -> Qualification -> Html
-ppShortDataDecl summary _links _loc dataDecl unicode qual
-
-  | [] <- cons = dataHeader 
-
-  | [lcon] <- cons, ResTyH98 <- resTy,
-    (cHead,cBody,cFoot) <- ppShortConstrParts summary (unLoc lcon) unicode qual
-       = (dataHeader <+> equals <+> cHead) +++ cBody +++ cFoot
-
-  | ResTyH98 <- resTy = dataHeader
-      +++ shortSubDecls (zipWith doConstr ('=':repeat '|') cons)
-
-  | otherwise = (dataHeader <+> keyword "where")
-      +++ shortSubDecls (map doGADTConstr cons)
-
-  where
-    dataHeader = ppDataHeader summary dataDecl unicode qual
-    doConstr c con = toHtml [c] <+> ppShortConstr summary (unLoc con) unicode qual
-    doGADTConstr con = ppShortConstr summary (unLoc con) unicode qual
-
-    cons      = tcdCons dataDecl
-    resTy     = (con_res . unLoc . head) cons
-
-
-ppDataDecl :: Bool -> LinksInfo -> [DocInstance DocName] ->
-              [(DocName, DocForDecl DocName)] ->
-              SrcSpan -> Maybe (Doc DocName) -> TyClDecl DocName -> Bool ->
-              Qualification -> Html
-ppDataDecl summary links instances subdocs loc mbDoc dataDecl unicode qual
-
-  | summary   = ppShortDataDecl summary links loc dataDecl unicode qual
-  | otherwise = header_ +++ maybeDocSection qual mbDoc +++ constrBit +++ instancesBit
-
-  where
-    docname   = unLoc . tcdLName $ dataDecl
-    cons      = tcdCons dataDecl
-    resTy     = (con_res . unLoc . head) cons
-
-    header_ = topDeclElem links loc [docname] (ppDataHeader summary dataDecl unicode qual
-             <+> whereBit)
-
-    whereBit
-      | null cons = noHtml
-      | otherwise = case resTy of
-        ResTyGADT _ -> keyword "where"
-        _ -> noHtml
-
-    constrBit = subConstructors qual
-      (map (ppSideBySideConstr subdocs unicode qual) cons)
-
-    instancesBit = ppInstances instances docname unicode qual
-
-
-
-ppShortConstr :: Bool -> ConDecl DocName -> Bool -> Qualification -> Html
-ppShortConstr summary con unicode qual = cHead <+> cBody <+> cFoot
-  where
-    (cHead,cBody,cFoot) = ppShortConstrParts summary con unicode qual
-
-
--- returns three pieces: header, body, footer so that header & footer can be
--- incorporated into the declaration
-ppShortConstrParts :: Bool -> ConDecl DocName -> Bool -> Qualification -> (Html, Html, Html)
-ppShortConstrParts summary con unicode qual = case con_res con of
-  ResTyH98 -> case con_details con of
-    PrefixCon args ->
-      (header_ unicode qual +++ hsep (ppBinder summary occ
-            : map (ppLParendType unicode qual) args), noHtml, noHtml)
-    RecCon fields ->
-      (header_ unicode qual +++ ppBinder summary occ <+> char '{',
-       doRecordFields fields,
-       char '}')
-    InfixCon arg1 arg2 ->
-      (header_ unicode qual +++ hsep [ppLParendType unicode qual arg1,
-            ppBinder summary occ, ppLParendType unicode qual arg2],
-       noHtml, noHtml)
-
-  ResTyGADT resTy -> case con_details con of
-    -- prefix & infix could use hsConDeclArgTys if it seemed to
-    -- simplify the code.
-    PrefixCon args -> (doGADTCon args resTy, noHtml, noHtml)
-    -- display GADT records with the new syntax,
-    -- Constr :: (Context) => { field :: a, field2 :: b } -> Ty (a, b)
-    -- (except each field gets its own line in docs, to match
-    -- non-GADT records)
-    RecCon fields -> (ppBinder summary occ <+> dcolon unicode <+>
-                            ppForAll forall ltvs lcontext unicode qual <+> char '{',
-                            doRecordFields fields,
-                            char '}' <+> arrow unicode <+> ppLType unicode qual resTy)
-    InfixCon arg1 arg2 -> (doGADTCon [arg1, arg2] resTy, noHtml, noHtml)
-
-  where
-    doRecordFields fields = shortSubDecls (map (ppShortField summary unicode qual) fields)
-    doGADTCon args resTy = ppBinder summary occ <+> dcolon unicode <+> hsep [
-                             ppForAll forall ltvs lcontext unicode qual,
-                             ppLType unicode qual (foldr mkFunTy resTy args) ]
-
-    header_  = ppConstrHdr forall tyVars context
-    occ      = nameOccName . getName . unLoc . con_name $ con
-    ltvs     = con_qvars con
-    tyVars   = tyvarNames ltvs
-    lcontext = con_cxt con
-    context  = unLoc (con_cxt con)
-    forall   = con_explicit con
-    mkFunTy a b = noLoc (HsFunTy a b)
-
-
--- ppConstrHdr is for (non-GADT) existentials constructors' syntax
-ppConstrHdr :: HsExplicitFlag -> [Name] -> HsContext DocName -> Bool
-            -> Qualification -> Html
-ppConstrHdr forall tvs ctxt unicode qual
- = (if null tvs then noHtml else ppForall)
-   +++
-   (if null ctxt then noHtml else ppContextNoArrow ctxt unicode qual
-        <+> darrow unicode +++ toHtml " ")
-  where
-    ppForall = case forall of
-      Explicit -> forallSymbol unicode <+> hsep (map ppName tvs) <+> toHtml ". "
-      Implicit -> noHtml
-
-
-ppSideBySideConstr :: [(DocName, DocForDecl DocName)] -> Bool -> Qualification
-                   -> LConDecl DocName -> SubDecl
-ppSideBySideConstr subdocs unicode qual (L _ con) = (decl, mbDoc, fieldPart)
- where
-    decl = case con_res con of
-      ResTyH98 -> case con_details con of
-        PrefixCon args ->
-          hsep ((header_ unicode qual +++ ppBinder False occ)
-            : map (ppLParendType unicode qual) args)
-
-        RecCon _ -> header_ unicode qual +++ ppBinder False occ
-
-        InfixCon arg1 arg2 ->
-          hsep [header_ unicode qual +++ ppLParendType unicode qual arg1,
-            ppBinder False occ,
-            ppLParendType unicode qual arg2]
-
-      ResTyGADT resTy -> case con_details con of
-        -- prefix & infix could also use hsConDeclArgTys if it seemed to
-        -- simplify the code.
-        PrefixCon args -> doGADTCon args resTy
-        cd@(RecCon _) -> doGADTCon (hsConDeclArgTys cd) resTy
-        InfixCon arg1 arg2 -> doGADTCon [arg1, arg2] resTy
-
-    fieldPart = case con_details con of
-        RecCon fields -> [doRecordFields fields]
-        _ -> []
-
-    doRecordFields fields = subFields qual
-      (map (ppSideBySideField subdocs unicode qual) fields)
-    doGADTCon :: [LHsType DocName] -> Located (HsType DocName) -> Html
-    doGADTCon args resTy =
-      ppBinder False occ <+> dcolon unicode
-        <+> hsep [ppForAll forall ltvs (con_cxt con) unicode qual,
-                  ppLType unicode qual (foldr mkFunTy resTy args) ]
-
-    header_ = ppConstrHdr forall tyVars context
-    occ     = nameOccName . getName . unLoc . con_name $ con
-    ltvs    = con_qvars con
-    tyVars  = tyvarNames (con_qvars con)
-    context = unLoc (con_cxt con)
-    forall  = con_explicit con
-    -- don't use "con_doc con", in case it's reconstructed from a .hi file,
-    -- or also because we want Haddock to do the doc-parsing, not GHC.
-    -- 'join' is in Maybe.
-    mbDoc = join $ fmap fst $ lookup (unLoc $ con_name con) subdocs
-    mkFunTy a b = noLoc (HsFunTy a b)
-
-
-ppSideBySideField :: [(DocName, DocForDecl DocName)] -> Bool -> Qualification
-                  -> ConDeclField DocName ->  SubDecl
-ppSideBySideField subdocs unicode qual (ConDeclField (L _ name) ltype _) =
-  (ppBinder False (nameOccName . getName $ name) <+> dcolon unicode <+> ppLType unicode qual ltype,
-    mbDoc,
-    [])
-  where
-    -- don't use cd_fld_doc for same reason we don't use con_doc above
-    mbDoc = join $ fmap fst $ lookup name subdocs
-
-
-ppShortField :: Bool -> Bool -> Qualification -> ConDeclField DocName -> Html
-ppShortField summary unicode qual (ConDeclField (L _ name) ltype _)
-  = ppBinder summary (nameOccName . getName $ name)
-    <+> dcolon unicode <+> ppLType unicode qual ltype
-
-
--- | Print the LHS of a data\/newtype declaration.
--- Currently doesn't handle 'data instance' decls or kind signatures
-ppDataHeader :: Bool -> TyClDecl DocName -> Bool -> Qualification -> Html
-ppDataHeader summary decl unicode qual
-  | not (isDataDecl decl) = error "ppDataHeader: illegal argument"
-  | otherwise =
-    -- newtype or data
-    (if tcdND decl == NewType then keyword "newtype" else keyword "data") <+>
-    -- context
-    ppLContext (tcdCtxt decl) unicode qual <+>
-    -- T a b c ..., or a :+: b
-    ppTyClBinderWithVars summary decl
-
-
---------------------------------------------------------------------------------
--- * Types and contexts
---------------------------------------------------------------------------------
-
-
-ppKind :: Outputable a => a -> Html
-ppKind k = toHtml $ showSDoc (ppr k)
-
-
-ppBang :: HsBang -> Html
-ppBang HsNoBang = noHtml
-ppBang _        = toHtml "!" -- Unpacked args is an implementation detail,
-                             -- so we just show the strictness annotation
-
-
-tupleParens :: Boxity -> [Html] -> Html
-tupleParens Boxed   = parenList
-tupleParens Unboxed = ubxParenList
-
-
---------------------------------------------------------------------------------
--- * Rendering of HsType
---------------------------------------------------------------------------------
-
-
-pREC_TOP, pREC_FUN, pREC_OP, pREC_CON :: Int
-
-pREC_TOP = (0 :: Int)   -- type in ParseIface.y in GHC
-pREC_FUN = (1 :: Int)   -- btype in ParseIface.y in GHC
-                        -- Used for LH arg of (->)
-pREC_OP  = (2 :: Int)   -- Used for arg of any infix operator
-                        -- (we don't keep their fixities around)
-pREC_CON = (3 :: Int)   -- Used for arg of type applicn:
-                        -- always parenthesise unless atomic
-
-maybeParen :: Int           -- Precedence of context
-           -> Int           -- Precedence of top-level operator
-           -> Html -> Html  -- Wrap in parens if (ctxt >= op)
-maybeParen ctxt_prec op_prec p | ctxt_prec >= op_prec = parens p
-                               | otherwise            = p
-
-
-ppLType, ppLParendType, ppLFunLhType :: Bool -> Qualification
-                                     -> Located (HsType DocName) -> Html
-ppLType       unicode qual y = ppType unicode qual (unLoc y)
-ppLParendType unicode qual y = ppParendType unicode qual (unLoc y)
-ppLFunLhType  unicode qual y = ppFunLhType unicode qual (unLoc y)
-
-
-ppType, ppParendType, ppFunLhType :: Bool -> Qualification-> HsType DocName -> Html
-ppType       unicode qual ty = ppr_mono_ty pREC_TOP ty unicode qual
-ppParendType unicode qual ty = ppr_mono_ty pREC_CON ty unicode qual
-ppFunLhType  unicode qual ty = ppr_mono_ty pREC_FUN ty unicode qual
-
-
--- Drop top-level for-all type variables in user style
--- since they are implicit in Haskell
-
-ppForAll :: HsExplicitFlag -> [Located (HsTyVarBndr DocName)]
-         -> Located (HsContext DocName) -> Bool -> Qualification -> Html
-ppForAll expl tvs cxt unicode qual
-  | show_forall = forall_part <+> ppLContext cxt unicode qual
-  | otherwise   = ppLContext cxt unicode qual
-  where
-    show_forall = not (null tvs) && is_explicit
-    is_explicit = case expl of {Explicit -> True; Implicit -> False}
-    forall_part = hsep (forallSymbol unicode : ppTyVars tvs) +++ dot
-
-
-ppr_mono_lty :: Int -> LHsType DocName -> Bool -> Qualification -> Html
-ppr_mono_lty ctxt_prec ty unicode qual = ppr_mono_ty ctxt_prec (unLoc ty) unicode qual
-
-
-ppr_mono_ty :: Int -> HsType DocName -> Bool -> Qualification -> Html
-ppr_mono_ty ctxt_prec (HsForAllTy expl tvs ctxt ty) unicode qual
-  = maybeParen ctxt_prec pREC_FUN $
-    hsep [ppForAll expl tvs ctxt unicode qual, ppr_mono_lty pREC_TOP ty unicode qual]
-
-ppr_mono_ty _         (HsBangTy b ty)     u q = ppBang b +++ ppLParendType u q ty
-ppr_mono_ty _         (HsTyVar name)      _ q = ppDocName q name
-ppr_mono_ty ctxt_prec (HsFunTy ty1 ty2)   u q = ppr_fun_ty ctxt_prec ty1 ty2 u q
-ppr_mono_ty _         (HsTupleTy con tys) u q = tupleParens con (map (ppLType u q) tys)
-ppr_mono_ty _         (HsKindSig ty kind) u q =
-    parens (ppr_mono_lty pREC_TOP ty u q <+> dcolon u <+> ppKind kind)
-ppr_mono_ty _         (HsListTy ty)       u q = brackets (ppr_mono_lty pREC_TOP ty u q)
-ppr_mono_ty _         (HsPArrTy ty)       u q = pabrackets (ppr_mono_lty pREC_TOP ty u q)
-ppr_mono_ty _         (HsPredTy p)        u q = parens (ppPred u q p)
-ppr_mono_ty _         (HsSpliceTy {})     _ _ = error "ppr_mono_ty HsSpliceTy"
-#if __GLASGOW_HASKELL__ == 612
-ppr_mono_ty _         (HsSpliceTyOut {})  _ _ = error "ppr_mono_ty HsQuasiQuoteTy"
-#else
-ppr_mono_ty _         (HsQuasiQuoteTy {}) _ _ = error "ppr_mono_ty HsQuasiQuoteTy"
-#endif
-ppr_mono_ty _         (HsRecTy {})        _ _ = error "ppr_mono_ty HsRecTy"
-ppr_mono_ty _         (HsCoreTy {})       _ _ = error "ppr_mono_ty HsCoreTy"
-
-ppr_mono_ty ctxt_prec (HsAppTy fun_ty arg_ty) unicode qual
-  = maybeParen ctxt_prec pREC_CON $
-    hsep [ppr_mono_lty pREC_FUN fun_ty unicode qual, ppr_mono_lty pREC_CON arg_ty unicode qual]
-
-ppr_mono_ty ctxt_prec (HsOpTy ty1 op ty2) unicode qual
-  = maybeParen ctxt_prec pREC_FUN $
-    ppr_mono_lty pREC_OP ty1 unicode qual <+> ppr_op <+> ppr_mono_lty pREC_OP ty2 unicode qual
-  where
-    ppr_op = if not (isSymOcc occName) then quote (ppLDocName qual op) else ppLDocName qual op
-    occName = nameOccName . getName . unLoc $ op
-
-ppr_mono_ty ctxt_prec (HsParTy ty) unicode qual
---  = parens (ppr_mono_lty pREC_TOP ty)
-  = ppr_mono_lty ctxt_prec ty unicode qual
-
-ppr_mono_ty ctxt_prec (HsDocTy ty _) unicode qual
-  = ppr_mono_lty ctxt_prec ty unicode qual
-
-
-ppr_fun_ty :: Int -> LHsType DocName -> LHsType DocName -> Bool -> Qualification -> Html
-ppr_fun_ty ctxt_prec ty1 ty2 unicode qual
-  = let p1 = ppr_mono_lty pREC_FUN ty1 unicode qual
-        p2 = ppr_mono_lty pREC_TOP ty2 unicode qual
-    in
-    maybeParen ctxt_prec pREC_FUN $
-    hsep [p1, arrow unicode <+> p2]
-
-
diff --git a/src/Haddock/Backends/Xhtml/DocMarkup.hs b/src/Haddock/Backends/Xhtml/DocMarkup.hs
deleted file mode 100644
--- a/src/Haddock/Backends/Xhtml/DocMarkup.hs
+++ /dev/null
@@ -1,124 +0,0 @@
------------------------------------------------------------------------------
--- |
--- Module      :  Haddock.Backends.Html.DocMarkup
--- Copyright   :  (c) Simon Marlow   2003-2006,
---                    David Waern    2006-2009,
---                    Mark Lentczner 2010
--- License     :  BSD-like
---
--- Maintainer  :  haddock@projects.haskell.org
--- Stability   :  experimental
--- Portability :  portable
------------------------------------------------------------------------------
-module Haddock.Backends.Xhtml.DocMarkup (
-  docToHtml,
-  rdrDocToHtml,
-  origDocToHtml,
-
-  docElement, docSection, maybeDocSection,
-) where
-
-
-import Haddock.Backends.Xhtml.Names
-import Haddock.Backends.Xhtml.Utils
-import Haddock.GhcUtils
-import Haddock.Types
-import Haddock.Utils
-
-import Text.XHtml hiding ( name, title, p, quote )
-
-import GHC
-import Name
-import RdrName
-
-
-parHtmlMarkup :: (a -> Html) -> (a -> Bool) -> DocMarkup a Html
-parHtmlMarkup ppId isTyCon = Markup {
-  markupEmpty         = noHtml,
-  markupString        = toHtml,
-  markupParagraph     = paragraph,
-  markupAppend        = (+++),
-  markupIdentifier    = thecode . ppId . choose,
-  markupModule        = \m -> let (mdl,ref) = break (=='#') m
-                              in ppModuleRef (mkModuleNoPackage mdl) ref,
-  markupEmphasis      = emphasize,
-  markupMonospaced    = thecode,
-  markupUnorderedList = unordList,
-  markupOrderedList   = ordList,
-  markupDefList       = defList,
-  markupCodeBlock     = pre,
-  markupURL           = \url -> anchor ! [href url] << url,
-  markupAName         = \aname -> namedAnchor aname << "",
-  markupPic           = \path -> image ! [src path],
-  markupExample       = examplesToHtml
-  }
-  where
-    -- If an id can refer to multiple things, we give precedence to type
-    -- constructors.  This should ideally be done during renaming from RdrName
-    -- to Name, but since we will move this process from GHC into Haddock in
-    -- the future, we fix it here in the meantime.
-    -- TODO: mention this rule in the documentation.
-    choose [] = error "empty identifier list in HsDoc"
-    choose [x] = x
-    choose (x:y:_)
-      | isTyCon x = x
-      | otherwise = y
-
-    examplesToHtml l = pre (concatHtml $ map exampleToHtml l) ! [theclass "screen"]
-
-    exampleToHtml (Example expression result) = htmlExample
-      where
-        htmlExample = htmlPrompt +++ htmlExpression +++ toHtml (unlines result)
-        htmlPrompt = (thecode . toHtml $ ">>> ") ! [theclass "prompt"]
-        htmlExpression = (strong . thecode . toHtml $ expression ++ "\n") ! [theclass "userinput"]
-
-
--- If the doc is a single paragraph, don't surround it with <P> (this causes
--- ugly extra whitespace with some browsers).  FIXME: Does this still apply?
-docToHtml :: Qualification -> Doc DocName -> Html
-docToHtml qual = markup fmt . cleanup
-  where fmt = parHtmlMarkup (ppDocName qual) (isTyConName . getName)
-
-
-origDocToHtml :: Doc Name -> Html
-origDocToHtml = markup fmt . cleanup
-  where fmt = parHtmlMarkup ppName isTyConName
-
-
-rdrDocToHtml :: Doc RdrName -> Html
-rdrDocToHtml = markup fmt . cleanup
-  where fmt = parHtmlMarkup ppRdrName isRdrTc
-
-
-docElement :: (Html -> Html) -> Html -> Html
-docElement el content_ =
-  if isNoHtml content_
-    then el ! [theclass "doc empty"] << spaceHtml
-    else el ! [theclass "doc"] << content_
-
-
-docSection :: Qualification -> Doc DocName -> Html
-docSection qual = (docElement thediv <<) . docToHtml qual
-
-
-maybeDocSection :: Qualification -> Maybe (Doc DocName) -> Html
-maybeDocSection qual = maybe noHtml (docSection qual)
-
-
-cleanup :: Doc a -> Doc a
-cleanup = markup fmtUnParagraphLists
-  where
-    -- If there is a single paragraph, then surrounding it with <P>..</P>
-    -- can add too much whitespace in some browsers (eg. IE).  However if
-    -- we have multiple paragraphs, then we want the extra whitespace to
-    -- separate them.  So we catch the single paragraph case and transform it
-    -- here. We don't do this in code blocks as it eliminates line breaks.
-    unParagraph :: Doc a -> Doc a
-    unParagraph (DocParagraph d) = d
-    unParagraph doc              = doc
-
-    fmtUnParagraphLists :: DocMarkup a (Doc a)
-    fmtUnParagraphLists = idMarkup {
-      markupUnorderedList = DocUnorderedList . map unParagraph,
-      markupOrderedList   = DocOrderedList   . map unParagraph
-      }
diff --git a/src/Haddock/Backends/Xhtml/Layout.hs b/src/Haddock/Backends/Xhtml/Layout.hs
deleted file mode 100644
--- a/src/Haddock/Backends/Xhtml/Layout.hs
+++ /dev/null
@@ -1,210 +0,0 @@
------------------------------------------------------------------------------
--- |
--- Module      :  Haddock.Backends.Html.Layout
--- Copyright   :  (c) Simon Marlow   2003-2006,
---                    David Waern    2006-2009,
---                    Mark Lentczner 2010
--- License     :  BSD-like
---
--- Maintainer  :  haddock@projects.haskell.org
--- Stability   :  experimental
--- Portability :  portable
------------------------------------------------------------------------------
-module Haddock.Backends.Xhtml.Layout (
-  miniBody,
-
-  divPackageHeader, divContent, divModuleHeader, divFooter,
-  divTableOfContents, divDescription, divSynposis, divInterface,
-  divIndex, divAlphabet, divModuleList,
-
-  sectionName,
-
-  shortDeclList,
-  shortSubDecls,
-
-  divTopDecl,
-
-  SubDecl,
-  subArguments,
-  subAssociatedTypes,
-  subConstructors,
-  subFields,
-  subInstances,
-  subMethods,
-
-  topDeclElem, declElem,
-) where
-
-
-import Haddock.Backends.Xhtml.DocMarkup
-import Haddock.Backends.Xhtml.Types
-import Haddock.Backends.Xhtml.Utils
-import Haddock.Types
-import Haddock.Utils (makeAnchorId)
-
-import qualified Data.Map as Map
-import Text.XHtml hiding ( name, title, p, quote )
-
-import FastString            ( unpackFS )
-import GHC
-
-
---------------------------------------------------------------------------------
--- * Sections of the document
---------------------------------------------------------------------------------
-
-
-miniBody :: Html -> Html
-miniBody = body ! [identifier "mini"]
-
-
-sectionDiv :: String -> Html -> Html
-sectionDiv i = thediv ! [identifier i]
-
-
-sectionName :: Html -> Html
-sectionName = paragraph ! [theclass "caption"]
-
-
-divPackageHeader, divContent, divModuleHeader, divFooter,
-  divTableOfContents, divDescription, divSynposis, divInterface,
-  divIndex, divAlphabet, divModuleList
-    :: Html -> Html
-
-divPackageHeader    = sectionDiv "package-header"
-divContent          = sectionDiv "content"
-divModuleHeader     = sectionDiv "module-header"
-divFooter           = sectionDiv "footer"
-divTableOfContents  = sectionDiv "table-of-contents"
-divDescription      = sectionDiv "description"
-divSynposis         = sectionDiv "synopsis"
-divInterface        = sectionDiv "interface"
-divIndex            = sectionDiv "index"
-divAlphabet         = sectionDiv "alphabet"
-divModuleList       = sectionDiv "module-list"
-
-
---------------------------------------------------------------------------------
--- * Declaration containers
---------------------------------------------------------------------------------
-
-
-shortDeclList :: [Html] -> Html
-shortDeclList items = ulist << map (li ! [theclass "src short"] <<) items
-
-
-shortSubDecls :: [Html] -> Html
-shortSubDecls items = ulist ! [theclass "subs"] << map (li <<) items
-
-
-divTopDecl :: Html -> Html
-divTopDecl = thediv ! [theclass "top"]
-
-
-type SubDecl = (Html, Maybe (Doc DocName), [Html])
-
-
-divSubDecls :: (HTML a) => String -> a -> Maybe Html -> Html
-divSubDecls cssClass captionName = maybe noHtml wrap
-  where
-    wrap = (subSection <<) . (subCaption +++)
-    subSection = thediv ! [theclass $ unwords ["subs", cssClass]]
-    subCaption = paragraph ! [theclass "caption"] << captionName
-
-
-subDlist :: Qualification -> [SubDecl] -> Maybe Html
-subDlist _ [] = Nothing
-subDlist qual decls = Just $ dlist << map subEntry decls +++ clearDiv
-  where
-    subEntry (decl, mdoc, subs) =
-      dterm ! [theclass "src"] << decl
-      +++
-      docElement ddef << (fmap (docToHtml qual) mdoc +++ subs)
-
-    clearDiv = thediv ! [ theclass "clear" ] << noHtml
-
-
-subTable :: Qualification -> [SubDecl] -> Maybe Html
-subTable _ [] = Nothing
-subTable qual decls = Just $ table << aboves (concatMap subRow decls)
-  where
-    subRow (decl, mdoc, subs) =
-      (td ! [theclass "src"] << decl
-       <->
-       docElement td << fmap (docToHtml qual) mdoc)
-      : map (cell . (td <<)) subs
-
-
-subBlock :: [Html] -> Maybe Html
-subBlock [] = Nothing
-subBlock hs = Just $ toHtml hs
-
-
-subArguments :: Qualification -> [SubDecl] -> Html
-subArguments qual = divSubDecls "arguments" "Arguments" . subTable qual
-
-
-subAssociatedTypes :: [Html] -> Html
-subAssociatedTypes = divSubDecls "associated-types" "Associated Types" . subBlock
-
-
-subConstructors :: Qualification -> [SubDecl] -> Html
-subConstructors qual = divSubDecls "constructors" "Constructors" . subTable qual
-
-
-subFields :: Qualification -> [SubDecl] -> Html
-subFields qual = divSubDecls "fields" "Fields" . subDlist qual
-
-
-subInstances :: Qualification -> String -> [SubDecl] -> Html
-subInstances qual nm = maybe noHtml wrap . instTable
-  where
-    wrap = (subSection <<) . (subCaption +++)
-    instTable = fmap (thediv ! collapseSection id_ True [] <<) . subTable qual
-    subSection = thediv ! [theclass "subs instances"]
-    subCaption = paragraph ! collapseControl id_ True "caption" << "Instances"
-    id_ = makeAnchorId $ "i:" ++ nm
-
-subMethods :: [Html] -> Html
-subMethods = divSubDecls "methods" "Methods" . subBlock
-
-
--- a box for displaying code
-declElem :: Html -> Html
-declElem = paragraph ! [theclass "src"]
-
-
--- a box for top level documented names
--- it adds a source and wiki link at the right hand side of the box
-topDeclElem :: LinksInfo -> SrcSpan -> [DocName] -> Html -> Html
-topDeclElem ((_,_,sourceMap), (_,_,maybe_wiki_url)) loc names html =
-    declElem << (html +++ srcLink +++ wikiLink)
-  where srcLink =
-          case Map.lookup origPkg sourceMap of
-            Nothing  -> noHtml
-            Just url -> let url' = spliceURL (Just fname) (Just origMod)
-                                               (Just n) (Just loc) url
-                          in anchor ! [href url', theclass "link"] << "Source"
-
-        wikiLink =
-          case maybe_wiki_url of
-            Nothing  -> noHtml
-            Just url -> let url' = spliceURL (Just fname) (Just mdl)
-                                               (Just n) (Just loc) url
-                          in anchor ! [href url', theclass "link"] << "Comments"
-
-        -- For source links, we want to point to the original module,
-        -- because only that will have the source.
-        -- TODO: do something about type instances. They will point to
-        -- the module defining the type family, which is wrong.
-        origMod = nameModule n
-        origPkg = modulePackageId origMod
-
-        -- Name must be documented, otherwise we wouldn't get here
-        Documented n mdl = head names
-        -- FIXME: is it ok to simply take the first name?
-
-        fname = case loc of
-                RealSrcSpan l -> unpackFS (srcSpanFile l)
-                UnhelpfulSpan _ -> error "topDeclElem UnhelpfulSpan"
-
diff --git a/src/Haddock/Backends/Xhtml/Names.hs b/src/Haddock/Backends/Xhtml/Names.hs
deleted file mode 100644
--- a/src/Haddock/Backends/Xhtml/Names.hs
+++ /dev/null
@@ -1,123 +0,0 @@
------------------------------------------------------------------------------
--- |
--- Module      :  Haddock.Backends.Html.Names
--- Copyright   :  (c) Simon Marlow   2003-2006,
---                    David Waern    2006-2009,
---                    Mark Lentczner 2010
--- License     :  BSD-like
---
--- Maintainer  :  haddock@projects.haskell.org
--- Stability   :  experimental
--- Portability :  portable
------------------------------------------------------------------------------
-module Haddock.Backends.Xhtml.Names (
-  ppName, ppDocName, ppLDocName, ppRdrName,
-  ppBinder, ppBinder',
-  ppModule, ppModuleRef,
-  linkId
-) where
-
-
-import Haddock.Backends.Xhtml.Utils
-import Haddock.GhcUtils
-import Haddock.Types
-import Haddock.Utils
-
-import Text.XHtml hiding ( name, title, p, quote )
-import qualified Data.List as List
-
-import GHC
-import Name
-import RdrName
-
-
-ppOccName :: OccName -> Html
-ppOccName = toHtml . occNameString
-
-
-ppRdrName :: RdrName -> Html
-ppRdrName = ppOccName . rdrNameOcc
-
-
-ppLDocName :: Qualification -> Located DocName -> Html
-ppLDocName qual (L _ d) = ppDocName qual d
-
-
-ppDocName :: Qualification -> DocName -> Html
-ppDocName qual docName =
-  case docName of
-    Documented name mdl ->
-      linkIdOcc mdl (Just (nameOccName name)) << ppQualifyName qual name mdl
-    Undocumented name -> ppQualifyName qual name (nameModule name)
-
-
--- | Render a name depending on the selected qualification mode
-ppQualifyName :: Qualification -> Name -> Module -> Html
-ppQualifyName qual name mdl =
-  case qual of
-    NoQual   -> ppName name
-    FullQual -> ppFullQualName mdl name
-    -- this is just in case, it should never happen
-    LocalQual Nothing -> ppQualifyName FullQual name mdl
-    LocalQual (Just localmdl)
-      | moduleString mdl == moduleString localmdl -> ppName name
-      | otherwise -> ppFullQualName mdl name
-    -- again, this never happens
-    RelativeQual Nothing -> ppQualifyName FullQual name mdl
-    RelativeQual (Just localmdl) ->
-      case List.stripPrefix (moduleString localmdl) (moduleString mdl) of
-        -- local, A.x -> x
-        Just []      -> ppQualifyName NoQual name mdl
-        -- sub-module, A.B.x -> B.x
-        Just ('.':m) -> toHtml $ m ++ '.' : getOccString name
-        -- some module with same prefix, ABC.x -> ABC.x
-        Just _       -> ppQualifyName FullQual name mdl
-        -- some other module, D.x -> D.x
-        Nothing      -> ppQualifyName FullQual name mdl
-
-
-ppFullQualName :: Module -> Name -> Html
-ppFullQualName mdl name = toHtml $ moduleString mdl ++ '.' : getOccString name
-
-
-ppName :: Name -> Html
-ppName name = toHtml (getOccString name)
-
-
-ppBinder :: Bool -> OccName -> Html
--- The Bool indicates whether we are generating the summary, in which case
--- the binder will be a link to the full definition.
-ppBinder True n = linkedAnchor (nameAnchorId n) << ppBinder' n
-ppBinder False n = namedAnchor (nameAnchorId n) ! [theclass "def"]
-                        << ppBinder' n
-
-
-ppBinder' :: OccName -> Html
-ppBinder' n
-  | isVarSym n = parens $ ppOccName n
-  | otherwise  = ppOccName n
-
-
-linkId :: Module -> Maybe Name -> Html -> Html
-linkId mdl mbName = linkIdOcc mdl (fmap nameOccName mbName)
-
-
-linkIdOcc :: Module -> Maybe OccName -> Html -> Html
-linkIdOcc mdl mbName = anchor ! [href url]
-  where
-    url = case mbName of
-      Nothing   -> moduleUrl mdl
-      Just name -> moduleNameUrl mdl name
-
-
-ppModule :: Module -> Html
-ppModule mdl = anchor ! [href (moduleUrl mdl)]
-               << toHtml (moduleString mdl)
-
-
-ppModuleRef :: Module -> String -> Html
-ppModuleRef mdl ref = anchor ! [href (moduleUrl mdl ++ ref)]
-                      << toHtml (moduleString mdl)
-    -- NB: The ref parameter already includes the '#'.
-    -- This function is only called from markupModule expanding a
-    -- DocModule, which doesn't seem to be ever be used.
diff --git a/src/Haddock/Backends/Xhtml/Themes.hs b/src/Haddock/Backends/Xhtml/Themes.hs
deleted file mode 100644
--- a/src/Haddock/Backends/Xhtml/Themes.hs
+++ /dev/null
@@ -1,209 +0,0 @@
------------------------------------------------------------------------------
--- |
--- Module      :  Haddock.Backends.Html.Themes
--- Copyright   :  (c) Mark Lentczner 2010
--- License     :  BSD-like
---
--- Maintainer  :  haddock@projects.haskell.org
--- Stability   :  experimental
--- Portability :  portable
------------------------------------------------------------------------------
-module Haddock.Backends.Xhtml.Themes (
-    Themes,
-    getThemes,
-
-    cssFiles, styleSheet
-    )
-    where
-
-import Haddock.Options
-
-import Control.Applicative
-import Control.Monad (liftM)
-import Data.Char (toLower)
-import Data.Either (lefts, rights)
-import Data.List (nub)
-import Data.Maybe (isJust, listToMaybe)
-
-import System.Directory
-import System.FilePath
-import Text.XHtml hiding ( name, title, p, quote, (</>) )
-import qualified Text.XHtml as XHtml
-
-
---------------------------------------------------------------------------------
--- * CSS Themes
---------------------------------------------------------------------------------
-
-data Theme = Theme {
-  themeName :: String,
-  themeHref :: String,
-  themeFiles :: [FilePath]
-  }
-
-type Themes = [Theme]
-
-type PossibleTheme = Either String Theme
-type PossibleThemes = Either String Themes
-
-
--- | Find a theme by name (case insensitive match)
-findTheme :: String -> Themes -> Maybe Theme
-findTheme s = listToMaybe . filter ((== ls).lower.themeName)
-  where lower = map toLower
-        ls = lower s
-
-
--- | Standard theme used by default
-standardTheme :: FilePath -> IO PossibleThemes
-standardTheme libDir = liftM (liftEither (take 1)) (defaultThemes libDir)
-
-
--- | Default themes that are part of Haddock; added with --default-themes
--- The first theme in this list is considered the standard theme.
--- Themes are "discovered" by scanning the html sub-dir of the libDir,
--- and looking for directories with the extension .theme or .std-theme.
--- The later is, obviously, the standard theme.
-defaultThemes :: FilePath -> IO PossibleThemes
-defaultThemes libDir = do
-  themeDirs <- getDirectoryItems (libDir </> "html")
-  themes <- mapM directoryTheme $ discoverThemes themeDirs
-  return $ sequenceEither themes
-  where
-    discoverThemes paths =
-      filterExt ".std-theme" paths ++ filterExt ".theme" paths
-    filterExt ext = filter ((== ext).takeExtension)
-
-
--- | Build a theme from a single .css file
-singleFileTheme :: FilePath -> IO PossibleTheme
-singleFileTheme path =
-  if isCssFilePath path
-      then retRight $ Theme name file [path]
-      else errMessage "File extension isn't .css" path
-  where
-    name = takeBaseName path
-    file = takeFileName path
-
-
--- | Build a theme from a directory
-directoryTheme :: FilePath -> IO PossibleTheme
-directoryTheme path = do
-  items <- getDirectoryItems path
-  case filter isCssFilePath items of
-    [cf] -> retRight $ Theme (takeBaseName path) (takeFileName cf) items
-    [] -> errMessage "No .css file in theme directory" path
-    _ -> errMessage "More than one .css file in theme directory" path
-
-
--- | Check if we have a built in theme
-doesBuiltInExist :: IO PossibleThemes -> String -> IO Bool
-doesBuiltInExist pts s = fmap (either (const False) test) pts
-  where test = isJust . findTheme s
-
-
--- | Find a built in theme
-builtInTheme :: IO PossibleThemes -> String -> IO PossibleTheme
-builtInTheme pts s = either Left fetch <$> pts
-  where fetch = maybe (Left ("Unknown theme: " ++ s)) Right . findTheme s
-
-
---------------------------------------------------------------------------------
--- * CSS Theme Arguments
---------------------------------------------------------------------------------
-
--- | Process input flags for CSS Theme arguments
-getThemes :: FilePath -> [Flag] -> IO PossibleThemes
-getThemes libDir flags =
-  liftM concatEither (mapM themeFlag flags) >>= someTheme
-  where
-    themeFlag :: Flag -> IO (Either String Themes)
-    themeFlag (Flag_CSS path) = (liftM . liftEither) (:[]) (theme path)
-    themeFlag (Flag_BuiltInThemes) = builtIns
-    themeFlag _ = retRight []
-
-    theme :: FilePath -> IO PossibleTheme
-    theme path = pick path
-      [(doesFileExist,              singleFileTheme),
-       (doesDirectoryExist,         directoryTheme),
-       (doesBuiltInExist builtIns,  builtInTheme builtIns)]
-      "Theme not found"
-
-    pick :: FilePath
-      -> [(FilePath -> IO Bool, FilePath -> IO PossibleTheme)] -> String
-      -> IO PossibleTheme
-    pick path [] msg = errMessage msg path
-    pick path ((test,build):opts) msg = do
-      pass <- test path
-      if pass then build path else pick path opts msg
-
-
-    someTheme :: Either String Themes -> IO (Either String Themes)
-    someTheme (Right []) = standardTheme libDir
-    someTheme est = return est
-
-    builtIns = defaultThemes libDir
-
-
-errMessage :: String -> FilePath -> IO (Either String a)
-errMessage msg path = return (Left msg')
-  where msg' = "Error: " ++ msg ++ ": \"" ++ path ++ "\"\n"
-
-
-retRight :: a -> IO (Either String a)
-retRight = return . Right
-
-
---------------------------------------------------------------------------------
--- * File Utilities
---------------------------------------------------------------------------------
-
-
-getDirectoryItems :: FilePath -> IO [FilePath]
-getDirectoryItems path =
-  map (combine path) . filter notDot <$> getDirectoryContents path
-  where notDot s = s /= "." && s /= ".."
-
-
-isCssFilePath :: FilePath -> Bool
-isCssFilePath path = takeExtension path == ".css"
-
-
---------------------------------------------------------------------------------
--- * Style Sheet Utilities
---------------------------------------------------------------------------------
-
-cssFiles :: Themes -> [String]
-cssFiles ts = nub $ concatMap themeFiles ts
-
-
-styleSheet :: Themes -> Html
-styleSheet ts = toHtml $ zipWith mkLink rels ts
-  where
-    rels = "stylesheet" : repeat "alternate stylesheet"
-    mkLink aRel t =
-      thelink
-        ! [ href (themeHref t),  rel aRel, thetype "text/css",
-            XHtml.title (themeName t)
-          ]
-        << noHtml
-
---------------------------------------------------------------------------------
--- * Either Utilities
---------------------------------------------------------------------------------
-
--- These three routines are here because Haddock does not have access to the
--- Control.Monad.Error module which supplies the Functor and Monad instances
--- for Either String.
-
-sequenceEither :: [Either a b] -> Either a [b]
-sequenceEither es = maybe (Right $ rights es) Left (listToMaybe (lefts es))
-
-
-liftEither :: (b -> c) -> Either a b -> Either a c
-liftEither f = either Left (Right . f)
-
-
-concatEither :: [Either a [b]] -> Either a [b]
-concatEither = liftEither concat . sequenceEither
-
diff --git a/src/Haddock/Backends/Xhtml/Types.hs b/src/Haddock/Backends/Xhtml/Types.hs
deleted file mode 100644
--- a/src/Haddock/Backends/Xhtml/Types.hs
+++ /dev/null
@@ -1,29 +0,0 @@
------------------------------------------------------------------------------
--- |
--- Module      :  Haddock.Backends.Html.Types
--- Copyright   :  (c) Simon Marlow   2003-2006,
---                    David Waern    2006-2009,
---                    Mark Lentczner 2010
--- License     :  BSD-like
---
--- Maintainer  :  haddock@projects.haskell.org
--- Stability   :  experimental
--- Portability :  portable
------------------------------------------------------------------------------
-module Haddock.Backends.Xhtml.Types (
-  SourceURLs, WikiURLs,
-  LinksInfo
-) where
-
-
-import Data.Map
-import GHC
-
-
--- the base, module and entity URLs for the source code and wiki links.
-type SourceURLs = (Maybe FilePath, Maybe FilePath, Map PackageId FilePath)
-type WikiURLs = (Maybe FilePath, Maybe FilePath, Maybe FilePath)
-
-
--- The URL for source and wiki links
-type LinksInfo = (SourceURLs, WikiURLs)
diff --git a/src/Haddock/Backends/Xhtml/Utils.hs b/src/Haddock/Backends/Xhtml/Utils.hs
deleted file mode 100644
--- a/src/Haddock/Backends/Xhtml/Utils.hs
+++ /dev/null
@@ -1,212 +0,0 @@
------------------------------------------------------------------------------
--- |
--- Module      :  Haddock.Backends.Html.Util
--- Copyright   :  (c) Simon Marlow   2003-2006,
---                    David Waern    2006-2009,
---                    Mark Lentczner 2010
--- License     :  BSD-like
---
--- Maintainer  :  haddock@projects.haskell.org
--- Stability   :  experimental
--- Portability :  portable
------------------------------------------------------------------------------
-module Haddock.Backends.Xhtml.Utils (
-  renderToString,
-
-  namedAnchor, linkedAnchor,
-  spliceURL,
-  groupId,
-
-  (<+>), char, nonEmpty,
-  keyword, punctuate,
-
-  braces, brackets, pabrackets, parens, parenList, ubxParenList,
-  arrow, comma, dcolon, dot, darrow, equals, forallSymbol, quote,
-
-  hsep,
-
-  collapseSection, collapseToggle, collapseControl,
-) where
-
-
-import Haddock.GhcUtils
-import Haddock.Utils
-
-import Data.Maybe
-
-import Text.XHtml hiding ( name, title, p, quote )
-import qualified Text.XHtml as XHtml
-
-import GHC      ( SrcSpan(..), srcSpanStartLine, Name )
-import Module   ( Module )
-import Name     ( getOccString, nameOccName, isValOcc )
-
-
-spliceURL :: Maybe FilePath -> Maybe Module -> Maybe GHC.Name ->
-             Maybe SrcSpan -> String -> String
-spliceURL maybe_file maybe_mod maybe_name maybe_loc url = run url
- where
-  file = fromMaybe "" maybe_file
-  mdl = case maybe_mod of
-          Nothing           -> ""
-          Just m -> moduleString m
-
-  (name, kind) =
-    case maybe_name of
-      Nothing             -> ("","")
-      Just n | isValOcc (nameOccName n) -> (escapeStr (getOccString n), "v")
-             | otherwise -> (escapeStr (getOccString n), "t")
-
-  line = case maybe_loc of
-    Nothing -> ""
-    Just span_ ->
-      case span_ of
-      RealSrcSpan span__ ->
-        show $ srcSpanStartLine span__
-      UnhelpfulSpan _ ->
-        error "spliceURL UnhelpfulSpan"
-
-  run "" = ""
-  run ('%':'M':rest) = mdl  ++ run rest
-  run ('%':'F':rest) = file ++ run rest
-  run ('%':'N':rest) = name ++ run rest
-  run ('%':'K':rest) = kind ++ run rest
-  run ('%':'L':rest) = line ++ run rest
-  run ('%':'%':rest) = "%"  ++ run rest
-
-  run ('%':'{':'M':'O':'D':'U':'L':'E':'}':rest) = mdl  ++ run rest
-  run ('%':'{':'F':'I':'L':'E':'}':rest)         = file ++ run rest
-  run ('%':'{':'N':'A':'M':'E':'}':rest)         = name ++ run rest
-  run ('%':'{':'K':'I':'N':'D':'}':rest)         = kind ++ run rest
-
-  run ('%':'{':'M':'O':'D':'U':'L':'E':'/':'.':'/':c:'}':rest) =
-    map (\x -> if x == '.' then c else x) mdl ++ run rest
-
-  run ('%':'{':'F':'I':'L':'E':'/':'/':'/':c:'}':rest) =
-    map (\x -> if x == '/' then c else x) file ++ run rest
-
-  run ('%':'{':'L':'I':'N':'E':'}':rest)         = line ++ run rest
-
-  run (c:rest) = c : run rest
-
-
-renderToString :: Bool -> Html -> String
-renderToString debug html
-  | debug = renderHtml html
-  | otherwise = showHtml html
-
-
-hsep :: [Html] -> Html
-hsep [] = noHtml
-hsep htmls = foldr1 (\a b -> a+++" "+++b) htmls
-
-
-infixr 8 <+>
-(<+>) :: Html -> Html -> Html
-a <+> b = a +++ toHtml " " +++ b
-
-
-keyword :: String -> Html
-keyword s = thespan ! [theclass "keyword"] << toHtml s
-
-
-equals, comma :: Html
-equals = char '='
-comma  = char ','
-
-
-char :: Char -> Html
-char c = toHtml [c]
-
-
--- | Make an element that always has at least something (a non-breaking space)
--- If it would have otherwise been empty, then give it the class ".empty"
-nonEmpty :: (Html -> Html) -> Html -> Html
-nonEmpty el content_ =
-  if isNoHtml content_
-    then el ! [theclass "empty"] << spaceHtml
-    else el << content_
-
-
-quote :: Html -> Html
-quote h = char '`' +++ h +++ '`'
-
-
-parens, brackets, pabrackets, braces :: Html -> Html
-parens h        = char '(' +++ h +++ char ')'
-brackets h      = char '[' +++ h +++ char ']'
-pabrackets h    = toHtml "[:" +++ h +++ toHtml ":]"
-braces h        = char '{' +++ h +++ char '}'
-
-
-punctuate :: Html -> [Html] -> [Html]
-punctuate _ []     = []
-punctuate h (d0:ds) = go d0 ds
-                   where
-                     go d [] = [d]
-                     go d (e:es) = (d +++ h) : go e es
-
-
-parenList :: [Html] -> Html
-parenList = parens . hsep . punctuate comma
-
-
-ubxParenList :: [Html] -> Html
-ubxParenList = ubxparens . hsep . punctuate comma
-
-
-ubxparens :: Html -> Html
-ubxparens h = toHtml "(#" +++ h +++ toHtml "#)"
-
-
-dcolon, arrow, darrow, forallSymbol :: Bool -> Html
-dcolon unicode = toHtml (if unicode then "∷" else "::")
-arrow  unicode = toHtml (if unicode then "→" else "->")
-darrow unicode = toHtml (if unicode then "⇒" else "=>")
-forallSymbol unicode = if unicode then toHtml "∀" else keyword "forall"
-
-
-dot :: Html
-dot = toHtml "."
-
-
--- | Generate a named anchor
-namedAnchor :: String -> Html -> Html
-namedAnchor n = anchor ! [XHtml.name n]
-
-
-linkedAnchor :: String -> Html -> Html
-linkedAnchor n = anchor ! [href ('#':n)]
-
-
--- | generate an anchor identifier for a group
-groupId :: String -> String
-groupId g = makeAnchorId ("g:" ++ g)
-
---
--- A section of HTML which is collapsible.
---
-
--- | Attributes for an area that can be collapsed
-collapseSection :: String -> Bool -> String -> [HtmlAttr]
-collapseSection id_ state classes = [ identifier sid, theclass cs ]
-  where cs = unwords (words classes ++ [pick state "show" "hide"])
-        sid = "section." ++ id_
-
--- | Attributes for an area that toggles a collapsed area
-collapseToggle :: String -> [HtmlAttr]
-collapseToggle id_ = [ strAttr "onclick" js ]
-  where js = "toggleSection('" ++ id_ ++ "')";
-  
--- | Attributes for an area that toggles a collapsed area,
--- and displays a control.
-collapseControl :: String -> Bool -> String -> [HtmlAttr]
-collapseControl id_ state classes =
-  [ identifier cid, theclass cs ] ++ collapseToggle id_
-  where cs = unwords (words classes ++ [pick state "collapser" "expander"])
-        cid = "control." ++ id_
-
-
-pick :: Bool -> a -> a -> a
-pick True  t _ = t
-pick False _ f = f
diff --git a/src/Haddock/Convert.hs b/src/Haddock/Convert.hs
deleted file mode 100644
--- a/src/Haddock/Convert.hs
+++ /dev/null
@@ -1,321 +0,0 @@
-{-# LANGUAGE PatternGuards #-}
------------------------------------------------------------------------------
--- |
--- Module      :  Haddock.Convert
--- Copyright   :  (c) Isaac Dupree 2009,
--- License     :  BSD-like
---
--- Maintainer  :  haddock@projects.haskell.org
--- Stability   :  experimental
--- Portability :  portable
---
--- Conversion between TyThing and HsDecl. This functionality may be moved into
--- GHC at some point.
------------------------------------------------------------------------------
-module Haddock.Convert where
--- Some other functions turned out to be useful for converting
--- instance heads, which aren't TyThings, so just export everything.
-
-
-import HsSyn
-import TcType ( tcSplitTyConApp_maybe, tcSplitSigmaTy )
-import TypeRep
-import Coercion ( splitKindFunTys, synTyConResKind )
-import Name
-import Var
-import Class
-import TyCon
-import DataCon
-import TysPrim ( alphaTyVars )
-import TysWiredIn ( listTyConName )
-import Bag ( emptyBag )
-import SrcLoc ( Located, noLoc, unLoc )
-
-
--- the main function here! yay!
-tyThingToLHsDecl :: TyThing -> LHsDecl Name
-tyThingToLHsDecl t = noLoc $ case t of
-  -- ids (functions and zero-argument a.k.a. CAFs) get a type signature.
-  -- Including built-in functions like seq.
-  -- foreign-imported functions could be represented with ForD
-  -- instead of SigD if we wanted...
-  --
-  -- in a future code version we could turn idVarDetails = foreign-call
-  -- into a ForD instead of a SigD if we wanted.  Haddock doesn't
-  -- need to care.
-  AnId i -> SigD (synifyIdSig ImplicitizeForAll i)
-
-  -- type-constructors (e.g. Maybe) are complicated, put the definition
-  -- later in the file (also it's used for class associated-types too.)
-  ATyCon tc -> TyClD (synifyTyCon tc)
-
-  -- type-constructors (e.g. Maybe) are complicated, put the definition
-  -- later in the file (also it's used for class associated-types too.)
-  ACoAxiom ax -> TyClD (synifyAxiom ax)
-
-  -- a data-constructor alone just gets rendered as a function:
-  ADataCon dc -> SigD (TypeSig [synifyName dc]
-    (synifyType ImplicitizeForAll (dataConUserType dc)))
-  -- classes are just a little tedious
-  AClass cl ->
-    TyClD $ ClassDecl
-      (synifyCtx (classSCTheta cl))
-      (synifyName cl)
-      (synifyTyVars (classTyVars cl))
-      (map (\ (l,r) -> noLoc
-                 (map getName l, map getName r) ) $
-         snd $ classTvsFds cl)
-      (map (noLoc . synifyIdSig DeleteTopLevelQuantification)
-           (classMethods cl))
-      emptyBag --ignore default method definitions, they don't affect signature
-      (map synifyClassAT (classATs cl))
-      [] --we don't have any docs at this point
-
-
--- class associated-types are a subset of TyCon
--- (mainly only type/data-families)
-synifyClassAT :: TyCon -> LTyClDecl Name
-synifyClassAT = noLoc . synifyTyCon
-
-synifyAxiom :: CoAxiom -> TyClDecl Name
-synifyAxiom (CoAxiom { co_ax_tvs = tvs, co_ax_lhs = lhs, co_ax_rhs = rhs })
-  | Just (tc, args) <- tcSplitTyConApp_maybe lhs
-  = let name      = synifyName tc
-        tyvars    = synifyTyVars tvs
-        typats    = map (synifyType WithinType) args
-        hs_rhs_ty = synifyType WithinType rhs
-    in TySynonym name tyvars (Just typats) hs_rhs_ty
-  | otherwise
-  = error "synifyAxiom" 
-
-synifyTyCon :: TyCon -> TyClDecl Name
-synifyTyCon tc
-  | isFunTyCon tc || isPrimTyCon tc =
-    TyData
-      -- arbitrary lie, they are neither algebraic data nor newtype:
-      DataType
-      -- no built-in type has any stupidTheta:
-      (noLoc [])
-      (synifyName tc)
-      -- tyConTyVars doesn't work on fun/prim, but we can make them up:
-      (zipWith
-         (\fakeTyVar realKind -> noLoc $
-             KindedTyVar (getName fakeTyVar) realKind)
-         alphaTyVars --a, b, c... which are unfortunately all kind *
-         (fst . splitKindFunTys $ tyConKind tc)
-      )
-      -- assume primitive types aren't members of data/newtype families:
-      Nothing
-      -- we have their kind accurately:
-      (Just (tyConKind tc))
-      -- no algebraic constructors:
-      []
-      -- "deriving" needn't be specified:
-      Nothing
-  | isSynFamilyTyCon tc =
-      case synTyConRhs tc of
-        SynFamilyTyCon ->
-          TyFamily TypeFamily (synifyName tc) (synifyTyVars (tyConTyVars tc))
-               (Just (synTyConResKind tc))
-        _ -> error "synifyTyCon: impossible open type synonym?"
-  | isDataFamilyTyCon tc = --(why no "isOpenAlgTyCon"?)
-      case algTyConRhs tc of
-        DataFamilyTyCon ->
-          TyFamily DataFamily (synifyName tc) (synifyTyVars (tyConTyVars tc))
-               Nothing --always kind '*'
-        _ -> error "synifyTyCon: impossible open data type?"
-  | otherwise =
-  -- (closed) type, newtype, and data
-  let
-  -- alg_ only applies to newtype/data
-  -- syn_ only applies to type
-  -- others apply to both
-  alg_nd = if isNewTyCon tc then NewType else DataType
-  alg_ctx = synifyCtx (tyConStupidTheta tc)
-  name = synifyName tc
-  tyvars = synifyTyVars (tyConTyVars tc)
-  typats = case tyConFamInst_maybe tc of
-     Nothing -> Nothing
-     Just (_, indexes) -> Just (map (synifyType WithinType) indexes)
-  alg_kindSig = Just (tyConKind tc)
-  -- The data constructors.
-  --
-  -- Any data-constructors not exported from the module that *defines* the
-  -- type will not (cannot) be included.
-  --
-  -- Very simple constructors, Haskell98 with no existentials or anything,
-  -- probably look nicer in non-GADT syntax.  In source code, all constructors
-  -- must be declared with the same (GADT vs. not) syntax, and it probably
-  -- is less confusing to follow that principle for the documentation as well.
-  --
-  -- There is no sensible infix-representation for GADT-syntax constructor
-  -- declarations.  They cannot be made in source code, but we could end up
-  -- with some here in the case where some constructors use existentials.
-  -- That seems like an acceptable compromise (they'll just be documented
-  -- in prefix position), since, otherwise, the logic (at best) gets much more
-  -- complicated. (would use dataConIsInfix.)
-  alg_use_gadt_syntax = any (not . isVanillaDataCon) (tyConDataCons tc)
-  alg_cons = map (synifyDataCon alg_use_gadt_syntax) (tyConDataCons tc)
-  -- "deriving" doesn't affect the signature, no need to specify any.
-  alg_deriv = Nothing
-  syn_type = synifyType WithinType (synTyConType tc)
- in if isSynTyCon tc
-  then TySynonym name tyvars typats syn_type
-  else TyData alg_nd alg_ctx name tyvars typats alg_kindSig alg_cons alg_deriv
-
-
--- User beware: it is your responsibility to pass True (use_gadt_syntax)
--- for any constructor that would be misrepresented by omitting its
--- result-type.
--- But you might want pass False in simple enough cases,
--- if you think it looks better.
-synifyDataCon :: Bool -> DataCon -> LConDecl Name
-synifyDataCon use_gadt_syntax dc = noLoc $
- let
-  -- dataConIsInfix allegedly tells us whether it was declared with
-  -- infix *syntax*.
-  use_infix_syntax = dataConIsInfix dc
-  use_named_field_syntax = not (null field_tys)
-  name = synifyName dc
-  -- con_qvars means a different thing depending on gadt-syntax
-  (univ_tvs, ex_tvs, _eq_spec, theta, arg_tys, res_ty) = dataConFullSig dc
-
-  qvars = if use_gadt_syntax
-          then synifyTyVars (univ_tvs ++ ex_tvs)
-          else synifyTyVars ex_tvs
-
-  -- skip any EqTheta, use 'orig'inal syntax
-  ctx = synifyCtx theta
-
-  linear_tys = zipWith (\ty bang ->
-            let tySyn = synifyType WithinType ty
-            in case bang of
-                 HsUnpackFailed -> noLoc $ HsBangTy HsStrict tySyn
-                 HsNoBang       -> tySyn
-                      -- HsNoBang never appears, it's implied instead.
-                 _              -> noLoc $ HsBangTy bang tySyn
-          )
-          arg_tys (dataConStrictMarks dc)
-  field_tys = zipWith (\field synTy -> ConDeclField
-                                           (synifyName field) synTy Nothing)
-                (dataConFieldLabels dc) linear_tys
-  hs_arg_tys = case (use_named_field_syntax, use_infix_syntax) of
-          (True,True) -> error "synifyDataCon: contradiction!"
-          (True,False) -> RecCon field_tys
-          (False,False) -> PrefixCon linear_tys
-          (False,True) -> case linear_tys of
-                           [a,b] -> InfixCon a b
-                           _ -> error "synifyDataCon: infix with non-2 args?"
-  hs_res_ty = if use_gadt_syntax
-              then ResTyGADT (synifyType WithinType res_ty)
-              else ResTyH98
- -- finally we get synifyDataCon's result!
- in ConDecl name Implicit{-we don't know nor care-}
-      qvars ctx hs_arg_tys hs_res_ty Nothing
-      False --we don't want any "deprecated GADT syntax" warnings!
-
-
-synifyName :: NamedThing n => n -> Located Name
-synifyName = noLoc . getName
-
-
-synifyIdSig :: SynifyTypeState -> Id -> Sig Name
-synifyIdSig s i = TypeSig [synifyName i] (synifyType s (varType i))
-
-
-synifyCtx :: [PredType] -> LHsContext Name
-synifyCtx = noLoc . map synifyPred
-
-
-synifyPred :: PredType -> LHsPred Name
-synifyPred (ClassP cls tys) =
-    let sTys = map (synifyType WithinType) tys
-    in noLoc $
-        HsClassP (getName cls) sTys
-synifyPred (IParam ip ty) =
-    let sTy = synifyType WithinType ty
-    -- IPName should be in class NamedThing...
-    in noLoc $
-      HsIParam ip sTy
-synifyPred (EqPred ty1 ty2) =
-    let
-     s1 = synifyType WithinType ty1
-     s2 = synifyType WithinType ty2
-    in noLoc $
-      HsEqualP s1 s2
-
-
-synifyTyVars :: [TyVar] -> [LHsTyVarBndr Name]
-synifyTyVars = map synifyTyVar
-  where
-    synifyTyVar tv = noLoc $ let
-      kind = tyVarKind tv
-      name = getName tv
-     in if isLiftedTypeKind kind
-        then UserTyVar name placeHolderKind
-        else KindedTyVar name kind
-
-
---states of what to do with foralls:
-data SynifyTypeState
-  = WithinType
-  -- ^ normal situation.  This is the safe one to use if you don't
-  -- quite understand what's going on.
-  | ImplicitizeForAll
-  -- ^ beginning of a function definition, in which, to make it look
-  --   less ugly, those rank-1 foralls are made implicit.
-  | DeleteTopLevelQuantification
-  -- ^ because in class methods the context is added to the type
-  --   (e.g. adding @forall a. Num a =>@ to @(+) :: a -> a -> a@)
-  --   which is rather sensible,
-  --   but we want to restore things to the source-syntax situation where
-  --   the defining class gets to quantify all its functions for free!
-
-
-synifyType :: SynifyTypeState -> Type -> LHsType Name
-synifyType _ (PredTy{}) = --should never happen.
-  error "synifyType: PredTys are not, in themselves, source-level types."
-synifyType _ (TyVarTy tv) = noLoc $ HsTyVar (getName tv)
-synifyType _ (TyConApp tc tys)
-  -- Use non-prefix tuple syntax where possible, because it looks nicer.
-  | isTupleTyCon tc, tyConArity tc == length tys =
-     noLoc $ HsTupleTy (tupleTyConBoxity tc) (map (synifyType WithinType) tys)
-  -- ditto for lists
-  | getName tc == listTyConName, [ty] <- tys =
-     noLoc $ HsListTy (synifyType WithinType ty)
-  -- Most TyCons:
-  | otherwise =
-    foldl (\t1 t2 -> noLoc (HsAppTy t1 t2))
-      (noLoc $ HsTyVar (getName tc))
-      (map (synifyType WithinType) tys)
-synifyType _ (AppTy t1 t2) = let
-  s1 = synifyType WithinType t1
-  s2 = synifyType WithinType t2
-  in noLoc $ HsAppTy s1 s2
-synifyType _ (FunTy t1 t2) = let
-  s1 = synifyType WithinType t1
-  s2 = synifyType WithinType t2
-  in noLoc $ HsFunTy s1 s2
-synifyType s forallty@(ForAllTy _tv _ty) =
-  let (tvs, ctx, tau) = tcSplitSigmaTy forallty
-  in case s of
-    DeleteTopLevelQuantification -> synifyType ImplicitizeForAll tau
-    _ -> let
-      forallPlicitness = case s of
-              WithinType -> Explicit
-              ImplicitizeForAll -> Implicit
-              _ -> error "synifyType: impossible case!!!"
-      sTvs = synifyTyVars tvs
-      sCtx = synifyCtx ctx
-      sTau = synifyType WithinType tau
-     in noLoc $
-           HsForAllTy forallPlicitness sTvs sCtx sTau
-
-
-synifyInstHead :: ([TyVar], [PredType], Class, [Type]) ->
-                  ([HsPred Name], Name, [HsType Name])
-synifyInstHead (_, preds, cls, ts) =
-  ( map (unLoc . synifyPred) preds
-  , getName cls
-  , map (unLoc . synifyType WithinType) ts
-  )
diff --git a/src/Haddock/Doc.hs b/src/Haddock/Doc.hs
deleted file mode 100644
--- a/src/Haddock/Doc.hs
+++ /dev/null
@@ -1,65 +0,0 @@
-module Haddock.Doc (
-  docAppend,
-  docParagraph
-  ) where
-
-
-import Haddock.Types
-import Data.Char (isSpace)
-
-
--- used to make parsing easier; we group the list items later
-docAppend :: Doc id -> Doc id -> Doc id
-docAppend (DocUnorderedList ds1) (DocUnorderedList ds2)
-  = DocUnorderedList (ds1++ds2)
-docAppend (DocUnorderedList ds1) (DocAppend (DocUnorderedList ds2) d)
-  = DocAppend (DocUnorderedList (ds1++ds2)) d
-docAppend (DocOrderedList ds1) (DocOrderedList ds2)
-  = DocOrderedList (ds1++ds2)
-docAppend (DocOrderedList ds1) (DocAppend (DocOrderedList ds2) d)
-  = DocAppend (DocOrderedList (ds1++ds2)) d
-docAppend (DocDefList ds1) (DocDefList ds2)
-  = DocDefList (ds1++ds2)
-docAppend (DocDefList ds1) (DocAppend (DocDefList ds2) d)
-  = DocAppend (DocDefList (ds1++ds2)) d
-docAppend DocEmpty d = d
-docAppend d DocEmpty = d
-docAppend d1 d2
-  = DocAppend d1 d2
-
-
--- again to make parsing easier - we spot a paragraph whose only item
--- is a DocMonospaced and make it into a DocCodeBlock
-docParagraph :: Doc id -> Doc id
-docParagraph (DocMonospaced p)
-  = DocCodeBlock (docCodeBlock p)
-docParagraph (DocAppend (DocString s1) (DocMonospaced p))
-  | all isSpace s1
-  = DocCodeBlock (docCodeBlock p)
-docParagraph (DocAppend (DocString s1)
-    (DocAppend (DocMonospaced p) (DocString s2)))
-  | all isSpace s1 && all isSpace s2
-  = DocCodeBlock (docCodeBlock p)
-docParagraph (DocAppend (DocMonospaced p) (DocString s2))
-  | all isSpace s2
-  = DocCodeBlock (docCodeBlock p)
-docParagraph p
-  = DocParagraph p
-
-
--- Drop trailing whitespace from @..@ code blocks.  Otherwise this:
---
---    -- @
---    -- foo
---    -- @
---
--- turns into (DocCodeBlock "\nfoo\n ") which when rendered in HTML
--- gives an extra vertical space after the code block.  The single space
--- on the final line seems to trigger the extra vertical space.
---
-docCodeBlock :: Doc id -> Doc id
-docCodeBlock (DocString s)
-  = DocString (reverse $ dropWhile (`elem` " \t") $ reverse s)
-docCodeBlock (DocAppend l r)
-  = DocAppend l (docCodeBlock r)
-docCodeBlock d = d
diff --git a/src/Haddock/GhcUtils.hs b/src/Haddock/GhcUtils.hs
deleted file mode 100644
--- a/src/Haddock/GhcUtils.hs
+++ /dev/null
@@ -1,283 +0,0 @@
-{-# LANGUAGE FlexibleInstances #-}
-{-# OPTIONS_GHC -fno-warn-orphans #-}
-{-# OPTIONS_HADDOCK hide #-}
------------------------------------------------------------------------------
--- |
--- Module      :  Haddock.GhcUtils
--- Copyright   :  (c) David Waern 2006-2009
--- License     :  BSD-like
---
--- Maintainer  :  haddock@projects.haskell.org
--- Stability   :  experimental
--- Portability :  portable
---
--- Utils for dealing with types from the GHC API
------------------------------------------------------------------------------
-module Haddock.GhcUtils where
-
-
-import Data.Version
-import Control.Applicative  ( (<$>) )
-import Control.Arrow
-import Data.Foldable hiding (concatMap)
-import Data.Traversable
-import Distribution.Compat.ReadP
-import Distribution.Text
-
-import Exception
-import Outputable
-import Name
-import Packages
-import Module
-import RdrName (GlobalRdrEnv)
-#if MIN_VERSION_ghc(7,1,0)
-import GhcMonad (withSession)
-#endif
-import HscTypes
-import UniqFM
-import GHC
-
-
-moduleString :: Module -> String
-moduleString = moduleNameString . moduleName
-
-
--- return the (name,version) of the package
-modulePackageInfo :: Module -> (String, [Char])
-modulePackageInfo modu = case unpackPackageId pkg of
-                          Nothing -> (packageIdString pkg, "")
-                          Just x -> (display $ pkgName x, showVersion (pkgVersion x))
-  where pkg = modulePackageId modu
-
-
--- This was removed from GHC 6.11
--- XXX we shouldn't be using it, probably
-
--- | Try and interpret a GHC 'PackageId' as a cabal 'PackageIdentifer'. Returns @Nothing@ if
--- we could not parse it as such an object.
-unpackPackageId :: PackageId -> Maybe PackageIdentifier
-unpackPackageId p
-  = case [ pid | (pid,"") <- readP_to_S parse str ] of
-        []      -> Nothing
-        (pid:_) -> Just pid
-  where str = packageIdString p
-
-
-mkModuleNoPackage :: String -> Module
-mkModuleNoPackage str = mkModule (stringToPackageId "") (mkModuleName str)
-
-
-lookupLoadedHomeModuleGRE  :: GhcMonad m => ModuleName -> m (Maybe GlobalRdrEnv)
-lookupLoadedHomeModuleGRE mod_name = withSession $ \hsc_env ->
-  case lookupUFM (hsc_HPT hsc_env) mod_name of
-    Just mod_info      -> return (mi_globals (hm_iface mod_info))
-    _not_a_home_module -> return Nothing
-
-
-isNameSym :: Name -> Bool
-isNameSym = isSymOcc . nameOccName
-
-
-isVarSym :: OccName -> Bool
-isVarSym = isLexVarSym . occNameFS
-
-
-getMainDeclBinder :: HsDecl name -> [name]
-getMainDeclBinder (TyClD d) = [tcdName d]
-getMainDeclBinder (ValD d) =
-#if __GLASGOW_HASKELL__ == 612
-  case collectAcc d [] of
-    []       -> []
-    (name:_) -> [unLoc name]
-#else
-  case collectHsBindBinders d of
-    []       -> []
-    (name:_) -> [name]
-#endif
-
-getMainDeclBinder (SigD d) = sigNameNoLoc d
-getMainDeclBinder (ForD (ForeignImport name _ _)) = [unLoc name]
-getMainDeclBinder (ForD (ForeignExport _ _ _)) = []
-getMainDeclBinder _ = []
-
--- Useful when there is a signature with multiple names, e.g.
---   foo, bar :: Types..
--- but only one of the names is exported and we have to change the
--- type signature to only include the exported names.
-filterLSigNames :: (name -> Bool) -> LSig name -> Maybe (LSig name)
-filterLSigNames p (L loc sig) = L loc <$> (filterSigNames p sig)
-
-filterSigNames :: (name -> Bool) -> Sig name -> Maybe (Sig name)
-filterSigNames p orig@(SpecSig n _ _)          = ifTrueJust (p $ unLoc n) orig
-filterSigNames p orig@(InlineSig n _)          = ifTrueJust (p $ unLoc n) orig
-filterSigNames p orig@(FixSig (FixitySig n _)) = ifTrueJust (p $ unLoc n) orig
-filterSigNames p (TypeSig ns ty)               =
-  case filter (p . unLoc) ns of
-    []       -> Nothing
-    filtered -> Just (TypeSig filtered ty)
-filterSigNames _ _                           = Nothing
-
-ifTrueJust :: Bool -> name -> Maybe name
-ifTrueJust True  = Just
-ifTrueJust False = const Nothing
-
-sigName :: LSig name -> [name]
-sigName (L _ sig) = sigNameNoLoc sig
-
-sigNameNoLoc :: Sig name -> [name]
-sigNameNoLoc (TypeSig   ns _)         = map unLoc ns
-sigNameNoLoc (SpecSig   n _ _)        = [unLoc n]
-sigNameNoLoc (InlineSig n _)          = [unLoc n]
-sigNameNoLoc (FixSig (FixitySig n _)) = [unLoc n]
-sigNameNoLoc _                        = []
-
-
-isTyClD :: HsDecl a -> Bool
-isTyClD (TyClD _) = True
-isTyClD _ = False
-
-
-isClassD :: HsDecl a -> Bool
-isClassD (TyClD d) = isClassDecl d
-isClassD _ = False
-
-
-isDocD :: HsDecl a -> Bool
-isDocD (DocD _) = True
-isDocD _ = False
-
-
-isInstD :: HsDecl a -> Bool
-isInstD (InstD _) = True
-isInstD (TyClD d) = isFamInstDecl d
-isInstD _ = False
-
-
-declATs :: HsDecl a -> [a]
-declATs (TyClD d) | isClassDecl d = map (tcdName . unL) $ tcdATs d
-declATs _ = []
-
-
-pretty :: Outputable a => a -> String
-pretty x = showSDoc (ppr x)
-
-
-trace_ppr :: Outputable a => a -> b -> b
-trace_ppr x y = trace (pretty x) y
-
-
--------------------------------------------------------------------------------
--- * Located
--------------------------------------------------------------------------------
-
-
-unL :: Located a -> a
-unL (L _ x) = x
-
-
-reL :: a -> Located a
-reL = L undefined
-
-
-instance Foldable (GenLocated l) where
-  foldMap f (L _ x) = f x
-
-
-instance Traversable (GenLocated l) where
-  mapM f (L l x) = (return . L l) =<< f x
-
-
--------------------------------------------------------------------------------
--- * NamedThing instances
--------------------------------------------------------------------------------
-
-
-instance NamedThing (TyClDecl Name) where
-  getName = tcdName
-
-
-instance NamedThing (ConDecl Name) where
-  getName = unL . con_name
-
-
--------------------------------------------------------------------------------
--- * Subordinates
--------------------------------------------------------------------------------
-
-
-class Parent a where
-  children :: a -> [Name]
-
-
-instance Parent (ConDecl Name) where
-  children con =
-    case con_details con of
-      RecCon fields -> map (unL . cd_fld_name) fields
-      _             -> []
-
-
-instance Parent (TyClDecl Name) where
-  children d
-    | isDataDecl  d = map (unL . con_name . unL) . tcdCons $ d
-    | isClassDecl d =
-        map (tcdName . unL) (tcdATs d) ++
-        [ unL n | L _ (TypeSig ns _) <- tcdSigs d, n <- ns ]
-    | otherwise = []
-
-
--- | A parent and its children
-family :: (NamedThing a, Parent a) => a -> (Name, [Name])
-family = getName &&& children
-
-
--- | A mapping from the parent (main-binder) to its children and from each
--- child to its grand-children, recursively.
-families :: TyClDecl Name -> [(Name, [Name])]
-families d
-  | isDataDecl  d = family d : map (family . unL) (tcdCons d)
-  | isClassDecl d = family d : concatMap (families . unL) (tcdATs d)
-  | otherwise     = []
-
-
--- | A mapping from child to parent
-parentMap :: TyClDecl Name -> [(Name, Name)]
-parentMap d = [ (c, p) | (p, cs) <- families d, c <- cs ]
-
-
--- | The parents of a subordinate in a declaration
-parents :: Name -> HsDecl Name -> [Name]
-parents n (TyClD d) = [ p | (c, p) <- parentMap d, c == n ]
-parents _ _ = []
-
-
--------------------------------------------------------------------------------
--- * Utils that work in monads defined by GHC
--------------------------------------------------------------------------------
-
-
-modifySessionDynFlags :: (DynFlags -> DynFlags) -> Ghc ()
-modifySessionDynFlags f = do
-  dflags <- getSessionDynFlags
-  _ <- setSessionDynFlags (f dflags)
-  return ()
-
-
--- | A variant of 'gbracket' where the return value from the first computation
--- is not required.
-gbracket_ :: ExceptionMonad m => m a -> m b -> m c -> m c
-gbracket_ before after thing = gbracket before (const after) (const thing)
-
-
--------------------------------------------------------------------------------
--- * DynFlags
--------------------------------------------------------------------------------
-
-
-setObjectDir, setHiDir, setStubDir, setOutputDir :: String -> DynFlags -> DynFlags
-setObjectDir  f d = d{ objectDir  = Just f}
-setHiDir      f d = d{ hiDir      = Just f}
-setStubDir    f d = d{ stubDir    = Just f, includePaths = f : includePaths d }
-  -- -stubdir D adds an implicit -I D, so that gcc can find the _stub.h file
-  -- \#included from the .hc file when compiling with -fvia-C.
-setOutputDir  f = setObjectDir f . setHiDir f . setStubDir f
-
diff --git a/src/Haddock/Interface.hs b/src/Haddock/Interface.hs
deleted file mode 100644
--- a/src/Haddock/Interface.hs
+++ /dev/null
@@ -1,211 +0,0 @@
------------------------------------------------------------------------------
--- |
--- Module      :  Haddock.Interface
--- Copyright   :  (c) Simon Marlow 2003-2006,
---                    David Waern  2006-2010
--- License     :  BSD-like
---
--- Maintainer  :  haddock@projects.haskell.org
--- Stability   :  experimental
--- Portability :  portable
---
--- This module typechecks Haskell modules using the GHC API and processes
--- the result to create 'Interface's. The typechecking and the 'Interface'
--- creation is interleaved, so that when a module is processed, the
--- 'Interface's of all previously processed modules are available. The
--- creation of an 'Interface' from a typechecked module is delegated to
--- "Haddock.Interface.Create".
---
--- When all modules have been typechecked and processed, information about
--- instances are attached to each 'Interface'. This task is delegated to
--- "Haddock.Interface.AttachInstances". Note that this is done as a separate
--- step because GHC can't know about all instances until all modules have been
--- typechecked.
---
--- As a last step a link environment is built which maps names to the \"best\"
--- places to link to in the documentation, and all 'Interface's are \"renamed\"
--- using this environment.
------------------------------------------------------------------------------
-module Haddock.Interface (
-  processModules
-) where
-
-
-import Haddock.GhcUtils
-import Haddock.InterfaceFile
-import Haddock.Interface.Create
-import Haddock.Interface.AttachInstances
-import Haddock.Interface.Rename
-import Haddock.Options hiding (verbosity)
-import Haddock.Types
-import Haddock.Utils
-
-import Control.Monad
-import Data.List
-import qualified Data.Map as Map
-import Distribution.Verbosity
-import System.Directory
-import System.FilePath
-import Text.Printf
-
-import Digraph
-import Exception
-import GHC hiding (verbosity, flags)
-import HscTypes
-
-
--- | Create 'Interface's and a link environment by typechecking the list of
--- modules using the GHC API and processing the resulting syntax trees.
-processModules
-  :: Verbosity                  -- ^ Verbosity of logging to 'stdout'
-  -> [String]                   -- ^ A list of file or module names sorted by
-                                -- module topology
-  -> [Flag]                     -- ^ Command-line flags
-  -> [InterfaceFile]            -- ^ Interface files of package dependencies
-  -> Ghc ([Interface], LinkEnv) -- ^ Resulting list of interfaces and renaming
-                                -- environment
-processModules verbosity modules flags extIfaces = do
-
-  out verbosity verbose "Creating interfaces..."
-  let instIfaceMap =  Map.fromList [ (instMod iface, iface) | ext <- extIfaces
-                                   , iface <- ifInstalledIfaces ext ]
-  interfaces <- createIfaces0 verbosity modules flags instIfaceMap
-
-  out verbosity verbose "Attaching instances..."
-  interfaces' <- attachInstances interfaces instIfaceMap
-
-  out verbosity verbose "Building cross-linking environment..."
-  -- Combine the link envs of the external packages into one
-  let extLinks  = Map.unions (map ifLinkEnv extIfaces)
-      homeLinks = buildHomeLinks interfaces -- Build the environment for the home
-                                            -- package
-      links     = homeLinks `Map.union` extLinks
-
-  out verbosity verbose "Renaming interfaces..."
-  let warnings = Flag_NoWarnings `notElem` flags
-  let (interfaces'', msgs) =
-         runWriter $ mapM (renameInterface links warnings) interfaces'
-  liftIO $ mapM_ putStrLn msgs
-
-  return (interfaces'', homeLinks)
-
-
---------------------------------------------------------------------------------
--- * Module typechecking and Interface creation
---------------------------------------------------------------------------------
-
-
-createIfaces0 :: Verbosity -> [String] -> [Flag] -> InstIfaceMap -> Ghc [Interface]
-createIfaces0 verbosity modules flags instIfaceMap =
-  -- Output dir needs to be set before calling depanal since depanal uses it to
-  -- compute output file names that are stored in the DynFlags of the
-  -- resulting ModSummaries.
-  (if useTempDir then withTempOutputDir else id) $ do
-    modGraph <- depAnalysis
-    if needsTemplateHaskell modGraph then do
-      modGraph' <- enableCompilation modGraph
-      createIfaces verbosity flags instIfaceMap modGraph'
-    else
-      createIfaces verbosity flags instIfaceMap modGraph
-
-  where
-    useTempDir :: Bool
-    useTempDir = Flag_NoTmpCompDir `notElem` flags
-
-
-    withTempOutputDir :: Ghc a -> Ghc a
-    withTempOutputDir action = do
-      tmp <- liftIO getTemporaryDirectory
-      x   <- liftIO getProcessID
-      let dir = tmp </> ".haddock-" ++ show x
-      modifySessionDynFlags (setOutputDir dir)
-      withTempDir dir action
-
-
-    depAnalysis :: Ghc ModuleGraph
-    depAnalysis = do
-      targets <- mapM (\f -> guessTarget f Nothing) modules
-      setTargets targets
-      depanal [] False
-
-
-    enableCompilation :: ModuleGraph -> Ghc ModuleGraph
-    enableCompilation modGraph = do
-      let enableComp d = d { hscTarget = defaultObjectTarget }
-      modifySessionDynFlags enableComp
-      -- We need to update the DynFlags of the ModSummaries as well.
-      let upd m = m { ms_hspp_opts = enableComp (ms_hspp_opts m) }
-      let modGraph' = map upd modGraph
-      return modGraph'
-
-
-createIfaces :: Verbosity -> [Flag] -> InstIfaceMap -> ModuleGraph -> Ghc [Interface]
-createIfaces verbosity flags instIfaceMap mods = do
-  let sortedMods = flattenSCCs $ topSortModuleGraph False mods Nothing
-  out verbosity normal "Haddock coverage:"
-  (ifaces, _) <- foldM f ([], Map.empty) sortedMods
-  return (reverse ifaces)
-  where
-    f (ifaces, ifaceMap) modSummary = do
-      x <- processModule verbosity modSummary flags ifaceMap instIfaceMap
-      return $ case x of
-        Just iface -> (iface:ifaces, Map.insert (ifaceMod iface) iface ifaceMap)
-        Nothing    -> (ifaces, ifaceMap) -- Boot modules don't generate ifaces.
-
-
-processModule :: Verbosity -> ModSummary -> [Flag] -> IfaceMap -> InstIfaceMap -> Ghc (Maybe Interface)
-processModule verbosity modsum flags modMap instIfaceMap = do
-  out verbosity verbose $ "Checking module " ++ moduleString (ms_mod modsum) ++ "..."
-  tm <- loadModule =<< typecheckModule =<< parseModule modsum
-  if not $ isBootSummary modsum then do
-    out verbosity verbose "Creating interface..."
-    (interface, msg) <- runWriterGhc $ createInterface tm flags modMap instIfaceMap
-    liftIO $ mapM_ putStrLn msg
-    let (haddockable, haddocked) = ifaceHaddockCoverage interface
-        percentage = round (fromIntegral haddocked * 100 / fromIntegral haddockable :: Double) :: Int
-        modString = moduleString (ifaceMod interface)
-        coverageMsg = printf " %3d%% (%3d /%3d) in '%s'" percentage haddocked haddockable modString
-    out verbosity normal coverageMsg
-    interface' <- liftIO $ evaluate interface
-    return (Just interface')
-  else
-    return Nothing
-
-
---------------------------------------------------------------------------------
--- * Building of cross-linking environment  
---------------------------------------------------------------------------------
-
-
--- | Build a mapping which for each original name, points to the "best"
--- place to link to in the documentation.  For the definition of
--- "best", we use "the module nearest the bottom of the dependency
--- graph which exports this name", not including hidden modules.  When
--- there are multiple choices, we pick a random one.
---
--- The interfaces are passed in in topologically sorted order, but we start
--- by reversing the list so we can do a foldl.
-buildHomeLinks :: [Interface] -> LinkEnv
-buildHomeLinks ifaces = foldl upd Map.empty (reverse ifaces)
-  where
-    upd old_env iface
-      | OptHide    `elem` ifaceOptions iface = old_env
-      | OptNotHome `elem` ifaceOptions iface =
-        foldl' keep_old old_env exported_names
-      | otherwise = foldl' keep_new old_env exported_names
-      where
-        exported_names = ifaceVisibleExports iface
-        mdl            = ifaceMod iface
-        keep_old env n = Map.insertWith (\_ old -> old) n mdl env
-        keep_new env n = Map.insert n mdl env
-
-
---------------------------------------------------------------------------------
--- * Utils
---------------------------------------------------------------------------------
-
-
-withTempDir :: (ExceptionMonad m, MonadIO m) => FilePath -> m a -> m a
-withTempDir dir = gbracket_ (liftIO $ createDirectory dir)
-                            (liftIO $ removeDirectoryRecursive dir)
-
diff --git a/src/Haddock/Interface/AttachInstances.hs b/src/Haddock/Interface/AttachInstances.hs
deleted file mode 100644
--- a/src/Haddock/Interface/AttachInstances.hs
+++ /dev/null
@@ -1,151 +0,0 @@
-{-# LANGUAGE MagicHash #-}
------------------------------------------------------------------------------
--- |
--- Module      :  Haddock.Interface.AttachInstances
--- Copyright   :  (c) Simon Marlow 2006,
---                    David Waern  2006-2009,
---                    Isaac Dupree 2009
--- License     :  BSD-like
---
--- Maintainer  :  haddock@projects.haskell.org
--- Stability   :  experimental
--- Portability :  portable
------------------------------------------------------------------------------
-module Haddock.Interface.AttachInstances (attachInstances) where
-
-
-import Haddock.Types
-import Haddock.Convert
-
-import Control.Arrow
-import Data.List
-import qualified Data.Map as Map
-
-import GHC
-import Name
-import InstEnv
-import Class
-#if MIN_VERSION_ghc(7,1,0)
-import GhcMonad (withSession)
-#else
-import HscTypes (withSession)
-#endif
-import TysPrim( funTyCon )
-import MonadUtils (liftIO)
-import TcRnDriver (tcRnGetInfo)
-import TypeRep
-import Var hiding (varName)
-import TyCon
-import PrelNames
-import FastString
-#define FSLIT(x) (mkFastString# (x#))
-
-
-attachInstances :: [Interface] -> InstIfaceMap -> Ghc [Interface]
-attachInstances ifaces instIfaceMap = mapM attach ifaces
-  where
-    -- TODO: take an IfaceMap as input
-    ifaceMap = Map.fromList [ (ifaceMod i, i) | i <- ifaces ]
-
-    attach iface = do
-      newItems <- mapM (attachToExportItem iface ifaceMap instIfaceMap)
-                       (ifaceExportItems iface)
-      return $ iface { ifaceExportItems = newItems }
-
-
-attachToExportItem :: Interface -> IfaceMap -> InstIfaceMap -> ExportItem Name -> Ghc (ExportItem Name)
-attachToExportItem iface ifaceMap instIfaceMap export =
-  case export of
-    ExportDecl { expItemDecl = L _ (TyClD d) } -> do
-      mb_info <- getAllInfo (unLoc (tcdLName d))
-      let export' =
-            export {
-              expItemInstances =
-                case mb_info of
-                  Just (_, _, instances) ->
-                    let insts = map (first synifyInstHead) $ sortImage (first instHead)
-                                [ (instanceHead i, getName i) | i <- instances ]
-                    in [ (inst, lookupInstDoc name iface ifaceMap instIfaceMap)
-                       | (inst, name) <- insts ]
-                  Nothing -> []
-            }
-      return export'
-    _ -> return export
-
-
-lookupInstDoc :: Name -> Interface -> IfaceMap -> InstIfaceMap -> Maybe (Doc Name)
--- TODO: capture this pattern in a function (when we have streamlined the
--- handling of instances)
-lookupInstDoc name iface ifaceMap instIfaceMap =
-  case Map.lookup name (ifaceInstanceDocMap iface) of
-    Just doc -> Just doc
-    Nothing ->
-      case Map.lookup modName ifaceMap of
-        Just iface2 ->
-          case Map.lookup name (ifaceInstanceDocMap iface2) of
-            Just doc -> Just doc
-            Nothing -> Nothing
-        Nothing ->
-          case Map.lookup modName instIfaceMap of
-            Just instIface ->
-              case Map.lookup name (instDocMap instIface) of
-                Just (doc, _) -> doc
-                Nothing -> Nothing
-            Nothing -> Nothing
-  where
-    modName = nameModule name
-
-
--- | Like GHC's getInfo but doesn't cut things out depending on the
--- interative context, which we don't set sufficiently anyway.
-getAllInfo :: GhcMonad m => Name -> m (Maybe (TyThing,Fixity,[Instance]))
-getAllInfo name = withSession $ \hsc_env -> do 
-   (_msgs, r) <- liftIO $ tcRnGetInfo hsc_env name
-   return r
-
-
---------------------------------------------------------------------------------
--- Collecting and sorting instances
---------------------------------------------------------------------------------
-
-
--- | Simplified type for sorting types, ignoring qualification (not visible
--- in Haddock output) and unifying special tycons with normal ones.
--- For the benefit of the user (looks nice and predictable) and the
--- tests (which prefer output to be deterministic).
-data SimpleType = SimpleType Name [SimpleType] deriving (Eq,Ord)
-
-
--- TODO: should we support PredTy here?
-instHead :: ([TyVar], [PredType], Class, [Type]) -> ([Int], Name, [SimpleType])
-instHead (_, _, cls, args)
-  = (map argCount args, className cls, map simplify args)
-  where
-    argCount (AppTy t _) = argCount t + 1
-    argCount (TyConApp _ ts) = length ts
-    argCount (FunTy _ _ ) = 2
-    argCount (ForAllTy _ t) = argCount t
-    argCount _ = 0
-
-    simplify (ForAllTy _ t) = simplify t
-    simplify (FunTy t1 t2) = 
-      SimpleType funTyConName [simplify t1, simplify t2]
-    simplify (AppTy t1 t2) = SimpleType s (ts ++ [simplify t2])
-      where (SimpleType s ts) = simplify t1
-    simplify (TyVarTy v) = SimpleType (tyVarName v) []
-    simplify (TyConApp tc ts) = SimpleType (tyConName tc) (map simplify ts)
-    simplify _ = error "simplify"
-
-
--- sortImage f = sortBy (\x y -> compare (f x) (f y))
-sortImage :: Ord b => (a -> b) -> [a] -> [a]
-sortImage f xs = map snd $ sortBy cmp_fst [(f x, x) | x <- xs]
- where cmp_fst (x,_) (y,_) = compare x y
-
-
-funTyConName :: Name
-funTyConName = mkWiredInName gHC_PRIM
-                        (mkOccNameFS tcName FSLIT("(->)"))
-                        funTyConKey
-                        (ATyCon funTyCon)       -- Relevant TyCon
-                        BuiltInSyntax
diff --git a/src/Haddock/Interface/Create.hs b/src/Haddock/Interface/Create.hs
deleted file mode 100644
--- a/src/Haddock/Interface/Create.hs
+++ /dev/null
@@ -1,821 +0,0 @@
------------------------------------------------------------------------------
--- |
--- Module      :  Haddock.Interface.Create
--- Copyright   :  (c) Simon Marlow 2003-2006,
---                    David Waern  2006-2009
--- License     :  BSD-like
---
--- Maintainer  :  haddock@projects.haskell.org
--- Stability   :  experimental
--- Portability :  portable
------------------------------------------------------------------------------
-module Haddock.Interface.Create (createInterface) where
-
-
-import Haddock.Types
-import Haddock.Options
-import Haddock.GhcUtils
-import Haddock.Utils
-import Haddock.Convert
-import Haddock.Interface.LexParseRn
-import Haddock.Interface.ExtractFnArgDocs
-
-import qualified Data.Map as Map
-import Data.Map (Map)
-import Data.List
-import Data.Maybe
-import Data.Ord
-import Control.Monad
-import qualified Data.Traversable as Traversable
-
-import GHC hiding (flags)
-import HscTypes
-import Name
-import Bag
-import RdrName (GlobalRdrEnv)
-
-
--- | Use a 'TypecheckedModule' to produce an 'Interface'.
--- To do this, we need access to already processed modules in the topological
--- sort. That's what's in the 'IfaceMap'.
-createInterface :: TypecheckedModule -> [Flag] -> IfaceMap -> InstIfaceMap
-                -> ErrMsgGhc Interface
-createInterface tm flags modMap instIfaceMap = do
-
-  let ms                  = pm_mod_summary . tm_parsed_module $ tm
-      mi                  = moduleInfo tm
-      mdl                 = ms_mod ms
-      dflags              = ms_hspp_opts ms
-      instances           = modInfoInstances mi
-      exportedNames       = modInfoExports mi
-      -- XXX: confirm always a Just.
-      Just (group_, _, optExports, optDocHeader) = renamedSource tm
-
-  -- The pattern-match should not fail, because createInterface is only
-  -- done on loaded modules.
-  Just gre <- liftGhcToErrMsgGhc $ lookupLoadedHomeModuleGRE (moduleName mdl)
-
-  opts0 <- liftErrMsg $ mkDocOpts (haddockOptions dflags) flags mdl
-  let opts
-        | Flag_IgnoreAllExports `elem` flags = OptIgnoreExports : opts0
-        | otherwise = opts0
-
-  (info, mbDoc)    <- liftErrMsg $ lexParseRnHaddockModHeader dflags gre optDocHeader
-  decls0           <- liftErrMsg $ declInfos dflags gre (topDecls group_)
-
-  let localInsts     = filter (nameIsLocalOrFrom mdl . getName) instances
-      declDocs       = [ (decl, doc) | (L _ decl, (Just doc, _), _) <- decls0 ]
-      instanceDocMap = mkInstanceDocMap localInsts declDocs
-
-      decls         = filterOutInstances decls0
-      declMap       = mkDeclMap decls
-      exports0      = fmap (reverse . map unLoc) optExports
-      exports
-        | OptIgnoreExports `elem` opts = Nothing
-        | otherwise = exports0
-
-  liftErrMsg $ warnAboutFilteredDecls mdl decls0
-
-  exportItems <- mkExportItems modMap mdl gre exportedNames decls declMap
-                               exports instances instIfaceMap dflags
-
-  let visibleNames = mkVisibleNames exportItems opts
-
-  -- measure haddock documentation coverage.
-  let
-    prunedExportItems0 = pruneExportItems exportItems
-    haddockable = 1 + length exportItems -- module + exports
-    haddocked = (if isJust mbDoc then 1 else 0) + length prunedExportItems0
-    coverage = (haddockable, haddocked)
-
-  -- prune the export list to just those declarations that have
-  -- documentation, if the 'prune' option is on.
-  let
-    prunedExportItems
-      | OptPrune `elem` opts = prunedExportItems0
-      | otherwise = exportItems
-
-  return Interface {
-    ifaceMod             = mdl,
-    ifaceOrigFilename    = msHsFilePath ms,
-    ifaceInfo            = info,
-    ifaceDoc             = mbDoc,
-    ifaceRnDoc           = Nothing,
-    ifaceOptions         = opts,
-    ifaceRnDocMap        = Map.empty,
-    ifaceExportItems     = prunedExportItems,
-    ifaceRnExportItems   = [],
-    ifaceExports         = exportedNames,
-    ifaceVisibleExports  = visibleNames,
-    ifaceDeclMap         = declMap,
-    ifaceSubMap          = mkSubMap declMap exportedNames,
-    ifaceInstances       = instances,
-    ifaceInstanceDocMap  = instanceDocMap,
-    ifaceHaddockCoverage = coverage
-  }
-
-
--------------------------------------------------------------------------------
--- Doc options
---
--- Haddock options that are embedded in the source file
--------------------------------------------------------------------------------
-
-
-mkDocOpts :: Maybe String -> [Flag] -> Module -> ErrMsgM [DocOption]
-mkDocOpts mbOpts flags mdl = do
-  opts <- case mbOpts of
-    Just opts -> case words $ replace ',' ' ' opts of
-      [] -> tell ["No option supplied to DOC_OPTION/doc_option"] >> return []
-      xs -> liftM catMaybes (mapM parseOption xs)
-    Nothing -> return []
-  if Flag_HideModule (moduleString mdl) `elem` flags
-    then return $ OptHide : opts
-    else return opts
-
-
-parseOption :: String -> ErrMsgM (Maybe DocOption)
-parseOption "hide"           = return (Just OptHide)
-parseOption "prune"          = return (Just OptPrune)
-parseOption "ignore-exports" = return (Just OptIgnoreExports)
-parseOption "not-home"       = return (Just OptNotHome)
-parseOption other = tell ["Unrecognised option: " ++ other] >> return Nothing
-
-
---------------------------------------------------------------------------------
--- Declarations
---------------------------------------------------------------------------------
-
-
-mkInstanceDocMap :: [Instance] -> [(HsDecl name, doc)] -> Map Name doc
-mkInstanceDocMap instances decls =
-  -- We relate Instances to InstDecls using the SrcSpans buried inside them.
-  -- That should work for normal user-written instances (from looking at GHC
-  -- sources). We can assume that commented instances are user-written.
-  -- This lets us relate Names (from Instances) to comments (associated
-  -- with InstDecls).
-  let docMap = Map.fromList [ (loc, doc)
-                            | (InstD (InstDecl (L loc _) _ _ _), doc) <- decls ]
-
-  in Map.fromList [ (name, doc) | inst <- instances
-                  , let name = getName inst
-                  , Just doc <- [ Map.lookup (getSrcSpan name) docMap ] ]
-
-
--- | Make a sub map from a declaration map. Make sure we only include exported
--- names.
-mkSubMap :: Map Name DeclInfo -> [Name] -> Map Name [Name]
-mkSubMap declMap exports =
-  Map.filterWithKey (\k _ -> k `elem` exports) (Map.map filterSubs declMap)
-  where
-    filterSubs (_, _, subs) = [ sub  | (sub, _) <- subs, sub `elem` exports ]
-
-
--- Make a map from names to 'DeclInfo's. Exclude declarations that don't have
--- names (e.g. instances and stand-alone documentation comments). Include
--- subordinate names, but map them to their parent declarations.
-mkDeclMap :: [DeclInfo] -> Map Name DeclInfo
-mkDeclMap decls = Map.fromList . concat $
-  [ decls_ ++ subDecls
-  | (parent@(L _ d), doc, subs) <- decls
-  , let decls_ = [ (name, (parent, doc, subs)) | name <- declNames d ]
-        subDecls = [ (n, (parent, doc', [])) | (n, doc') <- subs ]
-  , not (isDocD d), not (isInstD d) ]
-
-
-declInfos :: DynFlags -> GlobalRdrEnv -> [(Decl, MaybeDocStrings)] -> ErrMsgM [DeclInfo]
-declInfos dflags gre decls =
-  forM decls $ \(parent@(L _ d), mbDocString) -> do
-            mbDoc <- lexParseRnHaddockCommentList dflags NormalHaddockComment
-                       gre mbDocString
-            fnArgsDoc <- fmap (Map.mapMaybe id) $
-                Traversable.forM (getDeclFnArgDocs d) $
-                \doc -> lexParseRnHaddockComment dflags NormalHaddockComment gre doc
-
-            let subs_ = subordinates d
-            subs <- forM subs_ $ \(subName, mbSubDocStr, subFnArgsDocStr) -> do
-                mbSubDoc <- lexParseRnHaddockCommentList dflags NormalHaddockComment
-                              gre mbSubDocStr
-                subFnArgsDoc <- fmap (Map.mapMaybe id) $
-                  Traversable.forM subFnArgsDocStr $
-                  \doc -> lexParseRnHaddockComment dflags NormalHaddockComment gre doc
-                return (subName, (mbSubDoc, subFnArgsDoc))
-
-            return (parent, (mbDoc, fnArgsDoc), subs)
-
-
--- | If you know the HsDecl can't contain any docs
--- (e.g., it was loaded from a .hi file and you don't have a .haddock file
--- to help you find out about the subs or docs)
--- then you can use this to get its subs.
-subordinatesWithNoDocs :: HsDecl Name -> [(Name, DocForDecl Name)]
-subordinatesWithNoDocs decl = map noDocs (subordinates decl)
-  where
-    -- check the condition... or shouldn't we be checking?
-    noDocs (n, doc1, doc2) | null doc1, Map.null doc2
-        = (n, noDocForDecl)
-    noDocs _ = error ("no-docs thing has docs! " ++ pretty decl)
-
-
-subordinates :: HsDecl Name -> [(Name, MaybeDocStrings, Map Int HsDocString)]
-subordinates (TyClD d) = classDataSubs d
-subordinates _ = []
-
-
-classDataSubs :: TyClDecl Name -> [(Name, MaybeDocStrings, Map Int HsDocString)]
-classDataSubs decl
-  | isClassDecl decl = classSubs
-  | isDataDecl  decl = dataSubs
-  | otherwise        = []
-  where
-    classSubs = [ (name, doc, fnArgsDoc)
-                | (L _ d, doc) <- classDecls decl
-                , name <- declNames d
-                , let fnArgsDoc = getDeclFnArgDocs d ]
-    dataSubs  = constrs ++ fields
-      where
-        cons    = map unL $ tcdCons decl
-        -- should we use the type-signature of the constructor
-        -- and the docs of the fields to produce fnArgsDoc for the constr,
-        -- just in case someone exports it without exporting the type
-        -- and perhaps makes it look like a function?  I doubt it.
-        constrs = [ (unL $ con_name c, maybeToList $ fmap unL $ con_doc c, Map.empty)
-                  | c <- cons ]
-        fields  = [ (unL n, maybeToList $ fmap unL doc, Map.empty)
-                  | RecCon flds <- map con_details cons
-                  , ConDeclField n _ doc <- flds ]
-
-
--- All the sub declarations of a class (that we handle), ordered by
--- source location, with documentation attached if it exists.
-classDecls :: TyClDecl Name -> [(Decl, MaybeDocStrings)]
-classDecls = filterDecls . collectDocs . sortByLoc . declsFromClass
-
-
-declsFromClass :: TyClDecl a -> [Located (HsDecl a)]
-declsFromClass class_ = docs ++ defs ++ sigs ++ ats
-  where
-    docs = mkDecls tcdDocs DocD class_
-    defs = mkDecls (bagToList . tcdMeths) ValD class_
-    sigs = mkDecls tcdSigs SigD class_
-    ats  = mkDecls tcdATs TyClD class_
-
-
-declNames :: HsDecl a -> [a]
-declNames (TyClD d) = [tcdName d]
-declNames (ForD (ForeignImport n _ _)) = [unLoc n]
--- we have normal sigs only (since they are taken from ValBindsOut)
-declNames (SigD sig) = sigNameNoLoc sig
-declNames _ = error "unexpected argument to declNames"
-
-
--- | The top-level declarations of a module that we care about,
--- ordered by source location, with documentation attached if it exists.
-topDecls :: HsGroup Name -> [(Decl, MaybeDocStrings)]
-topDecls = filterClasses . filterDecls . collectDocs . sortByLoc . declsFromGroup
-
-
-filterOutInstances :: [(Located (HsDecl a), b, c)] -> [(Located (HsDecl a), b, c)]
-filterOutInstances = filter (\(L _ d, _, _) -> not (isInstD d))
-
-
--- | Take all declarations except pragmas, infix decls, rules and value
--- bindings from an 'HsGroup'.
-declsFromGroup :: HsGroup Name -> [Decl]
-declsFromGroup group_ =
-#if MIN_VERSION_ghc(7,0,2)
-  mkDecls (concat . hs_tyclds)  TyClD  group_ ++
-#else
-  mkDecls hs_tyclds             TyClD  group_ ++
-#endif
-  mkDecls hs_derivds            DerivD group_ ++
-  mkDecls hs_defds              DefD   group_ ++
-  mkDecls hs_fords              ForD   group_ ++
-  mkDecls hs_docs               DocD   group_ ++
-  mkDecls hs_instds             InstD  group_ ++
-  mkDecls (typesigs . hs_valds) SigD   group_
-  where
-    typesigs (ValBindsOut _ sigs) = filter isVanillaLSig sigs
-    typesigs _ = error "expected ValBindsOut"
-
-
--- | Take a field of declarations from a data structure and create HsDecls
--- using the given constructor
-mkDecls :: (a -> [Located b]) -> (b -> c) -> a -> [Located c]
-mkDecls field con struct = [ L loc (con decl) | L loc decl <- field struct ]
-
-
--- | Sort by source location
-sortByLoc :: [Located a] -> [Located a]
-sortByLoc = sortBy (comparing getLoc)
-
-
-warnAboutFilteredDecls :: Module -> [(LHsDecl Name, b, c)] -> ErrMsgM ()
-warnAboutFilteredDecls mdl decls = do
-  let modStr = moduleString mdl
-  let typeInstances =
-        nub [ tcdName d | (L _ (TyClD d), _, _) <- decls, isFamInstDecl d ]
-
-  unless (null typeInstances) $
-    tell [
-      "Warning: " ++ modStr ++ ": Instances of type and data "
-      ++ "families are not yet supported. Instances of the following families "
-      ++ "will be filtered out:\n  " ++ concat (intersperse ", "
-      $ map (occNameString . nameOccName) typeInstances) ]
-
-  let instances = nub [ pretty i | (L _ (InstD (InstDecl i _ _ ats)), _, _) <- decls
-                                 , not (null ats) ]
-
-  unless (null instances) $
-    tell [
-      "Warning: " ++ modStr ++ ": We do not support associated types in instances yet. "
-      ++ "These instances are affected:\n" ++ concat (intersperse ", " instances) ]
-
-
---------------------------------------------------------------------------------
--- Filtering of declarations
---
--- We filter out declarations that we don't intend to handle later.
---------------------------------------------------------------------------------
-
-
--- | Filter out declarations that we don't handle in Haddock
-filterDecls :: [(Decl, doc)] -> [(Decl, doc)]
-filterDecls decls = filter (isHandled . unL . fst) decls
-  where
-    isHandled (ForD (ForeignImport {})) = True
-    isHandled (TyClD {}) = True
-    isHandled (InstD {}) = True
-    isHandled (SigD d) = isVanillaLSig (reL d)
-    -- we keep doc declarations to be able to get at named docs
-    isHandled (DocD _) = True
-    isHandled _ = False
-
-
--- | Go through all class declarations and filter their sub-declarations
-filterClasses :: [(Decl, doc)] -> [(Decl, doc)]
-filterClasses decls = [ if isClassD d then (L loc (filterClass d), doc) else x
-                      | x@(L loc d, doc) <- decls ]
-  where
-    filterClass (TyClD c) =
-      TyClD $ c { tcdSigs = filter isVanillaLSig $ tcdSigs c }
-    filterClass _ = error "expected TyClD"
-
-
---------------------------------------------------------------------------------
--- Collect docs
---
--- To be able to attach the right Haddock comment to the right declaration,
--- we sort the declarations by their SrcLoc and "collect" the docs for each
--- declaration.
---------------------------------------------------------------------------------
-
-type MaybeDocStrings = [HsDocString]
--- avoid [] because we're appending from the left (quadratic),
--- and avoid adding another package dependency for haddock,
--- so use the difference-list pattern
-type MaybeDocStringsFast = MaybeDocStrings -> MaybeDocStrings
-docStringEmpty :: MaybeDocStringsFast
-docStringEmpty = id
-docStringSingleton :: HsDocString -> MaybeDocStringsFast
-docStringSingleton = (:)
-docStringAppend :: MaybeDocStringsFast -> MaybeDocStringsFast -> MaybeDocStringsFast
-docStringAppend = (.)
-docStringToList :: MaybeDocStringsFast -> MaybeDocStrings
-docStringToList = ($ [])
-
--- | Collect the docs and attach them to the right declaration.
-collectDocs :: [Decl] -> [(Decl, MaybeDocStrings)]
-collectDocs = collect Nothing docStringEmpty
-
-collect :: Maybe Decl -> MaybeDocStringsFast -> [Decl] -> [(Decl, MaybeDocStrings)]
-collect d doc_so_far [] =
-   case d of
-        Nothing -> []
-        Just d0  -> finishedDoc d0 doc_so_far []
-
-collect d doc_so_far (e:es) =
-  case e of
-    L _ (DocD (DocCommentNext str)) ->
-      case d of
-        Nothing -> collect d
-                     (docStringAppend doc_so_far (docStringSingleton str))
-                     es
-        Just d0 -> finishedDoc d0 doc_so_far (collect Nothing
-                     (docStringSingleton str)
-                     es)
-
-    L _ (DocD (DocCommentPrev str)) -> collect d
-                     (docStringAppend doc_so_far (docStringSingleton str))
-                     es
-
-    _ -> case d of
-      Nothing -> collect (Just e) doc_so_far es
-      Just d0 -> finishedDoc d0 doc_so_far (collect (Just e) docStringEmpty es)
-
-
--- This used to delete all DocD:s, unless doc was DocEmpty,
--- which I suppose means you could kill a DocCommentNamed
--- by:
---
--- > -- | killer
--- >
--- > -- $victim
---
--- Anyway I accidentally deleted the DocEmpty condition without
--- realizing it was necessary for retaining some DocDs (at least
--- DocCommentNamed), so I'm going to try just not testing any conditions
--- and see if anything breaks.  It really shouldn't break anything
--- to keep more doc decls around, IMHO.
---
--- -Isaac
-finishedDoc :: Decl -> MaybeDocStringsFast -> [(Decl, MaybeDocStrings)] -> [(Decl, MaybeDocStrings)]
-finishedDoc d doc rest = (d, docStringToList doc) : rest
-
-
--- | Build the list of items that will become the documentation, from the
--- export list.  At this point, the list of ExportItems is in terms of
--- original names.
---
--- We create the export items even if the module is hidden, since they
--- might be useful when creating the export items for other modules.
-mkExportItems
-  :: IfaceMap
-  -> Module             -- this module
-  -> GlobalRdrEnv
-  -> [Name]             -- exported names (orig)
-  -> [DeclInfo]
-  -> Map Name DeclInfo  -- maps local names to declarations
-  -> Maybe [IE Name]
-  -> [Instance]
-  -> InstIfaceMap
-  -> DynFlags
-  -> ErrMsgGhc [ExportItem Name]
-mkExportItems modMap thisMod gre exportedNames decls declMap
-              optExports _ instIfaceMap dflags =
-  case optExports of
-    Nothing      -> liftErrMsg $ fullContentsOfThisModule dflags gre decls
-    Just exports -> liftM (nubBy commaDeclared . concat) $ mapM lookupExport exports
-  where
-    -- A type signature can have multiple names, like:
-    --   foo, bar :: Types..
-    -- When going throug the exported names we have to take care to detect such
-    -- situations and remove the duplicates.
-    commaDeclared (ExportDecl (L _ sig1) _ _ _) (ExportDecl (L _ sig2) _ _ _) =
-      getMainDeclBinder sig1 == getMainDeclBinder sig2
-    commaDeclared _ _ = False
-
-
-    lookupExport (IEVar x)             = declWith x
-    lookupExport (IEThingAbs t)        = declWith t
-    lookupExport (IEThingAll t)        = declWith t
-    lookupExport (IEThingWith t _)     = declWith t
-    lookupExport (IEModuleContents m)  =
-      moduleExports thisMod m dflags gre exportedNames decls modMap instIfaceMap
-    lookupExport (IEGroup lev docStr)  = liftErrMsg $
-      ifDoc (lexParseRnHaddockComment dflags DocSectionComment gre docStr)
-            (\doc -> return [ ExportGroup lev "" doc ])
-    lookupExport (IEDoc docStr)        = liftErrMsg $
-      ifDoc (lexParseRnHaddockComment dflags NormalHaddockComment gre docStr)
-            (\doc -> return [ ExportDoc doc ])
-    lookupExport (IEDocNamed str)      = liftErrMsg $
-      ifDoc (findNamedDoc str [ unL d | (d,_,_) <- decls ])
-            (\docStr ->
-            ifDoc (lexParseRnHaddockComment dflags NormalHaddockComment gre docStr)
-                  (\doc -> return [ ExportDoc doc ]))
-
-
-    ifDoc :: (Monad m) => m (Maybe a) -> (a -> m [b]) -> m [b]
-    ifDoc parse finish = do
-      mbDoc <- parse
-      case mbDoc of Nothing -> return []; Just doc -> finish doc
-
-
-    declWith :: Name -> ErrMsgGhc [ ExportItem Name ]
-    declWith t =
-      case findDecl t of
-        Just (decl, doc, subs) ->
-          let declNames_ = getMainDeclBinder (unL decl)
-          in case () of
-            _
-              -- temp hack: we filter out separately exported ATs, since we haven't decided how
-              -- to handle them yet. We should really give an warning message also, and filter the
-              -- name out in mkVisibleNames...
-              | t `elem` declATs (unL decl)        -> return []
-
-              -- We should not show a subordinate by itself if any of its
-              -- parents is also exported. See note [1].
-              | not $ t `elem` declNames_,
-                Just p <- find isExported (parents t $ unL decl) ->
-                do liftErrMsg $ tell [
-                     "Warning: " ++ moduleString thisMod ++ ": " ++
-                     pretty (nameOccName t) ++ " is exported separately but " ++
-                     "will be documented under " ++ pretty (nameOccName p) ++
-                     ". Consider exporting it together with its parent(s)" ++
-                     " for code clarity." ]
-                   return []
-
-              -- normal case
-              | otherwise -> return [ mkExportDecl t (newDecl, doc, subs) ]
-                  where
-                    -- Since a single signature might refer to many names, we
-                    -- need to filter the ones that are actually exported. This
-                    -- requires modifying the type signatures to "hide" the
-                    -- names that are not exported.
-                    newDecl = case decl of
-                      (L loc (SigD sig)) ->
-                        L loc . SigD . fromJust $ filterSigNames isExported sig
-                        -- fromJust is safe since we already checked in guards
-                        -- that 't' is a name declared in this declaration.
-                      _                  -> decl
-        Nothing -> do
-          -- If we can't find the declaration, it must belong to
-          -- another package
-          mbTyThing <- liftGhcToErrMsgGhc $ lookupName t
-          -- show the name as exported as well as the name's
-          -- defining module (because the latter is where we
-          -- looked for the .hi/.haddock).  It's to help people
-          -- debugging after all, so good to show more info.
-          let exportInfoString =
-                         moduleString thisMod ++ "." ++ getOccString t
-                      ++ ": "
-                      ++ pretty (nameModule t) ++ "." ++ getOccString t
-
-          case mbTyThing of
-            Nothing -> do
-              liftErrMsg $ tell
-                 ["Warning: Couldn't find TyThing for exported "
-                 ++ exportInfoString ++ "; not documenting."]
-              -- Is getting to here a bug in Haddock?
-              -- Aren't the .hi files always present?
-              return [ ExportNoDecl t [] ]
-            Just tyThing -> do
-              let hsdecl = tyThingToLHsDecl tyThing
-              -- This is not the ideal way to implement haddockumentation
-              -- for functions/values without explicit type signatures.
-              --
-              -- However I didn't find an easy way to implement it properly,
-              -- and as long as we're using lookupName it is going to find
-              -- the types of local inferenced binds.  If we don't check for
-              -- this at all, then we'll get the "warning: couldn't find
-              -- .haddock" which is wrong.
-              --
-              -- The reason this is not an ideal implementation
-              -- (besides that we take a trip to desugared syntax and back
-              -- unnecessarily)
-              -- is that Haddock won't be able to detect doc-strings being
-              -- attached to such a function, such as,
-              --
-              -- > -- | this is an identity function
-              -- > id a = a
-              --
-              -- . It's more difficult to say what it ought to mean in cases
-              -- where multiple exports are bound at once, like
-              --
-              -- > -- | comment...
-              -- > (a, b) = ...
-              --
-              -- especially since in the export-list they might not even
-              -- be next to each other.  But a proper implementation would
-              -- really need to find the type of *all* exports as well as
-              -- addressing all these issues.  This implementation works
-              -- adequately.  Do you see a way to improve the situation?
-              -- Please go ahead!  I got stuck trying to figure out how to
-              -- get the 'PostTcType's that we want for all the bindings
-              -- of an HsBind (you get 'LHsBinds' from 'GHC.typecheckedSource'
-              -- for example).
-              --
-              -- But I might be missing something obvious.  What's important
-              -- /here/ is that we behave reasonably when we run into one of
-              -- those exported type-inferenced values.
-              isLocalAndTypeInferenced <- liftGhcToErrMsgGhc $ do
-                    let mdl = nameModule t
-                    if modulePackageId mdl == thisPackage dflags then
-                      isLoaded (moduleName mdl)
-                    else return False
-
-              if isLocalAndTypeInferenced then do
-                -- I don't think there can be any subs in this case,
-                -- currently?  But better not to rely on it.
-                let subs = subordinatesWithNoDocs (unLoc hsdecl)
-                return [ mkExportDecl t (hsdecl, noDocForDecl, subs) ]
-              else
-                -- We try to get the subs and docs
-                -- from the installed interface of that package.
-                case Map.lookup (nameModule t) instIfaceMap of
-                  -- It's Nothing in the cases where I thought
-                  -- Haddock has already warned the user: "Warning: The
-                  -- documentation for the following packages are not
-                  -- installed. No links will be generated to these packages:
-                  -- ..."
-                  -- But I guess it was Cabal creating that warning. Anyway,
-                  -- this is more serious than links: it's exported decls where
-                  -- we don't have the docs that they deserve!
-
-                  -- We could use 'subordinates' to find the Names of the subs
-                  -- (with no docs). Is that necessary? Yes it is, otherwise
-                  -- e.g. classes will be shown without their exported subs.
-                  Nothing -> do
-                     liftErrMsg $ tell
-                        ["Warning: Couldn't find .haddock for exported "
-                        ++ exportInfoString]
-                     let subs = subordinatesWithNoDocs (unLoc hsdecl)
-                     return [ mkExportDecl t (hsdecl, noDocForDecl, subs) ]
-                  Just iface -> do
-                     let subs = case Map.lookup t (instSubMap iface) of
-                             Nothing -> []
-                             Just x -> x
-                     return [ mkExportDecl t
-                       ( hsdecl
-                       , fromMaybe noDocForDecl $
-                            Map.lookup t (instDocMap iface)
-                       , map (\subt ->
-                                ( subt ,
-                                  fromMaybe noDocForDecl $
-                                     Map.lookup subt (instDocMap iface)
-                                )
-                             ) subs
-                       )]
-
-
-    mkExportDecl :: Name -> DeclInfo -> ExportItem Name
-    mkExportDecl n (decl, doc, subs) = decl'
-      where
-        decl' = ExportDecl (restrictTo sub_names (extractDecl n mdl decl)) doc subs' []
-        mdl = nameModule n
-        subs' = filter (isExported . fst) subs
-        sub_names = map fst subs'
-
-
-    isExported = (`elem` exportedNames)
-
-
-    findDecl :: Name -> Maybe DeclInfo
-    findDecl n
-      | m == thisMod = Map.lookup n declMap
-      | otherwise = case Map.lookup m modMap of
-                      Just iface -> Map.lookup n (ifaceDeclMap iface)
-                      Nothing -> Nothing
-      where
-        m = nameModule n
-
-
--- | Return all export items produced by an exported module. That is, we're
--- interested in the exports produced by \"module B\" in such a scenario:
---
--- > module A (module B) where
--- > import B (...) hiding (...)
---
--- There are three different cases to consider:
---
--- 1) B is hidden, in which case we return all its exports that are in scope in A.
--- 2) B is visible, but not all its exports are in scope in A, in which case we
---    only return those that are.
--- 3) B is visible and all its exports are in scope, in which case we return
---    a single 'ExportModule' item. 
-moduleExports :: Module           -- ^ Module A
-              -> ModuleName       -- ^ The real name of B, the exported module
-              -> DynFlags         -- ^ The flag used when typechecking A
-              -> GlobalRdrEnv     -- ^ The renaming environment used for A
-              -> [Name]           -- ^ All the exports of A
-              -> [DeclInfo]       -- ^ All the declarations in A
-              -> IfaceMap         -- ^ Already created interfaces
-              -> InstIfaceMap     -- ^ Interfaces in other packages
-              -> ErrMsgGhc [ExportItem Name] -- ^ Resulting export items
-moduleExports thisMod expMod dflags gre _exports decls ifaceMap instIfaceMap
-  | m == thisMod = liftErrMsg $ fullContentsOfThisModule dflags gre decls
-  | otherwise =
-    case Map.lookup m ifaceMap of
-      Just iface
-        | OptHide `elem` ifaceOptions iface -> return (ifaceExportItems iface)
-        | otherwise -> return [ ExportModule m ]
-
-      Nothing -> -- we have to try to find it in the installed interfaces
-                 -- (external packages)
-        case Map.lookup expMod (Map.mapKeys moduleName instIfaceMap) of
-          Just iface -> return [ ExportModule (instMod iface) ]
-          Nothing -> do
-            liftErrMsg $
-              tell ["Warning: " ++ pretty thisMod ++ ": Could not find " ++
-                    "documentation for exported module: " ++ pretty expMod]
-            return []
-  where
-    m = mkModule packageId expMod
-    packageId = modulePackageId thisMod
-
-
--- Note [1]:
-------------
--- It is unnecessary to document a subordinate by itself at the top level if
--- any of its parents is also documented. Furthermore, if the subordinate is a
--- record field or a class method, documenting it under its parent
--- indicates its special status.
---
--- A user might expect that it should show up separately, so we issue a
--- warning. It's a fine opportunity to also tell the user she might want to
--- export the subordinate through the parent export item for clarity.
---
--- The code removes top-level subordinates also when the parent is exported
--- through a 'module' export. I think that is fine.
---
--- (For more information, see Trac #69)
-
-
-fullContentsOfThisModule :: DynFlags -> GlobalRdrEnv -> [DeclInfo] -> ErrMsgM [ExportItem Name]
-fullContentsOfThisModule dflags gre decls = liftM catMaybes $ mapM mkExportItem decls
-  where
-    mkExportItem (L _ (DocD (DocGroup lev docStr)), _, _) = do
-        mbDoc <- lexParseRnHaddockComment dflags DocSectionComment gre docStr
-        return $ fmap (ExportGroup lev "") mbDoc
-    mkExportItem (L _ (DocD (DocCommentNamed _ docStr)), _, _) = do
-        mbDoc <- lexParseRnHaddockComment dflags NormalHaddockComment gre docStr
-        return $ fmap ExportDoc mbDoc
-    mkExportItem (decl, doc, subs) = return $ Just $ ExportDecl decl doc subs []
-
-
--- | Sometimes the declaration we want to export is not the "main" declaration:
--- it might be an individual record selector or a class method.  In these
--- cases we have to extract the required declaration (and somehow cobble
--- together a type signature for it...)
-extractDecl :: Name -> Module -> Decl -> Decl
-extractDecl name mdl decl
-  | name `elem` getMainDeclBinder (unLoc decl) = decl
-  | otherwise  =
-    case unLoc decl of
-      TyClD d | isClassDecl d ->
-        let matches = [ sig | sig <- tcdSigs d, name `elem` sigName sig,
-                        isVanillaLSig sig ] -- TODO: document fixity
-        in case matches of
-          [s0] -> let (n, tyvar_names) = name_and_tyvars d
-                      L pos sig = extractClassDecl n tyvar_names s0
-                  in L pos (SigD sig)
-          _ -> error "internal: extractDecl"
-      TyClD d | isDataDecl d ->
-        let (n, tyvar_names) = name_and_tyvars d
-            L pos sig = extractRecSel name mdl n tyvar_names (tcdCons d)
-        in L pos (SigD sig)
-      _ -> error "internal: extractDecl"
-  where
-    name_and_tyvars d = (unLoc (tcdLName d), hsLTyVarLocNames (tcdTyVars d))
-
-
-toTypeNoLoc :: Located Name -> LHsType Name
-toTypeNoLoc = noLoc . HsTyVar . unLoc
-
-
-extractClassDecl :: Name -> [Located Name] -> LSig Name -> LSig Name
-extractClassDecl c tvs0 (L pos (TypeSig lname ltype)) = case ltype of
-  L _ (HsForAllTy expl tvs (L _ preds) ty) ->
-    L pos (TypeSig lname (noLoc (HsForAllTy expl tvs (lctxt preds) ty)))
-  _ -> L pos (TypeSig lname (noLoc (mkImplicitHsForAllTy (lctxt []) ltype)))
-  where
-    lctxt = noLoc . ctxt
-    ctxt preds = noLoc (HsClassP c (map toTypeNoLoc tvs0)) : preds
-extractClassDecl _ _ _ = error "extractClassDecl: unexpected decl"
-
-
-extractRecSel :: Name -> Module -> Name -> [Located Name] -> [LConDecl Name]
-              -> LSig Name
-extractRecSel _ _ _ _ [] = error "extractRecSel: selector not found"
-
-extractRecSel nm mdl t tvs (L _ con : rest) =
-  case con_details con of
-    RecCon fields | (ConDeclField n ty _ : _) <- matching_fields fields ->
-      L (getLoc n) (TypeSig [noLoc nm] (noLoc (HsFunTy data_ty (getBangType ty))))
-    _ -> extractRecSel nm mdl t tvs rest
- where
-  matching_fields flds = [ f | f@(ConDeclField n _ _) <- flds, unLoc n == nm ]
-  data_ty = foldl (\x y -> noLoc (HsAppTy x y)) (noLoc (HsTyVar t)) (map toTypeNoLoc tvs)
-
-
--- Pruning
-pruneExportItems :: [ExportItem Name] -> [ExportItem Name]
-pruneExportItems items = filter hasDoc items
-  where
-    hasDoc (ExportDecl{expItemMbDoc = (d, _)}) = isJust d
-    hasDoc _ = True
-
-
-mkVisibleNames :: [ExportItem Name] -> [DocOption] -> [Name]
-mkVisibleNames exports opts
-  | OptHide `elem` opts = []
-  | otherwise = concatMap exportName exports
-  where
-    exportName e@ExportDecl {} = getMainDeclBinder (unL $ expItemDecl e) ++ subs
-      where subs = map fst (expItemSubDocs e)
-    exportName ExportNoDecl {} = [] -- we don't count these as visible, since
-                                    -- we don't want links to go to them.
-    exportName _ = []
-
-
--- | Find a stand-alone documentation comment by its name
-findNamedDoc :: String -> [HsDecl Name] -> ErrMsgM (Maybe HsDocString)
-findNamedDoc name decls = search decls
-  where
-    search [] = do
-      tell ["Cannot find documentation for: $" ++ name]
-      return Nothing
-    search ((DocD (DocCommentNamed name' doc)):rest)
-      | name == name' = return (Just doc)
-      | otherwise = search rest
-    search (_other_decl : rest) = search rest
diff --git a/src/Haddock/Interface/ExtractFnArgDocs.hs b/src/Haddock/Interface/ExtractFnArgDocs.hs
deleted file mode 100644
--- a/src/Haddock/Interface/ExtractFnArgDocs.hs
+++ /dev/null
@@ -1,49 +0,0 @@
------------------------------------------------------------------------------
--- |
--- Module      :  Haddock.Interface.ExtractFnArgDocs
--- Copyright   :  (c) Isaac Dupree 2009,
--- License     :  BSD-like
---
--- Maintainer  :  haddock@projects.haskell.org
--- Stability   :  experimental
--- Portability :  portable
------------------------------------------------------------------------------
-module Haddock.Interface.ExtractFnArgDocs (
-  getDeclFnArgDocs, getSigFnArgDocs, getTypeFnArgDocs
-) where
-
-import Haddock.Types
-
-import qualified Data.Map as Map
-import Data.Map (Map)
-
-import GHC
-
--- the type of Name doesn't matter, except in 6.10 where
--- HsDocString = HsDoc Name, so we can't just say "HsDecl name" yet.
-
-getDeclFnArgDocs :: HsDecl Name -> Map Int HsDocString
-getDeclFnArgDocs (SigD (TypeSig _ ty)) = getTypeFnArgDocs ty
-getDeclFnArgDocs (ForD (ForeignImport _ ty _)) = getTypeFnArgDocs ty
-getDeclFnArgDocs (TyClD (TySynonym {tcdSynRhs = ty})) = getTypeFnArgDocs ty
-getDeclFnArgDocs _ = Map.empty
-
-getSigFnArgDocs :: Sig Name -> Map Int HsDocString
-getSigFnArgDocs (TypeSig _ ty) = getTypeFnArgDocs ty
-getSigFnArgDocs _ = Map.empty
-
-getTypeFnArgDocs :: LHsType Name -> Map Int HsDocString
-getTypeFnArgDocs ty = getLTypeDocs 0 ty
-
-
-getLTypeDocs :: Int -> LHsType Name -> Map Int HsDocString
-getLTypeDocs n (L _ ty) = getTypeDocs n ty
-
-getTypeDocs :: Int -> HsType Name -> Map Int HsDocString
-getTypeDocs n (HsForAllTy _ _ _ ty) = getLTypeDocs n ty
-getTypeDocs n (HsFunTy (L _ (HsDocTy _arg_type (L _ doc))) res_type) =
-      Map.insert n doc $ getLTypeDocs (n+1) res_type
-getTypeDocs n (HsFunTy _ res_type) = getLTypeDocs (n+1) res_type
-getTypeDocs n (HsDocTy _res_type (L _ doc)) = Map.singleton n doc
-getTypeDocs _ _res_type = Map.empty
-
diff --git a/src/Haddock/Interface/LexParseRn.hs b/src/Haddock/Interface/LexParseRn.hs
deleted file mode 100644
--- a/src/Haddock/Interface/LexParseRn.hs
+++ /dev/null
@@ -1,72 +0,0 @@
------------------------------------------------------------------------------
--- |
--- Module      :  Haddock.Interface.LexParseRn
--- Copyright   :  (c) Isaac Dupree 2009,
--- License     :  BSD-like
---
--- Maintainer  :  haddock@projects.haskell.org
--- Stability   :  experimental
--- Portability :  portable
------------------------------------------------------------------------------
-module Haddock.Interface.LexParseRn (
-  HaddockCommentType(..),
-  lexParseRnHaddockComment,
-  lexParseRnHaddockCommentList,
-  lexParseRnMbHaddockComment,
-  lexParseRnHaddockModHeader
-  ) where
-
-import Haddock.Types
-import Haddock.Lex
-import Haddock.Parse
-import Haddock.Interface.Rn
-import Haddock.Interface.ParseModuleHeader
-import Haddock.Doc
-import Data.Maybe
-import FastString
-import GHC
-import RdrName
-
-data HaddockCommentType = NormalHaddockComment | DocSectionComment
-
-lexParseRnHaddockCommentList :: DynFlags -> HaddockCommentType -> GlobalRdrEnv -> [HsDocString] -> ErrMsgM (Maybe (Doc Name))
-lexParseRnHaddockCommentList dflags hty gre docStrs = do
-  docMbs <- mapM (lexParseRnHaddockComment dflags hty gre) docStrs
-  let docs = catMaybes docMbs
-  let doc = foldl docAppend DocEmpty docs
-  case doc of
-    DocEmpty -> return Nothing
-    _ -> return (Just doc)
-
-lexParseRnHaddockComment :: DynFlags -> HaddockCommentType ->
-    GlobalRdrEnv -> HsDocString -> ErrMsgM (Maybe (Doc Name))
-lexParseRnHaddockComment dflags hty gre (HsDocString fs) = do
-   let str = unpackFS fs
-   let toks = tokenise dflags str (0,0) -- TODO: real position
-   let parse = case hty of
-         NormalHaddockComment -> parseParas
-         DocSectionComment -> parseString
-   case parse toks of
-     Nothing -> do
-       tell ["doc comment parse failed: "++str]
-       return Nothing
-     Just doc -> return (Just (rnDoc gre doc))
-
-lexParseRnMbHaddockComment :: DynFlags -> HaddockCommentType -> GlobalRdrEnv -> Maybe HsDocString -> ErrMsgM (Maybe (Doc Name))
-lexParseRnMbHaddockComment _ _ _ Nothing = return Nothing
-lexParseRnMbHaddockComment dflags hty gre (Just d) = lexParseRnHaddockComment dflags hty gre d
-
--- yes, you always get a HaddockModInfo though it might be empty
-lexParseRnHaddockModHeader :: DynFlags -> GlobalRdrEnv -> GhcDocHdr -> ErrMsgM (HaddockModInfo Name, Maybe (Doc Name))
-lexParseRnHaddockModHeader dflags gre mbStr = do
-  let failure = (emptyHaddockModInfo, Nothing)
-  case mbStr of
-    Nothing -> return failure
-    Just (L _ (HsDocString fs)) -> do
-      let str = unpackFS fs
-      case parseModuleHeader dflags str of
-        Left mess -> do
-          tell ["haddock module header parse failed: " ++ mess]
-          return failure
-        Right (info, doc) ->
-          return (rnHaddockModInfo gre info, Just (rnDoc gre doc))
diff --git a/src/Haddock/Interface/ParseModuleHeader.hs b/src/Haddock/Interface/ParseModuleHeader.hs
deleted file mode 100644
--- a/src/Haddock/Interface/ParseModuleHeader.hs
+++ /dev/null
@@ -1,159 +0,0 @@
------------------------------------------------------------------------------
--- |
--- Module      :  Haddock.Interface.ParseModuleHeader
--- Copyright   :  (c) Simon Marlow 2006, Isaac Dupree 2009
--- License     :  BSD-like
---
--- Maintainer  :  haddock@projects.haskell.org
--- Stability   :  experimental
--- Portability :  portable
------------------------------------------------------------------------------
-module Haddock.Interface.ParseModuleHeader (parseModuleHeader) where
-
-import Haddock.Types
-import Haddock.Lex
-import Haddock.Parse
-
-import RdrName
-import DynFlags
-
-import Data.Char
-
--- -----------------------------------------------------------------------------
--- Parsing module headers
-
--- NB.  The headers must be given in the order Module, Description,
--- Copyright, License, Maintainer, Stability, Portability, except that
--- any or all may be omitted.
-parseModuleHeader :: DynFlags -> String -> Either String (HaddockModInfo RdrName, Doc RdrName)
-parseModuleHeader dflags str0 =
-   let
-      getKey :: String -> String -> (Maybe String,String)
-      getKey key str = case parseKey key str of
-         Nothing -> (Nothing,str)
-         Just (value,rest) -> (Just value,rest)
-
-      (_moduleOpt,str1) = getKey "Module" str0
-      (descriptionOpt,str2) = getKey "Description" str1
-      (_copyrightOpt,str3) = getKey "Copyright" str2
-      (_licenseOpt,str4) = getKey "License" str3
-      (_licenceOpt,str5) = getKey "Licence" str4
-      (maintainerOpt,str6) = getKey "Maintainer" str5
-      (stabilityOpt,str7) = getKey "Stability" str6
-      (portabilityOpt,str8) = getKey "Portability" str7
-
-      description1 :: Either String (Maybe (Doc RdrName))
-      description1 = case descriptionOpt of
-         Nothing -> Right Nothing
-         -- TODO: pass real file position
-         Just description -> case parseString $ tokenise dflags description (0,0) of
-            Nothing -> Left ("Cannot parse Description: " ++ description)
-            Just doc -> Right (Just doc)
-   in
-      case description1 of
-         Left mess -> Left mess
-         -- TODO: pass real file position
-         Right docOpt -> case parseParas $ tokenise dflags str8 (0,0) of
-           Nothing -> Left "Cannot parse header documentation paragraphs"
-           Just doc -> Right (HaddockModInfo {
-            hmi_description = docOpt,
-            hmi_portability = portabilityOpt,
-            hmi_stability = stabilityOpt,
-            hmi_maintainer = maintainerOpt
-            }, doc)
-
--- | This function is how we read keys.
---
--- all fields in the header are optional and have the form
---
--- [spaces1][field name][spaces] ":"
---    [text]"\n" ([spaces2][space][text]"\n" | [spaces]"\n")*
--- where each [spaces2] should have [spaces1] as a prefix.
---
--- Thus for the key "Description",
---
--- > Description : this is a
--- >    rather long
--- >
--- >    description
--- >
--- > The module comment starts here
---
--- the value will be "this is a .. description" and the rest will begin
--- at "The module comment".
-parseKey :: String -> String -> Maybe (String,String)
-parseKey key toParse0 =
-   do
-      let
-         (spaces0,toParse1) = extractLeadingSpaces toParse0
-
-         indentation = spaces0
-      afterKey0 <- extractPrefix key toParse1
-      let
-         afterKey1 = extractLeadingSpaces afterKey0
-      afterColon0 <- case snd afterKey1 of
-         ':':afterColon -> return afterColon
-         _ -> Nothing
-      let
-         (_,afterColon1) = extractLeadingSpaces afterColon0
-
-      return (scanKey True indentation afterColon1)
-   where
-      scanKey :: Bool -> String -> String -> (String,String)
-      scanKey _       _           [] = ([],[])
-      scanKey isFirst indentation str =
-         let
-            (nextLine,rest1) = extractNextLine str
-
-            accept = isFirst || sufficientIndentation || allSpaces
-
-            sufficientIndentation = case extractPrefix indentation nextLine of
-               Just (c:_) | isSpace c -> True
-               _ -> False
-
-            allSpaces = case extractLeadingSpaces nextLine of
-               (_,[]) -> True
-               _ -> False
-         in
-            if accept
-               then
-                  let
-                     (scanned1,rest2) = scanKey False indentation rest1
-
-                     scanned2 = case scanned1 of
-                        "" -> if allSpaces then "" else nextLine
-                        _ -> nextLine ++ "\n" ++ scanned1
-                  in
-                     (scanned2,rest2)
-               else
-                  ([],str)
-
-      extractLeadingSpaces :: String -> (String,String)
-      extractLeadingSpaces [] = ([],[])
-      extractLeadingSpaces (s@(c:cs))
-         | isSpace c =
-            let
-               (spaces1,cs1) = extractLeadingSpaces cs
-            in
-               (c:spaces1,cs1)
-         | True = ([],s)
-
-      extractNextLine :: String -> (String,String)
-      extractNextLine [] = ([],[])
-      extractNextLine (c:cs)
-         | c == '\n' =
-            ([],cs)
-         | True =
-            let
-               (line,rest) = extractNextLine cs
-            in
-               (c:line,rest)
-
-      -- comparison is case-insensitive.
-      extractPrefix :: String -> String -> Maybe String
-      extractPrefix [] s = Just s
-      extractPrefix _ [] = Nothing
-      extractPrefix (c1:cs1) (c2:cs2)
-         | toUpper c1 == toUpper c2 = extractPrefix cs1 cs2
-         | True = Nothing
-
diff --git a/src/Haddock/Interface/Rename.hs b/src/Haddock/Interface/Rename.hs
deleted file mode 100644
--- a/src/Haddock/Interface/Rename.hs
+++ /dev/null
@@ -1,458 +0,0 @@
-----------------------------------------------------------------------------
--- |
--- Module      :  Haddock.Interface.Rename
--- Copyright   :  (c) Simon Marlow 2003-2006,
---                    David Waern  2006-2009
--- License     :  BSD-like
---
--- Maintainer  :  haddock@projects.haskell.org
--- Stability   :  experimental
--- Portability :  portable
------------------------------------------------------------------------------
-module Haddock.Interface.Rename (renameInterface) where
-
-
-import Haddock.Types
-import Haddock.GhcUtils
-
-import GHC hiding (NoLink)
-import Name
-import BasicTypes
-import Bag (emptyBag)
-
-import Data.List
-import qualified Data.Map as Map hiding ( Map )
-import Prelude hiding (mapM)
-import Data.Traversable (mapM)
-import Control.Monad hiding (mapM)
-
-
-renameInterface :: LinkEnv -> Bool -> Interface -> ErrMsgM Interface
-renameInterface renamingEnv warnings iface =
-
-  -- first create the local env, where every name exported by this module
-  -- is mapped to itself, and everything else comes from the global renaming
-  -- env
-  let localEnv = foldl fn renamingEnv (ifaceVisibleExports iface)
-        where fn env name = Map.insert name (ifaceMod iface) env
-
-      docMap   = Map.map (\(_,x,_) -> x) (ifaceDeclMap iface)
-
-      -- make instance docs into 'docForDecls'
-      instDocs = [ (name, (Just doc, Map.empty))
-                 | (name, doc) <- Map.toList (ifaceInstanceDocMap iface) ]
-
-      docs     = Map.toList docMap ++ instDocs
-      renameMapElem (k,d) = do d' <- renameDocForDecl d; return (k, d')
-
-      -- rename names in the exported declarations to point to things that
-      -- are closer to, or maybe even exported by, the current module.
-      (renamedExportItems, missingNames1)
-        = runRnFM localEnv (renameExportItems (ifaceExportItems iface))
-
-      (rnDocMap, missingNames2)
-        = runRnFM localEnv (liftM Map.fromList (mapM renameMapElem docs))
-
-      (finalModuleDoc, missingNames3)
-        = runRnFM localEnv (renameMaybeDoc (ifaceDoc iface))
-
-      -- combine the missing names and filter out the built-ins, which would
-      -- otherwise allways be missing.
-      missingNames = nub $ filter isExternalName
-                    (missingNames1 ++ missingNames2 ++ missingNames3)
-
-      -- filter out certain built in type constructors using their string
-      -- representation. TODO: use the Name constants from the GHC API.
---      strings = filter (`notElem` ["()", "[]", "(->)"])
---                (map pretty missingNames)
-      strings = map pretty . filter (\n -> not (isSystemName n || isBuiltInSyntax n)) $ missingNames
-
-  in do
-    -- report things that we couldn't link to. Only do this for non-hidden
-    -- modules.
-    unless (OptHide `elem` ifaceOptions iface || null strings || not warnings) $
-      tell ["Warning: " ++ moduleString (ifaceMod iface) ++
-            ": could not find link destinations for:\n"++
-            unwords ("   " : strings) ]
-
-    return $ iface { ifaceRnDoc         = finalModuleDoc,
-                     ifaceRnDocMap      = rnDocMap,
-                     ifaceRnExportItems = renamedExportItems }
-
-
---------------------------------------------------------------------------------
--- Monad for renaming
---
--- The monad does two things for us: it passes around the environment for
--- renaming, and it returns a list of names which couldn't be found in
--- the environment.
---------------------------------------------------------------------------------
-
-
-newtype GenRnM n a =
-  RnM { unRn :: (n -> (Bool, DocName))  -- name lookup function
-             -> (a,[n])
-      }
-
-type RnM a = GenRnM Name a
-
-instance Monad (GenRnM n) where
-  (>>=) = thenRn
-  return = returnRn
-
-returnRn :: a -> GenRnM n a
-returnRn a   = RnM (const (a,[]))
-thenRn :: GenRnM n a -> (a -> GenRnM n b) -> GenRnM n b
-m `thenRn` k = RnM (\lkp -> case unRn m lkp of
-  (a,out1) -> case unRn (k a) lkp of
-    (b,out2) -> (b,out1++out2))
-
-getLookupRn :: RnM (Name -> (Bool, DocName))
-getLookupRn = RnM (\lkp -> (lkp,[]))
-outRn :: Name -> RnM ()
-outRn name = RnM (const ((),[name]))
-
-lookupRn :: (DocName -> a) -> Name -> RnM a
-lookupRn and_then name = do
-  lkp <- getLookupRn
-  case lkp name of
-    (False,maps_to) -> do outRn name; return (and_then maps_to)
-    (True, maps_to) -> return (and_then maps_to)
-
-
-runRnFM :: LinkEnv -> RnM a -> (a,[Name])
-runRnFM env rn = unRn rn lkp
-  where
-    lkp n = case Map.lookup n env of
-      Nothing  -> (False, Undocumented n)
-      Just mdl -> (True,  Documented n mdl)
-
-
---------------------------------------------------------------------------------
--- Renaming
---------------------------------------------------------------------------------
-
-
-rename :: Name -> RnM DocName
-rename = lookupRn id
-
-
-renameL :: Located Name -> RnM (Located DocName)
-renameL = mapM rename
-
-
-renameExportItems :: [ExportItem Name] -> RnM [ExportItem DocName]
-renameExportItems = mapM renameExportItem
-
-
-renameDocForDecl :: (Maybe (Doc Name), FnArgsDoc Name) -> RnM (Maybe (Doc DocName), FnArgsDoc DocName)
-renameDocForDecl (mbDoc, fnArgsDoc) = do
-  mbDoc' <- renameMaybeDoc mbDoc
-  fnArgsDoc' <- renameFnArgsDoc fnArgsDoc
-  return (mbDoc', fnArgsDoc')
-
-
-renameMaybeDoc :: Maybe (Doc Name) -> RnM (Maybe (Doc DocName))
-renameMaybeDoc = mapM renameDoc
-
-
-renameLDocHsSyn :: LHsDocString -> RnM LHsDocString
-renameLDocHsSyn = return
-
-
-renameDoc :: Doc Name -> RnM (Doc DocName)
-renameDoc d = case d of
-  DocEmpty -> return DocEmpty
-  DocAppend a b -> do
-    a' <- renameDoc a
-    b' <- renameDoc b
-    return (DocAppend a' b')
-  DocString str -> return (DocString str)
-  DocParagraph doc -> do
-    doc' <- renameDoc doc
-    return (DocParagraph doc')
-  DocIdentifier ids -> do
-    lkp <- getLookupRn
-    case [ n | (True, n) <- map lkp ids ] of
-      ids'@(_:_) -> return (DocIdentifier ids')
-      [] -> return (DocIdentifier (map Undocumented ids))
-  DocModule str -> return (DocModule str)
-  DocEmphasis doc -> do
-    doc' <- renameDoc doc
-    return (DocEmphasis doc')
-  DocMonospaced doc -> do
-    doc' <- renameDoc doc
-    return (DocMonospaced doc')
-  DocUnorderedList docs -> do
-    docs' <- mapM renameDoc docs
-    return (DocUnorderedList docs')
-  DocOrderedList docs -> do
-    docs' <- mapM renameDoc docs
-    return (DocOrderedList docs')
-  DocDefList docs -> do
-    docs' <- mapM (\(a,b) -> do
-      a' <- renameDoc a
-      b' <- renameDoc b
-      return (a',b')) docs
-    return (DocDefList docs')
-  DocCodeBlock doc -> do
-    doc' <- renameDoc doc
-    return (DocCodeBlock doc')
-  DocURL str -> return (DocURL str)
-  DocPic str -> return (DocPic str)
-  DocAName str -> return (DocAName str)
-  DocExamples e -> return (DocExamples e)
-
-
-renameFnArgsDoc :: FnArgsDoc Name -> RnM (FnArgsDoc DocName)
-renameFnArgsDoc = mapM renameDoc
-
-
-renameLPred :: LHsPred Name -> RnM (LHsPred DocName)
-renameLPred = mapM renamePred
-
-
-renamePred :: HsPred Name -> RnM (HsPred DocName)
-renamePred (HsClassP name types) = do
-  name'  <- rename name
-  types' <- mapM renameLType types
-  return (HsClassP name' types')
-renamePred (HsEqualP type1 type2) = do
-  type1' <- renameLType type1
-  type2' <- renameLType type2
-  return (HsEqualP type1' type2')
-renamePred (HsIParam (IPName name) t) = do
-  name' <- rename name
-  t'    <- renameLType t
-  return (HsIParam (IPName name') t')
-
-
-renameLType :: LHsType Name -> RnM (LHsType DocName)
-renameLType = mapM renameType
-
-
-renameType :: HsType Name -> RnM (HsType DocName)
-renameType t = case t of
-  HsForAllTy expl tyvars lcontext ltype -> do
-    tyvars'   <- mapM renameLTyVarBndr tyvars
-    lcontext' <- renameLContext lcontext
-    ltype'    <- renameLType ltype
-    return (HsForAllTy expl tyvars' lcontext' ltype')
-
-  HsTyVar n -> return . HsTyVar =<< rename n
-  HsBangTy b ltype -> return . HsBangTy b =<< renameLType ltype
-
-  HsAppTy a b -> do
-    a' <- renameLType a
-    b' <- renameLType b
-    return (HsAppTy a' b')
-
-  HsFunTy a b -> do
-    a' <- renameLType a
-    b' <- renameLType b
-    return (HsFunTy a' b')
-
-  HsListTy ty -> return . HsListTy =<< renameLType ty
-  HsPArrTy ty -> return . HsPArrTy =<< renameLType ty
-
-  HsTupleTy b ts -> return . HsTupleTy b =<< mapM renameLType ts
-
-  HsOpTy a (L loc op) b -> do
-    op' <- rename op
-    a'  <- renameLType a
-    b'  <- renameLType b
-    return (HsOpTy a' (L loc op') b')
-
-  HsParTy ty -> return . HsParTy =<< renameLType ty
-
-  HsPredTy p -> return . HsPredTy =<< renamePred p
-
-  HsKindSig ty k -> do
-    ty' <- renameLType ty
-    return (HsKindSig ty' k)
-
-  HsDocTy ty doc -> do
-    ty' <- renameLType ty
-    doc' <- renameLDocHsSyn doc
-    return (HsDocTy ty' doc')
-
-  _ -> error "renameType"
-
-
-renameLTyVarBndr :: LHsTyVarBndr Name -> RnM (LHsTyVarBndr DocName)
-renameLTyVarBndr (L loc tv) = do
-  name' <- rename (hsTyVarName tv)
-  return $ L loc (replaceTyVarName tv name')
-
-
-renameLContext :: Located [LHsPred Name] -> RnM (Located [LHsPred DocName])
-renameLContext (L loc context) = do
-  context' <- mapM renameLPred context
-  return (L loc context')
-
-
-renameInstHead :: InstHead Name -> RnM (InstHead DocName)
-renameInstHead (preds, className, types) = do
-  preds' <- mapM renamePred preds
-  className' <- rename className
-  types' <- mapM renameType types
-  return (preds', className', types')
-
-
-renameLDecl :: LHsDecl Name -> RnM (LHsDecl DocName)
-renameLDecl (L loc d) = return . L loc =<< renameDecl d
-
-
-renameDecl :: HsDecl Name -> RnM (HsDecl DocName)
-renameDecl decl = case decl of
-  TyClD d -> do
-    d' <- renameTyClD d
-    return (TyClD d')
-  SigD s -> do
-    s' <- renameSig s
-    return (SigD s')
-  ForD d -> do
-    d' <- renameForD d
-    return (ForD d')
-  InstD d -> do
-    d' <- renameInstD d
-    return (InstD d')
-  _ -> error "renameDecl"
-
-
-renameLTyClD :: LTyClDecl Name -> RnM (LTyClDecl DocName)
-renameLTyClD (L loc d) = return . L loc =<< renameTyClD d
-
-
-renameTyClD :: TyClDecl Name -> RnM (TyClDecl DocName)
-renameTyClD d = case d of
-  ForeignType lname b -> do
-    lname' <- renameL lname
-    return (ForeignType lname' b)
-
-  TyFamily flav lname ltyvars kind -> do
-    lname'   <- renameL lname
-    ltyvars' <- mapM renameLTyVarBndr ltyvars
-    return (TyFamily flav lname' ltyvars' kind)
-
-  TyData x lcontext lname ltyvars typats k cons _ -> do
-    lcontext' <- renameLContext lcontext
-    lname'    <- renameL lname
-    ltyvars'  <- mapM renameLTyVarBndr ltyvars
-    typats'   <- mapM (mapM renameLType) typats
-    cons'     <- mapM renameLCon cons
-    -- I don't think we need the derivings, so we return Nothing
-    return (TyData x lcontext' lname' ltyvars' typats' k cons' Nothing)
-
-  TySynonym lname ltyvars typats ltype -> do
-    lname'   <- renameL lname
-    ltyvars' <- mapM renameLTyVarBndr ltyvars
-    ltype'   <- renameLType ltype
-    typats'  <- mapM (mapM renameLType) typats
-    return (TySynonym lname' ltyvars' typats' ltype')
-
-  ClassDecl lcontext lname ltyvars lfundeps lsigs _ ats _ -> do
-    lcontext' <- renameLContext lcontext
-    lname'    <- renameL lname
-    ltyvars'  <- mapM renameLTyVarBndr ltyvars
-    lfundeps' <- mapM renameLFunDep lfundeps
-    lsigs'    <- mapM renameLSig lsigs
-    ats'      <- mapM renameLTyClD ats
-    -- we don't need the default methods or the already collected doc entities
-    return (ClassDecl lcontext' lname' ltyvars' lfundeps' lsigs' emptyBag ats' [])
-
-  where
-    renameLCon (L loc con) = return . L loc =<< renameCon con
-    renameCon decl@(ConDecl { con_name = lname, con_qvars = ltyvars
-                            , con_cxt = lcontext, con_details = details
-                            , con_res = restype, con_doc = mbldoc }) = do
-      lname'    <- renameL lname
-      ltyvars'  <- mapM renameLTyVarBndr ltyvars
-      lcontext' <- renameLContext lcontext
-      details'  <- renameDetails details
-      restype'  <- renameResType restype
-      mbldoc'   <- mapM renameLDocHsSyn mbldoc
-      return (decl { con_name = lname', con_qvars = ltyvars', con_cxt = lcontext'
-                   , con_details = details', con_res = restype', con_doc = mbldoc' })
-
-    renameDetails (RecCon fields) = return . RecCon =<< mapM renameField fields
-    renameDetails (PrefixCon ps) = return . PrefixCon =<< mapM renameLType ps
-    renameDetails (InfixCon a b) = do
-      a' <- renameLType a
-      b' <- renameLType b
-      return (InfixCon a' b')
-
-    renameField (ConDeclField name t doc) = do
-      name' <- renameL name
-      t'   <- renameLType t
-      doc' <- mapM renameLDocHsSyn doc
-      return (ConDeclField name' t' doc')
-
-    renameResType (ResTyH98) = return ResTyH98
-    renameResType (ResTyGADT t) = return . ResTyGADT =<< renameLType t
-
-    renameLFunDep (L loc (xs, ys)) = do
-      xs' <- mapM rename xs
-      ys' <- mapM rename ys
-      return (L loc (xs', ys'))
-
-    renameLSig (L loc sig) = return . L loc =<< renameSig sig
-
-
-renameSig :: Sig Name -> RnM (Sig DocName)
-renameSig sig = case sig of
-  TypeSig lnames ltype -> do
-    lnames' <- mapM renameL lnames
-    ltype' <- renameLType ltype
-    return (TypeSig lnames' ltype')
-  -- we have filtered out all other kinds of signatures in Interface.Create
-  _ -> error "expected TypeSig"
-
-
-renameForD :: ForeignDecl Name -> RnM (ForeignDecl DocName)
-renameForD (ForeignImport lname ltype x) = do
-  lname' <- renameL lname
-  ltype' <- renameLType ltype
-  return (ForeignImport lname' ltype' x)
-renameForD (ForeignExport lname ltype x) = do
-  lname' <- renameL lname
-  ltype' <- renameLType ltype
-  return (ForeignExport lname' ltype' x)
-
-
-renameInstD :: InstDecl Name -> RnM (InstDecl DocName)
-renameInstD (InstDecl ltype _ _ lATs) = do
-  ltype' <- renameLType ltype
-  lATs' <- mapM renameLTyClD lATs
-  return (InstDecl ltype' emptyBag [] lATs')
-
-
-renameExportItem :: ExportItem Name -> RnM (ExportItem DocName)
-renameExportItem item = case item of
-  ExportModule mdl -> return (ExportModule mdl)
-  ExportGroup lev id_ doc -> do
-    doc' <- renameDoc doc
-    return (ExportGroup lev id_ doc')
-  ExportDecl decl doc subs instances -> do
-    decl' <- renameLDecl decl
-    doc'  <- renameDocForDecl doc
-    subs' <- mapM renameSub subs
-    instances' <- forM instances $ \(inst, idoc) -> do
-      inst' <- renameInstHead inst
-      idoc' <- mapM renameDoc idoc
-      return (inst', idoc')
-    return (ExportDecl decl' doc' subs' instances')
-  ExportNoDecl x subs -> do
-    x'    <- lookupRn id x
-    subs' <- mapM (lookupRn id) subs
-    return (ExportNoDecl x' subs')
-  ExportDoc doc -> do
-    doc' <- renameDoc doc
-    return (ExportDoc doc')
-
-
-renameSub :: (Name, DocForDecl Name) -> RnM (DocName, DocForDecl DocName)
-renameSub (n,doc) = do
-  n' <- rename n
-  doc' <- renameDocForDecl doc
-  return (n', doc')
diff --git a/src/Haddock/Interface/Rn.hs b/src/Haddock/Interface/Rn.hs
deleted file mode 100644
--- a/src/Haddock/Interface/Rn.hs
+++ /dev/null
@@ -1,83 +0,0 @@
-module Haddock.Interface.Rn ( rnDoc, rnHaddockModInfo ) where
-
-import Haddock.Types
-
-import RnEnv       ( dataTcOccs )
-
-import RdrName     ( RdrName, gre_name, GlobalRdrEnv, lookupGRE_RdrName )
-import Name        ( Name )
-import Outputable  ( ppr, showSDoc )
-
-rnHaddockModInfo :: GlobalRdrEnv -> HaddockModInfo RdrName -> HaddockModInfo Name
-rnHaddockModInfo gre (HaddockModInfo desc port stab maint) =
-  HaddockModInfo (fmap (rnDoc gre) desc) port stab maint
-
-ids2string :: [RdrName] -> String
-ids2string []    = []
-ids2string (x:_) = showSDoc $ ppr x
-
-data Id x = Id {unId::x}
-instance Monad Id where (Id v)>>=f = f v; return = Id
-
-rnDoc :: GlobalRdrEnv -> Doc RdrName -> Doc Name
-rnDoc gre = unId . do_rn
-  where
- do_rn doc_to_rn = case doc_to_rn of 
-  
-  DocEmpty -> return DocEmpty
-
-  DocAppend a b -> do
-    a' <- do_rn a 
-    b' <- do_rn b
-    return (DocAppend a' b')
-
-  DocString str -> return (DocString str)
-
-  DocParagraph doc -> do
-    doc' <- do_rn doc
-    return (DocParagraph doc')
-
-  DocIdentifier ids -> do
-    let choices = concatMap dataTcOccs ids
-    let gres = concatMap (\rdrName ->
-                 map gre_name (lookupGRE_RdrName rdrName gre)) choices
-    case gres of
-      []   -> return (DocMonospaced (DocString (ids2string ids)))
-      ids' -> return (DocIdentifier ids')
-
-  DocModule str -> return (DocModule str)
-
-  DocEmphasis doc -> do
-    doc' <- do_rn doc
-    return (DocEmphasis doc')
-
-  DocMonospaced doc -> do
-    doc' <- do_rn doc 
-    return (DocMonospaced doc')
- 
-  DocUnorderedList docs -> do
-    docs' <- mapM do_rn docs
-    return (DocUnorderedList docs')
-
-  DocOrderedList docs -> do
-    docs' <- mapM do_rn docs
-    return (DocOrderedList docs')
-
-  DocDefList list -> do
-    list' <- mapM (\(a,b) -> do
-      a' <- do_rn a
-      b' <- do_rn b
-      return (a', b')) list
-    return (DocDefList list')
-
-  DocCodeBlock doc -> do
-    doc' <- do_rn doc
-    return (DocCodeBlock doc')
-
-  DocURL str -> return (DocURL str)
-
-  DocPic str -> return (DocPic str)
-
-  DocAName str -> return (DocAName str)
-
-  DocExamples e -> return (DocExamples e)
diff --git a/src/Haddock/InterfaceFile.hs b/src/Haddock/InterfaceFile.hs
deleted file mode 100644
--- a/src/Haddock/InterfaceFile.hs
+++ /dev/null
@@ -1,543 +0,0 @@
-{-# OPTIONS_GHC -fno-warn-orphans #-}
------------------------------------------------------------------------------
--- |
--- Module      :  Haddock.InterfaceFile
--- Copyright   :  (c) David Waern 2006-2009
--- License     :  BSD-like
---
--- Maintainer  :  haddock@projects.haskell.org
--- Stability   :  experimental
--- Portability :  portable
---
--- Reading and writing the .haddock interface file
------------------------------------------------------------------------------
-module Haddock.InterfaceFile (
-  InterfaceFile(..), ifPackageId,
-  readInterfaceFile, nameCacheFromGhc, freshNameCache, NameCacheAccessor,
-  writeInterfaceFile
-) where
-
-
-import Haddock.Types
-import Haddock.Utils hiding (out)
-
-import Data.List
-import Data.Word
-import Data.Array
-import Data.IORef
-import qualified Data.Map as Map
-import Data.Map (Map)
-
-import GHC hiding (NoLink)
-import Binary
-import Name
-import UniqSupply
-import UniqFM
-import IfaceEnv
-import HscTypes
-#if MIN_VERSION_ghc(7,1,0)
-import GhcMonad (withSession)
-#endif
-import FastMutInt
-import FastString
-import Unique
-
-
-data InterfaceFile = InterfaceFile {
-  ifLinkEnv         :: LinkEnv,
-  ifInstalledIfaces :: [InstalledInterface]
-}
-
-
-ifPackageId :: InterfaceFile -> PackageId
-ifPackageId if_ =
-  case ifInstalledIfaces if_ of
-    [] -> error "empty InterfaceFile"
-    iface:_ -> modulePackageId $ instMod iface
-
-
-binaryInterfaceMagic :: Word32
-binaryInterfaceMagic = 0xD0Cface
-
-
--- Since datatypes in the GHC API might change between major versions, and
--- because we store GHC datatypes in our interface files, we need to make sure
--- we version our interface files accordingly.
-binaryInterfaceVersion :: Word16
-#if __GLASGOW_HASKELL__ == 700
-binaryInterfaceVersion = 16
-#elif __GLASGOW_HASKELL__ == 701
-binaryInterfaceVersion = 16
-#elif __GLASGOW_HASKELL__ == 702
-binaryInterfaceVersion = 16
-#elif __GLASGOW_HASKELL__ == 703
-binaryInterfaceVersion = 16
-#else
-#error Unknown GHC version
-#endif
-
-
-initBinMemSize :: Int
-initBinMemSize = 1024*1024
-
-
-writeInterfaceFile :: FilePath -> InterfaceFile -> IO ()
-writeInterfaceFile filename iface = do 
-  bh0 <- openBinMem initBinMemSize
-  put_ bh0 binaryInterfaceMagic
-  put_ bh0 binaryInterfaceVersion
-
-  -- remember where the dictionary pointer will go
-  dict_p_p <- tellBin bh0
-  put_ bh0 dict_p_p
-
-  -- remember where the symbol table pointer will go
-  symtab_p_p <- tellBin bh0
-  put_ bh0 symtab_p_p
-
-  -- Make some intial state
-  symtab_next <- newFastMutInt
-  writeFastMutInt symtab_next 0
-  symtab_map <- newIORef emptyUFM
-  let bin_symtab = BinSymbolTable {
-                      bin_symtab_next = symtab_next,
-                      bin_symtab_map  = symtab_map }
-  dict_next_ref <- newFastMutInt
-  writeFastMutInt dict_next_ref 0
-  dict_map_ref <- newIORef emptyUFM
-  let bin_dict = BinDictionary {
-                      bin_dict_next = dict_next_ref,
-                      bin_dict_map  = dict_map_ref }
-  ud <- newWriteState (putName bin_symtab) (putFastString bin_dict)
-
-  -- put the main thing
-  bh <- return $ setUserData bh0 ud
-  put_ bh iface
-
-  -- write the symtab pointer at the front of the file
-  symtab_p <- tellBin bh
-  putAt bh symtab_p_p symtab_p
-  seekBin bh symtab_p
-
-  -- write the symbol table itself
-  symtab_next' <- readFastMutInt symtab_next
-  symtab_map'  <- readIORef symtab_map
-  putSymbolTable bh symtab_next' symtab_map'
-
-  -- write the dictionary pointer at the fornt of the file
-  dict_p <- tellBin bh
-  putAt bh dict_p_p dict_p
-  seekBin bh dict_p
-
-  -- write the dictionary itself
-  dict_next <- readFastMutInt dict_next_ref
-  dict_map  <- readIORef dict_map_ref
-  putDictionary bh dict_next dict_map
-
-  -- and send the result to the file
-  writeBinMem bh filename
-  return ()
-
-
-type NameCacheAccessor m = (m NameCache, NameCache -> m ())
-
-
-nameCacheFromGhc :: NameCacheAccessor Ghc
-nameCacheFromGhc = ( read_from_session , write_to_session )
-  where
-    read_from_session = do
-       ref <- withSession (return . hsc_NC)
-       liftIO $ readIORef ref
-    write_to_session nc' = do
-       ref <- withSession (return . hsc_NC)
-       liftIO $ writeIORef ref nc'
-
-
-freshNameCache :: NameCacheAccessor IO
-freshNameCache = ( create_fresh_nc , \_ -> return () )
-  where
-    create_fresh_nc = do
-       u  <- mkSplitUniqSupply 'a' -- ??
-       return (initNameCache u [])
-
-
--- | Read a Haddock (@.haddock@) interface file. Return either an 
--- 'InterfaceFile' or an error message.
---
--- This function can be called in two ways.  Within a GHC session it will
--- update the use and update the session's name cache.  Outside a GHC session
--- a new empty name cache is used.  The function is therefore generic in the
--- monad being used.  The exact monad is whichever monad the first
--- argument, the getter and setter of the name cache, requires.
---
-readInterfaceFile :: MonadIO m =>
-                     NameCacheAccessor m
-                  -> FilePath -> m (Either String InterfaceFile)
-readInterfaceFile (get_name_cache, set_name_cache) filename = do
-  bh0 <- liftIO $ readBinMem filename
-
-  magic   <- liftIO $ get bh0
-  version <- liftIO $ get bh0
-
-  case () of
-    _ | magic /= binaryInterfaceMagic -> return . Left $
-      "Magic number mismatch: couldn't load interface file: " ++ filename
-      | version /= binaryInterfaceVersion -> return . Left $
-      "Interface file is of wrong version: " ++ filename
-      | otherwise -> do
-
-      dict  <- get_dictionary bh0
-      bh1   <- init_handle_user_data bh0 dict
-
-      theNC <- get_name_cache
-      (nc', symtab) <- get_symbol_table bh1 theNC
-      set_name_cache nc'
-
-      -- set the symbol table
-      let ud' = getUserData bh1
-      bh2 <- return $! setUserData bh1 ud'{ud_symtab = symtab}
-
-      -- load the actual data
-      iface <- liftIO $ get bh2
-      return (Right iface)
- where
-   get_dictionary bin_handle = liftIO $ do
-      dict_p <- get bin_handle
-      data_p <- tellBin bin_handle
-      seekBin bin_handle dict_p
-      dict <- getDictionary bin_handle
-      seekBin bin_handle data_p
-      return dict
-
-   init_handle_user_data bin_handle dict = liftIO $ do
-      ud <- newReadState dict
-      return (setUserData bin_handle ud)
-
-   get_symbol_table bh1 theNC = liftIO $ do
-      symtab_p <- get bh1
-      data_p'  <- tellBin bh1
-      seekBin bh1 symtab_p
-      (nc', symtab) <- getSymbolTable bh1 theNC
-      seekBin bh1 data_p'
-      return (nc', symtab)
-
-
--------------------------------------------------------------------------------
--- * Symbol table
--------------------------------------------------------------------------------
-
-
-putName :: BinSymbolTable -> BinHandle -> Name -> IO ()
-putName BinSymbolTable{
-            bin_symtab_map = symtab_map_ref,
-            bin_symtab_next = symtab_next }    bh name
-  = do
-    symtab_map <- readIORef symtab_map_ref
-    case lookupUFM symtab_map name of
-      Just (off,_) -> put_ bh (fromIntegral off :: Word32)
-      Nothing -> do
-         off <- readFastMutInt symtab_next
-         writeFastMutInt symtab_next (off+1)
-         writeIORef symtab_map_ref
-             $! addToUFM symtab_map name (off,name)
-         put_ bh (fromIntegral off :: Word32)
-
-
-data BinSymbolTable = BinSymbolTable {
-        bin_symtab_next :: !FastMutInt, -- The next index to use
-        bin_symtab_map  :: !(IORef (UniqFM (Int,Name)))
-                                -- indexed by Name
-  }
-
-
-putFastString :: BinDictionary -> BinHandle -> FastString -> IO ()
-putFastString BinDictionary { bin_dict_next = j_r,
-                              bin_dict_map  = out_r}  bh f
-  = do
-    out <- readIORef out_r
-    let unique = getUnique f
-    case lookupUFM out unique of
-        Just (j, _)  -> put_ bh (fromIntegral j :: Word32)
-        Nothing -> do
-           j <- readFastMutInt j_r
-           put_ bh (fromIntegral j :: Word32)
-           writeFastMutInt j_r (j + 1)
-           writeIORef out_r $! addToUFM out unique (j, f)
-
-
-data BinDictionary = BinDictionary {
-        bin_dict_next :: !FastMutInt, -- The next index to use
-        bin_dict_map  :: !(IORef (UniqFM (Int,FastString)))
-                                -- indexed by FastString
-  }
-
-
-putSymbolTable :: BinHandle -> Int -> UniqFM (Int,Name) -> IO ()
-putSymbolTable bh next_off symtab = do
-  put_ bh next_off
-  let names = elems (array (0,next_off-1) (eltsUFM symtab))
-  mapM_ (\n -> serialiseName bh n symtab) names
-
-
-getSymbolTable :: BinHandle -> NameCache -> IO (NameCache, Array Int Name)
-getSymbolTable bh namecache = do
-  sz <- get bh
-  od_names <- sequence (replicate sz (get bh))
-  let
-        arr = listArray (0,sz-1) names
-        (namecache', names) =
-                mapAccumR (fromOnDiskName arr) namecache od_names
-  --
-  return (namecache', arr)
-
-
-type OnDiskName = (PackageId, ModuleName, OccName)
-
-
-fromOnDiskName
-   :: Array Int Name
-   -> NameCache
-   -> OnDiskName
-   -> (NameCache, Name)
-fromOnDiskName _ nc (pid, mod_name, occ) =
-  let
-        modu  = mkModule pid mod_name
-        cache = nsNames nc
-  in
-  case lookupOrigNameCache cache modu occ of
-     Just name -> (nc, name)
-     Nothing   ->
-        let
-                us        = nsUniqs nc
-                u         = uniqFromSupply us
-                name      = mkExternalName u modu occ noSrcSpan
-                new_cache = extendNameCache cache modu occ name
-        in
-        case splitUniqSupply us of { (us',_) ->
-        ( nc{ nsUniqs = us', nsNames = new_cache }, name )
-        }
-
-
-serialiseName :: BinHandle -> Name -> UniqFM (Int,Name) -> IO ()
-serialiseName bh name _ = do
-  let modu = nameModule name
-  put_ bh (modulePackageId modu, moduleName modu, nameOccName name)
-
-
--------------------------------------------------------------------------------
--- * GhcBinary instances
--------------------------------------------------------------------------------
-
-
-instance (Ord k, Binary k, Binary v) => Binary (Map k v) where
-  put_ bh m = put_ bh (Map.toList m)
-  get bh = fmap (Map.fromList) (get bh)
-
-
-instance Binary InterfaceFile where
-  put_ bh (InterfaceFile env ifaces) = do
-    put_ bh env
-    put_ bh ifaces
-
-  get bh = do
-    env    <- get bh
-    ifaces <- get bh
-    return (InterfaceFile env ifaces)
-
-
-instance Binary InstalledInterface where
-  put_ bh (InstalledInterface modu info docMap exps visExps opts subMap) = do
-    put_ bh modu
-    put_ bh info
-    put_ bh docMap
-    put_ bh exps
-    put_ bh visExps
-    put_ bh opts
-    put_ bh subMap
-
-  get bh = do
-    modu    <- get bh
-    info    <- get bh
-    docMap  <- get bh
-    exps    <- get bh
-    visExps <- get bh
-    opts    <- get bh
-    subMap  <- get bh
-
-    return (InstalledInterface modu info docMap
-            exps visExps opts subMap)
-
-
-instance Binary DocOption where
-    put_ bh OptHide = do
-            putByte bh 0
-    put_ bh OptPrune = do
-            putByte bh 1
-    put_ bh OptIgnoreExports = do
-            putByte bh 2
-    put_ bh OptNotHome = do
-            putByte bh 3
-    get bh = do
-            h <- getByte bh
-            case h of
-              0 -> do
-                    return OptHide
-              1 -> do
-                    return OptPrune
-              2 -> do
-                    return OptIgnoreExports
-              3 -> do
-                    return OptNotHome
-              _ -> fail "invalid binary data found"
-
-
-instance Binary Example where
-    put_ bh (Example expression result) = do
-        put_ bh expression
-        put_ bh result
-    get bh = do
-        expression <- get bh
-        result <- get bh
-        return (Example expression result)
-
-
-{-* Generated by DrIFT : Look, but Don't Touch. *-}
-instance (Binary id) => Binary (Doc id) where
-    put_ bh DocEmpty = do
-            putByte bh 0
-    put_ bh (DocAppend aa ab) = do
-            putByte bh 1
-            put_ bh aa
-            put_ bh ab
-    put_ bh (DocString ac) = do
-            putByte bh 2
-            put_ bh ac
-    put_ bh (DocParagraph ad) = do
-            putByte bh 3
-            put_ bh ad
-    put_ bh (DocIdentifier ae) = do
-            putByte bh 4
-            put_ bh ae
-    put_ bh (DocModule af) = do
-            putByte bh 5
-            put_ bh af
-    put_ bh (DocEmphasis ag) = do
-            putByte bh 6
-            put_ bh ag
-    put_ bh (DocMonospaced ah) = do
-            putByte bh 7
-            put_ bh ah
-    put_ bh (DocUnorderedList ai) = do
-            putByte bh 8
-            put_ bh ai
-    put_ bh (DocOrderedList aj) = do
-            putByte bh 9
-            put_ bh aj
-    put_ bh (DocDefList ak) = do
-            putByte bh 10
-            put_ bh ak
-    put_ bh (DocCodeBlock al) = do
-            putByte bh 11
-            put_ bh al
-    put_ bh (DocURL am) = do
-            putByte bh 12
-            put_ bh am
-    put_ bh (DocPic x) = do
-            putByte bh 13
-            put_ bh x
-    put_ bh (DocAName an) = do
-            putByte bh 14
-            put_ bh an
-    put_ bh (DocExamples ao) = do
-            putByte bh 15
-            put_ bh ao
-    get bh = do
-            h <- getByte bh
-            case h of
-              0 -> do
-                    return DocEmpty
-              1 -> do
-                    aa <- get bh
-                    ab <- get bh
-                    return (DocAppend aa ab)
-              2 -> do
-                    ac <- get bh
-                    return (DocString ac)
-              3 -> do
-                    ad <- get bh
-                    return (DocParagraph ad)
-              4 -> do
-                    ae <- get bh
-                    return (DocIdentifier ae)
-              5 -> do
-                    af <- get bh
-                    return (DocModule af)
-              6 -> do
-                    ag <- get bh
-                    return (DocEmphasis ag)
-              7 -> do
-                    ah <- get bh
-                    return (DocMonospaced ah)
-              8 -> do
-                    ai <- get bh
-                    return (DocUnorderedList ai)
-              9 -> do
-                    aj <- get bh
-                    return (DocOrderedList aj)
-              10 -> do
-                    ak <- get bh
-                    return (DocDefList ak)
-              11 -> do
-                    al <- get bh
-                    return (DocCodeBlock al)
-              12 -> do
-                    am <- get bh
-                    return (DocURL am)
-              13 -> do
-                    x <- get bh
-                    return (DocPic x)
-              14 -> do
-                    an <- get bh
-                    return (DocAName an)
-              15 -> do
-                    ao <- get bh
-                    return (DocExamples ao)
-              _ -> fail "invalid binary data found"
-
-
-instance Binary name => Binary (HaddockModInfo name) where
-  put_ bh hmi = do
-    put_ bh (hmi_description hmi)
-    put_ bh (hmi_portability hmi)
-    put_ bh (hmi_stability   hmi)
-    put_ bh (hmi_maintainer  hmi)
-
-  get bh = do
-    descr <- get bh
-    porta <- get bh
-    stabi <- get bh
-    maint <- get bh
-    return (HaddockModInfo descr porta stabi maint)
-
-
-instance Binary DocName where
-  put_ bh (Documented name modu) = do
-    putByte bh 0
-    put_ bh name
-    put_ bh modu
-  put_ bh (Undocumented name) = do
-    putByte bh 1
-    put_ bh name
-
-  get bh = do
-    h <- getByte bh
-    case h of
-      0 -> do
-        name <- get bh
-        modu <- get bh
-        return (Documented name modu)
-      1 -> do
-        name <- get bh
-        return (Undocumented name)
-      _ -> error "get DocName: Bad h"
-
diff --git a/src/Haddock/Lex.x b/src/Haddock/Lex.x
deleted file mode 100644
--- a/src/Haddock/Lex.x
+++ /dev/null
@@ -1,235 +0,0 @@
---
--- Haddock - A Haskell Documentation Tool
---
--- (c) Simon Marlow 2002
---
--- This file was modified and integrated into GHC by David Waern 2006.
--- Then moved back into Haddock by Isaac Dupree in 2009 :-)
---
-
-{
-{-# LANGUAGE BangPatterns #-}   -- Generated by Alex
-{-# OPTIONS -Wwarn -w #-}
--- The above warning supression flag is a temporary kludge.
--- While working on this module you are encouraged to remove it and fix
--- any warnings in the module. See
---     http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings
--- for details
-
-module Haddock.Lex (
-	Token(..),
-	LToken,
-	tokenise
- ) where
-
-import Lexer hiding (Token)
-import Parser ( parseIdentifier )
-import StringBuffer
-import RdrName
-import SrcLoc
-import DynFlags
-import FastString
-
-import Data.Char
-import Data.Word (Word8)
-import Numeric
-import System.IO.Unsafe
-}
-
-$ws    = $white # \n
-$digit = [0-9]
-$hexdigit = [0-9a-fA-F]
-$special =  [\"\@]
-$alphanum = [A-Za-z0-9]
-$ident    = [$alphanum \'\_\.\!\#\$\%\&\*\+\/\<\=\>\?\@\\\\\^\|\-\~\:]
-
-:-
-
--- beginning of a paragraph
-<0,para> {
- $ws* \n		;
- $ws* \>		{ begin birdtrack }
- $ws* \>\>\>            { strtoken TokExamplePrompt `andBegin` exampleexpr }
- $ws* [\*\-]		{ token TokBullet `andBegin` string }
- $ws* \[		{ token TokDefStart `andBegin` def }
- $ws* \( $digit+ \) 	{ token TokNumber `andBegin` string }
- $ws* $digit+ \. 	{ token TokNumber `andBegin` string }
- $ws*			{ begin string }		
-}
-
--- beginning of a line
-<line> {
-  $ws* \>		{ begin birdtrack }
-  $ws* \>\>\>		{ strtoken TokExamplePrompt `andBegin` exampleexpr }
-  $ws* \n		{ token TokPara `andBegin` para }
-  -- Here, we really want to be able to say
-  -- $ws* (\n | <eof>) 	{ token TokPara `andBegin` para}
-  -- because otherwise a trailing line of whitespace will result in 
-  -- a spurious TokString at the end of a docstring.  We don't have <eof>,
-  -- though (NOW I realise what it was for :-).  To get around this, we always
-  -- append \n to the end of a docstring.
-  () 			{ begin string }
-}
-
-<birdtrack> .*	\n?	{ strtokenNL TokBirdTrack `andBegin` line }
-
-<example> {
-  $ws*	\n		{ token TokPara `andBegin` para }
-  $ws* \>\>\>	        { strtoken TokExamplePrompt `andBegin` exampleexpr }
-  ()			{ begin exampleresult }
-}
-
-<exampleexpr> .* \n	{ strtokenNL TokExampleExpression `andBegin` example }
-
-<exampleresult> .* \n	{ strtokenNL TokExampleResult `andBegin` example }
-
-<string,def> {
-  $special			{ strtoken $ \s -> TokSpecial (head s) }
-  \<\< [^\>]* \>\>              { strtoken $ \s -> TokPic (init $ init $ tail $ tail s) }
-  \< [^\>]* \>			{ strtoken $ \s -> TokURL (init (tail s)) }
-  \# [^\#]* \#			{ strtoken $ \s -> TokAName (init (tail s)) }
-  \/ [^\/]* \/                  { strtoken $ \s -> TokEmphasis (init (tail s)) }
-  [\'\`] $ident+ [\'\`]		{ ident }
-  \\ .				{ strtoken (TokString . tail) }
-  "&#" $digit+ \;		{ strtoken $ \s -> TokString [chr (read (init (drop 2 s)))] }
-  "&#" [xX] $hexdigit+ \;	{ strtoken $ \s -> case readHex (init (drop 3 s)) of [(n,_)] -> TokString [chr n] }
-  -- allow special characters through if they don't fit one of the previous
-  -- patterns.
-  [\/\'\`\<\#\&\\]			{ strtoken TokString }
-  [^ $special \/ \< \# \n \'\` \& \\ \]]* \n { strtokenNL TokString `andBegin` line }
-  [^ $special \/ \< \# \n \'\` \& \\ \]]+    { strtoken TokString }
-}
-
-<def> {
-  \]				{ token TokDefEnd `andBegin` string }
-}
-
--- ']' doesn't have any special meaning outside of the [...] at the beginning
--- of a definition paragraph.
-<string> {
-  \]				{ strtoken TokString }
-}
-
-{
--- | A located token
-type LToken = (Token, AlexPosn)
-
-data Token
-  = TokPara
-  | TokNumber
-  | TokBullet
-  | TokDefStart
-  | TokDefEnd
-  | TokSpecial Char
-  | TokIdent [RdrName]
-  | TokString String
-  | TokURL String
-  | TokPic String
-  | TokEmphasis String
-  | TokAName String
-  | TokBirdTrack String
-  | TokExamplePrompt String
-  | TokExampleExpression String
-  | TokExampleResult String
---  deriving Show
-
-tokenPos :: LToken -> (Int, Int)
-tokenPos t = let AlexPn _ line col = snd t in (line, col)
-
--- -----------------------------------------------------------------------------
--- Alex support stuff
-
--- XXX: copied the posn wrapper code from Alex to make this lexer work
--- with both Alex 2.x and Alex 3.x.  However, we are not using the
--- Unicode/UTF-8 support in Alex 3.x, and Unicode documentation will
--- probably get mangled.
-
-type AlexInput = (AlexPosn,     -- current position,
-                  Char,         -- previous char
-                  String)       -- current input string
-
-alexInputPrevChar :: AlexInput -> Char
-alexInputPrevChar (p,c,s) = c
-
-alexGetByte :: AlexInput -> Maybe (Word8,AlexInput)
-alexGetByte (p,c,[]) = Nothing
-alexGetByte (p,_,(c:s))  = let p' = alexMove p c
-                              in p' `seq`  Just (fromIntegral (ord c), (p', c, s))
-
--- for compat with Alex 2.x:
-alexGetChar :: AlexInput -> Maybe (Char,AlexInput)
-alexGetChar i = case alexGetByte i of
-                  Nothing     -> Nothing
-                  Just (b,i') -> Just (chr (fromIntegral b), i')
-
-alexMove :: AlexPosn -> Char -> AlexPosn
-alexMove (AlexPn a l c) '\t' = AlexPn (a+1)  l     (((c+7) `div` 8)*8+1)
-alexMove (AlexPn a l c) '\n' = AlexPn (a+1) (l+1)   1
-alexMove (AlexPn a l c) _    = AlexPn (a+1)  l     (c+1)
-
-data AlexPosn = AlexPn !Int !Int !Int
-        deriving (Eq,Show)
-
-type StartCode = Int
-type Action = AlexPosn -> String -> StartCode -> (StartCode -> [LToken]) -> DynFlags -> [LToken]
-
-tokenise :: DynFlags -> String -> (Int, Int) -> [LToken]
-tokenise dflags str (line, col) = let toks = go (posn, '\n', eofHack str) para in {-trace (show toks)-} toks
-  where
-    posn = AlexPn 0 line col
-
-    go inp@(pos, _, str) sc =
-	  case alexScan inp sc of
-		AlexEOF -> []
-		AlexError _ -> error "lexical error"
-		AlexSkip  inp' _       -> go inp' sc
-		AlexToken inp'@(pos',_,_) len act -> act pos (take len str) sc (\sc -> go inp' sc) dflags
-
--- NB. we add a final \n to the string, (see comment in the beginning of line
--- production above).
-eofHack str = str++"\n"
-
-andBegin  :: Action -> StartCode -> Action
-andBegin act new_sc = \pos str _ cont dflags -> act pos str new_sc cont dflags
-
-token :: Token -> Action
-token t = \pos _ sc cont _ -> (t, pos) : cont sc
-
-strtoken, strtokenNL :: (String -> Token) -> Action
-strtoken t = \pos str sc cont _ -> (t str, pos) : cont sc
-strtokenNL t = \pos str sc cont _ -> (t (filter (/= '\r') str), pos) : cont sc
--- ^ We only want LF line endings in our internal doc string format, so we
--- filter out all CRs.
-
-begin :: StartCode -> Action
-begin sc = \_ _ _ cont _ -> cont sc
-
--- -----------------------------------------------------------------------------
--- Lex a string as a Haskell identifier
-
-ident :: Action
-ident pos str sc cont dflags = 
-  case strToHsQNames dflags loc id of
-	Just names -> (TokIdent names, pos) : cont sc
-	Nothing -> (TokString str, pos) : cont sc
- where id = init (tail str)
-       -- TODO: Get the real filename here. Maybe we should just be
-       --       using GHC SrcLoc's ourself?
-       filename = mkFastString "<unknown file>"
-       loc = case pos of
-             AlexPn _ line col ->
-                 mkRealSrcLoc filename line col
-
-strToHsQNames :: DynFlags -> RealSrcLoc -> String -> Maybe [RdrName]
-strToHsQNames dflags loc str0 = 
-#if MIN_VERSION_ghc(7,1,0)
-  let buffer = stringToStringBuffer str0
-#else
-  let buffer = unsafePerformIO (stringToStringBuffer str0)
-#endif
-      pstate = mkPState dflags buffer loc
-      result = unP parseIdentifier pstate 
-  in case result of 
-       POk _ name -> Just [unLoc name] 
-       _ -> Nothing
-}
diff --git a/src/Haddock/ModuleTree.hs b/src/Haddock/ModuleTree.hs
deleted file mode 100644
--- a/src/Haddock/ModuleTree.hs
+++ /dev/null
@@ -1,56 +0,0 @@
------------------------------------------------------------------------------
--- |
--- Module      :  Haddock.ModuleTree
--- Copyright   :  (c) Simon Marlow 2003-2006,
---                    David Waern  2006
--- License     :  BSD-like
---
--- Maintainer  :  haddock@projects.haskell.org
--- Stability   :  experimental
--- Portability :  portable
------------------------------------------------------------------------------
-module Haddock.ModuleTree ( ModuleTree(..), mkModuleTree ) where
-
-
-import Haddock.Types ( Doc )
-
-import GHC           ( Name )
-import Module        ( Module, moduleNameString, moduleName, modulePackageId,
-                       packageIdString )
-
-
-data ModuleTree = Node String Bool (Maybe String) (Maybe (Doc Name)) [ModuleTree]
-
-
-mkModuleTree :: Bool -> [(Module, Maybe (Doc Name))] -> [ModuleTree]
-mkModuleTree showPkgs mods =
-  foldr fn [] [ (splitModule mdl, modPkg mdl, short) | (mdl, short) <- mods ]
-  where
-    modPkg mod_ | showPkgs = Just (packageIdString (modulePackageId mod_))
-                | otherwise = Nothing
-    fn (mod_,pkg,short) = addToTrees mod_ pkg short
-
-
-addToTrees :: [String] -> Maybe String -> Maybe (Doc Name) -> [ModuleTree] -> [ModuleTree]
-addToTrees [] _ _ ts = ts
-addToTrees ss pkg short [] = mkSubTree ss pkg short
-addToTrees (s1:ss) pkg short (t@(Node s2 leaf node_pkg node_short subs) : ts)
-  | s1 >  s2  = t : addToTrees (s1:ss) pkg short ts
-  | s1 == s2  = Node s2 (leaf || null ss) this_pkg this_short (addToTrees ss pkg short subs) : ts
-  | otherwise = mkSubTree (s1:ss) pkg short ++ t : ts
- where
-  this_pkg = if null ss then pkg else node_pkg
-  this_short = if null ss then short else node_short
-
-
-mkSubTree :: [String] -> Maybe String -> Maybe (Doc Name) -> [ModuleTree]
-mkSubTree []     _   _     = []
-mkSubTree [s]    pkg short = [Node s True pkg short []]
-mkSubTree (s:ss) pkg short = [Node s (null ss) Nothing Nothing (mkSubTree ss pkg short)]
-
-
-splitModule :: Module -> [String]
-splitModule mdl = split (moduleNameString (moduleName mdl))
-  where split mod0 = case break (== '.') mod0 of
-          (s1, '.':s2) -> s1 : split s2
-          (s1, _)      -> [s1]
diff --git a/src/Haddock/Options.hs b/src/Haddock/Options.hs
deleted file mode 100644
--- a/src/Haddock/Options.hs
+++ /dev/null
@@ -1,265 +0,0 @@
------------------------------------------------------------------------------
--- |
--- Module      :  Haddock.Options
--- Copyright   :  (c) Simon Marlow 2003-2006,
---                    David Waern  2006-2009
--- License     :  BSD-like
---
--- Maintainer  :  haddock@projects.haskell.org
--- Stability   :  experimental
--- Portability :  portable
---
--- Definition of the command line interface of Haddock.
------------------------------------------------------------------------------
-module Haddock.Options (
-  parseHaddockOpts,
-  Flag(..),
-  getUsage,
-  optTitle,
-  outputDir,
-  optContentsUrl,
-  optIndexUrl,
-  optCssFile,
-  sourceUrls,
-  wikiUrls,
-  optDumpInterfaceFile,
-  optLaTeXStyle,
-  qualification,
-  verbosity,
-  ghcFlags,
-  readIfaceArgs
-) where
-
-
-import Data.Maybe
-import Distribution.Verbosity
-import Haddock.Utils
-import Haddock.Types
-import System.Console.GetOpt
-import qualified Data.Char as Char
-
-
-data Flag
-  = Flag_BuiltInThemes
-  | Flag_CSS String
---  | Flag_DocBook
-  | Flag_ReadInterface String
-  | Flag_DumpInterface String
-  | Flag_Heading String
-  | Flag_Html
-  | Flag_Hoogle
-  | Flag_Lib String
-  | Flag_OutputDir FilePath
-  | Flag_Prologue FilePath
-  | Flag_SourceBaseURL   String
-  | Flag_SourceModuleURL String
-  | Flag_SourceEntityURL String
-  | Flag_WikiBaseURL   String
-  | Flag_WikiModuleURL String
-  | Flag_WikiEntityURL String
-  | Flag_LaTeX
-  | Flag_LaTeXStyle String
-  | Flag_Help
-  | Flag_Verbosity String
-  | Flag_Version
-  | Flag_UseContents String
-  | Flag_GenContents
-  | Flag_UseIndex String
-  | Flag_GenIndex
-  | Flag_IgnoreAllExports
-  | Flag_HideModule String
-  | Flag_OptGhc String
-  | Flag_GhcLibDir String
-  | Flag_GhcVersion
-  | Flag_PrintGhcLibDir
-  | Flag_NoWarnings
-  | Flag_UseUnicode
-  | Flag_NoTmpCompDir
-  | Flag_Qualification String
-  | Flag_PrettyHtml
-  deriving (Eq)
-
-
-options :: Bool -> [OptDescr Flag]
-options backwardsCompat =
-  [
-    Option ['B']  []     (ReqArg Flag_GhcLibDir "DIR")
-      "path to a GHC lib dir, to override the default path",
-    Option ['o']  ["odir"]     (ReqArg Flag_OutputDir "DIR")
-      "directory in which to put the output files",
-    Option ['l']  ["lib"]         (ReqArg Flag_Lib "DIR")
-      "location of Haddock's auxiliary files",
-    Option ['i'] ["read-interface"] (ReqArg Flag_ReadInterface "FILE")
-      "read an interface from FILE",
-    Option ['D']  ["dump-interface"] (ReqArg Flag_DumpInterface "FILE")
-      "write the resulting interface to FILE",
---    Option ['S']  ["docbook"]  (NoArg Flag_DocBook)
---  "output in DocBook XML",
-    Option ['h']  ["html"]     (NoArg Flag_Html)
-      "output in HTML (XHTML 1.0)",
-    Option []  ["latex"]  (NoArg Flag_LaTeX) "use experimental LaTeX rendering",
-    Option []  ["latex-style"]  (ReqArg Flag_LaTeXStyle "FILE") "provide your own LaTeX style in FILE",
-    Option ['U'] ["use-unicode"] (NoArg Flag_UseUnicode) "use Unicode in HTML output",
-    Option []  ["hoogle"]     (NoArg Flag_Hoogle)
-      "output for Hoogle",
-    Option []  ["source-base"]   (ReqArg Flag_SourceBaseURL "URL")
-      "URL for a source code link on the contents\nand index pages",
-    Option ['s'] (if backwardsCompat then ["source", "source-module"] else ["source-module"])
-      (ReqArg Flag_SourceModuleURL "URL")
-      "URL for a source code link for each module\n(using the %{FILE} or %{MODULE} vars)",
-    Option []  ["source-entity"]  (ReqArg Flag_SourceEntityURL "URL")
-      "URL for a source code link for each entity\n(using the %{FILE}, %{MODULE}, %{NAME},\n%{KIND} or %{LINE} vars)",
-    Option []  ["comments-base"]   (ReqArg Flag_WikiBaseURL "URL")
-      "URL for a comments link on the contents\nand index pages",
-    Option []  ["comments-module"]  (ReqArg Flag_WikiModuleURL "URL")
-      "URL for a comments link for each module\n(using the %{MODULE} var)",
-    Option []  ["comments-entity"]  (ReqArg Flag_WikiEntityURL "URL")
-      "URL for a comments link for each entity\n(using the %{FILE}, %{MODULE}, %{NAME},\n%{KIND} or %{LINE} vars)",
-    Option ['c']  ["css", "theme"] (ReqArg Flag_CSS "PATH")
-      "the CSS file or theme directory to use for HTML output",
-    Option []  ["built-in-themes"] (NoArg Flag_BuiltInThemes)
-      "include all the built-in haddock themes",
-    Option ['p']  ["prologue"] (ReqArg Flag_Prologue "FILE")
-      "file containing prologue text",
-    Option ['t']  ["title"]    (ReqArg Flag_Heading "TITLE")
-      "page heading",
-    Option ['q']  ["qual"] (ReqArg Flag_Qualification "QUAL")
-      "qualification of names, one of \n'none' (default), 'full', 'local'\nor 'relative'",
-    Option ['?']  ["help"]  (NoArg Flag_Help)
-      "display this help and exit",
-    Option ['V']  ["version"]  (NoArg Flag_Version)
-      "output version information and exit",
-    Option ['v']  ["verbosity"]  (ReqArg Flag_Verbosity "VERBOSITY")
-      "set verbosity level",
-    Option [] ["use-contents"] (ReqArg Flag_UseContents "URL")
-      "use a separately-generated HTML contents page",
-    Option [] ["gen-contents"] (NoArg Flag_GenContents)
-      "generate an HTML contents from specified\ninterfaces",
-    Option [] ["use-index"] (ReqArg Flag_UseIndex "URL")
-      "use a separately-generated HTML index",
-    Option [] ["gen-index"] (NoArg Flag_GenIndex)
-      "generate an HTML index from specified\ninterfaces",
-    Option [] ["ignore-all-exports"] (NoArg Flag_IgnoreAllExports)
-      "behave as if all modules have the\nignore-exports atribute",
-    Option [] ["hide"] (ReqArg Flag_HideModule "MODULE")
-      "behave as if MODULE has the hide attribute",
-    Option [] ["optghc"] (ReqArg Flag_OptGhc "OPTION")
-      "option to be forwarded to GHC",
-    Option []  ["ghc-version"]  (NoArg Flag_GhcVersion)
-      "output GHC version in numeric format",
-    Option []  ["print-ghc-libdir"]  (NoArg Flag_PrintGhcLibDir)
-      "output GHC lib dir",
-    Option ['w'] ["no-warnings"] (NoArg Flag_NoWarnings) "turn off all warnings",
-    Option [] ["no-tmp-comp-dir"] (NoArg Flag_NoTmpCompDir)
-      "do not re-direct compilation output to a temporary directory",
-    Option [] ["pretty-html"] (NoArg Flag_PrettyHtml)
-      "generate html with newlines and indenting (for use with --html)"
-  ]
-
-
-getUsage :: IO String
-getUsage = do
-  prog <- getProgramName
-  return $ usageInfo (usageHeader prog) (options False)
-  where
-    usageHeader :: String -> String
-    usageHeader prog = "Usage: " ++ prog ++ " [OPTION...] file...\n"
-
-
-parseHaddockOpts :: [String] -> IO ([Flag], [String])
-parseHaddockOpts params =
-  case getOpt Permute (options True) params  of
-    (flags, args, []) -> return (flags, args)
-    (_, _, errors)    -> do
-      usage <- getUsage
-      throwE (concat errors ++ usage)
-
-
-optTitle :: [Flag] -> Maybe String
-optTitle flags =
-  case [str | Flag_Heading str <- flags] of
-    [] -> Nothing
-    (t:_) -> Just t
-
-
-outputDir :: [Flag] -> FilePath
-outputDir flags =
-  case [ path | Flag_OutputDir path <- flags ] of
-    []    -> "."
-    paths -> last paths
-
-
-optContentsUrl :: [Flag] -> Maybe String
-optContentsUrl flags = optLast [ url | Flag_UseContents url <- flags ]
-
-
-optIndexUrl :: [Flag] -> Maybe String
-optIndexUrl flags = optLast [ url | Flag_UseIndex url <- flags ]
-
-
-optCssFile :: [Flag] -> Maybe FilePath
-optCssFile flags = optLast [ str | Flag_CSS str <- flags ]
-
-
-sourceUrls :: [Flag] -> (Maybe String, Maybe String, Maybe String)
-sourceUrls flags =
-  (listToMaybe [str | Flag_SourceBaseURL   str <- flags]
-  ,listToMaybe [str | Flag_SourceModuleURL str <- flags]
-  ,listToMaybe [str | Flag_SourceEntityURL str <- flags])
-
-
-wikiUrls :: [Flag] -> (Maybe String, Maybe String, Maybe String)
-wikiUrls flags =
-  (listToMaybe [str | Flag_WikiBaseURL   str <- flags]
-  ,listToMaybe [str | Flag_WikiModuleURL str <- flags]
-  ,listToMaybe [str | Flag_WikiEntityURL str <- flags])
-
-
-optDumpInterfaceFile :: [Flag] -> Maybe FilePath
-optDumpInterfaceFile flags = optLast [ str | Flag_DumpInterface str <- flags ]
-
-
-optLaTeXStyle :: [Flag] -> Maybe String
-optLaTeXStyle flags = optLast [ str | Flag_LaTeXStyle str <- flags ]
-
-
-qualification :: [Flag] -> Qualification
-qualification flags =
-  case map (map Char.toLower) [ str | Flag_Qualification str <- flags ] of
-      "full":_     -> FullQual
-      "local":_    -> LocalQual Nothing
-      "relative":_ -> RelativeQual Nothing
-      _            -> NoQual
-
-
-verbosity :: [Flag] -> Verbosity
-verbosity flags =
-  case [ str | Flag_Verbosity str <- flags ] of
-    []  -> normal
-    x:_ -> case parseVerbosity x of
-      Left e -> throwE e
-      Right v -> v
-
-
-ghcFlags :: [Flag] -> [String]
-ghcFlags flags = [ option | Flag_OptGhc option <- flags ]
-
-
-readIfaceArgs :: [Flag] -> [(DocPaths, FilePath)]
-readIfaceArgs flags = [ parseIfaceOption s | Flag_ReadInterface s <- flags ]
-  where
-    parseIfaceOption :: String -> (DocPaths, FilePath)
-    parseIfaceOption str =
-      case break (==',') str of
-        (fpath, ',':rest) ->
-          case break (==',') rest of
-            (src, ',':file) -> ((fpath, Just src), file)
-            (file, _) -> ((fpath, Nothing), file)
-        (file, _) -> (("", Nothing), file)
-
-
--- | Like 'listToMaybe' but returns the last element instead of the first.
-optLast :: [a] -> Maybe a
-optLast [] = Nothing
-optLast xs = Just (last xs)
-
diff --git a/src/Haddock/Parse.y b/src/Haddock/Parse.y
deleted file mode 100644
--- a/src/Haddock/Parse.y
+++ /dev/null
@@ -1,150 +0,0 @@
-{
-{-# LANGUAGE BangPatterns #-} -- required for versions of Happy before 1.18.6
-{-# OPTIONS -Wwarn -w #-}
--- The above warning supression flag is a temporary kludge.
--- While working on this module you are encouraged to remove it and fix
--- any warnings in the module. See
---     http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings
--- for details
-
-module Haddock.Parse where
-
-import Haddock.Lex
-import Haddock.Types (Doc(..), Example(Example))
-import Haddock.Doc
-import HsSyn
-import RdrName
-import Data.Char  (isSpace)
-import Data.Maybe (fromMaybe)
-import Data.List  (stripPrefix)
-}
-
-%expect 0
-
-%tokentype { LToken }
-
-%token	'/'	{ (TokSpecial '/',_) }
-	'@'	{ (TokSpecial '@',_) }
-	'['     { (TokDefStart,_) }
-	']'     { (TokDefEnd,_) }
-	DQUO 	{ (TokSpecial '\"',_) }
-	URL	{ (TokURL $$,_) }
-	PIC     { (TokPic $$,_) }
-	ANAME	{ (TokAName $$,_) }
-	'/../'  { (TokEmphasis $$,_) }
-	'-'	{ (TokBullet,_) }
-	'(n)'	{ (TokNumber,_) }
-	'>..'	{ (TokBirdTrack $$,_) }
-	PROMPT	{ (TokExamplePrompt $$,_) }
-	RESULT	{ (TokExampleResult $$,_) }
-	EXP	{ (TokExampleExpression $$,_) }
-	IDENT   { (TokIdent $$,_) }
-	PARA    { (TokPara,_) }
-	STRING	{ (TokString $$,_) }
-
-%monad { Maybe }
-
-%name parseParas doc
-%name parseString seq
-
-%%
-
-doc	:: { Doc RdrName }
-	: apara PARA doc	{ docAppend $1 $3 }
-	| PARA doc 		{ $2 }
-	| apara			{ $1 }
-	| {- empty -}		{ DocEmpty }
-
-apara	:: { Doc RdrName }
-	: ulpara		{ DocUnorderedList [$1] }
-	| olpara		{ DocOrderedList [$1] }
-        | defpara               { DocDefList [$1] }
-	| para			{ $1 }
-
-ulpara  :: { Doc RdrName }
-	: '-' para		{ $2 }
-
-olpara  :: { Doc RdrName } 
-	: '(n)' para		{ $2 }
-
-defpara :: { (Doc RdrName, Doc RdrName) }
-	: '[' seq ']' seq	{ ($2, $4) }
-
-para    :: { Doc RdrName }
-	: seq			{ docParagraph $1 }
-	| codepara		{ DocCodeBlock $1 }
-	| examples		{ DocExamples $1 }
-
-codepara :: { Doc RdrName }
-	: '>..' codepara	{ docAppend (DocString $1) $2 }
-	| '>..'			{ DocString $1 }
-
-examples :: { [Example] }
-	: example examples	{ $1 : $2 }
-	| example		{ [$1] }
-
-example :: { Example }
-	: PROMPT EXP result	{ makeExample $1 $2 (lines $3) }
-	| PROMPT EXP		{ makeExample $1 $2 [] }
-
-result :: { String }
-	: RESULT result		{ $1 ++ $2 }
-	| RESULT		{ $1 }
-
-seq	:: { Doc RdrName }
-	: elem seq		{ docAppend $1 $2 }
-	| elem			{ $1 }
-
-elem	:: { Doc RdrName }
-	: elem1			{ $1 }
-	| '@' seq1 '@'		{ DocMonospaced $2 }
-
-seq1	:: { Doc RdrName }
-	: PARA seq1             { docAppend (DocString "\n") $2 }
-	| elem1 seq1            { docAppend $1 $2 }
-	| elem1			{ $1 }
-
-elem1	:: { Doc RdrName }
-	: STRING		{ DocString $1 }
-	| '/../'                { DocEmphasis (DocString $1) }
-	| URL			{ DocURL $1 }
-	| PIC                   { DocPic $1 }
-	| ANAME			{ DocAName $1 }
-	| IDENT			{ DocIdentifier $1 }
-	| DQUO strings DQUO	{ DocModule $2 }
-
-strings  :: { String }
-	: STRING		{ $1 }
-	| STRING strings	{ $1 ++ $2 }
-
-{
-happyError :: [LToken] -> Maybe a
-happyError toks = Nothing
-
--- | Create an 'Example', stripping superfluous characters as appropriate
-makeExample :: String -> String -> [String] -> Example
-makeExample prompt expression result =
-  Example
-	(strip expression)	-- we do not care about leading and trailing
-				-- whitespace in expressions, so drop them
-	result'
-  where
-	-- 1. drop trailing whitespace from the prompt, remember the prefix
-	(prefix, _) = span isSpace prompt
-
-	-- 2. drop, if possible, the exact same sequence of whitespace
-	-- characters from each result line
-	--
-	-- 3. interpret lines that only contain the string "<BLANKLINE>" as an
-	-- empty line
-	result' = map (substituteBlankLine . tryStripPrefix prefix) result
-	  where
-		tryStripPrefix xs ys = fromMaybe ys $ stripPrefix xs ys
-
-		substituteBlankLine "<BLANKLINE>" = ""
-		substituteBlankLine line          = line
-
--- | Remove all leading and trailing whitespace
-strip :: String -> String
-strip = dropWhile isSpace . reverse . dropWhile isSpace . reverse
-}
diff --git a/src/Haddock/Types.hs b/src/Haddock/Types.hs
deleted file mode 100644
--- a/src/Haddock/Types.hs
+++ /dev/null
@@ -1,439 +0,0 @@
-{-# OPTIONS_HADDOCK hide #-}
-{-# LANGUAGE DeriveDataTypeable, DeriveFunctor #-}
------------------------------------------------------------------------------
--- |
--- Module      :  Haddock.Types
--- Copyright   :  (c) Simon Marlow 2003-2006,
---                    David Waern  2006-2009
--- License     :  BSD-like
---
--- Maintainer  :  haddock@projects.haskellorg
--- Stability   :  experimental
--- Portability :  portable
---
--- Types that are commonly used through-out Haddock. Some of the most
--- important types are defined here, like 'Interface' and 'DocName'.
------------------------------------------------------------------------------
-module Haddock.Types (
-  module Haddock.Types
-  , HsDocString, LHsDocString
- ) where
-
-
-import Control.Exception
-import Control.Arrow
-import Data.Typeable
-import Data.Map (Map)
-import qualified Data.Map as Map
-import GHC hiding (NoLink)
-
-
------------------------------------------------------------------------------
--- * Convenient synonyms
------------------------------------------------------------------------------
-
-
-type IfaceMap      = Map Module Interface
-type InstIfaceMap  = Map Module InstalledInterface
-type DocMap        = Map Name (Doc DocName)
-type SrcMap        = Map PackageId FilePath
-type Decl          = LHsDecl Name
-type GhcDocHdr     = Maybe LHsDocString
-type DocPaths      = (FilePath, Maybe FilePath) -- paths to HTML and sources
-
-
------------------------------------------------------------------------------
--- * Interface
------------------------------------------------------------------------------
-
-
--- | 'Interface' holds all information used to render a single Haddock page.
--- It represents the /interface/ of a module. The core business of Haddock
--- lies in creating this structure. Note that the record contains some fields
--- that are only used to create the final record, and that are not used by the
--- backends.
-data Interface = Interface
-  {
-    -- | The module behind this interface.
-    ifaceMod             :: Module
-
-    -- | Original file name of the module.
-  , ifaceOrigFilename    :: FilePath
-
-    -- | Textual information about the module.
-  , ifaceInfo            :: !(HaddockModInfo Name)
-
-    -- | Documentation header.
-  , ifaceDoc             :: !(Maybe (Doc Name))
-
-    -- | Documentation header with cross-reference information.
-  , ifaceRnDoc           :: Maybe (Doc DocName)
-
-    -- | Haddock options for this module (prune, ignore-exports, etc).
-  , ifaceOptions         :: ![DocOption]
-
-    -- | Declarations originating from the module. Excludes declarations without
-    -- names (instances and stand-alone documentation comments). Includes
-    -- names of subordinate declarations mapped to their parent declarations.
-  , ifaceDeclMap         :: Map Name DeclInfo
-
-    -- | Documentation of declarations originating from the module (including
-    -- subordinates).
-  , ifaceRnDocMap        :: Map Name (DocForDecl DocName)
-
-  , ifaceSubMap          :: Map Name [Name]
-
-  , ifaceExportItems     :: ![ExportItem Name]
-  , ifaceRnExportItems   :: [ExportItem DocName]
-
-    -- | All names exported by the module.
-  , ifaceExports         :: ![Name]
-
-    -- | All \"visible\" names exported by the module.
-    -- A visible name is a name that will show up in the documentation of the
-    -- module.
-  , ifaceVisibleExports  :: ![Name]
-
-    -- | Instances exported by the module.
-  , ifaceInstances       :: ![Instance]
-
-    -- | Documentation of instances defined in the module.
-  , ifaceInstanceDocMap  :: Map Name (Doc Name)
-
-    -- | The number of haddockable and haddocked items in the module, as a
-    -- tuple. Haddockable items are the exports and the module itself.
-  , ifaceHaddockCoverage  :: (Int,Int)
-  }
-
-
--- | A subset of the fields of 'Interface' that we store in the interface
--- files.
-data InstalledInterface = InstalledInterface
-  {
-    -- | The module represented by this interface.
-    instMod            :: Module
-
-    -- | Textual information about the module.
-  , instInfo           :: HaddockModInfo Name
-
-    -- | Documentation of declarations originating from the module (including
-    -- subordinates).
-  , instDocMap         :: Map Name (DocForDecl Name)
-
-    -- | All names exported by this module.
-  , instExports        :: [Name]
-
-    -- | All \"visible\" names exported by the module.
-    -- A visible name is a name that will show up in the documentation of the
-    -- module.
-  , instVisibleExports :: [Name]
-
-    -- | Haddock options for this module (prune, ignore-exports, etc).
-  , instOptions        :: [DocOption]
-
-  , instSubMap         :: Map Name [Name]
-  }
-
-
--- | Convert an 'Interface' to an 'InstalledInterface'
-toInstalledIface :: Interface -> InstalledInterface
-toInstalledIface interface = InstalledInterface
-  { instMod            = ifaceMod            interface
-  , instInfo           = ifaceInfo           interface
-  , instDocMap         = fmap unrenameDocForDecl $ ifaceRnDocMap interface
-  , instExports        = ifaceExports        interface
-  , instVisibleExports = ifaceVisibleExports interface
-  , instOptions        = ifaceOptions        interface
-  , instSubMap         = ifaceSubMap         interface
-  }
-
-
------------------------------------------------------------------------------
--- * Export items & declarations
------------------------------------------------------------------------------
-
-
-data ExportItem name
-
-  -- | An exported declaration.
-  = ExportDecl
-      {
-        -- | A declaration.
-        expItemDecl :: LHsDecl name
-
-        -- | Maybe a doc comment, and possibly docs for arguments (if this
-        -- decl is a function or type-synonym).
-      , expItemMbDoc :: DocForDecl name
-
-        -- | Subordinate names, possibly with documentation.
-      , expItemSubDocs :: [(name, DocForDecl name)]
-
-        -- | Instances relevant to this declaration, possibly with
-        -- documentation.
-      , expItemInstances :: [DocInstance name]
-      }
-
-  -- | An exported entity for which we have no documentation (perhaps because it
-  -- resides in another package).
-  | ExportNoDecl
-      { expItemName :: name
-
-        -- | Subordinate names.
-      , expItemSubs :: [name]
-      }
-
-  -- | A section heading. 
-  | ExportGroup
-      {
-        -- | Section level (1, 2, 3, ...).
-        expItemSectionLevel :: Int
-
-        -- | Section id (for hyperlinks).
-      , expItemSectionId :: String
-
-        -- | Section heading text.
-      , expItemSectionText :: Doc name
-      }
-
-  -- | Some documentation.
-  | ExportDoc (Doc name)
-
-  -- | A cross-reference to another module.
-  | ExportModule Module
-
-
--- | A declaration that may have documentation, including its subordinates,
--- which may also have documentation.
-type DeclInfo = (Decl, DocForDecl Name, [(Name, DocForDecl Name)])
-
-
--- | Arguments and result are indexed by Int, zero-based from the left,
--- because that's the easiest to use when recursing over types.
-type FnArgsDoc name = Map Int (Doc name)
-type DocForDecl name = (Maybe (Doc name), FnArgsDoc name)
-
-
-noDocForDecl :: DocForDecl name
-noDocForDecl = (Nothing, Map.empty)
-
-
-unrenameDocForDecl :: DocForDecl DocName -> DocForDecl Name
-unrenameDocForDecl (mbDoc, fnArgsDoc) =
-    (fmap unrenameDoc mbDoc, fmap unrenameDoc fnArgsDoc)
-
-
------------------------------------------------------------------------------
--- * Cross-referencing
------------------------------------------------------------------------------
-
-
--- | Type of environment used to cross-reference identifiers in the syntax.
-type LinkEnv = Map Name Module
-
-
--- | Extends 'Name' with cross-reference information.
-data DocName
-  = Documented Name Module
-     -- ^ This thing is part of the (existing or resulting)
-     -- documentation. The 'Module' is the preferred place
-     -- in the documentation to refer to.
-  | Undocumented Name
-     -- ^ This thing is not part of the (existing or resulting)
-     -- documentation, as far as Haddock knows.
-  deriving Eq
-
-
-instance NamedThing DocName where
-  getName (Documented name _) = name
-  getName (Undocumented name) = name
-
-
------------------------------------------------------------------------------
--- * Instances
------------------------------------------------------------------------------
-
-
--- | An instance head that may have documentation.
-type DocInstance name = (InstHead name, Maybe (Doc name))
-
-
--- | The head of an instance. Consists of a context, a class name and a list
--- of instance types.
-type InstHead name = ([HsPred name], name, [HsType name])
-
-
------------------------------------------------------------------------------
--- * Documentation comments
------------------------------------------------------------------------------
-
-
-type LDoc id = Located (Doc id)
-
-
-data Doc id
-  = DocEmpty
-  | DocAppend (Doc id) (Doc id)
-  | DocString String
-  | DocParagraph (Doc id)
-  | DocIdentifier [id]
-  | DocModule String
-  | DocEmphasis (Doc id)
-  | DocMonospaced (Doc id)
-  | DocUnorderedList [Doc id]
-  | DocOrderedList [Doc id]
-  | DocDefList [(Doc id, Doc id)]
-  | DocCodeBlock (Doc id)
-  | DocURL String
-  | DocPic String
-  | DocAName String
-  | DocExamples [Example]
-  deriving (Eq, Show, Functor)
-
-
-unrenameDoc :: Doc DocName -> Doc Name
-unrenameDoc = fmap getName
-
-
-data Example = Example
-  { exampleExpression :: String
-  , exampleResult     :: [String]
-  } deriving (Eq, Show)
-
-
-exampleToString :: Example -> String
-exampleToString (Example expression result) =
-    ">>> " ++ expression ++ "\n" ++  unlines result
-
-
-data DocMarkup id a = Markup
-  { markupEmpty         :: a
-  , markupString        :: String -> a
-  , markupParagraph     :: a -> a
-  , markupAppend        :: a -> a -> a
-  , markupIdentifier    :: [id] -> a
-  , markupModule        :: String -> a
-  , markupEmphasis      :: a -> a
-  , markupMonospaced    :: a -> a
-  , markupUnorderedList :: [a] -> a
-  , markupOrderedList   :: [a] -> a
-  , markupDefList       :: [(a,a)] -> a
-  , markupCodeBlock     :: a -> a
-  , markupURL           :: String -> a
-  , markupAName         :: String -> a
-  , markupPic           :: String -> a
-  , markupExample       :: [Example] -> a
-  }
-
-
-data HaddockModInfo name = HaddockModInfo
-  { hmi_description :: Maybe (Doc name)
-  , hmi_portability :: Maybe String
-  , hmi_stability   :: Maybe String
-  , hmi_maintainer  :: Maybe String
-  }
-
-
-emptyHaddockModInfo :: HaddockModInfo a
-emptyHaddockModInfo = HaddockModInfo
-  { hmi_description = Nothing
-  , hmi_portability = Nothing
-  , hmi_stability   = Nothing
-  , hmi_maintainer  = Nothing
-  }
-
-
------------------------------------------------------------------------------
--- * Options
------------------------------------------------------------------------------
-
-
-{-! for DocOption derive: Binary !-}
--- | Source-level options for controlling the documentation.
-data DocOption
-  = OptHide            -- ^ This module should not appear in the docs.
-  | OptPrune
-  | OptIgnoreExports   -- ^ Pretend everything is exported.
-  | OptNotHome         -- ^ Not the best place to get docs for things
-                       -- exported by this module.
-  deriving (Eq, Show)
-
-
--- | Option controlling how to qualify names
-data Qualification
-  = NoQual                       -- ^ Never qualify any names.
-  | FullQual                     -- ^ Qualify all names fully.
-  | LocalQual (Maybe Module)     -- ^ Qualify all imported names fully.
-  | RelativeQual (Maybe Module)  -- ^ Like local, but strip module prefix.
-                                 --   from modules in the same hierarchy.
-
-
------------------------------------------------------------------------------
--- * Error handling
------------------------------------------------------------------------------
-
-
--- A monad which collects error messages, locally defined to avoid a dep on mtl
-
-
-type ErrMsg = String
-newtype ErrMsgM a = Writer { runWriter :: (a, [ErrMsg]) }
-
-
-instance Functor ErrMsgM where
-        fmap f (Writer (a, msgs)) = Writer (f a, msgs)
-
-
-instance Monad ErrMsgM where
-        return a = Writer (a, [])
-        m >>= k  = Writer $ let
-                (a, w)  = runWriter m
-                (b, w') = runWriter (k a)
-                in (b, w ++ w')
-
-
-tell :: [ErrMsg] -> ErrMsgM ()
-tell w = Writer ((), w)
-
-
--- Exceptions
-
-
--- | Haddock's own exception type.
-data HaddockException = HaddockException String deriving Typeable
-
-
-instance Show HaddockException where
-  show (HaddockException str) = str
-
-
-throwE :: String -> a
-instance Exception HaddockException
-throwE str = throw (HaddockException str)
-
-
--- In "Haddock.Interface.Create", we need to gather
--- @Haddock.Types.ErrMsg@s a lot, like @ErrMsgM@ does,
--- but we can't just use @GhcT ErrMsgM@ because GhcT requires the
--- transformed monad to be MonadIO.
-newtype ErrMsgGhc a = WriterGhc { runWriterGhc :: (Ghc (a, [ErrMsg])) }
---instance MonadIO ErrMsgGhc where
---  liftIO = WriterGhc . fmap (\a->(a,[])) liftIO
---er, implementing GhcMonad involves annoying ExceptionMonad and
---WarnLogMonad classes, so don't bother.
-liftGhcToErrMsgGhc :: Ghc a -> ErrMsgGhc a
-liftGhcToErrMsgGhc = WriterGhc . fmap (\a->(a,[]))
-liftErrMsg :: ErrMsgM a -> ErrMsgGhc a
-liftErrMsg = WriterGhc . return . runWriter
---  for now, use (liftErrMsg . tell) for this
---tell :: [ErrMsg] -> ErrMsgGhc ()
---tell msgs = WriterGhc $ return ( (), msgs )
-
-
-instance Functor ErrMsgGhc where
-  fmap f (WriterGhc x) = WriterGhc (fmap (first f) x)
-
-
-instance Monad ErrMsgGhc where
-  return a = WriterGhc (return (a, []))
-  m >>= k = WriterGhc $ runWriterGhc m >>= \ (a, msgs1) ->
-               fmap (second (msgs1 ++)) (runWriterGhc (k a))
diff --git a/src/Haddock/Utils.hs b/src/Haddock/Utils.hs
deleted file mode 100644
--- a/src/Haddock/Utils.hs
+++ /dev/null
@@ -1,438 +0,0 @@
------------------------------------------------------------------------------
--- |
--- Module      :  Haddock.Utils
--- Copyright   :  (c) The University of Glasgow 2001-2002,
---                    Simon Marlow 2003-2006,
---                    David Waern  2006-2009
--- License     :  BSD-like
---
--- Maintainer  :  haddock@projects.haskell.org
--- Stability   :  experimental
--- Portability :  portable
------------------------------------------------------------------------------
-module Haddock.Utils (
-
-  -- * Misc utilities
-  restrictTo,
-  toDescription, toInstalledDescription,
-
-  -- * Filename utilities
-  moduleHtmlFile,
-  contentsHtmlFile, indexHtmlFile,
-  frameIndexHtmlFile,
-  moduleIndexFrameName, mainFrameName, synopsisFrameName,
-  subIndexHtmlFile,
-  jsFile, framesFile,
-
-  -- * Anchor and URL utilities
-  moduleNameUrl, moduleUrl,
-  nameAnchorId,
-  makeAnchorId,
-
-  -- * Miscellaneous utilities
-  getProgramName, bye, die, dieMsg, noDieMsg, mapSnd, mapMaybeM, escapeStr,
-
-  -- * HTML cross reference mapping
-  html_xrefs_ref,
-
-  -- * Doc markup 
-  markup,
-  idMarkup,
-
-  -- * List utilities
-  replace,
-  spanWith,
-
-  -- * MTL stuff
-  MonadIO(..),
-
-  -- * Logging
-  parseVerbosity,
-  out,
-
-  -- * System tools
-  getProcessID
- ) where
-
-
-import Haddock.Types
-import Haddock.GhcUtils
-
-import GHC
-import Name
-
-import Control.Monad ( liftM )
-import Data.Char ( isAlpha, isAlphaNum, isAscii, ord, chr )
-import Numeric ( showIntAtBase )
-import Data.Map ( Map )
-import qualified Data.Map as Map hiding ( Map )
-import Data.IORef ( IORef, newIORef, readIORef )
-import Data.List ( isSuffixOf )
-import Data.Maybe ( mapMaybe )
-import System.Environment ( getProgName )
-import System.Exit ( exitWith, ExitCode(..) )
-import System.IO ( hPutStr, stderr )
-import System.IO.Unsafe ( unsafePerformIO )
-import qualified System.FilePath.Posix as HtmlPath
-import Distribution.Verbosity
-import Distribution.ReadE
-
-#ifndef mingw32_HOST_OS
-import qualified System.Posix.Internals
-#endif
-
-import MonadUtils ( MonadIO(..) )
-
-
---------------------------------------------------------------------------------
--- * Logging
---------------------------------------------------------------------------------
-
-
-parseVerbosity :: String -> Either String Verbosity
-parseVerbosity = runReadE flagToVerbosity
-
-
--- | Print a message to stdout, if it is not too verbose
-out :: MonadIO m
-    => Verbosity -- ^ program verbosity
-    -> Verbosity -- ^ message verbosity
-    -> String -> m ()
-out progVerbosity msgVerbosity msg
-  | msgVerbosity <= progVerbosity = liftIO $ putStrLn msg
-  | otherwise = return ()
-
-
---------------------------------------------------------------------------------
--- * Some Utilities
---------------------------------------------------------------------------------
-
-
--- | Extract a module's short description.
-toDescription :: Interface -> Maybe (Doc Name)
-toDescription = hmi_description . ifaceInfo
-
-
--- | Extract a module's short description.
-toInstalledDescription :: InstalledInterface -> Maybe (Doc Name)
-toInstalledDescription = hmi_description . instInfo
-
-
---------------------------------------------------------------------------------
--- * Making abstract declarations
---------------------------------------------------------------------------------
-
-
-restrictTo :: [Name] -> LHsDecl Name -> LHsDecl Name
-restrictTo names (L loc decl) = L loc $ case decl of
-  TyClD d | isDataDecl d && tcdND d == DataType ->
-    TyClD (d { tcdCons = restrictCons names (tcdCons d) })
-  TyClD d | isDataDecl d && tcdND d == NewType ->
-    case restrictCons names (tcdCons d) of
-      []    -> TyClD (d { tcdND = DataType, tcdCons = [] })
-      [con] -> TyClD (d { tcdCons = [con] })
-      _ -> error "Should not happen"
-  TyClD d | isClassDecl d ->
-    TyClD (d { tcdSigs = restrictDecls names (tcdSigs d),
-               tcdATs = restrictATs names (tcdATs d) })
-  _ -> decl
-
-
-restrictCons :: [Name] -> [LConDecl Name] -> [LConDecl Name]
-restrictCons names decls = [ L p d | L p (Just d) <- map (fmap keep) decls ]
-  where
-    keep d | unLoc (con_name d) `elem` names =
-      case con_details d of
-        PrefixCon _ -> Just d
-        RecCon fields
-          | all field_avail fields -> Just d
-          | otherwise -> Just (d { con_details = PrefixCon (field_types fields) })
-          -- if we have *all* the field names available, then
-          -- keep the record declaration.  Otherwise degrade to
-          -- a constructor declaration.  This isn't quite right, but
-          -- it's the best we can do.
-        InfixCon _ _ -> Just d
-      where
-        field_avail (ConDeclField n _ _) = unLoc n `elem` names
-        field_types flds = [ t | ConDeclField _ t _ <- flds ]
-
-    keep _ | otherwise = Nothing
-
-
-restrictDecls :: [Name] -> [LSig Name] -> [LSig Name]
-restrictDecls names decls = mapMaybe (filterLSigNames (`elem` names)) decls
-
-
-restrictATs :: [Name] -> [LTyClDecl Name] -> [LTyClDecl Name]
-restrictATs names ats = [ at | at <- ats , tcdName (unL at) `elem` names ]
-
-
---------------------------------------------------------------------------------
--- * Filename mangling functions stolen from s main/DriverUtil.lhs.
---------------------------------------------------------------------------------
-
-
-moduleHtmlFile :: Module -> FilePath
-moduleHtmlFile mdl =
-  case Map.lookup mdl html_xrefs of
-    Nothing  -> mdl' ++ ".html"
-    Just fp0 -> HtmlPath.joinPath [fp0, mdl' ++ ".html"]
-  where
-   mdl' = map (\c -> if c == '.' then '-' else c)
-              (moduleNameString (moduleName mdl))
-
-
-
-contentsHtmlFile, indexHtmlFile :: String
-contentsHtmlFile = "index.html"
-indexHtmlFile = "doc-index.html"
-
-
--- | The name of the module index file to be displayed inside a frame.
--- Modules are display in full, but without indentation.  Clicking opens in
--- the main window.
-frameIndexHtmlFile :: String
-frameIndexHtmlFile = "index-frames.html"
-
-
-moduleIndexFrameName, mainFrameName, synopsisFrameName :: String
-moduleIndexFrameName = "modules"
-mainFrameName = "main"
-synopsisFrameName = "synopsis"
-
-
-subIndexHtmlFile :: String -> String
-subIndexHtmlFile ls = "doc-index-" ++ b ++ ".html"
-   where b | all isAlpha ls = ls
-           | otherwise = concatMap (show . ord) ls
-
-
--------------------------------------------------------------------------------
--- * Anchor and URL utilities
---
--- NB: Anchor IDs, used as the destination of a link within a document must
--- conform to XML's NAME production. That, taken with XHTML and HTML 4.01's
--- various needs and compatibility constraints, means these IDs have to match:
---      [A-Za-z][A-Za-z0-9:_.-]*
--- Such IDs do not need to be escaped in any way when used as the fragment part
--- of a URL. Indeed, %-escaping them can lead to compatibility issues as it
--- isn't clear if such fragment identifiers should, or should not be unescaped
--- before being matched with IDs in the target document.
--------------------------------------------------------------------------------
- 
-
-moduleUrl :: Module -> String
-moduleUrl = moduleHtmlFile
-
-
-moduleNameUrl :: Module -> OccName -> String
-moduleNameUrl mdl n = moduleUrl mdl ++ '#' : nameAnchorId n
-
-
-nameAnchorId :: OccName -> String
-nameAnchorId name = makeAnchorId (prefix : ':' : occNameString name)
- where prefix | isValOcc name = 'v'
-              | otherwise     = 't'
-
-
--- | Takes an arbitrary string and makes it a valid anchor ID. The mapping is
--- identity preserving.
-makeAnchorId :: String -> String
-makeAnchorId [] = []
-makeAnchorId (f:r) = escape isAlpha f ++ concatMap (escape isLegal) r
-  where
-    escape p c | p c = [c]
-               | otherwise = '-' : show (ord c) ++ "-"
-    isLegal ':' = True
-    isLegal '_' = True
-    isLegal '.' = True
-    isLegal c = isAscii c && isAlphaNum c
-       -- NB: '-' is legal in IDs, but we use it as the escape char
-
-
--------------------------------------------------------------------------------
--- * Files we need to copy from our $libdir
--------------------------------------------------------------------------------
-
-
-jsFile, framesFile :: String
-jsFile    = "haddock-util.js"
-framesFile = "frames.html"
-
-
--------------------------------------------------------------------------------
--- * Misc. 
--------------------------------------------------------------------------------
-
-
-getProgramName :: IO String
-getProgramName = liftM (`withoutSuffix` ".bin") getProgName
-   where str `withoutSuffix` suff
-            | suff `isSuffixOf` str = take (length str - length suff) str
-            | otherwise             = str
-
-
-bye :: String -> IO a
-bye s = putStr s >> exitWith ExitSuccess
-
-
-die :: String -> IO a
-die s = hPutStr stderr s >> exitWith (ExitFailure 1)
-
-
-dieMsg :: String -> IO a
-dieMsg s = getProgramName >>= \prog -> die (prog ++ ": " ++ s)
-
-
-noDieMsg :: String -> IO ()
-noDieMsg s = getProgramName >>= \prog -> hPutStr stderr (prog ++ ": " ++ s)
-
-
-mapSnd :: (b -> c) -> [(a,b)] -> [(a,c)]
-mapSnd _ [] = []
-mapSnd f ((x,y):xs) = (x,f y) : mapSnd f xs
-
-
-mapMaybeM :: Monad m => (a -> m b) -> Maybe a -> m (Maybe b)
-mapMaybeM _ Nothing = return Nothing
-mapMaybeM f (Just a) = liftM Just (f a)
-
-
-escapeStr :: String -> String
-escapeStr = escapeURIString isUnreserved
-
-
--- Following few functions are copy'n'pasted from Network.URI module
--- to avoid depending on the network lib, since doing so gives a
--- circular build dependency between haddock and network
--- (at least if you want to build network with haddock docs)
--- NB: These functions do NOT escape Unicode strings for URLs as per the RFCs
-escapeURIChar :: (Char -> Bool) -> Char -> String
-escapeURIChar p c
-    | p c       = [c]
-    | otherwise = '%' : myShowHex (ord c) ""
-    where
-        myShowHex :: Int -> ShowS
-        myShowHex n r =  case showIntAtBase 16 toChrHex n r of
-            []  -> "00"
-            [a] -> ['0',a]
-            cs  -> cs
-        toChrHex d
-            | d < 10    = chr (ord '0' + fromIntegral d)
-            | otherwise = chr (ord 'A' + fromIntegral (d - 10))
-
-
-escapeURIString :: (Char -> Bool) -> String -> String
-escapeURIString = concatMap . escapeURIChar
-
-
-isUnreserved :: Char -> Bool
-isUnreserved c = isAlphaNumChar c || (c `elem` "-_.~")
-
-
-isAlphaChar, isDigitChar, isAlphaNumChar :: Char -> Bool
-isAlphaChar c    = (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')
-isDigitChar c    = c >= '0' && c <= '9'
-isAlphaNumChar c = isAlphaChar c || isDigitChar c
-
-
------------------------------------------------------------------------------
--- * HTML cross references
---
--- For each module, we need to know where its HTML documentation lives
--- so that we can point hyperlinks to it.  It is extremely
--- inconvenient to plumb this information to all the places that need
--- it (basically every function in HaddockHtml), and furthermore the
--- mapping is constant for any single run of Haddock.  So for the time
--- being I'm going to use a write-once global variable.
------------------------------------------------------------------------------
-
-
-{-# NOINLINE html_xrefs_ref #-}
-html_xrefs_ref :: IORef (Map Module FilePath)
-html_xrefs_ref = unsafePerformIO (newIORef (error "module_map"))
-
-
-{-# NOINLINE html_xrefs #-}
-html_xrefs :: Map Module FilePath
-html_xrefs = unsafePerformIO (readIORef html_xrefs_ref)
-
-
------------------------------------------------------------------------------
--- * List utils
------------------------------------------------------------------------------
-
-
-replace :: Eq a => a -> a -> [a] -> [a]
-replace a b = map (\x -> if x == a then b else x)
-
-
-spanWith :: (a -> Maybe b) -> [a] -> ([b],[a])
-spanWith _ [] = ([],[])
-spanWith p xs@(a:as)
-  | Just b <- p a = let (bs,cs) = spanWith p as in (b:bs,cs)
-  | otherwise     = ([],xs)
-
-
------------------------------------------------------------------------------
--- * Put here temporarily
------------------------------------------------------------------------------
-
-
-markup :: DocMarkup id a -> Doc id -> a
-markup m DocEmpty              = markupEmpty m
-markup m (DocAppend d1 d2)     = markupAppend m (markup m d1) (markup m d2)
-markup m (DocString s)         = markupString m s
-markup m (DocParagraph d)      = markupParagraph m (markup m d)
-markup m (DocIdentifier ids)   = markupIdentifier m ids
-markup m (DocModule mod0)      = markupModule m mod0
-markup m (DocEmphasis d)       = markupEmphasis m (markup m d)
-markup m (DocMonospaced d)     = markupMonospaced m (markup m d)
-markup m (DocUnorderedList ds) = markupUnorderedList m (map (markup m) ds)
-markup m (DocOrderedList ds)   = markupOrderedList m (map (markup m) ds)
-markup m (DocDefList ds)       = markupDefList m (map (markupPair m) ds)
-markup m (DocCodeBlock d)      = markupCodeBlock m (markup m d)
-markup m (DocURL url)          = markupURL m url
-markup m (DocAName ref)        = markupAName m ref
-markup m (DocPic img)          = markupPic m img
-markup m (DocExamples e)       = markupExample m e
-
-
-markupPair :: DocMarkup id a -> (Doc id, Doc id) -> (a, a)
-markupPair m (a,b) = (markup m a, markup m b)
-
-
--- | The identity markup
-idMarkup :: DocMarkup a (Doc a)
-idMarkup = Markup {
-  markupEmpty         = DocEmpty,
-  markupString        = DocString,
-  markupParagraph     = DocParagraph,
-  markupAppend        = DocAppend,
-  markupIdentifier    = DocIdentifier,
-  markupModule        = DocModule,
-  markupEmphasis      = DocEmphasis,
-  markupMonospaced    = DocMonospaced,
-  markupUnorderedList = DocUnorderedList,
-  markupOrderedList   = DocOrderedList,
-  markupDefList       = DocDefList,
-  markupCodeBlock     = DocCodeBlock,
-  markupURL           = DocURL,
-  markupAName         = DocAName,
-  markupPic           = DocPic,
-  markupExample       = DocExamples
-  }
-
-
------------------------------------------------------------------------------
--- * System tools
------------------------------------------------------------------------------
-
-
-#ifdef mingw32_HOST_OS
-foreign import ccall unsafe "_getpid" getProcessID :: IO Int -- relies on Int == Int32 on Windows
-#else
-getProcessID :: IO Int
-getProcessID = fmap fromIntegral System.Posix.Internals.c_getpid
-#endif
-
diff --git a/src/Haddock/Version.hs b/src/Haddock/Version.hs
deleted file mode 100644
--- a/src/Haddock/Version.hs
+++ /dev/null
@@ -1,23 +0,0 @@
------------------------------------------------------------------------------
--- |
--- Module      :  Haddock.Version
--- Copyright   :  (c) Simon Marlow 2003
--- License     :  BSD-like
---
--- Maintainer  :  haddock@projects.haskell.org
--- Stability   :  experimental
--- Portability :  portable
------------------------------------------------------------------------------
-module Haddock.Version ( 
-  projectName, projectVersion, projectUrl
-) where
-
-import Paths_haddock ( version )
-import Data.Version  ( showVersion )
-
-projectName, projectUrl :: String
-projectName = "Haddock"
-projectUrl  = "http://www.haskell.org/haddock/"
-
-projectVersion :: String
-projectVersion = showVersion version
diff --git a/src/Main.hs b/src/Main.hs
deleted file mode 100644
--- a/src/Main.hs
+++ /dev/null
@@ -1,435 +0,0 @@
-{-# OPTIONS_GHC -Wwarn #-}
-{-# LANGUAGE ScopedTypeVariables #-}
------------------------------------------------------------------------------
--- |
--- Module      :  Main
--- Copyright   :  (c) Simon Marlow 2003-2006,
---                    David Waern  2006-2010
--- License     :  BSD-like
---
--- Maintainer  :  haddock@projects.haskell.org
--- Stability   :  experimental
--- Portability :  portable
---
--- Haddock - A Haskell Documentation Tool
---
--- Program entry point and top-level code.
------------------------------------------------------------------------------
-module Main (main, readPackagesAndProcessModules) where
-
-
-import Haddock.Backends.Xhtml
-import Haddock.Backends.Xhtml.Themes (getThemes)
-import Haddock.Backends.LaTeX
-import Haddock.Backends.Hoogle
-import Haddock.Interface
-import Haddock.Lex
-import Haddock.Parse
-import Haddock.Types
-import Haddock.Version
-import Haddock.InterfaceFile
-import Haddock.Options
-import Haddock.Utils
-import Haddock.GhcUtils hiding (pretty)
-
-import Control.Monad
-import Control.Exception
-import Data.Maybe
-import Data.IORef
-import qualified Data.Map as Map
-import System.IO
-import System.Exit
-import System.Environment
-
-#if defined(mingw32_HOST_OS)
-import Foreign
-import Foreign.C
-import Data.Int
-#endif
-
-#ifdef IN_GHC_TREE
-import System.FilePath
-#else
-import GHC.Paths
-import Paths_haddock
-#endif
-
-import GHC hiding (flags, verbosity)
-import Config
-import DynFlags hiding (flags, verbosity)
-import Panic (panic, handleGhcException)
-import Module
-
-
---------------------------------------------------------------------------------
--- * Exception handling
---------------------------------------------------------------------------------
-
-
-handleTopExceptions :: IO a -> IO a
-handleTopExceptions =
-  handleNormalExceptions . handleHaddockExceptions . handleGhcExceptions
-
-
--- | Either returns normally or throws an ExitCode exception;
--- all other exceptions are turned into exit exceptions.
-handleNormalExceptions :: IO a -> IO a
-handleNormalExceptions inner =
-  (inner `onException` hFlush stdout)
-  `catches`
-  [  Handler (\(code :: ExitCode) -> exitWith code)
-
-  ,  Handler (\(ex :: AsyncException) ->
-       case ex of
-         StackOverflow -> do
-           putStrLn "stack overflow: use -g +RTS -K<size> to increase it"
-           exitFailure
-         _ -> do
-           putStrLn ("haddock: " ++ show ex)
-           exitFailure)
-
-  ,  Handler (\(ex :: SomeException) -> do
-        putStrLn ("haddock: internal error: " ++ show ex)
-        exitFailure)
-  ]
-
-
-handleHaddockExceptions :: IO a -> IO a
-handleHaddockExceptions inner =
-  catches inner [Handler handler]
-  where
-    handler (e::HaddockException) = do
-      putStrLn $ "haddock: " ++ show e
-      exitFailure
-
-
-handleGhcExceptions :: IO a -> IO a
-handleGhcExceptions =
-  -- error messages propagated as exceptions
-  handleGhcException $ \e -> do
-    hFlush stdout
-    case e of
-      PhaseFailed _ code -> exitWith code
-      _ -> do
-        print (e :: GhcException)
-        exitFailure
-
-
--------------------------------------------------------------------------------
--- * Top level
--------------------------------------------------------------------------------
-
-
-main :: IO ()
-main = handleTopExceptions $ do
-
-  -- Parse command-line flags and handle some of them initially.
-  args <- getArgs
-  (flags, files) <- parseHaddockOpts args
-  shortcutFlags flags
-
-  if not (null files) then do
-    (packages, ifaces, homeLinks) <- readPackagesAndProcessModules flags files
-
-    -- Dump an "interface file" (.haddock file), if requested.
-    case optDumpInterfaceFile flags of
-      Just f -> dumpInterfaceFile f (map toInstalledIface ifaces) homeLinks
-      Nothing -> return ()
-
-    -- Render the interfaces.
-    renderStep flags packages ifaces
-
-  else do
-    when (any (`elem` [Flag_Html, Flag_Hoogle, Flag_LaTeX]) flags) $
-      throwE "No input file(s)."
-
-    -- Get packages supplied with --read-interface.
-    packages <- readInterfaceFiles freshNameCache (readIfaceArgs flags)
-
-    -- Render even though there are no input files (usually contents/index).
-    renderStep flags packages []
-
-
-readPackagesAndProcessModules :: [Flag] -> [String]
-                              -> IO ([(DocPaths, InterfaceFile)], [Interface], LinkEnv)
-readPackagesAndProcessModules flags files = do
-  libDir <- getGhcLibDir flags
-
-  -- Catches all GHC source errors, then prints and re-throws them.
-  let handleSrcErrors action' = flip handleSourceError action' $ \err -> do
-        printException err
-        liftIO exitFailure
-
-  -- Initialize GHC.
-  withGhc libDir (ghcFlags flags) $ \_ -> handleSrcErrors $ do
-
-    -- Get packages supplied with --read-interface.
-    packages <- readInterfaceFiles nameCacheFromGhc (readIfaceArgs flags)
-
-    -- Create the interfaces -- this is the core part of Haddock.
-    let ifaceFiles = map snd packages
-    (ifaces, homeLinks) <- processModules (verbosity flags) files flags ifaceFiles
-
-    return (packages, ifaces, homeLinks)
-
-
-renderStep :: [Flag] -> [(DocPaths, InterfaceFile)] -> [Interface] -> IO ()
-renderStep flags pkgs interfaces = do
-  updateHTMLXRefs pkgs
-  let
-    ifaceFiles = map snd pkgs
-    installedIfaces = concatMap ifInstalledIfaces ifaceFiles
-    srcMap = Map.fromList [ (ifPackageId if_, x) | ((_, Just x), if_) <- pkgs ]
-  render flags interfaces installedIfaces srcMap
-
-
--- | Render the interfaces with whatever backend is specified in the flags.
-render :: [Flag] -> [Interface] -> [InstalledInterface] -> SrcMap -> IO ()
-render flags ifaces installedIfaces srcMap = do
-
-  let
-    title                = fromMaybe "" (optTitle flags)
-    unicode              = Flag_UseUnicode `elem` flags
-    pretty               = Flag_PrettyHtml `elem` flags
-    opt_wiki_urls        = wikiUrls          flags
-    opt_contents_url     = optContentsUrl    flags
-    opt_index_url        = optIndexUrl       flags
-    odir                 = outputDir         flags
-    opt_latex_style      = optLaTeXStyle     flags
-    opt_qualification    = qualification     flags
-
-    visibleIfaces    = [ i | i <- ifaces, OptHide `notElem` ifaceOptions i ]
-
-    -- /All/ visible interfaces including external package modules.
-    allIfaces        = map toInstalledIface ifaces ++ installedIfaces
-    allVisibleIfaces = [ i | i <- allIfaces, OptHide `notElem` instOptions i ]
-
-    pkgMod           = ifaceMod (head ifaces)
-    pkgId            = modulePackageId pkgMod
-    pkgStr           = Just (packageIdString pkgId)
-    (pkgName,pkgVer) = modulePackageInfo pkgMod
-
-    (srcBase, srcModule, srcEntity) = sourceUrls flags
-    srcMap' = maybe srcMap (\path -> Map.insert pkgId path srcMap) srcEntity
-    sourceUrls' = (srcBase, srcModule, srcMap')
-
-  libDir   <- getHaddockLibDir flags
-  prologue <- getPrologue flags
-  themes   <- getThemes libDir flags >>= either bye return
-
-  when (Flag_GenIndex `elem` flags) $ do
-    ppHtmlIndex odir title pkgStr
-                themes opt_contents_url sourceUrls' opt_wiki_urls
-                allVisibleIfaces pretty
-    copyHtmlBits odir libDir themes
-
-  when (Flag_GenContents `elem` flags) $ do
-    ppHtmlContents odir title pkgStr
-                   themes opt_index_url sourceUrls' opt_wiki_urls
-                   allVisibleIfaces True prologue pretty
-    copyHtmlBits odir libDir themes
-
-  when (Flag_Html `elem` flags) $ do
-    ppHtml title pkgStr visibleIfaces odir
-                prologue
-                themes sourceUrls' opt_wiki_urls
-                opt_contents_url opt_index_url unicode opt_qualification
-                pretty
-    copyHtmlBits odir libDir themes
-
-  when (Flag_Hoogle `elem` flags) $ do
-    let pkgName2 = if pkgName == "main" && title /= [] then title else pkgName
-    ppHoogle pkgName2 pkgVer title prologue visibleIfaces odir
-
-  when (Flag_LaTeX `elem` flags) $ do
-    ppLaTeX title pkgStr visibleIfaces odir prologue opt_latex_style
-                  libDir
-
-
--------------------------------------------------------------------------------
--- * Reading and dumping interface files
--------------------------------------------------------------------------------
-
-
-readInterfaceFiles :: MonadIO m =>
-                      NameCacheAccessor m
-                   -> [(DocPaths, FilePath)] ->
-                      m [(DocPaths, InterfaceFile)]
-readInterfaceFiles name_cache_accessor pairs = do
-  mbPackages <- mapM tryReadIface pairs
-  return (catMaybes mbPackages)
-  where
-    -- try to read an interface, warn if we can't
-    tryReadIface (paths, file) = do
-      eIface <- readInterfaceFile name_cache_accessor file
-      case eIface of
-        Left err -> liftIO $ do
-          putStrLn ("Warning: Cannot read " ++ file ++ ":")
-          putStrLn ("   " ++ err)
-          putStrLn "Skipping this interface."
-          return Nothing
-        Right f -> return $ Just (paths, f)
-
-
-dumpInterfaceFile :: FilePath -> [InstalledInterface] -> LinkEnv -> IO ()
-dumpInterfaceFile path ifaces homeLinks = writeInterfaceFile path ifaceFile
-  where
-    ifaceFile = InterfaceFile {
-        ifInstalledIfaces = ifaces,
-        ifLinkEnv         = homeLinks
-      }
-
-
--------------------------------------------------------------------------------
--- * Creating a GHC session
--------------------------------------------------------------------------------
-
-
--- | Start a GHC session with the -haddock flag set. Also turn off
--- compilation and linking. Then run the given 'Ghc' action.
-withGhc :: String -> [String] -> (DynFlags -> Ghc a) -> IO a
-withGhc libDir flags ghcActs = do
-  -- TODO: handle warnings?
-  (restFlags, _) <- parseStaticFlags (map noLoc flags)
-  runGhc (Just libDir) $ do
-    dynflags  <- getSessionDynFlags
-    let dynflags' = dopt_set dynflags Opt_Haddock
-    let dynflags'' = dynflags' {
-        hscTarget = HscNothing,
-        ghcMode   = CompManager,
-        ghcLink   = NoLink
-      }
-    dynflags''' <- parseGhcFlags dynflags'' restFlags flags
-    defaultCleanupHandler dynflags''' $ do
-        -- ignore the following return-value, which is a list of packages
-        -- that may need to be re-linked: Haddock doesn't do any
-        -- dynamic or static linking at all!
-        _ <- setSessionDynFlags dynflags'''
-        ghcActs dynflags'''
-  where
-    parseGhcFlags :: Monad m => DynFlags -> [Located String]
-                  -> [String] -> m DynFlags
-    parseGhcFlags dynflags flags_ origFlags = do
-      -- TODO: handle warnings?
-      (dynflags', rest, _) <- parseDynamicFlags dynflags flags_
-      if not (null rest)
-        then throwE ("Couldn't parse GHC options: " ++ unwords origFlags)
-        else return dynflags'
-
-
--------------------------------------------------------------------------------
--- * Misc
--------------------------------------------------------------------------------
-
-
-getHaddockLibDir :: [Flag] -> IO String
-getHaddockLibDir flags =
-  case [str | Flag_Lib str <- flags] of
-    [] ->
-#ifdef IN_GHC_TREE
-      getInTreeLibDir
-#else
-      getDataDir -- provided by Cabal
-#endif
-    fs -> return (last fs)
-
-
-getGhcLibDir :: [Flag] -> IO String
-getGhcLibDir flags =
-  case [ dir | Flag_GhcLibDir dir <- flags ] of
-    [] ->
-#ifdef IN_GHC_TREE
-      getInTreeLibDir
-#else
-      return libdir -- from GHC.Paths
-#endif
-    xs -> return $ last xs
-
-
-shortcutFlags :: [Flag] -> IO ()
-shortcutFlags flags = do
-  usage <- getUsage
-
-  when (Flag_Help           `elem` flags) (bye usage)
-  when (Flag_Version        `elem` flags) byeVersion
-  when (Flag_GhcVersion     `elem` flags) byeGhcVersion
-
-  when (Flag_PrintGhcLibDir `elem` flags) $ do
-    dir <- getGhcLibDir flags
-    bye $ dir ++ "\n"
-
-  when (Flag_UseUnicode `elem` flags && Flag_Html `notElem` flags) $
-    throwE "Unicode can only be enabled for HTML output."
-
-  when ((Flag_GenIndex `elem` flags || Flag_GenContents `elem` flags)
-        && Flag_Html `elem` flags) $
-    throwE "-h cannot be used with --gen-index or --gen-contents"
-
-  when ((Flag_GenIndex `elem` flags || Flag_GenContents `elem` flags)
-        && Flag_Hoogle `elem` flags) $
-    throwE "--hoogle cannot be used with --gen-index or --gen-contents"
-
-  when ((Flag_GenIndex `elem` flags || Flag_GenContents `elem` flags)
-        && Flag_LaTeX `elem` flags) $
-    throwE "--latex cannot be used with --gen-index or --gen-contents"
-  where
-    byeVersion = bye $
-      "Haddock version " ++ projectVersion ++ ", (c) Simon Marlow 2006\n"
-      ++ "Ported to use the GHC API by David Waern 2006-2008\n"
-
-    byeGhcVersion = bye (cProjectVersion ++ "\n")
-
-
-updateHTMLXRefs :: [(DocPaths, InterfaceFile)] -> IO ()
-updateHTMLXRefs packages = writeIORef html_xrefs_ref (Map.fromList mapping)
-  where
-    mapping = [ (instMod iface, html) | ((html, _), ifaces) <- packages
-              , iface <- ifInstalledIfaces ifaces ]
-
-
-getPrologue :: [Flag] -> IO (Maybe (Doc RdrName))
-getPrologue flags =
-  case [filename | Flag_Prologue filename <- flags ] of
-    [] -> return Nothing
-    [filename] -> do
-      str <- readFile filename
-      case parseParas (tokenise (defaultDynFlags (panic "No settings")) str
-                      (1,0) {- TODO: real position -}) of
-        Nothing -> throwE $ "failed to parse haddock prologue from file: " ++ filename
-        Just doc -> return (Just doc)
-    _otherwise -> throwE "multiple -p/--prologue options"
-
-
-#ifdef IN_GHC_TREE
-
-getInTreeLibDir :: IO String
-getInTreeLibDir = do
-  m <- getExecDir
-  case m of
-    Nothing -> error "No GhcLibDir found"
-#ifdef NEW_GHC_LAYOUT
-    Just d -> return (d </> ".." </> "lib")
-#else
-    Just d -> return (d </> "..")
-#endif
-
-
-getExecDir :: IO (Maybe String)
-#if defined(mingw32_HOST_OS)
-getExecDir = try_size 2048 -- plenty, PATH_MAX is 512 under Win32.
-  where
-    try_size size = allocaArray (fromIntegral size) $ \buf -> do
-        ret <- c_GetModuleFileName nullPtr buf size
-        case ret of
-          0 -> return Nothing
-          _ | ret < size -> fmap (Just . dropFileName) $ peekCWString buf
-            | otherwise  -> try_size (size * 2)
-
-foreign import stdcall unsafe "windows.h GetModuleFileNameW"
-  c_GetModuleFileName :: Ptr () -> CWString -> Word32 -> IO Word32
-#else
-getExecDir = return Nothing
-#endif
-
-#endif
-
diff --git a/src/haddock.sh b/src/haddock.sh
deleted file mode 100644
--- a/src/haddock.sh
+++ /dev/null
@@ -1,7 +0,0 @@
-# Mini-driver for Haddock
-
-# needs the following variables:
-#	HADDOCKLIB
-#	HADDOCKBIN
-
-$HADDOCKBIN --lib $HADDOCKLIB ${1+"$@"}
diff --git a/tests/html-tests/runtests.hs b/tests/html-tests/runtests.hs
deleted file mode 100644
--- a/tests/html-tests/runtests.hs
+++ /dev/null
@@ -1,117 +0,0 @@
-import System.Cmd
-import System.Environment
-import System.FilePath
-import System.Exit
-import System.Directory
-import System.Process
-import Data.List
-import Control.Monad
-import Text.Printf
-import Text.Regex
-import Distribution.Simple.Utils
-import Distribution.Simple.Program
-import Distribution.Verbosity
-import Data.Maybe
-
-
-packageRoot   = "."
-haddockPath   = packageRoot </> "dist" </> "build" </> "haddock" </> "haddock"
-testSuiteRoot = packageRoot </> "tests" </> "html-tests"
-testDir       = testSuiteRoot </> "tests"
-outDir        = testSuiteRoot </> "output"
-
-
-main = do
-  test
-  putStrLn "All tests passed!"
-
-
-test = do
-  x <- doesFileExist haddockPath
-  when (not x) $ die "you need to run 'cabal build' successfully first"
-
-  contents <- getDirectoryContents testDir
-  args <- getArgs
-  let (opts, spec) = span ("-" `isPrefixOf`) args
-  let mods =
-        case spec of
-          x:_ | x /= "all" -> [x ++ ".hs"]
-          _ -> filter ((==) ".hs" . takeExtension) contents
-
-  let mods' = map (testDir </>) mods
-  putStrLn ""
-  putStrLn "Haddock version: "
-  h1 <- runProcess haddockPath ["--version"] Nothing
-                   (Just [("haddock_datadir", packageRoot)]) Nothing Nothing Nothing
-  waitForProcess h1
-  putStrLn ""
-  putStrLn "GHC version: "
-  h2 <- runProcess haddockPath ["--ghc-version"] Nothing
-                   (Just [("haddock_datadir", packageRoot)]) Nothing Nothing Nothing
-  waitForProcess h2
-  putStrLn ""
-
-  -- TODO: use Distribution.* to get the packages instead
-  libdir <- rawSystemStdout normal haddockPath ["--print-ghc-libdir"]
-  let librariesPath = ".."</>".."</>"share"</>"doc"</>"ghc"</>"html"</>"libraries"
-
-  let mkDep name version =
-        let path = init libdir </> librariesPath </> name ++ "-" ++ version
-        in  "-i " ++ path ++ "," ++ path </> name ++ ".haddock"
-
-  let base    = mkDep "base" "4.3.1.0"
-      process = mkDep "process" "1.0.1.5"
-      ghcprim = mkDep "ghc-prim" "0.2.0.0"
-
-  putStrLn "Running tests..."
-  handle <- runProcess haddockPath
-                       (["-w", "-o", outDir, "-h", "--pretty-html", "--optghc=-fglasgow-exts"
-                        , "--optghc=-w", base, process, ghcprim] ++ opts ++ mods')
-                       Nothing (Just [("haddock_datadir", packageRoot)]) Nothing
-                       Nothing Nothing
-
-  code <- waitForProcess handle
-  when (code /= ExitSuccess) $ error "Haddock run failed! Exiting."
-  check mods (if not (null args) && args !! 0 == "all" then False else True)
-
-
-check modules strict = do
-  forM_ modules $ \mod -> do
-    let outfile = outDir  </> dropExtension mod ++ ".html"
-    let reffile = testDir </> dropExtension mod ++ ".html.ref"
-    b <- doesFileExist reffile
-    if b
-      then do
-        copyFile reffile (outDir </> takeFileName reffile)
-        out <- readFile outfile
-        ref <- readFile reffile
-        if not $ haddockEq out ref
-          then do
-            putStrLn $ "Output for " ++ mod ++ " has changed! Exiting with diff:"
-            let ref' = stripLinks ref
-                out' = stripLinks out
-            let reffile' = outDir </> takeFileName reffile ++ ".nolinks"
-                outfile' = outDir </> takeFileName outfile ++ ".nolinks"
-            writeFile reffile' ref'
-            writeFile outfile' out'
-            b <- programOnPath "colordiff"
-            if b
-              then system $ "colordiff " ++ reffile' ++ " " ++ outfile'
-              else system $ "diff " ++ reffile' ++ " " ++ outfile'
-            if strict then exitFailure else return ()
-          else do
-            putStrLn $ "Pass: " ++ mod
-      else do
-        putStrLn $ "Pass: " ++ mod ++ " (no .ref file)"
-
-
-haddockEq file1 file2 = stripLinks file1 == stripLinks file2
-
-
-stripLinks f = subRegex (mkRegexWithOpts "<A HREF=[^>]*>" False False) f "<A HREF=\"\">"
-
-
-programOnPath p = do
-  result <- findProgramLocation silent p
-  return (isJust result)
-
