diff --git a/CHANGES b/CHANGES
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,37 @@
+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
diff --git a/README b/README
deleted file mode 100644
--- a/README
+++ /dev/null
@@ -1,72 +0,0 @@
-# Haddock, a Haskell Documentation Tool
-
-
-#### About haddock
-
-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). 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.
-
-
-#### Documentation formats
-
-Haddock can generate documentation in multiple formats; currently HTML
-is implemented, and there is partial support for generating LaTeX and
-Hoogle.
-
-
-#### Source code documentation
-
-Full documentation can be found in the doc/ subdirectory, in DocBook
-format.
-
-
-#### Contributing
-
-Please create issues when you have any problems and pull requests if you have some code.
-
-###### Hacking
-
-To get started you'll need a latest GHC release installed. Below is an
-example setup using cabal sandboxes.
-
-```bash
-  git clone https://github.com/haskell/haddock.git
-  cd haddock
-  cabal sandbox init
-  cabal sandbox add-source haddock-library
-  cabal sandbox add-source haddock-api
-  # adjust -j to the number of cores you want to use
-  cabal install -j4 --dependencies-only --enable-tests
-  cabal configure --enable-tests
-  cabal build -j4
-  # run the test suite
-  cabal test
-```
-
-If you're a GHC developer and want to update Haddock to work with your
-changes, you should be working on `ghc-head` branch instead of master.
-See instructions at
-https://ghc.haskell.org/trac/ghc/wiki/WorkingConventions/Git/Submodules
-for an example workflow.
diff --git a/README.md b/README.md
new file mode 100644
--- /dev/null
+++ b/README.md
@@ -0,0 +1,93 @@
+# Haddock, a Haskell Documentation Tool
+
+
+#### About haddock
+
+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). 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.
+
+
+#### Documentation formats
+
+Haddock can generate documentation in multiple formats; currently HTML
+is implemented, and there is partial support for generating LaTeX and
+Hoogle.
+
+
+#### Source code documentation
+
+Full documentation can be found in the doc/ subdirectory, in DocBook
+format.
+
+
+#### Contributing
+
+Please create issues when you have any problems and pull requests if you have some code.
+
+##### Hacking
+
+To get started you'll need a latest GHC release installed.
+
+Clone the repository:
+
+```bash
+  git clone https://github.com/haskell/haddock.git
+  cd haddock
+```
+
+and then proceed using your favourite build tool.
+
+###### Using Cabal sandboxes
+
+```bash
+cabal sandbox init
+cabal sandbox add-source haddock-library
+cabal sandbox add-source haddock-api
+cabal sandbox add-source haddock-test
+# adjust -j to the number of cores you want to use
+cabal install -j4 --dependencies-only --enable-tests
+cabal configure --enable-tests
+cabal build -j4
+# run the test suite
+export HADDOCK_PATH="dist/build/haddock/haddock"
+cabal test
+```
+
+###### Using Stack
+
+```bash
+stack init
+stack install
+# run the test suite
+export HADDOCK_PATH="$HOME/.local/bin/haddock"
+stack test
+```
+
+
+If you're a GHC developer and want to update Haddock to work with your
+changes, you should be working on `ghc-head` branch instead of master.
+See instructions at
+https://ghc.haskell.org/trac/ghc/wiki/WorkingConventions/Git/Submodules
+for an example workflow.
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:
-
-    $ autoconf
-    $ ./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/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,2270 +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" [
-    <!ENTITY nbsp   '&#160;'>
-    <!ENTITY frac12 '&#189;'>
-    <!ENTITY mdash  '&#8212;'>
-    <!ENTITY lsquo  '&#8217;'>
-    <!ENTITY rsquo  '&#8218;'>
-    <!ENTITY ldquo  '&#8220;'>
-    <!ENTITY rdquo  '&#8221;'>
-] >
-
-<book id="haddock">
-  <bookinfo>
-    <date>2015-06-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>
-    <author>
-      <firstname>Mateusz</firstname>
-      <surname>Kowalczyk</surname>
-    </author>
-    <address><email>fuuzetsu@fuuzetsu.co.uk</email></address>
-    <copyright>
-      <year>2010</year>
-      <holder>Simon Marlow, David Waern</holder>
-    </copyright>
-    <copyright>
-      <year>2013-2015</year>
-      <holder>Mateusz Kowalczyk</holder>
-    </copyright>
-    <abstract>
-      <para>This document describes Haddock version 2.16.1, 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 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 <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
-        backends 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><simpara>Ashley Yakeley</simpara></listitem>
-        <listitem><simpara>Benjamin Franksen</simpara></listitem>
-        <listitem><simpara>Brett Letner</simpara></listitem>
-        <listitem><simpara>Clemens Fruhwirth</simpara></listitem>
-        <listitem><simpara>Conal Elliott</simpara></listitem>
-        <listitem><simpara>David Waern</simpara></listitem>
-        <listitem><simpara>Duncan Coutts</simpara></listitem>
-        <listitem><simpara>George Pollard</simpara></listitem>
-        <listitem><simpara>George Russel</simpara></listitem>
-        <listitem><simpara>Hal Daume</simpara></listitem>
-        <listitem><simpara>Ian Lynagh</simpara></listitem>
-        <listitem><simpara>Isaac Dupree</simpara></listitem>
-        <listitem><simpara>Joachim Breitner</simpara></listitem>
-        <listitem><simpara>Krasimir Angelov</simpara></listitem>
-        <listitem><simpara>Lennart Augustsson</simpara></listitem>
-        <listitem><simpara>Luke Plant</simpara></listitem>
-        <listitem><simpara>Malcolm Wallace</simpara></listitem>
-        <listitem><simpara>Manuel Chakravarty</simpara></listitem>
-        <listitem><simpara>Mark Lentczner</simpara></listitem>
-        <listitem><simpara>Mark Shields</simpara></listitem>
-        <listitem><simpara>Mateusz Kowalczyk</simpara></listitem>
-        <listitem><simpara>Mike Thomas</simpara></listitem>
-        <listitem><simpara>Neil Mitchell</simpara></listitem>
-        <listitem><simpara>Oliver Brown</simpara></listitem>
-        <listitem><simpara>Roman Cheplyaka</simpara></listitem>
-        <listitem><simpara>Ross Paterson</simpara></listitem>
-        <listitem><simpara>Sigbjorn Finne</simpara></listitem>
-        <listitem><simpara>Simon Hengel</simpara></listitem>
-        <listitem><simpara>Simon Marlow</simpara></listitem>
-        <listitem><simpara>Simon Peyton-Jones</simpara></listitem>
-        <listitem><simpara>Stefan O'Rear</simpara></listitem>
-        <listitem><simpara>Sven Panne</simpara></listitem>
-        <listitem><simpara>Thomas Schilling</simpara></listitem>
-        <listitem><simpara>Wolfgang Jeltsch</simpara></listitem>
-        <listitem><simpara>Yitzchak Gale</simpara></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
-    identifiers 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>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.</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 collapsible 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>
-        <term>
-          <indexterm><primary><option>--source-entity-line</option></primary></indexterm>
-          <option>--source-entity-line</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.
-          <option>--source-entity-line</option> 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.
-          </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>
-                        <simpara>none: x, y, z</simpara>
-                    </listitem>
-                    <listitem>
-                        <simpara>full: A.x, A.B.y, C.z</simpara>
-                    </listitem>
-                    <listitem>
-                        <simpara>local: x, A.B.y, C.z</simpara>
-                    </listitem>
-                    <listitem>
-                        <simpara>relative: x, B.y, C.z</simpara>
-                    </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 conjunction 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 behave 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 behave as if module
-            <replaceable>module</replaceable> has the <literal>hide</literal>
-            attribute. (<xref linkend="module-attributes" />).</para>
-        </listitem>
-      </varlistentry>
-
-      <varlistentry>
-        <term>
-          <indexterm><primary><option>--show-extensions</option></primary>
-          </indexterm>
-          <option>--show-extensions</option>&nbsp;<replaceable>module</replaceable>
-        </term>
-        <listitem>
-          <para>Causes Haddock to behave as if module
-            <replaceable>module</replaceable> has the <literal>show-extensions</literal>
-            attribute. (<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. Note that there is a double dash there, unlike for 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>--compatible-interface-versions</option></primary></indexterm>
-          <option>--compatible-interface-versions</option>
-        </term>
-        <listitem>
-          <para>
-            Prints out space-separated versions of binary Haddock interface files that this version is compatible
-            with.
-          </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>
-
-      <varlistentry>
-        <term>
-          <indexterm><primary><option>--print-missing-docs</option></primary></indexterm>
-          <option>--print-missing-docs</option>
-        </term>
-        <listitem>
-          <para>
-          Print extra information about any undocumented entities.
-          </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</para>
-        </listitem>
-        <listitem>
-          <para>A <literal>class</literal> declaration,</para>
-        </listitem>
-        <listitem>
-          <para>A <literal>data family</literal> or
-            <literal>type family</literal> declaration, or</para>
-        </listitem>
-        <listitem>
-          <para>A <literal>data instance</literal> or
-            <literal>type instance</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>
-
-        <para>In case that more than one constructor exports a field
-        with the same name, the documentation attached to the first
-        occurence of the field will be used, even if a comment is not
-        present.
-        </para>
-
-<programlisting>
-data T a = A { someField :: a -- ^ Doc for someField of A
-             }
-         | B { someField :: a -- ^ Doc for someField of B
-             }
-</programlisting>
-
-        <para>In the above example, all occurences of
-        <literal>someField</literal> in the documentation are going to
-        be documented with <literal>Doc for someField of A</literal>.
-        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
-        <literal>someField</literal> is actually the same (partial)
-        function.</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 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.</para>
-
-<programlisting>
-{-|
-Module      : W
-Description : Short description
-Copyright   : (c) Some Guy, 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
-...
-</programlisting>
-
-      <para>The <quote>Module</quote> field should be clear. It
-      currently doesn't affect the output of any of the backends but
-      you might want to include it for human information or for any
-      other tools that might be parsing these comments without the
-      help of GHC.</para>
-
-      <para>The <quote>Description</quote> 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.</para>
-
-      <para>The <quote>Copyright</quote>, <quote>License</quote>,
-      <quote>Maintainer</quote> and <quote>Stability</quote> fields
-      should be obvious. An alternative spelling for the
-      <quote>License</quote> field is accepted as
-      <quote>Licence</quote> but the output will always prefer
-      <quote>License</quote>.</para>
-
-      <para>The <quote>Portability</quote> 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 <quote>show-extensions</quote> module flag for the
-      latter.</para>
-
-      <para>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
-      <quote>Description</quote> in the documentation for the module.
-      All usual Haddock markup is valid in this comment.</para>
-
-      <para>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
-      <quote>--</quote> syntax, the consecutive lines have to start at
-      two spaces at the very least. Please note that we do not enforce
-      the format for any of the fields and the established formats are
-      just a convention.</para>
-
-    </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>
-
-<programlisting>
-module Foo where
-
--- * This heading will now appear before foo.
-
--- | Documentation for 'foo'.
-foo :: Integer
-foo = 5
-</programlisting>
-
-      </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> attribute 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>
-
-        <varlistentry>
-          <term>
-            <indexterm><primary><literal>show-extensions</literal></primary></indexterm>
-      <literal>show-extensions</literal>
-          </term>
-          <listitem>
-            <para>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.</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 below:
---
--- &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 documentation.</para>
-      </section>
-
-      <section>
-        <title>Properties</title>
-        <para>
-          Haddock provides markup for properties:
-<programlisting>
--- | Addition is commutative:
---
--- prop> a + b = b + a
-</programlisting>
-          This allows third-party applications to extract and verify them.
-        </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>Nothing special is needed to hyperlink identifiers which
-        contain apostrophes themselves: to hyperlink
-        <literal>foo'</literal> one would simply type
-        <literal>'foo''</literal>. To hyperlink identifiers written in
-        infix form, simply put them in quotes as always:
-        <literal>'`elem`'</literal>.</para>
-
-        <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, Bold and Monospaced text</title>
-
-        <para>Emphasis may be added by surrounding text with
-        <literal>/.../</literal>. Other markup is valid inside emphasis. To have a forward
-        slash inside of emphasis, just escape it: <literal>/fo\/o/</literal></para>
-
-        <para>Bold (strong) text is indicated by surrounding it with <literal>__...__</literal>.
-        Other markup is valid inside bold. For example, <literal>__/foo/__</literal> will make the emphasised
-        text <literal>foo</literal> bold. You don't have to escape a single underscore if you need it bold:
-        <literal>__This_text_with_underscores_is_bold__</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>
-
-        <para>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.
-        </para>
-
-      </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>
-
-      <para>Lists of the same type don't have to be separated by a newline:</para>
-<programlisting>
--- | This is an enumerated list:
---
---     (1) first item
---     2. second item
---
--- This is a bulleted list:
---
---     * first item
---     * second item
-</programlisting>
-
-      <para>You can have more than one line of content in a list element:
-      </para>
-<programlisting>
--- |
--- * first item
--- and more content for the first item
--- * second item
--- and more content for the second item
-</programlisting>
-
-     <para>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 paragraph:
-     </para>
-<programlisting>
-{-|
-* 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.
--}
-</programlisting>
-    <para>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.
-    </para>
-<programlisting>
-{-|
-    * foo
-
-    * bar
--}
-</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 and followed by a colon.
-        Other markup operators may be used freely within the
-        definition term. You can escape <literal>]</literal> with a backslash as usual.</para>
-
-      <para>Same rules about nesting and no newline separation as for bulleted and numbered lists apply.
-      </para>
-
-      </section>
-
-      <section>
-        <title>URLs</title>
-
-        <para>
-          A URL can be included in a documentation comment by surrounding it in
-          angle brackets, for example:
-        </para>
-
-<programlisting>
-&lt;http://example.com&gt;
-</programlisting>
-
-        <para>
-          If the output format supports it, the URL will be turned into a
-          hyperlink when rendered.
-        </para>
-
-        <para>If Haddock sees something that looks like a URL (such as something starting with
-        <literal>http://</literal> or <literal>ssh://</literal>) where the URL markup is valid,
-        it will automatically make it a hyperlink.</para>
-      </section>
-
-      <section>
-        <title>Links</title>
-
-        <para>
-          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:
-        </para>
-
-<programlisting>
-[some link](http://example.com)
-</programlisting>
-        <para>
-          The link text is used as a descriptive text for the URL, if the
-          output format supports it.
-        </para>
-      </section>
-
-      <section>
-        <title>Images</title>
-        <para>
-            Haddock supports Markdown syntax for inline images.  This resembles
-            the syntax for links, but starts with an exclamation mark.  An
-            example looks like this:
-        </para>
-
-<programlisting>
-![image description](pathtoimage.png)
-</programlisting>
-        <para>
-          If the output format supports it, the image will be rendered inside
-          the documentation.  The image description is used as relpacement text
-          and/or image title.
-        </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. Please note that in Haddock
-        versions 2.13.x and earlier, the syntax was
-        <literal>"<replaceable>module</replaceable>\#<replaceable>label</replaceable>"</literal>.
-        It is considered deprecated and will be removed in the future.</para>
-      </section>
-
-      <section>
-        <title>Headings</title>
-        <para>Headings inside of comment documentation are possible be preceding them with
-        a number of <literal>=</literal>s. From 1 to 6 are accepted. Extra <literal>=</literal>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.
-        </para>
-
-<programlisting>
--- |
--- = Heading level 1 with some /emphasis/
--- Something underneath the heading.
---
--- == /Subheading/
--- More content.
---
--- === Subsubheading
--- Even more content.
-</programlisting>
-
-        <para>Note that while headings have to start on a new paragraph, we allow paragraph-level content to
-        follow these immediately.
-        </para>
-
-<programlisting>
--- |
--- = Heading level 1 with some __bold__
--- Something underneath the heading.
---
--- == /Subheading/
--- More content.
---
--- === Subsubheading
--- >>> examples are only allowed at the start of paragraphs
-</programlisting>
-
-        <para>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
-        <literal>=</literal>s.</para>
-
-<programlisting>
--- |
--- === __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.
-</programlisting>
-
-      </section>
-
-      <section>
-        <title>Metadata</title>
-        <para>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.
-        </para>
-
-        <section>
-          <title>Since</title>
-          <para><literal>@since</literal> annotation can be used to
-          convey information about when the function was introduced or
-          when it has changed in the way significant to the user.
-          <literal>@since</literal> 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.
-          <literal>@since</literal> 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.
-          </para>
-
-<programlisting>
--- |
--- Some comment
---
--- @since 1.2.3
-</programlisting>
-
-        </section>
-
-      </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,21 @@
+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
+
+
+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,164 @@
+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 <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
+-----------------
+
+Distributions (source & binary) of Haddock can be obtained from its `web
+site <http://www.haskell.org/haddock/>`__.
+
+Up-to-date sources can also be obtained from our public darcs
+repository. The Haddock sources are at
+``http://code.haskell.org/haddock``. See
+`darcs.net <http://www.darcs.net/>`__ for more information on the darcs
+version control utility.
+
+License
+-------
+
+The following license covers this documentation, and the Haddock source
+code, except where otherwise indicated.
+
+    Copyright 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:
+
+    -  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.
+
+Contributors
+------------
+
+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.
+
+-  Ashley Yakeley
+-  Benjamin Franksen
+-  Brett Letner
+-  Clemens Fruhwirth
+-  Conal Elliott
+-  David Waern
+-  Duncan Coutts
+-  George Pollard
+-  George Russel
+-  Hal Daume
+-  Ian Lynagh
+-  Isaac Dupree
+-  Joachim Breitner
+-  Krasimir Angelov
+-  Lennart Augustsson
+-  Luke Plant
+-  Malcolm Wallace
+-  Manuel Chakravarty
+-  Mark Lentczner
+-  Mark Shields
+-  Mateusz Kowalczyk
+-  Mike Thomas
+-  Neil Mitchell
+-  Oliver Brown
+-  Roman Cheplyaka
+-  Ross Paterson
+-  Sigbjorn Finne
+-  Simon Hengel
+-  Simon Marlow
+-  Simon Peyton-Jones
+-  Stefan O'Rear
+-  Sven Panne
+-  Thomas Schilling
+-  Wolfgang Jeltsch
+-  Yitzchak Gale
+
+Acknowledgements
+----------------
+
+Several documentation systems provided the inspiration for Haddock, most
+notably:
+
+-  `IDoc <http://www.cse.unsw.edu.au/~chak/haskell/idoc/>`__
+
+-  `HDoc <http://www.fmi.uni-passau.de/~groessli/hdoc/>`__
+
+-  `Doxygen <http://www.stack.nl/~dimitri/doxygen/>`__
+
+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,459 @@
+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 and the :option:`--hoogle` option for
+outputting Hoogle data 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 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>
+
+    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.
+
+    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.
+
+.. [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 in frames.
+
+    ``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.
+
+    ``frames.html``
+        The top level document when viewing in frames.
+
+    ``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, and switching to frames
+        view.
+
+.. 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.
+
+.. 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:: --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 ("Ocean") 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 ("Ocean" or "Classic").
+
+.. option:: --built-in-themes
+
+    Includes the built-in themes ("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:: -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:: -?
+            --help
+
+    Display help and exit.
+
+.. option:: -V
+            --version
+
+    Output version information 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-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:: --compatible-interface-versions
+
+    Prints out space-separated versions of binary Haddock interface
+    files that this version is compatible with.
+
+.. 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 the :option:`-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,887 @@
+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.
+
+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 ``data`` declaration,
+
+-  A ``newtype`` declaration,
+
+-  A ``type`` declaration
+
+-  A ``class`` 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
+
+Note that Haddock doesn't contain a Haskell type system — 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.
+
+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
+
+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 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 case that more than one constructor exports a field with the same
+name, the documentation attached to the first occurence 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 occurences 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.
+
+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
+
+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 Guy, 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
+    ...
+
+The “Module” field should be clear. It currently doesn't affect the
+output of any of the backends but you might want to include it for human
+information or 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.
+
+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 usual
+Haddock markup is valid in this comment.
+
+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 “--” syntax, the consecutive lines have to start
+at two spaces at the very least. Please note that we do not enforce the
+format for any of the fields and the established formats are just a
+convention.
+
+Controlling the documentation structure
+---------------------------------------
+
+Haddock produces interface documentation that lists only the entities
+actually exported by the module. The documentation for a module will
+include *all* 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.
+
+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 *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.
+
+You can insert headings and sub-headings in the documentation by
+including annotations at the appropriate point in the 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.
+
+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
+
+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 [2]_.
+
+.. [2]
+   NOTE: this is not fully implemented at the time of writing (version
+   0.2). At the moment, Haddock always inserts a cross-reference.
+
+The exception to this rule is when the re-exported module is declared
+with the ``hide`` attribute (:ref:`module-attrs`), in which case the module is
+never cross-referenced; the contents are always expanded in place in the
+re-exporting module.
+
+Omitting the export list
+~~~~~~~~~~~~~~~~~~~~~~~~
+
+If there is no export list in the module, how does Haddock generate
+documentation? Well, when the export list is omitted, e.g.: ::
+
+    module Foo where
+
+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). ::
+
+    module Foo where
+
+    -- * This heading will now appear before foo.
+
+    -- | Documentation for 'foo'.
+    foo :: Integer
+    foo = 5
+
+Named chunks of documentation
+-----------------------------
+
+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:
+
+-  The documentation can be included in the export list directly, e.g.: ::
+
+       module Foo (
+          -- * A section heading
+
+          -- | Some documentation not attached to a particular Haskell entity
+          ...
+        ) where
+
+-  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
+   “``-- $``”: ::
+
+       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, which is the sequence of
+   alphanumeric characters directly after the “``-- $``”, and it may be
+   referred to by the same name in the export list.
+
+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 affects 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`` ``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.
+
+``hide`` ``prune``
+    Omit definitions that have no documentation annotations from the
+    generated documentation.
+
+``ignore-exports`` ``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`` ``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 ? for more details.
+
+``show-extensions`` ``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
+------
+
+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 that
+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, 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 ``&#``\ 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.
+
+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 single quotes: ::
+
+    -- | This module defines the type 'T'.
+
+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).
+
+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''``. To hyperlink identifiers written in infix form, simply put
+them in quotes as always: ``'`elem`'``.
+
+For compatibility with other systems, the following alternative form of
+markup is accepted [3]_: ```T'``.
+
+.. [3]
+   We chose not to use this as the primary markup for identifiers
+   because strictly speaking the ````` character should not be used as a
+   left quote, it is a grave accent.
+
+Emphasis, Bold and Monospaced text
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Emphasis may be added by surrounding text with ``/.../``. Other markup
+is valid inside emphasis. To have a forward slash inside of emphasis,
+just escape it: ``/fo\/o/``
+
+Bold (strong) text is indicated by surrounding it with ``__...__``.
+Other markup is valid inside bold. For example, ``__/foo/__`` will make
+the emphasised text ``foo`` bold. You don't have to escape a single
+underscore if you need it bold:
+``__This_text_with_underscores_is_bold__``.
+
+Monospaced (or typewriter) text is indicated by surrounding it with
+``@...@``. Other markup is valid inside a monospaced span: for example
+``@'f' a b@`` will hyperlink the identifier ``f`` inside the code
+fragment.
+
+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.
+
+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, eg.: ::
+
+    -- | 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 paragraph: ::
+
+    {-|
+    * 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 descriptive text 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 relpacement text and/or
+image title.
+
+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 be 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 the 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/driver-test/Main.hs b/driver-test/Main.hs
new file mode 100644
--- /dev/null
+++ b/driver-test/Main.hs
@@ -0,0 +1,12 @@
+module Main where
+
+import Test.Hspec (describe, hspec, Spec)
+import qualified ResponseFileSpec (spec)
+
+
+main :: IO ()
+main = hspec spec
+
+spec :: Spec
+spec = do
+    describe "ResponseFile" ResponseFileSpec.spec
diff --git a/driver/Main.hs b/driver/Main.hs
--- a/driver/Main.hs
+++ b/driver/Main.hs
@@ -1,29 +1,8 @@
-{-# LANGUAGE ScopedTypeVariables #-}
 module Main where
 
-import Control.Exception
 import Documentation.Haddock (haddock)
+import ResponseFile (expandResponse)
 import System.Environment (getArgs)
-import System.Exit (exitFailure)
-import System.IO
 
 main :: IO ()
 main = getArgs >>= expandResponse >>= haddock
-
-
--- | Arguments which look like '@foo' will be replaced with the
--- contents of file @foo@. The contents will be passed through 'words'
--- and blanks filtered out first.
---
--- We quit if the file is not found or reading somehow fails.
-expandResponse :: [String] -> IO [String]
-expandResponse = fmap concat . mapM expand
-  where
-    expand :: String -> IO [String]
-    expand ('@':f) = readFileExc f >>= return . filter (not . null) . words
-    expand x = return [x]
-
-    readFileExc f =
-      readFile f `catch` \(e :: IOException) -> do
-        hPutStrLn stderr $ "Error while expanding response file: " ++ show e
-        exitFailure
diff --git a/driver/ResponseFile.hs b/driver/ResponseFile.hs
new file mode 100644
--- /dev/null
+++ b/driver/ResponseFile.hs
@@ -0,0 +1,110 @@
+{-# LANGUAGE ScopedTypeVariables #-}
+module ResponseFile (
+    unescapeArgs,
+    escapeArgs,
+    expandResponse
+  ) where
+
+import Control.Exception
+import Data.Char (isSpace)
+import Data.Foldable (foldl')
+import System.Exit (exitFailure)
+import System.IO
+
+
+-- | Given a string of concatenated strings, separate each by removing
+-- a layer of /quoting/ and\/or /escaping/ of certain characters.
+--
+-- These characters are: any whitespace, single quote, double quote,
+-- and the backslash character.  The backslash character always
+-- escapes (i.e., passes through without further consideration) the
+-- character which follows.  Characters can also be escaped in blocks
+-- by quoting (i.e., surrounding the blocks with matching pairs of
+-- either single- or double-quotes which are not themselves escaped).
+--
+-- Any whitespace which appears outside of either of the quoting and
+-- escaping mechanisms, is interpreted as having been added by this
+-- special concatenation process to designate where the boundaries
+-- are between the original, un-concatenated list of strings.  These
+-- added whitespace characters are removed from the output.
+--
+-- > unescapeArgs "hello\\ \\\"world\\\"\n" == escapeArgs "hello \"world\""
+unescapeArgs :: String -> [String]
+unescapeArgs = filter (not . null) . unescape
+
+-- | Given a list of strings, concatenate them into a single string
+-- with escaping of certain characters, and the addition of a newline
+-- between each string.  The escaping is done by adding a single
+-- backslash character before any whitespace, single quote, double
+-- quote, or backslash character, so this escaping character must be
+-- removed.  Unescaped whitespace (in this case, newline) is part
+-- of this "transport" format to indicate the end of the previous
+-- string and the start of a new string.
+--
+-- While 'unescapeArgs' allows using quoting (i.e., convenient
+-- escaping of many characters) by having matching sets of single- or
+-- double-quotes,'escapeArgs' does not use the quoting mechasnism,
+-- and thus will always escape any whitespace, quotes, and
+-- backslashes.
+--
+-- > unescapeArgs "hello\\ \\\"world\\\"\\n" == escapeArgs "hello \"world\""
+escapeArgs :: [String] -> String
+escapeArgs = unlines . map escapeArg
+
+-- | Arguments which look like '@foo' will be replaced with the
+-- contents of file @foo@. A gcc-like syntax for response files arguments
+-- is expected.  This must re-constitute the argument list by doing an
+-- inverse of the escaping mechanism done by the calling-program side.
+--
+-- We quit if the file is not found or reading somehow fails.
+-- (A convenience routine for haddock or possibly other clients)
+expandResponse :: [String] -> IO [String]
+expandResponse = fmap concat . mapM expand
+  where
+    expand :: String -> IO [String]
+    expand ('@':f) = readFileExc f >>= return . unescapeArgs
+    expand x = return [x]
+
+    readFileExc f =
+      readFile f `catch` \(e :: IOException) -> do
+        hPutStrLn stderr $ "Error while expanding response file: " ++ show e
+        exitFailure
+
+data Quoting = NoneQ | SngQ | DblQ
+
+unescape :: String -> [String]
+unescape args = reverse . map reverse $ go args NoneQ False [] []
+    where
+      -- n.b., the order of these cases matters; these are cribbed from gcc
+      -- case 1: end of input
+      go []     _q    _bs   a as = a:as
+      -- case 2: back-slash escape in progress
+      go (c:cs) q     True  a as = go cs q     False (c:a) as
+      -- case 3: no back-slash escape in progress, but got a back-slash
+      go (c:cs) q     False a as
+        | '\\' == c              = go cs q     True  a     as
+      -- case 4: single-quote escaping in progress
+      go (c:cs) SngQ  False a as
+        | '\'' == c              = go cs NoneQ False a     as
+        | otherwise              = go cs SngQ  False (c:a) as
+      -- case 5: double-quote escaping in progress
+      go (c:cs) DblQ  False a as
+        | '"' == c               = go cs NoneQ False a     as
+        | otherwise              = go cs DblQ  False (c:a) as
+      -- case 6: no escaping is in progress
+      go (c:cs) NoneQ False a as
+        | isSpace c              = go cs NoneQ False []    (a:as)
+        | '\'' == c              = go cs SngQ  False a     as
+        | '"'  == c              = go cs DblQ  False a     as
+        | otherwise              = go cs NoneQ False (c:a) as
+
+escapeArg :: String -> String
+escapeArg = reverse . foldl' escape []
+
+escape :: String -> Char -> String
+escape cs c
+  |    isSpace c
+    || '\\' == c
+    || '\'' == c
+    || '"'  == c = c:'\\':cs -- n.b., our caller must reverse the result
+  | otherwise    = c:cs
diff --git a/haddock-api/src/Haddock.hs b/haddock-api/src/Haddock.hs
--- a/haddock-api/src/Haddock.hs
+++ b/haddock-api/src/Haddock.hs
@@ -30,6 +30,7 @@
 import Haddock.Backends.Xhtml.Themes (getThemes)
 import Haddock.Backends.LaTeX
 import Haddock.Backends.Hoogle
+import Haddock.Backends.Hyperlinker
 import Haddock.Interface
 import Haddock.Parser
 import Haddock.Types
@@ -45,6 +46,7 @@
 import Control.Exception
 import Data.Maybe
 import Data.IORef
+import Data.Map (Map)
 import qualified Data.Map as Map
 import System.IO
 import System.Exit
@@ -119,11 +121,8 @@
   -- error messages propagated as exceptions
   handleGhcException $ \e -> do
     hFlush stdout
-    case e of
-      PhaseFailed _ code -> exitWith code
-      _ -> do
-        print (e :: GhcException)
-        exitFailure
+    print (e :: GhcException)
+    exitFailure
 
 
 -------------------------------------------------------------------------------
@@ -158,6 +157,7 @@
           _ -> return flags
 
   unless (Flag_NoWarnings `elem` flags) $ do
+    hypSrcWarnings flags
     forM_ (warnings args) $ \warning -> do
       hPutStrLn stderr warning
 
@@ -226,13 +226,16 @@
   let
     ifaceFiles = map snd pkgs
     installedIfaces = concatMap ifInstalledIfaces ifaceFiles
-    srcMap = Map.fromList [ (ifPackageKey if_, x) | ((_, Just x), if_) <- pkgs ]
-  render dflags flags qual interfaces installedIfaces srcMap
+    extSrcMap = Map.fromList $ do
+      ((_, Just path), ifile) <- pkgs
+      iface <- ifInstalledIfaces ifile
+      return (instMod iface, path)
+  render dflags flags qual interfaces installedIfaces extSrcMap
 
 
 -- | Render the interfaces with whatever backend is specified in the flags.
-render :: DynFlags -> [Flag] -> QualOption -> [Interface] -> [InstalledInterface] -> SrcMap -> IO ()
-render dflags flags qual ifaces installedIfaces srcMap = do
+render :: DynFlags -> [Flag] -> QualOption -> [Interface] -> [InstalledInterface] -> Map Module FilePath -> IO ()
+render dflags flags qual ifaces installedIfaces extSrcMap = do
 
   let
     title                = fromMaybe "" (optTitle flags)
@@ -243,6 +246,11 @@
     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
 
     visibleIfaces    = [ i | i <- ifaces, OptHide `notElem` ifaceOptions i ]
 
@@ -251,37 +259,57 @@
     allVisibleIfaces = [ i | i <- allIfaces, OptHide `notElem` instOptions i ]
 
     pkgMod           = ifaceMod (head ifaces)
-    pkgKey           = modulePackageKey pkgMod
-    pkgStr           = Just (packageKeyString pkgKey)
+    pkgKey           = moduleUnitId pkgMod
+    pkgStr           = Just (unitIdString pkgKey)
     pkgNameVer       = modulePackageInfo dflags flags pkgMod
 
     (srcBase, srcModule, srcEntity, srcLEntity) = sourceUrls flags
-    srcMap' = maybe srcMap (\path -> Map.insert pkgKey path srcMap) srcEntity
+
+    srcModule'
+      | Flag_HyperlinkedSource `elem` flags = Just hypSrcModuleUrlFormat
+      | otherwise = srcModule
+
+    srcMap = mkSrcMap $ Map.union
+      (Map.map SrcExternal extSrcMap)
+      (Map.fromList [ (ifaceMod iface, SrcLocal) | iface <- ifaces ])
+
+    pkgSrcMap = Map.mapKeys moduleUnitId extSrcMap
+    pkgSrcMap'
+      | Flag_HyperlinkedSource `elem` flags =
+          Map.insert pkgKey hypSrcModuleNameUrlFormat pkgSrcMap
+      | Just srcNameUrl <- srcEntity = Map.insert pkgKey srcNameUrl pkgSrcMap
+      | otherwise = pkgSrcMap
+
     -- TODO: Get these from the interface files as with srcMap
-    srcLMap' = maybe Map.empty (\path -> Map.singleton pkgKey path) srcLEntity
-    sourceUrls' = (srcBase, srcModule, srcMap', srcLMap')
+    pkgSrcLMap'
+      | Flag_HyperlinkedSource `elem` flags =
+          Map.singleton pkgKey hypSrcModuleLineUrlFormat
+      | Just path <- srcLEntity = Map.singleton pkgKey path
+      | otherwise = Map.empty
 
+    sourceUrls' = (srcBase, srcModule', pkgSrcMap', pkgSrcLMap')
+
   libDir   <- getHaddockLibDir flags
-  prologue <- getPrologue dflags flags
+  prologue <- getPrologue dflags' 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
+                themes opt_mathjax opt_contents_url sourceUrls' opt_wiki_urls
                 allVisibleIfaces pretty
     copyHtmlBits odir libDir themes
 
   when (Flag_GenContents `elem` flags) $ do
-    ppHtmlContents dflags odir title pkgStr
-                   themes opt_index_url sourceUrls' opt_wiki_urls
+    ppHtmlContents dflags' odir title pkgStr
+                   themes opt_mathjax opt_index_url sourceUrls' opt_wiki_urls
                    allVisibleIfaces True prologue pretty
                    (makeContentsQual qual)
     copyHtmlBits odir libDir themes
 
   when (Flag_Html `elem` flags) $ do
-    ppHtml dflags title pkgStr visibleIfaces odir
+    ppHtml dflags' title pkgStr visibleIfaces odir
                 prologue
-                themes sourceUrls' opt_wiki_urls
+                themes opt_mathjax sourceUrls' opt_wiki_urls
                 opt_contents_url opt_index_url unicode qual
                 pretty
     copyHtmlBits odir libDir themes
@@ -301,13 +329,16 @@
       Just (PackageName pkgNameFS, pkgVer) ->
           let pkgNameStr | unpackFS pkgNameFS == "main" && title /= [] = title
                          | otherwise = unpackFS pkgNameFS
-          in ppHoogle dflags pkgNameStr pkgVer title (fmap _doc prologue)
+          in ppHoogle dflags' pkgNameStr pkgVer title (fmap _doc prologue)
                visibleIfaces odir
 
   when (Flag_LaTeX `elem` flags) $ do
     ppLaTeX title pkgStr visibleIfaces odir (fmap _doc prologue) opt_latex_style
                   libDir
 
+  when (Flag_HyperlinkedSource `elem` flags) $ do
+    ppHyperlinkedSource odir libDir opt_source_css pretty srcMap ifaces
+
 -- | From GHC 7.10, this function has a potential to crash with a
 -- nasty message such as @expectJust getPackageDetails@ because
 -- package name and versions can no longer reliably be extracted in
@@ -326,7 +357,7 @@
     cmdline <|> pkgDb
   where
     cmdline = (,) <$> optPackageName flags <*> optPackageVersion flags
-    pkgDb = (\pkg -> (packageName pkg, packageVersion pkg)) <$> lookupPackage dflags (modulePackageKey modu)
+    pkgDb = (\pkg -> (packageName pkg, packageVersion pkg)) <$> lookupPackage dflags (moduleUnitId modu)
 
 
 -------------------------------------------------------------------------------
@@ -474,6 +505,35 @@
     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 = Flag_HyperlinkedSource `elem` flags
+    isSourceUrlFlag (Flag_SourceBaseURL _) = True
+    isSourceUrlFlag (Flag_SourceModuleURL _) = True
+    isSourceUrlFlag (Flag_SourceEntityURL _) = True
+    isSourceUrlFlag (Flag_SourceLEntityURL _) = True
+    isSourceUrlFlag _ = False
+    isSourceCssFlag (Flag_SourceCss _) = True
+    isSourceCssFlag _ = False
 
 
 updateHTMLXRefs :: [(DocPaths, InterfaceFile)] -> IO ()
diff --git a/haddock-api/src/Haddock/Backends/HaddockDB.hs b/haddock-api/src/Haddock/Backends/HaddockDB.hs
--- a/haddock-api/src/Haddock/Backends/HaddockDB.hs
+++ b/haddock-api/src/Haddock/Backends/HaddockDB.hs
@@ -40,7 +40,7 @@
   where
      do_mod (Module mod, iface)
         =  text "<sect1 id=\"sec-" <> text mod <> text "\">"
-        $$ text "<title><literal>" 
+        $$ text "<title><literal>"
 	   <> text mod
 	   <> text "</literal></title>"
 	$$ text "<indexterm><primary><literal>"
@@ -50,10 +50,10 @@
 	$$ 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>" 
+	$$ text "<term><literal>"
 		<> do_decl decl
 		<> text "</literal></term>"
 	$$ text "<listitem>"
@@ -63,11 +63,11 @@
 	$$ text "</varlistentry>"
      do_export _ _ = empty
 
-     do_decl (HsTypeSig _ [nm] ty _) 
+     do_decl (HsTypeSig _ [nm] ty _)
 	=  ppHsName nm <> text " :: " <> ppHsType ty
      do_decl (HsTypeDecl _ nm args ty _)
 	=  hsep ([text "type", ppHsName nm ]
-		 ++ map ppHsName args 
+		 ++ map ppHsName args
 		 ++ [equals, ppHsType ty])
      do_decl (HsNewTypeDecl loc ctx nm args con drv _)
 	= hsep ([text "data", ppHsName nm] -- data, not newtype
@@ -87,7 +87,7 @@
 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) = 
+ppHsConstr (HsConDecl pos name tvs ctxt typeList maybe_doc) =
 	 hsep (ppHsName name : map ppHsBangType typeList)
 
 ppField (HsFieldDecl ns ty doc)
@@ -100,7 +100,7 @@
 
 ppHsContext :: HsContext -> Doc
 ppHsContext []      = empty
-ppHsContext context = parenList (map (\ (a,b) -> ppHsQName a <+> 
+ppHsContext context = parenList (map (\ (a,b) -> ppHsQName a <+>
 					 hsep (map ppHsAType b)) context)
 
 ppHsType :: HsType -> Doc
@@ -109,7 +109,7 @@
 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 "." : 
+     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]
@@ -135,7 +135,7 @@
 ppHsQName n@(Qual (Module mod) str)
 	 | n == unit_con_name		= ppHsName str
 	 | isSpecial str 		= ppHsName str
-	 | otherwise 
+	 | otherwise
 		=  text "<link linkend=" <> ppLinkId mod str <> char '>'
 		<> ppHsName str
 		<> text "</link>"
diff --git a/haddock-api/src/Haddock/Backends/Hoogle.hs b/haddock-api/src/Haddock/Backends/Hoogle.hs
--- a/haddock-api/src/Haddock/Backends/Hoogle.hs
+++ b/haddock-api/src/Haddock/Backends/Hoogle.hs
@@ -20,13 +20,17 @@
 import Haddock.GhcUtils
 import Haddock.Types hiding (Version)
 import Haddock.Utils hiding (out)
+
 import GHC
 import Outputable
+import NameSet
 
 import Data.Char
 import Data.List
 import Data.Maybe
 import Data.Version
+
+import System.Directory
 import System.FilePath
 import System.IO
 
@@ -45,6 +49,7 @@
                    ["@version " ++ showVersion version
                    | not (null (versionBranch version)) ] ++
                    concat [ppModule dflags i | i <- ifaces, OptHide `notElem` ifaceOptions i]
+    createDirectoryIfMissing True odir
     h <- openFile (odir </> filename) WriteMode
     hSetEncoding h utf8
     hPutStr h (unlines contents)
@@ -65,7 +70,8 @@
 dropHsDocTy = f
     where
         g (L src x) = L src (f x)
-        f (HsForAllTy a b c d e) = HsForAllTy a b c d (g e)
+        f (HsForAllTy a e) = HsForAllTy a (g e)
+        f (HsQualTy a e) = HsQualTy a (g e)
         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)
@@ -82,14 +88,6 @@
 outHsType dflags = out dflags . dropHsDocTy
 
 
-makeExplicit :: HsType a -> HsType a
-makeExplicit (HsForAllTy _ a b c d) = HsForAllTy Explicit a b c d
-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
@@ -120,54 +118,73 @@
 ppExport dflags ExportDecl { expItemDecl    = L _ decl
                            , expItemMbDoc   = (dc, _)
                            , expItemSubDocs = subdocs
+                           , expItemFixities = fixities
                            } = ppDocumentation dflags dc ++ f decl
     where
         f (TyClD d@DataDecl{})  = ppData dflags d subdocs
         f (TyClD d@SynDecl{})   = ppSynonym dflags d
         f (TyClD d@ClassDecl{}) = ppClass dflags d subdocs
-        f (ForD (ForeignImport name typ _ _)) = ppSig dflags $ TypeSig [name] typ []
-        f (ForD (ForeignExport name typ _ _)) = ppSig dflags $ TypeSig [name] typ []
-        f (SigD sig) = ppSig dflags sig
+        f (ForD (ForeignImport name typ _ _)) = [pp_sig dflags [name] (hsSigType typ)]
+        f (ForD (ForeignExport name typ _ _)) = [pp_sig dflags [name] (hsSigType typ)]
+        f (SigD sig) = ppSig dflags sig ++ ppFixities
         f _ = []
+
+        ppFixities = concatMap (ppFixity dflags) fixities
 ppExport _ _ = []
 
 ppSigWithDoc :: DynFlags -> Sig Name -> [(Name, DocForDecl Name)] -> [String]
-ppSigWithDoc dflags (TypeSig names sig _) subdocs
+ppSigWithDoc dflags (TypeSig names sig) subdocs
     = concatMap mkDocSig names
     where
         mkDocSig n = concatMap (ppDocumentation dflags) (getDoc n)
-                     ++ [mkSig n]
-        mkSig n = operator (out dflags n) ++ " :: " ++ outHsType dflags typ
+                     ++ [pp_sig dflags names (hsSigWcType sig)]
 
         getDoc :: Located Name -> [Documentation Name]
         getDoc n = maybe [] (return . fst) (lookup (unL n) subdocs)
 
-        typ = case unL sig of
-                   HsForAllTy Explicit a b c d  -> HsForAllTy Implicit a b c d
-                   HsForAllTy Qualified a b c d -> HsForAllTy Implicit a b c d
-                   x -> x
 ppSigWithDoc _ _ _ = []
 
 ppSig :: DynFlags -> Sig Name -> [String]
 ppSig dflags x  = ppSigWithDoc dflags x []
 
+pp_sig :: DynFlags -> [Located Name] -> LHsType Name -> String
+pp_sig dflags names (L _ typ)  =
+    operator prettyNames ++ " :: " ++ outHsType dflags typ
+    where
+      prettyNames = intercalate ", " $ map (out dflags) names
 
 -- note: does not yet output documentation for class methods
 ppClass :: DynFlags -> TyClDecl Name -> [(Name, DocForDecl Name)] -> [String]
-ppClass dflags x subdocs = out dflags x{tcdSigs=[]} :
-            concatMap (flip (ppSigWithDoc dflags) subdocs . addContext . unL) (tcdSigs x)
+ppClass dflags decl subdocs = (out dflags decl{tcdSigs=[]} ++ ppTyFams) :  ppMethods
     where
-        addContext (TypeSig name (L l sig) nwcs) = TypeSig name (L l $ f sig) nwcs
-        addContext (MinimalSig src sig) = MinimalSig src sig
-        addContext _ = error "expected TypeSig"
 
-        f (HsForAllTy a b c con d) = HsForAllTy a b c (reL (context : unLoc con)) d
-        f t = HsForAllTy Implicit Nothing emptyHsQTvs (reL [context]) (reL t)
+        ppMethods = concat . map (ppSig' . unLoc . add_ctxt) $ tcdSigs decl
+        ppSig' = flip (ppSigWithDoc dflags) subdocs
 
-        context = nlHsTyConApp (tcdName x)
-            (map (reL . HsTyVar . hsTyVarName . unL) (hsQTvBndrs (tyClDeclTyVars x)))
+        add_ctxt = addClassContext (tcdName decl) (tyClDeclTyVars decl)
 
+        ppTyFams
+            | null $ tcdATs decl = ""
+            | otherwise = (" " ++) . showSDocUnqual dflags . whereWrapper $ concat
+                [ map ppr (tcdATs decl)
+                , map (ppr . tyFamEqnToSyn . unLoc) (tcdATDefs decl)
+                ]
 
+        whereWrapper elems = vcat'
+            [ text "where" <+> lbrace
+            , nest 4 . vcat . map (<> semi) $ elems
+            , rbrace
+            ]
+
+        tyFamEqnToSyn :: TyFamDefltEqn Name -> TyClDecl Name
+        tyFamEqnToSyn tfe = SynDecl
+            { tcdLName = tfe_tycon tfe
+            , tcdTyVars = tfe_pats tfe
+            , tcdRhs = tfe_rhs tfe
+            , tcdFVs = emptyNameSet
+            }
+
+
 ppInstance :: DynFlags -> ClsInst -> [String]
 ppInstance dflags x =
   [dropComment $ outWith (showSDocForUser dflags alwaysQualify) cls]
@@ -205,31 +222,42 @@
   _ -> []
 
 ppCtor :: DynFlags -> TyClDecl Name -> [(Name, DocForDecl Name)] -> ConDecl Name -> [String]
-ppCtor dflags dat subdocs con
-   = concatMap (lookupCon dflags subdocs) (con_names con) ++ f (con_details con)
+ppCtor dflags dat subdocs con@ConDeclH98 {}
+  -- AZ:TODO get rid of the concatMap
+   = concatMap (lookupCon dflags subdocs) [con_name con] ++ f (getConDetails con)
     where
         f (PrefixCon args) = [typeSig name $ args ++ [resType]]
         f (InfixCon a1 a2) = f $ PrefixCon [a1,a2]
         f (RecCon (L _ recs)) = f (PrefixCon $ map cd_fld_type (map unLoc recs)) ++ concat
-                          [(concatMap (lookupCon dflags subdocs) (cd_fld_names r)) ++
-                           [out dflags (map unL $ cd_fld_names r) `typeSig` [resType, cd_fld_type r]]
+                          [(concatMap (lookupCon dflags subdocs . noLoc . selectorFieldOcc . unLoc) (cd_fld_names r)) ++
+                           [out dflags (map (selectorFieldOcc . unLoc) $ cd_fld_names r) `typeSig` [resType, cd_fld_type r]]
                           | r <- map unLoc recs]
 
-        funs = foldr1 (\x y -> reL $ HsFunTy (makeExplicitL x) (makeExplicitL y))
+        funs = foldr1 (\x y -> reL $ HsFunTy x y)
         apps = foldl1 (\x y -> reL $ HsAppTy x y)
 
-        typeSig nm flds = operator nm ++ " :: " ++ outHsType dflags (makeExplicit $ unL $ funs flds)
+        typeSig nm flds = operator nm ++ " :: " ++ outHsType dflags (unL $ 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 . map unL $ con_names con
+        name = commaSeparate dflags . map unL $ getConNames con
 
-        resType = case con_res con of
-            ResTyH98 -> apps $ map (reL . HsTyVar) $
-                        (tcdName dat) : [hsTyVarName v | L _ v@(UserTyVar _) <- hsQTvBndrs $ tyClDeclTyVars dat]
-            ResTyGADT _ x -> x
+        resType = apps $ map (reL . HsTyVar . reL) $
+                        (tcdName dat) : [hsTyVarName v | L _ v@(UserTyVar _) <- hsQTvExplicit $ tyClDeclTyVars dat]
 
+ppCtor dflags _dat subdocs con@ConDeclGADT {}
+   = concatMap (lookupCon dflags subdocs) (getConNames con) ++ f
+    where
+        f = [typeSig name (hsib_body $ con_type con)]
 
+        typeSig nm ty = operator nm ++ " :: " ++ outHsType dflags (unL ty)
+        name = out dflags $ map unL $ getConNames con
+
+
+ppFixity :: DynFlags -> (Name, Fixity) -> [String]
+ppFixity dflags (name, fixity) = [out dflags (FixitySig [noLoc name] fixity)]
+
+
 ---------------------------------------------------------------------
 -- DOCUMENTATION
 
@@ -283,6 +311,8 @@
   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'),
   markupDefList              = box (TagL 'u') . map (\(a,b) -> TagInline "i" a : Str " " : b),
@@ -358,3 +388,8 @@
         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,64 @@
+module Haddock.Backends.Hyperlinker
+    ( ppHyperlinkedSource
+    , module Haddock.Backends.Hyperlinker.Types
+    , module Haddock.Backends.Hyperlinker.Utils
+    ) where
+
+
+import Haddock.Types
+import Haddock.Backends.Hyperlinker.Renderer
+import Haddock.Backends.Hyperlinker.Types
+import Haddock.Backends.Hyperlinker.Utils
+
+import Text.XHtml hiding ((</>))
+
+import Data.Maybe
+import System.Directory
+import System.FilePath
+
+
+-- | 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 :: FilePath -- ^ Output directory
+                    -> FilePath -- ^ Resource directory
+                    -> Maybe FilePath -- ^ Custom CSS file path
+                    -> Bool -- ^ Flag indicating whether to pretty-print HTML
+                    -> SrcMap -- ^ Paths to sources
+                    -> [Interface] -- ^ Interfaces for which we create source
+                    -> IO ()
+ppHyperlinkedSource 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 srcdir pretty srcs) ifaces
+  where
+    srcdir = outdir </> hypSrcDir
+
+-- | Generate hyperlinked source for particular interface.
+ppHyperlinkedModuleSource :: FilePath -> Bool -> SrcMap -> Interface
+                          -> IO ()
+ppHyperlinkedModuleSource srcdir pretty srcs iface =
+    case ifaceTokenizedSrc iface of
+        Just tokens -> writeFile path . html . render' $ tokens
+        Nothing -> return ()
+  where
+    render' = render (Just srcCssFile) (Just highlightScript) srcs
+    html = if pretty then renderHtml else showHtml
+    path = srcdir </> hypSrcModuleFile (ifaceMod iface)
+
+-- | 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/Ast.hs b/haddock-api/src/Haddock/Backends/Hyperlinker/Ast.hs
new file mode 100644
--- /dev/null
+++ b/haddock-api/src/Haddock/Backends/Hyperlinker/Ast.hs
@@ -0,0 +1,185 @@
+{-# LANGUAGE RankNTypes #-}
+{-# LANGUAGE ScopedTypeVariables #-}
+{-# LANGUAGE RecordWildCards #-}
+{-# LANGUAGE TypeFamilies #-}
+
+
+module Haddock.Backends.Hyperlinker.Ast (enrich) where
+
+
+import Haddock.Syb
+import Haddock.Backends.Hyperlinker.Types
+
+import qualified GHC
+
+import Control.Applicative
+import Data.Data
+import Data.Maybe
+
+
+-- | Add more detailed information to token stream using GHC API.
+enrich :: GHC.RenamedSource -> [Token] -> [RichToken]
+enrich src =
+    map $ \token -> RichToken
+        { rtkToken = token
+        , rtkDetails = enrichToken token detailsMap
+        }
+  where
+    detailsMap = concatMap ($ src)
+        [ variables
+        , types
+        , decls
+        , binds
+        , imports
+        ]
+
+-- | A map containing association between source locations and "details" of
+-- this location.
+--
+-- For the time being, it is just a list of pairs. However, looking up things
+-- in such structure has linear complexity. We cannot use any hashmap-like
+-- stuff because source locations are not ordered. In the future, this should
+-- be replaced with interval tree data structure.
+type DetailsMap = [(GHC.SrcSpan, TokenDetails)]
+
+lookupBySpan :: Span -> DetailsMap -> Maybe TokenDetails
+lookupBySpan tspan = listToMaybe . map snd . filter (matches tspan . fst)
+
+enrichToken :: Token -> DetailsMap -> Maybe TokenDetails
+enrichToken (Token typ _ spn) dm
+    | typ `elem` [TkIdentifier, TkOperator] = lookupBySpan spn dm
+enrichToken _ _ = Nothing
+
+-- | Obtain details map for variables ("normally" used identifiers).
+variables :: GHC.RenamedSource -> DetailsMap
+variables =
+    everything (<|>) (var `combine` rec)
+  where
+    var term = case cast term of
+        (Just (GHC.L sspan (GHC.HsVar name))) ->
+            pure (sspan, RtkVar (GHC.unLoc name))
+        (Just (GHC.L _ (GHC.RecordCon (GHC.L sspan name) _ _ _))) ->
+            pure (sspan, RtkVar name)
+        _ -> empty
+    rec term = case cast term of
+        Just (GHC.HsRecField (GHC.L sspan name) (_ :: GHC.LHsExpr GHC.Name) _) ->
+            pure (sspan, RtkVar name)
+        _ -> empty
+
+-- | Obtain details map for types.
+types :: GHC.RenamedSource -> DetailsMap
+types =
+    everything (<|>) ty
+  where
+    ty term = case cast term of
+        (Just (GHC.L sspan (GHC.HsTyVar name))) ->
+            pure (sspan, RtkType (GHC.unLoc name))
+        _ -> empty
+
+-- | Obtain details map for identifier bindings.
+--
+-- That includes both identifiers bound by pattern matching or declared using
+-- ordinary assignment (in top-level declarations, let-expressions and where
+-- clauses).
+binds :: GHC.RenamedSource -> DetailsMap
+binds =
+    everything (<|>) (fun `combine` pat `combine` tvar)
+  where
+    fun term = case cast term of
+        (Just (GHC.FunBind (GHC.L sspan name) _ _ _ _ :: GHC.HsBind GHC.Name)) ->
+            pure (sspan, RtkBind name)
+        _ -> empty
+    pat term = case cast term of
+        (Just (GHC.L sspan (GHC.VarPat name))) ->
+            pure (sspan, RtkBind (GHC.unLoc name))
+        (Just (GHC.L _ (GHC.ConPatIn (GHC.L sspan name) recs))) ->
+            [(sspan, RtkVar name)] ++ everything (<|>) rec recs
+        (Just (GHC.L _ (GHC.AsPat (GHC.L sspan name) _))) ->
+            pure (sspan, RtkBind name)
+        _ -> empty
+    rec term = case cast term of
+        (Just (GHC.HsRecField (GHC.L sspan name) (_ :: GHC.LPat GHC.Name) _)) ->
+            pure (sspan, RtkVar name)
+        _ -> empty
+    tvar term = case cast term of
+        (Just (GHC.L sspan (GHC.UserTyVar name))) ->
+            pure (sspan, RtkBind (GHC.unLoc name))
+        (Just (GHC.L _ (GHC.KindedTyVar (GHC.L sspan name) _))) ->
+            pure (sspan, RtkBind name)
+        _ -> empty
+
+-- | Obtain details map for top-level declarations.
+decls :: GHC.RenamedSource -> DetailsMap
+decls (group, _, _, _) = concatMap ($ group)
+    [ concat . map typ . concat . map GHC.group_tyclds . GHC.hs_tyclds
+    , everything (<|>) fun . GHC.hs_valds
+    , everything (<|>) (con `combine` ins)
+    ]
+  where
+    typ (GHC.L _ t) = case t of
+        GHC.DataDecl { tcdLName = name } -> pure . decl $ name
+        GHC.SynDecl name _ _ _ -> pure . decl $ name
+        GHC.FamDecl fam -> pure . decl $ GHC.fdLName fam
+        GHC.ClassDecl{..} -> [decl tcdLName] ++ concatMap sig tcdSigs
+    fun term = case cast term of
+        (Just (GHC.FunBind (GHC.L sspan name) _ _ _ _ :: GHC.HsBind GHC.Name))
+            | GHC.isExternalName name -> pure (sspan, RtkDecl name)
+        _ -> empty
+    con term = case cast term of
+        (Just cdcl) ->
+            map decl (GHC.getConNames cdcl) ++ everything (<|>) fld cdcl
+        Nothing -> empty
+    ins term = case cast term of
+        (Just (GHC.DataFamInstD inst)) -> pure . tyref $ GHC.dfid_tycon inst
+        (Just (GHC.TyFamInstD (GHC.TyFamInstDecl (GHC.L _ eqn) _))) ->
+            pure . tyref $ GHC.tfe_tycon eqn
+        _ -> empty
+    fld term = case cast term of
+        Just (field :: GHC.ConDeclField GHC.Name)
+          -> map (decl . fmap GHC.selectorFieldOcc) $ GHC.cd_fld_names field
+        Nothing -> empty
+    sig (GHC.L _ (GHC.TypeSig names _)) = map decl names
+    sig _ = []
+    decl (GHC.L sspan name) = (sspan, RtkDecl name)
+    tyref (GHC.L sspan name) = (sspan, RtkType name)
+
+-- | Obtain details map for import declarations.
+--
+-- This map also includes type and variable details for items in export and
+-- import lists.
+imports :: GHC.RenamedSource -> DetailsMap
+imports src@(_, imps, _, _) =
+    everything (<|>) ie src ++ mapMaybe (imp . GHC.unLoc) imps
+  where
+    ie term = case cast term of
+        (Just (GHC.IEVar v)) -> pure $ var v
+        (Just (GHC.IEThingAbs t)) -> pure $ typ t
+        (Just (GHC.IEThingAll t)) -> pure $ typ t
+        (Just (GHC.IEThingWith t _ vs _fls)) ->
+          [typ t] ++ map var vs
+        _ -> empty
+    typ (GHC.L sspan name) = (sspan, RtkType name)
+    var (GHC.L sspan name) = (sspan, RtkVar name)
+    imp idecl | not . GHC.ideclImplicit $ idecl =
+        let (GHC.L sspan name) = GHC.ideclName idecl
+        in Just (sspan, RtkModule name)
+    imp _ = Nothing
+
+-- | Check whether token stream span matches GHC source span.
+--
+-- Currently, it is implemented as checking whether "our" span is contained
+-- in GHC span. The reason for that is because GHC span are generally wider
+-- and may spread across couple tokens. For example, @(>>=)@ consists of three
+-- tokens: @(@, @>>=@, @)@, but GHC source span associated with @>>=@ variable
+-- contains @(@ and @)@. Similarly, qualified identifiers like @Foo.Bar.quux@
+-- are tokenized as @Foo@, @.@, @Bar@, @.@, @quux@ but GHC source span
+-- associated with @quux@ contains all five elements.
+matches :: Span -> GHC.SrcSpan -> Bool
+matches tspan (GHC.RealSrcSpan aspan)
+    | saspan <= stspan && etspan <= easpan = True
+  where
+    stspan = (posRow . spStart $ tspan, posCol . spStart $ tspan)
+    etspan = (posRow . spEnd $ tspan, posCol . spEnd $ tspan)
+    saspan = (GHC.srcSpanStartLine aspan, GHC.srcSpanStartCol aspan)
+    easpan = (GHC.srcSpanEndLine aspan, GHC.srcSpanEndCol aspan)
+matches _ _ = False
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,204 @@
+module Haddock.Backends.Hyperlinker.Parser (parse) where
+
+
+import Data.Char
+import Data.List
+import Data.Maybe
+
+import Haddock.Backends.Hyperlinker.Types
+
+
+-- | Turn source code string into a stream of more descriptive tokens.
+--
+-- Result should retain original file layout (including comments, whitespace,
+-- etc.), i.e. the following "law" should hold:
+--
+-- @concat . map 'tkValue' . 'parse' = id@
+parse :: String -> [Token]
+parse = tokenize . tag . chunk
+
+-- | Split raw source string to more meaningful chunks.
+--
+-- This is the initial stage of tokenization process. Each chunk is either
+-- a comment (including comment delimiters), a whitespace string, preprocessor
+-- macro (and all its content until the end of a line) or valid Haskell lexeme.
+chunk :: String -> [String]
+chunk [] = []
+chunk str@(c:_)
+    | isSpace c =
+        let (space, mcpp, rest) = spanSpaceOrCpp str
+        in [space] ++ maybeToList mcpp ++ chunk rest
+chunk str
+    | "--" `isPrefixOf` str = chunk' $ spanToNewline str
+    | "{-" `isPrefixOf` str = chunk' $ chunkComment 0 str
+    | otherwise = case lex str of
+        (tok:_) -> chunk' tok
+        [] -> [str]
+  where
+    chunk' (c, rest) = c:(chunk rest)
+
+-- | Split input to "first line" string and the rest of it.
+--
+-- Ideally, this should be done simply with @'break' (== '\n')@. However,
+-- Haskell also allows line-unbreaking (or whatever it is called) so things
+-- are not as simple and this function deals with that.
+spanToNewline :: String -> (String, String)
+spanToNewline [] = ([], [])
+spanToNewline ('\\':'\n':str) =
+    let (str', rest) = spanToNewline str
+    in ('\\':'\n':str', rest)
+spanToNewline str@('\n':_) = ("", str)
+spanToNewline (c:str) =
+    let (str', rest) = spanToNewline str
+    in (c:str', rest)
+
+-- | Split input to whitespace string, (optional) preprocessor directive and
+-- the rest of it.
+--
+-- Again, using something like @'span' 'isSpace'@ would be nice to chunk input
+-- to whitespace. The problem is with /#/ symbol - if it is placed at the very
+-- beginning of a line, it should be recognized as preprocessor macro. In any
+-- other case, it is ordinary Haskell symbol and can be used to declare
+-- operators. Hence, while dealing with whitespace we also check whether there
+-- happens to be /#/ symbol just after a newline character - if that is the
+-- case, we begin treating the whole line as preprocessor macro.
+spanSpaceOrCpp :: String -> (String, Maybe String, String)
+spanSpaceOrCpp ('\n':'#':str) =
+    let (str', rest) = spanToNewline str
+    in ("\n", Just $ '#':str', rest)
+spanSpaceOrCpp (c:str')
+    | isSpace c =
+        let (space, mcpp, rest) = spanSpaceOrCpp str'
+        in (c:space, mcpp, rest)
+spanSpaceOrCpp str = ("", Nothing, str)
+
+-- | Split input to comment content (including delimiters) and the rest.
+--
+-- Again, some more logic than simple 'span' is required because of Haskell
+-- comment nesting policy.
+chunkComment :: Int -> String -> (String, String)
+chunkComment _ [] = ("", "")
+chunkComment depth ('{':'-':str) =
+    let (c, rest) = chunkComment (depth + 1) str
+    in ("{-" ++ c, rest)
+chunkComment depth ('-':'}':str)
+    | depth == 1 = ("-}", str)
+    | otherwise =
+        let (c, rest) = chunkComment (depth - 1) str
+        in ("-}" ++ c, rest)
+chunkComment depth (e:str) =
+    let (c, rest) = chunkComment depth str
+    in (e:c, rest)
+
+-- | Assign source location for each chunk in given stream.
+tag :: [String] -> [(Span, String)]
+tag =
+    reverse . snd . foldl aux (Position 1 1, [])
+  where
+    aux (pos, cs) str =
+        let pos' = foldl move pos str
+        in (pos', (Span pos pos', str):cs)
+    move pos '\n' = pos { posRow = posRow pos + 1, posCol = 1 }
+    move pos _ = pos { posCol = posCol pos + 1 }
+
+-- | Turn unrecognised chunk stream to more descriptive token stream.
+tokenize :: [(Span, String)] -> [Token]
+tokenize =
+    map aux
+  where
+    aux (sp, str) = Token
+        { tkType = classify str
+        , tkValue = str
+        , tkSpan = sp
+        }
+
+-- | Classify given string as appropriate Haskell token.
+--
+-- This method is based on Haskell 98 Report lexical structure description:
+-- https://www.haskell.org/onlinereport/lexemes.html
+--
+-- However, this is probably far from being perfect and most probably does not
+-- handle correctly all corner cases.
+classify :: String -> TokenType
+classify str
+    | "--" `isPrefixOf` str = TkComment
+    | "{-#" `isPrefixOf` str = TkPragma
+    | "{-" `isPrefixOf` str = TkComment
+classify str@(c:_)
+    | isSpace c = TkSpace
+    | isDigit c = TkNumber
+    | c `elem` special = TkSpecial
+    | str `elem` glyphs = TkGlyph
+    | all (`elem` symbols) str = TkOperator
+    | c == '#' = TkCpp
+    | c == '"' = TkString
+    | c == '\'' = TkChar
+classify str
+    | str `elem` keywords = TkKeyword
+    | isIdentifier str = TkIdentifier
+    | otherwise = TkUnknown
+
+keywords :: [String]
+keywords =
+    [ "as"
+    , "case"
+    , "class"
+    , "data"
+    , "default"
+    , "deriving"
+    , "do"
+    , "else"
+    , "hiding"
+    , "if"
+    , "import"
+    , "in"
+    , "infix"
+    , "infixl"
+    , "infixr"
+    , "instance"
+    , "let"
+    , "module"
+    , "newtype"
+    , "of"
+    , "qualified"
+    , "then"
+    , "type"
+    , "where"
+    , "forall"
+    , "family"
+    , "mdo"
+    ]
+
+glyphs :: [String]
+glyphs =
+    [ ".."
+    , ":"
+    , "::"
+    , "="
+    , "\\"
+    , "|"
+    , "<-"
+    , "->"
+    , "@"
+    , "~"
+    , "~#"
+    , "=>"
+    , "-"
+    , "!"
+    ]
+
+special :: [Char]
+special = "()[]{},;`"
+
+-- TODO: Add support for any Unicode symbol or punctuation.
+-- source: http://stackoverflow.com/questions/10548170/what-characters-are-permitted-for-haskell-operators
+symbols :: [Char]
+symbols = "!#$%&*+./<=>?@\\^|-~:"
+
+isIdentifier :: String -> Bool
+isIdentifier (s:str)
+    | (isLower' s || isUpper s) && all isAlphaNum' str = True
+  where
+    isLower' c = isLower c || c == '_'
+    isAlphaNum' c = isAlphaNum c || c == '_' || c == '\''
+isIdentifier _ = 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,189 @@
+{-# LANGUAGE RecordWildCards #-}
+
+
+module Haddock.Backends.Hyperlinker.Renderer (render) where
+
+
+import Haddock.Backends.Hyperlinker.Types
+import Haddock.Backends.Hyperlinker.Utils
+
+import qualified GHC
+import qualified Name as GHC
+import qualified Unique as GHC
+
+import System.FilePath.Posix ((</>))
+
+import Data.List
+import Data.Maybe
+import Data.Monoid
+import qualified Data.Map as Map
+
+import Text.XHtml (Html, HtmlAttr, (!))
+import qualified Text.XHtml as Html
+
+
+type StyleClass = String
+
+
+render :: Maybe FilePath -> Maybe FilePath -> SrcMap -> [RichToken]
+       -> Html
+render mcss mjs srcs tokens = header mcss mjs <> body srcs tokens
+
+
+data TokenGroup
+    = GrpNormal Token
+    | GrpRich TokenDetails [Token]
+
+
+-- | Group consecutive tokens pointing to the same element.
+--
+-- We want to render qualified identifiers as one entity. For example,
+-- @Bar.Baz.foo@ consists of 5 tokens (@Bar@, @.@, @Baz@, @.@, @foo@) but for
+-- better user experience when highlighting and clicking links, these tokens
+-- should be regarded as one identifier. Therefore, before rendering we must
+-- group consecutive elements pointing to the same 'GHC.Name' (note that even
+-- dot token has it if it is part of qualified name).
+groupTokens :: [RichToken] -> [TokenGroup]
+groupTokens [] = []
+groupTokens ((RichToken tok Nothing):rest) = (GrpNormal tok):(groupTokens rest)
+groupTokens ((RichToken tok (Just det)):rest) =
+    let (grp, rest') = span same rest
+    in (GrpRich det (tok:(map rtkToken grp))):(groupTokens rest')
+  where
+    same (RichToken _ (Just det')) = det == det'
+    same _ = False
+
+
+body :: SrcMap -> [RichToken] -> Html
+body srcs tokens =
+    Html.body . Html.pre $ hypsrc
+  where
+    hypsrc = mconcat . map (tokenGroup srcs) . groupTokens $ tokens
+
+
+header :: Maybe FilePath -> Maybe FilePath -> Html
+header mcss mjs
+    | isNothing mcss && isNothing mjs = 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
+        ]
+
+
+tokenGroup :: SrcMap -> TokenGroup -> Html
+tokenGroup _ (GrpNormal tok@(Token { .. }))
+    | tkType == TkSpace = renderSpace (posRow . spStart $ tkSpan) tkValue
+    | otherwise = tokenSpan tok ! attrs
+  where
+    attrs = [ multiclass . tokenStyle $ tkType ]
+tokenGroup srcs (GrpRich det tokens) =
+    externalAnchor det . internalAnchor det . hyperlink srcs det $ content
+  where
+    content = mconcat . map (richToken det) $ tokens
+
+
+richToken :: TokenDetails -> Token -> Html
+richToken det tok =
+    tokenSpan tok ! [ multiclass style ]
+  where
+    style = (tokenStyle . tkType) tok ++ richTokenStyle det
+
+
+tokenSpan :: Token -> Html
+tokenSpan = Html.thespan . Html.toHtml . tkValue
+
+
+richTokenStyle :: TokenDetails -> [StyleClass]
+richTokenStyle (RtkVar _) = ["hs-var"]
+richTokenStyle (RtkType _) = ["hs-type"]
+richTokenStyle _ = []
+
+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 . intercalate " "
+
+externalAnchor :: TokenDetails -> Html -> Html
+externalAnchor (RtkDecl name) content =
+    Html.anchor content ! [ Html.name $ externalAnchorIdent name ]
+externalAnchor _ content = content
+
+internalAnchor :: TokenDetails -> Html -> Html
+internalAnchor (RtkBind name) content =
+    Html.anchor content ! [ Html.name $ internalAnchorIdent name ]
+internalAnchor _ content = content
+
+externalAnchorIdent :: GHC.Name -> String
+externalAnchorIdent = hypSrcNameUrl
+
+internalAnchorIdent :: GHC.Name -> String
+internalAnchorIdent = ("local-" ++) . show . GHC.getKey . GHC.nameUnique
+
+hyperlink :: SrcMap -> TokenDetails -> Html -> Html
+hyperlink srcs details = case rtkName details of
+    Left name ->
+        if GHC.isInternalName name
+        then internalHyperlink name
+        else externalNameHyperlink srcs name
+    Right name -> externalModHyperlink srcs name
+
+internalHyperlink :: GHC.Name -> Html -> Html
+internalHyperlink name content =
+    Html.anchor content ! [ Html.href $ "#" ++ internalAnchorIdent name ]
+
+externalNameHyperlink :: SrcMap -> GHC.Name -> Html -> Html
+externalNameHyperlink (srcs, _) name content = case Map.lookup mdl srcs of
+    Just SrcLocal -> Html.anchor content !
+        [ Html.href $ hypSrcModuleNameUrl mdl name ]
+    Just (SrcExternal path) -> Html.anchor content !
+        [ Html.href $ path </> hypSrcModuleNameUrl mdl name ]
+    Nothing -> content
+  where
+    mdl = GHC.nameModule name
+
+externalModHyperlink :: SrcMap -> GHC.ModuleName -> Html -> Html
+externalModHyperlink (_, srcs) name content = case Map.lookup name srcs of
+    Just SrcLocal -> Html.anchor content !
+        [ Html.href $ hypSrcModuleUrl' name ]
+    Just (SrcExternal path) -> Html.anchor content !
+        [ Html.href $ path </> hypSrcModuleUrl' name ]
+    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.anchor Html.noHtml ! [ Html.name $ 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,85 @@
+module Haddock.Backends.Hyperlinker.Types where
+
+
+import qualified GHC
+
+import Data.Map (Map)
+import qualified Data.Map as Map
+
+
+data Token = Token
+    { tkType :: TokenType
+    , tkValue :: String
+    , tkSpan :: Span
+    }
+
+data Position = Position
+    { posRow :: !Int
+    , posCol :: !Int
+    }
+
+data Span = Span
+    { spStart :: Position
+    , spEnd :: Position
+    }
+
+data TokenType
+    = TkIdentifier
+    | TkKeyword
+    | TkString
+    | TkChar
+    | TkNumber
+    | TkOperator
+    | TkGlyph
+    | TkSpecial
+    | TkSpace
+    | TkComment
+    | TkCpp
+    | TkPragma
+    | TkUnknown
+    deriving (Show, Eq)
+
+
+data RichToken = RichToken
+    { rtkToken :: Token
+    , rtkDetails :: Maybe TokenDetails
+    }
+
+data TokenDetails
+    = RtkVar GHC.Name
+    | RtkType GHC.Name
+    | RtkBind GHC.Name
+    | RtkDecl GHC.Name
+    | RtkModule GHC.ModuleName
+    deriving (Eq)
+
+
+rtkName :: TokenDetails -> Either GHC.Name GHC.ModuleName
+rtkName (RtkVar name) = Left name
+rtkName (RtkType name) = Left name
+rtkName (RtkBind name) = Left name
+rtkName (RtkDecl name) = Left name
+rtkName (RtkModule name) = Right name
+
+
+-- | 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.
+--
+-- This mapping is actually a pair of maps instead of just one map. The reason
+-- for this is because when hyperlinking modules in import lists we have no
+-- 'GHC.Module' available. On the other hand, we can't just use map with
+-- 'GHC.ModuleName' as indices because certain modules may have common name
+-- but originate in different packages. Hence, we use both /rich/ and /poor/
+-- versions, where the /poor/ is just projection of /rich/ one cached in pair
+-- for better performance.
+type SrcMap = (Map GHC.Module SrcPath, Map GHC.ModuleName SrcPath)
+
+mkSrcMap :: Map GHC.Module SrcPath -> SrcMap
+mkSrcMap srcs = (srcs, Map.mapKeys GHC.moduleName srcs)
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,68 @@
+module Haddock.Backends.Hyperlinker.Utils
+    ( hypSrcDir, hypSrcModuleFile, hypSrcModuleFile'
+    , hypSrcModuleUrl, hypSrcModuleUrl'
+    , hypSrcNameUrl
+    , hypSrcLineUrl
+    , hypSrcModuleNameUrl, hypSrcModuleLineUrl
+    , hypSrcModuleUrlFormat
+    , hypSrcModuleNameUrlFormat, hypSrcModuleLineUrlFormat
+    ) where
+
+
+import Haddock.Backends.Xhtml.Utils
+
+import GHC
+import FastString
+import System.FilePath.Posix ((</>))
+
+
+hypSrcDir :: FilePath
+hypSrcDir = "src"
+
+hypSrcModuleFile :: Module -> FilePath
+hypSrcModuleFile = hypSrcModuleFile' . moduleName
+
+hypSrcModuleFile' :: ModuleName -> FilePath
+hypSrcModuleFile' mdl = spliceURL'
+    Nothing (Just mdl) Nothing Nothing moduleFormat
+
+hypSrcModuleUrl :: Module -> String
+hypSrcModuleUrl = hypSrcModuleFile
+
+hypSrcModuleUrl' :: ModuleName -> String
+hypSrcModuleUrl' = hypSrcModuleFile'
+
+hypSrcNameUrl :: Name -> String
+hypSrcNameUrl name = spliceURL
+    Nothing Nothing (Just name) Nothing nameFormat
+
+hypSrcLineUrl :: Int -> String
+hypSrcLineUrl line = spliceURL
+    Nothing Nothing Nothing (Just spn) lineFormat
+  where
+    loc = mkSrcLoc nilFS line 1
+    spn = mkSrcSpan loc loc
+
+hypSrcModuleNameUrl :: Module -> Name -> String
+hypSrcModuleNameUrl mdl name = hypSrcModuleUrl mdl ++ "#" ++ hypSrcNameUrl name
+
+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}"
diff --git a/haddock-api/src/Haddock/Backends/LaTeX.hs b/haddock-api/src/Haddock/Backends/LaTeX.hs
--- a/haddock-api/src/Haddock/Backends/LaTeX.hs
+++ b/haddock-api/src/Haddock/Backends/LaTeX.hs
@@ -1,4 +1,5 @@
 {-# OPTIONS_GHC -fno-warn-name-shadowing #-}
+{-# LANGUAGE RecordWildCards #-}
 -----------------------------------------------------------------------------
 -- |
 -- Module      :  Haddock.Backends.LaTeX
@@ -212,9 +213,9 @@
 
 
 isSimpleSig :: ExportItem DocName -> Maybe ([DocName], HsType DocName)
-isSimpleSig ExportDecl { expItemDecl = L _ (SigD (TypeSig lnames (L _ t) _))
+isSimpleSig ExportDecl { expItemDecl = L _ (SigD (TypeSig lnames t))
                        , expItemMbDoc = (Documentation Nothing Nothing, argDocs) }
-  | Map.null argDocs = Just (map unLoc lnames, t)
+  | Map.null argDocs = Just (map unLoc lnames, unLoc (hsSigWcType t))
 isSimpleSig _ = Nothing
 
 
@@ -249,8 +250,8 @@
 declNames :: LHsDecl DocName -> [DocName]
 declNames (L _ decl) = case decl of
   TyClD d  -> [tcdName d]
-  SigD (TypeSig lnames _ _) -> map unLoc lnames
-  SigD (PatSynSig lname _ _ _ _) -> [unLoc lname]
+  SigD (TypeSig lnames _ ) -> map unLoc lnames
+  SigD (PatSynSig lname _) -> [unLoc lname]
   ForD (ForeignImport (L _ n) _ _ _) -> [n]
   ForD (ForeignExport (L _ n) _ _ _) -> [n]
   _ -> error "declaration not supported by declNames"
@@ -292,10 +293,11 @@
 --  TyClD d@(TySynonym {})
 --    | Just _  <- tcdTyPats d    -> ppTyInst False loc doc d unicode
 -- Family instances happen via FamInst now
-  TyClD d@(ClassDecl {})         -> ppClassDecl instances loc doc subdocs d unicode
-  SigD (TypeSig lnames (L _ t) _) -> ppFunSig loc (doc, fnArgsDoc) (map unLoc lnames) t unicode
-  SigD (PatSynSig lname qtvs prov req ty) ->
-      ppLPatSig loc (doc, fnArgsDoc) lname qtvs prov req ty unicode
+  TyClD d@(ClassDecl {})    -> ppClassDecl instances loc doc subdocs d unicode
+  SigD (TypeSig lnames t)   -> ppFunSig loc (doc, fnArgsDoc) (map unLoc lnames)
+                                        (hsSigWcType t) unicode
+  SigD (PatSynSig lname ty) ->
+      ppLPatSig loc (doc, fnArgsDoc) lname ty unicode
   ForD d                         -> ppFor loc (doc, fnArgsDoc) d unicode
   InstD _                        -> empty
   _                              -> error "declaration not supported by ppDecl"
@@ -310,8 +312,8 @@
 
 
 ppFor :: SrcSpan -> DocForDecl DocName -> ForeignDecl DocName -> Bool -> LaTeX
-ppFor loc doc (ForeignImport (L _ name) (L _ typ) _ _) unicode =
-  ppFunSig loc doc [name] typ unicode
+ppFor loc doc (ForeignImport (L _ name) typ _ _) unicode =
+  ppFunSig loc doc [name] (hsSigType typ) unicode
 ppFor _ _ _ _ = error "ppFor error in Haddock.Backends.LaTeX"
 --  error "foreign declarations are currently not supported by --latex"
 
@@ -328,7 +330,9 @@
                          , tcdRhs = ltype }) unicode
   = ppTypeOrFunSig loc [name] (unLoc ltype) doc (full, hdr, char '=') unicode
   where
-    hdr  = hsep (keyword "type" : ppDocBinder name : ppTyVars ltyvars)
+    hdr  = hsep (keyword "type"
+                 : ppDocBinder name
+                 : map ppSymName (tyvarNames ltyvars))
     full = hdr <+> char '=' <+> ppLType unicode ltype
 
 ppTySyn _ _ _ _ = error "declaration not supported by ppTySyn"
@@ -339,9 +343,9 @@
 -------------------------------------------------------------------------------
 
 
-ppFunSig :: SrcSpan -> DocForDecl DocName -> [DocName] -> HsType DocName
+ppFunSig :: SrcSpan -> DocForDecl DocName -> [DocName] -> LHsType DocName
          -> Bool -> LaTeX
-ppFunSig loc doc docnames typ unicode =
+ppFunSig loc doc docnames (L _ typ) unicode =
   ppTypeOrFunSig loc docnames typ doc
     ( ppTypeSig names typ False
     , hsep . punctuate comma $ map ppSymName names
@@ -351,29 +355,17 @@
    names = map getName docnames
 
 ppLPatSig :: SrcSpan -> DocForDecl DocName -> Located DocName
-          -> (HsExplicitFlag, LHsTyVarBndrs DocName)
-          -> LHsContext DocName -> LHsContext DocName
-          -> LHsType DocName
+          -> LHsSigType DocName
           -> Bool -> LaTeX
-ppLPatSig _loc (doc, _argDocs) (L _ name) (expl, qtvs) lprov lreq (L _ ty) unicode
+ppLPatSig _loc (doc, _argDocs) (L _ name) ty unicode
   = declWithDoc pref1 (documentationToLaTeX doc)
   where
     pref1 = hsep [ keyword "pattern"
                  , ppDocBinder name
                  , dcolon unicode
-                 , ppLTyVarBndrs expl qtvs unicode
-                 , ctx
-                 , ppType unicode ty
+                 , ppLType unicode (hsSigType ty)
                  ]
 
-    ctx = case (ppLContextMaybe lprov unicode, ppLContextMaybe lreq unicode) of
-        (Nothing,   Nothing)  -> empty
-        (Nothing,   Just req) -> parens empty <+> darr <+> req <+> darr
-        (Just prov, Nothing)  -> prov <+> darr
-        (Just prov, Just req) -> prov <+> darr <+> req <+> darr
-
-    darr = darrow unicode
-
 ppTypeOrFunSig :: SrcSpan -> [DocName] -> HsType DocName
                -> DocForDecl DocName -> (LaTeX, LaTeX, LaTeX)
                -> Bool -> LaTeX
@@ -392,23 +384,15 @@
 
      arg_doc n = rDoc . fmap _doc $ 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 Qualified e a lctxt ltype)
-       = do_args n leader (HsForAllTy Implicit e a lctxt 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 :: Int -> LaTeX -> HsType DocName -> LaTeX
+     do_args _n leader (HsForAllTy tvs ltype)
+       = decltt leader
+         <-> decltt (hsep (forallSymbol unicode : ppTyVars tvs ++ [dot]))
+         <+> ppLType unicode ltype
+     do_args n leader (HsQualTy lctxt ltype)
+       = decltt leader
+         <-> ppLContextNoArrow lctxt unicode <+> nl $$
+             do_largs n (darrow unicode) 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
@@ -423,12 +407,12 @@
     <+> ppType unicode ty
 
 
-ppTyVars :: LHsTyVarBndrs DocName -> [LaTeX]
-ppTyVars tvs = map ppSymName (tyvarNames tvs)
+ppTyVars :: [LHsTyVarBndr DocName] -> [LaTeX]
+ppTyVars = map (ppSymName . getName . hsLTyVarName)
 
 
-tyvarNames :: LHsTyVarBndrs DocName -> [Name]
-tyvarNames = map getName . hsLTyVarNames
+tyvarNames :: LHsQTyVars DocName -> [Name]
+tyvarNames = map (getName . hsLTyVarName) . hsQTvExplicit
 
 
 declWithDoc :: LaTeX -> Maybe LaTeX -> LaTeX
@@ -477,12 +461,12 @@
 
 
 ppClassHdr :: Bool -> Located [LHsType DocName] -> DocName
-           -> LHsTyVarBndrs DocName -> [Located ([Located DocName], [Located DocName])]
+           -> LHsQTyVars DocName -> [Located ([Located DocName], [Located 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)
+  <+> ppAppDocNameNames summ n (tyvarNames tvs)
   <+> ppFds fds unicode
 
 
@@ -520,8 +504,8 @@
 
     methodTable =
       text "\\haddockpremethods{}\\textbf{Methods}" $$
-      vcat  [ ppFunSig loc doc names typ unicode
-            | L _ (TypeSig lnames (L _ typ) _) <- lsigs
+      vcat  [ ppFunSig loc doc names (hsSigWcType typ) unicode
+            | L _ (TypeSig lnames typ) <- lsigs
             , let doc = lookupAnySubdoc (head names) subdocs
                   names = map unLoc lnames ]
               -- FIXME: is taking just the first name ok? Is it possible that
@@ -560,12 +544,13 @@
 
 
 ppInstHead :: Bool -> InstHead DocName -> LaTeX
-ppInstHead unicode (n, ks, ts, ClassInst ctx) = ppContextNoLocs ctx unicode <+> ppAppNameTypes n ks ts unicode
-ppInstHead unicode (n, ks, ts, TypeInst rhs) = keyword "type"
-  <+> ppAppNameTypes n ks ts unicode
-  <+> maybe empty (\t -> equals <+> ppType unicode t) rhs
-ppInstHead _unicode (_n, _ks, _ts, DataInst _dd) =
-  error "data instances not supported by --latex yet"
+ppInstHead unicode (InstHead {..}) = case ihdInstType of
+    ClassInst ctx _ _ _ -> ppContextNoLocs ctx unicode <+> typ
+    TypeInst rhs -> keyword "type" <+> typ <+> tibody rhs
+    DataInst _ -> error "data instances not supported by --latex yet"
+  where
+    typ = ppAppNameTypes ihdClsName ihdKinds ihdTypes unicode
+    tibody = maybe empty (\t -> equals <+> ppType unicode t)
 
 lookupAnySubdoc :: (Eq name1) =>
                    name1 -> [(name1, DocForDecl name2)] -> DocForDecl name2
@@ -591,14 +576,14 @@
 
   where
     cons      = dd_cons (tcdDataDefn dataDecl)
-    resTy     = (con_res . unLoc . head) cons
+    resTy     = (unLoc . head) cons
 
     body = catMaybes [constrBit, doc >>= documentationToLaTeX]
 
     (whereBit, leaders)
       | null cons = (empty,[])
       | otherwise = case resTy of
-        ResTyGADT _ _ -> (decltt (keyword "where"), repeat empty)
+        ConDeclGADT{} -> (decltt (keyword "where"), repeat empty)
         _             -> (empty, (decltt (text "=") : repeat (decltt (text "|"))))
 
     constrBit
@@ -612,22 +597,86 @@
 
 
 -- ppConstrHdr is for (non-GADT) existentials constructors' syntax
-ppConstrHdr :: HsExplicitFlag -> [Name] -> HsContext DocName -> Bool -> LaTeX
+ppConstrHdr :: Bool -> [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 ". "
-      Qualified -> empty
-      Implicit -> empty
+      True  -> forallSymbol unicode <+> hsep (map ppName tvs) <+> text ". "
+      False -> empty
 
 
 ppSideBySideConstr :: [(DocName, DocForDecl DocName)] -> Bool -> LaTeX
                    -> LConDecl DocName -> LaTeX
-ppSideBySideConstr subdocs unicode leader (L _ con) =
+ppSideBySideConstr subdocs unicode leader (L _ con@(ConDeclH98 {})) =
   leader <->
+  case con_details con of
+
+    PrefixCon args ->
+      decltt (hsep ((header_ unicode <+> ppOcc) :
+                 map (ppLParendType unicode) args))
+      <-> rDoc mbDoc <+> nl
+
+    RecCon (L _ fields) ->
+      (decltt (header_ unicode <+> ppOcc)
+        <-> rDoc mbDoc <+> nl)
+      $$
+      doRecordFields fields
+
+    InfixCon arg1 arg2 ->
+      decltt (hsep [ header_ unicode <+> ppLParendType unicode arg1,
+                 ppOcc,
+                 ppLParendType unicode arg2 ])
+      <-> rDoc mbDoc <+> nl
+
+ where
+    doRecordFields fields =
+        vcat (map (ppSideBySideField subdocs unicode) (map unLoc fields))
+
+
+    header_ = ppConstrHdr False tyVars context
+    occ     = map (nameOccName . getName . unLoc) $ getConNames con
+    ppOcc   = case occ of
+      [one] -> ppBinder one
+      _     -> cat (punctuate comma (map ppBinder occ))
+    tyVars  = tyvarNames (fromMaybe (HsQTvs PlaceHolder [] PlaceHolder) (con_qvars con))
+    context = unLoc (fromMaybe (noLoc []) (con_cxt 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.
+    mbDoc = case getConNames con of
+              [] -> panic "empty con_names"
+              (cn:_) -> lookup (unLoc cn) subdocs >>=
+                        fmap _doc . combineDocumentation . fst
+
+ppSideBySideConstr subdocs unicode leader (L _ con@(ConDeclGADT {})) =
+  leader <->
+  doGADTCon (hsib_body $ con_type con)
+
+ where
+    doGADTCon resTy = decltt (ppOcc <+> dcolon unicode <+>
+                               ppLType unicode resTy
+                            ) <-> rDoc mbDoc
+
+    occ     = map (nameOccName . getName . unLoc) $ getConNames con
+    ppOcc   = case occ of
+      [one] -> ppBinder one
+      _     -> cat (punctuate comma (map ppBinder occ))
+
+    -- 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 getConNames con of
+              [] -> panic "empty con_names"
+              (cn:_) -> lookup (unLoc cn) subdocs >>=
+                        fmap _doc . combineDocumentation . fst
+{- old
+
+ppSideBySideConstr :: [(DocName, DocForDecl DocName)] -> Bool -> LaTeX
+                   -> LConDecl DocName -> LaTeX
+ppSideBySideConstr subdocs unicode leader (L loc con) =
+  leader <->
   case con_res con of
   ResTyH98 -> case con_details con of
 
@@ -660,13 +709,13 @@
     doRecordFields fields =
         vcat (map (ppSideBySideField subdocs unicode) (map unLoc fields))
 
-    doGADTCon args resTy = decltt (ppOcc <+> dcolon unicode <+> hsep [
-                               ppForAll forall ltvs (con_cxt con) unicode,
-                               ppLType unicode (foldr mkFunTy resTy args) ]
+    doGADTCon args resTy = decltt (ppOcc <+> dcolon unicode <+>
+                               ppLType unicode (mk_forall $ mk_phi $
+                                                foldr mkFunTy resTy args)
                             ) <-> rDoc mbDoc
 
 
-    header_ = ppConstrHdr forall tyVars context
+    header_ = ppConstrHdr (con_explicit con) tyVars context
     occ     = map (nameOccName . getName . unLoc) $ con_names con
     ppOcc   = case occ of
       [one] -> ppBinder one
@@ -674,7 +723,12 @@
     ltvs    = con_qvars con
     tyVars  = tyvarNames (con_qvars con)
     context = unLoc (con_cxt con)
-    forall  = con_explicit con
+
+    mk_forall ty | con_explicit con = L loc (HsForAllTy (hsQTvExplicit ltvs) ty)
+                 | otherwise        = ty
+    mk_phi ty | null context = ty
+              | otherwise    = L loc (HsQualTy (con_cxt con) ty)
+
     -- 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 con_names con of
@@ -682,16 +736,16 @@
               (cn:_) -> lookup (unLoc cn) subdocs >>=
                         fmap _doc . combineDocumentation . fst
     mkFunTy a b = noLoc (HsFunTy a b)
-
+-}
 
 ppSideBySideField :: [(DocName, DocForDecl DocName)] -> Bool -> ConDeclField DocName ->  LaTeX
 ppSideBySideField subdocs unicode (ConDeclField names ltype _) =
-  decltt (cat (punctuate comma (map (ppBinder . nameOccName . getName . unL) names))
+  decltt (cat (punctuate comma (map (ppBinder . rdrNameOcc . unLoc . rdrNameFieldOcc . 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 (unL $ head names) subdocs >>= fmap _doc . combineDocumentation . fst
+    mbDoc = lookup (selectorFieldOcc $ unLoc $ head names) subdocs >>= fmap _doc . combineDocumentation . fst
 
 -- {-
 -- ppHsFullConstr :: HsConDecl -> LaTeX
@@ -790,9 +844,6 @@
 ppLContext        = ppContext        . unLoc
 ppLContextNoArrow = ppContextNoArrow . unLoc
 
-ppLContextMaybe :: Located (HsContext DocName) -> Bool -> Maybe LaTeX
-ppLContextMaybe = ppContextNoLocsMaybe . map unLoc . unLoc
-
 ppContextNoLocsMaybe :: [HsType DocName] -> Bool -> Maybe LaTeX
 ppContextNoLocsMaybe [] _ = Nothing
 ppContextNoLocsMaybe cxt unicode = Just $ pp_hs_context cxt unicode
@@ -822,9 +873,10 @@
 -------------------------------------------------------------------------------
 
 
-ppBang :: HsBang -> LaTeX
-ppBang HsNoBang = empty
-ppBang _        = char '!' -- Unpacked args is an implementation detail,
+ppBang :: HsSrcBang -> LaTeX
+ppBang (HsSrcBang _ _ SrcStrict) = char '!'
+ppBang (HsSrcBang _ _ SrcLazy)   = char '~'
+ppBang _                         = empty
 
 
 tupleParens :: HsTupleSort -> [LaTeX] -> LaTeX
@@ -877,33 +929,22 @@
 -- Drop top-level for-all type variables in user style
 -- since they are implicit in Haskell
 
-ppForAll :: HsExplicitFlag -> LHsTyVarBndrs DocName
-         -> Located (HsContext DocName) -> Bool -> LaTeX
-ppForAll expl tvs cxt unicode = ppLTyVarBndrs expl tvs unicode <+> ppLContext cxt unicode
-
-ppLTyVarBndrs :: HsExplicitFlag -> LHsTyVarBndrs DocName
-              -> Bool -> LaTeX
-ppLTyVarBndrs expl tvs unicode
-  | show_forall = hsep (forallSymbol unicode : ppTyVars tvs) <> dot
-  | otherwise   = empty
-  where
-    show_forall = not (null (hsQTvBndrs tvs)) && is_explicit
-    is_explicit = case expl of {Explicit -> True; Implicit -> False; Qualified -> False}
-
 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 extra tvs ctxt ty) unicode
+ppr_mono_ty ctxt_prec (HsForAllTy tvs ty) unicode
   = maybeParen ctxt_prec pREC_FUN $
-    hsep [ppForAll expl tvs ctxt' unicode, ppr_mono_lty pREC_TOP ty unicode]
- where ctxt' = case extra of
-                 Just loc -> (++ [L loc HsWildcardTy]) `fmap` ctxt
-                 Nothing  -> ctxt
+    sep [ hsep (forallSymbol unicode : ppTyVars tvs) <> dot
+        , ppr_mono_lty pREC_TOP ty unicode ]
+ppr_mono_ty ctxt_prec (HsQualTy ctxt ty) unicode
+  = maybeParen ctxt_prec pREC_FUN $
+    sep [ ppLContext 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 _         (HsTyVar (L _ 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 <+> ppLKind u kind)
@@ -911,12 +952,10 @@
 ppr_mono_ty _         (HsPArrTy ty)       u = pabrackets (ppr_mono_lty pREC_TOP ty u)
 ppr_mono_ty _         (HsIParamTy n ty)   u = brackets (ppIPName n <+> dcolon u <+> ppr_mono_lty pREC_TOP ty u)
 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 _         (HsExplicitListTy _ tys) u = Pretty.quote $ brackets $ hsep $ punctuate comma $ map (ppLType u) tys
 ppr_mono_ty _         (HsExplicitTupleTy _ tys) u = Pretty.quote $ parenList $ map (ppLType u) tys
-ppr_mono_ty _         (HsWrapTy {})       _ = error "ppr_mono_ty HsWrapTy"
 
 ppr_mono_ty ctxt_prec (HsEqTy ty1 ty2) unicode
   = maybeParen ctxt_prec pREC_OP $
@@ -926,7 +965,7 @@
   = 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
+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
@@ -940,13 +979,13 @@
 ppr_mono_ty ctxt_prec (HsDocTy ty _) unicode
   = ppr_mono_lty ctxt_prec ty unicode
 
-ppr_mono_ty _ HsWildcardTy _ = char '_'
-
-ppr_mono_ty _ (HsNamedWildcardTy name) _ = ppDocName name
+ppr_mono_ty _ (HsWildCardTy (AnonWildCard _)) _ = char '_'
 
 ppr_mono_ty _ (HsTyLit t) u = ppr_tylit t u
 
+ppr_mono_ty _ (HsAppsTy {}) _ = panic "ppr_mono_ty:HsAppsTy"
 
+
 ppr_tylit :: HsTyLit -> Bool -> LaTeX
 ppr_tylit (HsNumTy _ n) _ = integer n
 ppr_tylit (HsStrTy _ s) _ = text (show s)
@@ -1066,6 +1105,8 @@
   markupMonospaced           = \p _ -> tt (p Mono),
   markupUnorderedList        = \p v -> itemizedList (map ($v) p) $$ text "",
   markupPic                  = \p _ -> markupPic p,
+  markupMathInline           = \p _ -> markupMathInline p,
+  markupMathDisplay          = \p _ -> markupMathDisplay p,
   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 "",
@@ -1097,6 +1138,10 @@
         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 ppId_ id v =
       case v of
diff --git a/haddock-api/src/Haddock/Backends/Xhtml.hs b/haddock-api/src/Haddock/Backends/Xhtml.hs
--- a/haddock-api/src/Haddock/Backends/Xhtml.hs
+++ b/haddock-api/src/Haddock/Backends/Xhtml.hs
@@ -63,6 +63,7 @@
        -> 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)
        -> Maybe String                 -- ^ The contents URL (--use-contents)
@@ -73,7 +74,7 @@
        -> IO ()
 
 ppHtml dflags doctitle maybe_package ifaces odir prologue
-        themes maybe_source_url maybe_wiki_url
+        themes maybe_mathjax_url maybe_source_url maybe_wiki_url
         maybe_contents_url maybe_index_url unicode
         qual debug =  do
   let
@@ -82,18 +83,18 @@
 
   when (isNothing maybe_contents_url) $
     ppHtmlContents dflags odir doctitle maybe_package
-        themes maybe_index_url maybe_source_url maybe_wiki_url
+        themes maybe_mathjax_url 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 (makeContentsQual qual)
 
   when (isNothing maybe_index_url) $
     ppHtmlIndex odir doctitle maybe_package
-      themes maybe_contents_url maybe_source_url maybe_wiki_url
+      themes maybe_mathjax_url 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_mathjax_url maybe_source_url maybe_wiki_url
            maybe_contents_url maybe_index_url unicode qual debug) visible_ifaces
 
 
@@ -107,13 +108,14 @@
   mapM_ copyLibFile [ jsFile, framesFile ]
 
 
-headHtml :: String -> Maybe String -> Themes -> Html
-headHtml docTitle miniPage themes =
+headHtml :: String -> Maybe String -> Themes -> Maybe String -> Html
+headHtml docTitle miniPage themes mathjax_url =
   header << [
     meta ! [httpequiv "Content-Type", content "text/html; charset=UTF-8"],
     thetitle << docTitle,
     styleSheet themes,
     script ! [src jsFile, thetype "text/javascript"] << noHtml,
+    script ! [src mjUrl, 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
@@ -124,6 +126,7 @@
     ]
   where
     setSynopsis = maybe "" (\p -> "setSynopsis(\"" ++ p ++ "\");") miniPage
+    mjUrl = maybe "https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" id mathjax_url
 
 
 srcButton :: SourceURLs -> Maybe Interface -> Maybe Html
@@ -242,6 +245,7 @@
    -> Maybe String
    -> Themes
    -> Maybe String
+   -> Maybe String
    -> SourceURLs
    -> WikiURLs
    -> [InstalledInterface] -> Bool -> Maybe (MDoc GHC.RdrName)
@@ -249,12 +253,12 @@
    -> Qualification  -- ^ How to qualify names
    -> IO ()
 ppHtmlContents dflags odir doctitle _maybe_package
-  themes maybe_index_url
+  themes mathjax_url maybe_index_url
   maybe_source_url maybe_wiki_url ifaces showPkgs prologue debug qual = do
   let tree = mkModuleTree dflags showPkgs
          [(instMod iface, toInstalledDescription iface) | iface <- ifaces]
       html =
-        headHtml doctitle Nothing themes +++
+        headHtml doctitle Nothing themes mathjax_url +++
         bodyHtml doctitle Nothing
           maybe_source_url maybe_wiki_url
           Nothing maybe_index_url << [
@@ -265,7 +269,7 @@
   writeFile (joinPath [odir, contentsHtmlFile]) (renderToString debug html)
 
   -- XXX: think of a better place for this?
-  ppHtmlContentsFrame odir doctitle themes ifaces debug
+  ppHtmlContentsFrame odir doctitle themes mathjax_url ifaces debug
 
 
 ppPrologue :: Qualification -> String -> Maybe (MDoc GHC.RdrName) -> Html
@@ -304,7 +308,7 @@
 
     htmlModule = thespan ! modAttrs << (cBtn +++
       if leaf
-        then ppModule (mkModule (stringToPackageKey (fromMaybe "" pkg))
+        then ppModule (mkModule (stringToUnitId (fromMaybe "" pkg))
                                        (mkModuleName mdl))
         else toHtml s
       )
@@ -338,12 +342,12 @@
         << toHtml txt
 
 
-ppHtmlContentsFrame :: FilePath -> String -> Themes
+ppHtmlContentsFrame :: FilePath -> String -> Themes -> Maybe String
   -> [InstalledInterface] -> Bool -> IO ()
-ppHtmlContentsFrame odir doctitle themes ifaces debug = do
+ppHtmlContentsFrame odir doctitle themes maybe_mathjax_url ifaces debug = do
   let mods = flatModuleTree ifaces
       html =
-        headHtml doctitle Nothing themes +++
+        headHtml doctitle Nothing themes maybe_mathjax_url +++
         miniBody << divModuleList <<
           (sectionName << "Modules" +++
            ulist << [ li ! [theclass "module"] << m | m <- mods ])
@@ -361,13 +365,14 @@
             -> Maybe String
             -> Themes
             -> Maybe String
+            -> 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
+  maybe_mathjax_url maybe_contents_url maybe_source_url maybe_wiki_url ifaces debug = do
   let html = indexPage split_indices Nothing
               (if split_indices then [] else index)
 
@@ -383,7 +388,7 @@
 
   where
     indexPage showLetters ch items =
-      headHtml (doctitle ++ " (" ++ indexName ch ++ ")") Nothing themes +++
+      headHtml (doctitle ++ " (" ++ indexName ch ++ ")") Nothing themes maybe_mathjax_url +++
       bodyHtml doctitle Nothing
         maybe_source_url maybe_wiki_url
         maybe_contents_url Nothing << [
@@ -483,11 +488,11 @@
 
 ppHtmlModule
         :: FilePath -> String -> Themes
-        -> SourceURLs -> WikiURLs
+        -> Maybe String -> SourceURLs -> WikiURLs
         -> Maybe String -> Maybe String -> Bool -> QualOption
         -> Bool -> Interface -> IO ()
 ppHtmlModule odir doctitle themes
-  maybe_source_url maybe_wiki_url
+  maybe_mathjax_url maybe_source_url maybe_wiki_url
   maybe_contents_url maybe_index_url unicode qual debug iface = do
   let
       mdl = ifaceMod iface
@@ -495,7 +500,7 @@
       mdl_str = moduleString mdl
       real_qual = makeModuleQual qual aliases mdl
       html =
-        headHtml mdl_str (Just $ "mini_" ++ moduleHtmlFile mdl) themes +++
+        headHtml mdl_str (Just $ "mini_" ++ moduleHtmlFile mdl) themes maybe_mathjax_url +++
         bodyHtml doctitle (Just iface)
           maybe_source_url maybe_wiki_url
           maybe_contents_url maybe_index_url << [
@@ -505,14 +510,14 @@
 
   createDirectoryIfMissing True odir
   writeFile (joinPath [odir, moduleHtmlFile mdl]) (renderToString debug html)
-  ppHtmlModuleMiniSynopsis odir doctitle themes iface unicode real_qual debug
+  ppHtmlModuleMiniSynopsis odir doctitle themes maybe_mathjax_url iface unicode real_qual debug
 
 ppHtmlModuleMiniSynopsis :: FilePath -> String -> Themes
-  -> Interface -> Bool -> Qualification -> Bool -> IO ()
-ppHtmlModuleMiniSynopsis odir _doctitle themes iface unicode qual debug = do
+  -> Maybe String -> Interface -> Bool -> Qualification -> Bool -> IO ()
+ppHtmlModuleMiniSynopsis odir _doctitle themes maybe_mathjax_url iface unicode qual debug = do
   let mdl = ifaceMod iface
       html =
-        headHtml (moduleString mdl) Nothing themes +++
+        headHtml (moduleString mdl) Nothing themes maybe_mathjax_url +++
         miniBody <<
           (divModuleHeader << sectionName << moduleString mdl +++
            miniSynopsis mdl iface unicode qual)
@@ -522,10 +527,10 @@
 
 ifaceToHtml :: SourceURLs -> WikiURLs -> Interface -> Bool -> Qualification -> Html
 ifaceToHtml maybe_source_url maybe_wiki_url iface unicode qual
-  = ppModuleContents qual exports +++
+  = ppModuleContents qual exports (not . null $ ifaceRnOrphanInstances iface) +++
     description +++
     synopsis +++
-    divInterface (maybe_doc_hdr +++ bdy)
+    divInterface (maybe_doc_hdr +++ bdy +++ orphans)
   where
     exports = numberSectionHeadings (ifaceRnExportItems iface)
 
@@ -546,7 +551,7 @@
     synopsis
       | no_doc_at_all = noHtml
       | otherwise
-      = divSynposis $
+      = divSynopsis $
             paragraph ! collapseControl "syn" False "caption" << "Synopsis" +++
             shortDeclList (
                 mapMaybe (processExport True linksInfo unicode qual) exports
@@ -564,6 +569,9 @@
       foldr (+++) noHtml $
         mapMaybe (processExport False linksInfo unicode qual) exports
 
+    orphans =
+      ppOrphanInstances linksInfo (ifaceRnOrphanInstances iface) False unicode qual
+
     linksInfo = (maybe_source_url, maybe_wiki_url)
 
 
@@ -583,7 +591,7 @@
         (DataDecl{})   -> [keyword "data" <+> b]
         (SynDecl{})    -> [keyword "type" <+> b]
         (ClassDecl {}) -> [keyword "class" <+> b]
-    SigD (TypeSig lnames (L _ _) _) ->
+    SigD (TypeSig lnames _) ->
       map (ppNameMini Prefix mdl . nameOccName . getName . unLoc) lnames
     _ -> []
 processForMiniSynopsis _ _ qual (ExportGroup lvl _id txt) =
@@ -604,16 +612,22 @@
       ns = tyvarNames $ tcdTyVars decl -- it's safe to use tcdTyVars, see code above
   in ppTypeApp n [] ns (\is_infix -> ppNameMini is_infix mdl . nameOccName . getName) ppTyName
 
-ppModuleContents :: Qualification -> [ExportItem DocName] -> Html
-ppModuleContents qual exports
-  | null sections = noHtml
-  | otherwise     = contentsDiv
+ppModuleContents :: Qualification
+                 -> [ExportItem DocName]
+                 -> Bool -- ^ Orphans sections
+                 -> Html
+ppModuleContents qual exports orphan
+  | null sections && not orphan  = noHtml
+  | otherwise                    = contentsDiv
  where
   contentsDiv = divTableOfContents << (
     sectionName << "Contents" +++
-    unordList sections)
+    unordList (sections ++ orphanSection))
 
   (sections, _leftovers{-should be []-}) = process 0 exports
+  orphanSection
+    | orphan =  [ linkedAnchor "section.orphans" << "Orphan instances" ]
+    | otherwise = []
 
   process :: Int -> [ExportItem DocName] -> ([Html],[ExportItem DocName])
   process _ [] = ([], [])
diff --git a/haddock-api/src/Haddock/Backends/Xhtml/Decl.hs b/haddock-api/src/Haddock/Backends/Xhtml/Decl.hs
--- a/haddock-api/src/Haddock/Backends/Xhtml/Decl.hs
+++ b/haddock-api/src/Haddock/Backends/Xhtml/Decl.hs
@@ -1,4 +1,6 @@
 {-# LANGUAGE TransformListComp #-}
+{-# LANGUAGE RecordWildCards #-}
+{-# LANGUAGE Rank2Types #-}
 -----------------------------------------------------------------------------
 -- |
 -- Module      :  Haddock.Backends.Html.Decl
@@ -14,7 +16,7 @@
 module Haddock.Backends.Xhtml.Decl (
   ppDecl,
 
-  ppTyName, ppTyFamHeader, ppTypeApp,
+  ppTyName, ppTyFamHeader, ppTypeApp, ppOrphanInstances,
   tyvarNames
 ) where
 
@@ -36,18 +38,20 @@
 import GHC.Exts
 import Name
 import BooleanFormula
+import RdrName ( rdrNameOcc )
 
 ppDecl :: Bool -> LinksInfo -> LHsDecl DocName
        -> DocForDecl DocName -> [DocInstance DocName] -> [(DocName, Fixity)]
        -> [(DocName, DocForDecl DocName)] -> Splice -> Unicode -> Qualification -> Html
 ppDecl summ links (L loc decl) (mbDoc, fnArgsDoc) instances fixities subdocs splice unicode qual = case decl of
-  TyClD (FamDecl d)           -> ppTyFam summ False links instances fixities loc mbDoc d splice unicode qual
-  TyClD d@(DataDecl {})       -> ppDataDecl summ links instances fixities subdocs loc mbDoc d splice unicode qual
-  TyClD d@(SynDecl {})        -> ppTySyn summ links fixities loc (mbDoc, fnArgsDoc) d splice unicode qual
-  TyClD d@(ClassDecl {})      -> ppClassDecl summ links instances fixities loc mbDoc subdocs d splice unicode qual
-  SigD (TypeSig lnames lty _) -> ppLFunSig summ links loc (mbDoc, fnArgsDoc) lnames lty fixities splice unicode qual
-  SigD (PatSynSig lname qtvs prov req ty) ->
-      ppLPatSig summ links loc (mbDoc, fnArgsDoc) lname qtvs prov req ty fixities splice unicode qual
+  TyClD (FamDecl d)         -> ppTyFam summ False links instances fixities loc mbDoc d splice unicode qual
+  TyClD d@(DataDecl {})     -> ppDataDecl summ links instances fixities subdocs loc mbDoc d splice unicode qual
+  TyClD d@(SynDecl {})      -> ppTySyn summ links fixities loc (mbDoc, fnArgsDoc) d splice unicode qual
+  TyClD d@(ClassDecl {})    -> ppClassDecl summ links instances fixities loc mbDoc subdocs d splice unicode qual
+  SigD (TypeSig lnames lty) -> ppLFunSig summ links loc (mbDoc, fnArgsDoc) lnames
+                                         (hsSigWcType lty) fixities splice unicode qual
+  SigD (PatSynSig lname ty) -> ppLPatSig summ links loc (mbDoc, fnArgsDoc) lname
+                                         ty fixities splice unicode qual
   ForD d                         -> ppFor summ links loc (mbDoc, fnArgsDoc) d fixities splice unicode qual
   InstD _                        -> noHtml
   _                              -> error "declaration not supported by ppDecl"
@@ -57,26 +61,23 @@
              [Located DocName] -> LHsType DocName -> [(DocName, Fixity)] ->
              Splice -> Unicode -> Qualification -> Html
 ppLFunSig summary links loc doc lnames lty fixities splice unicode qual =
-  ppFunSig summary links loc doc (map unLoc lnames) (unLoc lty) fixities
+  ppFunSig summary links loc doc (map unLoc lnames) lty fixities
            splice unicode qual
 
 ppFunSig :: Bool -> LinksInfo -> SrcSpan -> DocForDecl DocName ->
-            [DocName] -> HsType DocName -> [(DocName, Fixity)] ->
+            [DocName] -> LHsType DocName -> [(DocName, Fixity)] ->
             Splice -> Unicode -> Qualification -> Html
 ppFunSig summary links loc doc docnames typ fixities splice unicode qual =
-  ppSigLike summary links loc mempty doc docnames fixities (typ, pp_typ)
+  ppSigLike summary links loc mempty doc docnames fixities (unLoc typ, pp_typ)
             splice unicode qual
   where
-    pp_typ = ppType unicode qual typ
+    pp_typ = ppLType unicode qual typ
 
 ppLPatSig :: Bool -> LinksInfo -> SrcSpan -> DocForDecl DocName ->
-             Located DocName ->
-             (HsExplicitFlag, LHsTyVarBndrs DocName) ->
-             LHsContext DocName -> LHsContext DocName ->
-             LHsType DocName ->
+             Located DocName -> LHsSigType DocName ->
              [(DocName, Fixity)] ->
              Splice -> Unicode -> Qualification -> Html
-ppLPatSig summary links loc (doc, _argDocs) (L _ name) (expl, qtvs) lprov lreq typ fixities splice unicode qual
+ppLPatSig summary links loc (doc, _argDocs) (L _ name) typ fixities splice unicode qual
   | summary = pref1
   | otherwise = topDeclElem links loc splice [name] (pref1 <+> ppFixities fixities qual)
                 +++ docSection Nothing qual doc
@@ -84,18 +85,9 @@
     pref1 = hsep [ keyword "pattern"
                  , ppBinder summary occname
                  , dcolon unicode
-                 , ppLTyVarBndrs expl qtvs unicode qual
-                 , cxt
-                 , ppLType unicode qual typ
+                 , ppLType unicode qual (hsSigType typ)
                  ]
 
-    cxt = case (ppLContextMaybe lprov unicode qual, ppLContextMaybe lreq unicode qual) of
-        (Nothing,   Nothing)  -> noHtml
-        (Nothing,   Just req) -> parens noHtml <+> darr <+> req <+> darr
-        (Just prov, Nothing)  -> prov <+> darr
-        (Just prov, Just req) -> prov <+> darr <+> req <+> darr
-
-    darr = darrow unicode
     occname = nameOccName . getName $ name
 
 ppSigLike :: Bool -> LinksInfo -> SrcSpan -> Html -> DocForDecl DocName ->
@@ -129,22 +121,29 @@
     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 _ _ tvs lctxt ltype)
-      = case unLoc lctxt of
-        [] -> do_largs n leader' ltype
-        _  -> (leader' <+> ppLContextNoArrow lctxt unicode qual, Nothing, [])
-              : do_largs n (darrow unicode) ltype
-      where leader' = leader <+> ppForAll tvs unicode qual
+    do_args n leader (HsForAllTy tvs ltype)
+      = do_largs n leader' ltype
+      where
+        leader' = leader <+> ppForAll tvs unicode qual
+
+    do_args n leader (HsQualTy lctxt ltype)
+      | null (unLoc lctxt)
+      = do_largs n leader ltype
+      | otherwise
+      = (leader <+> ppLContextNoArrow lctxt unicode qual, Nothing, [])
+        : do_largs n (darrow unicode) 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, [])]
 
-ppForAll :: LHsTyVarBndrs DocName -> Unicode -> Qualification -> Html
+ppForAll :: [LHsTyVarBndr DocName] -> Unicode -> Qualification -> Html
 ppForAll tvs unicode qual =
-  case [ppKTv n k | L _ (KindedTyVar (L _ n) k) <- hsQTvBndrs tvs] of
+  case [ppKTv n k | L _ (KindedTyVar (L _ n) k) <- tvs] of
     [] -> noHtml
     ts -> forallSymbol unicode <+> hsep ts +++ dot
   where ppKTv n k = parens $
@@ -165,27 +164,27 @@
       _:[] -> 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
+    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
 
 
-ppTyVars :: LHsTyVarBndrs DocName -> [Html]
-ppTyVars tvs = map ppTyName (tyvarNames tvs)
-
+-- | Pretty-print type variables.
+ppTyVars :: [LHsTyVarBndr DocName] -> [Html]
+ppTyVars tvs = map (ppTyName . getName . hsLTyVarName) tvs
 
-tyvarNames :: LHsTyVarBndrs DocName -> [Name]
-tyvarNames = map getName . hsLTyVarNames
+tyvarNames :: LHsQTyVars DocName -> [Name]
+tyvarNames = map (getName . hsLTyVarName) . hsQTvExplicit
 
 
 ppFor :: Bool -> LinksInfo -> SrcSpan -> DocForDecl DocName
       -> ForeignDecl DocName -> [(DocName, Fixity)]
       -> Splice -> Unicode -> Qualification -> Html
-ppFor summary links loc doc (ForeignImport (L _ name) (L _ typ) _ _) fixities
+ppFor summary links loc doc (ForeignImport (L _ name) typ _ _) fixities
       splice unicode qual
-  = ppFunSig summary links loc doc [name] typ fixities splice unicode qual
+  = ppFunSig summary links loc doc [name] (hsSigType typ) fixities splice unicode qual
 ppFor _ _ _ _ _ _ _ _ _ = error "ppFor"
 
 
@@ -200,7 +199,8 @@
                    (full <+> fixs, hdr <+> fixs, spaceHtml +++ equals)
                    splice unicode qual
   where
-    hdr  = hsep ([keyword "type", ppBinder summary occ] ++ ppTyVars ltyvars)
+    hdr  = hsep ([keyword "type", ppBinder summary occ]
+                 ++ ppTyVars (hsQTvExplicit ltyvars))
     full = hdr <+> equals <+> ppLType unicode qual ltype
     occ  = nameOccName . getName $ name
     fixs
@@ -209,7 +209,7 @@
 ppTySyn _ _ _ _ _ _ _ _ _ = error "declaration not supported by ppTySyn"
 
 
-ppTypeSig :: Bool -> [OccName] -> Html  -> Bool -> Html
+ppTypeSig :: Bool -> [OccName] -> Html -> Unicode -> Html
 ppTypeSig summary nms pp_ty unicode =
   concatHtml htmlNames <+> dcolon unicode <+> pp_ty
   where
@@ -220,15 +220,37 @@
 ppTyName = ppName Prefix
 
 
+ppSimpleSig :: LinksInfo -> Splice -> Unicode -> Qualification -> SrcSpan
+            -> [DocName] -> HsType DocName
+            -> Html
+ppSimpleSig links splice unicode qual loc names typ =
+    topDeclElem' names $ ppTypeSig True occNames ppTyp unicode
+  where
+    topDeclElem' = topDeclElem links loc splice
+    ppTyp = ppType unicode qual typ
+    occNames = map getOccName names
+
+
 --------------------------------------------------------------------------------
 -- * Type families
 --------------------------------------------------------------------------------
 
 
+ppFamilyInfo :: Bool -> FamilyInfo DocName -> Html
+ppFamilyInfo assoc OpenTypeFamily
+    | assoc = keyword "type"
+    | otherwise = keyword "type family"
+ppFamilyInfo assoc DataFamily
+    | assoc = keyword "data"
+    | otherwise = keyword "data family"
+ppFamilyInfo _ (ClosedTypeFamily _) = keyword "type family"
+
+
 ppTyFamHeader :: Bool -> Bool -> FamilyDecl DocName
               -> Unicode -> Qualification -> Html
 ppTyFamHeader summary associated d@(FamilyDecl { fdInfo = info
-                                               , fdKindSig = mkind })
+                                               , fdResultSig = L _ result
+                                               , fdInjectivityAnn = injectivity })
               unicode qual =
   (case info of
      OpenTypeFamily
@@ -241,13 +263,38 @@
                     -> keyword "type family"
   ) <+>
 
-  ppFamDeclBinderWithVars summary d <+>
+  ppFamDeclBinderWithVars summary unicode qual d <+>
+  ppResultSig result unicode qual <+>
 
-  (case mkind of
-    Just kind -> dcolon unicode  <+> ppLKind unicode qual kind
-    Nothing   -> noHtml
+  (case injectivity of
+     Nothing                   -> noHtml
+     Just (L _ injectivityAnn) -> ppInjectivityAnn unicode qual injectivityAnn
+  ) <+>
+
+  (case info of
+     ClosedTypeFamily _ -> keyword "where ..."
+     _                  -> mempty
   )
 
+ppResultSig :: FamilyResultSig DocName -> 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
+
+ppPseudoFamilyHeader :: Unicode -> Qualification -> PseudoFamilyDecl DocName
+                     -> Html
+ppPseudoFamilyHeader unicode qual (PseudoFamilyDecl { .. }) =
+    ppFamilyInfo True pfdInfo <+>
+    ppAppNameTypes (unLoc pfdLName) [] (map unLoc pfdTyVars) unicode qual <+>
+    ppResultSig (unLoc pfdKindSig) unicode qual
+
+ppInjectivityAnn :: Bool -> Qualification -> InjectivityAnn DocName -> Html
+ppInjectivityAnn unicode qual (InjectivityAnn lhs rhs) =
+    char '|' <+> ppLDocName qual Raw lhs <+> arrow unicode <+>
+    hsep (map (ppLDocName qual Raw) rhs)
+
+
 ppTyFam :: Bool -> Bool -> LinksInfo -> [DocInstance DocName] ->
            [(DocName, Fixity)] -> SrcSpan -> Documentation DocName ->
            FamilyDecl DocName -> Splice -> Unicode -> Qualification -> Html
@@ -263,20 +310,32 @@
        ppTyFamHeader summary associated decl unicode qual <+> ppFixities fixities qual
 
     instancesBit
-      | FamilyDecl { fdInfo = ClosedTypeFamily eqns } <- decl
+      | FamilyDecl { fdInfo = ClosedTypeFamily mb_eqns } <- decl
       , not summary
-      = subEquations qual $ map (ppTyFamEqn . unLoc) eqns
+      = subEquations qual $ map (ppTyFamEqn . unLoc) $ fromMaybe [] mb_eqns
 
       | otherwise
-      = ppInstances links instances docname unicode qual
+      = ppInstances links (OriginFamily docname) instances splice unicode qual
 
     -- Individual equation of a closed type family
     ppTyFamEqn TyFamEqn { tfe_tycon = n, tfe_rhs = rhs
-                        , tfe_pats = HsWB { hswb_cts = ts }}
+                        , tfe_pats = HsIB { hsib_body = ts }}
       = ( ppAppNameTypes (unLoc n) [] (map unLoc ts) unicode qual
           <+> equals <+> ppType unicode qual (unLoc rhs)
         , Nothing, [] )
 
+
+
+ppPseudoFamilyDecl :: LinksInfo -> Splice -> Unicode -> Qualification
+                   -> PseudoFamilyDecl DocName
+                   -> Html
+ppPseudoFamilyDecl links splice unicode qual
+                   decl@(PseudoFamilyDecl { pfdLName = L loc name, .. }) =
+    wrapper $ ppPseudoFamilyHeader unicode qual decl
+  where
+    wrapper = topDeclElem links loc splice [name]
+
+
 --------------------------------------------------------------------------------
 -- * Associated Types
 --------------------------------------------------------------------------------
@@ -293,9 +352,9 @@
 --------------------------------------------------------------------------------
 
 -- | Print a type family and its variables
-ppFamDeclBinderWithVars :: Bool -> FamilyDecl DocName -> Html
-ppFamDeclBinderWithVars summ (FamilyDecl { fdLName = lname, fdTyVars = tvs }) =
-  ppAppDocNameNames summ (unLoc lname) (tyvarNames tvs)
+ppFamDeclBinderWithVars :: Bool -> Unicode -> Qualification -> FamilyDecl DocName -> Html
+ppFamDeclBinderWithVars summ unicode qual (FamilyDecl { fdLName = lname, fdTyVars = tvs }) =
+  ppAppDocNameTyVarBndrs summ unicode qual (unLoc lname) (map unLoc $ hsq_explicit tvs)
 
 -- | Print a newtype / data binder and its variables
 ppDataBinderWithVars :: Bool -> TyClDecl DocName -> Html
@@ -306,15 +365,22 @@
 -- * Type applications
 --------------------------------------------------------------------------------
 
+ppAppDocNameTyVarBndrs :: Bool -> Unicode -> Qualification -> DocName -> [HsTyVarBndr DocName] -> Html
+ppAppDocNameTyVarBndrs summ unicode qual n vs =
+    ppTypeApp n [] vs ppDN (ppHsTyVarBndr unicode qual)
+  where
+    ppDN notation = ppBinderFixity notation summ . nameOccName . getName
+    ppBinderFixity Infix = ppBinderInfix
+    ppBinderFixity _ = ppBinder
 
--- | Print an application of a DocName and two lists of HsTypes (kinds, types)
+-- | Print an application of a 'DocName' and two lists of 'HsTypes' (kinds, types)
 ppAppNameTypes :: DocName -> [HsType DocName] -> [HsType DocName]
                -> Unicode -> Qualification -> Html
 ppAppNameTypes n ks ts unicode qual =
     ppTypeApp n ks ts (\p -> ppDocName qual p True) (ppParendType unicode qual)
 
 
--- | Print an application of a DocName and a list of Names
+-- | Print an application of a 'DocName' and a list of 'Names'
 ppAppDocNameNames :: Bool -> DocName -> [Name] -> Html
 ppAppDocNameNames summ n ns =
     ppTypeApp n [] ns ppDN ppTyName
@@ -345,10 +411,6 @@
 ppLContext        = ppContext        . unLoc
 ppLContextNoArrow = ppContextNoArrow . unLoc
 
-
-ppLContextMaybe :: Located (HsContext DocName) -> Unicode -> Qualification -> Maybe Html
-ppLContextMaybe = ppContextNoLocsMaybe . map unLoc . unLoc
-
 ppContextNoArrow :: HsContext DocName -> Unicode -> Qualification -> Html
 ppContextNoArrow cxt unicode qual = fromMaybe noHtml $
                                     ppContextNoLocsMaybe (map unLoc cxt) unicode qual
@@ -379,7 +441,7 @@
 
 
 ppClassHdr :: Bool -> Located [LHsType DocName] -> DocName
-           -> LHsTyVarBndrs DocName -> [Located ([Located DocName], [Located DocName])]
+           -> LHsQTyVars DocName -> [Located ([Located DocName], [Located DocName])]
            -> Unicode -> Qualification -> Html
 ppClassHdr summ lctxt n tvs fds unicode qual =
   keyword "class"
@@ -402,7 +464,7 @@
 ppShortClassDecl summary links (ClassDecl { tcdCtxt = lctxt, tcdLName = lname, tcdTyVars = tvs
                                           , tcdFDs = fds, tcdSigs = sigs, tcdATs = ats }) loc
     subdocs splice unicode qual =
-  if not (any isVanillaLSig sigs) && null ats
+  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
@@ -412,8 +474,9 @@
 
                 -- ToDo: add associated type defaults
 
-            [ ppFunSig summary links loc doc names typ [] splice unicode qual
-              | L _ (TypeSig lnames (L _ typ) _) <- sigs
+            [ ppFunSig summary links loc doc names (hsSigWcType typ)
+                       [] splice unicode qual
+              | L _ (TypeSig 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
@@ -439,8 +502,10 @@
   | otherwise = classheader +++ docSection Nothing qual d
                   +++ minimalBit +++ atBit +++ methodBit +++ instancesBit
   where
+    sigs = map unLoc lsigs
+
     classheader
-      | any isVanillaLSig lsigs = topDeclElem links loc splice [nm] (hdr unicode qual <+> keyword "where" <+> fixs)
+      | 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
@@ -457,8 +522,9 @@
                             doc = lookupAnySubdoc (unL $ fdLName $ unL at) subdocs
                             subfixs = [ f | f@(n',_) <- fixities, n == n' ] ]
 
-    methodBit = subMethods [ ppFunSig summary links loc doc names typ subfixs splice unicode qual
-                           | L _ (TypeSig lnames (L _ typ) _) <- lsigs
+    methodBit = subMethods [ ppFunSig summary links loc doc names (hsSigType typ)
+                                      subfixs splice unicode qual
+                           | L _ (ClassOpSig _ lnames typ) <- lsigs
                            , let doc = lookupAnySubdoc (head names) subdocs
                                  subfixs = [ f | n <- names
                                                , f@(n',_) <- fixities
@@ -468,15 +534,15 @@
                            -- there are different subdocs for different names in a single
                            -- type signature?
 
-    minimalBit = case [ s | L _ (MinimalSig _ s) <- lsigs ] of
+    minimalBit = case [ s | MinimalSig _ (L _ s) <- sigs ] of
       -- Miminal complete definition = every shown method
-      And xs : _ | sort [getName n | Var (L _ n) <- xs] ==
-                   sort [getName n | L _ (TypeSig ns _ _) <- lsigs, L _ n <- ns]
+      And xs : _ | sort [getName n | L _ (Var (L _ n)) <- xs] ==
+                   sort [getName n | TypeSig ns _ <- sigs, L _ n <- ns]
         -> noHtml
 
       -- Minimal complete definition = the only shown method
       Var (L _ n) : _ | [getName n] ==
-                        [getName n' | L _ (TypeSig ns _ _) <- lsigs, L _ n' <- ns]
+                        [getName n' | L _ (TypeSig ns _) <- lsigs, L _ n' <- ns]
         -> noHtml
 
       -- Minimal complete definition = nothing
@@ -486,36 +552,123 @@
       _ -> noHtml
 
     ppMinimal _ (Var (L _ n)) = ppDocName qual Prefix True n
-    ppMinimal _ (And fs) = foldr1 (\a b -> a+++", "+++b) $ map (ppMinimal True) fs
-    ppMinimal p (Or fs) = wrap $ foldr1 (\a b -> a+++" | "+++b) $ map (ppMinimal False) fs
+    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)
 
-    instancesBit = ppInstances links instances nm unicode qual
+    instancesBit = ppInstances links (OriginClass nm) instances
+        splice unicode qual
 
 ppClassDecl _ _ _ _ _ _ _ _ _ _ _ = error "declaration type not supported by ppShortClassDecl"
 
 
-ppInstances :: LinksInfo -> [DocInstance DocName] -> DocName -> Unicode -> Qualification -> Html
-ppInstances links instances baseName unicode qual
-  = subInstances qual instName links True (map instDecl instances)
+ppInstances :: LinksInfo
+            -> InstOrigin DocName -> [DocInstance DocName]
+            -> Splice -> Unicode -> Qualification
+            -> Html
+ppInstances links origin instances splice unicode qual
+  = subInstances qual instName links True (zipWith instDecl [1..] instances)
   -- force Splice = True to use line URLs
   where
-    instName = getOccString $ getName baseName
-    instDecl :: DocInstance DocName -> (SubDecl,Located DocName)
-    instDecl (inst, maybeDoc,l) = ((instHead inst, maybeDoc, []),l)
-    instHead (n, ks, ts, ClassInst cs) = ppContextNoLocs cs unicode qual
-        <+> ppAppNameTypes n ks ts unicode qual
-    instHead (n, ks, ts, TypeInst rhs) = keyword "type"
-        <+> ppAppNameTypes n ks ts unicode qual
-        <+> maybe noHtml (\t -> equals <+> ppType unicode qual t) rhs
-    instHead (n, ks, ts, DataInst dd) = keyword "data"
-        <+> ppAppNameTypes n ks ts unicode qual
-        <+> ppShortDataDecl False True dd unicode qual
+    instName = getOccString origin
+    instDecl :: Int -> DocInstance DocName -> (SubDecl,Located DocName)
+    instDecl no (inst, mdoc, loc) =
+        ((ppInstHead links splice unicode qual mdoc origin False no inst), loc)
 
+
+ppOrphanInstances :: LinksInfo
+                  -> [DocInstance DocName]
+                  -> Splice -> Unicode -> Qualification
+                  -> Html
+ppOrphanInstances links instances splice unicode qual
+  = subOrphanInstances qual links True (zipWith instDecl [1..] instances)
+  where
+    instOrigin :: InstHead name -> InstOrigin name
+    instOrigin inst = OriginClass (ihdClsName inst)
+
+    instDecl :: Int -> DocInstance DocName -> (SubDecl,Located DocName)
+    instDecl no (inst, mdoc, loc) =
+        ((ppInstHead links splice unicode qual mdoc (instOrigin inst) True no inst), loc)
+
+
+ppInstHead :: LinksInfo -> Splice -> Unicode -> Qualification
+           -> Maybe (MDoc DocName)
+           -> InstOrigin DocName
+           -> Bool -- ^ Is instance orphan
+           -> Int  -- ^ Normal
+           -> InstHead DocName
+           -> SubDecl
+ppInstHead links splice unicode qual mdoc origin orphan no ihd@(InstHead {..}) =
+    case ihdInstType of
+        ClassInst { .. } ->
+            ( subInstHead iid $ ppContextNoLocs clsiCtx unicode qual <+> typ
+            , mdoc
+            , [subInstDetails iid ats sigs]
+            )
+          where
+            sigs = ppInstanceSigs links splice unicode qual clsiSigs
+            ats = ppInstanceAssocTys links splice unicode qual clsiAssocTys
+        TypeInst rhs ->
+            ( subInstHead iid ptype
+            , mdoc
+            , [subFamInstDetails iid prhs]
+            )
+          where
+            ptype = keyword "type" <+> typ
+            prhs = ptype <+> maybe noHtml
+                                   (\t -> equals <+> ppType unicode qual t) rhs
+        DataInst dd ->
+            ( subInstHead iid pdata
+            , mdoc
+            , [subFamInstDetails iid pdecl])
+          where
+            pdata = keyword "data" <+> typ
+            pdecl = pdata <+> ppShortDataDecl False True dd unicode qual
+  where
+    iid = instanceId origin no orphan ihd
+    typ = ppAppNameTypes ihdClsName ihdKinds ihdTypes unicode qual
+
+
+ppInstanceAssocTys :: LinksInfo -> Splice -> Unicode -> Qualification
+                   -> [PseudoFamilyDecl DocName]
+                   -> [Html]
+ppInstanceAssocTys links splice unicode qual =
+    map ppFamilyDecl'
+  where
+    ppFamilyDecl' = ppPseudoFamilyDecl links splice unicode qual
+
+
+ppInstanceSigs :: LinksInfo -> Splice -> Unicode -> Qualification
+              -> [Sig DocName]
+              -> [Html]
+ppInstanceSigs links splice unicode qual sigs = do
+    TypeSig lnames typ <- sigs
+    let names = map unLoc lnames
+        L loc rtyp = get_type typ
+    return $ ppSimpleSig links splice unicode qual loc names rtyp
+    where
+      get_type = hswc_body . hsib_body
+
+
 lookupAnySubdoc :: Eq id1 => id1 -> [(id1, DocForDecl id2)] -> DocForDecl id2
 lookupAnySubdoc n = fromMaybe noDocForDecl . lookup n
 
 
+instanceId :: InstOrigin DocName -> Int -> Bool -> InstHead DocName -> String
+instanceId origin no orphan ihd = concat $
+    [ "o:" | orphan ] ++
+    [ qual origin
+    , ":" ++ getOccString origin
+    , ":" ++ (occNameString . getOccName . ihdClsName) ihd
+    , ":" ++ show no
+    ]
+  where
+    qual (OriginClass _) = "ic"
+    qual (OriginData _) = "id"
+    qual (OriginFamily _) = "if"
+
+
 -------------------------------------------------------------------------------
 -- * Data & newtype declarations
 -------------------------------------------------------------------------------
@@ -527,11 +680,11 @@
 
   | [] <- cons = dataHeader
 
-  | [lcon] <- cons, ResTyH98 <- resTy,
+  | [lcon] <- cons, isH98,
     (cHead,cBody,cFoot) <- ppShortConstrParts summary dataInst (unLoc lcon) unicode qual
        = (dataHeader <+> equals <+> cHead) +++ cBody +++ cFoot
 
-  | ResTyH98 <- resTy = dataHeader
+  | isH98 = dataHeader
       +++ shortSubDecls dataInst (zipWith doConstr ('=':repeat '|') cons)
 
   | otherwise = (dataHeader <+> keyword "where")
@@ -545,7 +698,9 @@
     doGADTConstr con = ppShortConstr summary (unLoc con) unicode qual
 
     cons      = dd_cons (tcdDataDefn dataDecl)
-    resTy     = (con_res . unLoc . head) cons
+    isH98     = case unLoc (head cons) of
+                  ConDeclH98 {} -> True
+                  ConDeclGADT{} -> False
 
 
 ppDataDecl :: Bool -> LinksInfo -> [DocInstance DocName] -> [(DocName, Fixity)] ->
@@ -561,7 +716,9 @@
   where
     docname   = tcdName dataDecl
     cons      = dd_cons (tcdDataDefn dataDecl)
-    resTy     = (con_res . unLoc . head) cons
+    isH98     = case unLoc (head cons) of
+                  ConDeclH98 {} -> True
+                  ConDeclGADT{} -> False
 
     header_ = topDeclElem links loc splice [docname] $
              ppDataHeader summary dataDecl unicode qual <+> whereBit <+> fix
@@ -570,18 +727,17 @@
 
     whereBit
       | null cons = noHtml
-      | otherwise = case resTy of
-        ResTyGADT _ _ -> keyword "where"
-        _ -> noHtml
+      | otherwise = if isH98 then noHtml else keyword "where"
 
     constrBit = subConstructors qual
       [ ppSideBySideConstr subdocs subfixs unicode qual c
       | c <- cons
       , let subfixs = filter (\(n,_) -> any (\cn -> cn == n)
-                                     (map unLoc (con_names (unLoc c)))) fixities
+                                     (map unLoc (getConNames (unLoc c)))) fixities
       ]
 
-    instancesBit = ppInstances links instances docname unicode qual
+    instancesBit = ppInstances links (OriginData docname) instances
+        splice unicode qual
 
 
 
@@ -594,8 +750,8 @@
 -- returns three pieces: header, body, footer so that header & footer can be
 -- incorporated into the declaration
 ppShortConstrParts :: Bool -> Bool -> ConDecl DocName -> Unicode -> Qualification -> (Html, Html, Html)
-ppShortConstrParts summary dataInst con unicode qual = case con_res con of
-  ResTyH98 -> case con_details con of
+ppShortConstrParts summary dataInst con unicode qual = case con of
+  ConDeclH98{} -> case con_details con of
     PrefixCon args ->
       (header_ unicode qual +++ hsep (ppOcc
             : map (ppLParendType unicode qual) args), noHtml, noHtml)
@@ -608,28 +764,15 @@
             ppOccInfix, 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 (L _ fields) -> (ppOcc <+> dcolon unicode <+>
-                            ppForAllCon forall_ ltvs lcontext unicode qual <+> char '{',
-                            doRecordFields fields,
-                            char '}' <+> arrow unicode <+> ppLType unicode qual resTy)
-    InfixCon arg1 arg2 -> (doGADTCon [arg1, arg2] resTy, noHtml, noHtml)
+  ConDeclGADT {} -> (ppOcc <+> dcolon unicode <+> ppLType unicode qual resTy,noHtml,noHtml)
 
   where
+    resTy = hsib_body (con_type con)
+
     doRecordFields fields = shortSubDecls dataInst (map (ppShortField summary unicode qual) (map unLoc fields))
-    doGADTCon args resTy = ppOcc <+> dcolon unicode <+> hsep [
-                             ppForAllCon forall_ ltvs lcontext unicode qual,
-                             ppLType unicode qual (foldr mkFunTy resTy args) ]
 
     header_  = ppConstrHdr forall_ tyVars context
-    occ        = map (nameOccName . getName . unLoc) $ con_names con
+    occ        = map (nameOccName . getName . unLoc) $ getConNames con
 
     ppOcc      = case occ of
       [one] -> ppBinder summary one
@@ -639,35 +782,34 @@
       [one] -> ppBinderInfix summary one
       _     -> hsep (punctuate comma (map (ppBinderInfix summary) occ))
 
-    ltvs     = con_qvars con
+    ltvs     = fromMaybe (HsQTvs PlaceHolder [] PlaceHolder) (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)
+    lcontext = fromMaybe (noLoc []) (con_cxt con)
+    context  = unLoc lcontext
+    forall_  = False
 
 
 -- ppConstrHdr is for (non-GADT) existentials constructors' syntax
-ppConstrHdr :: HsExplicitFlag -> [Name] -> HsContext DocName -> Unicode
+ppConstrHdr :: Bool -> [Name] -> HsContext DocName -> Unicode
             -> 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 " ")
+   (if null ctxt then noHtml
+    else ppContextNoArrow ctxt unicode qual
+         <+> darrow unicode +++ toHtml " ")
   where
-    ppForall = case forall_ of
-      Explicit -> forallSymbol unicode <+> hsep (map (ppName Prefix) tvs) <+> toHtml ". "
-      Qualified -> noHtml
-      Implicit -> noHtml
-
+    ppForall | forall_   = forallSymbol unicode <+> hsep (map (ppName Prefix) tvs)
+                           <+> toHtml ". "
+             | otherwise = noHtml
 
 ppSideBySideConstr :: [(DocName, DocForDecl DocName)] -> [(DocName, Fixity)]
                    -> Unicode -> Qualification -> LConDecl DocName -> SubDecl
-ppSideBySideConstr subdocs fixities unicode qual (L _ con) = (decl, mbDoc, fieldPart)
+ppSideBySideConstr subdocs fixities unicode qual (L _ con)
+ = (decl, mbDoc, fieldPart)
  where
-    decl = case con_res con of
-      ResTyH98 -> case con_details con of
+    decl = case con of
+      ConDeclH98{} -> case con_details con of
         PrefixCon args ->
           hsep ((header_ +++ ppOcc)
             : map (ppLParendType unicode qual) args)
@@ -681,28 +823,26 @@
             ppLParendType unicode qual arg2]
           <+> fixity
 
-      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
+      ConDeclGADT{} -> doGADTCon resTy
 
-    fieldPart = case con_details con of
+    resTy = hsib_body (con_type con)
+
+    fieldPart = case getConDetails con of
         RecCon (L _ fields) -> [doRecordFields fields]
         _ -> []
 
     doRecordFields fields = subFields qual
       (map (ppSideBySideField subdocs unicode qual) (map unLoc fields))
-    doGADTCon :: [LHsType DocName] -> Located (HsType DocName) -> Html
-    doGADTCon args resTy = ppOcc <+> dcolon unicode
-        <+> hsep [ppForAllCon forall_ ltvs (con_cxt con) unicode qual,
-                  ppLType unicode qual (foldr mkFunTy resTy args) ]
+
+    doGADTCon :: Located (HsType DocName) -> Html
+    doGADTCon ty = ppOcc <+> dcolon unicode
+        -- ++AZ++ make this prepend "{..}" when it is a record style GADT
+        <+> ppLType unicode qual ty
         <+> fixity
 
     fixity  = ppFixities fixities qual
     header_ = ppConstrHdr forall_ tyVars context unicode qual
-    occ       = map (nameOccName . getName . unLoc) $ con_names con
+    occ       = map (nameOccName . getName . unLoc) $ getConNames con
 
     ppOcc     = case occ of
       [one] -> ppBinder False one
@@ -712,32 +852,30 @@
       [one] -> ppBinderInfix False one
       _     -> hsep (punctuate comma (map (ppBinderInfix False) occ))
 
-    ltvs    = con_qvars con
-    tyVars  = tyvarNames (con_qvars con)
-    context = unLoc (con_cxt con)
-    forall_ = con_explicit con
+    tyVars  = tyvarNames (fromMaybe (HsQTvs PlaceHolder [] PlaceHolder) (con_qvars con))
+    context = unLoc (fromMaybe (noLoc []) (con_cxt con))
+    forall_ = False
     -- 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 (unLoc $ head $ con_names con) subdocs >>=
+    mbDoc = lookup (unLoc $ head $ getConNames con) subdocs >>=
             combineDocumentation . fst
-    mkFunTy a b = noLoc (HsFunTy a b)
 
 
 ppSideBySideField :: [(DocName, DocForDecl DocName)] -> Unicode -> Qualification
                   -> ConDeclField DocName -> SubDecl
 ppSideBySideField subdocs unicode qual (ConDeclField names ltype _) =
-  (hsep (punctuate comma (map ((ppBinder False) . nameOccName . getName . unL) names)) <+> dcolon unicode <+> ppLType unicode qual ltype,
+  (hsep (punctuate comma (map ((ppBinder False) . rdrNameOcc . unLoc . rdrNameFieldOcc . unLoc) names)) <+> dcolon unicode <+> ppLType unicode qual 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 (unL $ head names) subdocs >>= combineDocumentation . fst
+    mbDoc = lookup (selectorFieldOcc $ unLoc $ head names) subdocs >>= combineDocumentation . fst
 
 
 ppShortField :: Bool -> Unicode -> Qualification -> ConDeclField DocName -> Html
 ppShortField summary unicode qual (ConDeclField names ltype _)
-  = hsep (punctuate comma (map ((ppBinder summary) . nameOccName . getName . unL) names))
+  = hsep (punctuate comma (map ((ppBinder summary) . rdrNameOcc . unLoc . rdrNameFieldOcc . unLoc) names))
     <+> dcolon unicode <+> ppLType unicode qual ltype
 
 
@@ -767,10 +905,10 @@
 --------------------------------------------------------------------------------
 
 
-ppBang :: HsBang -> Html
-ppBang HsNoBang = noHtml
-ppBang _        = toHtml "!" -- Unpacked args is an implementation detail,
-                             -- so we just show the strictness annotation
+ppBang :: HsSrcBang -> Html
+ppBang (HsSrcBang _ _ SrcStrict) = toHtml "!"
+ppBang (HsSrcBang _ _ SrcLazy)   = toHtml "~"
+ppBang _                         = noHtml
 
 
 tupleParens :: HsTupleSort -> [Html] -> Html
@@ -816,52 +954,42 @@
 ppParendType unicode qual ty = ppr_mono_ty pREC_CON ty unicode qual
 ppFunLhType  unicode qual ty = ppr_mono_ty pREC_FUN ty unicode qual
 
+ppHsTyVarBndr :: Unicode -> Qualification -> HsTyVarBndr DocName -> Html
+ppHsTyVarBndr _       qual (UserTyVar (L _ name)) =
+    ppDocName qual Raw False name
+ppHsTyVarBndr unicode qual (KindedTyVar name kind) =
+    parens (ppDocName qual Raw False (unLoc name) <+> dcolon unicode <+>
+            ppLKind unicode qual kind)
+
 ppLKind :: Unicode -> Qualification -> LHsKind DocName -> Html
 ppLKind unicode qual y = ppKind unicode qual (unLoc y)
 
 ppKind :: Unicode -> Qualification -> HsKind DocName -> Html
 ppKind unicode qual ki = ppr_mono_ty pREC_TOP ki unicode qual
 
--- Drop top-level for-all type variables in user style
--- since they are implicit in Haskell
-
-ppForAllCon :: HsExplicitFlag -> LHsTyVarBndrs DocName
-         -> Located (HsContext DocName) -> Unicode -> Qualification -> Html
-ppForAllCon expl tvs cxt unicode qual =
-  forall_part <+> ppLContext cxt unicode qual
-  where
-    forall_part = ppLTyVarBndrs expl tvs unicode qual
-
-ppLTyVarBndrs :: HsExplicitFlag -> LHsTyVarBndrs DocName
-              -> Unicode -> Qualification
-              -> Html
-ppLTyVarBndrs expl tvs unicode _qual
-  | show_forall = hsep (forallSymbol unicode : ppTyVars tvs) +++ dot
-  | otherwise   = noHtml
-  where
-    show_forall = not (null (hsQTvBndrs tvs)) && is_explicit
-    is_explicit = case expl of {Explicit -> True; Implicit -> False; Qualified -> False}
-
+ppForAllPart :: [LHsTyVarBndr DocName] -> Unicode -> Html
+ppForAllPart tvs unicode = hsep (forallSymbol unicode : ppTyVars tvs) +++ dot
 
 ppr_mono_lty :: Int -> LHsType DocName -> Unicode -> Qualification -> Html
 ppr_mono_lty ctxt_prec ty = ppr_mono_ty ctxt_prec (unLoc ty)
 
 
 ppr_mono_ty :: Int -> HsType DocName -> Unicode -> Qualification -> Html
-ppr_mono_ty ctxt_prec (HsForAllTy expl extra tvs ctxt ty) unicode qual
-  = maybeParen ctxt_prec pREC_FUN $ ppForAllCon expl tvs ctxt' unicode qual
-                                    <+> ppr_mono_lty pREC_TOP ty unicode qual
- where ctxt' = case extra of
-                 Just loc -> (++ [L loc HsWildcardTy]) `fmap` ctxt
-                 Nothing  -> ctxt
+ppr_mono_ty ctxt_prec (HsForAllTy tvs ty) unicode qual
+  = maybeParen ctxt_prec pREC_FUN $
+    ppForAllPart tvs unicode <+> ppr_mono_lty pREC_TOP ty unicode qual
 
+ppr_mono_ty ctxt_prec (HsQualTy ctxt ty) unicode qual
+  = maybeParen ctxt_prec pREC_FUN $
+    ppLContext ctxt unicode qual <+> ppr_mono_lty pREC_TOP ty unicode qual
+
 -- UnicodeSyntax alternatives
-ppr_mono_ty _ (HsTyVar name) True _
+ppr_mono_ty _ (HsTyVar (L _ name)) True _
   | getOccString (getName name) == "*"    = toHtml "★"
   | getOccString (getName name) == "(->)" = toHtml "(→)"
 
 ppr_mono_ty _         (HsBangTy b ty)     u q = ppBang b +++ ppLParendType u q ty
-ppr_mono_ty _         (HsTyVar name)      _ q = ppDocName q Prefix True name
+ppr_mono_ty _         (HsTyVar (L _ name)) _ q = ppDocName q Prefix True 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 =
@@ -871,12 +999,14 @@
 ppr_mono_ty ctxt_prec (HsIParamTy n ty)   u q =
     maybeParen ctxt_prec pREC_CTX $ ppIPName n <+> dcolon u <+> ppr_mono_lty pREC_TOP ty u q
 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 _         (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 _         (HsCoreTy {})       _ _ = error "ppr_mono_ty HsCoreTy"
-ppr_mono_ty _         (HsExplicitListTy _ tys) u q = quote $ brackets $ hsep $ punctuate comma $ map (ppLType u q) tys
-ppr_mono_ty _         (HsExplicitTupleTy _ tys) u q = quote $ parenList $ map (ppLType u q) tys
-ppr_mono_ty _         (HsWrapTy {})       _ _ = error "ppr_mono_ty HsWrapTy"
+ppr_mono_ty _         (HsExplicitListTy _ tys) u q = promoQuote $ brackets $ hsep $ punctuate comma $ map (ppLType u q) tys
+ppr_mono_ty _         (HsExplicitTupleTy _ tys) u q = promoQuote $ parenList $ map (ppLType u q) tys
+ppr_mono_ty _         (HsAppsTy {})       _ _ = error "ppr_mono_ty HsAppsTy"
 
 ppr_mono_ty ctxt_prec (HsEqTy ty1 ty2) unicode qual
   = maybeParen ctxt_prec pREC_CTX $
@@ -886,11 +1016,16 @@
   = 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
+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 = ppLDocName qual Infix op
+    -- `(:)` is valid in type signature only as constructor to promoted list
+    -- and needs to be quoted in code so we explicitly quote it here too.
+    ppr_op
+        | (getOccString . getName . unLoc) op == ":" = promoQuote ppr_op'
+        | otherwise = ppr_op'
+    ppr_op' = ppLDocName qual Infix op
 
 ppr_mono_ty ctxt_prec (HsParTy ty) unicode qual
 --  = parens (ppr_mono_lty pREC_TOP ty)
@@ -899,10 +1034,7 @@
 ppr_mono_ty ctxt_prec (HsDocTy ty _) unicode qual
   = ppr_mono_lty ctxt_prec ty unicode qual
 
-ppr_mono_ty _ HsWildcardTy _ _ = char '_'
-
-ppr_mono_ty _ (HsNamedWildcardTy name) _ q = ppDocName q Prefix True name
-
+ppr_mono_ty _ (HsWildCardTy (AnonWildCard _)) _ _ = char '_'
 ppr_mono_ty _ (HsTyLit n) _ _ = ppr_tylit n
 
 ppr_tylit :: HsTyLit -> Html
diff --git a/haddock-api/src/Haddock/Backends/Xhtml/DocMarkup.hs b/haddock-api/src/Haddock/Backends/Xhtml/DocMarkup.hs
--- a/haddock-api/src/Haddock/Backends/Xhtml/DocMarkup.hs
+++ b/haddock-api/src/Haddock/Backends/Xhtml/DocMarkup.hs
@@ -33,6 +33,7 @@
 import GHC
 import Name
 
+
 parHtmlMarkup :: Qualification -> Bool
               -> (Bool -> a -> Html) -> DocMarkup a Html
 parHtmlMarkup qual insertAnchors ppId = Markup {
@@ -67,6 +68,8 @@
                                   then namedAnchor aname << ""
                                   else noHtml,
   markupPic                  = \(Picture uri t) -> image ! ([src uri] ++ fromMaybe [] (return . title <$> t)),
+  markupMathInline           = \mathjax -> toHtml ("\\(" ++ mathjax ++ "\\)"),
+  markupMathDisplay          = \mathjax -> toHtml ("\\[" ++ mathjax ++ "\\]"),
   markupProperty             = pre . toHtml,
   markupExample              = examplesToHtml,
   markupHeader               = \(Header l t) -> makeHeader l t
@@ -161,8 +164,9 @@
       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_ True "caption"
-            instTable = (thediv ! collapseSection id_ False [] <<)
+            expanded = False
+            col' = collapseControl id_ expanded "caption"
+            instTable = (thediv ! collapseSection id_ expanded [] <<)
             lvs = zip [1 .. ] [h1, h2, h3, h4, h5, h6]
             getHeader = fromMaybe caption (lookup lvl lvs)
             subCaption = getHeader ! col' << markup fmt titl
diff --git a/haddock-api/src/Haddock/Backends/Xhtml/Layout.hs b/haddock-api/src/Haddock/Backends/Xhtml/Layout.hs
--- a/haddock-api/src/Haddock/Backends/Xhtml/Layout.hs
+++ b/haddock-api/src/Haddock/Backends/Xhtml/Layout.hs
@@ -14,7 +14,7 @@
   miniBody,
 
   divPackageHeader, divContent, divModuleHeader, divFooter,
-  divTableOfContents, divDescription, divSynposis, divInterface,
+  divTableOfContents, divDescription, divSynopsis, divInterface,
   divIndex, divAlphabet, divModuleList,
 
   sectionName,
@@ -31,7 +31,8 @@
   subConstructors,
   subEquations,
   subFields,
-  subInstances,
+  subInstances, subOrphanInstances,
+  subInstHead, subInstDetails, subFamInstDetails,
   subMethods,
   subMinimal,
 
@@ -43,12 +44,13 @@
 import Haddock.Backends.Xhtml.Types
 import Haddock.Backends.Xhtml.Utils
 import Haddock.Types
-import Haddock.Utils (makeAnchorId)
+import Haddock.Utils (makeAnchorId, nameAnchorId)
 import qualified Data.Map as Map
 import Text.XHtml hiding ( name, title, p, quote )
 
 import FastString            ( unpackFS )
 import GHC
+import Name (nameOccName)
 
 --------------------------------------------------------------------------------
 -- * Sections of the document
@@ -76,7 +78,7 @@
 
 
 divPackageHeader, divContent, divModuleHeader, divFooter,
-  divTableOfContents, divDescription, divSynposis, divInterface,
+  divTableOfContents, divDescription, divSynopsis, divInterface,
   divIndex, divAlphabet, divModuleList
     :: Html -> Html
 
@@ -86,7 +88,7 @@
 divFooter           = sectionDiv "footer"
 divTableOfContents  = sectionDiv "table-of-contents"
 divDescription      = sectionDiv "description"
-divSynposis         = sectionDiv "synopsis"
+divSynopsis         = sectionDiv "synopsis"
 divInterface        = sectionDiv "interface"
 divIndex            = sectionDiv "index"
 divAlphabet         = sectionDiv "alphabet"
@@ -127,14 +129,12 @@
 
 subDlist :: Qualification -> [SubDecl] -> Maybe Html
 subDlist _ [] = Nothing
-subDlist qual decls = Just $ dlist << map subEntry decls +++ clearDiv
+subDlist qual decls = Just $ ulist << map subEntry decls
   where
     subEntry (decl, mdoc, subs) =
-      dterm ! [theclass "src"] << decl
-      +++
-      docElement ddef << (fmap (docToHtml Nothing qual) mdoc +++ subs)
-
-    clearDiv = thediv ! [ theclass "clear" ] << noHtml
+      li <<
+        (define ! [theclass "src"] << decl +++
+         docElement thediv << (fmap (docToHtml Nothing qual) mdoc +++ subs))
 
 
 subTable :: Qualification -> [SubDecl] -> Maybe Html
@@ -180,7 +180,6 @@
 subConstructors :: Qualification -> [SubDecl] -> Html
 subConstructors qual = divSubDecls "constructors" "Constructors" . subTable qual
 
-
 subFields :: Qualification -> [SubDecl] -> Html
 subFields qual = divSubDecls "fields" "Fields" . subDlist qual
 
@@ -202,6 +201,48 @@
     subCaption = paragraph ! collapseControl id_ True "caption" << "Instances"
     id_ = makeAnchorId $ "i:" ++ nm
 
+
+subOrphanInstances :: Qualification
+                   -> LinksInfo -> Bool
+                   -> [(SubDecl,Located DocName)] -> Html
+subOrphanInstances qual lnks splice  = maybe noHtml wrap . instTable
+  where
+    wrap = ((h1 << "Orphan instances") +++)
+    instTable = fmap (thediv ! collapseSection id_ True [] <<) . subTableSrc 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) False "instance"
+
+
+subInstDetails :: String -- ^ Instance unique id (for anchor generation)
+               -> [Html] -- ^ Associated type contents
+               -> [Html] -- ^ Method contents (pretty-printed signatures)
+               -> Html
+subInstDetails iid ats mets =
+    subInstSection iid << (subAssociatedTypes ats <+> subMethods mets)
+
+subFamInstDetails :: String -- ^ Instance unique id (for anchor generation)
+                  -> Html   -- ^ Type or data family instance
+                  -> Html
+subFamInstDetails iid fi =
+    subInstSection iid << thediv ! [theclass "src"] << fi
+
+subInstSection :: String -- ^ Instance unique id (for anchor generation)
+               -> Html
+               -> Html
+subInstSection iid = thediv ! collapseSection (instAnchorId iid) False "inst-details"
+
+instAnchorId :: String -> String
+instAnchorId iid = makeAnchorId $ "i:" ++ iid
+
+
 subMethods :: [Html] -> Html
 subMethods = divSubDecls "methods" "Methods" . subBlock
 
@@ -224,9 +265,11 @@
 -- | 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 -> DocName -> Html
-links ((_,_,sourceMap,lineMap), (_,_,maybe_wiki_url)) loc splice (Documented n mdl) =
-   (srcLink <+> wikiLink)
-  where srcLink = let nameUrl = Map.lookup origPkg sourceMap
+links ((_,_,sourceMap,lineMap), (_,_,maybe_wiki_url)) loc splice 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
@@ -249,7 +292,7 @@
         -- TODO: do something about type instances. They will point to
         -- the module defining the type family, which is wrong.
         origMod = nameModule n
-        origPkg = modulePackageKey origMod
+        origPkg = moduleUnitId origMod
 
         fname = case loc of
           RealSrcSpan l -> unpackFS (srcSpanFile l)
diff --git a/haddock-api/src/Haddock/Backends/Xhtml/Names.hs b/haddock-api/src/Haddock/Backends/Xhtml/Names.hs
--- a/haddock-api/src/Haddock/Backends/Xhtml/Names.hs
+++ b/haddock-api/src/Haddock/Backends/Xhtml/Names.hs
@@ -110,16 +110,21 @@
 
 
 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' Prefix n
-ppBinder False n = namedAnchor (nameAnchorId n) ! [theclass "def"]
-                        << ppBinder' Prefix n
+ppBinder = ppBinderWith Prefix
 
 ppBinderInfix :: Bool -> OccName -> Html
-ppBinderInfix True n = linkedAnchor (nameAnchorId n) << ppBinder' Infix n
-ppBinderInfix False n = namedAnchor (nameAnchorId n) ! [theclass "def"]
-                             << ppBinder' Infix n
+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
diff --git a/haddock-api/src/Haddock/Backends/Xhtml/Types.hs b/haddock-api/src/Haddock/Backends/Xhtml/Types.hs
--- a/haddock-api/src/Haddock/Backends/Xhtml/Types.hs
+++ b/haddock-api/src/Haddock/Backends/Xhtml/Types.hs
@@ -23,7 +23,7 @@
 
 
 -- the base, module and entity URLs for the source code and wiki links.
-type SourceURLs = (Maybe FilePath, Maybe FilePath, Map PackageKey FilePath, Map PackageKey FilePath)
+type SourceURLs = (Maybe FilePath, Maybe FilePath, Map UnitId FilePath, Map UnitId FilePath)
 type WikiURLs = (Maybe FilePath, Maybe FilePath, Maybe FilePath)
 
 
diff --git a/haddock-api/src/Haddock/Backends/Xhtml/Utils.hs b/haddock-api/src/Haddock/Backends/Xhtml/Utils.hs
--- a/haddock-api/src/Haddock/Backends/Xhtml/Utils.hs
+++ b/haddock-api/src/Haddock/Backends/Xhtml/Utils.hs
@@ -14,14 +14,14 @@
   renderToString,
 
   namedAnchor, linkedAnchor,
-  spliceURL,
+  spliceURL, spliceURL',
   groupId,
 
   (<+>), (<=>), char,
   keyword, punctuate,
 
   braces, brackets, pabrackets, parens, parenList, ubxParenList,
-  arrow, comma, dcolon, dot, darrow, equals, forallSymbol, quote,
+  arrow, comma, dcolon, dot, darrow, equals, forallSymbol, quote, promoQuote,
 
   hsep, vcat,
 
@@ -29,7 +29,6 @@
 ) where
 
 
-import Haddock.GhcUtils
 import Haddock.Utils
 
 import Data.Maybe
@@ -38,18 +37,31 @@
 import qualified Text.XHtml as XHtml
 
 import GHC      ( SrcSpan(..), srcSpanStartLine, Name )
-import Module   ( Module )
+import Module   ( Module, ModuleName, moduleName, moduleNameString )
 import 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 maybe_file maybe_mod maybe_name maybe_loc = run
+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 -> moduleString m
+          Just m -> moduleNameString m
 
   (name, kind) =
     case maybe_name of
@@ -138,6 +150,11 @@
 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 ']'
@@ -178,7 +195,7 @@
 
 -- | Generate a named anchor
 namedAnchor :: String -> Html -> Html
-namedAnchor n = anchor ! [XHtml.name n]
+namedAnchor n = anchor ! [XHtml.identifier n]
 
 
 linkedAnchor :: String -> Html -> Html
@@ -203,7 +220,7 @@
 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]
diff --git a/haddock-api/src/Haddock/Convert.hs b/haddock-api/src/Haddock/Convert.hs
--- a/haddock-api/src/Haddock/Convert.hs
+++ b/haddock-api/src/Haddock/Convert.hs
@@ -1,3 +1,4 @@
+
 {-# LANGUAGE CPP, PatternGuards #-}
 -----------------------------------------------------------------------------
 -- |
@@ -22,27 +23,31 @@
 import CoAxiom
 import ConLike
 import Data.Either (lefts, rights)
-import Data.List( partition )
 import DataCon
 import FamInstEnv
-import Haddock.Types
 import HsSyn
-import Kind ( splitKindFunTys, synTyConResKind, isKind )
 import Name
+import NameSet ( emptyNameSet )
+import RdrName ( mkVarUnqual )
 import PatSyn
-import PrelNames (ipClassName)
-import SrcLoc ( Located, noLoc, unLoc, noSrcSpan )
+import SrcLoc ( Located, noLoc, unLoc )
 import TcType ( tcSplitSigmaTy )
 import TyCon
-import Type (isStrLitTy, mkFunTys)
-import TypeRep
-import TysPrim ( alphaTyVars )
-import TysWiredIn ( listTyConName, eqTyCon )
+import Type
+import TyCoRep
+import TysPrim ( alphaTyVars, unliftedTypeKindTyConName )
+import TysWiredIn ( listTyConName, starKindTyConName, unitTy )
+import PrelNames ( hasKey, eqTyConKey, ipClassKey
+                 , tYPETyConKey, ptrRepLiftedDataConKey, ptrRepUnliftedDataConKey )
 import Unique ( getUnique )
+import Util ( filterByList, filterOut )
 import Var
 
+import Haddock.Types
+import Haddock.Interface.Specialize
 
 
+
 -- the main function here! yay!
 tyThingToLHsDecl :: TyThing -> Either ErrMsg ([ErrMsg], (HsDecl Name))
 tyThingToLHsDecl t = case t of
@@ -76,7 +81,7 @@
          , tcdFDs = map (\ (l,r) -> noLoc
                         (map (noLoc . getName) l, map (noLoc . getName) r) ) $
                          snd $ classTvsFds cl
-         , tcdSigs = noLoc (MinimalSig mempty . fmap noLoc $ classMinimalDef cl) :
+         , tcdSigs = noLoc (MinimalSig mempty . noLoc . fmap noLoc $ classMinimalDef cl) :
                       map (noLoc . synifyIdSig DeleteTopLevelQuantification)
                         (classMethods cl)
          , tcdMeths = emptyBag --ignore default method definitions, they don't affect signature
@@ -94,17 +99,10 @@
 
   -- a data-constructor alone just gets rendered as a function:
   AConLike (RealDataCon dc) -> allOK $ SigD (TypeSig [synifyName dc]
-    (synifyType ImplicitizeForAll (dataConUserType dc)) [])
+    (synifySigWcType ImplicitizeForAll (dataConUserType dc)))
 
   AConLike (PatSynCon ps) ->
-      let (univ_tvs, ex_tvs, req_theta, prov_theta, arg_tys, res_ty) = patSynSig ps
-          qtvs = univ_tvs ++ ex_tvs
-          ty = mkFunTys arg_tys res_ty
-      in allOK . SigD $ PatSynSig (synifyName ps)
-                          (Implicit, synifyTyVars qtvs)
-                          (synifyCtx req_theta)
-                          (synifyCtx prov_theta)
-                          (synifyType WithinType ty)
+    allOK . SigD $ PatSynSig (synifyName ps) (synifyPatSynSigType ps)
   where
     withErrs e x = return (e, x)
     allOK x = return (mempty, x)
@@ -114,12 +112,9 @@
   = let name       = synifyName tc
         typats     = map (synifyType WithinType) args
         hs_rhs     = synifyType WithinType rhs
-        (kvs, tvs) = partition isKindVar tkvs
     in TyFamEqn { tfe_tycon = name
-                , tfe_pats  = HsWB { hswb_cts = typats
-                                    , hswb_kvs = map tyVarName kvs
-                                    , hswb_tvs = map tyVarName tvs
-                                    , hswb_wcs = [] }
+                , tfe_pats  = HsIB { hsib_body = typats
+                                   , hsib_vars = map tyVarName tkvs }
                 , tfe_rhs   = hs_rhs }
 
 synifyAxiom :: CoAxiom br -> Either ErrMsg (HsDecl Name)
@@ -130,7 +125,7 @@
                     (TyFamInstDecl { tfid_eqn = noLoc $ synifyAxBranch tc branch
                                    , tfid_fvs = placeHolderNamesTc }))
 
-  | Just ax' <- isClosedSynFamilyTyCon_maybe tc
+  | Just ax' <- isClosedSynFamilyTyConWithAxiom_maybe tc
   , getUnique ax' == getUnique ax   -- without the getUniques, type error
   = synifyTyCon (Just ax) tc >>= return . TyClD
 
@@ -139,7 +134,7 @@
 
 -- | Turn type constructors into type class declarations
 synifyTyCon :: Maybe (CoAxiom br) -> TyCon -> Either ErrMsg (TyClDecl Name)
-synifyTyCon coax tc
+synifyTyCon _coax tc
   | isFunTyCon tc || isPrimTyCon tc
   = return $
     DataDecl { tcdLName = synifyName tc
@@ -147,10 +142,10 @@
                          let mk_hs_tv realKind fakeTyVar
                                 = noLoc $ KindedTyVar (noLoc (getName fakeTyVar))
                                                       (synifyKindSig realKind)
-                         in HsQTvs { hsq_kvs = []   -- No kind polymorphism
-                                   , hsq_tvs = zipWith mk_hs_tv (fst (splitKindFunTys (tyConKind tc)))
+                         in HsQTvs { hsq_implicit = []   -- No kind polymorphism
+                                   , hsq_explicit = zipWith mk_hs_tv (fst (splitFunTys (tyConKind tc)))
                                                                 alphaTyVars --a, b, c... which are unfortunately all kind *
-                                   }
+                                   , hsq_dependent = emptyNameSet }
 
            , tcdDataDefn = HsDataDefn { dd_ND = DataType  -- arbitrary lie, they are neither
                                                     -- algebraic data nor newtype:
@@ -160,35 +155,40 @@
                                                -- we have their kind accurately:
                                       , dd_cons = []  -- No constructors
                                       , dd_derivs = Nothing }
+           , tcdDataCusk = False
            , tcdFVs = placeHolderNamesTc }
 
-  | isTypeFamilyTyCon tc
-  = case famTyConFlav_maybe tc of
-      Just rhs ->
-        let info = case rhs of
-              OpenSynFamilyTyCon -> return OpenTypeFamily
-              ClosedSynFamilyTyCon (CoAxiom { co_ax_branches = branches }) ->
-                return $ ClosedTypeFamily
-                  (brListMap (noLoc . synifyAxBranch tc) branches)
-              BuiltInSynFamTyCon {} -> return $ ClosedTypeFamily []
-              AbstractClosedSynFamilyTyCon {} -> return $ ClosedTypeFamily []
-        in info >>= \i ->
-           return (FamDecl
-                   (FamilyDecl { fdInfo = i
-                               , fdLName = synifyName tc
-                               , fdTyVars = synifyTyVars (tyConTyVars tc)
-                               , fdKindSig =
-                                 Just (synifyKindSig (synTyConResKind tc))
-                               }))
-      Nothing -> Left "synifyTyCon: impossible open type synonym?"
+synifyTyCon _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 (noLoc . synifyAxBranch tc) (fromBranches branches)
+        | otherwise
+          -> mkFamDecl $ ClosedTypeFamily $ Just []
+      BuiltInSynFamTyCon {}
+        -> mkFamDecl $ ClosedTypeFamily $ Just []
+      AbstractClosedSynFamilyTyCon {}
+        -> mkFamDecl $ ClosedTypeFamily Nothing
+      DataFamilyTyCon {}
+        -> mkFamDecl DataFamily
+  where
+    resultVar = famTcResVar tc
+    mkFamDecl i = return $ FamDecl $
+      FamilyDecl { fdInfo = i
+                 , fdLName = synifyName tc
+                 , fdTyVars = synifyTyVars (tyConTyVars tc)
+                 , fdResultSig =
+                       synifyFamilyResultSig resultVar (tyConResKind tc)
+                 , fdInjectivityAnn =
+                       synifyInjectivityAnn  resultVar (tyConTyVars tc)
+                                       (familyTyConInjectivityInfo tc)
+                 }
 
-  | isDataFamilyTyCon tc
-  = --(why no "isOpenAlgTyCon"?)
-    case algTyConRhs tc of
-        DataFamilyTyCon -> return $
-          FamDecl (FamilyDecl DataFamily (synifyName tc) (synifyTyVars (tyConTyVars tc))
-                              Nothing) --always kind '*'
-        _ -> Left "synifyTyCon: impossible open data type?"
+synifyTyCon coax tc
   | Just ty <- synTyConRhs_maybe tc
   = return $ SynDecl { tcdLName = synifyName tc
                      , tcdTyVars = synifyTyVars (tyConTyVars tc)
@@ -235,9 +235,23 @@
  in case lefts consRaw of
   [] -> return $
         DataDecl { tcdLName = name, tcdTyVars = tyvars, tcdDataDefn = defn
-                 , tcdFVs = placeHolderNamesTc }
+                 , tcdDataCusk = False, tcdFVs = placeHolderNamesTc }
   dataConErrs -> Left $ unlines dataConErrs
 
+synifyInjectivityAnn :: Maybe Name -> [TyVar] -> Injectivity
+                     -> Maybe (LInjectivityAnn Name)
+synifyInjectivityAnn Nothing _ _            = Nothing
+synifyInjectivityAnn _       _ NotInjective = Nothing
+synifyInjectivityAnn (Just lhs) tvs (Injective inj) =
+    let rhs = map (noLoc . tyVarName) (filterByList inj tvs)
+    in Just $ noLoc $ InjectivityAnn (noLoc lhs) rhs
+
+synifyFamilyResultSig :: Maybe Name -> Kind -> LFamilyResultSig Name
+synifyFamilyResultSig  Nothing    kind =
+   noLoc $ KindSig  (synifyKindSig kind)
+synifyFamilyResultSig (Just name) kind =
+   noLoc $ TyVarSig (noLoc $ KindedTyVar (noLoc 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.
@@ -261,21 +275,18 @@
   -- skip any EqTheta, use 'orig'inal syntax
   ctx = synifyCtx theta
 
-  linear_tys = zipWith (\ty bang ->
-            let tySyn = synifyType WithinType ty
-                src_bang = case bang of
-                             HsUnpack {} -> HsSrcBang Nothing (Just True) True
-                             HsStrict    -> HsSrcBang Nothing (Just False) True
-                             _           -> bang
-            in case src_bang of
-                 HsNoBang -> tySyn
-                 _        -> noLoc $ HsBangTy bang tySyn
-            -- HsNoBang never appears, it's implied instead.
-          )
-          arg_tys (dataConSrcBangs dc)
-  field_tys = zipWith (\field synTy -> noLoc $ ConDeclField
-                                               [synifyName field] synTy Nothing)
-                (dataConFieldLabels dc) linear_tys
+  linear_tys =
+    zipWith (\ty bang ->
+               let tySyn = synifyType WithinType ty
+               in case bang of
+                    (HsSrcBang _ NoSrcUnpack NoSrcStrict) -> tySyn
+                    bang' -> noLoc $ HsBangTy bang' tySyn)
+            arg_tys (dataConSrcBangs dc)
+
+  field_tys = zipWith con_decl_field (dataConFieldLabels dc) linear_tys
+  con_decl_field fl synTy = noLoc $
+    ConDeclField [noLoc $ FieldOcc (noLoc $ mkVarUnqual $ flLabel fl) (flSelector fl)] synTy
+                 Nothing
   hs_arg_tys = case (use_named_field_syntax, use_infix_syntax) of
           (True,True) -> Left "synifyDataCon: contradiction!"
           (True,False) -> return $ RecCon (noLoc field_tys)
@@ -283,39 +294,46 @@
           (False,True) -> case linear_tys of
                            [a,b] -> return $ InfixCon a b
                            _ -> Left "synifyDataCon: infix with non-2 args?"
-  hs_res_ty = if use_gadt_syntax
-              then ResTyGADT noSrcSpan (synifyType WithinType res_ty)
-              else ResTyH98
+  gadt_ty = HsIB [] (synifyType WithinType res_ty)
  -- finally we get synifyDataCon's result!
  in hs_arg_tys >>=
-      \hat -> return . noLoc $ ConDecl [name] Implicit -- we don't know nor care
-                qvars ctx hat hs_res_ty Nothing
-                -- we don't want any "deprecated GADT syntax" warnings!
-                False
+      \hat ->
+        if use_gadt_syntax
+           then return $ noLoc $
+              ConDeclGADT { con_names = [name]
+                          , con_type = gadt_ty
+                          , con_doc =  Nothing }
+           else return $ noLoc $
+              ConDeclH98 { con_name = name
+                         , con_qvars = Just qvars
+                         , con_cxt   = Just ctx
+                         , con_details =  hat
+                         , con_doc =  Nothing }
 
 synifyName :: NamedThing n => n -> Located Name
 synifyName = noLoc . getName
 
 
 synifyIdSig :: SynifyTypeState -> Id -> Sig Name
-synifyIdSig s i = TypeSig [synifyName i] (synifyType s (varType i)) []
+synifyIdSig s i = TypeSig [synifyName i] (synifySigWcType s (varType i))
 
 
 synifyCtx :: [PredType] -> LHsContext Name
 synifyCtx = noLoc . map (synifyType WithinType)
 
 
-synifyTyVars :: [TyVar] -> LHsTyVarBndrs Name
-synifyTyVars ktvs = HsQTvs { hsq_kvs = map tyVarName kvs
-                           , hsq_tvs = map synifyTyVar tvs }
+synifyTyVars :: [TyVar] -> LHsQTyVars Name
+synifyTyVars ktvs = HsQTvs { hsq_implicit = []
+                           , hsq_explicit = map synifyTyVar ktvs
+                           , hsq_dependent = emptyNameSet }
+
+synifyTyVar :: TyVar -> LHsTyVarBndr Name
+synifyTyVar tv
+  | isLiftedTypeKind kind = noLoc (UserTyVar (noLoc name))
+  | otherwise             = noLoc (KindedTyVar (noLoc name) (synifyKindSig kind))
   where
-    (kvs, tvs) = partition isKindVar ktvs
-    synifyTyVar tv
-      | isLiftedTypeKind kind = noLoc (UserTyVar name)
-      | otherwise             = noLoc (KindedTyVar (noLoc name) (synifyKindSig kind))
-      where
-        kind = tyVarKind tv
-        name = getName tv
+    kind = tyVarKind tv
+    name = getName tv
 
 --states of what to do with foralls:
 data SynifyTypeState
@@ -333,12 +351,35 @@
   --   the defining class gets to quantify all its functions for free!
 
 
+synifySigType :: SynifyTypeState -> Type -> LHsSigType Name
+-- The empty binders is a bit suspicious;
+-- what if the type has free variables?
+synifySigType s ty = mkEmptyImplicitBndrs (synifyType s ty)
+
+synifySigWcType :: SynifyTypeState -> Type -> LHsSigWcType Name
+-- Ditto (see synifySigType)
+synifySigWcType s ty = mkEmptyImplicitBndrs (mkEmptyWildCardBndrs (synifyType s ty))
+
+synifyPatSynSigType :: PatSyn -> LHsSigType Name
+-- Ditto (see synifySigType)
+synifyPatSynSigType ps = mkEmptyImplicitBndrs (synifyPatSynType ps)
+
 synifyType :: SynifyTypeState -> Type -> LHsType Name
-synifyType _ (TyVarTy tv) = noLoc $ HsTyVar (getName tv)
+synifyType _ (TyVarTy tv) = noLoc $ HsTyVar $ noLoc (getName tv)
 synifyType _ (TyConApp tc tys)
+  -- Use */# instead of TYPE 'Lifted/TYPE 'Unlifted (#473)
+  | tc `hasKey` tYPETyConKey
+  , [TyConApp lev []] <- tys
+  , lev `hasKey` ptrRepLiftedDataConKey
+  = noLoc (HsTyVar (noLoc starKindTyConName))
+  | tc `hasKey` tYPETyConKey
+  , [TyConApp lev []] <- tys
+  , lev `hasKey` ptrRepUnliftedDataConKey
+  = noLoc (HsTyVar (noLoc unliftedTypeKindTyConName))
   -- Use non-prefix tuple syntax where possible, because it looks nicer.
-  | isTupleTyCon tc, tyConArity tc == length tys =
-     noLoc $ HsTupleTy (case tupleTyConSort tc of
+  | Just sort <- tyConTuple_maybe tc
+  , tyConArity tc == length tys
+  = noLoc $ HsTupleTy (case sort of
                           BoxedTuple      -> HsBoxedTuple
                           ConstraintTuple -> HsConstraintTuple
                           UnboxedTuple    -> HsUnboxedTuple)
@@ -347,41 +388,59 @@
   | getName tc == listTyConName, [ty] <- tys =
      noLoc $ HsListTy (synifyType WithinType ty)
   -- ditto for implicit parameter tycons
-  | tyConName tc == ipClassName
+  | tc `hasKey` ipClassKey
   , [name, ty] <- tys
   , Just x <- isStrLitTy name
   = noLoc $ HsIParamTy (HsIPName x) (synifyType WithinType ty)
   -- and equalities
-  | tc == eqTyCon
+  | tc `hasKey` eqTyConKey
   , [ty1, ty2] <- tys
   = noLoc $ HsEqTy (synifyType WithinType ty1) (synifyType WithinType ty2)
   -- Most TyCons:
   | otherwise =
     foldl (\t1 t2 -> noLoc (HsAppTy t1 t2))
-      (noLoc $ HsTyVar (getName tc))
-      (map (synifyType WithinType) tys)
+      (noLoc $ HsTyVar $ noLoc (getName tc))
+      (map (synifyType WithinType) $
+       filterOut isCoercionTy tys)
+synifyType s (AppTy t1 (CoercionTy {})) = synifyType s t1
 synifyType _ (AppTy t1 t2) = let
   s1 = synifyType WithinType t1
   s2 = synifyType WithinType t2
   in noLoc $ HsAppTy s1 s2
-synifyType _ (FunTy t1 t2) = let
+synifyType _ (ForAllTy (Anon 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
-      sTvs = synifyTyVars tvs
-      sCtx = synifyCtx ctx
-      sTau = synifyType WithinType tau
-      mkHsForAllTy forallPlicitness =
-        noLoc $ HsForAllTy forallPlicitness Nothing sTvs sCtx sTau
+      sPhi = HsQualTy { hst_ctxt = synifyCtx ctx
+                      , hst_body = synifyType WithinType tau }
   in case s of
     DeleteTopLevelQuantification -> synifyType ImplicitizeForAll tau
-    WithinType -> mkHsForAllTy Explicit
-    ImplicitizeForAll -> mkHsForAllTy Implicit
+    WithinType        -> noLoc $ HsForAllTy { hst_bndrs = map synifyTyVar tvs
+                                            , hst_body  = noLoc sPhi }
+    ImplicitizeForAll -> noLoc sPhi
 
 synifyType _ (LitTy t) = noLoc $ HsTyLit $ synifyTyLit t
+synifyType s (CastTy t _) = synifyType s t
+synifyType _ (CoercionTy {}) = error "synifyType:Coercion"
 
+synifyPatSynType :: PatSyn -> LHsType Name
+synifyPatSynType ps = let
+  (univ_tvs, req_theta, ex_tvs, prov_theta, arg_tys, res_ty) = patSynSig ps
+  req_theta' | null req_theta && not (null prov_theta && null ex_tvs) = [unitTy]
+               -- 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
+             | otherwise = req_theta
+  sForAll []  s = s
+  sForAll tvs s = HsForAllTy { hst_bndrs = map synifyTyVar tvs
+                             , hst_body  = noLoc s }
+  sQual theta s = HsQualTy   { hst_ctxt  = synifyCtx theta
+                             , hst_body  = noLoc s }
+  sTau = unLoc $ synifyType WithinType $ mkFunTys arg_tys res_ty
+  in noLoc $ sForAll univ_tvs $ sQual req_theta' $ sForAll ex_tvs $ sQual prov_theta sTau
+
 synifyTyLit :: TyLit -> HsTyLit
 synifyTyLit (NumTyLit n) = HsNumTy mempty n
 synifyTyLit (StrTyLit s) = HsStrTy mempty s
@@ -390,23 +449,38 @@
 synifyKindSig k = synifyType WithinType k
 
 synifyInstHead :: ([TyVar], [PredType], Class, [Type]) -> InstHead Name
-synifyInstHead (_, preds, cls, types) =
-  ( getName cls
-  , map (unLoc . synifyType WithinType) ks
-  , map (unLoc . synifyType WithinType) ts
-  , ClassInst $ map (unLoc . synifyType WithinType) preds
-  )
-  where (ks,ts) = break (not . isKind) types
+synifyInstHead (_, preds, cls, types) = specializeInstHead $ InstHead
+    { ihdClsName = getName cls
+    , ihdKinds = map (unLoc . synifyType WithinType) ks
+    , ihdTypes = map (unLoc . synifyType WithinType) ts
+    , ihdInstType = ClassInst
+        { clsiCtx = map (unLoc . synifyType WithinType) preds
+        , clsiTyVars = synifyTyVars $ classTyVars cls
+        , clsiSigs = map synifyClsIdSig $ classMethods cls
+        , clsiAssocTys = do
+            (Right (FamDecl fam)) <- map (synifyTyCon Nothing) $ classATs cls
+            pure $ mkPseudoFamilyDecl fam
+        }
+    }
+  where
+    (ks,ts) = partitionInvisibles (classTyCon cls) id types
+    synifyClsIdSig = synifyIdSig DeleteTopLevelQuantification
 
 -- Convert a family instance, this could be a type family or data family
 synifyFamInst :: FamInst -> Bool -> Either ErrMsg (InstHead Name)
-synifyFamInst fi opaque =
-  let fff = case fi_flavor fi of
-        SynFamilyInst | opaque -> return $ TypeInst Nothing
-        SynFamilyInst ->
-          return . TypeInst . Just . unLoc . synifyType WithinType $ fi_rhs fi
-        DataFamilyInst c ->
-          synifyTyCon (Just $ famInstAxiom fi) c >>= return . DataInst
-  in fff >>= \f' -> return (fi_fam fi , map (unLoc . synifyType WithinType) ks,
-                            map (unLoc . synifyType WithinType) ts , f')
-  where (ks,ts) = break (not . isKind) $ fi_tys fi
+synifyFamInst fi opaque = do
+    ityp' <- ityp $ fi_flavor fi
+    return InstHead
+        { ihdClsName = fi_fam fi
+        , ihdKinds = synifyTypes ks
+        , ihdTypes = synifyTypes ts
+        , ihdInstType = ityp'
+        }
+  where
+    ityp SynFamilyInst | opaque = return $ TypeInst Nothing
+    ityp SynFamilyInst =
+        return . TypeInst . Just . unLoc . synifyType WithinType $ fi_rhs fi
+    ityp (DataFamilyInst c) =
+        DataInst <$> synifyTyCon (Just $ famInstAxiom fi) c
+    (ks,ts) = partitionInvisibles (famInstTyCon fi) id $ fi_tys fi
+    synifyTypes = map (unLoc. synifyType WithinType)
diff --git a/haddock-api/src/Haddock/GhcUtils.hs b/haddock-api/src/Haddock/GhcUtils.hs
--- a/haddock-api/src/Haddock/GhcUtils.hs
+++ b/haddock-api/src/Haddock/GhcUtils.hs
@@ -35,13 +35,6 @@
 moduleString :: Module -> String
 moduleString = moduleNameString . moduleName
 
-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
 
@@ -68,7 +61,7 @@
 -- to correlate InstDecls with their Instance/CoAxiom Names, via the
 -- instanceMap.
 getInstLoc :: InstDecl name -> SrcSpan
-getInstLoc (ClsInstD (ClsInstDecl { cid_poly_ty = L l _ })) = l
+getInstLoc (ClsInstD (ClsInstDecl { cid_poly_ty = ty })) = getLoc (hsSigType ty)
 getInstLoc (DataFamInstD (DataFamInstDecl { dfid_tycon = L l _ })) = l
 getInstLoc (TyFamInstD (TyFamInstDecl
   -- Since CoAxioms' Names refer to the whole line for type family instances
@@ -91,10 +84,14 @@
     []       -> Nothing
     filtered -> Just (FixSig (FixitySig filtered ty))
 filterSigNames _ orig@(MinimalSig _ _)      = Just orig
-filterSigNames p (TypeSig ns ty nwcs) =
+filterSigNames p (TypeSig ns ty) =
   case filter (p . unLoc) ns of
     []       -> Nothing
-    filtered -> Just (TypeSig filtered ty nwcs)
+    filtered -> Just (TypeSig filtered ty)
+filterSigNames p (ClassOpSig is_default ns ty) =
+  case filter (p . unLoc) ns of
+    []       -> Nothing
+    filtered -> Just (ClassOpSig is_default filtered ty)
 filterSigNames _ _                           = Nothing
 
 ifTrueJust :: Bool -> name -> Maybe name
@@ -105,34 +102,25 @@
 sigName (L _ sig) = sigNameNoLoc sig
 
 sigNameNoLoc :: Sig name -> [name]
-sigNameNoLoc (TypeSig   ns _ _)        = map unLoc ns
-sigNameNoLoc (PatSynSig n _ _ _ _)     = [unLoc n]
-sigNameNoLoc (SpecSig   n _ _)         = [unLoc n]
-sigNameNoLoc (InlineSig n _)           = [unLoc n]
+sigNameNoLoc (TypeSig      ns _)       = map unLoc ns
+sigNameNoLoc (ClassOpSig _ ns _)       = map unLoc ns
+sigNameNoLoc (PatSynSig    n _)        = [unLoc n]
+sigNameNoLoc (SpecSig      n _ _)      = [unLoc n]
+sigNameNoLoc (InlineSig    n _)        = [unLoc n]
 sigNameNoLoc (FixSig (FixitySig ns _)) = map unLoc ns
 sigNameNoLoc _                         = []
 
-
-isTyClD :: HsDecl a -> Bool
-isTyClD (TyClD _) = True
-isTyClD _ = False
+-- | Was this signature given by the user?
+isUserLSig :: LSig name -> Bool
+isUserLSig (L _(TypeSig {}))    = True
+isUserLSig (L _(ClassOpSig {})) = True
+isUserLSig _                    = 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 _ = False
-
-
 isValD :: HsDecl a -> Bool
 isValD (ValD _) = True
 isValD _ = False
@@ -146,11 +134,6 @@
 pretty :: Outputable a => DynFlags -> a -> String
 pretty = showPpr
 
-
-trace_ppr :: Outputable a => DynFlags -> a -> b -> b
-trace_ppr dflags x y = trace (pretty dflags x) y
-
-
 -------------------------------------------------------------------------------
 -- * Located
 -------------------------------------------------------------------------------
@@ -163,11 +146,6 @@
 reL :: a -> Located a
 reL = L undefined
 
-
-before :: Located a -> Located a -> Bool
-before = (<) `on` getLoc
-
-
 -------------------------------------------------------------------------------
 -- * NamedThing instances
 -------------------------------------------------------------------------------
@@ -187,17 +165,18 @@
 
 instance Parent (ConDecl Name) where
   children con =
-    case con_details con of
-      RecCon fields -> map unL $ concatMap (cd_fld_names . unL) (unL fields)
+    case getConDetails con of
+      RecCon fields -> map (selectorFieldOcc . unL) $
+                         concatMap (cd_fld_names . unL) (unL fields)
       _             -> []
 
 instance Parent (TyClDecl Name) where
   children d
-    | isDataDecl  d = map unL $ concatMap (con_names . unL)
+    | isDataDecl  d = map unL $ concatMap (getConNames . unL)
                               $ (dd_cons . tcdDataDefn) $ d
     | isClassDecl d =
         map (unL . fdLName . unL) (tcdATs d) ++
-        [ unL n | L _ (TypeSig ns _ _) <- tcdSigs d, n <- ns ]
+        [ unL n | L _ (TypeSig ns _) <- tcdSigs d, n <- ns ]
     | otherwise = []
 
 
@@ -207,7 +186,7 @@
 
 
 familyConDecl :: ConDecl Name -> [(Name, [Name])]
-familyConDecl d = zip (map unL (con_names d)) (repeat $ children d)
+familyConDecl d = zip (map unL (getConNames d)) (repeat $ children d)
 
 -- | A mapping from the parent (main-binder) to its children and from each
 -- child to its grand-children, recursively.
diff --git a/haddock-api/src/Haddock/Interface.hs b/haddock-api/src/Haddock/Interface.hs
--- a/haddock-api/src/Haddock/Interface.hs
+++ b/haddock-api/src/Haddock/Interface.hs
@@ -228,7 +228,7 @@
         foldl' keep_old old_env exported_names
       | otherwise = foldl' keep_new old_env exported_names
       where
-        exported_names = ifaceVisibleExports iface
+        exported_names = ifaceVisibleExports iface ++ map getName (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
@@ -239,6 +239,6 @@
 --------------------------------------------------------------------------------
 
 
-withTempDir :: (ExceptionMonad m, MonadIO m) => FilePath -> m a -> m a
+withTempDir :: (ExceptionMonad m) => FilePath -> m a -> m a
 withTempDir dir = gbracket_ (liftIO $ createDirectory dir)
                             (liftIO $ removeDirectoryRecursive dir)
diff --git a/haddock-api/src/Haddock/Interface/AttachInstances.hs b/haddock-api/src/Haddock/Interface/AttachInstances.hs
--- a/haddock-api/src/Haddock/Interface/AttachInstances.hs
+++ b/haddock-api/src/Haddock/Interface/AttachInstances.hs
@@ -22,17 +22,18 @@
 import Data.List
 import Data.Ord (comparing)
 import Data.Function (on)
+import Data.Maybe ( maybeToList, mapMaybe )
 import qualified Data.Map as Map
 import qualified Data.Set as Set
 
 import Class
 import DynFlags
+import CoreSyn (isOrphan)
 import ErrUtils
 import FamInstEnv
 import FastString
 import GHC
 import GhcMonad (withSession)
-import Id
 import InstEnv
 import MonadUtils (liftIO)
 import Name
@@ -40,9 +41,8 @@
 import PrelNames
 import SrcLoc
 import TcRnDriver (tcRnGetInfo)
-import TcType (tcSplitSigmaTy)
 import TyCon
-import TypeRep
+import TyCoRep
 import TysPrim( funTyCon )
 import Var hiding (varName)
 #define FSLIT(x) (mkFastString# (x#))
@@ -61,9 +61,20 @@
     attach iface = do
       newItems <- mapM (attachToExportItem expInfo iface ifaceMap instIfaceMap)
                        (ifaceExportItems iface)
-      return $ iface { ifaceExportItems = newItems }
+      let orphanInstances = attachOrphanInstances expInfo iface ifaceMap instIfaceMap (ifaceInstances iface)
+      return $ iface { ifaceExportItems = newItems
+                     , ifaceOrphanInstances = orphanInstances
+                     }
 
+attachOrphanInstances :: ExportInfo -> Interface -> IfaceMap -> InstIfaceMap -> [ClsInst] -> [DocInstance Name]
+attachOrphanInstances expInfo iface ifaceMap instIfaceMap cls_instances =
+  [ (synifyInstHead i, instLookup instDocMap n iface ifaceMap instIfaceMap, (L (getSrcSpan n) n))
+  | let is = [ (instanceSig i, getName i) | i <- cls_instances, isOrphan (is_orphan i) ]
+  , (i@(_,_,cls,tys), n) <- sortBy (comparing $ first instHead) is
+  , not $ isInstanceHidden expInfo cls tys
+  ]
 
+
 attachToExportItem :: ExportInfo -> Interface -> IfaceMap -> InstIfaceMap
                    -> ExportItem Name
                    -> Ghc (ExportItem Name)
@@ -82,7 +93,7 @@
                           , let opaque = isTypeHidden expInfo (fi_rhs i)
                           ]
               cls_insts = [ (synifyInstHead i, instLookup instDocMap n iface ifaceMap instIfaceMap, spanName n (synifyInstHead i) (L eSpan (tcdName d)))
-                          | let is = [ (instanceHead' i, getName i) | i <- cls_instances ]
+                          | let is = [ (instanceSig i, getName i) | i <- cls_instances ]
                           , (i@(_,_,cls,tys), n) <- sortBy (comparing $ first instHead) is
                           , not $ isInstanceHidden expInfo cls tys
                           ]
@@ -108,7 +119,7 @@
 
     attachFixities e = e
     -- spanName: attach the location to the name that is the same file as the instance location
-    spanName s (clsn,_,_,_) (L instL instn) =
+    spanName s (InstHead { ihdClsName = clsn }) (L instL instn) =
         let s1 = getSrcSpan s
             sn = if srcSpanFileName_maybe s1 == srcSpanFileName_maybe instL
                     then instn
@@ -131,20 +142,6 @@
       iface' <- Map.lookup (nameModule name) ifaceMaps
       Map.lookup name (f iface')
 
--- | Like GHC's 'instanceHead' but drops "silent" arguments.
-instanceHead' :: ClsInst -> ([TyVar], ThetaType, Class, [Type])
-instanceHead' ispec = (tvs, dropSilentArgs dfun theta, cls, tys)
-  where
-    dfun = is_dfun ispec
-    (tvs, cls, tys) = instanceHead ispec
-    (_, theta, _) = tcSplitSigmaTy (idType dfun)
-
--- | Drop "silent" arguments. See GHC Note [Silent superclass
--- arguments].
-dropSilentArgs :: DFunId -> ThetaType -> ThetaType
-dropSilentArgs dfun theta = drop (dfunNSilent dfun) theta
-
-
 -- | 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,[ClsInst],[FamInst]))
@@ -174,19 +171,27 @@
 argCount :: Type -> Int
 argCount (AppTy t _) = argCount t + 1
 argCount (TyConApp _ ts) = length ts
-argCount (FunTy _ _ ) = 2
+argCount (ForAllTy (Anon _) _ ) = 2
 argCount (ForAllTy _ t) = argCount t
+argCount (CastTy t _) = argCount t
 argCount _ = 0
 
 simplify :: Type -> SimpleType
+simplify (ForAllTy (Anon t1) t2) = SimpleType funTyConName [simplify t1, simplify t2]
 simplify (ForAllTy _ t) = simplify t
-simplify (FunTy t1 t2) = SimpleType funTyConName [simplify t1, simplify t2]
-simplify (AppTy t1 t2) = SimpleType s (ts ++ [simplify t2])
+simplify (AppTy t1 t2) = SimpleType s (ts ++ maybeToList (simplify_maybe t2))
   where (SimpleType s ts) = simplify t1
 simplify (TyVarTy v) = SimpleType (tyVarName v) []
-simplify (TyConApp tc ts) = SimpleType (tyConName tc) (map simplify ts)
+simplify (TyConApp tc ts) = SimpleType (tyConName tc)
+                                       (mapMaybe simplify_maybe ts)
 simplify (LitTy l) = SimpleTyLit l
+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], Name, [SimpleType], Int, SimpleType)
 instFam FamInst { fi_fam = n, fi_tys = ts, fi_rhs = t }
@@ -235,9 +240,10 @@
         TyVarTy {} -> False
         AppTy t1 t2 -> typeHidden t1 || typeHidden t2
         TyConApp tcon args -> nameHidden (getName tcon) || any typeHidden args
-        FunTy t1 t2 -> typeHidden t1 || typeHidden t2
-        ForAllTy _ ty -> typeHidden ty
+        ForAllTy bndr ty -> typeHidden (binderType bndr) || typeHidden ty
         LitTy _ -> False
+        CastTy ty _ -> typeHidden ty
+        CoercionTy {} -> False
 
     nameHidden :: Name -> Bool
     nameHidden = isNameHidden expInfo
diff --git a/haddock-api/src/Haddock/Interface/Create.hs b/haddock-api/src/Haddock/Interface/Create.hs
--- a/haddock-api/src/Haddock/Interface/Create.hs
+++ b/haddock-api/src/Haddock/Interface/Create.hs
@@ -21,6 +21,9 @@
 import Haddock.Utils
 import Haddock.Convert
 import Haddock.Interface.LexParseRn
+import Haddock.Backends.Hyperlinker.Types
+import Haddock.Backends.Hyperlinker.Ast as Hyperlinker
+import Haddock.Backends.Hyperlinker.Parser as Hyperlinker
 
 import qualified Data.Map as M
 import Data.Map (Map)
@@ -45,7 +48,9 @@
 import RdrName
 import TcRnTypes
 import FastString (concatFS)
+import BasicTypes ( StringLiteral(..) )
 import qualified Outputable as O
+import HsDecls ( gadtDeclDetails,getConDetails )
 
 -- | Use a 'TypecheckedModule' to produce an 'Interface'.
 -- To do this, we need access to already processed modules in the topological
@@ -122,6 +127,8 @@
         mkAliasMap dflags $ tm_renamed_source tm
       modWarn = moduleWarning dflags gre warnings
 
+  tokenizedSrc <- mkMaybeTokenizedSrc flags tm
+
   return $! Interface {
     ifaceMod             = mdl
   , ifaceOrigFilename    = msHsFilePath ms
@@ -143,8 +150,11 @@
   , ifaceModuleAliases   = aliases
   , ifaceInstances       = instances
   , ifaceFamInstances    = fam_instances
+  , ifaceOrphanInstances   = [] -- Filled in `attachInstances`
+  , ifaceRnOrphanInstances = [] -- Filled in `renameInterface`
   , ifaceHaddockCoverage = coverage
   , ifaceWarningMap      = warningMap
+  , ifaceTokenizedSrc    = tokenizedSrc
   }
 
 mkAliasMap :: DynFlags -> Maybe RenamedSource -> M.Map Module ModuleName
@@ -157,21 +167,21 @@
         alias <- ideclAs impDecl
         return $
           (lookupModuleDyn dflags
-             (fmap Module.fsToPackageKey $
-              ideclPkgQual impDecl)
+             (fmap Module.fsToUnitId $
+              fmap sl_fs $ ideclPkgQual impDecl)
              (case ideclName impDecl of SrcLoc.L _ name -> name),
            alias))
         impDecls
 
 -- similar to GHC.lookupModule
 lookupModuleDyn ::
-  DynFlags -> Maybe PackageKey -> ModuleName -> Module
+  DynFlags -> Maybe UnitId -> ModuleName -> Module
 lookupModuleDyn _ (Just pkgId) mdlName =
   Module.mkModule pkgId mdlName
 lookupModuleDyn dflags Nothing mdlName =
   case Packages.lookupModuleInAllPackages dflags mdlName of
     (m,_):_ -> m
-    [] -> Module.mkModule Module.mainPackageKey mdlName
+    [] -> Module.mkModule Module.mainUnitId mdlName
 
 
 -------------------------------------------------------------------------------
@@ -194,8 +204,8 @@
 
 parseWarning :: DynFlags -> GlobalRdrEnv -> WarningTxt -> Doc Name
 parseWarning dflags gre w = force $ case w of
-  DeprecatedTxt _ msg -> format "Deprecated: " (concatFS $ map unLoc msg)
-  WarningTxt    _ msg -> format "Warning: "    (concatFS $ map unLoc msg)
+  DeprecatedTxt _ msg -> format "Deprecated: " (concatFS $ map (sl_fs . unLoc) msg)
+  WarningTxt    _ msg -> format "Warning: "    (concatFS $ map (sl_fs . unLoc) msg)
   where
     format x xs = DocWarning . DocParagraph . DocAppend (DocString x)
                   . processDocString dflags gre $ HsDocString xs
@@ -328,30 +338,30 @@
     classSubs dd = [ (name, doc, typeDocs d) | (L _ d, doc) <- classDecls dd
                    , name <- getMainDeclBinder d, not (isValD d)
                    ]
+    dataSubs :: HsDataDefn Name -> [(Name, [HsDocString], Map Int HsDocString)]
     dataSubs dd = constrs ++ fields
       where
         cons = map unL $ (dd_cons dd)
         constrs = [ (unL cname, maybeToList $ fmap unL $ con_doc c, M.empty)
-                  | c <- cons, cname <- con_names c ]
-        fields  = [ (unL n, maybeToList $ fmap unL doc, M.empty)
-                  | RecCon flds <- map con_details cons
+                  | c <- cons, cname <- getConNames c ]
+        fields  = [ (selectorFieldOcc n, maybeToList $ fmap unL doc, M.empty)
+                  | RecCon flds <- map getConDetails cons
                   , L _ (ConDeclField ns _ doc) <- (unLoc flds)
-                  , n <- ns ]
+                  , L _ n <- ns ]
 
 -- | Extract function argument docs from inside types.
 typeDocs :: HsDecl Name -> Map Int HsDocString
 typeDocs d =
   let docs = go 0 in
   case d of
-    SigD (TypeSig _ ty _) -> docs (unLoc ty)
-    SigD (PatSynSig _ _ req prov ty) ->
-        let allTys = ty : concat [ unLoc req, unLoc prov ]
-        in F.foldMap (docs . unLoc) allTys
-    ForD (ForeignImport _ ty _ _) -> docs (unLoc ty)
+    SigD (TypeSig _ ty)   -> docs (unLoc (hsSigWcType ty))
+    SigD (PatSynSig _ ty) -> docs (unLoc (hsSigType ty))
+    ForD (ForeignImport _ ty _ _)   -> docs (unLoc (hsSigType ty))
     TyClD (SynDecl { tcdRhs = ty }) -> docs (unLoc ty)
     _ -> M.empty
   where
-    go n (HsForAllTy _ _ _ _ ty) = go n (unLoc ty)
+    go n (HsForAllTy { hst_body = ty }) = go n (unLoc ty)
+    go n (HsQualTy   { hst_body = ty }) = go n (unLoc ty)
     go n (HsFunTy (L _ (HsDocTy _ (L _ x))) (L _ ty)) = M.insert n x $ go (n+1) ty
     go n (HsFunTy _ ty) = go (n+1) (unLoc ty)
     go n (HsDocTy _ (L _ doc)) = M.singleton n doc
@@ -394,7 +404,7 @@
   mkDecls (typesigs . hs_valds)  SigD   group_ ++
   mkDecls (valbinds . hs_valds)  ValD   group_
   where
-    typesigs (ValBindsOut _ sigs) = filter isVanillaLSig sigs
+    typesigs (ValBindsOut _ sigs) = filter isUserLSig sigs
     typesigs _ = error "expected ValBindsOut"
 
     valbinds (ValBindsOut binds _) = concatMap bagToList . snd . unzip $ binds
@@ -426,7 +436,7 @@
     isHandled (ForD (ForeignImport {})) = True
     isHandled (TyClD {}) = True
     isHandled (InstD {}) = True
-    isHandled (SigD d) = isVanillaLSig (reL d)
+    isHandled (SigD d) = isUserLSig (reL d)
     isHandled (ValD _) = True
     -- we keep doc declarations to be able to get at named docs
     isHandled (DocD _) = True
@@ -439,7 +449,7 @@
                       | x@(L loc d, doc) <- decls ]
   where
     filterClass (TyClD c) =
-      TyClD $ c { tcdSigs = filter (liftA2 (||) isVanillaLSig isMinimalLSig) $ tcdSigs c }
+      TyClD $ c { tcdSigs = filter (liftA2 (||) isUserLSig isMinimalLSig) $ tcdSigs c }
     filterClass _ = error "expected TyClD"
 
 
@@ -498,7 +508,7 @@
     lookupExport (IEVar (L _ x))         = declWith x
     lookupExport (IEThingAbs (L _ t))    = declWith t
     lookupExport (IEThingAll (L _ t))    = declWith t
-    lookupExport (IEThingWith (L _ t) _) = declWith t
+    lookupExport (IEThingWith (L _ t) _ _ _) = declWith t
     lookupExport (IEModuleContents (L _ m)) =
       moduleExports thisMod m dflags warnings gre exportedNames decls modMap instIfaceMap maps fixMap splices
     lookupExport (IEGroup lev docStr)  = return $
@@ -523,7 +533,7 @@
           let declNames = getMainDeclBinder (unL decl)
           in case () of
             _
-              -- temp hack: we filter out separately exported ATs, since we haven't decided how
+              -- TODO: 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 []
@@ -553,7 +563,7 @@
 
                   L loc (TyClD cl@ClassDecl{}) -> do
                     mdef <- liftGhcToErrMsgGhc $ minimalDef t
-                    let sig = maybeToList $ fmap (noLoc . MinimalSig mempty . fmap noLoc) mdef
+                    let sig = maybeToList $ fmap (noLoc . MinimalSig mempty . noLoc . fmap noLoc) mdef
                     return [ mkExportDecl t
                       (L loc $ TyClD cl { tcdSigs = sig ++ tcdSigs cl }) docs_ ]
 
@@ -695,8 +705,8 @@
                     "documentation for exported module: " ++ pretty dflags expMod]
             return []
   where
-    m = mkModule packageKey expMod
-    packageKey = modulePackageKey thisMod
+    m = mkModule unitId expMod
+    unitId = moduleUnitId thisMod
 
 
 -- Note [1]:
@@ -730,8 +740,8 @@
     expandSig = foldr f []
       where
         f :: LHsDecl name -> [LHsDecl name] -> [LHsDecl name]
-        f (L l (SigD (TypeSig    names t nwcs)))     xs = foldr (\n acc -> L l (SigD (TypeSig    [n] t nwcs))     : acc) xs names
-        f (L l (SigD (GenericSig names t)))          xs = foldr (\n acc -> L l (SigD (GenericSig [n] t))          : acc) xs names
+        f (L l (SigD (TypeSig    names t)))   xs = foldr (\n acc -> L l (SigD (TypeSig      [n] t)) : acc) xs names
+        f (L l (SigD (ClassOpSig b names t))) xs = foldr (\n acc -> L l (SigD (ClassOpSig b [n] t)) : acc) xs names
         f x xs = x : xs
 
     mkExportItem :: LHsDecl Name -> ErrMsgGhc (Maybe (ExportItem Name))
@@ -751,7 +761,7 @@
         return $ Just (ExportDecl decl doc subs [] (fixities name subs) (l `elem` splices))
     mkExportItem (L l (TyClD cl@ClassDecl{ tcdLName = L _ name, tcdSigs = sigs })) = do
       mdef <- liftGhcToErrMsgGhc $ minimalDef name
-      let sig = maybeToList $ fmap (noLoc . MinimalSig mempty . fmap noLoc) mdef
+      let sig = maybeToList $ fmap (noLoc . MinimalSig mempty . noLoc . fmap noLoc) mdef
       expDecl (L l (TyClD cl { tcdSigs = sig ++ sigs })) l name
     mkExportItem decl@(L l d)
       | name:_ <- getMainDeclBinder d = expDecl decl l name
@@ -775,64 +785,49 @@
     case unLoc decl of
       TyClD d@ClassDecl {} ->
         let matches = [ sig | sig <- tcdSigs d, name `elem` sigName sig,
-                        isVanillaLSig sig ] -- TODO: document fixity
+                        isTypeLSig sig ] -- TODO: document fixity
         in case matches of
-          [s0] -> let (n, tyvar_names) = (tcdName d, getTyVars d)
-                      L pos sig = extractClassDecl n tyvar_names s0
+          [s0] -> let (n, tyvar_names) = (tcdName d, tyClDeclTyVars d)
+                      L pos sig = addClassContext n tyvar_names s0
                   in L pos (SigD sig)
           _ -> error "internal: extractDecl (ClassDecl)"
       TyClD d@DataDecl {} ->
-        let (n, tyvar_names) = (tcdName d, map toTypeNoLoc $ getTyVars d)
-        in SigD <$> extractRecSel name mdl n tyvar_names (dd_cons (tcdDataDefn d))
+        let (n, tyvar_tys) = (tcdName d, lHsQTyVarsToTypes (tyClDeclTyVars d))
+        in SigD <$> extractRecSel name mdl n tyvar_tys (dd_cons (tcdDataDefn d))
       InstD (DataFamInstD DataFamInstDecl { dfid_tycon = L _ n
-                                          , dfid_pats = HsWB { hswb_cts = tys }
+                                          , dfid_pats = HsIB { hsib_body = tys }
                                           , dfid_defn = defn }) ->
         SigD <$> extractRecSel name mdl n tys (dd_cons defn)
       InstD (ClsInstD ClsInstDecl { cid_datafam_insts = insts }) ->
         let matches = [ d | L _ d <- insts
-                          , L _ ConDecl { con_details = RecCon rec } <- dd_cons (dfid_defn d)
+                          -- , L _ ConDecl { con_details = RecCon rec } <- dd_cons (dfid_defn d)
+                          , RecCon rec <- map (getConDetails . unLoc) (dd_cons (dfid_defn d))
                           , ConDeclField { cd_fld_names = ns } <- map unLoc (unLoc rec)
                           , L _ n <- ns
-                          , n == name
+                          , selectorFieldOcc n == name
                       ]
         in case matches of
           [d0] -> extractDecl name mdl (noLoc . InstD $ DataFamInstD d0)
           _ -> error "internal: extractDecl (ClsInstD)"
       _ -> error "internal: extractDecl"
-  where
-    getTyVars = hsLTyVarLocNames . tyClDeclTyVars
 
-
-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 Nothing tvs (lctxt preds) ty)) [])
-  _ -> L pos (TypeSig lname (noLoc (HsForAllTy Implicit Nothing emptyHsQTvs (lctxt []) ltype)) [])
-  where
-    lctxt = noLoc . ctxt
-    ctxt preds = nlHsTyConApp c (map toTypeNoLoc tvs0) : preds
-extractClassDecl _ _ _ = error "extractClassDecl: unexpected decl"
-
-
 extractRecSel :: Name -> Module -> Name -> [LHsType 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 (L _ fields) | ((n,L _ (ConDeclField _nn ty _)) : _) <- matching_fields fields ->
-      L (getLoc n) (TypeSig [noLoc nm] (noLoc (HsFunTy data_ty (getBangType ty))) [])
+  case getConDetails con of
+    RecCon (L _ fields) | ((l,L _ (ConDeclField _nn ty _)) : _) <- matching_fields fields ->
+      L l (TypeSig [noLoc nm] (mkEmptySigWcType (noLoc (HsFunTy data_ty (getBangType ty)))))
     _ -> extractRecSel nm mdl t tvs rest
  where
-  matching_fields flds = [ (n,f) | f@(L _ (ConDeclField ns _ _)) <- flds, n <- ns, unLoc n == nm ]
+  matching_fields :: [LConDeclField Name] -> [(SrcSpan, LConDeclField Name)]
+  matching_fields flds = [ (l,f) | f@(L _ (ConDeclField ns _ _)) <- flds
+                                 , L l n <- ns, selectorFieldOcc n == nm ]
   data_ty
-    | ResTyGADT _ ty <- con_res con = ty
-    | otherwise = foldl' (\x y -> noLoc (HsAppTy x y)) (noLoc (HsTyVar t)) tvs
-
+    -- | ResTyGADT _ ty <- con_res con = ty
+    | ConDeclGADT{} <- con = hsib_body $ con_type con
+    | otherwise = foldl' (\x y -> noLoc (HsAppTy x y)) (noLoc (HsTyVar (noLoc t))) tvs
 
 -- | Keep export items with docs.
 pruneExportItems :: [ExportItem Name] -> [ExportItem Name]
@@ -860,6 +855,30 @@
 seqList :: [a] -> ()
 seqList [] = ()
 seqList (x : xs) = x `seq` seqList xs
+
+mkMaybeTokenizedSrc :: [Flag] -> TypecheckedModule
+                    -> ErrMsgGhc (Maybe [RichToken])
+mkMaybeTokenizedSrc flags tm
+    | Flag_HyperlinkedSource `elem` flags = case renamedSource tm of
+        Just src -> do
+            tokens <- liftGhcToErrMsgGhc . liftIO $ mkTokenizedSrc summary src
+            return $ Just tokens
+        Nothing -> do
+            liftErrMsg . tell . pure $ concat
+                [ "Warning: Cannot hyperlink module \""
+                , moduleNameString . ms_mod_name $ summary
+                , "\" because renamed source is not available"
+                ]
+            return Nothing
+    | otherwise = return Nothing
+  where
+    summary = pm_mod_summary . tm_parsed_module $ tm
+
+mkTokenizedSrc :: ModSummary -> RenamedSource -> IO [RichToken]
+mkTokenizedSrc ms src =
+    Hyperlinker.enrich src . Hyperlinker.parse <$> rawSrc
+  where
+    rawSrc = readFile $ msHsFilePath ms
 
 -- | Find a stand-alone documentation comment by its name.
 findNamedDoc :: String -> [HsDecl Name] -> ErrMsgM (Maybe HsDocString)
diff --git a/haddock-api/src/Haddock/Interface/LexParseRn.hs b/haddock-api/src/Haddock/Interface/LexParseRn.hs
--- a/haddock-api/src/Haddock/Interface/LexParseRn.hs
+++ b/haddock-api/src/Haddock/Interface/LexParseRn.hs
@@ -21,14 +21,15 @@
 import Data.IntSet (toList)
 import Data.List
 import Documentation.Haddock.Doc (metaDocConcat)
-import DynFlags (ExtensionFlag(..), languageExtensions)
+import DynFlags (languageExtensions)
+import qualified GHC.LanguageExtensions as LangExt
 import FastString
 import GHC
 import Haddock.Interface.ParseModuleHeader
 import Haddock.Parser
 import Haddock.Types
 import Name
-import Outputable (showPpr)
+import Outputable ( showPpr )
 import RdrName
 import RnEnv (dataTcOccs)
 
@@ -64,7 +65,7 @@
             doc' = overDoc (rename dflags gre) doc
         return (hmi', Just doc')
 
-  let flags :: [ExtensionFlag]
+  let flags :: [LangExt.Extension]
       -- We remove the flags implied by the language setting and we display the language instead
       flags = map toEnum (toList $ extensionFlags dflags) \\ languageExtensions (language dflags)
   return (hmi { hmi_safety = Just $ showPpr dflags safety
@@ -131,6 +132,8 @@
       DocModule str -> DocModule str
       DocHyperlink l -> DocHyperlink l
       DocPic str -> DocPic str
+      DocMathInline str -> DocMathInline str
+      DocMathDisplay str -> DocMathDisplay str
       DocAName str -> DocAName str
       DocProperty p -> DocProperty p
       DocExamples e -> DocExamples e
diff --git a/haddock-api/src/Haddock/Interface/Rename.hs b/haddock-api/src/Haddock/Interface/Rename.hs
--- a/haddock-api/src/Haddock/Interface/Rename.hs
+++ b/haddock-api/src/Haddock/Interface/Rename.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE TypeFamilies #-}
+{-# LANGUAGE RecordWildCards #-}
 ----------------------------------------------------------------------------
 -- |
 -- Module      :  Haddock.Interface.Rename
@@ -21,8 +21,6 @@
 import Bag (emptyBag)
 import GHC hiding (NoLink)
 import Name
-import NameSet
-import Coercion
 
 import Control.Applicative
 import Control.Monad hiding (mapM)
@@ -49,13 +47,17 @@
 
       (rnArgMap, missingNames3) = runRnFM localEnv (mapM (mapM renameDoc) (ifaceArgMap iface))
 
-      (finalModuleDoc, missingNames4)
+      (renamedOrphanInstances, missingNames4)
+        = runRnFM localEnv (mapM renameDocInstance (ifaceOrphanInstances iface))
+
+      (finalModuleDoc, missingNames5)
         = runRnFM localEnv (renameDocumentation (ifaceDoc iface))
 
       -- combine the missing names and filter out the built-ins, which would
-      -- otherwise allways be missing.
+      -- otherwise always be missing.
       missingNames = nub $ filter isExternalName  -- XXX: isExternalName filters out too much
-                    (missingNames1 ++ missingNames2 ++ missingNames3 ++ missingNames4)
+                    (missingNames1 ++ missingNames2 ++ missingNames3
+                     ++ missingNames4 ++ missingNames5)
 
       -- filter out certain built in type constructors using their string
       -- representation. TODO: use the Name constants from the GHC API.
@@ -74,7 +76,8 @@
     return $ iface { ifaceRnDoc         = finalModuleDoc,
                      ifaceRnDocMap      = rnDocMap,
                      ifaceRnArgMap      = rnArgMap,
-                     ifaceRnExportItems = renamedExportItems }
+                     ifaceRnExportItems = renamedExportItems,
+                     ifaceRnOrphanInstances = renamedOrphanInstances}
 
 
 --------------------------------------------------------------------------------
@@ -93,13 +96,13 @@
 
 instance Monad RnM where
   (>>=) = thenRn
-  return = returnRn
+  return = pure
 
 instance Functor RnM where
   fmap f x = do a <- x; return (f a)
 
 instance Applicative RnM where
-  pure = return
+  pure = returnRn
   (<*>) = ap
 
 returnRn :: a -> RnM a
@@ -172,22 +175,51 @@
 renameLType :: LHsType Name -> RnM (LHsType DocName)
 renameLType = mapM renameType
 
+renameLSigType :: LHsSigType Name -> RnM (LHsSigType DocName)
+renameLSigType = renameImplicit renameLType
+
+renameLSigWcType :: LHsSigWcType Name -> RnM (LHsSigWcType DocName)
+renameLSigWcType = renameImplicit (renameWc renameLType)
+
 renameLKind :: LHsKind Name -> RnM (LHsKind DocName)
 renameLKind = renameLType
 
 renameMaybeLKind :: Maybe (LHsKind Name) -> RnM (Maybe (LHsKind DocName))
 renameMaybeLKind = traverse renameLKind
 
+renameFamilyResultSig :: LFamilyResultSig Name -> RnM (LFamilyResultSig DocName)
+renameFamilyResultSig (L loc NoSig)
+    = return (L loc NoSig)
+renameFamilyResultSig (L loc (KindSig ki))
+    = do { ki' <- renameLKind ki
+         ; return (L loc (KindSig ki')) }
+renameFamilyResultSig (L loc (TyVarSig bndr))
+    = do { bndr' <- renameLTyVarBndr bndr
+         ; return (L loc (TyVarSig bndr')) }
 
+renameInjectivityAnn :: LInjectivityAnn Name -> RnM (LInjectivityAnn DocName)
+renameInjectivityAnn (L loc (InjectivityAnn lhs rhs))
+    = do { lhs' <- renameL lhs
+         ; rhs' <- mapM renameL rhs
+         ; return (L loc (InjectivityAnn lhs' rhs')) }
+
+renameMaybeInjectivityAnn :: Maybe (LInjectivityAnn Name)
+                          -> RnM (Maybe (LInjectivityAnn DocName))
+renameMaybeInjectivityAnn = traverse renameInjectivityAnn
+
 renameType :: HsType Name -> RnM (HsType DocName)
 renameType t = case t of
-  HsForAllTy expl extra tyvars lcontext ltype -> do
-    tyvars'   <- renameLTyVarBndrs tyvars
+  HsForAllTy { hst_bndrs = tyvars, hst_body = ltype } -> do
+    tyvars'   <- mapM renameLTyVarBndr tyvars
+    ltype'    <- renameLType ltype
+    return (HsForAllTy { hst_bndrs = tyvars', hst_body = ltype' })
+
+  HsQualTy { hst_ctxt = lcontext , hst_body = ltype } -> do
     lcontext' <- renameLContext lcontext
     ltype'    <- renameLType ltype
-    return (HsForAllTy expl extra tyvars' lcontext' ltype')
+    return (HsQualTy { hst_ctxt = lcontext', hst_body = ltype' })
 
-  HsTyVar n -> return . HsTyVar =<< rename n
+  HsTyVar (L l n) -> return . HsTyVar . L l =<< rename n
   HsBangTy b ltype -> return . HsBangTy b =<< renameLType ltype
 
   HsAppTy a b -> do
@@ -207,11 +239,11 @@
 
   HsTupleTy b ts -> return . HsTupleTy b =<< mapM renameLType ts
 
-  HsOpTy a (w, L loc op) b -> do
+  HsOpTy a (L loc op) b -> do
     op' <- rename op
     a'  <- renameLType a
     b'  <- renameLType b
-    return (HsOpTy a' (w, L loc op') b')
+    return (HsOpTy a' (L loc op') b')
 
   HsParTy ty -> return . HsParTy =<< renameLType ty
 
@@ -227,29 +259,24 @@
 
   HsTyLit x -> return (HsTyLit x)
 
-  HsWrapTy a b            -> HsWrapTy a <$> renameType b
   HsRecTy a               -> HsRecTy <$> mapM renameConDeclFieldField a
   HsCoreTy a              -> pure (HsCoreTy a)
   HsExplicitListTy  a b   -> HsExplicitListTy  a <$> mapM renameLType b
   HsExplicitTupleTy a b   -> HsExplicitTupleTy a <$> mapM renameLType b
-  HsQuasiQuoteTy a        -> HsQuasiQuoteTy <$> renameHsQuasiQuote a
   HsSpliceTy _ _          -> error "renameType: HsSpliceTy"
-  HsWildcardTy            -> pure HsWildcardTy
-  HsNamedWildcardTy a     -> HsNamedWildcardTy <$> rename a
-
-renameHsQuasiQuote :: HsQuasiQuote Name -> RnM (HsQuasiQuote DocName)
-renameHsQuasiQuote (HsQuasiQuote a b c) = HsQuasiQuote <$> rename a <*> pure b <*> pure c
+  HsWildCardTy a          -> HsWildCardTy <$> renameWildCardInfo a
+  HsAppsTy _              -> error "renameType: HsAppsTy"
 
-renameLTyVarBndrs :: LHsTyVarBndrs Name -> RnM (LHsTyVarBndrs DocName)
-renameLTyVarBndrs (HsQTvs { hsq_kvs = _, hsq_tvs = tvs })
+renameLHsQTyVars :: LHsQTyVars Name -> RnM (LHsQTyVars DocName)
+renameLHsQTyVars (HsQTvs { hsq_implicit = _, hsq_explicit = tvs })
   = do { tvs' <- mapM renameLTyVarBndr tvs
-       ; return (HsQTvs { hsq_kvs = error "haddock:renameLTyVarBndrs", hsq_tvs = tvs' }) }
+       ; return (HsQTvs { hsq_implicit = error "haddock:renameLHsQTyVars", hsq_explicit = tvs', hsq_dependent = error "haddock:renameLHsQTyVars" }) }
                 -- This is rather bogus, but I'm not sure what else to do
 
 renameLTyVarBndr :: LHsTyVarBndr Name -> RnM (LHsTyVarBndr DocName)
-renameLTyVarBndr (L loc (UserTyVar n))
+renameLTyVarBndr (L loc (UserTyVar (L l n)))
   = do { n' <- rename n
-       ; return (L loc (UserTyVar n')) }
+       ; return (L loc (UserTyVar (L l n'))) }
 renameLTyVarBndr (L loc (KindedTyVar (L lv n) kind))
   = do { n' <- rename n
        ; kind' <- renameLKind kind
@@ -260,17 +287,28 @@
   context' <- mapM renameLType context
   return (L loc context')
 
+renameWildCardInfo :: HsWildCardInfo Name -> RnM (HsWildCardInfo DocName)
+renameWildCardInfo (AnonWildCard  (L l name)) = AnonWildCard . L l <$> rename name
+
 renameInstHead :: InstHead Name -> RnM (InstHead DocName)
-renameInstHead (className, k, types, rest) = do
-  className' <- rename className
-  k' <- mapM renameType k
-  types' <- mapM renameType types
-  rest' <- case rest of
-    ClassInst cs -> ClassInst <$> mapM renameType cs
+renameInstHead InstHead {..} = do
+  cname <- rename ihdClsName
+  kinds <- mapM renameType ihdKinds
+  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 (className', k', types', rest')
-
+  return InstHead
+    { ihdClsName = cname
+    , ihdKinds = kinds
+    , ihdTypes = types
+    , ihdInstType = itype
+    }
 
 renameLDecl :: LHsDecl Name -> RnM (LHsDecl DocName)
 renameLDecl (L loc d) = return . L loc =<< renameDecl d
@@ -304,21 +342,21 @@
 
   SynDecl { tcdLName = lname, tcdTyVars = tyvars, tcdRhs = rhs, tcdFVs = _fvs } -> do
     lname'    <- renameL lname
-    tyvars'   <- renameLTyVarBndrs tyvars
+    tyvars'   <- renameLHsQTyVars tyvars
     rhs'     <- renameLType rhs
     return (SynDecl { tcdLName = lname', tcdTyVars = tyvars', tcdRhs = rhs', tcdFVs = placeHolderNames })
 
   DataDecl { tcdLName = lname, tcdTyVars = tyvars, tcdDataDefn = defn, tcdFVs = _fvs } -> do
     lname'    <- renameL lname
-    tyvars'   <- renameLTyVarBndrs tyvars
+    tyvars'   <- renameLHsQTyVars tyvars
     defn'     <- renameDataDefn defn
-    return (DataDecl { tcdLName = lname', tcdTyVars = tyvars', tcdDataDefn = defn', tcdFVs = placeHolderNames })
+    return (DataDecl { tcdLName = lname', tcdTyVars = tyvars', tcdDataDefn = defn', tcdDataCusk = PlaceHolder, tcdFVs = placeHolderNames })
 
   ClassDecl { tcdCtxt = lcontext, tcdLName = lname, tcdTyVars = ltyvars
             , tcdFDs = lfundeps, tcdSigs = lsigs, tcdATs = ats, tcdATDefs = at_defs } -> do
     lcontext' <- renameLContext lcontext
     lname'    <- renameL lname
-    ltyvars'  <- renameLTyVarBndrs ltyvars
+    ltyvars'  <- renameLHsQTyVars ltyvars
     lfundeps' <- mapM renameLFunDep lfundeps
     lsigs'    <- mapM renameLSig lsigs
     ats'      <- mapM (renameLThing renameFamilyDecl) ats
@@ -338,19 +376,32 @@
 
 renameFamilyDecl :: FamilyDecl Name -> RnM (FamilyDecl DocName)
 renameFamilyDecl (FamilyDecl { fdInfo = info, fdLName = lname
-                             , fdTyVars = ltyvars, fdKindSig = tckind }) = do
-    info'    <- renameFamilyInfo info
-    lname'   <- renameL lname
-    ltyvars' <- renameLTyVarBndrs ltyvars
-    tckind'  <- renameMaybeLKind tckind
+                             , fdTyVars = ltyvars, fdResultSig = result
+                             , fdInjectivityAnn = injectivity }) = do
+    info'        <- renameFamilyInfo info
+    lname'       <- renameL lname
+    ltyvars'     <- renameLHsQTyVars ltyvars
+    result'      <- renameFamilyResultSig result
+    injectivity' <- renameMaybeInjectivityAnn injectivity
     return (FamilyDecl { fdInfo = info', fdLName = lname'
-                       , fdTyVars = ltyvars', fdKindSig = tckind' })
+                       , fdTyVars = ltyvars', fdResultSig = result'
+                       , fdInjectivityAnn = injectivity' })
 
+
+renamePseudoFamilyDecl :: PseudoFamilyDecl Name
+                       -> RnM (PseudoFamilyDecl DocName)
+renamePseudoFamilyDecl (PseudoFamilyDecl { .. }) =  PseudoFamilyDecl
+    <$> renameFamilyInfo pfdInfo
+    <*> renameL pfdLName
+    <*> mapM renameLType pfdTyVars
+    <*> renameFamilyResultSig pfdKindSig
+
+
 renameFamilyInfo :: FamilyInfo Name -> RnM (FamilyInfo DocName)
 renameFamilyInfo DataFamily     = return DataFamily
 renameFamilyInfo OpenTypeFamily = return OpenTypeFamily
 renameFamilyInfo (ClosedTypeFamily eqns)
-  = do { eqns' <- mapM renameLTyFamInstEqn eqns
+  = do { eqns' <- mapM (mapM renameLTyFamInstEqn) eqns
        ; return $ ClosedTypeFamily eqns' }
 
 renameDataDefn :: HsDataDefn Name -> RnM (HsDataDefn DocName)
@@ -364,17 +415,16 @@
                        , dd_kindSig = k', dd_cons = cons', dd_derivs = Nothing })
 
 renameCon :: ConDecl Name -> RnM (ConDecl DocName)
-renameCon decl@(ConDecl { con_names = lnames, con_qvars = ltyvars
-                        , con_cxt = lcontext, con_details = details
-                        , con_res = restype, con_doc = mbldoc }) = do
-      lnames'   <- mapM renameL lnames
-      ltyvars'  <- renameLTyVarBndrs ltyvars
-      lcontext' <- renameLContext lcontext
+renameCon decl@(ConDeclH98 { con_name = lname, con_qvars = ltyvars
+                           , con_cxt = lcontext, con_details = details
+                           , con_doc = mbldoc }) = do
+      lname'    <- renameL lname
+      ltyvars'  <- traverse renameLHsQTyVars ltyvars
+      lcontext' <- traverse renameLContext lcontext
       details'  <- renameDetails details
-      restype'  <- renameResType restype
       mbldoc'   <- mapM renameLDocHsSyn mbldoc
-      return (decl { con_names = lnames', con_qvars = ltyvars', con_cxt = lcontext'
-                   , con_details = details', con_res = restype', con_doc = mbldoc' })
+      return (decl { con_name = lname', con_qvars = ltyvars', con_cxt = lcontext'
+                   , con_details = details', con_doc = mbldoc' })
 
   where
     renameDetails (RecCon (L l fields)) = do
@@ -386,35 +436,47 @@
       b' <- renameLType b
       return (InfixCon a' b')
 
-    renameResType (ResTyH98) = return ResTyH98
-    renameResType (ResTyGADT l t) = return . ResTyGADT l =<< renameLType t
-
+renameCon decl@(ConDeclGADT { con_names = lnames
+                            , con_type = lty
+                            , con_doc = mbldoc }) = do
+      lnames'   <- mapM renameL lnames
+      lty'      <- renameLSigType lty
+      mbldoc'   <- mapM renameLDocHsSyn mbldoc
+      return (decl { con_names = lnames'
+                   , con_type = lty', con_doc = mbldoc' })
 
 renameConDeclFieldField :: LConDeclField Name -> RnM (LConDeclField DocName)
 renameConDeclFieldField (L l (ConDeclField names t doc)) = do
-  names' <- mapM renameL names
+  names' <- mapM renameLFieldOcc names
   t'   <- renameLType t
   doc' <- mapM renameLDocHsSyn doc
   return $ L l (ConDeclField names' t' doc')
 
+renameLFieldOcc :: LFieldOcc Name -> RnM (LFieldOcc DocName)
+renameLFieldOcc (L l (FieldOcc lbl sel)) = do
+  sel' <- rename sel
+  return $ L l (FieldOcc lbl sel')
 
 renameSig :: Sig Name -> RnM (Sig DocName)
 renameSig sig = case sig of
-  TypeSig lnames ltype _ -> do
+  TypeSig lnames ltype -> do
     lnames' <- mapM renameL lnames
-    ltype' <- renameLType ltype
-    return (TypeSig lnames' ltype' PlaceHolder)
-  PatSynSig lname (flag, qtvs) lreq lprov lty -> do
+    ltype' <- renameLSigWcType ltype
+    return (TypeSig lnames' ltype')
+  ClassOpSig is_default lnames sig_ty -> do
+    lnames' <- mapM renameL lnames
+    ltype' <- renameLSigType sig_ty
+    return (ClassOpSig is_default lnames' ltype')
+  PatSynSig lname sig_ty -> do
     lname' <- renameL lname
-    qtvs' <- renameLTyVarBndrs qtvs
-    lreq' <- renameLContext lreq
-    lprov' <- renameLContext lprov
-    lty' <- renameLType lty
-    return $ PatSynSig lname' (flag, qtvs') lreq' lprov' lty'
+    sig_ty' <- renameLSigType sig_ty
+    return $ PatSynSig lname' sig_ty'
   FixSig (FixitySig lnames fixity) -> do
     lnames' <- mapM renameL lnames
     return $ FixSig (FixitySig lnames' fixity)
-  MinimalSig src s -> MinimalSig src <$> traverse renameL s
+  MinimalSig src (L l s) -> do
+    s' <- traverse renameL s
+    return $ MinimalSig src (L l s')
   -- we have filtered out all other kinds of signatures in Interface.Create
   _ -> error "expected TypeSig"
 
@@ -422,11 +484,11 @@
 renameForD :: ForeignDecl Name -> RnM (ForeignDecl DocName)
 renameForD (ForeignImport lname ltype co x) = do
   lname' <- renameL lname
-  ltype' <- renameLType ltype
+  ltype' <- renameLSigType ltype
   return (ForeignImport lname' ltype' co x)
 renameForD (ForeignExport lname ltype co x) = do
   lname' <- renameL lname
-  ltype' <- renameLType ltype
+  ltype' <- renameLSigType ltype
   return (ForeignExport lname' ltype' co x)
 
 
@@ -445,7 +507,7 @@
 renameClsInstD (ClsInstDecl { cid_overlap_mode = omode
                             , cid_poly_ty =ltype, cid_tyfam_insts = lATs
                             , cid_datafam_insts = lADTs }) = do
-  ltype' <- renameLType ltype
+  ltype' <- renameLSigType ltype
   lATs'  <- mapM (mapM renameTyFamInstD) lATs
   lADTs' <- mapM (mapM renameDataFamInstD) lADTs
   return (ClsInstDecl { cid_overlap_mode = omode
@@ -461,33 +523,55 @@
                                , tfid_fvs = placeHolderNames }) }
 
 renameLTyFamInstEqn :: LTyFamInstEqn Name -> RnM (LTyFamInstEqn DocName)
-renameLTyFamInstEqn (L loc (TyFamEqn { tfe_tycon = tc, tfe_pats = pats_w_bndrs, tfe_rhs = rhs }))
+renameLTyFamInstEqn (L loc (TyFamEqn { tfe_tycon = tc, tfe_pats = pats, tfe_rhs = rhs }))
   = do { tc' <- renameL tc
-       ; pats' <- mapM renameLType (hswb_cts pats_w_bndrs)
+       ; pats' <- renameImplicit (mapM renameLType) pats
        ; rhs' <- renameLType rhs
        ; return (L loc (TyFamEqn { tfe_tycon = tc'
-                                 , tfe_pats = HsWB pats' PlaceHolder PlaceHolder PlaceHolder
+                                 , tfe_pats = pats'
                                  , tfe_rhs = rhs' })) }
 
 renameLTyFamDefltEqn :: LTyFamDefltEqn Name -> RnM (LTyFamDefltEqn DocName)
 renameLTyFamDefltEqn (L loc (TyFamEqn { tfe_tycon = tc, tfe_pats = tvs, tfe_rhs = rhs }))
-  = do { tc' <- renameL tc
-       ; tvs'  <- renameLTyVarBndrs tvs
+  = do { tc'  <- renameL tc
+       ; tvs' <- renameLHsQTyVars tvs
        ; rhs' <- renameLType rhs
        ; return (L loc (TyFamEqn { tfe_tycon = tc'
                                  , tfe_pats = tvs'
                                  , tfe_rhs = rhs' })) }
 
 renameDataFamInstD :: DataFamInstDecl Name -> RnM (DataFamInstDecl DocName)
-renameDataFamInstD (DataFamInstDecl { dfid_tycon = tc, dfid_pats = pats_w_bndrs, dfid_defn = defn })
+renameDataFamInstD (DataFamInstDecl { dfid_tycon = tc, dfid_pats = pats, dfid_defn = defn })
   = do { tc' <- renameL tc
-       ; pats' <- mapM renameLType (hswb_cts pats_w_bndrs)
+       ; pats' <- renameImplicit (mapM renameLType) pats
        ; defn' <- renameDataDefn defn
        ; return (DataFamInstDecl { dfid_tycon = tc'
-                                 , dfid_pats
-                                       = HsWB pats' PlaceHolder PlaceHolder PlaceHolder
+                                 , dfid_pats = pats'
                                  , dfid_defn = defn', dfid_fvs = placeHolderNames }) }
 
+renameImplicit :: (in_thing -> RnM out_thing)
+               -> HsImplicitBndrs Name in_thing
+               -> RnM (HsImplicitBndrs DocName out_thing)
+renameImplicit rn_thing (HsIB { hsib_body = thing })
+  = do { thing' <- rn_thing thing
+       ; return (HsIB { hsib_body = thing'
+                      , hsib_vars = PlaceHolder }) }
+
+renameWc :: (in_thing -> RnM out_thing)
+         -> HsWildCardBndrs Name in_thing
+         -> RnM (HsWildCardBndrs DocName out_thing)
+renameWc rn_thing (HsWC { hswc_body = thing })
+  = do { thing' <- rn_thing thing
+       ; return (HsWC { hswc_body = thing'
+                      , hswc_wcs = PlaceHolder, hswc_ctx = Nothing }) }
+
+renameDocInstance :: DocInstance Name -> RnM (DocInstance DocName)
+renameDocInstance (inst, idoc, L l n) = do
+  inst' <- renameInstHead inst
+  n' <- rename n
+  idoc' <- mapM renameDoc idoc
+  return (inst', idoc',L l n')
+
 renameExportItem :: ExportItem Name -> RnM (ExportItem DocName)
 renameExportItem item = case item of
   ExportModule mdl -> return (ExportModule mdl)
@@ -498,11 +582,7 @@
     decl' <- renameLDecl decl
     doc'  <- renameDocForDecl doc
     subs' <- mapM renameSub subs
-    instances' <- forM instances $ \(inst, idoc, L l n) -> do
-      inst' <- renameInstHead inst
-      n' <- rename n
-      idoc' <- mapM renameDoc idoc
-      return (inst', idoc',L l n')
+    instances' <- forM instances renameDocInstance
     fixities' <- forM fixities $ \(name, fixity) -> do
       name' <- lookupRn name
       return (name', fixity)
@@ -521,12 +601,3 @@
   n' <- rename n
   doc' <- renameDocForDecl doc
   return (n', doc')
-
-type instance PostRn DocName NameSet  = PlaceHolder
-type instance PostRn DocName Fixity   = PlaceHolder
-type instance PostRn DocName Bool     = PlaceHolder
-type instance PostRn DocName [Name]   = PlaceHolder
-
-type instance PostTc DocName Kind     = PlaceHolder
-type instance PostTc DocName Type     = PlaceHolder
-type instance PostTc DocName Coercion = PlaceHolder
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,406 @@
+{-# LANGUAGE FlexibleContexts #-}
+{-# LANGUAGE Rank2Types #-}
+{-# LANGUAGE ScopedTypeVariables #-}
+{-# LANGUAGE RecordWildCards #-}
+
+
+module Haddock.Interface.Specialize
+    ( specializeInstHead
+    ) where
+
+
+import Haddock.Syb
+import Haddock.Types
+
+import GHC
+import Name
+import FastString
+
+import Control.Monad
+import Control.Monad.Trans.Reader
+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 name with particular type.
+specialize :: (Eq name, Typeable name)
+           => Data a
+           => name -> HsType name -> a -> a
+specialize name details =
+    everywhere $ mkT step
+  where
+    step (HsTyVar (L _ name')) | name == name' = details
+    step typ = typ
+
+
+-- | Instantiate all occurrences of given names with corresponding types.
+--
+-- It is just a convenience function wrapping 'specialize' that supports more
+-- that one specialization.
+specialize' :: (Eq name, Typeable name)
+            => Data a
+            => [(name, HsType name)] -> a -> a
+specialize' = flip $ foldr (uncurry specialize)
+
+
+-- | 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 :: (Eq name, DataId name)
+                     => Data a
+                     => LHsQTyVars name -> [HsType name]
+                     -> a -> a
+specializeTyVarBndrs bndrs typs =
+    specialize' $ zip bndrs' typs
+  where
+    bndrs' = map (bname . unLoc) . hsq_explicit $ bndrs
+    bname (UserTyVar (L _ name)) = name
+    bname (KindedTyVar (L _ name) _) = name
+
+
+specializePseudoFamilyDecl :: (Eq name, DataId name)
+                           => LHsQTyVars name -> [HsType name]
+                           -> PseudoFamilyDecl name
+                           -> PseudoFamilyDecl name
+specializePseudoFamilyDecl bndrs typs decl =
+    decl { pfdTyVars = map specializeTyVars (pfdTyVars decl) }
+  where
+    specializeTyVars = specializeTyVarBndrs bndrs typs
+
+
+specializeSig :: forall name . (Eq name, DataId name, SetName name)
+              => LHsQTyVars name -> [HsType name]
+              -> Sig name
+              -> Sig name
+specializeSig bndrs typs (TypeSig lnames typ) =
+    TypeSig lnames (typ { hsib_body = (hsib_body typ) { hswc_body = noLoc typ'}})
+  where
+    true_type :: HsType name
+    true_type = unLoc (hswc_body (hsib_body typ))
+    typ' :: HsType name
+    typ' = rename fv . sugar $ specializeTyVarBndrs bndrs typs true_type
+    fv = foldr Set.union Set.empty . map freeVariables $ typs
+specializeSig _ _ sig = sig
+
+
+-- | Make all details of instance head (signatures, associated types)
+-- specialized to that particular instance type.
+specializeInstHead :: (Eq name, DataId name, SetName name)
+                   => InstHead name -> InstHead name
+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 :: forall name. (NamedThing name, DataId name)
+      => HsType name -> HsType name
+sugar =
+    everywhere $ mkT step
+  where
+    step :: HsType name -> HsType name
+    step = sugarOperators . sugarTuples . sugarLists
+
+
+sugarLists :: NamedThing name => HsType name -> HsType name
+sugarLists (HsAppTy (L _ (HsTyVar (L _ name))) ltyp)
+    | isBuiltInSyntax name' && strName == "[]" = HsListTy ltyp
+  where
+    name' = getName name
+    strName = occNameString . nameOccName $ name'
+sugarLists typ = typ
+
+
+sugarTuples :: NamedThing name => HsType name -> HsType name
+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 HsBoxedTuple apps
+      where
+        name' = getName name
+        strName = occNameString . nameOccName $ name'
+        suitable = case parseTupleArity strName of
+            Just arity -> arity == length apps
+            Nothing -> False
+    aux _ _ = typ
+
+
+sugarOperators :: NamedThing name => HsType name -> HsType name
+sugarOperators (HsAppTy (L _ (HsAppTy (L _ (HsTyVar (L l name))) la)) lb)
+    | isSymOcc $ getOccName name' = mkHsOpTy la (L l name) lb
+    | isBuiltInSyntax name' && getOccString name == "(->)" = HsFunTy 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.
+type NameRep = FastString
+
+getNameRep :: NamedThing name => name -> NameRep
+getNameRep = occNameFS . getOccName
+
+nameRepString :: NameRep -> String
+nameRepString = unpackFS
+
+stringNameRep :: String -> NameRep
+stringNameRep = mkFastString
+
+setInternalNameRep :: SetName name => NameRep -> name -> name
+setInternalNameRep = setInternalOccName . mkVarOccFS
+
+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 given type.
+freeVariables :: forall name. (NamedThing name, DataId name)
+              => HsType name -> Set NameRep
+freeVariables =
+    everythingWithState Set.empty Set.union query
+  where
+    query term ctx = case cast term :: Maybe (HsType name) of
+        Just (HsForAllTy bndrs _) ->
+            (Set.empty, Set.union ctx (bndrsNames bndrs))
+        Just (HsTyVar (L _ name))
+            | getName name `Set.member` ctx -> (Set.empty, ctx)
+            | otherwise -> (Set.singleton $ getNameRep name, ctx)
+        _ -> (Set.empty, ctx)
+    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 -> c) -> b@).
+rename :: SetName name => Set NameRep -> HsType name -> HsType name
+rename fv typ = runReader (renameType typ) $ RenameEnv
+    { rneFV = fv
+    , rneCtx = Map.empty
+    }
+
+
+-- | Renaming monad.
+type Rename name = Reader (RenameEnv name)
+
+-- | Binding generation monad.
+type Rebind name = State (RenameEnv name)
+
+data RenameEnv name = RenameEnv
+    { rneFV :: Set NameRep
+    , rneCtx :: Map Name name
+    }
+
+
+renameType :: SetName name => HsType name -> Rename name (HsType name)
+renameType (HsForAllTy bndrs lt) = rebind bndrs $ \bndrs' ->
+    HsForAllTy
+        <$> pure bndrs'
+        <*> renameLType lt
+renameType (HsQualTy lctxt lt) =
+  HsQualTy
+        <$> located renameContext lctxt
+        <*> renameLType lt
+renameType (HsTyVar name) = HsTyVar <$> located renameName name
+renameType (HsAppTy lf la) = HsAppTy <$> renameLType lf <*> renameLType la
+renameType (HsFunTy la lr) = HsFunTy <$> renameLType la <*> renameLType lr
+renameType (HsListTy lt) = HsListTy <$> renameLType lt
+renameType (HsPArrTy lt) = HsPArrTy <$> renameLType lt
+renameType (HsTupleTy srt lt) = HsTupleTy srt <$> mapM renameLType lt
+renameType (HsOpTy la lop lb) =
+    HsOpTy <$> renameLType la <*> located renameName lop <*> renameLType lb
+renameType (HsParTy lt) = HsParTy <$> renameLType lt
+renameType (HsIParamTy ip lt) = HsIParamTy ip <$> renameLType lt
+renameType (HsEqTy la lb) = HsEqTy <$> renameLType la <*> renameLType lb
+renameType (HsKindSig lt lk) = HsKindSig <$> renameLType lt <*> pure lk
+renameType t@(HsSpliceTy _ _) = pure t
+renameType (HsDocTy lt doc) = HsDocTy <$> renameLType lt <*> pure doc
+renameType (HsBangTy bang lt) = HsBangTy bang <$> renameLType lt
+renameType t@(HsRecTy _) = pure t
+renameType t@(HsCoreTy _) = pure t
+renameType (HsExplicitListTy ph ltys) =
+    HsExplicitListTy ph <$> renameLTypes ltys
+renameType (HsExplicitTupleTy phs ltys) =
+    HsExplicitTupleTy phs <$> renameLTypes ltys
+renameType t@(HsTyLit _) = pure t
+renameType (HsWildCardTy wc) = pure (HsWildCardTy wc)
+renameType (HsAppsTy _) = error "HsAppsTy: Only used before renaming"
+
+
+renameLType :: SetName name => LHsType name -> Rename name (LHsType name)
+renameLType = located renameType
+
+
+renameLTypes :: SetName name => [LHsType name] -> Rename name [LHsType name]
+renameLTypes = mapM renameLType
+
+
+renameContext :: SetName name => HsContext name -> Rename name (HsContext name)
+renameContext = renameLTypes
+
+{-
+renameLTyOp :: SetName name => LHsTyOp name -> Rename name (LHsTyOp name)
+renameLTyOp (wrap, lname) = (,) wrap <$> located renameName lname
+-}
+
+
+renameName :: SetName name => name -> Rename name name
+renameName name = do
+    RenameEnv { rneCtx = ctx } <- ask
+    pure $ fromMaybe name (Map.lookup (getName name) ctx)
+
+
+rebind :: SetName name
+       => [LHsTyVarBndr name] -> ([LHsTyVarBndr name] -> Rename name a)
+       -> Rename name a
+rebind lbndrs action = do
+    (lbndrs', env') <- runState (rebindLTyVarBndrs lbndrs) <$> ask
+    local (const env') (action lbndrs')
+
+
+rebindLTyVarBndrs :: SetName name
+                  => [LHsTyVarBndr name] -> Rebind name [LHsTyVarBndr name]
+rebindLTyVarBndrs lbndrs = mapM (located rebindTyVarBndr) lbndrs
+
+
+rebindTyVarBndr :: SetName name
+                => HsTyVarBndr name -> Rebind name (HsTyVarBndr name)
+rebindTyVarBndr (UserTyVar (L l name)) =
+    UserTyVar . L l <$> rebindName name
+rebindTyVarBndr (KindedTyVar name kinds) =
+    KindedTyVar <$> located rebindName name <*> pure kinds
+
+
+rebindName :: SetName name => name -> Rebind name name
+rebindName name = do
+    RenameEnv { .. } <- get
+    taken <- takenNames
+    case Map.lookup (getName name) rneCtx of
+        Just name' -> pure name'
+        Nothing | getNameRep name `Set.member` taken -> freshName name
+        Nothing -> reuseName name
+
+
+-- | Generate fresh occurrence name, put it into context and return.
+freshName :: SetName name => name -> Rebind name name
+freshName name = do
+    env@RenameEnv { .. } <- get
+    taken <- takenNames
+    let name' = setInternalNameRep (findFreshName taken rep) name
+    put $ env { rneCtx = Map.insert nname name' rneCtx }
+    return name'
+  where
+    nname = getName name
+    rep = getNameRep nname
+
+
+reuseName :: SetName name => name -> Rebind name name
+reuseName name = do
+    env@RenameEnv { .. } <- get
+    put $ env { rneCtx = Map.insert (getName name) name rneCtx }
+    return name
+
+
+takenNames :: NamedThing name => Rebind name (Set NameRep)
+takenNames = do
+    RenameEnv { .. } <- get
+    return $ Set.union rneFV (ctxElems rneCtx)
+  where
+    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
+    | [_] <- nameRepString name = letterNames ++ alternativeNames' name
+  where
+    letterNames = map (stringNameRep . pure) ['a'..'z']
+alternativeNames name = alternativeNames' name
+
+
+alternativeNames' :: NameRep -> [NameRep]
+alternativeNames' name =
+    [ stringNameRep $ str ++ show i | i :: Int <- [0..] ]
+  where
+    str = nameRepString name
+
+
+located :: Functor f => (a -> f b) -> Located a -> f (Located b)
+located f (L loc e) = L loc <$> f e
+
+
+tyVarName :: HsTyVarBndr name -> name
+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
--- a/haddock-api/src/Haddock/InterfaceFile.hs
+++ b/haddock-api/src/Haddock/InterfaceFile.hs
@@ -14,7 +14,7 @@
 -- Reading and writing the .haddock interface file
 -----------------------------------------------------------------------------
 module Haddock.InterfaceFile (
-  InterfaceFile(..), ifPackageKey,
+  InterfaceFile(..), ifUnitId, ifModule,
   readInterfaceFile, nameCacheFromGhc, freshNameCache, NameCacheAccessor,
   writeInterfaceFile, binaryInterfaceVersion, binaryInterfaceVersionCompatibility
 ) where
@@ -51,13 +51,19 @@
 }
 
 
-ifPackageKey :: InterfaceFile -> PackageKey
-ifPackageKey if_ =
+ifModule :: InterfaceFile -> Module
+ifModule if_ =
   case ifInstalledIfaces if_ of
     [] -> error "empty InterfaceFile"
-    iface:_ -> modulePackageKey $ instMod iface
+    iface:_ -> instMod iface
 
+ifUnitId :: InterfaceFile -> UnitId
+ifUnitId if_ =
+  case ifInstalledIfaces if_ of
+    [] -> error "empty InterfaceFile"
+    iface:_ -> moduleUnitId $ instMod iface
 
+
 binaryInterfaceMagic :: Word32
 binaryInterfaceMagic = 0xD0Cface
 
@@ -75,8 +81,8 @@
 -- (2) set `binaryInterfaceVersionCompatibility` to [binaryInterfaceVersion]
 --
 binaryInterfaceVersion :: Word16
-#if (__GLASGOW_HASKELL__ >= 709) && (__GLASGOW_HASKELL__ < 711)
-binaryInterfaceVersion = 27
+#if (__GLASGOW_HASKELL__ >= 711) && (__GLASGOW_HASKELL__ < 801)
+binaryInterfaceVersion = 28
 
 binaryInterfaceVersionCompatibility :: [Word16]
 binaryInterfaceVersionCompatibility = [binaryInterfaceVersion]
@@ -309,7 +315,7 @@
   return (namecache', arr)
 
 
-type OnDiskName = (PackageKey, ModuleName, OccName)
+type OnDiskName = (UnitId, ModuleName, OccName)
 
 
 fromOnDiskName
@@ -339,7 +345,7 @@
 serialiseName :: BinHandle -> Name -> UniqFM (Int,Name) -> IO ()
 serialiseName bh name _ = do
   let modu = nameModule name
-  put_ bh (modulePackageKey modu, moduleName modu, nameOccName name)
+  put_ bh (moduleUnitId modu, moduleName modu, nameOccName name)
 
 
 -------------------------------------------------------------------------------
@@ -467,7 +473,6 @@
     d <- get bh
     return $ MetaDoc { _meta = m, _doc = d }
 
-{-* Generated by DrIFT : Look, but Don't Touch. *-}
 instance (Binary mod, Binary id) => Binary (DocH mod id) where
     put_ bh DocEmpty = do
             putByte bh 0
@@ -532,6 +537,12 @@
     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
 
     get bh = do
             h <- getByte bh
@@ -599,6 +610,12 @@
               20 -> do
                     aa <- get bh
                     return (DocHeader aa)
+              21 -> do
+                    x <- get bh
+                    return (DocMathInline x)
+              22 -> do
+                    x <- get bh
+                    return (DocMathDisplay x)
               _ -> error "invalid binary data found in the interface file"
 
 
diff --git a/haddock-api/src/Haddock/ModuleTree.hs b/haddock-api/src/Haddock/ModuleTree.hs
--- a/haddock-api/src/Haddock/ModuleTree.hs
+++ b/haddock-api/src/Haddock/ModuleTree.hs
@@ -15,7 +15,7 @@
 import Haddock.Types ( MDoc )
 
 import GHC           ( Name )
-import Module        ( Module, moduleNameString, moduleName, modulePackageKey, packageKeyString )
+import Module        ( Module, moduleNameString, moduleName, moduleUnitId, unitIdString )
 import DynFlags      ( DynFlags )
 import Packages      ( lookupPackage )
 import PackageConfig ( sourcePackageIdString )
@@ -28,10 +28,10 @@
 mkModuleTree dflags showPkgs mods =
   foldr fn [] [ (splitModule mdl, modPkg mdl, modSrcPkg mdl, short) | (mdl, short) <- mods ]
   where
-    modPkg mod_ | showPkgs = Just (packageKeyString (modulePackageKey mod_))
+    modPkg mod_ | showPkgs = Just (unitIdString (moduleUnitId mod_))
                 | otherwise = Nothing
     modSrcPkg mod_ | showPkgs = fmap sourcePackageIdString
-                                     (lookupPackage dflags (modulePackageKey mod_))
+                                     (lookupPackage dflags (moduleUnitId mod_))
                    | otherwise = Nothing
     fn (mod_,pkg,srcPkg,short) = addToTrees mod_ pkg srcPkg short
 
diff --git a/haddock-api/src/Haddock/Options.hs b/haddock-api/src/Haddock/Options.hs
--- a/haddock-api/src/Haddock/Options.hs
+++ b/haddock-api/src/Haddock/Options.hs
@@ -21,10 +21,12 @@
   optContentsUrl,
   optIndexUrl,
   optCssFile,
+  optSourceCssFile,
   sourceUrls,
   wikiUrls,
   optDumpInterfaceFile,
   optLaTeXStyle,
+  optMathjax,
   qualification,
   verbosity,
   ghcFlags,
@@ -66,6 +68,9 @@
   | Flag_WikiEntityURL String
   | Flag_LaTeX
   | Flag_LaTeXStyle String
+  | Flag_HyperlinkedSource
+  | Flag_SourceCss String
+  | Flag_Mathjax String
   | Flag_Help
   | Flag_Verbosity String
   | Flag_Version
@@ -113,9 +118,14 @@
       "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 [] ["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"])
@@ -239,6 +249,8 @@
 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 =
@@ -261,6 +273,10 @@
 
 optLaTeXStyle :: [Flag] -> Maybe String
 optLaTeXStyle flags = optLast [ str | Flag_LaTeXStyle str <- flags ]
+
+
+optMathjax :: [Flag] -> Maybe String
+optMathjax flags = optLast [ str | Flag_Mathjax str <- flags ]
 
 
 qualification :: [Flag] -> Either String QualOption
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,55 @@
+{-# LANGUAGE Rank2Types #-}
+
+
+module Haddock.Syb
+    ( everything, everythingWithState, everywhere
+    , mkT
+    , combine
+    ) where
+
+
+import Data.Data
+import Control.Applicative
+
+
+-- | Perform a query on each level of a tree.
+--
+-- This is stolen directly from SYB package and copied here to not introduce
+-- additional dependencies.
+everything :: (r -> r -> r) -> (forall a. Data a => a -> r)
+           -> (forall a. Data a => a -> r)
+everything k f x = foldl k (f x) (gmapQ (everything k f) x)
+
+
+-- | 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)
+
+
+-- | Apply transformation on each level of a tree.
+--
+-- Just like 'everything', this is stolen from SYB package.
+everywhere :: (forall a. Data a => a -> a) -> (forall a. Data a => a -> a)
+everywhere f = f . gmapT (everywhere f)
+
+-- | 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
+
+-- | Combine two queries into one using alternative combinator.
+combine :: Alternative f => (forall a. Data a => a -> f r)
+                         -> (forall a. Data a => a -> f r)
+                         -> (forall a. Data a => a -> f r)
+combine f g x = f x <|> g x
diff --git a/haddock-api/src/Haddock/Types.hs b/haddock-api/src/Haddock/Types.hs
--- a/haddock-api/src/Haddock/Types.hs
+++ b/haddock-api/src/Haddock/Types.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE DeriveDataTypeable, DeriveFunctor, DeriveFoldable, DeriveTraversable, StandaloneDeriving #-}
+{-# LANGUAGE DeriveDataTypeable, DeriveFunctor, DeriveFoldable, DeriveTraversable, StandaloneDeriving, TypeFamilies, RecordWildCards #-}
 {-# OPTIONS_GHC -fno-warn-orphans #-}
 -----------------------------------------------------------------------------
 -- |
@@ -27,15 +27,23 @@
 import Control.DeepSeq
 import Data.Typeable
 import Data.Map (Map)
+import Data.Data (Data)
 import qualified Data.Map as Map
 import Documentation.Haddock.Types
 import BasicTypes (Fixity(..))
+
 import GHC hiding (NoLink)
-import DynFlags (ExtensionFlag, Language)
+import DynFlags (Language)
+import qualified GHC.LanguageExtensions as LangExt
+import Coercion
+import NameSet
 import OccName
 import Outputable
+import Control.Applicative (Applicative(..))
 import Control.Monad (ap)
 
+import Haddock.Backends.Hyperlinker.Types
+
 -----------------------------------------------------------------------------
 -- * Convenient synonyms
 -----------------------------------------------------------------------------
@@ -49,7 +57,6 @@
 type DeclMap       = Map Name [LHsDecl Name]
 type InstMap       = Map SrcSpan Name
 type FixMap        = Map Name Fixity
-type SrcMap        = Map PackageKey FilePath
 type DocPaths      = (FilePath, Maybe FilePath) -- paths to HTML and sources
 
 
@@ -119,12 +126,20 @@
   , ifaceInstances       :: ![ClsInst]
   , ifaceFamInstances    :: ![FamInst]
 
+    -- | Orphan instances
+  , ifaceOrphanInstances :: ![DocInstance Name]
+  , ifaceRnOrphanInstances :: ![DocInstance DocName]
+
     -- | 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 (avaliable if Haddock is invoked with
+    -- source generation flag).
+  , ifaceTokenizedSrc :: !(Maybe [RichToken])
   }
 
 type WarningMap = Map Name (Doc Name)
@@ -253,11 +268,6 @@
 noDocForDecl = (Documentation Nothing Nothing, Map.empty)
 
 
-unrenameDocForDecl :: DocForDecl DocName -> DocForDecl Name
-unrenameDocForDecl (doc, fnArgsDoc) =
-    (fmap getName doc, (fmap . fmap) getName fnArgsDoc)
-
-
 -----------------------------------------------------------------------------
 -- * Cross-referencing
 -----------------------------------------------------------------------------
@@ -266,7 +276,6 @@
 -- | 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
@@ -276,36 +285,131 @@
   | Undocumented Name
      -- ^ This thing is not part of the (existing or resulting)
      -- documentation, as far as Haddock knows.
-  deriving Eq
+  deriving (Eq, Data)
 
+type instance PostRn DocName NameSet  = PlaceHolder
+type instance PostRn DocName Fixity   = PlaceHolder
+type instance PostRn DocName Bool     = PlaceHolder
+type instance PostRn DocName [Name]   = PlaceHolder
 
+type instance PostTc DocName Kind     = PlaceHolder
+type instance PostTc DocName Type     = PlaceHolder
+type instance PostTc DocName Coercion = PlaceHolder
+
 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'
+
+
+
 -----------------------------------------------------------------------------
 -- * Instances
 -----------------------------------------------------------------------------
 
 -- | The three types of instances
 data InstType name
-  = ClassInst [HsType name]         -- ^ Context
+  = 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 OutputableBndr a => Outputable (InstType a) where
-  ppr (ClassInst a) = text "ClassInst" <+> ppr a
+  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 :: Located name
+    , pfdTyVars :: [LHsType name]
+    , pfdKindSig :: LFamilyResultSig name
+    }
+
+
+mkPseudoFamilyDecl :: FamilyDecl name -> PseudoFamilyDecl name
+mkPseudoFamilyDecl (FamilyDecl { .. }) = PseudoFamilyDecl
+    { pfdInfo = fdInfo
+    , pfdLName = fdLName
+    , pfdTyVars = [ L loc (mkType bndr) | L loc bndr <- hsq_explicit fdTyVars ]
+    , pfdKindSig = fdResultSig
+    }
+  where
+    mkType (KindedTyVar (L loc name) lkind) =
+        HsKindSig tvar lkind
+      where
+        tvar = L loc (HsTyVar (L loc name))
+    mkType (UserTyVar name) = HsTyVar name
+
+
 -- | An instance head that may have documentation and a source location.
 type DocInstance name = (InstHead name, Maybe (MDoc name), Located name)
 
 -- | The head of an instance. Consists of a class name, a list of kind
 -- parameters, a list of type parameters and an instance type
-type InstHead name = (name, [HsType name], [HsType name], InstType name)
+data InstHead name = InstHead
+    { ihdClsName :: name
+    , ihdKinds :: [HsType 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
 -----------------------------------------------------------------------------
@@ -336,6 +440,8 @@
     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` ()
@@ -383,6 +489,8 @@
   , markupHyperlink            :: Hyperlink -> a
   , markupAName                :: String -> a
   , markupPic                  :: Picture -> a
+  , markupMathInline           :: String -> a
+  , markupMathDisplay          :: String -> a
   , markupProperty             :: String -> a
   , markupExample              :: [Example] -> a
   , markupHeader               :: Header a -> a
@@ -398,7 +506,7 @@
   , hmi_portability :: Maybe String
   , hmi_safety      :: Maybe String
   , hmi_language    :: Maybe Language
-  , hmi_extensions  :: [ExtensionFlag]
+  , hmi_extensions  :: [LangExt.Extension]
   }
 
 
@@ -421,7 +529,6 @@
 -----------------------------------------------------------------------------
 
 
-{-! for DocOption derive: Binary !-}
 -- | Source-level options for controlling the documentation.
 data DocOption
   = OptHide            -- ^ This module should not appear in the docs.
@@ -490,11 +597,11 @@
         fmap f (Writer (a, msgs)) = Writer (f a, msgs)
 
 instance Applicative ErrMsgM where
-    pure = return
-    (<*>) = ap
+    pure a = Writer (a, [])
+    (<*>)  = ap
 
 instance Monad ErrMsgM where
-        return a = Writer (a, [])
+        return   = pure
         m >>= k  = Writer $ let
                 (a, w)  = runWriter m
                 (b, w') = runWriter (k a)
@@ -543,10 +650,27 @@
   fmap f (WriterGhc x) = WriterGhc (fmap (first f) x)
 
 instance Applicative ErrMsgGhc where
-    pure = return
+    pure a = WriterGhc (return (a, []))
     (<*>) = ap
 
 instance Monad ErrMsgGhc where
-  return a = WriterGhc (return (a, []))
+  return = pure
   m >>= k = WriterGhc $ runWriterGhc m >>= \ (a, msgs1) ->
                fmap (second (msgs1 ++)) (runWriterGhc (k a))
+
+
+-----------------------------------------------------------------------------
+-- * Pass sensitive types
+-----------------------------------------------------------------------------
+
+type instance PostRn DocName NameSet        = PlaceHolder
+type instance PostRn DocName Fixity         = PlaceHolder
+type instance PostRn DocName Bool           = PlaceHolder
+type instance PostRn DocName Name           = DocName
+type instance PostRn DocName (Located Name) = Located DocName
+type instance PostRn DocName [Name]         = PlaceHolder
+type instance PostRn DocName DocName        = DocName
+
+type instance PostTc DocName Kind     = PlaceHolder
+type instance PostTc DocName Type     = PlaceHolder
+type instance PostTc DocName Coercion = PlaceHolder
diff --git a/haddock-api/src/Haddock/Utils.hs b/haddock-api/src/Haddock/Utils.hs
--- a/haddock-api/src/Haddock/Utils.hs
+++ b/haddock-api/src/Haddock/Utils.hs
@@ -16,6 +16,7 @@
   -- * Misc utilities
   restrictTo, emptyHsQTvs,
   toDescription, toInstalledDescription,
+  mkEmptySigWcType, addClassContext, lHsQTyVarsToTypes,
 
   -- * Filename utilities
   moduleHtmlFile, moduleHtmlFile',
@@ -63,6 +64,8 @@
 
 import GHC
 import Name
+import NameSet ( emptyNameSet )
+import HsTypes (selectorFieldOcc)
 
 import Control.Monad ( liftM )
 import Data.Char ( isAlpha, isAlphaNum, isAscii, ord, chr )
@@ -123,6 +126,34 @@
 mkMeta :: Doc a -> MDoc a
 mkMeta x = emptyMetaDoc { _doc = x }
 
+mkEmptySigWcType :: LHsType Name -> LHsSigWcType Name
+-- Dubious, because the implicit binders are empty even
+-- though the type might have free varaiables
+mkEmptySigWcType ty = mkEmptyImplicitBndrs (mkEmptyWildCardBndrs ty)
+
+addClassContext :: Name -> LHsQTyVars Name -> LSig Name -> LSig Name
+-- Add the class context to a class-op signature
+addClassContext cls tvs0 (L pos (ClassOpSig _ lname ltype))
+  = L pos (TypeSig lname (mkEmptySigWcType (go (hsSigType ltype))))
+          -- The mkEmptySigWcType is suspicious
+  where
+    go (L loc (HsForAllTy { hst_bndrs = tvs, hst_body = ty }))
+       = L loc (HsForAllTy { hst_bndrs = tvs, hst_body = go ty })
+    go (L loc (HsQualTy { hst_ctxt = ctxt, hst_body = ty }))
+       = L loc (HsQualTy { hst_ctxt = add_ctxt ctxt, hst_body = ty })
+    go (L loc ty)
+       = L loc (HsQualTy { hst_ctxt = add_ctxt (L loc []), hst_body = L loc ty })
+
+    extra_pred = nlHsTyConApp cls (lHsQTyVarsToTypes tvs0)
+    add_ctxt (L loc preds) = L loc (extra_pred : preds)
+
+addClassContext _ _ sig = sig   -- E.g. a MinimalSig is fine
+
+lHsQTyVarsToTypes :: LHsQTyVars Name -> [LHsType Name]
+lHsQTyVarsToTypes tvs
+  = [ noLoc (HsTyVar (noLoc (hsLTyVarName tv)))
+    | tv <- hsQTvExplicit tvs ]
+
 --------------------------------------------------------------------------------
 -- * Making abstract declarations
 --------------------------------------------------------------------------------
@@ -150,19 +181,37 @@
 restrictCons :: [Name] -> [LConDecl Name] -> [LConDecl Name]
 restrictCons names decls = [ L p d | L p (Just d) <- map (fmap keep) decls ]
   where
-    keep d | any (\n -> n `elem` names) (map unLoc $ con_names d) =
-      case con_details d of
+    keep d | any (\n -> n `elem` names) (map unLoc $ getConNames d) =
+      case getConDetails h98d of
         PrefixCon _ -> Just d
         RecCon fields
           | all field_avail (unL fields) -> Just d
-          | otherwise -> Just (d { con_details = PrefixCon (field_types (map unL (unL fields))) })
+          | otherwise -> Just (h98d { con_details = PrefixCon (field_types (map unL (unL 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 (L _ (ConDeclField ns _ _)) = all (\n -> unLoc n `elem` names) ns
+        h98d = h98ConDecl d
+        h98ConDecl c@ConDeclH98{} = c
+        h98ConDecl c@ConDeclGADT{} = c'
+          where
+            (details,_res_ty,cxt,tvs) = gadtDeclDetails (con_type c)
+            c' :: ConDecl Name
+            c' = ConDeclH98
+                   { con_name = head (con_names c)
+                   , con_qvars = Just $ HsQTvs { hsq_implicit = mempty
+                                               , hsq_explicit = tvs
+                                               , hsq_dependent = emptyNameSet }
+                   , con_cxt = Just cxt
+                   , con_details = details
+                   , con_doc = con_doc c
+                   }
+
+        field_avail :: LConDeclField Name -> Bool
+        field_avail (L _ (ConDeclField fs _ _))
+            = all (\f -> selectorFieldOcc (unLoc f) `elem` names) fs
         field_types flds = [ t | ConDeclField _ t _ <- flds ]
 
     keep _ = Nothing
@@ -174,11 +223,13 @@
 restrictATs :: [Name] -> [LFamilyDecl Name] -> [LFamilyDecl Name]
 restrictATs names ats = [ at | at <- ats , unL (fdLName (unL at)) `elem` names ]
 
-emptyHsQTvs :: LHsTyVarBndrs Name
+emptyHsQTvs :: LHsQTyVars Name
 -- This function is here, rather than in HsTypes, because it *renamed*, but
 -- does not necessarily have all the rigt kind variables.  It is used
 -- in Haddock just for printing, so it doesn't matter
-emptyHsQTvs = HsQTvs { hsq_kvs = error "haddock:emptyHsQTvs", hsq_tvs = [] }
+emptyHsQTvs = HsQTvs { hsq_implicit = error "haddock:emptyHsQTvs"
+                     , hsq_explicit = []
+                     , hsq_dependent = error "haddock:emptyHsQTvs" }
 
 
 --------------------------------------------------------------------------------
@@ -430,6 +481,8 @@
 markup m (DocHyperlink l)            = markupHyperlink 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))
@@ -460,6 +513,8 @@
   markupHyperlink            = DocHyperlink,
   markupAName                = DocAName,
   markupPic                  = DocPic,
+  markupMathInline           = DocMathInline,
+  markupMathDisplay          = DocMathDisplay,
   markupProperty             = DocProperty,
   markupExample              = DocExamples,
   markupHeader               = DocHeader
diff --git a/haddock-api/src/Haddock/Version.hs b/haddock-api/src/Haddock/Version.hs
--- a/haddock-api/src/Haddock/Version.hs
+++ b/haddock-api/src/Haddock/Version.hs
@@ -9,7 +9,7 @@
 -- Stability   :  experimental
 -- Portability :  portable
 -----------------------------------------------------------------------------
-module Haddock.Version ( 
+module Haddock.Version (
   projectName, projectVersion, projectUrl
 ) where
 
diff --git a/haddock-library/src/Documentation/Haddock/Parser.hs b/haddock-library/src/Documentation/Haddock/Parser.hs
--- a/haddock-library/src/Documentation/Haddock/Parser.hs
+++ b/haddock-library/src/Documentation/Haddock/Parser.hs
@@ -73,6 +73,8 @@
     g (DocCodeBlock x) = DocCodeBlock $ g x
     g (DocHyperlink x) = DocHyperlink 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
@@ -113,7 +115,9 @@
   where
     p :: Parser (DocH mod Identifier)
     p = docConcat <$> many (monospace <|> anchor <|> identifier <|> moduleName
-                            <|> picture <|> markdownImage <|> hyperlink <|> bold
+                            <|> picture <|> mathDisplay <|> mathInline
+                            <|> markdownImage
+                            <|> hyperlink <|> bold
                             <|> emphasis <|> encodedChar <|> string'
                             <|> skipSpecialChar)
 
@@ -223,6 +227,22 @@
 picture :: Parser (DocH mod a)
 picture = DocPic . makeLabeled Picture . decodeUtf8
           <$> 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 . decodeUtf8
+             <$> 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 . decodeUtf8
+              <$> ("\\[" *> takeUntil "\\]")
 
 markdownImage :: Parser (DocH mod a)
 markdownImage = fromHyperlink <$> ("!" *> linkParser)
diff --git a/haddock-library/src/Documentation/Haddock/Types.hs b/haddock-library/src/Documentation/Haddock/Types.hs
--- a/haddock-library/src/Documentation/Haddock/Types.hs
+++ b/haddock-library/src/Documentation/Haddock/Types.hs
@@ -71,6 +71,8 @@
   | DocCodeBlock (DocH mod id)
   | DocHyperlink Hyperlink
   | DocPic Picture
+  | DocMathInline String
+  | DocMathDisplay String
   | DocAName String
   | DocProperty String
   | DocExamples [Example]
diff --git a/haddock-library/vendor/attoparsec-0.12.1.1/Data/Attoparsec/Internal/Types.hs b/haddock-library/vendor/attoparsec-0.12.1.1/Data/Attoparsec/Internal/Types.hs
--- a/haddock-library/vendor/attoparsec-0.12.1.1/Data/Attoparsec/Internal/Types.hs
+++ b/haddock-library/vendor/attoparsec-0.12.1.1/Data/Attoparsec/Internal/Types.hs
@@ -126,7 +126,7 @@
       where msg = "Failed reading: " ++ err
     {-# INLINE fail #-}
 
-    return v = Parser $ \t pos more _lose succ -> succ t pos more v
+    return = pure
     {-# INLINE return #-}
 
     m >>= k = Parser $ \t !pos more lose succ ->
@@ -158,7 +158,7 @@
 {-# INLINE apP #-}
 
 instance Applicative (Parser i) where
-    pure   = return
+    pure v = Parser $ \t pos more _lose succ -> succ t pos more v
     {-# INLINE pure #-}
     (<*>)  = apP
     {-# INLINE (<*>) #-}
@@ -166,7 +166,7 @@
     -- These definitions are equal to the defaults, but this
     -- way the optimizer doesn't have to work so hard to figure
     -- that out.
-    (*>)   = (>>)
+    m *> k = m >>= \_ -> k
     {-# INLINE (*>) #-}
     x <* y = x >>= \a -> y >> return a
     {-# INLINE (<*) #-}
diff --git a/haddock.cabal b/haddock.cabal
--- a/haddock.cabal
+++ b/haddock.cabal
@@ -1,5 +1,5 @@
 name:                 haddock
-version:              2.16.1
+version:              2.17.2
 synopsis:             A documentation-generation tool for Haskell libraries
 description:          Haddock is a documentation-generation tool for Haskell
                       libraries
@@ -17,18 +17,16 @@
 
 extra-source-files:
   CHANGES
-  README
+  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
+  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/ref/src/*.html
   latex-test/src/Simple/*.hs
   latex-test/ref/Simple/*.tex
   latex-test/ref/Simple/*.sty
@@ -45,7 +43,7 @@
   ghc-options:          -funbox-strict-fields -Wall -fwarn-tabs -O2 -threaded
 
   build-depends:
-    base >= 4.3 && < 4.9
+    base >= 4.3 && < 4.10
   if flag(in-ghc-tree)
     hs-source-dirs: haddock-api/src, haddock-library/vendor/attoparsec-0.12.1.1, haddock-library/src
     cpp-options: -DIN_GHC_TREE
@@ -57,11 +55,14 @@
       array,
       xhtml >= 3000.2 && < 3000.3,
       Cabal >= 1.10,
-      ghc >= 7.9 && < 7.12,
+      ghc-boot,
+      ghc >= 7.11 && < 8.1,
       bytestring,
       transformers
 
     other-modules:
+      ResponseFile,
+
       Documentation.Haddock.Parser
       Documentation.Haddock.Parser.Monad
       Documentation.Haddock.Types
@@ -88,6 +89,7 @@
       Haddock.Interface.AttachInstances
       Haddock.Interface.LexParseRn
       Haddock.Interface.ParseModuleHeader
+      Haddock.Interface.Specialize
       Haddock.Parser
       Haddock.Utils
       Haddock.Backends.Xhtml
@@ -101,6 +103,12 @@
       Haddock.Backends.LaTeX
       Haddock.Backends.HaddockDB
       Haddock.Backends.Hoogle
+      Haddock.Backends.Hyperlinker
+      Haddock.Backends.Hyperlinker.Ast
+      Haddock.Backends.Hyperlinker.Parser
+      Haddock.Backends.Hyperlinker.Renderer
+      Haddock.Backends.Hyperlinker.Types
+      Haddock.Backends.Hyperlinker.Utils
       Haddock.ModuleTree
       Haddock.Types
       Haddock.Doc
@@ -108,23 +116,46 @@
       Haddock.InterfaceFile
       Haddock.Options
       Haddock.GhcUtils
+      Haddock.Syb
       Haddock.Convert
   else
-    build-depends:  haddock-api == 2.16.*
+    build-depends:  haddock-api == 2.17.*
 
+test-suite driver-test
+  type:             exitcode-stdio-1.0
+  default-language: Haskell2010
+  main-is:          Main.hs
+  hs-source-dirs:   driver-test, driver
+  build-depends:    base, hspec
+
 test-suite html-test
   type:             exitcode-stdio-1.0
   default-language: Haskell2010
-  main-is:          run.lhs
+  main-is:          Main.hs
   hs-source-dirs:   html-test
-  build-depends:    base, directory, process, filepath, Cabal
+  build-depends:    base, filepath, haddock-test
 
+test-suite hypsrc-test
+  type:             exitcode-stdio-1.0
+  default-language: Haskell2010
+  main-is:          Main.hs
+  hs-source-dirs:   hypsrc-test
+  build-depends:    base, filepath, haddock-test
+  ghc-options:      -Wall -fwarn-tabs
+
 test-suite latex-test
   type:             exitcode-stdio-1.0
   default-language: Haskell2010
-  main-is:          run.lhs
+  main-is:          Main.hs
   hs-source-dirs:   latex-test
-  build-depends:    base, directory, process, filepath, Cabal
+  build-depends:    base, filepath, haddock-test
+
+test-suite hoogle-test
+  type:             exitcode-stdio-1.0
+  default-language: Haskell2010
+  main-is:          Main.hs
+  hs-source-dirs:   hoogle-test
+  build-depends:    base, filepath, haddock-test
 
 source-repository head
   type:     git
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,32 @@
+{-# LANGUAGE CPP #-}
+
+
+import System.Environment
+import System.FilePath
+
+import Test.Haddock
+
+
+checkConfig :: CheckConfig String
+checkConfig = CheckConfig
+    { ccfgRead = Just
+    , ccfgClean = \_ -> id
+    , ccfgDump = id
+    , ccfgEqual = (==)
+    }
+
+
+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/html-test/Main.hs b/html-test/Main.hs
new file mode 100644
--- /dev/null
+++ b/html-test/Main.hs
@@ -0,0 +1,53 @@
+{-# 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"]
+
+
+checkIgnore :: FilePath -> Bool
+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
--- a/html-test/ref/A.html
+++ b/html-test/ref/A.html
@@ -1,32 +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
     >A</title
-    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_A.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_A.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -48,35 +49,35 @@
 	><li class="src short"
 	  ><span class="keyword"
 	    >data</span
-	    > <a href=""
+	    > <a href="#"
 	    >A</a
-	    > = <a href=""
+	    > = <a href="#"
 	    >A</a
 	    ></li
 	  ><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >other</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
 	    ></li
 	  ><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >test2</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Bool</a
 	    ></li
 	  ><li class="src short"
 	  ><span class="keyword"
 	    >data</span
-	    > <a href=""
+	    > <a href="#"
 	    >X</a
-	    > = <a href=""
+	    > = <a href="#"
 	    >X</a
 	    ></li
 	  ><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >reExport</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
 	    ></li
 	  ></ul
@@ -88,8 +89,10 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >data</span
-	    > <a name="t:A" class="def"
+	    > <a id="t:A" class="def"
 	    >A</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="subs constructors"
 	  ><p class="caption"
@@ -97,29 +100,33 @@
 	    ><table
 	    ><tr
 	      ><td class="src"
-		><a name="v:A" class="def"
+		><a id="v:A" class="def"
 		  >A</a
 		  ></td
 		><td class="doc empty"
-		>&nbsp;</td
+		></td
 		></tr
 	      ></table
 	    ></div
 	  ></div
 	><div class="top"
 	><p class="src"
-	  ><a name="v:other" class="def"
+	  ><a id="v:other" class="def"
 	    >other</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ></div
 	><div class="top"
 	><p class="src"
-	  ><a name="v:test2" class="def"
+	  ><a id="v:test2" class="def"
 	    >test2</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Bool</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="doc"
 	  ><p
@@ -130,8 +137,10 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >data</span
-	    > <a name="t:X" class="def"
+	    > <a id="t:X" class="def"
 	    >X</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="doc"
 	  ><p
@@ -143,7 +152,7 @@
 	    ><table
 	    ><tr
 	      ><td class="src"
-		><a name="v:X" class="def"
+		><a id="v:X" class="def"
 		  >X</a
 		  ></td
 		><td class="doc"
@@ -156,10 +165,12 @@
 	  ></div
 	><div class="top"
 	><p class="src"
-	  ><a name="v:reExport" class="def"
+	  ><a id="v:reExport" class="def"
 	    >reExport</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="doc"
 	  ><p
@@ -169,11 +180,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.15.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/AdvanceTypes.html b/html-test/ref/AdvanceTypes.html
deleted file mode 100644
--- a/html-test/ref/AdvanceTypes.html
+++ /dev/null
@@ -1,97 +0,0 @@
-<!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 type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_AdvanceTypes.html");};
-//]]>
-</script
-    ></head
-  ><body
-  ><div id="package-header"
-    ><ul class="links" id="page-menu"
-      ><li
-	><a href=""
-	  >Contents</a
-	  ></li
-	><li
-	><a href=""
-	  >Index</a
-	  ></li
-	></ul
-      ><p class="caption empty"
-      >&nbsp;</p
-      ></div
-    ><div id="content"
-    ><div id="module-header"
-      ><table class="info"
-	><tr
-	  ><th
-	    >Safe Haskell</th
-	    ><td
-	    >Safe</td
-	    ></tr
-	  ></table
-	><p class="caption"
-	>AdvanceTypes</p
-	></div
-      ><div id="interface"
-      ><h1
-	>Documentation</h1
-	><div class="top"
-	><p class="src"
-	  ><span class="keyword"
-	    >data</span
-	    > <a name="t:Pattern" class="def"
-	    >Pattern</a
-	    > :: [*] -&gt; * <span class="keyword"
-	    >where</span
-	    ></p
-	  ><div class="subs constructors"
-	  ><p class="caption"
-	    >Constructors</p
-	    ><table
-	    ><tr
-	      ><td class="src"
-		><a name="v:Nil" class="def"
-		  >Nil</a
-		  > ::  <a href=""
-		  >Pattern</a
-		  > []</td
-		><td class="doc empty"
-		>&nbsp;</td
-		></tr
-	      ><tr
-	      ><td class="src"
-		><a name="v:Cons" class="def"
-		  >Cons</a
-		  > ::  <a href=""
-		  >Maybe</a
-		  > h -&gt; <a href=""
-		  >Pattern</a
-		  > t -&gt; <a href=""
-		  >Pattern</a
-		  > (h : t)</td
-		><td class="doc empty"
-		>&nbsp;</td
-		></tr
-	      ></table
-	    ></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/B.html b/html-test/ref/B.html
--- a/html-test/ref/B.html
+++ b/html-test/ref/B.html
@@ -1,32 +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
     >B</title
-    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_B.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_B.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -46,27 +47,27 @@
 	>Synopsis</p
 	><ul id="section.syn" class="hide" onclick="toggleSection('syn')"
 	><li class="src short"
-	  >module <a href=""
+	  >module <a href="#"
 	    >A</a
 	    ></li
 	  ><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >test</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
 	    ></li
 	  ><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >reExport</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
 	    ></li
 	  ><li class="src short"
 	  ><span class="keyword"
 	    >data</span
-	    > <a href=""
+	    > <a href="#"
 	    >X</a
-	    > = <a href=""
+	    > = <a href="#"
 	    >X</a
 	    ></li
 	  ></ul
@@ -76,16 +77,18 @@
 	>Documentation</h1
 	><div class="top"
 	><p class="src"
-	  >module <a href=""
+	  >module <a href="#"
 	    >A</a
 	    ></p
 	  ></div
 	><div class="top"
 	><p class="src"
-	  ><a name="v:test" class="def"
+	  ><a id="v:test" class="def"
 	    >test</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="doc"
 	  ><p
@@ -93,37 +96,39 @@
 	      >other</code
 	      >.
    These links should work: <code
-	      ><a href=""
+	      ><a href="#"
 		>other</a
 		></code
 	      >, <code
-	      ><a href=""
+	      ><a href="#"
 		>sortBy</a
 		></code
 	      >, <code
-	      ><a href=""
+	      ><a href="#"
 		>test2</a
 		></code
 	      >, <code
-	      ><a href=""
+	      ><a href="#"
 		>test2</a
 		></code
 	      >, <code
-	      ><a href=""
+	      ><a href="#"
 		>fromMaybe</a
 		></code
 	      >.
-   Module link: <a href=""
+   Module link: <a href="#"
 	      >Prelude</a
 	      >.</p
 	    ></div
 	  ></div
 	><div class="top"
 	><p class="src"
-	  ><a name="v:reExport" class="def"
+	  ><a id="v:reExport" class="def"
 	    >reExport</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="doc"
 	  ><p
@@ -134,8 +139,10 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >data</span
-	    > <a name="t:X" class="def"
+	    > <a id="t:X" class="def"
 	    >X</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="doc"
 	  ><p
@@ -147,7 +154,7 @@
 	    ><table
 	    ><tr
 	      ><td class="src"
-		><a name="v:X" class="def"
+		><a id="v:X" class="def"
 		  >X</a
 		  ></td
 		><td class="doc"
@@ -161,11 +168,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.15.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/Bold.html b/html-test/ref/Bold.html
--- a/html-test/ref/Bold.html
+++ b/html-test/ref/Bold.html
@@ -1,32 +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
     >Bold</title
-    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_Bold.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_Bold.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -46,9 +47,9 @@
 	>Synopsis</p
 	><ul id="section.syn" class="hide" onclick="toggleSection('syn')"
 	><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >foo</a
-	    > :: t</li
+	    > :: a</li
 	  ></ul
 	></div
       ><div id="interface"
@@ -56,9 +57,11 @@
 	>Documentation</h1
 	><div class="top"
 	><p class="src"
-	  ><a name="v:foo" class="def"
+	  ><a id="v:foo" class="def"
 	    >foo</a
-	    > :: t</p
+	    > :: a <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ><div class="doc"
 	  ><p
 	    >Some <strong
@@ -89,11 +92,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.15.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/Bug1.html b/html-test/ref/Bug1.html
--- a/html-test/ref/Bug1.html
+++ b/html-test/ref/Bug1.html
@@ -1,32 +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
     >Bug1</title
-    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_Bug1.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_Bug1.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -48,9 +49,9 @@
 	><li class="src short"
 	  ><span class="keyword"
 	    >data</span
-	    > <a href=""
+	    > <a href="#"
 	    >T</a
-	    > = <a href=""
+	    > = <a href="#"
 	    >T</a
 	    ></li
 	  ></ul
@@ -62,14 +63,16 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >data</span
-	    > <a name="t:T" class="def"
+	    > <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=""
+	      ><a href="#"
 		>T</a
 		></code
 	      >.</p
@@ -80,11 +83,11 @@
 	    ><table
 	    ><tr
 	      ><td class="src"
-		><a name="v:T" class="def"
+		><a id="v:T" class="def"
 		  >T</a
 		  ></td
 		><td class="doc empty"
-		>&nbsp;</td
+		></td
 		></tr
 	      ></table
 	    ></div
@@ -92,11 +95,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.15.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/Bug195.html b/html-test/ref/Bug195.html
--- a/html-test/ref/Bug195.html
+++ b/html-test/ref/Bug195.html
@@ -1,32 +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
     >Bug195</title
-    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_Bug195.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_Bug195.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -48,8 +49,10 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >data</span
-	    > <a name="t:T" class="def"
+	    > <a id="t:T" class="def"
 	    >T</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="subs constructors"
 	  ><p class="caption"
@@ -57,109 +60,115 @@
 	    ><table
 	    ><tr
 	      ><td class="src"
-		><a name="v:A" class="def"
+		><a id="v:A" class="def"
 		  >A</a
 		  ></td
 		><td class="doc empty"
-		>&nbsp;</td
+		></td
 		></tr
 	      ><tr
 	      ><td colspan="2"
 		><div class="subs fields"
 		  ><p class="caption"
 		    >Fields</p
-		    ><dl
-		    ><dt class="src"
-		      ><a name="v:someField" class="def"
-			>someField</a
-			> :: ()</dt
-		      ><dd class="doc"
-		      ><p
-			>Doc for someField of A</p
-			></dd
-		      ><dt class="src"
-		      ><a name="v:someOtherField" class="def"
-			>someOtherField</a
-			> :: ()</dt
-		      ><dd class="doc"
-		      ><p
-			>Doc for someOtherField of A</p
-			></dd
-		      ></dl
-		    ><div class="clear"
-		    ></div
+		    ><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 name="v:B" class="def"
+		><a id="v:B" class="def"
 		  >B</a
 		  ></td
 		><td class="doc empty"
-		>&nbsp;</td
+		></td
 		></tr
 	      ><tr
 	      ><td colspan="2"
 		><div class="subs fields"
 		  ><p class="caption"
 		    >Fields</p
-		    ><dl
-		    ><dt class="src"
-		      ><a name="v:someField" class="def"
-			>someField</a
-			> :: ()</dt
-		      ><dd class="doc"
-		      ><p
-			>Doc for someField of A</p
-			></dd
-		      ><dt class="src"
-		      ><a name="v:someOtherField" class="def"
-			>someOtherField</a
-			> :: ()</dt
-		      ><dd class="doc"
-		      ><p
-			>Doc for someOtherField of A</p
-			></dd
-		      ></dl
-		    ><div class="clear"
-		    ></div
+		    ><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 name="v:C" class="def"
+		><a id="v:C" class="def"
 		  >C</a
 		  ></td
 		><td class="doc empty"
-		>&nbsp;</td
+		></td
 		></tr
 	      ><tr
 	      ><td colspan="2"
 		><div class="subs fields"
 		  ><p class="caption"
 		    >Fields</p
-		    ><dl
-		    ><dt class="src"
-		      ><a name="v:someField" class="def"
-			>someField</a
-			> :: ()</dt
-		      ><dd class="doc"
-		      ><p
-			>Doc for someField of A</p
-			></dd
-		      ><dt class="src"
-		      ><a name="v:someOtherField" class="def"
-			>someOtherField</a
-			> :: ()</dt
-		      ><dd class="doc"
-		      ><p
-			>Doc for someOtherField of A</p
-			></dd
-		      ></dl
-		    ><div class="clear"
-		    ></div
+		    ><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
@@ -169,11 +178,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.16.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/Bug2.html b/html-test/ref/Bug2.html
--- a/html-test/ref/Bug2.html
+++ b/html-test/ref/Bug2.html
@@ -1,32 +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"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_Bug2.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_Bug2.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -46,20 +47,18 @@
 	>Documentation</h1
 	><div class="top"
 	><p class="src"
-	  ><a name="v:x" class="def"
+	  ><a id="v:x" class="def"
 	    >x</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >A</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ></div
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.15.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/Bug201.html b/html-test/ref/Bug201.html
--- a/html-test/ref/Bug201.html
+++ b/html-test/ref/Bug201.html
@@ -1,32 +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
     >Bug201</title
-    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_Bug201.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_Bug201.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -46,11 +47,11 @@
 	>Synopsis</p
 	><ul id="section.syn" class="hide" onclick="toggleSection('syn')"
 	><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >f</a
 	    > :: ()</li
 	  ><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >g</a
 	    > :: ()</li
 	  ></ul
@@ -60,9 +61,11 @@
 	>Documentation</h1
 	><div class="top"
 	><p class="src"
-	  ><a name="v:f" class="def"
+	  ><a id="v:f" class="def"
 	    >f</a
-	    > :: ()</p
+	    > :: () <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ><div class="doc"
 	  ><pre
 	    >This leading whitespace
@@ -72,9 +75,11 @@
 	  ></div
 	><div class="top"
 	><p class="src"
-	  ><a name="v:g" class="def"
+	  ><a id="v:g" class="def"
 	    >g</a
-	    > :: ()</p
+	    > :: () <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ><div class="doc"
 	  ><pre
 	    > But this one
@@ -92,11 +97,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.15.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/Bug253.html b/html-test/ref/Bug253.html
--- a/html-test/ref/Bug253.html
+++ b/html-test/ref/Bug253.html
@@ -1,32 +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
     >Bug253</title
-    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_Bug253.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_Bug253.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href="index.html"
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href="doc-index.html"
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -62,7 +63,7 @@
 	>Synopsis</p
 	><ul id="section.syn" class="hide" onclick="toggleSection('syn')"
 	><li class="src short"
-	  ><a href="#v:foo"
+	  ><a href="#"
 	    >foo</a
 	    > :: ()</li
 	  ></ul
@@ -72,15 +73,17 @@
 	>Documentation</h1
 	><div class="top"
 	><p class="src"
-	  ><a name="v:foo" class="def"
+	  ><a id="v:foo" class="def"
 	    >foo</a
-	    > :: ()</p
+	    > :: () <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ><div class="doc"
 	  ><p
 	    >This link should generate <code
 	      >#v</code
 	      > anchor: <code
-	      ><a href="DoesNotExist.html#v:fakeFakeFake"
+	      ><a href="#"
 		>fakeFakeFake</a
 		></code
 	      ></p
@@ -89,11 +92,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href="http://www.haskell.org/haddock/"
-	>Haddock</a
-	> version 2.16.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/Bug26.html b/html-test/ref/Bug26.html
--- a/html-test/ref/Bug26.html
+++ b/html-test/ref/Bug26.html
@@ -1,32 +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
     >Bug26</title
-    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_Bug26.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_Bug26.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -58,26 +59,22 @@
 	>Synopsis</p
 	><ul id="section.syn" class="hide" onclick="toggleSection('syn')"
 	><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >f</a
 	    > :: ()</li
 	  ><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >g</a
 	    > :: ()</li
 	  ><li class="src short"
 	  ><span class="keyword"
 	    >class</span
-	    > <a href=""
+	    > <a href="#"
 	    >C</a
 	    > a <span class="keyword"
 	    >where</span
 	    ><ul class="subs"
-	    ><li
-	      ><a href=""
-		>c_f</a
-		> :: a</li
-	      ></ul
+	    ></ul
 	    ></li
 	  ></ul
 	></div
@@ -86,9 +83,11 @@
 	>Documentation</h1
 	><div class="top"
 	><p class="src"
-	  ><a name="v:f" class="def"
+	  ><a id="v:f" class="def"
 	    >f</a
-	    > :: ()</p
+	    > :: () <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ><div class="doc"
 	  ><p
 	    >Foo</p
@@ -100,9 +99,11 @@
 	  ></div
 	><div class="top"
 	><p class="src"
-	  ><a name="v:g" class="def"
+	  ><a id="v:g" class="def"
 	    >g</a
-	    > :: ()</p
+	    > :: () <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ><div class="doc"
 	  ><p
 	    >Bar</p
@@ -112,10 +113,12 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >class</span
-	    > <a name="t:C" class="def"
+	    > <a id="t:C" class="def"
 	    >C</a
 	    > a <span class="keyword"
 	    >where</span
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="doc"
 	  ><p
@@ -125,13 +128,23 @@
 	      >Since: 1.0</em
 	      ></p
 	    ></div
+	  ><div class="subs minimal"
+	  ><p class="caption"
+	    >Minimal complete definition</p
+	    ><p class="src"
+	    ><a href="#"
+	      >c_f</a
+	      ></p
+	    ></div
 	  ><div class="subs methods"
 	  ><p class="caption"
 	    >Methods</p
 	    ><p class="src"
-	    ><a name="v:c_f" class="def"
+	    ><a id="v:c_f" class="def"
 	      >c_f</a
-	      > :: a</p
+	      > :: a <a href="#" class="selflink"
+	      >#</a
+	      ></p
 	    ><div class="doc"
 	    ><p
 	      ><em
@@ -147,9 +160,13 @@
 	      ><tr
 		><td class="src clearfix"
 		  ><span class="inst-left"
-		    ><a href=""
+		    ><span id="control.i:ic:C:C:1" class="instance expander" onclick="toggleSection('i:ic:C:C:1')"
+		      ></span
+		      > <a href="#"
 		      >C</a
 		      > ()</span
+		    > <a href="#" class="selflink"
+		    >#</a
 		    ></td
 		  ><td class="doc"
 		  ><p
@@ -160,6 +177,22 @@
 		      ></p
 		    ></td
 		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:ic:C:C:1" class="inst-details hide"
+		    ><div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >c_f</a
+			  > :: () <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></div
+		    ></td
+		  ></tr
 		></table
 	      ></div
 	    ></div
@@ -167,11 +200,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.16.1</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/Bug294.html b/html-test/ref/Bug294.html
--- a/html-test/ref/Bug294.html
+++ b/html-test/ref/Bug294.html
@@ -1,32 +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
     >Bug294</title
-    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_Bug294.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_Bug294.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -48,8 +49,10 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >data</span
-	    > <a name="t:A" class="def"
+	    > <a id="t:A" class="def"
 	    >A</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="subs instances"
 	  ><p id="control.i:A" class="caption collapser" onclick="toggleSection('i:A')"
@@ -59,78 +62,122 @@
 	      ><tr
 		><td class="src clearfix"
 		  ><span class="inst-left"
-		    ><span class="keyword"
+		    ><span id="control.i:id:A:DP:1" class="instance expander" onclick="toggleSection('i:id:A:DP:1')"
+		      ></span
+		      > <span class="keyword"
 		      >data</span
-		      > <a href=""
+		      > <a href="#"
 		      >DP</a
-		      > <a href=""
-		      >A</a
-		      > = <a name="v:ProblemCtor-39-" class="def"
-		      >ProblemCtor'</a
-		      > <a href=""
+		      > <a href="#"
 		      >A</a
 		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
 		    ></td
 		  ><td class="doc empty"
-		  >&nbsp;</td
+		  ></td
 		  ></tr
 		><tr
+		><td colspan="2"
+		  ><div id="section.i:id:A:DP:1" class="inst-details hide"
+		    ><div class="src"
+		      ><span class="keyword"
+			>data</span
+			> <a href="#"
+			>DP</a
+			> <a href="#"
+			>A</a
+			> = <a id="v:ProblemCtor-39-" class="def"
+			>ProblemCtor'</a
+			> <a href="#"
+			>A</a
+			></div
+		      ></div
+		    ></td
+		  ></tr
+		><tr
 		><td class="src clearfix"
 		  ><span class="inst-left"
-		    ><span class="keyword"
+		    ><span id="control.i:id:A:TP:2" class="instance expander" onclick="toggleSection('i:id:A:TP:2')"
+		      ></span
+		      > <span class="keyword"
 		      >data</span
-		      > TP <a href=""
-		      >A</a
-		      > = <a name="v:ProblemCtor" class="def"
-		      >ProblemCtor</a
-		      > <a href=""
+		      > TP <a href="#"
 		      >A</a
 		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
 		    ></td
 		  ><td class="doc empty"
-		  >&nbsp;</td
+		  ></td
 		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:id:A:TP:2" class="inst-details hide"
+		    ><div class="src"
+		      ><span class="keyword"
+			>data</span
+			> TP <a href="#"
+			>A</a
+			> = <a id="v:ProblemCtor" class="def"
+			>ProblemCtor</a
+			> <a href="#"
+			>A</a
+			></div
+		      ></div
+		    ></td
+		  ></tr
 		></table
 	      ></div
 	    ></div
 	  ></div
 	><div class="top"
 	><p class="src"
-	  ><a name="v:problemField" class="def"
+	  ><a id="v:problemField" class="def"
 	    >problemField</a
-	    > :: TO <a href=""
+	    > :: TO <a href="#"
 	    >A</a
-	    > -&gt; <a href=""
+	    > -&gt; <a href="#"
 	    >A</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ></div
 	><div class="top"
 	><p class="src"
-	  ><a name="v:problemField-39-" class="def"
+	  ><a id="v:problemField-39-" class="def"
 	    >problemField'</a
-	    > :: DO <a href=""
+	    > :: DO <a href="#"
 	    >A</a
-	    > -&gt; <a href=""
+	    > -&gt; <a href="#"
 	    >A</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ></div
 	><div class="top"
 	><p class="src"
-	  ><a name="v:gadtField" class="def"
+	  ><a id="v:gadtField" class="def"
 	    >gadtField</a
-	    > :: GADT <a href=""
+	    > :: ({..} -&gt; GADT <a href="#"
 	    >A</a
-	    > -&gt; <a href=""
+	    >) -&gt; <a href="#"
 	    >A</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ></div
 	><div class="top"
 	><p class="src"
 	  ><span class="keyword"
 	    >data family</span
-	    > <a name="t:DP" class="def"
+	    > <a id="t:DP" class="def"
 	    >DP</a
-	    > t :: *</p
+	    > t :: <a href="#"
+	    >*</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ><div class="subs instances"
 	  ><p id="control.i:DP" class="caption collapser" onclick="toggleSection('i:DP')"
 	    >Instances</p
@@ -139,21 +186,39 @@
 	      ><tr
 		><td class="src clearfix"
 		  ><span class="inst-left"
-		    ><span class="keyword"
+		    ><span id="control.i:if:DP:DP:1" class="instance expander" onclick="toggleSection('i:if:DP:DP:1')"
+		      ></span
+		      > <span class="keyword"
 		      >data</span
-		      > <a href=""
+		      > <a href="#"
 		      >DP</a
-		      > <a href=""
-		      >A</a
-		      > = <a name="v:ProblemCtor-39-" class="def"
-		      >ProblemCtor'</a
-		      > <a href=""
+		      > <a href="#"
 		      >A</a
 		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
 		    ></td
 		  ><td class="doc empty"
-		  >&nbsp;</td
+		  ></td
 		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:if:DP:DP:1" class="inst-details hide"
+		    ><div class="src"
+		      ><span class="keyword"
+			>data</span
+			> <a href="#"
+			>DP</a
+			> <a href="#"
+			>A</a
+			> = <a id="v:ProblemCtor-39-" class="def"
+			>ProblemCtor'</a
+			> <a href="#"
+			>A</a
+			></div
+		      ></div
+		    ></td
+		  ></tr
 		></table
 	      ></div
 	    ></div
@@ -161,11 +226,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.16.1</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/Bug298.html b/html-test/ref/Bug298.html
--- a/html-test/ref/Bug298.html
+++ b/html-test/ref/Bug298.html
@@ -1,32 +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
     >Bug298</title
-    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_Bug298.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_Bug298.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -46,23 +47,23 @@
 	>Synopsis</p
 	><ul id="section.syn" class="hide" onclick="toggleSection('syn')"
 	><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >(&lt;^&gt;)</a
 	    > :: (a -&gt; a) -&gt; a -&gt; a</li
 	  ><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >(&lt;^)</a
 	    > :: a -&gt; a -&gt; a</li
 	  ><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >(^&gt;)</a
 	    > :: a -&gt; a -&gt; a</li
 	  ><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >(&#8902;^)</a
 	    > :: a -&gt; a -&gt; a</li
 	  ><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >f</a
 	    > :: ()</li
 	  ></ul
@@ -72,49 +73,59 @@
 	>Documentation</h1
 	><div class="top"
 	><p class="src"
-	  ><a name="v:-60--94--62-" class="def"
+	  ><a id="v:-60--94--62-" class="def"
 	    >(&lt;^&gt;)</a
-	    > :: (a -&gt; a) -&gt; a -&gt; a</p
+	    > :: (a -&gt; a) -&gt; a -&gt; a <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ></div
 	><div class="top"
 	><p class="src"
-	  ><a name="v:-60--94-" class="def"
+	  ><a id="v:-60--94-" class="def"
 	    >(&lt;^)</a
-	    > :: a -&gt; a -&gt; a</p
+	    > :: a -&gt; a -&gt; a <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ></div
 	><div class="top"
 	><p class="src"
-	  ><a name="v:-94--62-" class="def"
+	  ><a id="v:-94--62-" class="def"
 	    >(^&gt;)</a
-	    > :: a -&gt; a -&gt; a</p
+	    > :: a -&gt; a -&gt; a <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ></div
 	><div class="top"
 	><p class="src"
-	  ><a name="v:-8902--94-" class="def"
+	  ><a id="v:-8902--94-" class="def"
 	    >(&#8902;^)</a
-	    > :: a -&gt; a -&gt; a</p
+	    > :: a -&gt; a -&gt; a <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ></div
 	><div class="top"
 	><p class="src"
-	  ><a name="v:f" class="def"
+	  ><a id="v:f" class="def"
 	    >f</a
-	    > :: ()</p
+	    > :: () <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ><div class="doc"
 	  ><p
 	    >Links to <code
-	      ><a href=""
+	      ><a href="#"
 		>&lt;^&gt;</a
 		></code
 	      > and <code
-	      ><a href=""
+	      ><a href="#"
 		>^&gt;</a
 		></code
 	      >, <code
-	      ><a href=""
+	      ><a href="#"
 		>&lt;^</a
 		></code
 	      > and <code
-	      ><a href=""
+	      ><a href="#"
 		>&#8902;^</a
 		></code
 	      >.</p
@@ -123,11 +134,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.15.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/Bug3.html b/html-test/ref/Bug3.html
--- a/html-test/ref/Bug3.html
+++ b/html-test/ref/Bug3.html
@@ -1,32 +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"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_Bug3.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_Bug3.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -46,9 +47,9 @@
 	>Synopsis</p
 	><ul id="section.syn" class="hide" onclick="toggleSection('syn')"
 	><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >foo</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
 	    ></li
 	  ></ul
@@ -58,10 +59,12 @@
 	>Documentation</h1
 	><div class="top"
 	><p class="src"
-	  ><a name="v:foo" class="def"
+	  ><a id="v:foo" class="def"
 	    >foo</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="doc"
 	  ><p
@@ -72,11 +75,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.15.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/Bug308.html b/html-test/ref/Bug308.html
--- a/html-test/ref/Bug308.html
+++ b/html-test/ref/Bug308.html
@@ -1,32 +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
     >Bug308</title
-    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_Bug308.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_Bug308.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -46,11 +47,11 @@
 	>Synopsis</p
 	><ul id="section.syn" class="hide" onclick="toggleSection('syn')"
 	><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >f</a
 	    > :: ()</li
 	  ><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >g</a
 	    > :: ()</li
 	  ></ul
@@ -60,40 +61,44 @@
 	>Documentation</h1
 	><div class="top"
 	><p class="src"
-	  ><a name="v:f" class="def"
+	  ><a id="v:f" class="def"
 	    >f</a
-	    > :: ()</p
+	    > :: () <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ><div class="doc"
 	  ><p
-	    >start<a name="startAnchor"
+	    >start<a id="startAnchor"
 	      ></a
-	      > followed by middle<a name="middleAnchor"
+	      > followed by middle<a id="middleAnchor"
 	      ></a
-	      > and end<a name="endAnchor"
+	      > and end<a id="endAnchor"
 	      ></a
 	      ></p
 	    ></div
 	  ></div
 	><div class="top"
 	><p class="src"
-	  ><a name="v:g" class="def"
+	  ><a id="v:g" class="def"
 	    >g</a
-	    > :: ()</p
+	    > :: () <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ><div class="doc"
 	  ><p
-	    >start <a href=""
+	    >start <a href="#"
 	      >Bug308</a
 	      ></p
 	    ><p
-	    >startOldStyle <a href=""
+	    >startOldStyle <a href="#"
 	      >Bug308</a
 	      ></p
 	    ><p
-	    >middle <a href=""
+	    >middle <a href="#"
 	      >Bug308</a
 	      ></p
 	    ><p
-	    >end <a href=""
+	    >end <a href="#"
 	      >Bug308</a
 	      ></p
 	    ></div
@@ -101,11 +106,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.15.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/Bug308CrossModule.html b/html-test/ref/Bug308CrossModule.html
--- a/html-test/ref/Bug308CrossModule.html
+++ b/html-test/ref/Bug308CrossModule.html
@@ -1,32 +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
     >Bug308CrossModule</title
-    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_Bug308CrossModule.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_Bug308CrossModule.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -46,7 +47,7 @@
 	>Synopsis</p
 	><ul id="section.syn" class="hide" onclick="toggleSection('syn')"
 	><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >h</a
 	    > :: ()</li
 	  ></ul
@@ -56,24 +57,26 @@
 	>Documentation</h1
 	><div class="top"
 	><p class="src"
-	  ><a name="v:h" class="def"
+	  ><a id="v:h" class="def"
 	    >h</a
-	    > :: ()</p
+	    > :: () <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ><div class="doc"
 	  ><p
-	    >start <a href=""
+	    >start <a href="#"
 	      >Bug308</a
 	      ></p
 	    ><p
-	    >startOldStyle <a href=""
+	    >startOldStyle <a href="#"
 	      >Bug308</a
 	      ></p
 	    ><p
-	    >middle <a href=""
+	    >middle <a href="#"
 	      >Bug308</a
 	      ></p
 	    ><p
-	    >end <a href=""
+	    >end <a href="#"
 	      >Bug308</a
 	      ></p
 	    ></div
@@ -81,11 +84,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.15.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/Bug310.html b/html-test/ref/Bug310.html
--- a/html-test/ref/Bug310.html
+++ b/html-test/ref/Bug310.html
@@ -1,32 +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
     >Bug310</title
-    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_Bug310.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_Bug310.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -48,10 +49,16 @@
 	><li class="src short"
 	  ><span class="keyword"
 	    >type family</span
-	    > a <a href=""
+	    > (a :: <a href="#"
+	    >Nat</a
+	    >) <a href="#"
 	    >+</a
-	    > b :: <a href=""
+	    > (b :: <a href="#"
 	    >Nat</a
+	    >) :: <a href="#"
+	    >Nat</a
+	    > <span class="keyword"
+	    >where ...</span
 	    ></li
 	  ></ul
 	></div
@@ -62,14 +69,22 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >type family</span
-	    > a <a name="t:-43-" class="def"
+	    > (a :: <a href="#"
+	    >Nat</a
+	    >) <a id="t:-43-" class="def"
 	    >+</a
-	    > b :: <a href=""
+	    > (b :: <a href="#"
 	    >Nat</a
+	    >) :: <a href="#"
+	    >Nat</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
@@ -79,11 +94,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.16.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/Bug313.html b/html-test/ref/Bug313.html
--- a/html-test/ref/Bug313.html
+++ b/html-test/ref/Bug313.html
@@ -1,32 +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
     >Bug313</title
-    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_Bug313.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_Bug313.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -49,7 +50,7 @@
 	  >The first list is incorrectly numbered as 1. 2. 1.; the second example
  renders fine (1. 2. 3.).</p
 	  ><p
-	  >See <a href=""
+	  >See <a href="#"
 	    >https://github.com/haskell/haddock/issues/313</a
 	    ></p
 	  ></div
@@ -59,11 +60,11 @@
 	>Synopsis</p
 	><ul id="section.syn" class="hide" onclick="toggleSection('syn')"
 	><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >a</a
 	    > :: a</li
 	  ><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >b</a
 	    > :: a</li
 	  ></ul
@@ -73,9 +74,11 @@
 	>Documentation</h1
 	><div class="top"
 	><p class="src"
-	  ><a name="v:a" class="def"
+	  ><a id="v:a" class="def"
 	    >a</a
-	    > :: a</p
+	    > :: a <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ><div class="doc"
 	  ><p
 	    >Some text.</p
@@ -97,9 +100,11 @@
 	  ></div
 	><div class="top"
 	><p class="src"
-	  ><a name="v:b" class="def"
+	  ><a id="v:b" class="def"
 	    >b</a
-	    > :: a</p
+	    > :: a <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ><div class="doc"
 	  ><p
 	    >Some text.</p
@@ -122,11 +127,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.15.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/Bug335.html b/html-test/ref/Bug335.html
--- a/html-test/ref/Bug335.html
+++ b/html-test/ref/Bug335.html
@@ -1,32 +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
     >Bug335</title
-    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_Bug335.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_Bug335.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -46,11 +47,11 @@
 	>Synopsis</p
 	><ul id="section.syn" class="hide" onclick="toggleSection('syn')"
 	><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >f</a
 	    > :: ()</li
 	  ><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >g</a
 	    > :: ()</li
 	  ></ul
@@ -60,11 +61,13 @@
 	>Documentation</h1
 	><div class="top"
 	><p class="src"
-	  ><a name="v:f" class="def"
+	  ><a id="v:f" class="def"
 	    >f</a
-	    > :: ()</p
+	    > :: () <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ><div class="doc"
-	  ><h3 id="control.ch:f0" class="caption collapser" onclick="toggleSection('ch:f0')"
+	  ><h3 id="control.ch:f0" class="caption expander" onclick="toggleSection('ch:f0')"
 	    >ExF:</h3
 	    ><div id="section.ch:f0" class="hide"
 	    ><p
@@ -74,11 +77,13 @@
 	  ></div
 	><div class="top"
 	><p class="src"
-	  ><a name="v:g" class="def"
+	  ><a id="v:g" class="def"
 	    >g</a
-	    > :: ()</p
+	    > :: () <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ><div class="doc"
-	  ><h3 id="control.ch:g0" class="caption collapser" onclick="toggleSection('ch:g0')"
+	  ><h3 id="control.ch:g0" class="caption expander" onclick="toggleSection('ch:g0')"
 	    >ExG:</h3
 	    ><div id="section.ch:g0" class="hide"
 	    ><pre class="screen"
@@ -115,11 +120,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.16.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/Bug387.html b/html-test/ref/Bug387.html
--- a/html-test/ref/Bug387.html
+++ b/html-test/ref/Bug387.html
@@ -1,32 +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
     >Bug387</title
-    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_Bug387.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_Bug387.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -46,11 +47,11 @@
 	>Contents</p
 	><ul
 	><li
-	  ><a href=""
+	  ><a href="#"
 	    >Section1</a
 	    ></li
 	  ><li
-	  ><a href=""
+	  ><a href="#"
 	    >Section2</a
 	    ></li
 	  ></ul
@@ -60,52 +61,52 @@
 	>Synopsis</p
 	><ul id="section.syn" class="hide" onclick="toggleSection('syn')"
 	><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >test1</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
 	    ></li
 	  ><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >test2</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
 	    ></li
 	  ></ul
 	></div
       ><div id="interface"
       ><h1 id="g:1"
-	>Section1<a name="a:section1"
+	>Section1<a id="a:section1"
 	  ></a
 	  ></h1
 	><div class="top"
 	><p class="src"
-	  ><a name="v:test1" class="def"
+	  ><a id="v:test1" class="def"
 	    >test1</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ></div
 	><h1 id="g:2"
-	>Section2<a name="a:section2"
+	>Section2<a id="a:section2"
 	  ></a
 	  ></h1
 	><div class="top"
 	><p class="src"
-	  ><a name="v:test2" class="def"
+	  ><a id="v:test2" class="def"
 	    >test2</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ></div
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.16.1</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/Bug4.html b/html-test/ref/Bug4.html
--- a/html-test/ref/Bug4.html
+++ b/html-test/ref/Bug4.html
@@ -1,32 +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"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_Bug4.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_Bug4.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -46,9 +47,9 @@
 	>Synopsis</p
 	><ul id="section.syn" class="hide" onclick="toggleSection('syn')"
 	><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >foo</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
 	    ></li
 	  ></ul
@@ -58,10 +59,12 @@
 	>Documentation</h1
 	><div class="top"
 	><p class="src"
-	  ><a name="v:foo" class="def"
+	  ><a id="v:foo" class="def"
 	    >foo</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="doc"
 	  ><p
@@ -71,11 +74,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.15.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/Bug6.html b/html-test/ref/Bug6.html
--- a/html-test/ref/Bug6.html
+++ b/html-test/ref/Bug6.html
@@ -1,32 +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
     >Bug6</title
-    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_Bug6.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_Bug6.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -56,25 +57,25 @@
 	><li class="src short"
 	  ><span class="keyword"
 	    >data</span
-	    > <a href=""
+	    > <a href="#"
 	    >A</a
-	    > = <a href=""
+	    > = <a href="#"
 	    >A</a
-	    > <a href=""
+	    > <a href="#"
 	    >Int</a
 	    ></li
 	  ><li class="src short"
 	  ><span class="keyword"
 	    >data</span
-	    > <a href=""
+	    > <a href="#"
 	    >B</a
-	    > = <a href=""
+	    > = <a href="#"
 	    >B</a
 	    > {<ul class="subs"
 	    ><li
-	      ><a href=""
+	      ><a href="#"
 		>b</a
-		> :: <a href=""
+		> :: <a href="#"
 		>Int</a
 		></li
 	      ></ul
@@ -82,21 +83,21 @@
 	  ><li class="src short"
 	  ><span class="keyword"
 	    >data</span
-	    > <a href=""
+	    > <a href="#"
 	    >C</a
-	    > = <a href=""
+	    > = <a href="#"
 	    >C</a
 	    > {<ul class="subs"
 	    ><li
-	      ><a href=""
+	      ><a href="#"
 		>c1</a
-		> :: <a href=""
+		> :: <a href="#"
 		>Int</a
 		></li
 	      ><li
-	      ><a href=""
+	      ><a href="#"
 		>c2</a
-		> :: <a href=""
+		> :: <a href="#"
 		>Int</a
 		></li
 	      ></ul
@@ -104,23 +105,23 @@
 	  ><li class="src short"
 	  ><span class="keyword"
 	    >data</span
-	    > <a href=""
+	    > <a href="#"
 	    >D</a
-	    > = <a href=""
+	    > = <a href="#"
 	    >D</a
-	    > <a href=""
+	    > <a href="#"
 	    >Int</a
-	    > <a href=""
+	    > <a href="#"
 	    >Int</a
 	    ></li
 	  ><li class="src short"
 	  ><span class="keyword"
 	    >newtype</span
-	    > <a href=""
+	    > <a href="#"
 	    >E</a
-	    > = <a href=""
+	    > = <a href="#"
 	    >E</a
-	    > <a href=""
+	    > <a href="#"
 	    >Int</a
 	    ></li
 	  ></ul
@@ -132,8 +133,10 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >data</span
-	    > <a name="t:A" class="def"
+	    > <a id="t:A" class="def"
 	    >A</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="doc"
 	  ><p
@@ -145,13 +148,13 @@
 	    ><table
 	    ><tr
 	      ><td class="src"
-		><a name="v:A" class="def"
+		><a id="v:A" class="def"
 		  >A</a
-		  > <a href=""
+		  > <a href="#"
 		  >Int</a
 		  ></td
 		><td class="doc empty"
-		>&nbsp;</td
+		></td
 		></tr
 	      ></table
 	    ></div
@@ -160,8 +163,10 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >data</span
-	    > <a name="t:B" class="def"
+	    > <a id="t:B" class="def"
 	    >B</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="doc"
 	  ><p
@@ -174,29 +179,29 @@
 	    ><table
 	    ><tr
 	      ><td class="src"
-		><a name="v:B" class="def"
+		><a id="v:B" class="def"
 		  >B</a
 		  ></td
 		><td class="doc empty"
-		>&nbsp;</td
+		></td
 		></tr
 	      ><tr
 	      ><td colspan="2"
 		><div class="subs fields"
 		  ><p class="caption"
 		    >Fields</p
-		    ><dl
-		    ><dt class="src"
-		      ><a name="v:b" class="def"
-			>b</a
-			> :: <a href=""
-			>Int</a
-			></dt
-		      ><dd class="doc empty"
-		      >&nbsp;</dd
-		      ></dl
-		    ><div class="clear"
-		    ></div
+		    ><ul
+		    ><li
+		      ><dfn class="src"
+			><a id="v:b" class="def"
+			  >b</a
+			  > :: <a href="#"
+			  >Int</a
+			  ></dfn
+			><div class="doc empty"
+			></div
+			></li
+		      ></ul
 		    ></div
 		  ></td
 		></tr
@@ -207,8 +212,10 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >data</span
-	    > <a name="t:C" class="def"
+	    > <a id="t:C" class="def"
 	    >C</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="doc"
 	  ><p
@@ -220,37 +227,39 @@
 	    ><table
 	    ><tr
 	      ><td class="src"
-		><a name="v:C" class="def"
+		><a id="v:C" class="def"
 		  >C</a
 		  ></td
 		><td class="doc empty"
-		>&nbsp;</td
+		></td
 		></tr
 	      ><tr
 	      ><td colspan="2"
 		><div class="subs fields"
 		  ><p class="caption"
 		    >Fields</p
-		    ><dl
-		    ><dt class="src"
-		      ><a name="v:c1" class="def"
-			>c1</a
-			> :: <a href=""
-			>Int</a
-			></dt
-		      ><dd class="doc empty"
-		      >&nbsp;</dd
-		      ><dt class="src"
-		      ><a name="v:c2" class="def"
-			>c2</a
-			> :: <a href=""
-			>Int</a
-			></dt
-		      ><dd class="doc empty"
-		      >&nbsp;</dd
-		      ></dl
-		    ><div class="clear"
-		    ></div
+		    ><ul
+		    ><li
+		      ><dfn class="src"
+			><a id="v:c1" class="def"
+			  >c1</a
+			  > :: <a href="#"
+			  >Int</a
+			  ></dfn
+			><div class="doc empty"
+			></div
+			></li
+		      ><li
+		      ><dfn class="src"
+			><a id="v:c2" class="def"
+			  >c2</a
+			  > :: <a href="#"
+			  >Int</a
+			  ></dfn
+			><div class="doc empty"
+			></div
+			></li
+		      ></ul
 		    ></div
 		  ></td
 		></tr
@@ -261,8 +270,10 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >data</span
-	    > <a name="t:D" class="def"
+	    > <a id="t:D" class="def"
 	    >D</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="doc"
 	  ><p
@@ -275,15 +286,15 @@
 	    ><table
 	    ><tr
 	      ><td class="src"
-		><a name="v:D" class="def"
+		><a id="v:D" class="def"
 		  >D</a
-		  > <a href=""
+		  > <a href="#"
 		  >Int</a
-		  > <a href=""
+		  > <a href="#"
 		  >Int</a
 		  ></td
 		><td class="doc empty"
-		>&nbsp;</td
+		></td
 		></tr
 	      ></table
 	    ></div
@@ -292,8 +303,10 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >newtype</span
-	    > <a name="t:E" class="def"
+	    > <a id="t:E" class="def"
 	    >E</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="doc"
 	  ><p
@@ -305,13 +318,13 @@
 	    ><table
 	    ><tr
 	      ><td class="src"
-		><a name="v:E" class="def"
+		><a id="v:E" class="def"
 		  >E</a
-		  > <a href=""
+		  > <a href="#"
 		  >Int</a
 		  ></td
 		><td class="doc empty"
-		>&nbsp;</td
+		></td
 		></tr
 	      ></table
 	    ></div
@@ -319,11 +332,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.15.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/Bug7.html b/html-test/ref/Bug7.html
--- a/html-test/ref/Bug7.html
+++ b/html-test/ref/Bug7.html
@@ -1,32 +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
     >Bug7</title
-    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_Bug7.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_Bug7.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -57,15 +58,15 @@
 	><li class="src short"
 	  ><span class="keyword"
 	    >data</span
-	    > <a href=""
+	    > <a href="#"
 	    >Foo</a
-	    > = <a href=""
+	    > = <a href="#"
 	    >Foo</a
 	    ></li
 	  ><li class="src short"
 	  ><span class="keyword"
 	    >class</span
-	    > <a href=""
+	    > <a href="#"
 	    >Bar</a
 	    > x y</li
 	  ></ul
@@ -77,8 +78,10 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >data</span
-	    > <a name="t:Foo" class="def"
+	    > <a id="t:Foo" class="def"
 	    >Foo</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="doc"
 	  ><p
@@ -90,11 +93,11 @@
 	    ><table
 	    ><tr
 	      ><td class="src"
-		><a name="v:Foo" class="def"
+		><a id="v:Foo" class="def"
 		  >Foo</a
 		  ></td
 		><td class="doc empty"
-		>&nbsp;</td
+		></td
 		></tr
 	      ></table
 	    ></div
@@ -106,19 +109,29 @@
 	      ><tr
 		><td class="src clearfix"
 		  ><span class="inst-left"
-		    ><a href=""
+		    ><span id="control.i:id:Foo:Bar:1" class="instance expander" onclick="toggleSection('i:id:Foo:Bar:1')"
+		      ></span
+		      > <a href="#"
 		      >Bar</a
-		      > <a href=""
+		      > <a href="#"
 		      >Foo</a
-		      > <a href=""
+		      > <a href="#"
 		      >Foo</a
 		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
 		    ></td
 		  ><td class="doc"
 		  ><p
 		    >Just one instance</p
 		    ></td
 		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:id:Foo:Bar:1" class="inst-details hide"
+		    ></div
+		    ></td
+		  ></tr
 		></table
 	      ></div
 	    ></div
@@ -127,9 +140,11 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >class</span
-	    > <a name="t:Bar" class="def"
+	    > <a id="t:Bar" class="def"
 	    >Bar</a
-	    > x y</p
+	    > x y <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ><div class="doc"
 	  ><p
 	    >The Bar class</p
@@ -142,19 +157,29 @@
 	      ><tr
 		><td class="src clearfix"
 		  ><span class="inst-left"
-		    ><a href=""
+		    ><span id="control.i:ic:Bar:Bar:1" class="instance expander" onclick="toggleSection('i:ic:Bar:Bar:1')"
+		      ></span
+		      > <a href="#"
 		      >Bar</a
-		      > <a href=""
+		      > <a href="#"
 		      >Foo</a
-		      > <a href=""
+		      > <a href="#"
 		      >Foo</a
 		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
 		    ></td
 		  ><td class="doc"
 		  ><p
 		    >Just one instance</p
 		    ></td
 		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:ic:Bar:Bar:1" class="inst-details hide"
+		    ></div
+		    ></td
+		  ></tr
 		></table
 	      ></div
 	    ></div
@@ -162,11 +187,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.16.1</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/Bug8.html b/html-test/ref/Bug8.html
--- a/html-test/ref/Bug8.html
+++ b/html-test/ref/Bug8.html
@@ -1,32 +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
     >Bug8</title
-    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_Bug8.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_Bug8.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -48,8 +49,10 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >data</span
-	    > <a name="t:Typ" class="def"
+	    > <a id="t:Typ" class="def"
 	    >Typ</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="subs constructors"
 	  ><p class="caption"
@@ -57,85 +60,91 @@
 	    ><table
 	    ><tr
 	      ><td class="src"
-		><a name="v:Type" class="def"
+		><a id="v:Type" class="def"
 		  >Type</a
-		  > (<a href=""
+		  > (<a href="#"
 		  >Typ</a
-		  >, [<a href=""
+		  >, [<a href="#"
 		  >Typ</a
 		  >])</td
 		><td class="doc empty"
-		>&nbsp;</td
+		></td
 		></tr
 	      ><tr
 	      ><td class="src"
-		><a name="v:TFree" class="def"
+		><a id="v:TFree" class="def"
 		  >TFree</a
-		  > (<a href=""
+		  > (<a href="#"
 		  >Typ</a
-		  >, [<a href=""
+		  >, [<a href="#"
 		  >Typ</a
 		  >])</td
 		><td class="doc empty"
-		>&nbsp;</td
+		></td
 		></tr
 	      ></table
 	    ></div
 	  ></div
 	><div class="top"
 	><p class="src"
-	  ><a name="v:-45--45--62-" class="def"
+	  ><a id="v:-45--45--62-" class="def"
 	    >(--&gt;)</a
-	    > :: t -&gt; t1 -&gt; <a href=""
+	    > :: t -&gt; t1 -&gt; <a href="#"
 	    >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 name="v:-45--45--45--62-" class="def"
+	  ><a id="v:-45--45--45--62-" class="def"
 	    >(---&gt;)</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Foldable</a
-	    > t0 =&gt; t0 t -&gt; <a href=""
+	    > t0 =&gt; t0 t -&gt; <a href="#"
 	    >Typ</a
-	    > -&gt; <a href=""
+	    > -&gt; <a href="#"
 	    >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 name="v:s" class="def"
+	  ><a id="v:s" class="def"
 	    >s</a
-	    > :: t</p
+	    > :: a <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ></div
 	><div class="top"
 	><p class="src"
-	  ><a name="v:t" class="def"
+	  ><a id="v:t" class="def"
 	    >t</a
-	    > :: t</p
+	    > :: a <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ></div
 	><div class="top"
 	><p class="src"
-	  ><a name="v:main" class="def"
+	  ><a id="v:main" class="def"
 	    >main</a
-	    > :: t</p
+	    > :: a <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ></div
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.16.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/Bug85.html b/html-test/ref/Bug85.html
--- a/html-test/ref/Bug85.html
+++ b/html-test/ref/Bug85.html
@@ -1,32 +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
     >Bug85</title
-    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_Bug85.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_Bug85.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -48,10 +49,20 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >data</span
-	    > <a name="t:Foo" class="def"
+	    > <a id="t:Foo" class="def"
 	    >Foo</a
-	    > :: (* -&gt; *) -&gt; * -&gt; * <span class="keyword"
+	    > :: (<a href="#"
+	    >*</a
+	    > -&gt; <a href="#"
+	    >*</a
+	    >) -&gt; <a href="#"
+	    >*</a
+	    > -&gt; <a href="#"
+	    >*</a
+	    > <span class="keyword"
 	    >where</span
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="subs constructors"
 	  ><p class="caption"
@@ -59,13 +70,13 @@
 	    ><table
 	    ><tr
 	      ><td class="src"
-		><a name="v:Bar" class="def"
+		><a id="v:Bar" class="def"
 		  >Bar</a
-		  > ::  f x -&gt; <a href=""
+		  > :: f x -&gt; <a href="#"
 		  >Foo</a
 		  > f (f x)</td
 		><td class="doc empty"
-		>&nbsp;</td
+		></td
 		></tr
 	      ></table
 	    ></div
@@ -74,10 +85,14 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >data</span
-	    > <a name="t:Baz" class="def"
+	    > <a id="t:Baz" class="def"
 	    >Baz</a
-	    > :: * <span class="keyword"
+	    > :: <a href="#"
+	    >*</a
+	    > <span class="keyword"
 	    >where</span
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="subs constructors"
 	  ><p class="caption"
@@ -85,13 +100,13 @@
 	    ><table
 	    ><tr
 	      ><td class="src"
-		><a name="v:Baz-39-" class="def"
+		><a id="v:Baz-39-" class="def"
 		  >Baz'</a
-		  > ::  <a href=""
+		  > :: <a href="#"
 		  >Baz</a
 		  ></td
 		><td class="doc empty"
-		>&nbsp;</td
+		></td
 		></tr
 	      ></table
 	    ></div
@@ -100,10 +115,12 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >data</span
-	    > <a name="t:Qux" class="def"
+	    > <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"
@@ -111,13 +128,13 @@
 	    ><table
 	    ><tr
 	      ><td class="src"
-		><a name="v:Quux" class="def"
+		><a id="v:Quux" class="def"
 		  >Quux</a
-		  > ::  <a href=""
+		  > :: <a href="#"
 		  >Qux</a
 		  ></td
 		><td class="doc empty"
-		>&nbsp;</td
+		></td
 		></tr
 	      ></table
 	    ></div
@@ -125,11 +142,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.16.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/BugDeprecated.html b/html-test/ref/BugDeprecated.html
--- a/html-test/ref/BugDeprecated.html
+++ b/html-test/ref/BugDeprecated.html
@@ -1,32 +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
     >BugDeprecated</title
-    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_BugDeprecated.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_BugDeprecated.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -46,39 +47,39 @@
 	>Synopsis</p
 	><ul id="section.syn" class="hide" onclick="toggleSection('syn')"
 	><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >foo</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
 	    ></li
 	  ><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >bar</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
 	    ></li
 	  ><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >baz</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
 	    ></li
 	  ><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >one</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
 	    ></li
 	  ><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >two</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
 	    ></li
 	  ><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >three</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
 	    ></li
 	  ></ul
@@ -88,10 +89,12 @@
 	>Documentation</h1
 	><div class="top"
 	><p class="src"
-	  ><a name="v:foo" class="def"
+	  ><a id="v:foo" class="def"
 	    >foo</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="doc"
 	  ><div class="warning"
@@ -102,10 +105,12 @@
 	  ></div
 	><div class="top"
 	><p class="src"
-	  ><a name="v:bar" class="def"
+	  ><a id="v:bar" class="def"
 	    >bar</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="doc"
 	  ><div class="warning"
@@ -116,10 +121,12 @@
 	  ></div
 	><div class="top"
 	><p class="src"
-	  ><a name="v:baz" class="def"
+	  ><a id="v:baz" class="def"
 	    >baz</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="doc"
 	  ><div class="warning"
@@ -130,10 +137,12 @@
 	  ></div
 	><div class="top"
 	><p class="src"
-	  ><a name="v:one" class="def"
+	  ><a id="v:one" class="def"
 	    >one</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="doc"
 	  ><div class="warning"
@@ -146,10 +155,12 @@
 	  ></div
 	><div class="top"
 	><p class="src"
-	  ><a name="v:two" class="def"
+	  ><a id="v:two" class="def"
 	    >two</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="doc"
 	  ><div class="warning"
@@ -160,10 +171,12 @@
 	  ></div
 	><div class="top"
 	><p class="src"
-	  ><a name="v:three" class="def"
+	  ><a id="v:three" class="def"
 	    >three</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="doc"
 	  ><div class="warning"
@@ -175,11 +188,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.15.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/BugExportHeadings.html b/html-test/ref/BugExportHeadings.html
--- a/html-test/ref/BugExportHeadings.html
+++ b/html-test/ref/BugExportHeadings.html
@@ -1,32 +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
     >BugExportHeadings</title
-    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_BugExportHeadings.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_BugExportHeadings.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -46,27 +47,27 @@
 	>Contents</p
 	><ul
 	><li
-	  ><a href=""
+	  ><a href="#"
 	    >Foo</a
 	    ></li
 	  ><li
-	  ><a href=""
+	  ><a href="#"
 	    >Bar</a
 	    ></li
 	  ><li
-	  ><a href=""
+	  ><a href="#"
 	    >Baz</a
 	    ></li
 	  ><li
-	  ><a href=""
+	  ><a href="#"
 	    >One</a
 	    ></li
 	  ><li
-	  ><a href=""
+	  ><a href="#"
 	    >Two</a
 	    ></li
 	  ><li
-	  ><a href=""
+	  ><a href="#"
 	    >Three</a
 	    ></li
 	  ></ul
@@ -76,39 +77,39 @@
 	>Synopsis</p
 	><ul id="section.syn" class="hide" onclick="toggleSection('syn')"
 	><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >foo</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
 	    ></li
 	  ><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >bar</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
 	    ></li
 	  ><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >baz</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
 	    ></li
 	  ><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >one</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
 	    ></li
 	  ><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >two</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
 	    ></li
 	  ><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >three</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
 	    ></li
 	  ></ul
@@ -118,40 +119,48 @@
 	>Foo</h1
 	><div class="top"
 	><p class="src"
-	  ><a name="v:foo" class="def"
+	  ><a id="v:foo" class="def"
 	    >foo</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ></div
 	><h1 id="g:2"
 	>Bar</h1
 	><div class="top"
 	><p class="src"
-	  ><a name="v:bar" class="def"
+	  ><a id="v:bar" class="def"
 	    >bar</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ></div
 	><h1 id="g:3"
 	>Baz</h1
 	><div class="top"
 	><p class="src"
-	  ><a name="v:baz" class="def"
+	  ><a id="v:baz" class="def"
 	    >baz</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ></div
 	><h1 id="g:4"
 	>One</h1
 	><div class="top"
 	><p class="src"
-	  ><a name="v:one" class="def"
+	  ><a id="v:one" class="def"
 	    >one</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="doc"
 	  ><div class="warning"
@@ -164,10 +173,12 @@
 	>Two</h1
 	><div class="top"
 	><p class="src"
-	  ><a name="v:two" class="def"
+	  ><a id="v:two" class="def"
 	    >two</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="doc"
 	  ><div class="warning"
@@ -180,10 +191,12 @@
 	>Three</h1
 	><div class="top"
 	><p class="src"
-	  ><a name="v:three" class="def"
+	  ><a id="v:three" class="def"
 	    >three</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="doc"
 	  ><div class="warning"
@@ -195,11 +208,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.15.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/Bugs.html b/html-test/ref/Bugs.html
--- a/html-test/ref/Bugs.html
+++ b/html-test/ref/Bugs.html
@@ -1,32 +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
     >Bugs</title
-    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_Bugs.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_Bugs.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -48,22 +49,24 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >data</span
-	    > <a name="t:A" class="def"
+	    > <a id="t:A" class="def"
 	    >A</a
-	    > a</p
+	    > a <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ><div class="subs constructors"
 	  ><p class="caption"
 	    >Constructors</p
 	    ><table
 	    ><tr
 	      ><td class="src"
-		><a name="v:A" class="def"
+		><a id="v:A" class="def"
 		  >A</a
-		  > a (a -&gt; <a href=""
+		  > a (a -&gt; <a href="#"
 		  >Int</a
 		  >)</td
 		><td class="doc empty"
-		>&nbsp;</td
+		></td
 		></tr
 	      ></table
 	    ></div
@@ -71,11 +74,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.15.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/DeprecatedClass.html b/html-test/ref/DeprecatedClass.html
--- a/html-test/ref/DeprecatedClass.html
+++ b/html-test/ref/DeprecatedClass.html
@@ -1,32 +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
     >DeprecatedClass</title
-    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_DeprecatedClass.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_DeprecatedClass.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -48,30 +49,22 @@
 	><li class="src short"
 	  ><span class="keyword"
 	    >class</span
-	    > <a href=""
+	    > <a href="#"
 	    >SomeClass</a
 	    > a <span class="keyword"
 	    >where</span
 	    ><ul class="subs"
-	    ><li
-	      ><a href=""
-		>foo</a
-		> :: a -&gt; a</li
-	      ></ul
+	    ></ul
 	    ></li
 	  ><li class="src short"
 	  ><span class="keyword"
 	    >class</span
-	    > <a href=""
+	    > <a href="#"
 	    >SomeOtherClass</a
 	    > a <span class="keyword"
 	    >where</span
 	    ><ul class="subs"
-	    ><li
-	      ><a href=""
-		>bar</a
-		> :: a -&gt; a</li
-	      ></ul
+	    ></ul
 	    ></li
 	  ></ul
 	></div
@@ -82,10 +75,12 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >class</span
-	    > <a name="t:SomeClass" class="def"
+	    > <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"
@@ -95,13 +90,23 @@
 	    ><p
 	    >some class</p
 	    ></div
+	  ><div class="subs minimal"
+	  ><p class="caption"
+	    >Minimal complete definition</p
+	    ><p class="src"
+	    ><a href="#"
+	      >foo</a
+	      ></p
+	    ></div
 	  ><div class="subs methods"
 	  ><p class="caption"
 	    >Methods</p
 	    ><p class="src"
-	    ><a name="v:foo" class="def"
+	    ><a id="v:foo" class="def"
 	      >foo</a
-	      > :: a -&gt; a</p
+	      > :: a -&gt; a <a href="#" class="selflink"
+	      >#</a
+	      ></p
 	    ><div class="doc"
 	    ><div class="warning"
 	      ><p
@@ -116,10 +121,12 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >class</span
-	    > <a name="t:SomeOtherClass" class="def"
+	    > <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"
@@ -127,13 +134,23 @@
 	      >Deprecated: SomeOtherClass</p
 	      ></div
 	    ></div
+	  ><div class="subs minimal"
+	  ><p class="caption"
+	    >Minimal complete definition</p
+	    ><p class="src"
+	    ><a href="#"
+	      >bar</a
+	      ></p
+	    ></div
 	  ><div class="subs methods"
 	  ><p class="caption"
 	    >Methods</p
 	    ><p class="src"
-	    ><a name="v:bar" class="def"
+	    ><a id="v:bar" class="def"
 	      >bar</a
-	      > :: a -&gt; a</p
+	      > :: a -&gt; a <a href="#" class="selflink"
+	      >#</a
+	      ></p
 	    ><div class="doc"
 	    ><div class="warning"
 	      ><p
@@ -145,11 +162,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.15.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/DeprecatedData.html b/html-test/ref/DeprecatedData.html
--- a/html-test/ref/DeprecatedData.html
+++ b/html-test/ref/DeprecatedData.html
@@ -1,32 +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
     >DeprecatedData</title
-    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_DeprecatedData.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_DeprecatedData.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -48,15 +49,15 @@
 	><li class="src short"
 	  ><span class="keyword"
 	    >data</span
-	    > <a href=""
+	    > <a href="#"
 	    >Foo</a
 	    ><ul class="subs"
 	    ><li
-	      >= <a href=""
+	      >= <a href="#"
 		>Foo</a
 		></li
 	      ><li
-	      >| <a href=""
+	      >| <a href="#"
 		>Bar</a
 		></li
 	      ></ul
@@ -64,15 +65,15 @@
 	  ><li class="src short"
 	  ><span class="keyword"
 	    >data</span
-	    > <a href=""
+	    > <a href="#"
 	    >One</a
 	    ><ul class="subs"
 	    ><li
-	      >= <a href=""
+	      >= <a href="#"
 		>One</a
 		></li
 	      ><li
-	      >| <a href=""
+	      >| <a href="#"
 		>Two</a
 		></li
 	      ></ul
@@ -86,8 +87,10 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >data</span
-	    > <a name="t:Foo" class="def"
+	    > <a id="t:Foo" class="def"
 	    >Foo</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="doc"
 	  ><div class="warning"
@@ -103,7 +106,7 @@
 	    ><table
 	    ><tr
 	      ><td class="src"
-		><a name="v:Foo" class="def"
+		><a id="v:Foo" class="def"
 		  >Foo</a
 		  ></td
 		><td class="doc"
@@ -117,7 +120,7 @@
 		></tr
 	      ><tr
 	      ><td class="src"
-		><a name="v:Bar" class="def"
+		><a id="v:Bar" class="def"
 		  >Bar</a
 		  ></td
 		><td class="doc"
@@ -136,8 +139,10 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >data</span
-	    > <a name="t:One" class="def"
+	    > <a id="t:One" class="def"
 	    >One</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="doc"
 	  ><div class="warning"
@@ -151,7 +156,7 @@
 	    ><table
 	    ><tr
 	      ><td class="src"
-		><a name="v:One" class="def"
+		><a id="v:One" class="def"
 		  >One</a
 		  ></td
 		><td class="doc"
@@ -163,7 +168,7 @@
 		></tr
 	      ><tr
 	      ><td class="src"
-		><a name="v:Two" class="def"
+		><a id="v:Two" class="def"
 		  >Two</a
 		  ></td
 		><td class="doc"
@@ -179,11 +184,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.15.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/DeprecatedFunction.html b/html-test/ref/DeprecatedFunction.html
--- a/html-test/ref/DeprecatedFunction.html
+++ b/html-test/ref/DeprecatedFunction.html
@@ -1,32 +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
     >DeprecatedFunction</title
-    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_DeprecatedFunction.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_DeprecatedFunction.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -46,15 +47,15 @@
 	>Synopsis</p
 	><ul id="section.syn" class="hide" onclick="toggleSection('syn')"
 	><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >foo</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
 	    ></li
 	  ><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >bar</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
 	    ></li
 	  ></ul
@@ -64,16 +65,18 @@
 	>Documentation</h1
 	><div class="top"
 	><p class="src"
-	  ><a name="v:foo" class="def"
+	  ><a id="v:foo" class="def"
 	    >foo</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="doc"
 	  ><div class="warning"
 	    ><p
 	      >Deprecated: use <code
-		><a href=""
+		><a href="#"
 		  >bar</a
 		  ></code
 		> instead</p
@@ -84,10 +87,12 @@
 	  ></div
 	><div class="top"
 	><p class="src"
-	  ><a name="v:bar" class="def"
+	  ><a id="v:bar" class="def"
 	    >bar</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="doc"
 	  ><p
@@ -97,11 +102,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.15.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/DeprecatedFunction2.html b/html-test/ref/DeprecatedFunction2.html
--- a/html-test/ref/DeprecatedFunction2.html
+++ b/html-test/ref/DeprecatedFunction2.html
@@ -1,32 +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"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_DeprecatedFunction2.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_DeprecatedFunction2.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -46,9 +47,9 @@
 	>Synopsis</p
 	><ul id="section.syn" class="hide" onclick="toggleSection('syn')"
 	><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >foo</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
 	    ></li
 	  ></ul
@@ -58,10 +59,12 @@
 	>Documentation</h1
 	><div class="top"
 	><p class="src"
-	  ><a name="v:foo" class="def"
+	  ><a id="v:foo" class="def"
 	    >foo</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="doc"
 	  ><div class="warning"
@@ -73,11 +76,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.15.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/DeprecatedFunction3.html b/html-test/ref/DeprecatedFunction3.html
--- a/html-test/ref/DeprecatedFunction3.html
+++ b/html-test/ref/DeprecatedFunction3.html
@@ -1,32 +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"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_DeprecatedFunction3.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_DeprecatedFunction3.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -46,9 +47,9 @@
 	>Synopsis</p
 	><ul id="section.syn" class="hide" onclick="toggleSection('syn')"
 	><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >foo</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Integer</a
 	    ></li
 	  ></ul
@@ -58,10 +59,12 @@
 	>Documentation</h1
 	><div class="top"
 	><p class="src"
-	  ><a name="v:foo" class="def"
+	  ><a id="v:foo" class="def"
 	    >foo</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Integer</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="doc"
 	  ><div class="warning"
@@ -73,11 +76,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.15.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/DeprecatedModule.html b/html-test/ref/DeprecatedModule.html
--- a/html-test/ref/DeprecatedModule.html
+++ b/html-test/ref/DeprecatedModule.html
@@ -1,32 +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"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_DeprecatedModule.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_DeprecatedModule.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -47,12 +48,12 @@
 	><div class="doc"
 	><div class="warning"
 	  ><p
-	    >Deprecated: Use <a href=""
+	    >Deprecated: Use <a href="#"
 	      >Foo</a
 	      > instead</p
 	    ></div
 	  ><p
-	  >Documentation for <a href=""
+	  >Documentation for <a href="#"
 	    >DeprecatedModule</a
 	    >.</p
 	  ></div
@@ -62,20 +63,18 @@
 	>Documentation</h1
 	><div class="top"
 	><p class="src"
-	  ><a name="v:foo" class="def"
+	  ><a id="v:foo" class="def"
 	    >foo</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ></div
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.15.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/DeprecatedModule2.html b/html-test/ref/DeprecatedModule2.html
--- a/html-test/ref/DeprecatedModule2.html
+++ b/html-test/ref/DeprecatedModule2.html
@@ -1,32 +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"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_DeprecatedModule2.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_DeprecatedModule2.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -56,20 +57,18 @@
 	>Documentation</h1
 	><div class="top"
 	><p class="src"
-	  ><a name="v:foo" class="def"
+	  ><a id="v:foo" class="def"
 	    >foo</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ></div
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.15.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/DeprecatedNewtype.html b/html-test/ref/DeprecatedNewtype.html
--- a/html-test/ref/DeprecatedNewtype.html
+++ b/html-test/ref/DeprecatedNewtype.html
@@ -1,32 +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
     >DeprecatedNewtype</title
-    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_DeprecatedNewtype.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_DeprecatedNewtype.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -48,21 +49,21 @@
 	><li class="src short"
 	  ><span class="keyword"
 	    >newtype</span
-	    > <a href=""
+	    > <a href="#"
 	    >SomeNewType</a
-	    > = <a href=""
+	    > = <a href="#"
 	    >SomeNewTypeConst</a
-	    > <a href=""
+	    > <a href="#"
 	    >String</a
 	    ></li
 	  ><li class="src short"
 	  ><span class="keyword"
 	    >newtype</span
-	    > <a href=""
+	    > <a href="#"
 	    >SomeOtherNewType</a
-	    > = <a href=""
+	    > = <a href="#"
 	    >SomeOtherNewTypeConst</a
-	    > <a href=""
+	    > <a href="#"
 	    >String</a
 	    ></li
 	  ></ul
@@ -74,8 +75,10 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >newtype</span
-	    > <a name="t:SomeNewType" class="def"
+	    > <a id="t:SomeNewType" class="def"
 	    >SomeNewType</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="doc"
 	  ><div class="warning"
@@ -91,9 +94,9 @@
 	    ><table
 	    ><tr
 	      ><td class="src"
-		><a name="v:SomeNewTypeConst" class="def"
+		><a id="v:SomeNewTypeConst" class="def"
 		  >SomeNewTypeConst</a
-		  > <a href=""
+		  > <a href="#"
 		  >String</a
 		  ></td
 		><td class="doc"
@@ -112,8 +115,10 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >newtype</span
-	    > <a name="t:SomeOtherNewType" class="def"
+	    > <a id="t:SomeOtherNewType" class="def"
 	    >SomeOtherNewType</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="doc"
 	  ><div class="warning"
@@ -127,9 +132,9 @@
 	    ><table
 	    ><tr
 	      ><td class="src"
-		><a name="v:SomeOtherNewTypeConst" class="def"
+		><a id="v:SomeOtherNewTypeConst" class="def"
 		  >SomeOtherNewTypeConst</a
-		  > <a href=""
+		  > <a href="#"
 		  >String</a
 		  ></td
 		><td class="doc"
@@ -145,11 +150,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.15.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/DeprecatedReExport.html b/html-test/ref/DeprecatedReExport.html
--- a/html-test/ref/DeprecatedReExport.html
+++ b/html-test/ref/DeprecatedReExport.html
@@ -1,32 +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
     >DeprecatedReExport</title
-    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_DeprecatedReExport.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_DeprecatedReExport.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -46,11 +47,11 @@
 	>Contents</p
 	><ul
 	><li
-	  ><a href=""
+	  ><a href="#"
 	    >Re-exported from an other module</a
 	    ></li
 	  ><li
-	  ><a href=""
+	  ><a href="#"
 	    >Re-exported from an other package</a
 	    ></li
 	  ></ul
@@ -72,9 +73,9 @@
 	>Synopsis</p
 	><ul id="section.syn" class="hide" onclick="toggleSection('syn')"
 	><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >foo</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
 	    ></li
 	  ></ul
@@ -84,16 +85,18 @@
 	>Re-exported from an other module</h1
 	><div class="top"
 	><p class="src"
-	  ><a name="v:foo" class="def"
+	  ><a id="v:foo" class="def"
 	    >foo</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="doc"
 	  ><div class="warning"
 	    ><p
 	      >Deprecated: use <code
-		><a href=""
+		><a href="#"
 		  >bar</a
 		  ></code
 		> instead</p
@@ -106,7 +109,7 @@
 	>Re-exported from an other package</h1
 	><div class="doc"
 	><p
-	  >Not yet working, see <a href=""
+	  >Not yet working, see <a href="#"
 	    >http://trac.haskell.org/haddock/ticket/223</a
 	    >
  , isEmptyChan</p
@@ -114,11 +117,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.15.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/DeprecatedRecord.html b/html-test/ref/DeprecatedRecord.html
--- a/html-test/ref/DeprecatedRecord.html
+++ b/html-test/ref/DeprecatedRecord.html
@@ -1,32 +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
     >DeprecatedRecord</title
-    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_DeprecatedRecord.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_DeprecatedRecord.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -48,21 +49,21 @@
 	><li class="src short"
 	  ><span class="keyword"
 	    >data</span
-	    > <a href=""
+	    > <a href="#"
 	    >Foo</a
-	    > = <a href=""
+	    > = <a href="#"
 	    >Foo</a
 	    > {<ul class="subs"
 	    ><li
-	      ><a href=""
+	      ><a href="#"
 		>fooName</a
-		> :: <a href=""
+		> :: <a href="#"
 		>String</a
 		></li
 	      ><li
-	      ><a href=""
+	      ><a href="#"
 		>fooValue</a
-		> :: <a href=""
+		> :: <a href="#"
 		>Int</a
 		></li
 	      ></ul
@@ -76,8 +77,10 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >data</span
-	    > <a name="t:Foo" class="def"
+	    > <a id="t:Foo" class="def"
 	    >Foo</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="doc"
 	  ><p
@@ -89,45 +92,47 @@
 	    ><table
 	    ><tr
 	      ><td class="src"
-		><a name="v:Foo" class="def"
+		><a id="v:Foo" class="def"
 		  >Foo</a
 		  ></td
 		><td class="doc empty"
-		>&nbsp;</td
+		></td
 		></tr
 	      ><tr
 	      ><td colspan="2"
 		><div class="subs fields"
 		  ><p class="caption"
 		    >Fields</p
-		    ><dl
-		    ><dt class="src"
-		      ><a name="v:fooName" class="def"
-			>fooName</a
-			> :: <a href=""
-			>String</a
-			></dt
-		      ><dd class="doc"
-		      ><p
-			>some name</p
-			></dd
-		      ><dt class="src"
-		      ><a name="v:fooValue" class="def"
-			>fooValue</a
-			> :: <a href=""
-			>Int</a
-			></dt
-		      ><dd class="doc"
-		      ><div class="warning"
+		    ><ul
+		    ><li
+		      ><dfn class="src"
+			><a id="v:fooName" class="def"
+			  >fooName</a
+			  > :: <a href="#"
+			  >String</a
+			  ></dfn
+			><div class="doc"
 			><p
-			  >Deprecated: do not use this</p
+			  >some name</p
 			  ></div
-			><p
-			>some value</p
-			></dd
-		      ></dl
-		    ><div class="clear"
-		    ></div
+			></li
+		      ><li
+		      ><dfn class="src"
+			><a id="v:fooValue" class="def"
+			  >fooValue</a
+			  > :: <a href="#"
+			  >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
@@ -137,11 +142,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.15.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/DeprecatedTypeFamily.html b/html-test/ref/DeprecatedTypeFamily.html
--- a/html-test/ref/DeprecatedTypeFamily.html
+++ b/html-test/ref/DeprecatedTypeFamily.html
@@ -1,32 +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
     >DeprecatedTypeFamily</title
-    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_DeprecatedTypeFamily.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_DeprecatedTypeFamily.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -48,15 +49,23 @@
 	><li class="src short"
 	  ><span class="keyword"
 	    >data family</span
-	    > <a href=""
+	    > <a href="#"
 	    >SomeTypeFamily</a
-	    > k :: * -&gt; *</li
+	    > k :: <a href="#"
+	    >*</a
+	    > -&gt; <a href="#"
+	    >*</a
+	    ></li
 	  ><li class="src short"
 	  ><span class="keyword"
 	    >data family</span
-	    > <a href=""
+	    > <a href="#"
 	    >SomeOtherTypeFamily</a
-	    > k :: * -&gt; *</li
+	    > k :: <a href="#"
+	    >*</a
+	    > -&gt; <a href="#"
+	    >*</a
+	    ></li
 	  ></ul
 	></div
       ><div id="interface"
@@ -66,9 +75,15 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >data family</span
-	    > <a name="t:SomeTypeFamily" class="def"
+	    > <a id="t:SomeTypeFamily" class="def"
 	    >SomeTypeFamily</a
-	    > k :: * -&gt; *</p
+	    > k :: <a href="#"
+	    >*</a
+	    > -&gt; <a href="#"
+	    >*</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ><div class="doc"
 	  ><div class="warning"
 	    ><p
@@ -82,9 +97,15 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >data family</span
-	    > <a name="t:SomeOtherTypeFamily" class="def"
+	    > <a id="t:SomeOtherTypeFamily" class="def"
 	    >SomeOtherTypeFamily</a
-	    > k :: * -&gt; *</p
+	    > k :: <a href="#"
+	    >*</a
+	    > -&gt; <a href="#"
+	    >*</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ><div class="doc"
 	  ><div class="warning"
 	    ><p
@@ -95,11 +116,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.16.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/DeprecatedTypeSynonym.html b/html-test/ref/DeprecatedTypeSynonym.html
--- a/html-test/ref/DeprecatedTypeSynonym.html
+++ b/html-test/ref/DeprecatedTypeSynonym.html
@@ -1,32 +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
     >DeprecatedTypeSynonym</title
-    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_DeprecatedTypeSynonym.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_DeprecatedTypeSynonym.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -48,17 +49,17 @@
 	><li class="src short"
 	  ><span class="keyword"
 	    >type</span
-	    > <a href=""
+	    > <a href="#"
 	    >TypeSyn</a
-	    > = <a href=""
+	    > = <a href="#"
 	    >String</a
 	    ></li
 	  ><li class="src short"
 	  ><span class="keyword"
 	    >type</span
-	    > <a href=""
+	    > <a href="#"
 	    >OtherTypeSyn</a
-	    > = <a href=""
+	    > = <a href="#"
 	    >String</a
 	    ></li
 	  ></ul
@@ -70,10 +71,12 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >type</span
-	    > <a name="t:TypeSyn" class="def"
+	    > <a id="t:TypeSyn" class="def"
 	    >TypeSyn</a
-	    > = <a href=""
+	    > = <a href="#"
 	    >String</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="doc"
 	  ><div class="warning"
@@ -88,10 +91,12 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >type</span
-	    > <a name="t:OtherTypeSyn" class="def"
+	    > <a id="t:OtherTypeSyn" class="def"
 	    >OtherTypeSyn</a
-	    > = <a href=""
+	    > = <a href="#"
 	    >String</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="doc"
 	  ><div class="warning"
@@ -103,11 +108,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.15.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/Examples.html b/html-test/ref/Examples.html
--- a/html-test/ref/Examples.html
+++ b/html-test/ref/Examples.html
@@ -1,32 +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"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_Examples.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_Examples.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -46,11 +47,11 @@
 	>Synopsis</p
 	><ul id="section.syn" class="hide" onclick="toggleSection('syn')"
 	><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >fib</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Integer</a
-	    > -&gt; <a href=""
+	    > -&gt; <a href="#"
 	    >Integer</a
 	    ></li
 	  ></ul
@@ -60,17 +61,19 @@
 	>Documentation</h1
 	><div class="top"
 	><p class="src"
-	  ><a name="v:fib" class="def"
+	  ><a id="v:fib" class="def"
 	    >fib</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Integer</a
-	    > -&gt; <a href=""
+	    > -&gt; <a href="#"
 	    >Integer</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="doc"
 	  ><p
 	    >Fibonacci number of given <code
-	      ><a href=""
+	      ><a href="#"
 		>Integer</a
 		></code
 	      >.</p
@@ -164,11 +167,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.15.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/Extensions.html b/html-test/ref/Extensions.html
--- a/html-test/ref/Extensions.html
+++ b/html-test/ref/Extensions.html
@@ -1,32 +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
     >Extensions</title
-    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_Extensions.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_Extensions.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -58,7 +59,7 @@
 	>Synopsis</p
 	><ul id="section.syn" class="hide" onclick="toggleSection('syn')"
 	><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >foobar</a
 	    > :: t</li
 	  ></ul
@@ -68,9 +69,11 @@
 	>Documentation</h1
 	><div class="top"
 	><p class="src"
-	  ><a name="v:foobar" class="def"
+	  ><a id="v:foobar" class="def"
 	    >foobar</a
-	    > :: t</p
+	    > :: t <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ><div class="doc"
 	  ><p
 	    >Bar</p
@@ -79,11 +82,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.15.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/FunArgs.html b/html-test/ref/FunArgs.html
--- a/html-test/ref/FunArgs.html
+++ b/html-test/ref/FunArgs.html
@@ -1,32 +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
     >FunArgs</title
-    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_FunArgs.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_FunArgs.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -46,8 +47,10 @@
 	>Documentation</h1
 	><div class="top"
 	><p class="src"
-	  ><a name="v:f" class="def"
+	  ><a id="v:f" class="def"
 	    >f</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="subs arguments"
 	  ><p class="caption"
@@ -55,15 +58,15 @@
 	    ><table
 	    ><tr
 	      ><td class="src"
-		>:: <a href=""
+		>:: <a href="#"
 		  >Ord</a
 		  > a</td
 		><td class="doc empty"
-		>&nbsp;</td
+		></td
 		></tr
 	      ><tr
 	      ><td class="src"
-		>=&gt; <a href=""
+		>=&gt; <a href="#"
 		  >Int</a
 		  ></td
 		><td class="doc"
@@ -81,7 +84,7 @@
 		></tr
 	      ><tr
 	      ><td class="src"
-		>-&gt; <a href=""
+		>-&gt; <a href="#"
 		  >Bool</a
 		  ></td
 		><td class="doc"
@@ -110,8 +113,10 @@
 	  ></div
 	><div class="top"
 	><p class="src"
-	  ><a name="v:g" class="def"
+	  ><a id="v:g" class="def"
 	    >g</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="subs arguments"
 	  ><p class="caption"
@@ -154,8 +159,10 @@
 	  ></div
 	><div class="top"
 	><p class="src"
-	  ><a name="v:h" class="def"
+	  ><a id="v:h" class="def"
 	    >h</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="subs arguments"
 	  ><p class="caption"
@@ -198,8 +205,10 @@
 	  ></div
 	><div class="top"
 	><p class="src"
-	  ><a name="v:i" class="def"
+	  ><a id="v:i" class="def"
 	    >i</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="subs arguments"
 	  ><p class="caption"
@@ -209,13 +218,11 @@
 	      ><td class="src"
 		>:: <span class="keyword"
 		  >forall</span
-		  > (b :: <a href=""
-		  >()</a
-		  >). (d ~ <a href=""
+		  > (b :: ()). d ~ <a href="#"
 		  >()</a
-		  >)</td
+		  ></td
 		><td class="doc empty"
-		>&nbsp;</td
+		></td
 		></tr
 	      ><tr
 	      ><td class="src"
@@ -238,8 +245,10 @@
 	  ></div
 	><div class="top"
 	><p class="src"
-	  ><a name="v:j" class="def"
+	  ><a id="v:j" class="def"
 	    >j</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="subs arguments"
 	  ><p class="caption"
@@ -249,9 +258,7 @@
 	      ><td class="src"
 		>:: <span class="keyword"
 		  >forall</span
-		  > (a :: <a href=""
-		  >()</a
-		  >). proxy a</td
+		  > (a :: ()). proxy a</td
 		><td class="doc"
 		><p
 		  >First argument</p
@@ -271,11 +278,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.15.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/GADTRecords.html b/html-test/ref/GADTRecords.html
--- a/html-test/ref/GADTRecords.html
+++ b/html-test/ref/GADTRecords.html
@@ -1,32 +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
     >GADTRecords</title
-    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_GADTRecords.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_GADTRecords.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -48,55 +49,41 @@
 	><li class="src short"
 	  ><span class="keyword"
 	    >data</span
-	    > <a href=""
+	    > <a href="#"
 	    >H1</a
 	    > a b <span class="keyword"
 	    >where</span
 	    ><ul class="subs"
 	    ><li
-	      ><a href=""
+	      ><a href="#"
 		>C1</a
-		> ::  <a href=""
+		> :: <a href="#"
 		>H1</a
 		> a b</li
 	      ><li
-	      ><a href=""
+	      ><a href="#"
 		>C2</a
-		> :: <a href=""
+		> :: <a href="#"
 		>Ord</a
-		> a =&gt; [a] -&gt; <a href=""
+		> a =&gt; [a] -&gt; <a href="#"
 		>H1</a
 		> a a</li
 	      ><li
-	      ><a href=""
+	      ><a href="#"
 		>C3</a
-		> :: { <ul class="subs"
-		><li
-		  ><a href=""
-		    >field</a
-		    > :: <a href=""
-		    >Int</a
-		    ></li
-		  ></ul
-		> } -&gt; <a href=""
+		> :: {..} -&gt; <a href="#"
 		>H1</a
-		> <a href=""
+		> <a href="#"
 		>Int</a
-		> <a href=""
+		> <a href="#"
 		>Int</a
 		></li
 	      ><li
-	      ><a href=""
+	      ><a href="#"
 		>C4</a
-		> :: { <ul class="subs"
-		><li
-		  ><a href=""
-		    >field2</a
-		    > :: a</li
-		  ></ul
-		> } -&gt; <a href=""
+		> :: {..} -&gt; <a href="#"
 		>H1</a
-		> <a href=""
+		> <a href="#"
 		>Int</a
 		> a</li
 	      ></ul
@@ -110,10 +97,12 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >data</span
-	    > <a name="t:H1" class="def"
+	    > <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
@@ -125,93 +114,91 @@
 	    ><table
 	    ><tr
 	      ><td class="src"
-		><a name="v:C1" class="def"
+		><a id="v:C1" class="def"
 		  >C1</a
-		  > ::  <a href=""
+		  > :: <a href="#"
 		  >H1</a
 		  > a b</td
 		><td class="doc empty"
-		>&nbsp;</td
+		></td
 		></tr
 	      ><tr
 	      ><td class="src"
-		><a name="v:C2" class="def"
+		><a id="v:C2" class="def"
 		  >C2</a
-		  > :: <a href=""
+		  > :: <a href="#"
 		  >Ord</a
-		  > a =&gt; [a] -&gt; <a href=""
+		  > a =&gt; [a] -&gt; <a href="#"
 		  >H1</a
 		  > a a</td
 		><td class="doc empty"
-		>&nbsp;</td
+		></td
 		></tr
 	      ><tr
 	      ><td class="src"
-		><a name="v:C3" class="def"
+		><a id="v:C3" class="def"
 		  >C3</a
-		  > ::  <a href=""
-		  >Int</a
-		  > -&gt; <a href=""
+		  > :: {..} -&gt; <a href="#"
 		  >H1</a
-		  > <a href=""
+		  > <a href="#"
 		  >Int</a
-		  > <a href=""
+		  > <a href="#"
 		  >Int</a
 		  ></td
 		><td class="doc empty"
-		>&nbsp;</td
+		></td
 		></tr
 	      ><tr
 	      ><td colspan="2"
 		><div class="subs fields"
 		  ><p class="caption"
 		    >Fields</p
-		    ><dl
-		    ><dt class="src"
-		      ><a name="v:field" class="def"
-			>field</a
-			> :: <a href=""
-			>Int</a
-			></dt
-		      ><dd class="doc"
-		      ><p
-			>hello docs</p
-			></dd
-		      ></dl
-		    ><div class="clear"
-		    ></div
+		    ><ul
+		    ><li
+		      ><dfn class="src"
+			><a id="v:field" class="def"
+			  >field</a
+			  > :: <a href="#"
+			  >Int</a
+			  ></dfn
+			><div class="doc"
+			><p
+			  >hello docs</p
+			  ></div
+			></li
+		      ></ul
 		    ></div
 		  ></td
 		></tr
 	      ><tr
 	      ><td class="src"
-		><a name="v:C4" class="def"
+		><a id="v:C4" class="def"
 		  >C4</a
-		  > ::  a -&gt; <a href=""
+		  > :: {..} -&gt; <a href="#"
 		  >H1</a
-		  > <a href=""
+		  > <a href="#"
 		  >Int</a
 		  > a</td
 		><td class="doc empty"
-		>&nbsp;</td
+		></td
 		></tr
 	      ><tr
 	      ><td colspan="2"
 		><div class="subs fields"
 		  ><p class="caption"
 		    >Fields</p
-		    ><dl
-		    ><dt class="src"
-		      ><a name="v:field2" class="def"
-			>field2</a
-			> :: a</dt
-		      ><dd class="doc"
-		      ><p
-			>hello2 docs</p
-			></dd
-		      ></dl
-		    ><div class="clear"
-		    ></div
+		    ><ul
+		    ><li
+		      ><dfn class="src"
+			><a id="v:field2" class="def"
+			  >field2</a
+			  > :: a</dfn
+			><div class="doc"
+			><p
+			  >hello2 docs</p
+			  ></div
+			></li
+		      ></ul
 		    ></div
 		  ></td
 		></tr
@@ -221,11 +208,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.15.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/Hash.html b/html-test/ref/Hash.html
--- a/html-test/ref/Hash.html
+++ b/html-test/ref/Hash.html
@@ -1,32 +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
     >Hash</title
-    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_Hash.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_Hash.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -46,13 +47,13 @@
 	>Contents</p
 	><ul
 	><li
-	  ><a href=""
+	  ><a href="#"
 	    >The <code
 	      >HashTable</code
 	      > type</a
 	    ><ul
 	    ><li
-	      ><a href=""
+	      ><a href="#"
 		>Operations on <code
 		  >HashTable</code
 		  >s</a
@@ -60,7 +61,7 @@
 	      ></ul
 	    ></li
 	  ><li
-	  ><a href=""
+	  ><a href="#"
 	    >The <code
 	      >Hash</code
 	      > class</a
@@ -83,58 +84,52 @@
 	><li class="src short"
 	  ><span class="keyword"
 	    >data</span
-	    > <a href=""
+	    > <a href="#"
 	    >HashTable</a
 	    > key val</li
 	  ><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >new</a
-	    > :: (<a href=""
+	    > :: (<a href="#"
 	    >Eq</a
-	    > key, <a href=""
+	    > key, <a href="#"
 	    >Hash</a
-	    > key) =&gt; <a href=""
+	    > key) =&gt; <a href="#"
 	    >Int</a
-	    > -&gt; <a href=""
+	    > -&gt; <a href="#"
 	    >IO</a
-	    > (<a href=""
+	    > (<a href="#"
 	    >HashTable</a
 	    > key val)</li
 	  ><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >insert</a
-	    > :: (<a href=""
+	    > :: (<a href="#"
 	    >Eq</a
-	    > key, <a href=""
+	    > key, <a href="#"
 	    >Hash</a
-	    > key) =&gt; key -&gt; val -&gt; <a href=""
+	    > key) =&gt; key -&gt; val -&gt; <a href="#"
 	    >IO</a
 	    > ()</li
 	  ><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >lookup</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Hash</a
-	    > key =&gt; key -&gt; <a href=""
+	    > key =&gt; key -&gt; <a href="#"
 	    >IO</a
-	    > (<a href=""
+	    > (<a href="#"
 	    >Maybe</a
 	    > val)</li
 	  ><li class="src short"
 	  ><span class="keyword"
 	    >class</span
-	    > <a href=""
+	    > <a href="#"
 	    >Hash</a
 	    > a <span class="keyword"
 	    >where</span
 	    ><ul class="subs"
-	    ><li
-	      ><a href=""
-		>hash</a
-		> :: a -&gt; <a href=""
-		>Int</a
-		></li
-	      ></ul
+	    ></ul
 	    ></li
 	  ></ul
 	></div
@@ -147,9 +142,11 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >data</span
-	    > <a name="t:HashTable" class="def"
+	    > <a id="t:HashTable" class="def"
 	    >HashTable</a
-	    > key val</p
+	    > key val <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ><div class="doc"
 	  ><p
 	    >A hash table with keys of type <code
@@ -160,7 +157,7 @@
  The type <code
 	      >key</code
 	      > should be an instance of <code
-	      ><a href=""
+	      ><a href="#"
 		>Eq</a
 		></code
 	      >.</p
@@ -172,19 +169,21 @@
 	  >s</h2
 	><div class="top"
 	><p class="src"
-	  ><a name="v:new" class="def"
+	  ><a id="v:new" class="def"
 	    >new</a
-	    > :: (<a href=""
+	    > :: (<a href="#"
 	    >Eq</a
-	    > key, <a href=""
+	    > key, <a href="#"
 	    >Hash</a
-	    > key) =&gt; <a href=""
+	    > key) =&gt; <a href="#"
 	    >Int</a
-	    > -&gt; <a href=""
+	    > -&gt; <a href="#"
 	    >IO</a
-	    > (<a href=""
+	    > (<a href="#"
 	    >HashTable</a
-	    > key val)</p
+	    > key val) <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ><div class="doc"
 	  ><p
 	    >Builds a new hash table with a given size</p
@@ -192,15 +191,17 @@
 	  ></div
 	><div class="top"
 	><p class="src"
-	  ><a name="v:insert" class="def"
+	  ><a id="v:insert" class="def"
 	    >insert</a
-	    > :: (<a href=""
+	    > :: (<a href="#"
 	    >Eq</a
-	    > key, <a href=""
+	    > key, <a href="#"
 	    >Hash</a
-	    > key) =&gt; key -&gt; val -&gt; <a href=""
+	    > key) =&gt; key -&gt; val -&gt; <a href="#"
 	    >IO</a
-	    > ()</p
+	    > () <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ><div class="doc"
 	  ><p
 	    >Inserts a new element into the hash table</p
@@ -208,26 +209,28 @@
 	  ></div
 	><div class="top"
 	><p class="src"
-	  ><a name="v:lookup" class="def"
+	  ><a id="v:lookup" class="def"
 	    >lookup</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Hash</a
-	    > key =&gt; key -&gt; <a href=""
+	    > key =&gt; key -&gt; <a href="#"
 	    >IO</a
-	    > (<a href=""
+	    > (<a href="#"
 	    >Maybe</a
-	    > val)</p
+	    > val) <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ><div class="doc"
 	  ><p
 	    >Looks up a key in the hash table, returns <code
 	      ><code
-		><a href=""
+		><a href="#"
 		  >Just</a
 		  ></code
 		> val</code
 	      > if the key
  was found, or <code
-	      ><a href=""
+	      ><a href="#"
 		>Nothing</a
 		></code
 	      > otherwise.</p
@@ -241,30 +244,42 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >class</span
-	    > <a name="t:Hash" class="def"
+	    > <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 minimal"
+	  ><p class="caption"
+	    >Minimal complete definition</p
+	    ><p class="src"
+	    ><a href="#"
+	      >hash</a
+	      ></p
+	    ></div
 	  ><div class="subs methods"
 	  ><p class="caption"
 	    >Methods</p
 	    ><p class="src"
-	    ><a name="v:hash" class="def"
+	    ><a id="v:hash" class="def"
 	      >hash</a
-	      > :: a -&gt; <a href=""
+	      > :: a -&gt; <a href="#"
 	      >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=""
+		><a href="#"
 		  >Int</a
 		  ></code
 		></p
@@ -278,41 +293,111 @@
 	      ><tr
 		><td class="src clearfix"
 		  ><span class="inst-left"
-		    ><a href=""
+		    ><span id="control.i:ic:Hash:Hash:1" class="instance expander" onclick="toggleSection('i:ic:Hash:Hash:1')"
+		      ></span
+		      > <a href="#"
 		      >Hash</a
-		      > <a href=""
+		      > <a href="#"
 		      >Float</a
 		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
 		    ></td
 		  ><td class="doc empty"
-		  >&nbsp;</td
+		  ></td
 		  ></tr
 		><tr
+		><td colspan="2"
+		  ><div id="section.i:ic:Hash:Hash:1" class="inst-details hide"
+		    ><div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >hash</a
+			  > :: <a href="#"
+			  >Float</a
+			  > -&gt; <a href="#"
+			  >Int</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></div
+		    ></td
+		  ></tr
+		><tr
 		><td class="src clearfix"
 		  ><span class="inst-left"
-		    ><a href=""
+		    ><span id="control.i:ic:Hash:Hash:2" class="instance expander" onclick="toggleSection('i:ic:Hash:Hash:2')"
+		      ></span
+		      > <a href="#"
 		      >Hash</a
-		      > <a href=""
+		      > <a href="#"
 		      >Int</a
 		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
 		    ></td
 		  ><td class="doc empty"
-		  >&nbsp;</td
+		  ></td
 		  ></tr
 		><tr
+		><td colspan="2"
+		  ><div id="section.i:ic:Hash:Hash:2" class="inst-details hide"
+		    ><div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >hash</a
+			  > :: <a href="#"
+			  >Int</a
+			  > -&gt; <a href="#"
+			  >Int</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></div
+		    ></td
+		  ></tr
+		><tr
 		><td class="src clearfix"
 		  ><span class="inst-left"
-		    >(<a href=""
+		    ><span id="control.i:ic:Hash:Hash:3" class="instance expander" onclick="toggleSection('i:ic:Hash:Hash:3')"
+		      ></span
+		      > (<a href="#"
 		      >Hash</a
-		      > a, <a href=""
+		      > a, <a href="#"
 		      >Hash</a
-		      > b) =&gt; <a href=""
+		      > b) =&gt; <a href="#"
 		      >Hash</a
 		      > (a, b)</span
+		    > <a href="#" class="selflink"
+		    >#</a
 		    ></td
 		  ><td class="doc empty"
-		  >&nbsp;</td
+		  ></td
 		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:ic:Hash:Hash:3" class="inst-details hide"
+		    ><div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >hash</a
+			  > :: (a, b) -&gt; <a href="#"
+			  >Int</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></div
+		    ></td
+		  ></tr
 		></table
 	      ></div
 	    ></div
@@ -320,11 +405,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.16.1</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/HiddenInstances.html b/html-test/ref/HiddenInstances.html
--- a/html-test/ref/HiddenInstances.html
+++ b/html-test/ref/HiddenInstances.html
@@ -1,32 +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
     >HiddenInstances</title
-    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_HiddenInstances.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_HiddenInstances.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -48,13 +49,13 @@
 	><li class="src short"
 	  ><span class="keyword"
 	    >class</span
-	    > <a href=""
+	    > <a href="#"
 	    >VisibleClass</a
 	    > a</li
 	  ><li class="src short"
 	  ><span class="keyword"
 	    >data</span
-	    > <a href=""
+	    > <a href="#"
 	    >VisibleData</a
 	    ></li
 	  ></ul
@@ -66,9 +67,11 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >class</span
-	    > <a name="t:VisibleClass" class="def"
+	    > <a id="t:VisibleClass" class="def"
 	    >VisibleClass</a
-	    > a</p
+	    > a <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ><div class="doc"
 	  ><p
 	    >Should be visible</p
@@ -81,11 +84,15 @@
 	      ><tr
 		><td class="src clearfix"
 		  ><span class="inst-left"
-		    ><a href=""
+		    ><span id="control.i:ic:VisibleClass:VisibleClass:1" class="instance expander" onclick="toggleSection('i:ic:VisibleClass:VisibleClass:1')"
+		      ></span
+		      > <a href="#"
 		      >VisibleClass</a
-		      > <a href=""
+		      > <a href="#"
 		      >Int</a
 		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
 		    ></td
 		  ><td class="doc"
 		  ><p
@@ -93,19 +100,35 @@
 		    ></td
 		  ></tr
 		><tr
+		><td colspan="2"
+		  ><div id="section.i:ic:VisibleClass:VisibleClass:1" class="inst-details hide"
+		    ></div
+		    ></td
+		  ></tr
+		><tr
 		><td class="src clearfix"
 		  ><span class="inst-left"
-		    ><a href=""
+		    ><span id="control.i:ic:VisibleClass:VisibleClass:2" class="instance expander" onclick="toggleSection('i:ic:VisibleClass:VisibleClass:2')"
+		      ></span
+		      > <a href="#"
 		      >VisibleClass</a
-		      > <a href=""
+		      > <a href="#"
 		      >VisibleData</a
 		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
 		    ></td
 		  ><td class="doc"
 		  ><p
 		    >Should be visible</p
 		    ></td
 		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:ic:VisibleClass:VisibleClass:2" class="inst-details hide"
+		    ></div
+		    ></td
+		  ></tr
 		></table
 	      ></div
 	    ></div
@@ -114,8 +137,10 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >data</span
-	    > <a name="t:VisibleData" class="def"
+	    > <a id="t:VisibleData" class="def"
 	    >VisibleData</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="doc"
 	  ><p
@@ -129,11 +154,15 @@
 	      ><tr
 		><td class="src clearfix"
 		  ><span class="inst-left"
-		    ><a href=""
+		    ><span id="control.i:id:VisibleData:Num:1" class="instance expander" onclick="toggleSection('i:id:VisibleData:Num:1')"
+		      ></span
+		      > <a href="#"
 		      >Num</a
-		      > <a href=""
+		      > <a href="#"
 		      >VisibleData</a
 		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
 		    ></td
 		  ><td class="doc"
 		  ><p
@@ -141,19 +170,115 @@
 		    ></td
 		  ></tr
 		><tr
+		><td colspan="2"
+		  ><div id="section.i:id:VisibleData:Num:1" class="inst-details hide"
+		    ><div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >(+)</a
+			  > :: <a href="#"
+			  >VisibleData</a
+			  > -&gt; <a href="#"
+			  >VisibleData</a
+			  > -&gt; <a href="#"
+			  >VisibleData</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >(-)</a
+			  > :: <a href="#"
+			  >VisibleData</a
+			  > -&gt; <a href="#"
+			  >VisibleData</a
+			  > -&gt; <a href="#"
+			  >VisibleData</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >(*)</a
+			  > :: <a href="#"
+			  >VisibleData</a
+			  > -&gt; <a href="#"
+			  >VisibleData</a
+			  > -&gt; <a href="#"
+			  >VisibleData</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >negate</a
+			  > :: <a href="#"
+			  >VisibleData</a
+			  > -&gt; <a href="#"
+			  >VisibleData</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >abs</a
+			  > :: <a href="#"
+			  >VisibleData</a
+			  > -&gt; <a href="#"
+			  >VisibleData</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >signum</a
+			  > :: <a href="#"
+			  >VisibleData</a
+			  > -&gt; <a href="#"
+			  >VisibleData</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >fromInteger</a
+			  > :: <a href="#"
+			  >Integer</a
+			  > -&gt; <a href="#"
+			  >VisibleData</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></div
+		    ></td
+		  ></tr
+		><tr
 		><td class="src clearfix"
 		  ><span class="inst-left"
-		    ><a href=""
+		    ><span id="control.i:id:VisibleData:VisibleClass:2" class="instance expander" onclick="toggleSection('i:id:VisibleData:VisibleClass:2')"
+		      ></span
+		      > <a href="#"
 		      >VisibleClass</a
-		      > <a href=""
+		      > <a href="#"
 		      >VisibleData</a
 		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
 		    ></td
 		  ><td class="doc"
 		  ><p
 		    >Should be visible</p
 		    ></td
 		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:id:VisibleData:VisibleClass:2" class="inst-details hide"
+		    ></div
+		    ></td
+		  ></tr
 		></table
 	      ></div
 	    ></div
@@ -161,11 +286,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.16.1</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/HiddenInstancesB.html b/html-test/ref/HiddenInstancesB.html
--- a/html-test/ref/HiddenInstancesB.html
+++ b/html-test/ref/HiddenInstancesB.html
@@ -1,32 +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
     >HiddenInstancesB</title
-    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_HiddenInstancesB.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_HiddenInstancesB.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -48,13 +49,13 @@
 	><li class="src short"
 	  ><span class="keyword"
 	    >class</span
-	    > <a href=""
+	    > <a href="#"
 	    >Foo</a
 	    > a</li
 	  ><li class="src short"
 	  ><span class="keyword"
 	    >data</span
-	    > <a href=""
+	    > <a href="#"
 	    >Bar</a
 	    ></li
 	  ></ul
@@ -66,9 +67,11 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >class</span
-	    > <a name="t:Foo" class="def"
+	    > <a id="t:Foo" class="def"
 	    >Foo</a
-	    > a</p
+	    > a <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ><div class="doc"
 	  ><p
 	    >Should be visible</p
@@ -81,17 +84,27 @@
 	      ><tr
 		><td class="src clearfix"
 		  ><span class="inst-left"
-		    ><a href=""
+		    ><span id="control.i:ic:Foo:Foo:1" class="instance expander" onclick="toggleSection('i:ic:Foo:Foo:1')"
+		      ></span
+		      > <a href="#"
 		      >Foo</a
-		      > <a href=""
+		      > <a href="#"
 		      >Bar</a
 		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
 		    ></td
 		  ><td class="doc"
 		  ><p
 		    >Should be visible</p
 		    ></td
 		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:ic:Foo:Foo:1" class="inst-details hide"
+		    ></div
+		    ></td
+		  ></tr
 		></table
 	      ></div
 	    ></div
@@ -100,8 +113,10 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >data</span
-	    > <a name="t:Bar" class="def"
+	    > <a id="t:Bar" class="def"
 	    >Bar</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="doc"
 	  ><p
@@ -115,17 +130,27 @@
 	      ><tr
 		><td class="src clearfix"
 		  ><span class="inst-left"
-		    ><a href=""
+		    ><span id="control.i:id:Bar:Foo:1" class="instance expander" onclick="toggleSection('i:id:Bar:Foo:1')"
+		      ></span
+		      > <a href="#"
 		      >Foo</a
-		      > <a href=""
+		      > <a href="#"
 		      >Bar</a
 		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
 		    ></td
 		  ><td class="doc"
 		  ><p
 		    >Should be visible</p
 		    ></td
 		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:id:Bar:Foo:1" class="inst-details hide"
+		    ></div
+		    ></td
+		  ></tr
 		></table
 	      ></div
 	    ></div
@@ -133,11 +158,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.16.1</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/Hyperlinks.html b/html-test/ref/Hyperlinks.html
--- a/html-test/ref/Hyperlinks.html
+++ b/html-test/ref/Hyperlinks.html
@@ -1,32 +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"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_Hyperlinks.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_Hyperlinks.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -46,9 +47,9 @@
 	>Synopsis</p
 	><ul id="section.syn" class="hide" onclick="toggleSection('syn')"
 	><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >foo</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
 	    ></li
 	  ></ul
@@ -58,18 +59,20 @@
 	>Documentation</h1
 	><div class="top"
 	><p class="src"
-	  ><a name="v:foo" class="def"
+	  ><a id="v:foo" class="def"
 	    >foo</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="doc"
 	  ><p
-	    >A plain URL: <a href=""
+	    >A plain URL: <a href="#"
 	      >http://example.com/</a
 	      ></p
 	    ><p
-	    >A URL with a label: <a href=""
+	    >A URL with a label: <a href="#"
 	      >some link</a
 	      ></p
 	    ></div
@@ -77,11 +80,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.15.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/IgnoreExports.html b/html-test/ref/IgnoreExports.html
--- a/html-test/ref/IgnoreExports.html
+++ b/html-test/ref/IgnoreExports.html
@@ -1,32 +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
     >IgnoreExports</title
-    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_IgnoreExports.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_IgnoreExports.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -46,15 +47,15 @@
 	>Synopsis</p
 	><ul id="section.syn" class="hide" onclick="toggleSection('syn')"
 	><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >foo</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
 	    ></li
 	  ><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >bar</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
 	    ></li
 	  ></ul
@@ -64,10 +65,12 @@
 	>Documentation</h1
 	><div class="top"
 	><p class="src"
-	  ><a name="v:foo" class="def"
+	  ><a id="v:foo" class="def"
 	    >foo</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="doc"
 	  ><p
@@ -76,10 +79,12 @@
 	  ></div
 	><div class="top"
 	><p class="src"
-	  ><a name="v:bar" class="def"
+	  ><a id="v:bar" class="def"
 	    >bar</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="doc"
 	  ><p
@@ -89,11 +94,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.15.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/ImplicitParams.html b/html-test/ref/ImplicitParams.html
--- a/html-test/ref/ImplicitParams.html
+++ b/html-test/ref/ImplicitParams.html
@@ -1,32 +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
     >ImplicitParams</title
-    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_ImplicitParams.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_ImplicitParams.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -48,8 +49,10 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >data</span
-	    > <a name="t:X" class="def"
+	    > <a id="t:X" class="def"
 	    >X</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="subs constructors"
 	  ><p class="caption"
@@ -57,55 +60,57 @@
 	    ><table
 	    ><tr
 	      ><td class="src"
-		><a name="v:X" class="def"
+		><a id="v:X" class="def"
 		  >X</a
 		  ></td
 		><td class="doc empty"
-		>&nbsp;</td
+		></td
 		></tr
 	      ></table
 	    ></div
 	  ></div
 	><div class="top"
 	><p class="src"
-	  ><a name="v:c" class="def"
+	  ><a id="v:c" class="def"
 	    >c</a
-	    > :: (?x :: <a href=""
+	    > :: (?x :: <a href="#"
 	    >X</a
-	    >) =&gt; <a href=""
+	    >) =&gt; <a href="#"
 	    >X</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ></div
 	><div class="top"
 	><p class="src"
-	  ><a name="v:d" class="def"
+	  ><a id="v:d" class="def"
 	    >d</a
-	    > :: (?x :: <a href=""
+	    > :: (?x :: <a href="#"
 	    >X</a
-	    >, ?y :: <a href=""
+	    >, ?y :: <a href="#"
 	    >X</a
-	    >) =&gt; (<a href=""
+	    >) =&gt; (<a href="#"
 	    >X</a
-	    >, <a href=""
+	    >, <a href="#"
 	    >X</a
-	    >)</p
+	    >) <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ></div
 	><div class="top"
 	><p class="src"
-	  ><a name="v:f" class="def"
+	  ><a id="v:f" class="def"
 	    >f</a
-	    > :: ((?x :: <a href=""
+	    > :: ((?x :: <a href="#"
 	    >X</a
-	    >) =&gt; a) -&gt; a</p
+	    >) =&gt; a) -&gt; a <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ></div
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.15.0</p
-      ></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,1956 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >Instances</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_Instances.html&quot;);};
+//
+</script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ><p class="caption empty"
+      ></p
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe</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"
+		></td
+		></tr
+	      ></table
+	    ></div
+	  ><div class="subs instances"
+	  ><p id="control.i:-60--126--126-" class="caption collapser" onclick="toggleSection('i:-60--126--126-')"
+	    >Instances</p
+	    ><div id="section.i:-60--126--126-" class="show"
+	    ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:id:-60--126--126-:Foo:1" class="instance expander" onclick="toggleSection('i:id:-60--126--126-:Foo:1')"
+		      ></span
+		      > <a href="#"
+		      >Foo</a
+		      > (<a href="#"
+		      >(&lt;~~)</a
+		      > a)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:id:-60--126--126-:Foo:1" class="inst-details hide"
+		    ><div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >foo</a
+			  > :: (a <a href="#"
+			  >&lt;~~</a
+			  > <a href="#"
+			  >Int</a
+			  >) -&gt; a -&gt; a <a href="#"
+			  >&lt;~~</a
+			  > a <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >foo'</a
+			  > :: (a <a href="#"
+			  >&lt;~~</a
+			  > (a <a href="#"
+			  >&lt;~~</a
+			  > a)) -&gt; <a href="#"
+			  >Int</a
+			  > -&gt; a <a href="#"
+			  >&lt;~~</a
+			  > (a <a href="#"
+			  >&lt;~~</a
+			  > <a href="#"
+			  >Int</a
+			  >) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></div
+		    ></td
+		  ></tr
+		></table
+	      ></div
+	    ></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 methods"
+	  ><p class="caption"
+	    >Methods</p
+	    ><p class="src"
+	    ><a id="v:foo" class="def"
+	      >foo</a
+	      > :: f <a href="#"
+	      >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="#"
+	      >Int</a
+	      > -&gt; f (f <a href="#"
+	      >Int</a
+	      >) <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ></div
+	  ><div class="subs instances"
+	  ><p id="control.i:Foo" class="caption collapser" onclick="toggleSection('i:Foo')"
+	    >Instances</p
+	    ><div id="section.i:Foo" class="show"
+	    ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:ic:Foo:Foo:1" class="instance expander" onclick="toggleSection('i:ic:Foo:Foo:1')"
+		      ></span
+		      > <a href="#"
+		      >Foo</a
+		      > []</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:ic:Foo:Foo:1" class="inst-details hide"
+		    ><div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >foo</a
+			  > :: [<a href="#"
+			  >Int</a
+			  >] -&gt; a -&gt; [a] <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >foo'</a
+			  > :: [[a]] -&gt; <a href="#"
+			  >Int</a
+			  > -&gt; [[<a href="#"
+			  >Int</a
+			  >]] <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></div
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:ic:Foo:Foo:2" class="instance expander" onclick="toggleSection('i:ic:Foo:Foo:2')"
+		      ></span
+		      > <a href="#"
+		      >Foo</a
+		      > <a href="#"
+		      >Maybe</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:ic:Foo:Foo:2" class="inst-details hide"
+		    ><div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >foo</a
+			  > :: <a href="#"
+			  >Maybe</a
+			  > <a href="#"
+			  >Int</a
+			  > -&gt; a -&gt; <a href="#"
+			  >Maybe</a
+			  > a <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >foo'</a
+			  > :: <a href="#"
+			  >Maybe</a
+			  > (<a href="#"
+			  >Maybe</a
+			  > a) -&gt; <a href="#"
+			  >Int</a
+			  > -&gt; <a href="#"
+			  >Maybe</a
+			  > (<a href="#"
+			  >Maybe</a
+			  > <a href="#"
+			  >Int</a
+			  >) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></div
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:ic:Foo:Foo:3" class="instance expander" onclick="toggleSection('i:ic:Foo:Foo:3')"
+		      ></span
+		      > <a href="#"
+		      >Foo</a
+		      > ((-&gt;) a)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:ic:Foo:Foo:3" class="inst-details hide"
+		    ><div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >foo</a
+			  > :: (a -&gt; <a href="#"
+			  >Int</a
+			  >) -&gt; a -&gt; a -&gt; a <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >foo'</a
+			  > :: (a -&gt; a -&gt; a) -&gt; <a href="#"
+			  >Int</a
+			  > -&gt; a -&gt; a -&gt; <a href="#"
+			  >Int</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></div
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:ic:Foo:Foo:4" class="instance expander" onclick="toggleSection('i:ic:Foo:Foo:4')"
+		      ></span
+		      > <a href="#"
+		      >Foo</a
+		      > (<a href="#"
+		      >Either</a
+		      > a)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:ic:Foo:Foo:4" class="inst-details hide"
+		    ><div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >foo</a
+			  > :: <a href="#"
+			  >Either</a
+			  > a <a href="#"
+			  >Int</a
+			  > -&gt; a -&gt; <a href="#"
+			  >Either</a
+			  > a a <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >foo'</a
+			  > :: <a href="#"
+			  >Either</a
+			  > a (<a href="#"
+			  >Either</a
+			  > a a) -&gt; <a href="#"
+			  >Int</a
+			  > -&gt; <a href="#"
+			  >Either</a
+			  > a (<a href="#"
+			  >Either</a
+			  > a <a href="#"
+			  >Int</a
+			  >) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></div
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:ic:Foo:Foo:5" class="instance expander" onclick="toggleSection('i:ic:Foo:Foo:5')"
+		      ></span
+		      > (<a href="#"
+		      >Eq</a
+		      > a, <a href="#"
+		      >Foo</a
+		      > f) =&gt; <a href="#"
+		      >Foo</a
+		      > (<a href="#"
+		      >(,)</a
+		      > (f a))</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:ic:Foo:Foo:5" class="inst-details hide"
+		    ><div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >foo</a
+			  > :: (f a, <a href="#"
+			  >Int</a
+			  >) -&gt; a -&gt; (f a, a) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >foo'</a
+			  > :: (f a, (f a, a)) -&gt; <a href="#"
+			  >Int</a
+			  > -&gt; (f a, (f a, <a href="#"
+			  >Int</a
+			  >)) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></div
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:ic:Foo:Foo:6" class="instance expander" onclick="toggleSection('i:ic:Foo:Foo:6')"
+		      ></span
+		      > <a href="#"
+		      >Foo</a
+		      > (<a href="#"
+		      >(&lt;~~)</a
+		      > a)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:ic:Foo:Foo:6" class="inst-details hide"
+		    ><div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >foo</a
+			  > :: (a <a href="#"
+			  >&lt;~~</a
+			  > <a href="#"
+			  >Int</a
+			  >) -&gt; a -&gt; a <a href="#"
+			  >&lt;~~</a
+			  > a <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >foo'</a
+			  > :: (a <a href="#"
+			  >&lt;~~</a
+			  > (a <a href="#"
+			  >&lt;~~</a
+			  > a)) -&gt; <a href="#"
+			  >Int</a
+			  > -&gt; a <a href="#"
+			  >&lt;~~</a
+			  > (a <a href="#"
+			  >&lt;~~</a
+			  > <a href="#"
+			  >Int</a
+			  >) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></div
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:ic:Foo:Foo:7" class="instance expander" onclick="toggleSection('i:ic:Foo:Foo:7')"
+		      ></span
+		      > <a href="#"
+		      >Foo</a
+		      > (<a href="#"
+		      >(,,)</a
+		      > a a)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:ic:Foo:Foo:7" class="inst-details hide"
+		    ><div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >foo</a
+			  > :: (a, a, <a href="#"
+			  >Int</a
+			  >) -&gt; a -&gt; (a, a, a) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >foo'</a
+			  > :: (a, a, (a, a, a)) -&gt; <a href="#"
+			  >Int</a
+			  > -&gt; (a, a, (a, a, <a href="#"
+			  >Int</a
+			  >)) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></div
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:ic:Foo:Foo:8" class="instance expander" onclick="toggleSection('i:ic:Foo:Foo:8')"
+		      ></span
+		      > <a href="#"
+		      >Foo</a
+		      > (<a href="#"
+		      >Quux</a
+		      > a b)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:ic:Foo:Foo:8" class="inst-details hide"
+		    ><div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >foo</a
+			  > :: <a href="#"
+			  >Quux</a
+			  > a b <a href="#"
+			  >Int</a
+			  > -&gt; a -&gt; <a href="#"
+			  >Quux</a
+			  > a b a <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >foo'</a
+			  > :: <a href="#"
+			  >Quux</a
+			  > a b (<a href="#"
+			  >Quux</a
+			  > a b a) -&gt; <a href="#"
+			  >Int</a
+			  > -&gt; <a href="#"
+			  >Quux</a
+			  > a b (<a href="#"
+			  >Quux</a
+			  > a b <a href="#"
+			  >Int</a
+			  >) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></div
+		    ></td
+		  ></tr
+		></table
+	      ></div
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >class</span
+	    > <a href="#"
+	    >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 methods"
+	  ><p class="caption"
+	    >Methods</p
+	    ><p class="src"
+	    ><a id="v:bar" class="def"
+	      >bar</a
+	      > :: f a -&gt; f <a href="#"
+	      >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
+	      >, <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"
+	  ><p id="control.i:Bar" class="caption collapser" onclick="toggleSection('i:Bar')"
+	    >Instances</p
+	    ><div id="section.i:Bar" class="show"
+	    ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:ic:Bar:Bar:1" class="instance expander" onclick="toggleSection('i:ic:Bar:Bar:1')"
+		      ></span
+		      > <a href="#"
+		      >Bar</a
+		      > <a href="#"
+		      >Maybe</a
+		      > <a href="#"
+		      >Bool</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:ic:Bar:Bar:1" class="inst-details hide"
+		    ><div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >bar</a
+			  > :: <a href="#"
+			  >Maybe</a
+			  > <a href="#"
+			  >Bool</a
+			  > -&gt; <a href="#"
+			  >Maybe</a
+			  > <a href="#"
+			  >Bool</a
+			  > -&gt; <a href="#"
+			  >Bool</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >bar'</a
+			  > :: <a href="#"
+			  >Maybe</a
+			  > (<a href="#"
+			  >Maybe</a
+			  > <a href="#"
+			  >Bool</a
+			  >) -&gt; <a href="#"
+			  >Maybe</a
+			  > (<a href="#"
+			  >Maybe</a
+			  > (<a href="#"
+			  >Maybe</a
+			  > b)) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >bar0</a
+			  > :: (<a href="#"
+			  >Maybe</a
+			  > <a href="#"
+			  >Bool</a
+			  >, <a href="#"
+			  >Maybe</a
+			  > <a href="#"
+			  >Bool</a
+			  >) -&gt; (<a href="#"
+			  >Maybe</a
+			  > b, <a href="#"
+			  >Maybe</a
+			  > c) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >bar1</a
+			  > :: (<a href="#"
+			  >Maybe</a
+			  > <a href="#"
+			  >Bool</a
+			  >, <a href="#"
+			  >Maybe</a
+			  > <a href="#"
+			  >Bool</a
+			  >) -&gt; (<a href="#"
+			  >Maybe</a
+			  > b, <a href="#"
+			  >Maybe</a
+			  > c) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></div
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:ic:Bar:Bar:2" class="instance expander" onclick="toggleSection('i:ic:Bar:Bar:2')"
+		      ></span
+		      > <a href="#"
+		      >Bar</a
+		      > <a href="#"
+		      >Maybe</a
+		      > [a]</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:ic:Bar:Bar:2" class="inst-details hide"
+		    ><div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >bar</a
+			  > :: <a href="#"
+			  >Maybe</a
+			  > [a] -&gt; <a href="#"
+			  >Maybe</a
+			  > <a href="#"
+			  >Bool</a
+			  > -&gt; [a] <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >bar'</a
+			  > :: <a href="#"
+			  >Maybe</a
+			  > (<a href="#"
+			  >Maybe</a
+			  > [a]) -&gt; <a href="#"
+			  >Maybe</a
+			  > (<a href="#"
+			  >Maybe</a
+			  > (<a href="#"
+			  >Maybe</a
+			  > b)) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >bar0</a
+			  > :: (<a href="#"
+			  >Maybe</a
+			  > [a], <a href="#"
+			  >Maybe</a
+			  > [a]) -&gt; (<a href="#"
+			  >Maybe</a
+			  > b, <a href="#"
+			  >Maybe</a
+			  > c) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >bar1</a
+			  > :: (<a href="#"
+			  >Maybe</a
+			  > [a], <a href="#"
+			  >Maybe</a
+			  > [a]) -&gt; (<a href="#"
+			  >Maybe</a
+			  > b, <a href="#"
+			  >Maybe</a
+			  > c) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></div
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:ic:Bar:Bar:3" class="instance expander" onclick="toggleSection('i:ic:Bar:Bar:3')"
+		      ></span
+		      > <a href="#"
+		      >Bar</a
+		      > [] (a, a)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:ic:Bar:Bar:3" class="inst-details hide"
+		    ><div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >bar</a
+			  > :: [(a, a)] -&gt; [<a href="#"
+			  >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
+		      ></div
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:ic:Bar:Bar:4" class="instance expander" onclick="toggleSection('i:ic:Bar:Bar:4')"
+		      ></span
+		      > <a href="#"
+		      >Foo</a
+		      > f =&gt; <a href="#"
+		      >Bar</a
+		      > (<a href="#"
+		      >Either</a
+		      > a) (f a)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:ic:Bar:Bar:4" class="inst-details hide"
+		    ><div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >bar</a
+			  > :: <a href="#"
+			  >Either</a
+			  > a (f a) -&gt; <a href="#"
+			  >Either</a
+			  > a <a href="#"
+			  >Bool</a
+			  > -&gt; f a <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >bar'</a
+			  > :: <a href="#"
+			  >Either</a
+			  > a (<a href="#"
+			  >Either</a
+			  > a (f a)) -&gt; <a href="#"
+			  >Either</a
+			  > a (<a href="#"
+			  >Either</a
+			  > a (<a href="#"
+			  >Either</a
+			  > a b)) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >bar0</a
+			  > :: (<a href="#"
+			  >Either</a
+			  > a (f a), <a href="#"
+			  >Either</a
+			  > a (f a)) -&gt; (<a href="#"
+			  >Either</a
+			  > a b, <a href="#"
+			  >Either</a
+			  > a c) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >bar1</a
+			  > :: (<a href="#"
+			  >Either</a
+			  > a (f a), <a href="#"
+			  >Either</a
+			  > a (f a)) -&gt; (<a href="#"
+			  >Either</a
+			  > a b, <a href="#"
+			  >Either</a
+			  > a c) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></div
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:ic:Bar:Bar:5" class="instance expander" onclick="toggleSection('i:ic:Bar:Bar:5')"
+		      ></span
+		      > <a href="#"
+		      >Foo</a
+		      > (<a href="#"
+		      >(,,)</a
+		      > a b) =&gt; <a href="#"
+		      >Bar</a
+		      > (<a href="#"
+		      >(,,)</a
+		      > a b) (a, b, a)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:ic:Bar:Bar:5" class="inst-details hide"
+		    ><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="#"
+			  >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, b))) <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, b), (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, b), (a, b, c)) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></div
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:ic:Bar:Bar:6" class="instance expander" onclick="toggleSection('i:ic:Bar:Bar:6')"
+		      ></span
+		      > <a href="#"
+		      >Bar</a
+		      > (<a href="#"
+		      >Quux</a
+		      > a c) (<a href="#"
+		      >Quux</a
+		      > a b c)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:ic:Bar:Bar:6" class="inst-details hide"
+		    ><div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >bar</a
+			  > :: <a href="#"
+			  >Quux</a
+			  > a c (<a href="#"
+			  >Quux</a
+			  > a b c) -&gt; <a href="#"
+			  >Quux</a
+			  > a c <a href="#"
+			  >Bool</a
+			  > -&gt; <a href="#"
+			  >Quux</a
+			  > a b c <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >bar'</a
+			  > :: <a href="#"
+			  >Quux</a
+			  > a c (<a href="#"
+			  >Quux</a
+			  > a c (<a href="#"
+			  >Quux</a
+			  > a b c)) -&gt; <a href="#"
+			  >Quux</a
+			  > a c (<a href="#"
+			  >Quux</a
+			  > a c (<a href="#"
+			  >Quux</a
+			  > a c b)) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >bar0</a
+			  > :: (<a href="#"
+			  >Quux</a
+			  > a c (<a href="#"
+			  >Quux</a
+			  > a b c), <a href="#"
+			  >Quux</a
+			  > a c (<a href="#"
+			  >Quux</a
+			  > a b c)) -&gt; (<a href="#"
+			  >Quux</a
+			  > a c b, <a href="#"
+			  >Quux</a
+			  > a c c) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >bar1</a
+			  > :: (<a href="#"
+			  >Quux</a
+			  > a c (<a href="#"
+			  >Quux</a
+			  > a b c), <a href="#"
+			  >Quux</a
+			  > a c (<a href="#"
+			  >Quux</a
+			  > a b c)) -&gt; (<a href="#"
+			  >Quux</a
+			  > a c b, <a href="#"
+			  >Quux</a
+			  > a c c) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></div
+		    ></td
+		  ></tr
+		></table
+	      ></div
+	    ></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 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"
+	  ><p id="control.i:Baz" class="caption collapser" onclick="toggleSection('i:Baz')"
+	    >Instances</p
+	    ><div id="section.i:Baz" class="show"
+	    ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:ic:Baz:Baz:1" class="instance expander" onclick="toggleSection('i:ic:Baz:Baz:1')"
+		      ></span
+		      > <a href="#"
+		      >Baz</a
+		      > [c]</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:ic:Baz:Baz:1" class="inst-details hide"
+		    ><div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >baz</a
+			  > :: [c] -&gt; (<span class="keyword"
+			  >forall</span
+			  > a. a -&gt; a) -&gt; (b, <span class="keyword"
+			  >forall</span
+			  > a. a -&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
+			  > b. b -&gt; [c]) -&gt; (<span class="keyword"
+			  >forall</span
+			  > b. b -&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
+			  > b. (<span class="keyword"
+			  >forall</span
+			  > a. a -&gt; [c]) -&gt; c) -&gt; <span class="keyword"
+			  >forall</span
+			  > a. a -&gt; b <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></div
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:ic:Baz:Baz:2" class="instance expander" onclick="toggleSection('i:ic:Baz:Baz:2')"
+		      ></span
+		      > <a href="#"
+		      >Baz</a
+		      > (a -&gt; b)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:ic:Baz:Baz:2" class="inst-details hide"
+		    ><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
+			  > c. c -&gt; c) -&gt; (b, <span class="keyword"
+			  >forall</span
+			  > c. c -&gt; a -&gt; b) -&gt; (b, c) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >baz'</a
+			  > :: b -&gt; (<span class="keyword"
+			  >forall</span
+			  > c. c -&gt; a -&gt; b) -&gt; (<span class="keyword"
+			  >forall</span
+			  > c. c -&gt; a -&gt; b) -&gt; [(b, a -&gt; b)] <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >baz''</a
+			  > :: b -&gt; (<span class="keyword"
+			  >forall</span
+			  > c. (<span class="keyword"
+			  >forall</span
+			  > d. d -&gt; a -&gt; b) -&gt; c) -&gt; <span class="keyword"
+			  >forall</span
+			  > c. c -&gt; b <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></div
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:ic:Baz:Baz:3" class="instance expander" onclick="toggleSection('i:ic:Baz:Baz:3')"
+		      ></span
+		      > <a href="#"
+		      >Baz</a
+		      > (a, b, c)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:ic:Baz:Baz:3" class="inst-details hide"
+		    ><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
+			  > d. d -&gt; d) -&gt; (b, <span class="keyword"
+			  >forall</span
+			  > d. d -&gt; (a, b, c)) -&gt; (b, c) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >baz'</a
+			  > :: b -&gt; (<span class="keyword"
+			  >forall</span
+			  > d. d -&gt; (a, b, c)) -&gt; (<span class="keyword"
+			  >forall</span
+			  > d. d -&gt; (a, b, c)) -&gt; [(b, (a, b, c))] <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >baz''</a
+			  > :: b -&gt; (<span class="keyword"
+			  >forall</span
+			  > d. (<span class="keyword"
+			  >forall</span
+			  > e. e -&gt; (a, b, c)) -&gt; c) -&gt; <span class="keyword"
+			  >forall</span
+			  > d. d -&gt; b <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></div
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:ic:Baz:Baz:4" class="instance expander" onclick="toggleSection('i:ic:Baz:Baz:4')"
+		      ></span
+		      > <a href="#"
+		      >Baz</a
+		      > (<a href="#"
+		      >Quux</a
+		      > a b c)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:ic:Baz:Baz:4" class="inst-details hide"
+		    ><div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >baz</a
+			  > :: <a href="#"
+			  >Quux</a
+			  > a b c -&gt; (<span class="keyword"
+			  >forall</span
+			  > d. d -&gt; d) -&gt; (b, <span class="keyword"
+			  >forall</span
+			  > d. d -&gt; <a href="#"
+			  >Quux</a
+			  > a b c) -&gt; (b, c) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >baz'</a
+			  > :: b -&gt; (<span class="keyword"
+			  >forall</span
+			  > d. d -&gt; <a href="#"
+			  >Quux</a
+			  > a b c) -&gt; (<span class="keyword"
+			  >forall</span
+			  > d. d -&gt; <a href="#"
+			  >Quux</a
+			  > a b c) -&gt; [(b, <a href="#"
+			  >Quux</a
+			  > a b c)] <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >baz''</a
+			  > :: b -&gt; (<span class="keyword"
+			  >forall</span
+			  > d. (<span class="keyword"
+			  >forall</span
+			  > e. e -&gt; <a href="#"
+			  >Quux</a
+			  > a b c) -&gt; c) -&gt; <span class="keyword"
+			  >forall</span
+			  > d. d -&gt; b <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></div
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:ic:Baz:Baz:5" class="instance expander" onclick="toggleSection('i:ic:Baz:Baz:5')"
+		      ></span
+		      > <a href="#"
+		      >Baz</a
+		      > (a, [b], b, a)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:ic:Baz:Baz:5" class="inst-details hide"
+		    ><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
+			  > c. c -&gt; c) -&gt; (b, <span class="keyword"
+			  >forall</span
+			  > c. c -&gt; (a, [b], b, a)) -&gt; (b, c) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >baz'</a
+			  > :: b -&gt; (<span class="keyword"
+			  >forall</span
+			  > c. c -&gt; (a, [b], b, a)) -&gt; (<span class="keyword"
+			  >forall</span
+			  > c. c -&gt; (a, [b], b, a)) -&gt; [(b, (a, [b], b, a))] <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >baz''</a
+			  > :: b -&gt; (<span class="keyword"
+			  >forall</span
+			  > c. (<span class="keyword"
+			  >forall</span
+			  > d. d -&gt; (a, [b], b, a)) -&gt; c) -&gt; <span class="keyword"
+			  >forall</span
+			  > c. c -&gt; b <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></div
+		    ></td
+		  ></tr
+		></table
+	      ></div
+	    ></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"
+		></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		><a id="v:Qux" class="def"
+		  >Qux</a
+		  > a b</td
+		><td class="doc empty"
+		></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		><a id="v:Quux" class="def"
+		  >Quux</a
+		  > a b c</td
+		><td class="doc empty"
+		></td
+		></tr
+	      ></table
+	    ></div
+	  ><div class="subs instances"
+	  ><p id="control.i:Quux" class="caption collapser" onclick="toggleSection('i:Quux')"
+	    >Instances</p
+	    ><div id="section.i:Quux" class="show"
+	    ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:id:Quux:Foo:1" class="instance expander" onclick="toggleSection('i:id:Quux:Foo:1')"
+		      ></span
+		      > <a href="#"
+		      >Foo</a
+		      > (<a href="#"
+		      >Quux</a
+		      > a b)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:id:Quux:Foo:1" class="inst-details hide"
+		    ><div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >foo</a
+			  > :: <a href="#"
+			  >Quux</a
+			  > a b <a href="#"
+			  >Int</a
+			  > -&gt; a -&gt; <a href="#"
+			  >Quux</a
+			  > a b a <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >foo'</a
+			  > :: <a href="#"
+			  >Quux</a
+			  > a b (<a href="#"
+			  >Quux</a
+			  > a b a) -&gt; <a href="#"
+			  >Int</a
+			  > -&gt; <a href="#"
+			  >Quux</a
+			  > a b (<a href="#"
+			  >Quux</a
+			  > a b <a href="#"
+			  >Int</a
+			  >) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></div
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:id:Quux:Bar:2" class="instance expander" onclick="toggleSection('i:id:Quux:Bar:2')"
+		      ></span
+		      > <a href="#"
+		      >Bar</a
+		      > (<a href="#"
+		      >Quux</a
+		      > a c) (<a href="#"
+		      >Quux</a
+		      > a b c)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:id:Quux:Bar:2" class="inst-details hide"
+		    ><div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >bar</a
+			  > :: <a href="#"
+			  >Quux</a
+			  > a c (<a href="#"
+			  >Quux</a
+			  > a b c) -&gt; <a href="#"
+			  >Quux</a
+			  > a c <a href="#"
+			  >Bool</a
+			  > -&gt; <a href="#"
+			  >Quux</a
+			  > a b c <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >bar'</a
+			  > :: <a href="#"
+			  >Quux</a
+			  > a c (<a href="#"
+			  >Quux</a
+			  > a c (<a href="#"
+			  >Quux</a
+			  > a b c)) -&gt; <a href="#"
+			  >Quux</a
+			  > a c (<a href="#"
+			  >Quux</a
+			  > a c (<a href="#"
+			  >Quux</a
+			  > a c b)) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >bar0</a
+			  > :: (<a href="#"
+			  >Quux</a
+			  > a c (<a href="#"
+			  >Quux</a
+			  > a b c), <a href="#"
+			  >Quux</a
+			  > a c (<a href="#"
+			  >Quux</a
+			  > a b c)) -&gt; (<a href="#"
+			  >Quux</a
+			  > a c b, <a href="#"
+			  >Quux</a
+			  > a c c) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >bar1</a
+			  > :: (<a href="#"
+			  >Quux</a
+			  > a c (<a href="#"
+			  >Quux</a
+			  > a b c), <a href="#"
+			  >Quux</a
+			  > a c (<a href="#"
+			  >Quux</a
+			  > a b c)) -&gt; (<a href="#"
+			  >Quux</a
+			  > a c b, <a href="#"
+			  >Quux</a
+			  > a c c) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></div
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:id:Quux:Baz:3" class="instance expander" onclick="toggleSection('i:id:Quux:Baz:3')"
+		      ></span
+		      > <a href="#"
+		      >Baz</a
+		      > (<a href="#"
+		      >Quux</a
+		      > a b c)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:id:Quux:Baz:3" class="inst-details hide"
+		    ><div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >baz</a
+			  > :: <a href="#"
+			  >Quux</a
+			  > a b c -&gt; (<span class="keyword"
+			  >forall</span
+			  > d. d -&gt; d) -&gt; (b, <span class="keyword"
+			  >forall</span
+			  > d. d -&gt; <a href="#"
+			  >Quux</a
+			  > a b c) -&gt; (b, c) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >baz'</a
+			  > :: b -&gt; (<span class="keyword"
+			  >forall</span
+			  > d. d -&gt; <a href="#"
+			  >Quux</a
+			  > a b c) -&gt; (<span class="keyword"
+			  >forall</span
+			  > d. d -&gt; <a href="#"
+			  >Quux</a
+			  > a b c) -&gt; [(b, <a href="#"
+			  >Quux</a
+			  > a b c)] <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >baz''</a
+			  > :: b -&gt; (<span class="keyword"
+			  >forall</span
+			  > d. (<span class="keyword"
+			  >forall</span
+			  > e. e -&gt; <a href="#"
+			  >Quux</a
+			  > a b c) -&gt; c) -&gt; <span class="keyword"
+			  >forall</span
+			  > d. d -&gt; b <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></div
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:id:Quux:Thud:4" class="instance expander" onclick="toggleSection('i:id:Quux:Thud:4')"
+		      ></span
+		      > <span class="keyword"
+		      >data</span
+		      > <a href="#"
+		      >Thud</a
+		      > <a href="#"
+		      >Int</a
+		      > (<a href="#"
+		      >Quux</a
+		      > a [a] c)</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:id:Quux:Thud:4" class="inst-details hide"
+		    ><div class="src"
+		      ><span class="keyword"
+			>data</span
+			> <a href="#"
+			>Thud</a
+			> <a href="#"
+			>Int</a
+			> (<a href="#"
+			>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="#"
+			    >Int</a
+			    > <a href="#"
+			    >Int</a
+			    ></li
+			  ></ul
+			></div
+		      ></div
+		    ></td
+		  ></tr
+		></table
+	      ></div
+	    ></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 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="#"
+	      >Plugh</a
+	      > a c b -&gt; a -&gt; (a -&gt; c) -&gt; b <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ></div
+	  ><div class="subs instances"
+	  ><p id="control.i:Norf" class="caption collapser" onclick="toggleSection('i:Norf')"
+	    >Instances</p
+	    ><div id="section.i:Norf" class="show"
+	    ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:ic:Norf:Norf:1" class="instance expander" onclick="toggleSection('i:ic:Norf:Norf:1')"
+		      ></span
+		      > <a href="#"
+		      >Norf</a
+		      > <a href="#"
+		      >Int</a
+		      > <a href="#"
+		      >Bool</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:ic:Norf:Norf:1" class="inst-details hide"
+		    ><div class="subs associated-types"
+		      ><p class="caption"
+			>Associated Types</p
+			><p class="src"
+			><span class="keyword"
+			  >type</span
+			  > <a href="#"
+			  >Plugh</a
+			  > <a href="#"
+			  >Int</a
+			  > c <a href="#"
+			  >Bool</a
+			  > :: <a href="#"
+			  >*</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><span class="keyword"
+			  >data</span
+			  > <a href="#"
+			  >Thud</a
+			  > <a href="#"
+			  >Int</a
+			  > c :: <a href="#"
+			  >*</a
+			  > <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="#"
+			  >Plugh</a
+			  > <a href="#"
+			  >Int</a
+			  > c <a href="#"
+			  >Bool</a
+			  > -&gt; <a href="#"
+			  >Int</a
+			  > -&gt; (<a href="#"
+			  >Int</a
+			  > -&gt; c) -&gt; <a href="#"
+			  >Bool</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></div
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:ic:Norf:Norf:2" class="instance expander" onclick="toggleSection('i:ic:Norf:Norf:2')"
+		      ></span
+		      > <a href="#"
+		      >Norf</a
+		      > [a] [b]</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:ic:Norf:Norf:2" class="inst-details hide"
+		    ><div class="subs associated-types"
+		      ><p class="caption"
+			>Associated Types</p
+			><p class="src"
+			><span class="keyword"
+			  >type</span
+			  > <a href="#"
+			  >Plugh</a
+			  > [a] c [b] :: <a href="#"
+			  >*</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><span class="keyword"
+			  >data</span
+			  > <a href="#"
+			  >Thud</a
+			  > [a] c :: <a href="#"
+			  >*</a
+			  > <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="#"
+			  >Plugh</a
+			  > [a] c [b] -&gt; [a] -&gt; ([a] -&gt; c) -&gt; [b] <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></div
+		    ></td
+		  ></tr
+		></table
+	      ></div
+	    ></div
+	  ></div
+	></div
+      ></div
+    ><div id="footer"
+    ></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,100 @@
+<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="#" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_Math.html&quot;);};
+//
+</script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ><p class="caption empty"
+      ></p
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe</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
+	  >\[
+ \int_{-\infty}^{\infty} e^{-x^2/2} = \sqrt{2\pi}
+ \]</p
+	  ><p
+	  >\(\int_{-\infty}^{\infty} e^{-x^2/2} = \sqrt{2\pi}\)</p
+	  ></div
+	></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="#"
+	    >f</a
+	    > :: <a href="#"
+	    >Integer</a
+	    ></li
+	  ></ul
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><a id="v:f" class="def"
+	    >f</a
+	    > :: <a href="#"
+	    >Integer</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Math (inline) for <code
+	      >normalDensity</code
+	      >
+ \(\int_{-\infty}^{\infty} e^{-x^2/2} = \sqrt{2\pi}\)
+ \[\int_{-\infty}^{\infty} e^{-x^2/2} = \sqrt{2\pi}\]</p
+	    ></div
+	  ></div
+	></div
+      ></div
+    ><div id="footer"
+    ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Minimal.html b/html-test/ref/Minimal.html
--- a/html-test/ref/Minimal.html
+++ b/html-test/ref/Minimal.html
@@ -1,32 +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
     >Minimal</title
-    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_Minimal.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_Minimal.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -56,28 +57,30 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >class</span
-	    > <a name="t:Foo" class="def"
+	    > <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=""
+	    ><a href="#"
 	      >foo</a
-	      >, <a href=""
+	      >, <a href="#"
 	      >bar</a
-	      > | <a href=""
+	      > | <a href="#"
 	      >bar</a
-	      >, <a href=""
+	      >, <a href="#"
 	      >bat</a
-	      > | <a href=""
+	      > | <a href="#"
 	      >foo</a
-	      >, <a href=""
+	      >, <a href="#"
 	      >bat</a
-	      > | <a href=""
+	      > | <a href="#"
 	      >fooBarBat</a
 	      ></p
 	    ></div
@@ -85,25 +88,33 @@
 	  ><p class="caption"
 	    >Methods</p
 	    ><p class="src"
-	    ><a name="v:foo" class="def"
+	    ><a id="v:foo" class="def"
 	      >foo</a
-	      > :: a</p
+	      > :: a <a href="#" class="selflink"
+	      >#</a
+	      ></p
 	    ><div class="doc"
 	    ><p
 	      >Any two of these are required...</p
 	      ></div
 	    ><p class="src"
-	    ><a name="v:bar" class="def"
+	    ><a id="v:bar" class="def"
 	      >bar</a
-	      > :: a</p
+	      > :: a <a href="#" class="selflink"
+	      >#</a
+	      ></p
 	    ><p class="src"
-	    ><a name="v:bat" class="def"
+	    ><a id="v:bat" class="def"
 	      >bat</a
-	      > :: a</p
+	      > :: a <a href="#" class="selflink"
+	      >#</a
+	      ></p
 	    ><p class="src"
-	    ><a name="v:fooBarBat" class="def"
+	    ><a id="v:fooBarBat" class="def"
 	      >fooBarBat</a
-	      > :: (a, a, a)</p
+	      > :: (a, a, a) <a href="#" class="selflink"
+	      >#</a
+	      ></p
 	    ><div class="doc"
 	    ><p
 	      >.. or just this</p
@@ -114,28 +125,30 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >class</span
-	    > <a name="t:Weird" class="def"
+	    > <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=""
+	    ><a href="#"
 	      >a</a
-	      >, <a href=""
+	      >, <a href="#"
 	      >b</a
-	      >, <a href=""
+	      >, <a href="#"
 	      >c</a
-	      > | <a href=""
+	      > | <a href="#"
 	      >d</a
-	      > | <a href=""
+	      > | <a href="#"
 	      >e</a
-	      >, (<a href=""
+	      >, (<a href="#"
 	      >f</a
-	      > | <a href=""
+	      > | <a href="#"
 	      >g</a
 	      >)</p
 	    ></div
@@ -143,51 +156,67 @@
 	  ><p class="caption"
 	    >Methods</p
 	    ><p class="src"
-	    ><a name="v:a" class="def"
+	    ><a id="v:a" class="def"
 	      >a</a
-	      > :: a</p
+	      > :: a <a href="#" class="selflink"
+	      >#</a
+	      ></p
 	    ><p class="src"
-	    ><a name="v:b" class="def"
+	    ><a id="v:b" class="def"
 	      >b</a
-	      > :: a</p
+	      > :: a <a href="#" class="selflink"
+	      >#</a
+	      ></p
 	    ><p class="src"
-	    ><a name="v:c" class="def"
+	    ><a id="v:c" class="def"
 	      >c</a
-	      > :: a</p
+	      > :: a <a href="#" class="selflink"
+	      >#</a
+	      ></p
 	    ><p class="src"
-	    ><a name="v:d" class="def"
+	    ><a id="v:d" class="def"
 	      >d</a
-	      > :: a</p
+	      > :: a <a href="#" class="selflink"
+	      >#</a
+	      ></p
 	    ><p class="src"
-	    ><a name="v:e" class="def"
+	    ><a id="v:e" class="def"
 	      >e</a
-	      > :: a</p
+	      > :: a <a href="#" class="selflink"
+	      >#</a
+	      ></p
 	    ><p class="src"
-	    ><a name="v:f" class="def"
+	    ><a id="v:f" class="def"
 	      >f</a
-	      > :: a</p
+	      > :: a <a href="#" class="selflink"
+	      >#</a
+	      ></p
 	    ><p class="src"
-	    ><a name="v:g" class="def"
+	    ><a id="v:g" class="def"
 	      >g</a
-	      > :: a</p
+	      > :: a <a href="#" class="selflink"
+	      >#</a
+	      ></p
 	    ></div
 	  ></div
 	><div class="top"
 	><p class="src"
 	  ><span class="keyword"
 	    >class</span
-	    > <a name="t:NoMins" class="def"
+	    > <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=""
+	    ><a href="#"
 	      >x</a
-	      >, <a href=""
+	      >, <a href="#"
 	      >y</a
 	      ></p
 	    ></div
@@ -195,55 +224,79 @@
 	  ><p class="caption"
 	    >Methods</p
 	    ><p class="src"
-	    ><a name="v:x" class="def"
+	    ><a id="v:x" class="def"
 	      >x</a
-	      > :: a</p
+	      > :: a <a href="#" class="selflink"
+	      >#</a
+	      ></p
 	    ><p class="src"
-	    ><a name="v:y" class="def"
+	    ><a id="v:y" class="def"
 	      >y</a
-	      > :: a</p
+	      > :: a <a href="#" class="selflink"
+	      >#</a
+	      ></p
 	    ><p class="src"
-	    ><a name="v:z" class="def"
+	    ><a id="v:z" class="def"
 	      >z</a
-	      > :: a</p
+	      > :: a <a href="#" class="selflink"
+	      >#</a
+	      ></p
 	    ></div
 	  ></div
 	><div class="top"
 	><p class="src"
 	  ><span class="keyword"
 	    >class</span
-	    > <a name="t:FullMin" class="def"
+	    > <a id="t:FullMin" class="def"
 	    >FullMin</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="#"
+	      >aaa</a
+	      >, <a href="#"
+	      >bbb</a
+	      ></p
+	    ></div
 	  ><div class="subs methods"
 	  ><p class="caption"
 	    >Methods</p
 	    ><p class="src"
-	    ><a name="v:aaa" class="def"
+	    ><a id="v:aaa" class="def"
 	      >aaa</a
-	      > :: a</p
+	      > :: a <a href="#" class="selflink"
+	      >#</a
+	      ></p
 	    ><p class="src"
-	    ><a name="v:bbb" class="def"
+	    ><a id="v:bbb" class="def"
 	      >bbb</a
-	      > :: a</p
+	      > :: a <a href="#" class="selflink"
+	      >#</a
+	      ></p
 	    ></div
 	  ></div
 	><div class="top"
 	><p class="src"
 	  ><span class="keyword"
 	    >class</span
-	    > <a name="t:PartialMin" class="def"
+	    > <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=""
+	    ><a href="#"
 	      >ccc</a
 	      >, ddd</p
 	    ></div
@@ -251,47 +304,45 @@
 	  ><p class="caption"
 	    >Methods</p
 	    ><p class="src"
-	    ><a name="v:ccc" class="def"
+	    ><a id="v:ccc" class="def"
 	      >ccc</a
-	      > :: a</p
+	      > :: a <a href="#" class="selflink"
+	      >#</a
+	      ></p
 	    ></div
 	  ></div
 	><div class="top"
 	><p class="src"
 	  ><span class="keyword"
 	    >class</span
-	    > <a name="t:EmptyMin" class="def"
+	    > <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 name="v:eee" class="def"
+	    ><a id="v:eee" class="def"
 	      >eee</a
-	      > :: a</p
+	      > :: a <a href="#" class="selflink"
+	      >#</a
+	      ></p
 	    ><p class="src"
-	    ><a name="v:fff" class="def"
+	    ><a id="v:fff" class="def"
 	      >fff</a
-	      > :: a</p
+	      > :: a <a href="#" class="selflink"
+	      >#</a
+	      ></p
 	    ></div
 	  ></div
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.15.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/ModuleWithWarning.html b/html-test/ref/ModuleWithWarning.html
--- a/html-test/ref/ModuleWithWarning.html
+++ b/html-test/ref/ModuleWithWarning.html
@@ -1,32 +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"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_ModuleWithWarning.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_ModuleWithWarning.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -47,12 +48,12 @@
 	><div class="doc"
 	><div class="warning"
 	  ><p
-	    >Warning: This is an unstable interface.  Prefer functions from <a href=""
+	    >Warning: This is an unstable interface.  Prefer functions from <a href="#"
 	      >Prelude</a
 	      > instead!</p
 	    ></div
 	  ><p
-	  >Documentation for <a href=""
+	  >Documentation for <a href="#"
 	    >ModuleWithWarning</a
 	    >.</p
 	  ></div
@@ -62,20 +63,18 @@
 	>Documentation</h1
 	><div class="top"
 	><p class="src"
-	  ><a name="v:foo" class="def"
+	  ><a id="v:foo" class="def"
 	    >foo</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ></div
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.15.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/NamedDoc.html b/html-test/ref/NamedDoc.html
--- a/html-test/ref/NamedDoc.html
+++ b/html-test/ref/NamedDoc.html
@@ -1,32 +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
     >NamedDoc</title
-    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_NamedDoc.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_NamedDoc.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -57,11 +58,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.15.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/Nesting.html b/html-test/ref/Nesting.html
--- a/html-test/ref/Nesting.html
+++ b/html-test/ref/Nesting.html
@@ -1,32 +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
     >Nesting</title
-    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_Nesting.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_Nesting.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -46,35 +47,35 @@
 	>Synopsis</p
 	><ul id="section.syn" class="hide" onclick="toggleSection('syn')"
 	><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >d</a
 	    > :: t</li
 	  ><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >e</a
 	    > :: t</li
 	  ><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >f</a
 	    > :: t</li
 	  ><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >g</a
 	    > :: t</li
 	  ><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >h</a
 	    > :: t</li
 	  ><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >i</a
 	    > :: t</li
 	  ><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >j</a
 	    > :: t</li
 	  ><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >k</a
 	    > :: t</li
 	  ></ul
@@ -84,9 +85,11 @@
 	>Documentation</h1
 	><div class="top"
 	><p class="src"
-	  ><a name="v:d" class="def"
+	  ><a id="v:d" class="def"
 	    >d</a
-	    > :: t</p
+	    > :: t <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ><div class="doc"
 	  ><ul
 	    ><li
@@ -116,9 +119,11 @@
 	  ></div
 	><div class="top"
 	><p class="src"
-	  ><a name="v:e" class="def"
+	  ><a id="v:e" class="def"
 	    >e</a
-	    > :: t</p
+	    > :: t <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ><div class="doc"
 	  ><ul
 	    ><li
@@ -137,9 +142,11 @@
 	  ></div
 	><div class="top"
 	><p class="src"
-	  ><a name="v:f" class="def"
+	  ><a id="v:f" class="def"
 	    >f</a
-	    > :: t</p
+	    > :: t <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ><div class="doc"
 	  ><ul
 	    ><li
@@ -155,9 +162,11 @@
 	  ></div
 	><div class="top"
 	><p class="src"
-	  ><a name="v:g" class="def"
+	  ><a id="v:g" class="def"
 	    >g</a
-	    > :: t</p
+	    > :: t <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ><div class="doc"
 	  ><ul
 	    ><li
@@ -173,9 +182,11 @@
 	  ></div
 	><div class="top"
 	><p class="src"
-	  ><a name="v:h" class="def"
+	  ><a id="v:h" class="def"
 	    >h</a
-	    > :: t</p
+	    > :: t <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ><div class="doc"
 	  ><ul
 	    ><li
@@ -191,9 +202,11 @@
 	  ></div
 	><div class="top"
 	><p class="src"
-	  ><a name="v:i" class="def"
+	  ><a id="v:i" class="def"
 	    >i</a
-	    > :: t</p
+	    > :: t <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ><div class="doc"
 	  ><ul
 	    ><li
@@ -241,9 +254,11 @@
 	  ></div
 	><div class="top"
 	><p class="src"
-	  ><a name="v:j" class="def"
+	  ><a id="v:j" class="def"
 	    >j</a
-	    > :: t</p
+	    > :: t <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ><div class="doc"
 	  ><dl
 	    ><dt
@@ -309,9 +324,11 @@
 	  ></div
 	><div class="top"
 	><p class="src"
-	  ><a name="v:k" class="def"
+	  ><a id="v:k" class="def"
 	    >k</a
-	    > :: t</p
+	    > :: t <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ><div class="doc"
 	  ><ul
 	    ><li
@@ -335,11 +352,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.16.1</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/NoLayout.html b/html-test/ref/NoLayout.html
--- a/html-test/ref/NoLayout.html
+++ b/html-test/ref/NoLayout.html
@@ -1,32 +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"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_NoLayout.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_NoLayout.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -46,9 +47,9 @@
 	>Synopsis</p
 	><ul id="section.syn" class="hide" onclick="toggleSection('syn')"
 	><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >g</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
 	    ></li
 	  ></ul
@@ -58,15 +59,17 @@
 	>Documentation</h1
 	><div class="top"
 	><p class="src"
-	  ><a name="v:g" class="def"
+	  ><a id="v:g" class="def"
 	    >g</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="doc"
 	  ><p
 	    >the function <code
-	      ><a href=""
+	      ><a href="#"
 		>g</a
 		></code
 	      ></p
@@ -75,11 +78,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.15.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/NonGreedy.html b/html-test/ref/NonGreedy.html
--- a/html-test/ref/NonGreedy.html
+++ b/html-test/ref/NonGreedy.html
@@ -1,32 +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"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_NonGreedy.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_NonGreedy.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -46,7 +47,7 @@
 	>Synopsis</p
 	><ul id="section.syn" class="hide" onclick="toggleSection('syn')"
 	><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >f</a
 	    > :: a</li
 	  ></ul
@@ -56,14 +57,16 @@
 	>Documentation</h1
 	><div class="top"
 	><p class="src"
-	  ><a name="v:f" class="def"
+	  ><a id="v:f" class="def"
 	    >f</a
-	    > :: a</p
+	    > :: a <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ><div class="doc"
 	  ><p
-	    ><a href=""
+	    ><a href="#"
 	      >url1</a
-	      > <a href=""
+	      > <a href="#"
 	      >url2</a
 	      ></p
 	    ></div
@@ -71,11 +74,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.15.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/Operators.html b/html-test/ref/Operators.html
--- a/html-test/ref/Operators.html
+++ b/html-test/ref/Operators.html
@@ -1,32 +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
     >Operators</title
-    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_Operators.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_Operators.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -54,37 +55,37 @@
 	>Synopsis</p
 	><ul id="section.syn" class="hide" onclick="toggleSection('syn')"
 	><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >(+-)</a
 	    > :: a -&gt; a -&gt; a</li
 	  ><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >(*/)</a
 	    > :: a -&gt; a -&gt; a</li
 	  ><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >foo</a
 	    > :: a -&gt; a -&gt; a</li
 	  ><li class="src short"
 	  ><span class="keyword"
 	    >data</span
-	    > <a href=""
+	    > <a href="#"
 	    >Foo</a
 	    ><ul class="subs"
 	    ><li
-	      >= <a href=""
+	      >= <a href="#"
 		>Foo</a
-		> <a href=""
+		> <a href="#"
 		>`Bar`</a
-		> <a href=""
+		> <a href="#"
 		>Foo</a
 		></li
 	      ><li
-	      >| <a href=""
+	      >| <a href="#"
 		>Foo</a
-		> <a href=""
+		> <a href="#"
 		>:-</a
-		> <a href=""
+		> <a href="#"
 		>Foo</a
 		></li
 	      ></ul
@@ -92,21 +93,23 @@
 	  ><li class="src short"
 	  ><span class="keyword"
 	    >pattern</span
-	    > <a href=""
+	    > <a href="#"
 	    >(:+)</a
-	    > ::   t -&gt; t -&gt; [t]</li
+	    > :: <span class="keyword"
+	    >forall</span
+	    > t. t -&gt; t -&gt; [t]</li
 	  ><li class="src short"
 	  ><span class="keyword"
 	    >data</span
-	    > a <a href=""
+	    > a <a href="#"
 	    >&lt;-&gt;</a
 	    > b <span class="keyword"
 	    >where</span
 	    ><ul class="subs"
 	    ><li
-	      ><a href=""
+	      ><a href="#"
 		>(:&lt;-&gt;)</a
-		> ::  a -&gt; b -&gt; a <a href=""
+		> :: a -&gt; b -&gt; a <a href="#"
 		>&lt;-&gt;</a
 		> b</li
 	      ></ul
@@ -114,59 +117,45 @@
 	  ><li class="src short"
 	  ><span class="keyword"
 	    >type family</span
-	    > a <a href=""
+	    > a <a href="#"
 	    >++</a
 	    > b</li
 	  ><li class="src short"
 	  ><span class="keyword"
 	    >data family</span
-	    > a <a href=""
+	    > a <a href="#"
 	    >**</a
 	    > b</li
 	  ><li class="src short"
 	  ><span class="keyword"
 	    >class</span
-	    > a <a href=""
+	    > a <a href="#"
 	    >&gt;&lt;&gt;</a
-	    > b <span class="keyword"
+	    > b | a -&gt; b <span class="keyword"
 	    >where</span
 	    ><ul class="subs"
 	    ><li
 	      ><span class="keyword"
 		>type</span
-		> a <a href=""
+		> a <a href="#"
 		>&lt;&gt;&lt;</a
-		> b :: *</li
+		> b :: <a href="#"
+		>*</a
+		></li
 	      ><li
 	      ><span class="keyword"
 		>data</span
-		> a <a href=""
+		> 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=""
+	    > <a href="#"
 	    >(&gt;-&lt;)</a
-	    > a b = a <a href=""
+	    > a b = a <a href="#"
 	    >&lt;-&gt;</a
 	    > b</li
 	  ></ul
@@ -176,9 +165,11 @@
 	>Documentation</h1
 	><div class="top"
 	><p class="src"
-	  ><a name="v:-43--45-" class="def"
+	  ><a id="v:-43--45-" class="def"
 	    >(+-)</a
-	    > :: a -&gt; a -&gt; a</p
+	    > :: a -&gt; a -&gt; a <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ><div class="doc"
 	  ><p
 	    >Operator with no fixity</p
@@ -186,12 +177,14 @@
 	  ></div
 	><div class="top"
 	><p class="src"
-	  ><a name="v:-42--47-" class="def"
+	  ><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
@@ -200,12 +193,14 @@
 	  ></div
 	><div class="top"
 	><p class="src"
-	  ><a name="v:foo" class="def"
+	  ><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
@@ -216,8 +211,10 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >data</span
-	    > <a name="t:Foo" class="def"
+	    > <a id="t:Foo" class="def"
 	    >Foo</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="doc"
 	  ><p
@@ -229,11 +226,11 @@
 	    ><table
 	    ><tr
 	      ><td class="src"
-		><a href=""
+		><a href="#"
 		  >Foo</a
-		  > <a name="v:Bar" class="def"
+		  > <a id="v:Bar" class="def"
 		  >`Bar`</a
-		  > <a href=""
+		  > <a href="#"
 		  >Foo</a
 		  > <span class="fixity"
 		  >infixl 3</span
@@ -247,11 +244,11 @@
 		></tr
 	      ><tr
 	      ><td class="src"
-		><a href=""
+		><a href="#"
 		  >Foo</a
-		  > <a name="v::-45-" class="def"
+		  > <a id="v::-45-" class="def"
 		  >:-</a
-		  > <a href=""
+		  > <a href="#"
 		  >Foo</a
 		  > <span class="fixity"
 		  >infixr 5</span
@@ -270,12 +267,16 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >pattern</span
-	    > <a name="v::-43-" class="def"
+	    > <a id="v::-43-" class="def"
 	    >(:+)</a
-	    > ::   t -&gt; t -&gt; [t] <span class="fixity"
+	    > :: <span class="keyword"
+	    >forall</span
+	    > t. t -&gt; t -&gt; [t] <span class="fixity"
 	    >infixr 3</span
 	    ><span class="rightedge"
 	    ></span
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="doc"
 	  ><p
@@ -286,7 +287,7 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >data</span
-	    > a <a name="t:-60--45--62-" class="def"
+	    > a <a id="t:-60--45--62-" class="def"
 	    >&lt;-&gt;</a
 	    > b <span class="keyword"
 	    >where</span
@@ -294,6 +295,8 @@
 	    >infixl 6</span
 	    ><span class="rightedge"
 	    ></span
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="doc"
 	  ><p
@@ -305,9 +308,9 @@
 	    ><table
 	    ><tr
 	      ><td class="src"
-		><a name="v::-60--45--62-" class="def"
+		><a id="v::-60--45--62-" class="def"
 		  >(:&lt;-&gt;)</a
-		  > ::  a -&gt; b -&gt; a <a href=""
+		  > :: a -&gt; b -&gt; a <a href="#"
 		  >&lt;-&gt;</a
 		  > b <span class="fixity"
 		  >infixr 6</span
@@ -315,7 +318,7 @@
 		  ></span
 		  ></td
 		><td class="doc empty"
-		>&nbsp;</td
+		></td
 		></tr
 	      ></table
 	    ></div
@@ -324,12 +327,14 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >type family</span
-	    > a <a name="t:-43--43-" class="def"
+	    > 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
@@ -340,12 +345,14 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >data family</span
-	    > a <a name="t:-42--42-" class="def"
+	    > 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
@@ -356,50 +363,76 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >class</span
-	    > a <a name="t:-62--60--62-" class="def"
+	    > a <a id="t:-62--60--62-" class="def"
 	    >&gt;&lt;&gt;</a
-	    > b <span class="keyword"
+	    > 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 minimal"
+	  ><p class="caption"
+	    >Minimal complete definition</p
+	    ><p class="src"
+	    ><a href="#"
+	      >(&gt;&gt;&lt;)</a
+	      >, <a href="#"
+	      >(&lt;&lt;&gt;)</a
+	      >, <a href="#"
+	      >(**&gt;)</a
+	      >, <a href="#"
+	      >(**&lt;)</a
+	      >, <a href="#"
+	      >(&gt;**)</a
+	      >, <a href="#"
+	      >(&lt;**)</a
+	      ></p
+	    ></div
 	  ><div class="subs associated-types"
 	  ><p class="caption"
 	    >Associated Types</p
 	    ><p class="src"
 	    ><span class="keyword"
 	      >type</span
-	      > a <a name="t:-60--62--60-" class="def"
+	      > a <a id="t:-60--62--60-" class="def"
 	      >&lt;&gt;&lt;</a
-	      > b :: * <span class="fixity"
+	      > b :: <a href="#"
+	      >*</a
+	      > <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 name="t:-62--60--60-" class="def"
+	      > 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 name="v:-62--62--60-" class="def"
+	    ><a id="v:-62--62--60-" class="def"
 	      >(&gt;&gt;&lt;)</a
-	      >, <a name="v:-60--60--62-" class="def"
+	      >, <a id="v:-60--60--62-" class="def"
 	      >(&lt;&lt;&gt;)</a
 	      > :: a -&gt; b -&gt; () <span class="fixity"
 	      >infixl 5 &lt;&lt;&gt;</span
@@ -407,15 +440,17 @@
 	      >infixr 4 &gt;&gt;&lt;</span
 	      ><span class="rightedge"
 	      ></span
+	      > <a href="#" class="selflink"
+	      >#</a
 	      ></p
 	    ><p class="src"
-	    ><a name="v:-42--42--62-" class="def"
+	    ><a id="v:-42--42--62-" class="def"
 	      >(**&gt;)</a
-	      >, <a name="v:-42--42--60-" class="def"
+	      >, <a id="v:-42--42--60-" class="def"
 	      >(**&lt;)</a
-	      >, <a name="v:-62--42--42-" class="def"
+	      >, <a id="v:-62--42--42-" class="def"
 	      >(&gt;**)</a
-	      >, <a name="v:-60--42--42-" class="def"
+	      >, <a id="v:-60--42--42-" class="def"
 	      >(&lt;**)</a
 	      > :: a -&gt; a -&gt; () <span class="fixity"
 	      >infixr 8 **&gt;, &gt;**</span
@@ -423,6 +458,8 @@
 	      >infixl 8 **&lt;, &lt;**</span
 	      ><span class="rightedge"
 	      ></span
+	      > <a href="#" class="selflink"
+	      >#</a
 	      ></p
 	    ><div class="doc"
 	    ><p
@@ -434,14 +471,16 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >type</span
-	    > <a name="t:-62--45--60-" class="def"
+	    > <a id="t:-62--45--60-" class="def"
 	    >(&gt;-&lt;)</a
-	    > a b = a <a href=""
+	    > a b = a <a href="#"
 	    >&lt;-&gt;</a
 	    > b <span class="fixity"
 	    >infixl 6</span
 	    ><span class="rightedge"
 	    ></span
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="doc"
 	  ><p
@@ -451,11 +490,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.16.0</p
-      ></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,114 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >OrphanInstances</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_OrphanInstances.html&quot;);};
+//
+</script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ><p class="caption empty"
+      ></p
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>OrphanInstances</p
+	></div
+      ><div id="table-of-contents"
+      ><p class="caption"
+	>Contents</p
+	><ul
+	><li
+	  ><a href="#"
+	    >Orphan instances</a
+	    ></li
+	  ></ul
+	></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')"
+	></ul
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><h1
+	>Orphan instances</h1
+	><div id="section.orphans" class="show"
+	><table
+	  ><tr
+	    ><td class="src clearfix"
+	      ><span class="inst-left"
+		><span id="control.i:o:ic:AClass:AClass:1" class="instance expander" onclick="toggleSection('i:o:ic:AClass:AClass:1')"
+		  ></span
+		  > <a href="#"
+		  >AClass</a
+		  > <a href="#"
+		  >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"
+	      ><div id="section.i:o:ic:AClass:AClass:1" class="inst-details hide"
+		><div class="subs methods"
+		  ><p class="caption"
+		    >Methods</p
+		    ><p class="src"
+		    ><a href="#"
+		      >aClass</a
+		      > :: <a href="#"
+		      >AType</a
+		      > -&gt; <a href="#"
+		      >Int</a
+		      > <a href="#" class="selflink"
+		      >#</a
+		      ></p
+		    ></div
+		  ></div
+		></td
+	      ></tr
+	    ></table
+	  ></div
+	></div
+      ></div
+    ><div id="footer"
+    ></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,86 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >OrphanInstancesClass</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_OrphanInstancesClass.html&quot;);};
+//
+</script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ><p class="caption empty"
+      ></p
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe</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 minimal"
+	  ><p class="caption"
+	    >Minimal complete definition</p
+	    ><p class="src"
+	    ><a href="#"
+	      >aClass</a
+	      ></p
+	    ></div
+	  ><div class="subs methods"
+	  ><p class="caption"
+	    >Methods</p
+	    ><p class="src"
+	    ><a id="v:aClass" class="def"
+	      >aClass</a
+	      > :: a -&gt; <a href="#"
+	      >Int</a
+	      > <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ></div
+	  ></div
+	></div
+      ></div
+    ><div id="footer"
+    ></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,80 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >OrphanInstancesType</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_OrphanInstancesType.html&quot;);};
+//
+</script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ><p class="caption empty"
+      ></p
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe</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="#"
+		  >Int</a
+		  ></td
+		><td class="doc empty"
+		></td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	></div
+      ></div
+    ><div id="footer"
+    ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/PatternSyns.html b/html-test/ref/PatternSyns.html
--- a/html-test/ref/PatternSyns.html
+++ b/html-test/ref/PatternSyns.html
@@ -1,32 +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
     >PatternSyns</title
-    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_PatternSyns.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_PatternSyns.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -56,57 +57,65 @@
 	><li class="src short"
 	  ><span class="keyword"
 	    >data</span
-	    > <a href=""
+	    > <a href="#"
 	    >FooType</a
-	    > x = <a href=""
+	    > x = <a href="#"
 	    >FooCtor</a
 	    > x</li
 	  ><li class="src short"
 	  ><span class="keyword"
 	    >pattern</span
-	    > <a href=""
+	    > <a href="#"
 	    >Foo</a
-	    > ::   t -&gt; <a href=""
+	    > :: <span class="keyword"
+	    >forall</span
+	    > t. t -&gt; <a href="#"
 	    >FooType</a
 	    > t</li
 	  ><li class="src short"
 	  ><span class="keyword"
 	    >pattern</span
-	    > <a href=""
+	    > <a href="#"
 	    >Bar</a
-	    > ::   t -&gt; <a href=""
+	    > :: <span class="keyword"
+	    >forall</span
+	    > t. t -&gt; <a href="#"
 	    >FooType</a
-	    > (<a href=""
+	    > (<a href="#"
 	    >FooType</a
 	    > t)</li
 	  ><li class="src short"
 	  ><span class="keyword"
 	    >pattern</span
-	    > <a href=""
+	    > <a href="#"
 	    >(:&lt;-&gt;)</a
-	    > ::   t -&gt; t -&gt; (<a href=""
+	    > :: <span class="keyword"
+	    >forall</span
+	    > t t1. t -&gt; t1 -&gt; (<a href="#"
 	    >FooType</a
-	    > t, <a href=""
+	    > t, <a href="#"
 	    >FooType</a
-	    > (<a href=""
+	    > (<a href="#"
 	    >FooType</a
-	    > t))</li
+	    > t1))</li
 	  ><li class="src short"
 	  ><span class="keyword"
 	    >data</span
-	    > a <a href=""
+	    > a <a href="#"
 	    >&gt;&lt;</a
-	    > b = <a href=""
+	    > b = <a href="#"
 	    >Empty</a
 	    ></li
 	  ><li class="src short"
 	  ><span class="keyword"
 	    >pattern</span
-	    > <a href=""
+	    > <a href="#"
 	    >E</a
-	    > ::   <a href=""
+	    > :: <span class="keyword"
+	    >forall</span
+	    > k t t1. <a href="#"
 	    >(&gt;&lt;)</a
-	    > k t t</li
+	    > k t t1</li
 	  ></ul
 	></div
       ><div id="interface"
@@ -116,9 +125,11 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >data</span
-	    > <a name="t:FooType" class="def"
+	    > <a id="t:FooType" class="def"
 	    >FooType</a
-	    > x</p
+	    > x <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ><div class="doc"
 	  ><p
 	    >FooType doc</p
@@ -129,11 +140,11 @@
 	    ><table
 	    ><tr
 	      ><td class="src"
-		><a name="v:FooCtor" class="def"
+		><a id="v:FooCtor" class="def"
 		  >FooCtor</a
 		  > x</td
 		><td class="doc empty"
-		>&nbsp;</td
+		></td
 		></tr
 	      ></table
 	    ></div
@@ -142,15 +153,19 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >pattern</span
-	    > <a name="v:Foo" class="def"
+	    > <a id="v:Foo" class="def"
 	    >Foo</a
-	    > ::   t -&gt; <a href=""
+	    > :: <span class="keyword"
+	    >forall</span
+	    > t. t -&gt; <a href="#"
 	    >FooType</a
-	    > t</p
+	    > t <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ><div class="doc"
 	  ><p
 	    >Pattern synonym for <code
-	      ><a href=""
+	      ><a href="#"
 		>Foo</a
 		></code
 	      > x</p
@@ -160,17 +175,21 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >pattern</span
-	    > <a name="v:Bar" class="def"
+	    > <a id="v:Bar" class="def"
 	    >Bar</a
-	    > ::   t -&gt; <a href=""
+	    > :: <span class="keyword"
+	    >forall</span
+	    > t. t -&gt; <a href="#"
 	    >FooType</a
-	    > (<a href=""
+	    > (<a href="#"
 	    >FooType</a
-	    > t)</p
+	    > t) <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ><div class="doc"
 	  ><p
 	    >Pattern synonym for <code
-	      ><a href=""
+	      ><a href="#"
 		>Bar</a
 		></code
 	      > x</p
@@ -180,19 +199,23 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >pattern</span
-	    > <a name="v::-60--45--62-" class="def"
+	    > <a id="v::-60--45--62-" class="def"
 	    >(:&lt;-&gt;)</a
-	    > ::   t -&gt; t -&gt; (<a href=""
+	    > :: <span class="keyword"
+	    >forall</span
+	    > t t1. t -&gt; t1 -&gt; (<a href="#"
 	    >FooType</a
-	    > t, <a href=""
+	    > t, <a href="#"
 	    >FooType</a
-	    > (<a href=""
+	    > (<a href="#"
 	    >FooType</a
-	    > t))</p
+	    > t1)) <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ><div class="doc"
 	  ><p
 	    >Pattern synonym for (<code
-	      ><a href=""
+	      ><a href="#"
 		>:&lt;-&gt;</a
 		></code
 	      >)</p
@@ -202,13 +225,17 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >data</span
-	    > a <a name="t:-62--60-" class="def"
+	    > a <a id="t:-62--60-" class="def"
 	    >&gt;&lt;</a
-	    > b</p
+	    > b <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ><div class="doc"
 	  ><p
 	    >Doc for (<code
-	      >&gt;&lt;</code
+	      ><a href="#"
+		>&gt;&lt;</a
+		></code
 	      >)</p
 	    ></div
 	  ><div class="subs constructors"
@@ -217,11 +244,11 @@
 	    ><table
 	    ><tr
 	      ><td class="src"
-		><a name="v:Empty" class="def"
+		><a id="v:Empty" class="def"
 		  >Empty</a
 		  ></td
 		><td class="doc empty"
-		>&nbsp;</td
+		></td
 		></tr
 	      ></table
 	    ></div
@@ -230,15 +257,19 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >pattern</span
-	    > <a name="v:E" class="def"
+	    > <a id="v:E" class="def"
 	    >E</a
-	    > ::   <a href=""
+	    > :: <span class="keyword"
+	    >forall</span
+	    > k t t1. <a href="#"
 	    >(&gt;&lt;)</a
-	    > k t t</p
+	    > k t t1 <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ><div class="doc"
 	  ><p
 	    >Pattern for <code
-	      ><a href=""
+	      ><a href="#"
 		>Empty</a
 		></code
 	      ></p
@@ -247,11 +278,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.15.0</p
-      ></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,220 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >PromotedTypes</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_PromotedTypes.html&quot;);};
+//
+</script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ><p class="caption empty"
+      ></p
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe</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"
+		></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		>(<a href="#"
+		  >RevList</a
+		  > a) <a id="v::-62-" class="def"
+		  >:&gt;</a
+		  > a</td
+		><td class="doc empty"
+		></td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:Pattern" class="def"
+	    >Pattern</a
+	    > :: [<a href="#"
+	    >*</a
+	    >] -&gt; <a href="#"
+	    >*</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:Nil" class="def"
+		  >Nil</a
+		  > :: <a href="#"
+		  >Pattern</a
+		  > '[]</td
+		><td class="doc empty"
+		></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		><a id="v:Cons" class="def"
+		  >Cons</a
+		  > :: <a href="#"
+		  >Maybe</a
+		  > h -&gt; <a href="#"
+		  >Pattern</a
+		  > t -&gt; <a href="#"
+		  >Pattern</a
+		  > (h ': t)</td
+		><td class="doc empty"
+		></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="#"
+	    >RevList</a
+	    > <a href="#"
+	    >*</a
+	    > -&gt; <a href="#"
+	    >*</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:RevNil" class="def"
+		  >RevNil</a
+		  > :: <a href="#"
+		  >RevPattern</a
+		  > <a href="#"
+		  >RNil</a
+		  ></td
+		><td class="doc empty"
+		></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		><a id="v:RevCons" class="def"
+		  >RevCons</a
+		  > :: <a href="#"
+		  >Maybe</a
+		  > h -&gt; <a href="#"
+		  >RevPattern</a
+		  > t -&gt; <a href="#"
+		  >RevPattern</a
+		  > (t <a href="#"
+		  >:&gt;</a
+		  > h)</td
+		><td class="doc empty"
+		></td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >data</span
+	    > <a id="t:Tuple" class="def"
+	    >Tuple</a
+	    > :: (<a href="#"
+	    >*</a
+	    >, <a href="#"
+	    >*</a
+	    >) -&gt; <a href="#"
+	    >*</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:Tuple" class="def"
+		  >Tuple</a
+		  > :: a -&gt; b -&gt; <a href="#"
+		  >Tuple</a
+		  > '(a, b)</td
+		><td class="doc empty"
+		></td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	></div
+      ></div
+    ><div id="footer"
+    ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Properties.html b/html-test/ref/Properties.html
--- a/html-test/ref/Properties.html
+++ b/html-test/ref/Properties.html
@@ -1,32 +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"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_Properties.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_Properties.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -46,11 +47,11 @@
 	>Synopsis</p
 	><ul id="section.syn" class="hide" onclick="toggleSection('syn')"
 	><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >fib</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Integer</a
-	    > -&gt; <a href=""
+	    > -&gt; <a href="#"
 	    >Integer</a
 	    ></li
 	  ></ul
@@ -60,17 +61,19 @@
 	>Documentation</h1
 	><div class="top"
 	><p class="src"
-	  ><a name="v:fib" class="def"
+	  ><a id="v:fib" class="def"
 	    >fib</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Integer</a
-	    > -&gt; <a href=""
+	    > -&gt; <a href="#"
 	    >Integer</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="doc"
 	  ><p
 	    >Fibonacci number of given <code
-	      ><a href=""
+	      ><a href="#"
 		>Integer</a
 		></code
 	      >.</p
@@ -81,11 +84,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.15.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/PruneWithWarning.html b/html-test/ref/PruneWithWarning.html
--- a/html-test/ref/PruneWithWarning.html
+++ b/html-test/ref/PruneWithWarning.html
@@ -1,32 +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
     >PruneWithWarning</title
-    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_PruneWithWarning.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_PruneWithWarning.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -60,11 +61,7 @@
       ></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.15.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/QuasiExpr.html b/html-test/ref/QuasiExpr.html
--- a/html-test/ref/QuasiExpr.html
+++ b/html-test/ref/QuasiExpr.html
@@ -1,32 +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
     >QuasiExpr</title
-    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_QuasiExpr.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_QuasiExpr.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -48,8 +49,10 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >data</span
-	    > <a name="t:Expr" class="def"
+	    > <a id="t:Expr" class="def"
 	    >Expr</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="subs constructors"
 	  ><p class="caption"
@@ -57,47 +60,47 @@
 	    ><table
 	    ><tr
 	      ><td class="src"
-		><a name="v:IntExpr" class="def"
+		><a id="v:IntExpr" class="def"
 		  >IntExpr</a
-		  > <a href=""
+		  > <a href="#"
 		  >Integer</a
 		  ></td
 		><td class="doc empty"
-		>&nbsp;</td
+		></td
 		></tr
 	      ><tr
 	      ><td class="src"
-		><a name="v:AntiIntExpr" class="def"
+		><a id="v:AntiIntExpr" class="def"
 		  >AntiIntExpr</a
-		  > <a href=""
+		  > <a href="#"
 		  >String</a
 		  ></td
 		><td class="doc empty"
-		>&nbsp;</td
+		></td
 		></tr
 	      ><tr
 	      ><td class="src"
-		><a name="v:BinopExpr" class="def"
+		><a id="v:BinopExpr" class="def"
 		  >BinopExpr</a
-		  > <a href=""
+		  > <a href="#"
 		  >BinOp</a
-		  > <a href=""
+		  > <a href="#"
 		  >Expr</a
-		  > <a href=""
+		  > <a href="#"
 		  >Expr</a
 		  ></td
 		><td class="doc empty"
-		>&nbsp;</td
+		></td
 		></tr
 	      ><tr
 	      ><td class="src"
-		><a name="v:AntiExpr" class="def"
+		><a id="v:AntiExpr" class="def"
 		  >AntiExpr</a
-		  > <a href=""
+		  > <a href="#"
 		  >String</a
 		  ></td
 		><td class="doc empty"
-		>&nbsp;</td
+		></td
 		></tr
 	      ></table
 	    ></div
@@ -109,15 +112,61 @@
 	      ><tr
 		><td class="src clearfix"
 		  ><span class="inst-left"
-		    ><a href=""
+		    ><span id="control.i:id:Expr:Show:1" class="instance expander" onclick="toggleSection('i:id:Expr:Show:1')"
+		      ></span
+		      > <a href="#"
 		      >Show</a
-		      > <a href=""
+		      > <a href="#"
 		      >Expr</a
 		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
 		    ></td
 		  ><td class="doc empty"
-		  >&nbsp;</td
+		  ></td
 		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:id:Expr:Show:1" class="inst-details hide"
+		    ><div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >showsPrec</a
+			  > :: <a href="#"
+			  >Int</a
+			  > -&gt; <a href="#"
+			  >Expr</a
+			  > -&gt; <a href="#"
+			  >ShowS</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >show</a
+			  > :: <a href="#"
+			  >Expr</a
+			  > -&gt; <a href="#"
+			  >String</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >showList</a
+			  > :: [<a href="#"
+			  >Expr</a
+			  >] -&gt; <a href="#"
+			  >ShowS</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></div
+		    ></td
+		  ></tr
 		></table
 	      ></div
 	    ></div
@@ -126,8 +175,10 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >data</span
-	    > <a name="t:BinOp" class="def"
+	    > <a id="t:BinOp" class="def"
 	    >BinOp</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="subs constructors"
 	  ><p class="caption"
@@ -135,35 +186,35 @@
 	    ><table
 	    ><tr
 	      ><td class="src"
-		><a name="v:AddOp" class="def"
+		><a id="v:AddOp" class="def"
 		  >AddOp</a
 		  ></td
 		><td class="doc empty"
-		>&nbsp;</td
+		></td
 		></tr
 	      ><tr
 	      ><td class="src"
-		><a name="v:SubOp" class="def"
+		><a id="v:SubOp" class="def"
 		  >SubOp</a
 		  ></td
 		><td class="doc empty"
-		>&nbsp;</td
+		></td
 		></tr
 	      ><tr
 	      ><td class="src"
-		><a name="v:MulOp" class="def"
+		><a id="v:MulOp" class="def"
 		  >MulOp</a
 		  ></td
 		><td class="doc empty"
-		>&nbsp;</td
+		></td
 		></tr
 	      ><tr
 	      ><td class="src"
-		><a name="v:DivOp" class="def"
+		><a id="v:DivOp" class="def"
 		  >DivOp</a
 		  ></td
 		><td class="doc empty"
-		>&nbsp;</td
+		></td
 		></tr
 	      ></table
 	    ></div
@@ -175,51 +226,99 @@
 	      ><tr
 		><td class="src clearfix"
 		  ><span class="inst-left"
-		    ><a href=""
+		    ><span id="control.i:id:BinOp:Show:1" class="instance expander" onclick="toggleSection('i:id:BinOp:Show:1')"
+		      ></span
+		      > <a href="#"
 		      >Show</a
-		      > <a href=""
+		      > <a href="#"
 		      >BinOp</a
 		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
 		    ></td
 		  ><td class="doc empty"
-		  >&nbsp;</td
+		  ></td
 		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:id:BinOp:Show:1" class="inst-details hide"
+		    ><div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >showsPrec</a
+			  > :: <a href="#"
+			  >Int</a
+			  > -&gt; <a href="#"
+			  >BinOp</a
+			  > -&gt; <a href="#"
+			  >ShowS</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >show</a
+			  > :: <a href="#"
+			  >BinOp</a
+			  > -&gt; <a href="#"
+			  >String</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >showList</a
+			  > :: [<a href="#"
+			  >BinOp</a
+			  >] -&gt; <a href="#"
+			  >ShowS</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></div
+		    ></td
+		  ></tr
 		></table
 	      ></div
 	    ></div
 	  ></div
 	><div class="top"
 	><p class="src"
-	  ><a name="v:eval" class="def"
+	  ><a id="v:eval" class="def"
 	    >eval</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Expr</a
-	    > -&gt; <a href=""
+	    > -&gt; <a href="#"
 	    >Integer</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ></div
 	><div class="top"
 	><p class="src"
-	  ><a name="v:expr" class="def"
+	  ><a id="v:expr" class="def"
 	    >expr</a
-	    > :: QuasiQuoter</p
+	    > :: QuasiQuoter <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ></div
 	><div class="top"
 	><p class="src"
-	  ><a name="v:parseExprExp" class="def"
+	  ><a id="v:parseExprExp" class="def"
 	    >parseExprExp</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >String</a
-	    > -&gt; Q Exp</p
+	    > -&gt; Q Exp <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ></div
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.16.1</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/QuasiQuote.html b/html-test/ref/QuasiQuote.html
--- a/html-test/ref/QuasiQuote.html
+++ b/html-test/ref/QuasiQuote.html
@@ -1,32 +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"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_QuasiQuote.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_QuasiQuote.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -46,20 +47,18 @@
 	>Documentation</h1
 	><div class="top"
 	><p class="src"
-	  ><a name="v:val" class="def"
+	  ><a id="v:val" class="def"
 	    >val</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Integer</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ></div
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.15.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/SpuriousSuperclassConstraints.html b/html-test/ref/SpuriousSuperclassConstraints.html
--- a/html-test/ref/SpuriousSuperclassConstraints.html
+++ b/html-test/ref/SpuriousSuperclassConstraints.html
@@ -1,32 +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
     >SpuriousSuperclassConstraints</title
-    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_SpuriousSuperclassConstraints.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_SpuriousSuperclassConstraints.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -51,13 +52,13 @@
 	  >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=""
+	  ><a href="#"
 	    >http://www.haskell.org/pipermail/haskell-cafe/2012-September/103600.html</a
 	    ></p
 	  ><p
 	  >And here is the corresponding theard on glasgow-haskell-users:</p
 	  ><p
-	  ><a href=""
+	  ><a href="#"
 	    >http://www.haskell.org/pipermail/glasgow-haskell-users/2012-September/022914.html</a
 	    ></p
 	  ><p
@@ -74,9 +75,11 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >data</span
-	    > <a name="t:SomeType" class="def"
+	    > <a id="t:SomeType" class="def"
 	    >SomeType</a
-	    > f a</p
+	    > f a <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ><div class="subs instances"
 	  ><p id="control.i:SomeType" class="caption collapser" onclick="toggleSection('i:SomeType')"
 	    >Instances</p
@@ -85,29 +88,121 @@
 	      ><tr
 		><td class="src clearfix"
 		  ><span class="inst-left"
-		    ><a href=""
+		    ><span id="control.i:id:SomeType:Functor:1" class="instance expander" onclick="toggleSection('i:id:SomeType:Functor:1')"
+		      ></span
+		      > <a href="#"
 		      >Functor</a
-		      > (<a href=""
+		      > (<a href="#"
 		      >SomeType</a
 		      > f)</span
+		    > <a href="#" class="selflink"
+		    >#</a
 		    ></td
 		  ><td class="doc empty"
-		  >&nbsp;</td
+		  ></td
 		  ></tr
 		><tr
+		><td colspan="2"
+		  ><div id="section.i:id:SomeType:Functor:1" class="inst-details hide"
+		    ><div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >fmap</a
+			  > :: (a -&gt; b) -&gt; <a href="#"
+			  >SomeType</a
+			  > f a -&gt; <a href="#"
+			  >SomeType</a
+			  > f b <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >(&lt;$)</a
+			  > :: a -&gt; <a href="#"
+			  >SomeType</a
+			  > f b -&gt; <a href="#"
+			  >SomeType</a
+			  > f a <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></div
+		    ></td
+		  ></tr
+		><tr
 		><td class="src clearfix"
 		  ><span class="inst-left"
-		    ><a href=""
+		    ><span id="control.i:id:SomeType:Applicative:2" class="instance expander" onclick="toggleSection('i:id:SomeType:Applicative:2')"
+		      ></span
+		      > <a href="#"
 		      >Applicative</a
-		      > f =&gt; <a href=""
+		      > f =&gt; <a href="#"
 		      >Applicative</a
-		      > (<a href=""
+		      > (<a href="#"
 		      >SomeType</a
 		      > f)</span
+		    > <a href="#" class="selflink"
+		    >#</a
 		    ></td
 		  ><td class="doc empty"
-		  >&nbsp;</td
+		  ></td
 		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:id:SomeType:Applicative:2" class="inst-details hide"
+		    ><div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >pure</a
+			  > :: a -&gt; <a href="#"
+			  >SomeType</a
+			  > f a <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >(&lt;*&gt;)</a
+			  > :: <a href="#"
+			  >SomeType</a
+			  > f (a -&gt; b) -&gt; <a href="#"
+			  >SomeType</a
+			  > f a -&gt; <a href="#"
+			  >SomeType</a
+			  > f b <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >(*&gt;)</a
+			  > :: <a href="#"
+			  >SomeType</a
+			  > f a -&gt; <a href="#"
+			  >SomeType</a
+			  > f b -&gt; <a href="#"
+			  >SomeType</a
+			  > f b <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >(&lt;*)</a
+			  > :: <a href="#"
+			  >SomeType</a
+			  > f a -&gt; <a href="#"
+			  >SomeType</a
+			  > f b -&gt; <a href="#"
+			  >SomeType</a
+			  > f a <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></div
+		    ></td
+		  ></tr
 		></table
 	      ></div
 	    ></div
@@ -115,11 +210,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.16.1</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/TH.html b/html-test/ref/TH.html
--- a/html-test/ref/TH.html
+++ b/html-test/ref/TH.html
@@ -1,32 +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"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_TH.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_TH.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -46,18 +47,16 @@
 	>Documentation</h1
 	><div class="top"
 	><p class="src"
-	  ><a name="v:decl" class="def"
+	  ><a id="v:decl" class="def"
 	    >decl</a
-	    > :: Q [Dec]</p
+	    > :: Q [Dec] <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ></div
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.15.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/TH2.html b/html-test/ref/TH2.html
--- a/html-test/ref/TH2.html
+++ b/html-test/ref/TH2.html
@@ -1,32 +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"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_TH2.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_TH2.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -46,18 +47,16 @@
 	>Documentation</h1
 	><div class="top"
 	><p class="src"
-	  ><a name="v:f" class="def"
+	  ><a id="v:f" class="def"
 	    >f</a
-	    > :: t -&gt; t</p
+	    > :: t -&gt; t <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ></div
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.15.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/Test.html b/html-test/ref/Test.html
--- a/html-test/ref/Test.html
+++ b/html-test/ref/Test.html
@@ -1,2123 +1,2288 @@
-<!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 type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_Test.html");};
-//]]>
-</script
-    ></head
-  ><body
-  ><div id="package-header"
-    ><ul class="links" id="page-menu"
-      ><li
-	><a href=""
-	  >Contents</a
-	  ></li
-	><li
-	><a href=""
-	  >Index</a
-	  ></li
-	></ul
-      ><p class="caption empty"
-      >&nbsp;</p
-      ></div
-    ><div id="content"
-    ><div id="module-header"
-      ><table class="info"
-	><tr
-	  ><th
-	    >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</td
-	    ></tr
-	  ></table
-	><p class="caption"
-	>Test</p
-	></div
-      ><div id="table-of-contents"
-      ><p class="caption"
-	>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 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=""
-	      >T</a
-	      ></code
-	    >, <code
-	    ><a href=""
-	      >f</a
-	      ></code
-	    >, <code
-	    ><a href=""
-	      >g</a
-	      ></code
-	    >, <code
-	    ><a href=""
-	      >visible</a
-	      ></code
-	    >.</p
-	  ></div
-	></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"
-	  ><span class="keyword"
-	    >data</span
-	    > <a href=""
-	    >T</a
-	    > a b<ul class="subs"
-	    ><li
-	      >= <a href=""
-		>A</a
-		> <a href=""
-		>Int</a
-		> (<a href=""
-		>Maybe</a
-		> <a href=""
-		>Float</a
-		>)</li
-	      ><li
-	      >| <a href=""
-		>B</a
-		> (<a href=""
-		>T</a
-		> a b, <a href=""
-		>T</a
-		> <a href=""
-		>Int</a
-		> <a href=""
-		>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=""
-		    >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=""
-		    >Int</a
-		    ></li
-		  ></ul
-		> }</li
-	      ><li
-	      >| <a href=""
-		>C2</a
-		> { <ul class="subs"
-		><li
-		  ><a href=""
-		    >t</a
-		    > :: T1 -&gt; <a href=""
-		    >T2</a
-		    > <a href=""
-		    >Int</a
-		    > <a href=""
-		    >Int</a
-		    > -&gt; <a href=""
-		    >T3</a
-		    > <a href=""
-		    >Bool</a
-		    > <a href=""
-		    >Bool</a
-		    > -&gt; <a href=""
-		    >T4</a
-		    > <a href=""
-		    >Float</a
-		    > <a href=""
-		    >Float</a
-		    > -&gt; <a href=""
-		    >T5</a
-		    > () ()</li
-		  ><li
-		  ><a href=""
-		    >u</a
-		    >, <a href=""
-		    >v</a
-		    > :: <a href=""
-		    >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=""
-		>Int</a
-		></li
-	      ><li
-	      ><a href=""
-		>s2</a
-		> :: <a href=""
-		>Int</a
-		></li
-	      ><li
-	      ><a href=""
-		>s3</a
-		> :: <a href=""
-		>Int</a
-		></li
-	      ></ul
-	    >}</li
-	  ><li class="src short"
-	  ><span class="keyword"
-	    >class</span
-	    > <a href=""
-	    >D</a
-	    > a =&gt; <a href=""
-	    >C</a
-	    > a <span class="keyword"
-	    >where</span
-	    ><ul class="subs"
-	    ><li
-	      ><a href=""
-		>a</a
-		> :: <a href=""
-		>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=""
-		>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=""
-	    >f</a
-	    > :: <a href=""
-	    >C</a
-	    > a =&gt; a -&gt; <a href=""
-	    >Int</a
-	    ></li
-	  ><li class="src short"
-	  ><a href=""
-	    >g</a
-	    > :: <a href=""
-	    >Int</a
-	    > -&gt; <a href=""
-	    >IO</a
-	    > CInt</li
-	  ><li class="src short"
-	  ><a href=""
-	    >hidden</a
-	    > :: <a href=""
-	    >Int</a
-	    > -&gt; <a href=""
-	    >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=""
-		>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=""
-		>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=""
-	    >T</a
-	    > () () -&gt; <a href=""
-	    >T2</a
-	    > <a href=""
-	    >Int</a
-	    > <a href=""
-	    >Int</a
-	    > -&gt; (<a href=""
-	    >T3</a
-	    > <a href=""
-	    >Bool</a
-	    > <a href=""
-	    >Bool</a
-	    > -&gt; <a href=""
-	    >T4</a
-	    > <a href=""
-	    >Float</a
-	    > <a href=""
-	    >Float</a
-	    >) -&gt; <a href=""
-	    >T5</a
-	    > () () -&gt; <a href=""
-	    >IO</a
-	    > ()</li
-	  ><li class="src short"
-	  ><a href=""
-	    >l</a
-	    > :: (<a href=""
-	    >Int</a
-	    >, <a href=""
-	    >Int</a
-	    >, <a href=""
-	    >Float</a
-	    >) -&gt; <a href=""
-	    >Int</a
-	    ></li
-	  ><li class="src short"
-	  ><a href=""
-	    >m</a
-	    > :: <a href=""
-	    >R</a
-	    > -&gt; <a href=""
-	    >N1</a
-	    > () -&gt; <a href=""
-	    >IO</a
-	    > <a href=""
-	    >Int</a
-	    ></li
-	  ><li class="src short"
-	  ><a href=""
-	    >o</a
-	    > :: <a href=""
-	    >Float</a
-	    > -&gt; <a href=""
-	    >IO</a
-	    > <a href=""
-	    >Float</a
-	    ></li
-	  ><li class="src short"
-	  ><a href=""
-	    >f'</a
-	    > :: <a href=""
-	    >Int</a
-	    ></li
-	  ><li class="src short"
-	  ><a href=""
-	    >withType</a
-	    > :: <a href=""
-	    >Int</a
-	    ></li
-	  ><li class="src short"
-	  ><a href=""
-	    >withoutType</a
-	    > :: t</li
-	  ></ul
-	></div
-      ><div id="interface"
-      ><h1 id="g:1"
-	>Type declarations</h1
-	><h2 id="g:2"
-	>Data types</h2
-	><div class="top"
-	><p class="src"
-	  ><span class="keyword"
-	    >data</span
-	    > <a name="t:T" class="def"
-	    >T</a
-	    > a b</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 name="v:A" class="def"
-		  >A</a
-		  > <a href=""
-		  >Int</a
-		  > (<a href=""
-		  >Maybe</a
-		  > <a href=""
-		  >Float</a
-		  >)</td
-		><td class="doc"
-		><p
-		  >This comment describes the <code
-		    ><a href=""
-		      >A</a
-		      ></code
-		    > constructor</p
-		  ></td
-		></tr
-	      ><tr
-	      ><td class="src"
-		><a name="v:B" class="def"
-		  >B</a
-		  > (<a href=""
-		  >T</a
-		  > a b, <a href=""
-		  >T</a
-		  > <a href=""
-		  >Int</a
-		  > <a href=""
-		  >Float</a
-		  >)</td
-		><td class="doc"
-		><p
-		  >This comment describes the <code
-		    ><a href=""
-		      >B</a
-		      ></code
-		    > constructor</p
-		  ></td
-		></tr
-	      ></table
-	    ></div
-	  ></div
-	><div class="top"
-	><p class="src"
-	  ><span class="keyword"
-	    >data</span
-	    > <a name="t:T2" class="def"
-	    >T2</a
-	    > a b</p
-	  ><div class="doc"
-	  ><p
-	    >An abstract data declaration</p
-	    ></div
-	  ></div
-	><div class="top"
-	><p class="src"
-	  ><span class="keyword"
-	    >data</span
-	    > <a name="t:T3" class="def"
-	    >T3</a
-	    > a b</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 name="v:A1" class="def"
-		  >A1</a
-		  > a</td
-		><td class="doc empty"
-		>&nbsp;</td
-		></tr
-	      ><tr
-	      ><td class="src"
-		><a name="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 name="t:T4" class="def"
-	    >T4</a
-	    > a b</p
-	  ><div class="subs constructors"
-	  ><p class="caption"
-	    >Constructors</p
-	    ><table
-	    ><tr
-	      ><td class="src"
-		><a name="v:A2" class="def"
-		  >A2</a
-		  > a</td
-		><td class="doc empty"
-		>&nbsp;</td
-		></tr
-	      ><tr
-	      ><td class="src"
-		><a name="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 name="t:T5" class="def"
-	    >T5</a
-	    > a b</p
-	  ><div class="subs constructors"
-	  ><p class="caption"
-	    >Constructors</p
-	    ><table
-	    ><tr
-	      ><td class="src"
-		><a name="v:A3" class="def"
-		  >A3</a
-		  > a</td
-		><td class="doc"
-		><p
-		  >documents <code
-		    ><a href=""
-		      >A3</a
-		      ></code
-		    ></p
-		  ></td
-		></tr
-	      ><tr
-	      ><td class="src"
-		><a name="v:B3" class="def"
-		  >B3</a
-		  > b</td
-		><td class="doc"
-		><p
-		  >documents <code
-		    ><a href=""
-		      >B3</a
-		      ></code
-		    ></p
-		  ></td
-		></tr
-	      ></table
-	    ></div
-	  ></div
-	><div class="top"
-	><p class="src"
-	  ><span class="keyword"
-	    >data</span
-	    > <a name="t:T6" class="def"
-	    >T6</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 name="v:A4" class="def"
-		  >A4</a
-		  ></td
-		><td class="doc"
-		><p
-		  >This is the doc for <code
-		    ><a href=""
-		      >A4</a
-		      ></code
-		    ></p
-		  ></td
-		></tr
-	      ><tr
-	      ><td class="src"
-		><a name="v:B4" class="def"
-		  >B4</a
-		  ></td
-		><td class="doc"
-		><p
-		  >This is the doc for <code
-		    ><a href=""
-		      >B4</a
-		      ></code
-		    ></p
-		  ></td
-		></tr
-	      ><tr
-	      ><td class="src"
-		><a name="v:C4" class="def"
-		  >C4</a
-		  ></td
-		><td class="doc"
-		><p
-		  >This is the doc for <code
-		    ><a href=""
-		      >C4</a
-		      ></code
-		    ></p
-		  ></td
-		></tr
-	      ></table
-	    ></div
-	  ></div
-	><div class="top"
-	><p class="src"
-	  ><span class="keyword"
-	    >newtype</span
-	    > <a name="t:N1" class="def"
-	    >N1</a
-	    > 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 name="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 name="t:N2" class="def"
-	    >N2</a
-	    > a b</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 name="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
-		    ><dl
-		    ><dt class="src"
-		      ><a name="v:n" class="def"
-			>n</a
-			> :: a b</dt
-		      ><dd class="doc empty"
-		      >&nbsp;</dd
-		      ></dl
-		    ><div class="clear"
-		    ></div
-		    ></div
-		  ></td
-		></tr
-	      ></table
-	    ></div
-	  ></div
-	><div class="top"
-	><p class="src"
-	  ><span class="keyword"
-	    >newtype</span
-	    > <a name="t:N3" class="def"
-	    >N3</a
-	    > a b</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 name="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
-		    ><dl
-		    ><dt class="src"
-		      ><a name="v:n3" class="def"
-			>n3</a
-			> :: a b</dt
-		      ><dd class="doc"
-		      ><p
-			>this is the <code
-			  ><a href=""
-			    >n3</a
-			    ></code
-			  > field</p
-			></dd
-		      ></dl
-		    ><div class="clear"
-		    ></div
-		    ></div
-		  ></td
-		></tr
-	      ></table
-	    ></div
-	  ></div
-	><div class="top"
-	><p class="src"
-	  ><span class="keyword"
-	    >data</span
-	    > <a name="t:N4" class="def"
-	    >N4</a
-	    > a b</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 name="t:N5" class="def"
-	    >N5</a
-	    > a b</p
-	  ><div class="subs constructors"
-	  ><p class="caption"
-	    >Constructors</p
-	    ><table
-	    ><tr
-	      ><td class="src"
-		><a name="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
-		    ><dl
-		    ><dt class="src"
-		      ><a name="v:n5" class="def"
-			>n5</a
-			> :: a b</dt
-		      ><dd class="doc"
-		      ><p
-			>no docs on the datatype or the constructor</p
-			></dd
-		      ></dl
-		    ><div class="clear"
-		    ></div
-		    ></div
-		  ></td
-		></tr
-	      ></table
-	    ></div
-	  ></div
-	><div class="top"
-	><p class="src"
-	  ><span class="keyword"
-	    >newtype</span
-	    > <a name="t:N6" class="def"
-	    >N6</a
-	    > a b</p
-	  ><div class="subs constructors"
-	  ><p class="caption"
-	    >Constructors</p
-	    ><table
-	    ><tr
-	      ><td class="src"
-		><a name="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
-		    ><dl
-		    ><dt class="src"
-		      ><a name="v:n6" class="def"
-			>n6</a
-			> :: a b</dt
-		      ><dd class="doc empty"
-		      >&nbsp;</dd
-		      ></dl
-		    ><div class="clear"
-		    ></div
-		    ></div
-		  ></td
-		></tr
-	      ></table
-	    ></div
-	  ></div
-	><div class="top"
-	><p class="src"
-	  ><span class="keyword"
-	    >newtype</span
-	    > <a name="t:N7" class="def"
-	    >N7</a
-	    > a b</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 name="v:N7" class="def"
-		  >N7</a
-		  ></td
-		><td class="doc"
-		><p
-		  >The <code
-		    ><a href=""
-		      >N7</a
-		      ></code
-		    > constructor</p
-		  ></td
-		></tr
-	      ><tr
-	      ><td colspan="2"
-		><div class="subs fields"
-		  ><p class="caption"
-		    >Fields</p
-		    ><dl
-		    ><dt class="src"
-		      ><a name="v:n7" class="def"
-			>n7</a
-			> :: a b</dt
-		      ><dd class="doc empty"
-		      >&nbsp;</dd
-		      ></dl
-		    ><div class="clear"
-		    ></div
-		    ></div
-		  ></td
-		></tr
-	      ></table
-	    ></div
-	  ></div
-	><h2 id="g:3"
-	>Records</h2
-	><div class="top"
-	><p class="src"
-	  ><span class="keyword"
-	    >data</span
-	    > <a name="t:R" class="def"
-	    >R</a
-	    ></p
-	  ><div class="doc"
-	  ><p
-	    >This is the documentation for the <code
-	      ><a href=""
-		>R</a
-		></code
-	      > record, which has four fields,
- <code
-	      ><a href=""
-		>p</a
-		></code
-	      >, <code
-	      ><a href=""
-		>q</a
-		></code
-	      >, <code
-	      ><a href=""
-		>r</a
-		></code
-	      >, and <code
-	      ><a href=""
-		>s</a
-		></code
-	      >.</p
-	    ></div
-	  ><div class="subs constructors"
-	  ><p class="caption"
-	    >Constructors</p
-	    ><table
-	    ><tr
-	      ><td class="src"
-		><a name="v:C1" class="def"
-		  >C1</a
-		  ></td
-		><td class="doc"
-		><p
-		  >This is the <code
-		    ><a href=""
-		      >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
-		    ><dl
-		    ><dt class="src"
-		      ><a name="v:p" class="def"
-			>p</a
-			> :: <a href=""
-			>Int</a
-			></dt
-		      ><dd class="doc"
-		      ><p
-			>This comment applies to the <code
-			  ><a href=""
-			    >p</a
-			    ></code
-			  > field</p
-			></dd
-		      ><dt class="src"
-		      ><a name="v:q" class="def"
-			>q</a
-			> :: <span class="keyword"
-			>forall</span
-			> a. a -&gt; a</dt
-		      ><dd class="doc"
-		      ><p
-			>This comment applies to the <code
-			  ><a href=""
-			    >q</a
-			    ></code
-			  > field</p
-			></dd
-		      ><dt class="src"
-		      ><a name="v:r" class="def"
-			>r</a
-			>, <a name="v:s" class="def"
-			>s</a
-			> :: <a href=""
-			>Int</a
-			></dt
-		      ><dd class="doc"
-		      ><p
-			>This comment applies to both <code
-			  ><a href=""
-			    >r</a
-			    ></code
-			  > and <code
-			  ><a href=""
-			    >s</a
-			    ></code
-			  ></p
-			></dd
-		      ></dl
-		    ><div class="clear"
-		    ></div
-		    ></div
-		  ></td
-		></tr
-	      ><tr
-	      ><td class="src"
-		><a name="v:C2" class="def"
-		  >C2</a
-		  ></td
-		><td class="doc"
-		><p
-		  >This is the <code
-		    ><a href=""
-		      >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
-		    ><dl
-		    ><dt class="src"
-		      ><a name="v:t" class="def"
-			>t</a
-			> :: T1 -&gt; <a href=""
-			>T2</a
-			> <a href=""
-			>Int</a
-			> <a href=""
-			>Int</a
-			> -&gt; <a href=""
-			>T3</a
-			> <a href=""
-			>Bool</a
-			> <a href=""
-			>Bool</a
-			> -&gt; <a href=""
-			>T4</a
-			> <a href=""
-			>Float</a
-			> <a href=""
-			>Float</a
-			> -&gt; <a href=""
-			>T5</a
-			> () ()</dt
-		      ><dd class="doc empty"
-		      >&nbsp;</dd
-		      ><dt class="src"
-		      ><a name="v:u" class="def"
-			>u</a
-			>, <a name="v:v" class="def"
-			>v</a
-			> :: <a href=""
-			>Int</a
-			></dt
-		      ><dd class="doc empty"
-		      >&nbsp;</dd
-		      ></dl
-		    ><div class="clear"
-		    ></div
-		    ></div
-		  ></td
-		></tr
-	      ></table
-	    ></div
-	  ></div
-	><div class="top"
-	><p class="src"
-	  ><span class="keyword"
-	    >data</span
-	    > <a name="t:R1" class="def"
-	    >R1</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 name="v:C3" class="def"
-		  >C3</a
-		  ></td
-		><td class="doc"
-		><p
-		  >This is the <code
-		    ><a href=""
-		      >C3</a
-		      ></code
-		    > record constructor</p
-		  ></td
-		></tr
-	      ><tr
-	      ><td colspan="2"
-		><div class="subs fields"
-		  ><p class="caption"
-		    >Fields</p
-		    ><dl
-		    ><dt class="src"
-		      ><a name="v:s1" class="def"
-			>s1</a
-			> :: <a href=""
-			>Int</a
-			></dt
-		      ><dd class="doc"
-		      ><p
-			>The <code
-			  ><a href=""
-			    >s1</a
-			    ></code
-			  > record selector</p
-			></dd
-		      ><dt class="src"
-		      ><a name="v:s2" class="def"
-			>s2</a
-			> :: <a href=""
-			>Int</a
-			></dt
-		      ><dd class="doc"
-		      ><p
-			>The <code
-			  ><a href=""
-			    >s2</a
-			    ></code
-			  > record selector</p
-			></dd
-		      ><dt class="src"
-		      ><a name="v:s3" class="def"
-			>s3</a
-			> :: <a href=""
-			>Int</a
-			></dt
-		      ><dd class="doc"
-		      ><p
-			>The <code
-			  ><a href=""
-			    >s3</a
-			    ></code
-			  > record selector</p
-			></dd
-		      ></dl
-		    ><div class="clear"
-		    ></div
-		    ></div
-		  ></td
-		></tr
-	      ></table
-	    ></div
-	  ></div
-	><div class="doc"
-	><p
-	  >test that we can export record selectors on their own:</p
-	  ></div
-	><h1 id="g:4"
-	>Class declarations</h1
-	><div class="top"
-	><p class="src"
-	  ><span class="keyword"
-	    >class</span
-	    > <a href=""
-	    >D</a
-	    > a =&gt; <a name="t:C" class="def"
-	    >C</a
-	    > a <span class="keyword"
-	    >where</span
-	    ></p
-	  ><div class="doc"
-	  ><p
-	    >This comment applies to the <em
-	      >previous</em
-	      > declaration (the <code
-	      ><a href=""
-		>C</a
-		></code
-	      > class)</p
-	    ></div
-	  ><div class="subs methods"
-	  ><p class="caption"
-	    >Methods</p
-	    ><p class="src"
-	    ><a name="v:a" class="def"
-	      >a</a
-	      > :: <a href=""
-	      >IO</a
-	      > a</p
-	    ><div class="doc"
-	    ><p
-	      >this is a description of the <code
-		><a href=""
-		  >a</a
-		  ></code
-		> method</p
-	      ></div
-	    ><p class="src"
-	    ><a name="v:b" class="def"
-	      >b</a
-	      > :: [a]</p
-	    ><div class="doc"
-	    ><p
-	      >this is a description of the <code
-		><a href=""
-		  >b</a
-		  ></code
-		> method</p
-	      ></div
-	    ></div
-	  ></div
-	><div class="top"
-	><p class="src"
-	  ><span class="keyword"
-	    >class</span
-	    > <a name="t:D" class="def"
-	    >D</a
-	    > a <span class="keyword"
-	    >where</span
-	    ></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 name="v:d" class="def"
-	      >d</a
-	      > :: <a href=""
-	      >T</a
-	      > a b</p
-	    ><p class="src"
-	    ><a name="v:e" class="def"
-	      >e</a
-	      > :: (a, a)</p
-	    ></div
-	  ><div class="subs instances"
-	  ><p id="control.i:D" class="caption collapser" onclick="toggleSection('i:D')"
-	    >Instances</p
-	    ><div id="section.i:D" class="show"
-	    ><table
-	      ><tr
-		><td class="src clearfix"
-		  ><span class="inst-left"
-		    ><a href=""
-		      >D</a
-		      > <a href=""
-		      >Float</a
-		      ></span
-		    ></td
-		  ><td class="doc empty"
-		  >&nbsp;</td
-		  ></tr
-		><tr
-		><td class="src clearfix"
-		  ><span class="inst-left"
-		    ><a href=""
-		      >D</a
-		      > <a href=""
-		      >Int</a
-		      ></span
-		    ></td
-		  ><td class="doc empty"
-		  >&nbsp;</td
-		  ></tr
-		></table
-	      ></div
-	    ></div
-	  ></div
-	><div class="top"
-	><p class="src"
-	  ><span class="keyword"
-	    >class</span
-	    > <a name="t:E" class="def"
-	    >E</a
-	    > 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 name="t:F" class="def"
-	    >F</a
-	    > a <span class="keyword"
-	    >where</span
-	    ></p
-	  ><div class="subs methods"
-	  ><p class="caption"
-	    >Methods</p
-	    ><p class="src"
-	    ><a name="v:ff" class="def"
-	      >ff</a
-	      > :: a</p
-	    ></div
-	  ></div
-	><div class="doc"
-	><p
-	  >Test that we can export a class method on its own:</p
-	  ></div
-	><h1 id="g:5"
-	>Function types</h1
-	><div class="top"
-	><p class="src"
-	  ><a name="v:f" class="def"
-	    >f</a
-	    > :: <a href=""
-	    >C</a
-	    > a =&gt; a -&gt; <a href=""
-	    >Int</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=""
-		>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
-	      >This is an ordered list</li
-	      ><li
-	      >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=""
-		>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 name="v:g" class="def"
-	    >g</a
-	    > :: <a href=""
-	    >Int</a
-	    > -&gt; <a href=""
-	    >IO</a
-	    > CInt</p
-	  ><div class="doc"
-	  ><p
-	    >we can export foreign declarations too</p
-	    ></div
-	  ></div
-	><h1 id="g:6"
-	>Auxiliary stuff</h1
-	><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
-	><h1 id="g:7"
-	>A hidden module</h1
-	><div class="top"
-	><p class="src"
-	  ><a name="v:hidden" class="def"
-	    >hidden</a
-	    > :: <a href=""
-	    >Int</a
-	    > -&gt; <a href=""
-	    >Int</a
-	    ></p
-	  ></div
-	><h1 id="g:8"
-	>A visible module</h1
-	><div class="top"
-	><p class="src"
-	  >module <a href=""
-	    >Visible</a
-	    ></p
-	  ></div
-	><div class="doc"
-	><p
-	  >nested-style doc comments </p
-	  ></div
-	><h1 id="g:9"
-	>Existential / Universal types</h1
-	><div class="top"
-	><p class="src"
-	  ><span class="keyword"
-	    >data</span
-	    > <a name="t:Ex" class="def"
-	    >Ex</a
-	    > 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=""
-		  >C</a
-		  > b =&gt; <a name="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 name="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=""
-		  >C</a
-		  > a =&gt; <a name="v:Ex3" class="def"
-		  >Ex3</a
-		  > b</td
-		><td class="doc empty"
-		>&nbsp;</td
-		></tr
-	      ><tr
-	      ><td class="src"
-		><a name="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
-	><h1 id="g:10"
-	>Type signatures with argument docs</h1
-	><div class="top"
-	><p class="src"
-	  ><a name="v:k" class="def"
-	    >k</a
-	    ></p
-	  ><div class="subs arguments"
-	  ><p class="caption"
-	    >Arguments</p
-	    ><table
-	    ><tr
-	      ><td class="src"
-		>:: <a href=""
-		  >T</a
-		  > () ()</td
-		><td class="doc"
-		><p
-		  >This argument has type <code
-		    ><a href=""
-		      >T</a
-		      ></code
-		    ></p
-		  ></td
-		></tr
-	      ><tr
-	      ><td class="src"
-		>-&gt; <a href=""
-		  >T2</a
-		  > <a href=""
-		  >Int</a
-		  > <a href=""
-		  >Int</a
-		  ></td
-		><td class="doc"
-		><p
-		  >This argument has type 'T2 Int Int'</p
-		  ></td
-		></tr
-	      ><tr
-	      ><td class="src"
-		>-&gt; (<a href=""
-		  >T3</a
-		  > <a href=""
-		  >Bool</a
-		  > <a href=""
-		  >Bool</a
-		  > -&gt; <a href=""
-		  >T4</a
-		  > <a href=""
-		  >Float</a
-		  > <a href=""
-		  >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=""
-		  >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=""
-		  >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 name="v:l" class="def"
-	    >l</a
-	    ></p
-	  ><div class="subs arguments"
-	  ><p class="caption"
-	    >Arguments</p
-	    ><table
-	    ><tr
-	      ><td class="src"
-		>:: (<a href=""
-		  >Int</a
-		  >, <a href=""
-		  >Int</a
-		  >, <a href=""
-		  >Float</a
-		  >)</td
-		><td class="doc"
-		><p
-		  >takes a triple</p
-		  ></td
-		></tr
-	      ><tr
-	      ><td class="src"
-		>-&gt; <a href=""
-		  >Int</a
-		  ></td
-		><td class="doc"
-		><p
-		  >returns an <code
-		    ><a href=""
-		      >Int</a
-		      ></code
-		    ></p
-		  ></td
-		></tr
-	      ></table
-	    ></div
-	  ></div
-	><div class="top"
-	><p class="src"
-	  ><a name="v:m" class="def"
-	    >m</a
-	    ></p
-	  ><div class="subs arguments"
-	  ><p class="caption"
-	    >Arguments</p
-	    ><table
-	    ><tr
-	      ><td class="src"
-		>:: <a href=""
-		  >R</a
-		  ></td
-		><td class="doc empty"
-		>&nbsp;</td
-		></tr
-	      ><tr
-	      ><td class="src"
-		>-&gt; <a href=""
-		  >N1</a
-		  > ()</td
-		><td class="doc"
-		><p
-		  >one of the arguments</p
-		  ></td
-		></tr
-	      ><tr
-	      ><td class="src"
-		>-&gt; <a href=""
-		  >IO</a
-		  > <a href=""
-		  >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 name="v:o" class="def"
-	    >o</a
-	    ></p
-	  ><div class="subs arguments"
-	  ><p class="caption"
-	    >Arguments</p
-	    ><table
-	    ><tr
-	      ><td class="src"
-		>:: <a href=""
-		  >Float</a
-		  ></td
-		><td class="doc"
-		><p
-		  >The input float</p
-		  ></td
-		></tr
-	      ><tr
-	      ><td class="src"
-		>-&gt; <a href=""
-		  >IO</a
-		  > <a href=""
-		  >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
-	><h1 id="g:11"
-	>A section</h1
-	><h2 id="g:12"
-	>A subsection</h2
-	><div class="doc"
-	><pre
-	  >a literal line</pre
-	  ><p
-	  >$ a non <em
-	    >literal</em
-	    > line $</p
-	  ></div
-	><div class="top"
-	><p class="src"
-	  ><a name="v:f-39-" class="def"
-	    >f'</a
-	    > :: <a href=""
-	    >Int</a
-	    ></p
-	  ><div class="doc"
-	  ><p
-	    >a function with a prime can be referred to as <code
-	      ><a href=""
-		>f'</a
-		></code
-	      >
- but f' doesn't get link'd 'f\''</p
-	    ></div
-	  ></div
-	><div class="top"
-	><p class="src"
-	  ><a name="v:withType" class="def"
-	    >withType</a
-	    > :: <a href=""
-	    >Int</a
-	    ></p
-	  ><div class="doc"
-	  ><p
-	    >Comment on a definition with type signature</p
-	    ></div
-	  ></div
-	><div class="top"
-	><p class="src"
-	  ><a name="v:withoutType" class="def"
-	    >withoutType</a
-	    > :: t</p
-	  ><div class="doc"
-	  ><p
-	    >Comment on a definition without type signature</p
-	    ></div
-	  ></div
-	></div
-      ></div
-    ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.16.1</p
-      ></div
+<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="#" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_Test.html&quot;);};
+//
+</script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ><p class="caption empty"
+      ></p
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >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</td
+	    ></tr
+	  ></table
+	><p class="caption"
+	>Test</p
+	></div
+      ><div id="table-of-contents"
+      ><p class="caption"
+	>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 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="#"
+	      >T</a
+	      ></code
+	    >, <code
+	    ><a href="#"
+	      >f</a
+	      ></code
+	    >, <code
+	    ><a href="#"
+	      >g</a
+	      ></code
+	    >, <code
+	    ><a href="#"
+	      >visible</a
+	      ></code
+	    >.</p
+	  ></div
+	></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"
+	  ><span class="keyword"
+	    >data</span
+	    > <a href="#"
+	    >T</a
+	    > a b<ul class="subs"
+	    ><li
+	      >= <a href="#"
+		>A</a
+		> <a href="#"
+		>Int</a
+		> (<a href="#"
+		>Maybe</a
+		> <a href="#"
+		>Float</a
+		>)</li
+	      ><li
+	      >| <a href="#"
+		>B</a
+		> (<a href="#"
+		>T</a
+		> a b, <a href="#"
+		>T</a
+		> <a href="#"
+		>Int</a
+		> <a href="#"
+		>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="#"
+		    >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="#"
+		    >Int</a
+		    ></li
+		  ></ul
+		> }</li
+	      ><li
+	      >| <a href="#"
+		>C2</a
+		> { <ul class="subs"
+		><li
+		  ><a href="#"
+		    >t</a
+		    > :: T1 -&gt; <a href="#"
+		    >T2</a
+		    > <a href="#"
+		    >Int</a
+		    > <a href="#"
+		    >Int</a
+		    > -&gt; <a href="#"
+		    >T3</a
+		    > <a href="#"
+		    >Bool</a
+		    > <a href="#"
+		    >Bool</a
+		    > -&gt; <a href="#"
+		    >T4</a
+		    > <a href="#"
+		    >Float</a
+		    > <a href="#"
+		    >Float</a
+		    > -&gt; <a href="#"
+		    >T5</a
+		    > () ()</li
+		  ><li
+		  ><a href="#"
+		    >u</a
+		    >, <a href="#"
+		    >v</a
+		    > :: <a href="#"
+		    >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="#"
+		>Int</a
+		></li
+	      ><li
+	      ><a href="#"
+		>s2</a
+		> :: <a href="#"
+		>Int</a
+		></li
+	      ><li
+	      ><a href="#"
+		>s3</a
+		> :: <a href="#"
+		>Int</a
+		></li
+	      ></ul
+	    >}</li
+	  ><li class="src short"
+	  ><span class="keyword"
+	    >class</span
+	    > <a href="#"
+	    >D</a
+	    > a =&gt; <a href="#"
+	    >C</a
+	    > a <span class="keyword"
+	    >where</span
+	    ><ul class="subs"
+	    ></ul
+	    ></li
+	  ><li class="src short"
+	  ><span class="keyword"
+	    >class</span
+	    > <a href="#"
+	    >D</a
+	    > a <span class="keyword"
+	    >where</span
+	    ><ul class="subs"
+	    ></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"
+	    ></ul
+	    ></li
+	  ><li class="src short"
+	  ><a href="#"
+	    >a</a
+	    > :: <a href="#"
+	    >C</a
+	    > a =&gt; <a href="#"
+	    >IO</a
+	    > a</li
+	  ><li class="src short"
+	  ><a href="#"
+	    >f</a
+	    > :: <a href="#"
+	    >C</a
+	    > a =&gt; a -&gt; <a href="#"
+	    >Int</a
+	    ></li
+	  ><li class="src short"
+	  ><a href="#"
+	    >g</a
+	    > :: <a href="#"
+	    >Int</a
+	    > -&gt; <a href="#"
+	    >IO</a
+	    > CInt</li
+	  ><li class="src short"
+	  ><a href="#"
+	    >hidden</a
+	    > :: <a href="#"
+	    >Int</a
+	    > -&gt; <a href="#"
+	    >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
+	      >= <a href="#"
+		>C</a
+		> b =&gt; <a href="#"
+		>Ex1</a
+		> b</li
+	      ><li
+	      >| <a href="#"
+		>Ex2</a
+		> b</li
+	      ><li
+	      >| <a href="#"
+		>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="#"
+	    >T</a
+	    > () () -&gt; <a href="#"
+	    >T2</a
+	    > <a href="#"
+	    >Int</a
+	    > <a href="#"
+	    >Int</a
+	    > -&gt; (<a href="#"
+	    >T3</a
+	    > <a href="#"
+	    >Bool</a
+	    > <a href="#"
+	    >Bool</a
+	    > -&gt; <a href="#"
+	    >T4</a
+	    > <a href="#"
+	    >Float</a
+	    > <a href="#"
+	    >Float</a
+	    >) -&gt; <a href="#"
+	    >T5</a
+	    > () () -&gt; <a href="#"
+	    >IO</a
+	    > ()</li
+	  ><li class="src short"
+	  ><a href="#"
+	    >l</a
+	    > :: (<a href="#"
+	    >Int</a
+	    >, <a href="#"
+	    >Int</a
+	    >, <a href="#"
+	    >Float</a
+	    >) -&gt; <a href="#"
+	    >Int</a
+	    ></li
+	  ><li class="src short"
+	  ><a href="#"
+	    >m</a
+	    > :: <a href="#"
+	    >R</a
+	    > -&gt; <a href="#"
+	    >N1</a
+	    > () -&gt; <a href="#"
+	    >IO</a
+	    > <a href="#"
+	    >Int</a
+	    ></li
+	  ><li class="src short"
+	  ><a href="#"
+	    >o</a
+	    > :: <a href="#"
+	    >Float</a
+	    > -&gt; <a href="#"
+	    >IO</a
+	    > <a href="#"
+	    >Float</a
+	    ></li
+	  ><li class="src short"
+	  ><a href="#"
+	    >f'</a
+	    > :: <a href="#"
+	    >Int</a
+	    ></li
+	  ><li class="src short"
+	  ><a href="#"
+	    >withType</a
+	    > :: <a href="#"
+	    >Int</a
+	    ></li
+	  ><li class="src short"
+	  ><a href="#"
+	    >withoutType</a
+	    > :: a</li
+	  ></ul
+	></div
+      ><div id="interface"
+      ><h1 id="g:1"
+	>Type declarations</h1
+	><h2 id="g:2"
+	>Data types</h2
+	><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="#"
+		  >Int</a
+		  > (<a href="#"
+		  >Maybe</a
+		  > <a href="#"
+		  >Float</a
+		  >)</td
+		><td class="doc"
+		><p
+		  >This comment describes the <code
+		    ><a href="#"
+		      >A</a
+		      ></code
+		    > constructor</p
+		  ></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		><a id="v:B" class="def"
+		  >B</a
+		  > (<a href="#"
+		  >T</a
+		  > a b, <a href="#"
+		  >T</a
+		  > <a href="#"
+		  >Int</a
+		  > <a href="#"
+		  >Float</a
+		  >)</td
+		><td class="doc"
+		><p
+		  >This comment describes the <code
+		    ><a href="#"
+		      >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"
+		></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		><a id="v:B1" class="def"
+		  >B1</a
+		  > b</td
+		><td class="doc empty"
+		></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"
+		></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		><a id="v:B2" class="def"
+		  >B2</a
+		  > b</td
+		><td class="doc empty"
+		></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="#"
+		      >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="#"
+		      >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="#"
+		      >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="#"
+		      >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="#"
+		      >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"
+		></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"
+		></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"
+			></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"
+		></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="#"
+			      >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"
+		></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"
+			></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="#"
+		      >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"
+			></div
+			></li
+		      ></ul
+		    ></div
+		  ></td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><h2 id="g:3"
+	>Records</h2
+	><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="#"
+		>R</a
+		></code
+	      > record, which has four fields,
+ <code
+	      ><a href="#"
+		>p</a
+		></code
+	      >, <code
+	      ><a href="#"
+		>q</a
+		></code
+	      >, <code
+	      ><a href="#"
+		>r</a
+		></code
+	      >, and <code
+	      ><a href="#"
+		>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="#"
+		      >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="#"
+			  >Int</a
+			  ></dfn
+			><div class="doc"
+			><p
+			  >This comment applies to the <code
+			    ><a href="#"
+			      >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="#"
+			      >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="#"
+			  >Int</a
+			  ></dfn
+			><div class="doc"
+			><p
+			  >This comment applies to both <code
+			    ><a href="#"
+			      >r</a
+			      ></code
+			    > and <code
+			    ><a href="#"
+			      >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="#"
+		      >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="#"
+			  >T2</a
+			  > <a href="#"
+			  >Int</a
+			  > <a href="#"
+			  >Int</a
+			  > -&gt; <a href="#"
+			  >T3</a
+			  > <a href="#"
+			  >Bool</a
+			  > <a href="#"
+			  >Bool</a
+			  > -&gt; <a href="#"
+			  >T4</a
+			  > <a href="#"
+			  >Float</a
+			  > <a href="#"
+			  >Float</a
+			  > -&gt; <a href="#"
+			  >T5</a
+			  > () ()</dfn
+			><div class="doc empty"
+			></div
+			></li
+		      ><li
+		      ><dfn class="src"
+			><a id="v:u" class="def"
+			  >u</a
+			  >, <a id="v:v" class="def"
+			  >v</a
+			  > :: <a href="#"
+			  >Int</a
+			  ></dfn
+			><div class="doc empty"
+			></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="#"
+		      >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="#"
+			  >Int</a
+			  ></dfn
+			><div class="doc"
+			><p
+			  >The <code
+			    ><a href="#"
+			      >s1</a
+			      ></code
+			    > record selector</p
+			  ></div
+			></li
+		      ><li
+		      ><dfn class="src"
+			><a id="v:s2" class="def"
+			  >s2</a
+			  > :: <a href="#"
+			  >Int</a
+			  ></dfn
+			><div class="doc"
+			><p
+			  >The <code
+			    ><a href="#"
+			      >s2</a
+			      ></code
+			    > record selector</p
+			  ></div
+			></li
+		      ><li
+		      ><dfn class="src"
+			><a id="v:s3" class="def"
+			  >s3</a
+			  > :: <a href="#"
+			  >Int</a
+			  ></dfn
+			><div class="doc"
+			><p
+			  >The <code
+			    ><a href="#"
+			      >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
+	><h1 id="g:4"
+	>Class declarations</h1
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >class</span
+	    > <a href="#"
+	    >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="#"
+		>C</a
+		></code
+	      > class)</p
+	    ></div
+	  ><div class="subs minimal"
+	  ><p class="caption"
+	    >Minimal complete definition</p
+	    ><p class="src"
+	    ><a href="#"
+	      >a</a
+	      >, <a href="#"
+	      >b</a
+	      ></p
+	    ></div
+	  ><div class="subs methods"
+	  ><p class="caption"
+	    >Methods</p
+	    ><p class="src"
+	    ><a id="v:a" class="def"
+	      >a</a
+	      > :: <a href="#"
+	      >IO</a
+	      > a <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ><div class="doc"
+	    ><p
+	      >this is a description of the <code
+		><a href="#"
+		  >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="#"
+		  >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 minimal"
+	  ><p class="caption"
+	    >Minimal complete definition</p
+	    ><p class="src"
+	    ><a href="#"
+	      >d</a
+	      >, <a href="#"
+	      >e</a
+	      ></p
+	    ></div
+	  ><div class="subs methods"
+	  ><p class="caption"
+	    >Methods</p
+	    ><p class="src"
+	    ><a id="v:d" class="def"
+	      >d</a
+	      > :: <a href="#"
+	      >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"
+	  ><p id="control.i:D" class="caption collapser" onclick="toggleSection('i:D')"
+	    >Instances</p
+	    ><div id="section.i:D" class="show"
+	    ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:ic:D:D:1" class="instance expander" onclick="toggleSection('i:ic:D:D:1')"
+		      ></span
+		      > <a href="#"
+		      >D</a
+		      > <a href="#"
+		      >Float</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:ic:D:D:1" class="inst-details hide"
+		    ><div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >d</a
+			  > :: <a href="#"
+			  >T</a
+			  > <a href="#"
+			  >Float</a
+			  > b <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >e</a
+			  > :: (<a href="#"
+			  >Float</a
+			  >, <a href="#"
+			  >Float</a
+			  >) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></div
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:ic:D:D:2" class="instance expander" onclick="toggleSection('i:ic:D:D:2')"
+		      ></span
+		      > <a href="#"
+		      >D</a
+		      > <a href="#"
+		      >Int</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:ic:D:D:2" class="inst-details hide"
+		    ><div class="subs methods"
+		      ><p class="caption"
+			>Methods</p
+			><p class="src"
+			><a href="#"
+			  >d</a
+			  > :: <a href="#"
+			  >T</a
+			  > <a href="#"
+			  >Int</a
+			  > b <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><a href="#"
+			  >e</a
+			  > :: (<a href="#"
+			  >Int</a
+			  >, <a href="#"
+			  >Int</a
+			  >) <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></div
+		    ></td
+		  ></tr
+		></table
+	      ></div
+	    ></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 minimal"
+	  ><p class="caption"
+	    >Minimal complete definition</p
+	    ><p class="src"
+	    ><a href="#"
+	      >ff</a
+	      ></p
+	    ></div
+	  ><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="#"
+	    >C</a
+	    > a =&gt; <a href="#"
+	    >IO</a
+	    > a <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >this is a description of the <code
+	      ><a href="#"
+		>a</a
+		></code
+	      > method</p
+	    ></div
+	  ></div
+	><h1 id="g:5"
+	>Function types</h1
+	><div class="top"
+	><p class="src"
+	  ><a id="v:f" class="def"
+	    >f</a
+	    > :: <a href="#"
+	    >C</a
+	    > a =&gt; a -&gt; <a href="#"
+	    >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="#"
+		>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
+	      >This is an ordered list</li
+	      ><li
+	      >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="#"
+		>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="#"
+	    >Int</a
+	    > -&gt; <a href="#"
+	    >IO</a
+	    > CInt <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >we can export foreign declarations too</p
+	    ></div
+	  ></div
+	><h1 id="g:6"
+	>Auxiliary stuff</h1
+	><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
+	><h1 id="g:7"
+	>A hidden module</h1
+	><div class="top"
+	><p class="src"
+	  ><a id="v:hidden" class="def"
+	    >hidden</a
+	    > :: <a href="#"
+	    >Int</a
+	    > -&gt; <a href="#"
+	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ></div
+	><h1 id="g:8"
+	>A visible module</h1
+	><div class="top"
+	><p class="src"
+	  >module <a href="#"
+	    >Visible</a
+	    ></p
+	  ></div
+	><div class="doc"
+	><p
+	  >nested-style doc comments </p
+	  ></div
+	><h1 id="g:9"
+	>Existential / Universal types</h1
+	><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"
+		><a href="#"
+		  >C</a
+		  > b =&gt; <a id="v:Ex1" class="def"
+		  >Ex1</a
+		  > b</td
+		><td class="doc empty"
+		></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		><a id="v:Ex2" class="def"
+		  >Ex2</a
+		  > b</td
+		><td class="doc empty"
+		></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		><a href="#"
+		  >C</a
+		  > a =&gt; <a id="v:Ex3" class="def"
+		  >Ex3</a
+		  > b</td
+		><td class="doc empty"
+		></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"
+		></td
+		></tr
+	      ></table
+	    ></div
+	  ></div
+	><h1 id="g:10"
+	>Type signatures with argument docs</h1
+	><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="#"
+		  >T</a
+		  > () ()</td
+		><td class="doc"
+		><p
+		  >This argument has type <code
+		    ><a href="#"
+		      >T</a
+		      ></code
+		    ></p
+		  ></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		>-&gt; <a href="#"
+		  >T2</a
+		  > <a href="#"
+		  >Int</a
+		  > <a href="#"
+		  >Int</a
+		  ></td
+		><td class="doc"
+		><p
+		  >This argument has type 'T2 Int Int'</p
+		  ></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		>-&gt; (<a href="#"
+		  >T3</a
+		  > <a href="#"
+		  >Bool</a
+		  > <a href="#"
+		  >Bool</a
+		  > -&gt; <a href="#"
+		  >T4</a
+		  > <a href="#"
+		  >Float</a
+		  > <a href="#"
+		  >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="#"
+		  >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="#"
+		  >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="#"
+		  >Int</a
+		  >, <a href="#"
+		  >Int</a
+		  >, <a href="#"
+		  >Float</a
+		  >)</td
+		><td class="doc"
+		><p
+		  >takes a triple</p
+		  ></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		>-&gt; <a href="#"
+		  >Int</a
+		  ></td
+		><td class="doc"
+		><p
+		  >returns an <code
+		    ><a href="#"
+		      >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="#"
+		  >R</a
+		  ></td
+		><td class="doc empty"
+		></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		>-&gt; <a href="#"
+		  >N1</a
+		  > ()</td
+		><td class="doc"
+		><p
+		  >one of the arguments</p
+		  ></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		>-&gt; <a href="#"
+		  >IO</a
+		  > <a href="#"
+		  >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="#"
+		  >Float</a
+		  ></td
+		><td class="doc"
+		><p
+		  >The input float</p
+		  ></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		>-&gt; <a href="#"
+		  >IO</a
+		  > <a href="#"
+		  >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
+	><h1 id="g:11"
+	>A section</h1
+	><h2 id="g:12"
+	>A subsection</h2
+	><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="#"
+	    >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="#"
+		>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="#"
+	    >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
+    ><div id="footer"
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/Threaded.html b/html-test/ref/Threaded.html
--- a/html-test/ref/Threaded.html
+++ b/html-test/ref/Threaded.html
@@ -1,32 +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
     >Threaded</title
-    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_Threaded.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_Threaded.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href="index.html"
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href="doc-index.html"
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -56,9 +57,9 @@
 	>Synopsis</p
 	><ul id="section.syn" class="hide" onclick="toggleSection('syn')"
 	><li class="src short"
-	  ><a href="#v:f"
+	  ><a href="#"
 	    >f</a
-	    > :: <a href=" ${pkgroot}/../../share/doc/ghc/html/libraries/base-4.8.0.0/Prelude.html#t:Integer"
+	    > :: <a href="#"
 	    >Integer</a
 	    ></li
 	  ></ul
@@ -68,10 +69,12 @@
 	>Documentation</h1
 	><div class="top"
 	><p class="src"
-	  ><a name="v:f" class="def"
+	  ><a id="v:f" class="def"
 	    >f</a
-	    > :: <a href=" ${pkgroot}/../../share/doc/ghc/html/libraries/base-4.8.0.0/Prelude.html#t:Integer"
+	    > :: <a href="#"
 	    >Integer</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="doc"
 	  ><p
@@ -84,11 +87,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href="http://www.haskell.org/haddock/"
-	>Haddock</a
-	> version 2.16.0</p
-      ></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,90 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+><head
+  ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
+     /><title
+    >Threaded_TH</title
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_Threaded_TH.html&quot;);};
+//
+</script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ><p class="caption empty"
+      ></p
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >None</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"
+      ><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="#"
+	    >forkTH</a
+	    > :: Q Exp</li
+	  ></ul
+	></div
+      ><div id="interface"
+      ><h1
+	>Documentation</h1
+	><div class="top"
+	><p class="src"
+	  ><a id="v:forkTH" class="def"
+	    >forkTH</a
+	    > :: Q Exp <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
+    ><div id="footer"
+    ></div
+    ></body
+  ></html
+>
diff --git a/html-test/ref/Ticket112.html b/html-test/ref/Ticket112.html
--- a/html-test/ref/Ticket112.html
+++ b/html-test/ref/Ticket112.html
@@ -1,32 +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"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_Ticket112.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_Ticket112.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -46,7 +47,7 @@
 	>Synopsis</p
 	><ul id="section.syn" class="hide" onclick="toggleSection('syn')"
 	><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >f</a
 	    > :: a</li
 	  ></ul
@@ -56,13 +57,15 @@
 	>Documentation</h1
 	><div class="top"
 	><p class="src"
-	  ><a name="v:f" class="def"
+	  ><a id="v:f" class="def"
 	    >f</a
-	    > :: a</p
+	    > :: a <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ><div class="doc"
 	  ><p
 	    >...given a raw <code
-	      ><a href=""
+	      ><a href="#"
 		>Addr#</a
 		></code
 	      > to the string, and the length of the string.</p
@@ -71,11 +74,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.15.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/Ticket61.html b/html-test/ref/Ticket61.html
--- a/html-test/ref/Ticket61.html
+++ b/html-test/ref/Ticket61.html
@@ -1,32 +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
     >Ticket61</title
-    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_Ticket61.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_Ticket61.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -48,18 +49,30 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >class</span
-	    > <a name="t:C" class="def"
+	    > <a id="t:C" class="def"
 	    >C</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="#"
+	      >f</a
+	      ></p
+	    ></div
 	  ><div class="subs methods"
 	  ><p class="caption"
 	    >Methods</p
 	    ><p class="src"
-	    ><a name="v:f" class="def"
+	    ><a id="v:f" class="def"
 	      >f</a
-	      > :: a</p
+	      > :: a <a href="#" class="selflink"
+	      >#</a
+	      ></p
 	    ><div class="doc"
 	    ><p
 	      >A comment about f</p
@@ -69,11 +82,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.15.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/Ticket75.html b/html-test/ref/Ticket75.html
--- a/html-test/ref/Ticket75.html
+++ b/html-test/ref/Ticket75.html
@@ -1,32 +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
     >Ticket75</title
-    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_Ticket75.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_Ticket75.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -48,15 +49,15 @@
 	><li class="src short"
 	  ><span class="keyword"
 	    >data</span
-	    > a <a href=""
+	    > a <a href="#"
 	    >:-</a
-	    > b = <a href=""
+	    > b = <a href="#"
 	    >Q</a
 	    ></li
 	  ><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >f</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
 	    ></li
 	  ></ul
@@ -68,35 +69,39 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >data</span
-	    > a <a name="t::-45-" class="def"
+	    > a <a id="t::-45-" class="def"
 	    >:-</a
-	    > b</p
+	    > b <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ><div class="subs constructors"
 	  ><p class="caption"
 	    >Constructors</p
 	    ><table
 	    ><tr
 	      ><td class="src"
-		><a name="v:Q" class="def"
+		><a id="v:Q" class="def"
 		  >Q</a
 		  ></td
 		><td class="doc empty"
-		>&nbsp;</td
+		></td
 		></tr
 	      ></table
 	    ></div
 	  ></div
 	><div class="top"
 	><p class="src"
-	  ><a name="v:f" class="def"
+	  ><a id="v:f" class="def"
 	    >f</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="doc"
 	  ><p
 	    >A reference to <code
-	      ><a href=""
+	      ><a href="#"
 		>:-</a
 		></code
 	      ></p
@@ -105,11 +110,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.15.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/TitledPicture.html b/html-test/ref/TitledPicture.html
--- a/html-test/ref/TitledPicture.html
+++ b/html-test/ref/TitledPicture.html
@@ -1,32 +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
     >TitledPicture</title
-    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_TitledPicture.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_TitledPicture.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -46,15 +47,15 @@
 	>Synopsis</p
 	><ul id="section.syn" class="hide" onclick="toggleSection('syn')"
 	><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >foo</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Integer</a
 	    ></li
 	  ><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >bar</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Integer</a
 	    ></li
 	  ></ul
@@ -64,15 +65,17 @@
 	>Documentation</h1
 	><div class="top"
 	><p class="src"
-	  ><a name="v:foo" class="def"
+	  ><a id="v:foo" class="def"
 	    >foo</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Integer</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="doc"
 	  ><p
 	    >Picture for <code
-	      ><a href=""
+	      ><a href="#"
 		>foo</a
 		></code
 	      > without a title <img src="bar"
@@ -81,15 +84,17 @@
 	  ></div
 	><div class="top"
 	><p class="src"
-	  ><a name="v:bar" class="def"
+	  ><a id="v:bar" class="def"
 	    >bar</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Integer</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="doc"
 	  ><p
 	    >Picture for <code
-	      ><a href=""
+	      ><a href="#"
 		>bar</a
 		></code
 	      > with title <img src="un&#8739;&#8705;&#8728;" title="&#948;&#8712;"
@@ -99,11 +104,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.15.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/TypeFamilies.html b/html-test/ref/TypeFamilies.html
--- a/html-test/ref/TypeFamilies.html
+++ b/html-test/ref/TypeFamilies.html
@@ -1,1117 +1,1828 @@
-<!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 type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_TypeFamilies.html");};
-//]]>
-</script
-    ></head
-  ><body
-  ><div id="package-header"
-    ><ul class="links" id="page-menu"
-      ><li
-	><a href=""
-	  >Contents</a
-	  ></li
-	><li
-	><a href=""
-	  >Index</a
-	  ></li
-	></ul
-      ><p class="caption empty"
-      >&nbsp;</p
-      ></div
-    ><div id="content"
-    ><div id="module-header"
-      ><table class="info"
-	><tr
-	  ><th
-	    >Safe Haskell</th
-	    ><td
-	    >Safe</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"
-      ><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"
-	  ><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 :: *</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</li
-	  ><li class="src short"
-	  ><span class="keyword"
-	    >type family</span
-	    > a <a href=""
-	    >&lt;&gt;</a
-	    > b :: k</li
-	  ><li class="src short"
-	  ><span class="keyword"
-	    >class</span
-	    > a <a href=""
-	    >&gt;&lt;</a
-	    > b</li
-	  ></ul
-	></div
-      ><div id="interface"
-      ><h1
-	>Documentation</h1
-	><div class="top"
-	><p class="src"
-	  ><span class="keyword"
-	    >data</span
-	    > <a name="t:X" class="def"
-	    >X</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 name="v:X" class="def"
-		  >X</a
-		  ></td
-		><td class="doc"
-		><p
-		  >Doc for: X</p
-		  ></td
-		></tr
-	      ><tr
-	      ><td class="src"
-		><a name="v:XX" class="def"
-		  >XX</a
-		  ></td
-		><td class="doc"
-		><p
-		  >Doc for: XX</p
-		  ></td
-		></tr
-	      ><tr
-	      ><td class="src"
-		><a name="v:XXX" class="def"
-		  >XXX</a
-		  ></td
-		><td class="doc"
-		><p
-		  >Doc for: XXX</p
-		  ></td
-		></tr
-	      ></table
-	    ></div
-	  ><div class="subs instances"
-	  ><p id="control.i:X" class="caption collapser" onclick="toggleSection('i:X')"
-	    >Instances</p
-	    ><div id="section.i:X" class="show"
-	    ><table
-	      ><tr
-		><td class="src clearfix"
-		  ><span class="inst-left"
-		    ><a href=""
-		      >Assoc</a
-		      > * <a href=""
-		      >X</a
-		      ></span
-		    ></td
-		  ><td class="doc"
-		  ><p
-		    >Doc for: instance Assoc X</p
-		    ></td
-		  ></tr
-		><tr
-		><td class="src clearfix"
-		  ><span class="inst-left"
-		    ><a href=""
-		      >Test</a
-		      > * <a href=""
-		      >X</a
-		      ></span
-		    ></td
-		  ><td class="doc"
-		  ><p
-		    >Doc for: instance Test X</p
-		    ></td
-		  ></tr
-		><tr
-		><td class="src clearfix"
-		  ><span class="inst-left"
-		    ><a href=""
-		      >(&gt;&lt;)</a
-		      > <a href=""
-		      >X</a
-		      > <a href=""
-		      >XX</a
-		      > <a href=""
-		      >XXX</a
-		      ></span
-		    ></td
-		  ><td class="doc empty"
-		  >&nbsp;</td
-		  ></tr
-		><tr
-		><td class="src clearfix"
-		  ><span class="inst-left"
-		    ><span class="keyword"
-		      >type</span
-		      > <a href=""
-		      >Foo</a
-		      > <a href=""
-		      >X</a
-		      > = <a href=""
-		      >Y</a
-		      ></span
-		    ></td
-		  ><td class="doc"
-		  ><p
-		    >External instance</p
-		    ></td
-		  ></tr
-		><tr
-		><td class="src clearfix"
-		  ><span class="inst-left"
-		    ><span class="keyword"
-		      >data</span
-		      > <a href=""
-		      >AssocD</a
-		      > * <a href=""
-		      >X</a
-		      > = <a name="v:AssocX" class="def"
-		      >AssocX</a
-		      ></span
-		    ></td
-		  ><td class="doc empty"
-		  >&nbsp;</td
-		  ></tr
-		><tr
-		><td class="src clearfix"
-		  ><span class="inst-left"
-		    ><span class="keyword"
-		      >type</span
-		      > <a href=""
-		      >AssocT</a
-		      > * <a href=""
-		      >X</a
-		      > = <a href=""
-		      >Foo</a
-		      > * <a href=""
-		      >X</a
-		      ></span
-		    ></td
-		  ><td class="doc empty"
-		  >&nbsp;</td
-		  ></tr
-		><tr
-		><td class="src clearfix"
-		  ><span class="inst-left"
-		    ><span class="keyword"
-		      >data</span
-		      > <a href=""
-		      >Bat</a
-		      > * <a href=""
-		      >X</a
-		      > <ul class="inst"
-		      ><li class="inst"
-			>= <a name="v:BatX" class="def"
-			  >BatX</a
-			  > <a href=""
-			  >X</a
-			  ></li
-			><li class="inst"
-			>| <a name="v:BatXX" class="def"
-			  >BatXX</a
-			  > { <ul class="subs"
-			  ><li
-			    ><a name="v:aaa" class="def"
-			      >aaa</a
-			      > :: <a href=""
-			      >X</a
-			      ></li
-			    ><li
-			    ><a name="v:bbb" class="def"
-			      >bbb</a
-			      > :: <a href=""
-			      >Y</a
-			      ></li
-			    ></ul
-			  > }</li
-			></ul
-		      ></span
-		    ></td
-		  ><td class="doc"
-		  ><p
-		    >Doc for: data instance Bat X</p
-		    ></td
-		  ></tr
-		><tr
-		><td class="src clearfix"
-		  ><span class="inst-left"
-		    ><span class="keyword"
-		      >type</span
-		      > <a href=""
-		      >Foo</a
-		      > * <a href=""
-		      >X</a
-		      > = <a href=""
-		      >Y</a
-		      ></span
-		    ></td
-		  ><td class="doc"
-		  ><p
-		    >Doc for: type instance Foo X = Y</p
-		    ></td
-		  ></tr
-		><tr
-		><td class="src clearfix"
-		  ><span class="inst-left"
-		    ><span class="keyword"
-		      >type</span
-		      > <a href=""
-		      >(&lt;&gt;)</a
-		      > * <a href=""
-		      >X</a
-		      > a = <a href=""
-		      >X</a
-		      ></span
-		    ></td
-		  ><td class="doc empty"
-		  >&nbsp;</td
-		  ></tr
-		><tr
-		><td class="src clearfix"
-		  ><span class="inst-left"
-		    ><span class="keyword"
-		      >type</span
-		      > <a href=""
-		      >(&lt;&gt;)</a
-		      > <a href=""
-		      >X</a
-		      > <a href=""
-		      >XXX</a
-		      > <a href=""
-		      >XX</a
-		      > = <a href=""
-		      >X</a
-		      ></span
-		    ></td
-		  ><td class="doc empty"
-		  >&nbsp;</td
-		  ></tr
-		></table
-	      ></div
-	    ></div
-	  ></div
-	><div class="top"
-	><p class="src"
-	  ><span class="keyword"
-	    >data</span
-	    > <a name="t:Y" class="def"
-	    >Y</a
-	    ></p
-	  ><div class="doc"
-	  ><p
-	    >Doc for: data Y</p
-	    ></div
-	  ><div class="subs instances"
-	  ><p id="control.i:Y" class="caption collapser" onclick="toggleSection('i:Y')"
-	    >Instances</p
-	    ><div id="section.i:Y" class="show"
-	    ><table
-	      ><tr
-		><td class="src clearfix"
-		  ><span class="inst-left"
-		    ><a href=""
-		      >Assoc</a
-		      > * <a href=""
-		      >Y</a
-		      ></span
-		    ></td
-		  ><td class="doc"
-		  ><p
-		    >Doc for: instance Assoc Y</p
-		    ></td
-		  ></tr
-		><tr
-		><td class="src clearfix"
-		  ><span class="inst-left"
-		    ><a href=""
-		      >Test</a
-		      > * <a href=""
-		      >Y</a
-		      ></span
-		    ></td
-		  ><td class="doc"
-		  ><p
-		    >Doc for: instance Test Y</p
-		    ></td
-		  ></tr
-		><tr
-		><td class="src clearfix"
-		  ><span class="inst-left"
-		    ><span class="keyword"
-		      >data</span
-		      > <a href=""
-		      >Bar</a
-		      > <a href=""
-		      >Y</a
-		      ></span
-		    ></td
-		  ><td class="doc empty"
-		  >&nbsp;</td
-		  ></tr
-		><tr
-		><td class="src clearfix"
-		  ><span class="inst-left"
-		    ><span class="keyword"
-		      >data</span
-		      > <a href=""
-		      >AssocD</a
-		      > * <a href=""
-		      >Y</a
-		      > = <a name="v:AssocY" class="def"
-		      >AssocY</a
-		      ></span
-		    ></td
-		  ><td class="doc empty"
-		  >&nbsp;</td
-		  ></tr
-		><tr
-		><td class="src clearfix"
-		  ><span class="inst-left"
-		    ><span class="keyword"
-		      >type</span
-		      > <a href=""
-		      >AssocT</a
-		      > * <a href=""
-		      >Y</a
-		      > = <a href=""
-		      >Bat</a
-		      > * <a href=""
-		      >Y</a
-		      ></span
-		    ></td
-		  ><td class="doc empty"
-		  >&nbsp;</td
-		  ></tr
-		><tr
-		><td class="src clearfix"
-		  ><span class="inst-left"
-		    ><span class="keyword"
-		      >data</span
-		      > <a href=""
-		      >Bat</a
-		      > * <a href=""
-		      >Y</a
-		      > = <a name="v:BatY" class="def"
-		      >BatY</a
-		      > <a href=""
-		      >Y</a
-		      ></span
-		    ></td
-		  ><td class="doc"
-		  ><p
-		    >Doc for: data instance Bat Y</p
-		    ></td
-		  ></tr
-		><tr
-		><td class="src clearfix"
-		  ><span class="inst-left"
-		    ><span class="keyword"
-		      >type</span
-		      > <a href=""
-		      >Foo</a
-		      > * <a href=""
-		      >Y</a
-		      > = <a href=""
-		      >X</a
-		      ></span
-		    ></td
-		  ><td class="doc"
-		  ><p
-		    >Doc for: type instance Foo Y = X</p
-		    ></td
-		  ></tr
-		><tr
-		><td class="src clearfix"
-		  ><span class="inst-left"
-		    ><span class="keyword"
-		      >type</span
-		      > <a href=""
-		      >(&lt;&gt;)</a
-		      > * <a href=""
-		      >Y</a
-		      > a = a</span
-		    ></td
-		  ><td class="doc empty"
-		  >&nbsp;</td
-		  ></tr
-		></table
-	      ></div
-	    ></div
-	  ></div
-	><div class="top"
-	><p class="src"
-	  ><span class="keyword"
-	    >data</span
-	    > <a name="t:Z" class="def"
-	    >Z</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 name="v:ZA" class="def"
-		  >ZA</a
-		  ></td
-		><td class="doc empty"
-		>&nbsp;</td
-		></tr
-	      ><tr
-	      ><td class="src"
-		><a name="v:ZB" class="def"
-		  >ZB</a
-		  ></td
-		><td class="doc empty"
-		>&nbsp;</td
-		></tr
-	      ></table
-	    ></div
-	  ><div class="subs instances"
-	  ><p id="control.i:Z" class="caption collapser" onclick="toggleSection('i:Z')"
-	    >Instances</p
-	    ><div id="section.i:Z" class="show"
-	    ><table
-	      ><tr
-		><td class="src clearfix"
-		  ><span class="inst-left"
-		    ><span class="keyword"
-		      >data</span
-		      > <a href=""
-		      >Bat</a
-		      > <a href=""
-		      >Z</a
-		      > <span class="keyword"
-		      >where</span
-		      ><ul class="inst"
-		      ><li class="inst"
-			><a name="v:BatZ1" class="def"
-			  >BatZ1</a
-			  > ::  <a href=""
-			  >Z</a
-			  > -&gt; <a href=""
-			  >Bat</a
-			  > <a href=""
-			  >Z</a
-			  > <a href=""
-			  >ZA</a
-			  ></li
-			><li class="inst"
-			><a name="v:BatZ2" class="def"
-			  >BatZ2</a
-			  > :: { <ul class="subs"
-			  ><li
-			    ><a name="v:batx" class="def"
-			      >batx</a
-			      > :: <a href=""
-			      >X</a
-			      ></li
-			    ><li
-			    ><a name="v:baty" class="def"
-			      >baty</a
-			      > :: <a href=""
-			      >Y</a
-			      ></li
-			    ></ul
-			  > } -&gt; <a href=""
-			  >Bat</a
-			  > <a href=""
-			  >Z</a
-			  > <a href=""
-			  >ZB</a
-			  ></li
-			></ul
-		      ></span
-		    ></td
-		  ><td class="doc"
-		  ><p
-		    >Doc for: data instance Bat Z</p
-		    ></td
-		  ></tr
-		></table
-	      ></div
-	    ></div
-	  ></div
-	><div class="top"
-	><p class="src"
-	  ><span class="keyword"
-	    >class</span
-	    > <a name="t:Test" class="def"
-	    >Test</a
-	    > a</p
-	  ><div class="doc"
-	  ><p
-	    >Doc for: class Test a</p
-	    ></div
-	  ><div class="subs instances"
-	  ><p id="control.i:Test" class="caption collapser" onclick="toggleSection('i:Test')"
-	    >Instances</p
-	    ><div id="section.i:Test" class="show"
-	    ><table
-	      ><tr
-		><td class="src clearfix"
-		  ><span class="inst-left"
-		    ><a href=""
-		      >Test</a
-		      > * <a href=""
-		      >Y</a
-		      ></span
-		    ></td
-		  ><td class="doc"
-		  ><p
-		    >Doc for: instance Test Y</p
-		    ></td
-		  ></tr
-		><tr
-		><td class="src clearfix"
-		  ><span class="inst-left"
-		    ><a href=""
-		      >Test</a
-		      > * <a href=""
-		      >X</a
-		      ></span
-		    ></td
-		  ><td class="doc"
-		  ><p
-		    >Doc for: instance Test X</p
-		    ></td
-		  ></tr
-		></table
-	      ></div
-	    ></div
-	  ></div
-	><div class="top"
-	><p class="src"
-	  ><span class="keyword"
-	    >type family</span
-	    > <a name="t:Foo" class="def"
-	    >Foo</a
-	    > a :: k</p
-	  ><div class="doc"
-	  ><p
-	    >Doc for: type family Foo a</p
-	    ></div
-	  ><div class="subs instances"
-	  ><p id="control.i:Foo" class="caption collapser" onclick="toggleSection('i:Foo')"
-	    >Instances</p
-	    ><div id="section.i:Foo" class="show"
-	    ><table
-	      ><tr
-		><td class="src clearfix"
-		  ><span class="inst-left"
-		    ><span class="keyword"
-		      >type</span
-		      > <a href=""
-		      >Foo</a
-		      > * <a href=""
-		      >Y</a
-		      > = <a href=""
-		      >X</a
-		      ></span
-		    ></td
-		  ><td class="doc"
-		  ><p
-		    >Doc for: type instance Foo Y = X</p
-		    ></td
-		  ></tr
-		><tr
-		><td class="src clearfix"
-		  ><span class="inst-left"
-		    ><span class="keyword"
-		      >type</span
-		      > <a href=""
-		      >Foo</a
-		      > * <a href=""
-		      >X</a
-		      > = <a href=""
-		      >Y</a
-		      ></span
-		    ></td
-		  ><td class="doc"
-		  ><p
-		    >Doc for: type instance Foo X = Y</p
-		    ></td
-		  ></tr
-		></table
-	      ></div
-	    ></div
-	  ></div
-	><div class="top"
-	><p class="src"
-	  ><span class="keyword"
-	    >data family</span
-	    > <a name="t:Bat" class="def"
-	    >Bat</a
-	    > a :: *</p
-	  ><div class="doc"
-	  ><p
-	    >Doc for: data family Bat a</p
-	    ></div
-	  ><div class="subs instances"
-	  ><p id="control.i:Bat" class="caption collapser" onclick="toggleSection('i:Bat')"
-	    >Instances</p
-	    ><div id="section.i:Bat" class="show"
-	    ><table
-	      ><tr
-		><td class="src clearfix"
-		  ><span class="inst-left"
-		    ><span class="keyword"
-		      >data</span
-		      > <a href=""
-		      >Bat</a
-		      > <a href=""
-		      >Z</a
-		      > <span class="keyword"
-		      >where</span
-		      ><ul class="inst"
-		      ><li class="inst"
-			><a name="v:BatZ1" class="def"
-			  >BatZ1</a
-			  > ::  <a href=""
-			  >Z</a
-			  > -&gt; <a href=""
-			  >Bat</a
-			  > <a href=""
-			  >Z</a
-			  > <a href=""
-			  >ZA</a
-			  ></li
-			><li class="inst"
-			><a name="v:BatZ2" class="def"
-			  >BatZ2</a
-			  > :: { <ul class="subs"
-			  ><li
-			    ><a name="v:batx" class="def"
-			      >batx</a
-			      > :: <a href=""
-			      >X</a
-			      ></li
-			    ><li
-			    ><a name="v:baty" class="def"
-			      >baty</a
-			      > :: <a href=""
-			      >Y</a
-			      ></li
-			    ></ul
-			  > } -&gt; <a href=""
-			  >Bat</a
-			  > <a href=""
-			  >Z</a
-			  > <a href=""
-			  >ZB</a
-			  ></li
-			></ul
-		      ></span
-		    ></td
-		  ><td class="doc"
-		  ><p
-		    >Doc for: data instance Bat Z</p
-		    ></td
-		  ></tr
-		><tr
-		><td class="src clearfix"
-		  ><span class="inst-left"
-		    ><span class="keyword"
-		      >data</span
-		      > <a href=""
-		      >Bat</a
-		      > * <a href=""
-		      >Y</a
-		      > = <a name="v:BatY" class="def"
-		      >BatY</a
-		      > <a href=""
-		      >Y</a
-		      ></span
-		    ></td
-		  ><td class="doc"
-		  ><p
-		    >Doc for: data instance Bat Y</p
-		    ></td
-		  ></tr
-		><tr
-		><td class="src clearfix"
-		  ><span class="inst-left"
-		    ><span class="keyword"
-		      >data</span
-		      > <a href=""
-		      >Bat</a
-		      > * <a href=""
-		      >X</a
-		      > <ul class="inst"
-		      ><li class="inst"
-			>= <a name="v:BatX" class="def"
-			  >BatX</a
-			  > <a href=""
-			  >X</a
-			  ></li
-			><li class="inst"
-			>| <a name="v:BatXX" class="def"
-			  >BatXX</a
-			  > { <ul class="subs"
-			  ><li
-			    ><a name="v:aaa" class="def"
-			      >aaa</a
-			      > :: <a href=""
-			      >X</a
-			      ></li
-			    ><li
-			    ><a name="v:bbb" class="def"
-			      >bbb</a
-			      > :: <a href=""
-			      >Y</a
-			      ></li
-			    ></ul
-			  > }</li
-			></ul
-		      ></span
-		    ></td
-		  ><td class="doc"
-		  ><p
-		    >Doc for: data instance Bat X</p
-		    ></td
-		  ></tr
-		></table
-	      ></div
-	    ></div
-	  ></div
-	><div class="top"
-	><p class="src"
-	  ><span class="keyword"
-	    >class</span
-	    > <a name="t:Assoc" class="def"
-	    >Assoc</a
-	    > 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 name="t:AssocD" class="def"
-	      >AssocD</a
-	      > a :: *</p
-	    ><div class="doc"
-	    ><p
-	      >Doc for: data AssocD a</p
-	      ></div
-	    ><p class="src"
-	    ><span class="keyword"
-	      >type</span
-	      > <a name="t:AssocT" class="def"
-	      >AssocT</a
-	      > a :: *</p
-	    ><div class="doc"
-	    ><p
-	      >Doc for: type AssocT a</p
-	      ></div
-	    ></div
-	  ><div class="subs instances"
-	  ><p id="control.i:Assoc" class="caption collapser" onclick="toggleSection('i:Assoc')"
-	    >Instances</p
-	    ><div id="section.i:Assoc" class="show"
-	    ><table
-	      ><tr
-		><td class="src clearfix"
-		  ><span class="inst-left"
-		    ><a href=""
-		      >Assoc</a
-		      > * <a href=""
-		      >Y</a
-		      ></span
-		    ></td
-		  ><td class="doc"
-		  ><p
-		    >Doc for: instance Assoc Y</p
-		    ></td
-		  ></tr
-		><tr
-		><td class="src clearfix"
-		  ><span class="inst-left"
-		    ><a href=""
-		      >Assoc</a
-		      > * <a href=""
-		      >X</a
-		      ></span
-		    ></td
-		  ><td class="doc"
-		  ><p
-		    >Doc for: instance Assoc X</p
-		    ></td
-		  ></tr
-		></table
-	      ></div
-	    ></div
-	  ></div
-	><div class="top"
-	><p class="src"
-	  ><span class="keyword"
-	    >type family</span
-	    > <a name="t:Bar" class="def"
-	    >Bar</a
-	    > b</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=""
-		  >Bar</a
-		  > <a href=""
-		  >X</a
-		  > = <a href=""
-		  >X</a
-		  ></td
-		><td class="doc empty"
-		>&nbsp;</td
-		></tr
-	      ><tr
-	      ><td class="src"
-		><a href=""
-		  >Bar</a
-		  > y = <a href=""
-		  >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 <a name="t:-60--62-" class="def"
-	    >&lt;&gt;</a
-	    > b :: k</p
-	  ><div class="subs instances"
-	  ><p id="control.i:-60--62-" class="caption collapser" onclick="toggleSection('i:-60--62-')"
-	    >Instances</p
-	    ><div id="section.i:-60--62-" class="show"
-	    ><table
-	      ><tr
-		><td class="src clearfix"
-		  ><span class="inst-left"
-		    ><span class="keyword"
-		      >type</span
-		      > <a href=""
-		      >(&lt;&gt;)</a
-		      > * <a href=""
-		      >Y</a
-		      > a = a</span
-		    ></td
-		  ><td class="doc empty"
-		  >&nbsp;</td
-		  ></tr
-		><tr
-		><td class="src clearfix"
-		  ><span class="inst-left"
-		    ><span class="keyword"
-		      >type</span
-		      > <a href=""
-		      >(&lt;&gt;)</a
-		      > * <a href=""
-		      >X</a
-		      > a = <a href=""
-		      >X</a
-		      ></span
-		    ></td
-		  ><td class="doc empty"
-		  >&nbsp;</td
-		  ></tr
-		><tr
-		><td class="src clearfix"
-		  ><span class="inst-left"
-		    ><span class="keyword"
-		      >type</span
-		      > <a href=""
-		      >(&lt;&gt;)</a
-		      > <a href=""
-		      >X</a
-		      > <a href=""
-		      >XXX</a
-		      > <a href=""
-		      >XX</a
-		      > = <a href=""
-		      >X</a
-		      ></span
-		    ></td
-		  ><td class="doc empty"
-		  >&nbsp;</td
-		  ></tr
-		></table
-	      ></div
-	    ></div
-	  ></div
-	><div class="top"
-	><p class="src"
-	  ><span class="keyword"
-	    >class</span
-	    > a <a name="t:-62--60-" class="def"
-	    >&gt;&lt;</a
-	    > b</p
-	  ><div class="subs instances"
-	  ><p id="control.i:-62--60-" class="caption collapser" onclick="toggleSection('i:-62--60-')"
-	    >Instances</p
-	    ><div id="section.i:-62--60-" class="show"
-	    ><table
-	      ><tr
-		><td class="src clearfix"
-		  ><span class="inst-left"
-		    ><a href=""
-		      >(&gt;&lt;)</a
-		      > <a href=""
-		      >X</a
-		      > <a href=""
-		      >XX</a
-		      > <a href=""
-		      >XXX</a
-		      ></span
-		    ></td
-		  ><td class="doc empty"
-		  >&nbsp;</td
-		  ></tr
-		></table
-	      ></div
-	    ></div
-	  ></div
-	></div
-      ></div
-    ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.16.1</p
-      ></div
+<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="#" rel="stylesheet" type="text/css" title="Ocean"
+     /><script src="haddock-util.js" type="text/javascript"
+    ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
+    ><script type="text/javascript"
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_TypeFamilies.html&quot;);};
+//
+</script
+    ></head
+  ><body
+  ><div id="package-header"
+    ><ul class="links" id="page-menu"
+      ><li
+	><a href="#"
+	  >Contents</a
+	  ></li
+	><li
+	><a href="#"
+	  >Index</a
+	  ></li
+	></ul
+      ><p class="caption empty"
+      ></p
+      ></div
+    ><div id="content"
+    ><div id="module-header"
+      ><table class="info"
+	><tr
+	  ><th
+	    >Safe Haskell</th
+	    ><td
+	    >Safe</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"
+      ><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"
+	  ><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) :: <a href="#"
+	    >*</a
+	    ></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 :: <a href="#"
+		>*</a
+		></li
+	      ><li
+	      ><span class="keyword"
+		>type</span
+		> <a href="#"
+		>AssocT</a
+		> a :: <a href="#"
+		>*</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 <a href="#"
+	    >&gt;&lt;</a
+	    > b</li
+	  ></ul
+	></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"
+	  ><p id="control.i:X" class="caption collapser" onclick="toggleSection('i:X')"
+	    >Instances</p
+	    ><div id="section.i:X" class="show"
+	    ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:id:X:-62--60-:1" class="instance expander" onclick="toggleSection('i:id:X:-62--60-:1')"
+		      ></span
+		      > <a href="#"
+		      >(&gt;&lt;)</a
+		      > <a href="#"
+		      >X</a
+		      > <a href="#"
+		      >XX</a
+		      > <a href="#"
+		      >XXX</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:id:X:-62--60-:1" class="inst-details hide"
+		    ></div
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:id:X:Assoc:2" class="instance expander" onclick="toggleSection('i:id:X:Assoc:2')"
+		      ></span
+		      > <a href="#"
+		      >Assoc</a
+		      > <a href="#"
+		      >*</a
+		      > <a href="#"
+		      >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"
+		  ><div id="section.i:id:X:Assoc:2" class="inst-details hide"
+		    ><div class="subs associated-types"
+		      ><p class="caption"
+			>Associated Types</p
+			><p class="src"
+			><span class="keyword"
+			  >data</span
+			  > <a href="#"
+			  >AssocD</a
+			  > <a href="#"
+			  >X</a
+			  > (a :: <a href="#"
+			  >X</a
+			  >) :: <a href="#"
+			  >*</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><span class="keyword"
+			  >type</span
+			  > <a href="#"
+			  >AssocT</a
+			  > <a href="#"
+			  >X</a
+			  > (a :: <a href="#"
+			  >X</a
+			  >) :: <a href="#"
+			  >*</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></div
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:id:X:Test:3" class="instance expander" onclick="toggleSection('i:id:X:Test:3')"
+		      ></span
+		      > <a href="#"
+		      >Test</a
+		      > <a href="#"
+		      >*</a
+		      > <a href="#"
+		      >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"
+		  ><div id="section.i:id:X:Test:3" class="inst-details hide"
+		    ></div
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:id:X:Foo:4" class="instance expander" onclick="toggleSection('i:id:X:Foo:4')"
+		      ></span
+		      > <span class="keyword"
+		      >type</span
+		      > <a href="#"
+		      >Foo</a
+		      > <a href="#"
+		      >X</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:id:X:Foo:4" class="inst-details hide"
+		    ><div class="src"
+		      ><span class="keyword"
+			>type</span
+			> <a href="#"
+			>Foo</a
+			> <a href="#"
+			>X</a
+			> = <a href="#"
+			>Y</a
+			></div
+		      ></div
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:id:X:-60--62-:5" class="instance expander" onclick="toggleSection('i:id:X:-60--62-:5')"
+		      ></span
+		      > <span class="keyword"
+		      >type</span
+		      > <a href="#"
+		      >(&lt;&gt;)</a
+		      > <a href="#"
+		      >X</a
+		      > <a href="#"
+		      >XXX</a
+		      > <a href="#"
+		      >XX</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:id:X:-60--62-:5" class="inst-details hide"
+		    ><div class="src"
+		      ><span class="keyword"
+			>type</span
+			> <a href="#"
+			>(&lt;&gt;)</a
+			> <a href="#"
+			>X</a
+			> <a href="#"
+			>XXX</a
+			> <a href="#"
+			>XX</a
+			> = <a href="#"
+			>X</a
+			></div
+		      ></div
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:id:X:AssocD:6" class="instance expander" onclick="toggleSection('i:id:X:AssocD:6')"
+		      ></span
+		      > <span class="keyword"
+		      >data</span
+		      > <a href="#"
+		      >AssocD</a
+		      > <a href="#"
+		      >*</a
+		      > <a href="#"
+		      >X</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:id:X:AssocD:6" class="inst-details hide"
+		    ><div class="src"
+		      ><span class="keyword"
+			>data</span
+			> <a href="#"
+			>AssocD</a
+			> <a href="#"
+			>*</a
+			> <a href="#"
+			>X</a
+			> = <a id="v:AssocX" class="def"
+			>AssocX</a
+			></div
+		      ></div
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:id:X:AssocT:7" class="instance expander" onclick="toggleSection('i:id:X:AssocT:7')"
+		      ></span
+		      > <span class="keyword"
+		      >type</span
+		      > <a href="#"
+		      >AssocT</a
+		      > <a href="#"
+		      >*</a
+		      > <a href="#"
+		      >X</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:id:X:AssocT:7" class="inst-details hide"
+		    ><div class="src"
+		      ><span class="keyword"
+			>type</span
+			> <a href="#"
+			>AssocT</a
+			> <a href="#"
+			>*</a
+			> <a href="#"
+			>X</a
+			> = <a href="#"
+			>Foo</a
+			> <a href="#"
+			>*</a
+			> <a href="#"
+			>X</a
+			></div
+		      ></div
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:id:X:Bat:8" class="instance expander" onclick="toggleSection('i:id:X:Bat:8')"
+		      ></span
+		      > <span class="keyword"
+		      >data</span
+		      > <a href="#"
+		      >Bat</a
+		      > <a href="#"
+		      >*</a
+		      > <a href="#"
+		      >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"
+		  ><div id="section.i:id:X:Bat:8" class="inst-details hide"
+		    ><div class="src"
+		      ><span class="keyword"
+			>data</span
+			> <a href="#"
+			>Bat</a
+			> <a href="#"
+			>*</a
+			> <a href="#"
+			>X</a
+			> <ul class="inst"
+			><li class="inst"
+			  >= <a id="v:BatX" class="def"
+			    >BatX</a
+			    > <a href="#"
+			    >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="#"
+				>X</a
+				></li
+			      ><li
+			      ><a id="v:bbb" class="def"
+				>bbb</a
+				> :: <a href="#"
+				>Y</a
+				></li
+			      ></ul
+			    > }</li
+			  ></ul
+			></div
+		      ></div
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:id:X:Foo:9" class="instance expander" onclick="toggleSection('i:id:X:Foo:9')"
+		      ></span
+		      > <span class="keyword"
+		      >type</span
+		      > <a href="#"
+		      >Foo</a
+		      > <a href="#"
+		      >*</a
+		      > <a href="#"
+		      >X</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:id:X:Foo:9" class="inst-details hide"
+		    ><div class="src"
+		      ><span class="keyword"
+			>type</span
+			> <a href="#"
+			>Foo</a
+			> <a href="#"
+			>*</a
+			> <a href="#"
+			>X</a
+			> = <a href="#"
+			>Y</a
+			></div
+		      ></div
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:id:X:-60--62-:10" class="instance expander" onclick="toggleSection('i:id:X:-60--62-:10')"
+		      ></span
+		      > <span class="keyword"
+		      >type</span
+		      > <a href="#"
+		      >(&lt;&gt;)</a
+		      > <a href="#"
+		      >*</a
+		      > <a href="#"
+		      >X</a
+		      > a</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:id:X:-60--62-:10" class="inst-details hide"
+		    ><div class="src"
+		      ><span class="keyword"
+			>type</span
+			> <a href="#"
+			>(&lt;&gt;)</a
+			> <a href="#"
+			>*</a
+			> <a href="#"
+			>X</a
+			> a = <a href="#"
+			>X</a
+			></div
+		      ></div
+		    ></td
+		  ></tr
+		></table
+	      ></div
+	    ></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"
+	  ><p id="control.i:Y" class="caption collapser" onclick="toggleSection('i:Y')"
+	    >Instances</p
+	    ><div id="section.i:Y" class="show"
+	    ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:id:Y:Assoc:1" class="instance expander" onclick="toggleSection('i:id:Y:Assoc:1')"
+		      ></span
+		      > <a href="#"
+		      >Assoc</a
+		      > <a href="#"
+		      >*</a
+		      > <a href="#"
+		      >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"
+		  ><div id="section.i:id:Y:Assoc:1" class="inst-details hide"
+		    ><div class="subs associated-types"
+		      ><p class="caption"
+			>Associated Types</p
+			><p class="src"
+			><span class="keyword"
+			  >data</span
+			  > <a href="#"
+			  >AssocD</a
+			  > <a href="#"
+			  >Y</a
+			  > (a :: <a href="#"
+			  >Y</a
+			  >) :: <a href="#"
+			  >*</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><span class="keyword"
+			  >type</span
+			  > <a href="#"
+			  >AssocT</a
+			  > <a href="#"
+			  >Y</a
+			  > (a :: <a href="#"
+			  >Y</a
+			  >) :: <a href="#"
+			  >*</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></div
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:id:Y:Test:2" class="instance expander" onclick="toggleSection('i:id:Y:Test:2')"
+		      ></span
+		      > <a href="#"
+		      >Test</a
+		      > <a href="#"
+		      >*</a
+		      > <a href="#"
+		      >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"
+		  ><div id="section.i:id:Y:Test:2" class="inst-details hide"
+		    ></div
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:id:Y:Bar:3" class="instance expander" onclick="toggleSection('i:id:Y:Bar:3')"
+		      ></span
+		      > <span class="keyword"
+		      >data</span
+		      > <a href="#"
+		      >Bar</a
+		      > <a href="#"
+		      >Y</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:id:Y:Bar:3" class="inst-details hide"
+		    ><div class="src"
+		      ><span class="keyword"
+			>data</span
+			> <a href="#"
+			>Bar</a
+			> <a href="#"
+			>Y</a
+			></div
+		      ></div
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:id:Y:AssocD:4" class="instance expander" onclick="toggleSection('i:id:Y:AssocD:4')"
+		      ></span
+		      > <span class="keyword"
+		      >data</span
+		      > <a href="#"
+		      >AssocD</a
+		      > <a href="#"
+		      >*</a
+		      > <a href="#"
+		      >Y</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:id:Y:AssocD:4" class="inst-details hide"
+		    ><div class="src"
+		      ><span class="keyword"
+			>data</span
+			> <a href="#"
+			>AssocD</a
+			> <a href="#"
+			>*</a
+			> <a href="#"
+			>Y</a
+			> = <a id="v:AssocY" class="def"
+			>AssocY</a
+			></div
+		      ></div
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:id:Y:AssocT:5" class="instance expander" onclick="toggleSection('i:id:Y:AssocT:5')"
+		      ></span
+		      > <span class="keyword"
+		      >type</span
+		      > <a href="#"
+		      >AssocT</a
+		      > <a href="#"
+		      >*</a
+		      > <a href="#"
+		      >Y</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:id:Y:AssocT:5" class="inst-details hide"
+		    ><div class="src"
+		      ><span class="keyword"
+			>type</span
+			> <a href="#"
+			>AssocT</a
+			> <a href="#"
+			>*</a
+			> <a href="#"
+			>Y</a
+			> = <a href="#"
+			>Bat</a
+			> <a href="#"
+			>*</a
+			> <a href="#"
+			>Y</a
+			></div
+		      ></div
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:id:Y:Bat:6" class="instance expander" onclick="toggleSection('i:id:Y:Bat:6')"
+		      ></span
+		      > <span class="keyword"
+		      >data</span
+		      > <a href="#"
+		      >Bat</a
+		      > <a href="#"
+		      >*</a
+		      > <a href="#"
+		      >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"
+		  ><div id="section.i:id:Y:Bat:6" class="inst-details hide"
+		    ><div class="src"
+		      ><span class="keyword"
+			>data</span
+			> <a href="#"
+			>Bat</a
+			> <a href="#"
+			>*</a
+			> <a href="#"
+			>Y</a
+			> = <a id="v:BatY" class="def"
+			>BatY</a
+			> <a href="#"
+			>Y</a
+			></div
+		      ></div
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:id:Y:Foo:7" class="instance expander" onclick="toggleSection('i:id:Y:Foo:7')"
+		      ></span
+		      > <span class="keyword"
+		      >type</span
+		      > <a href="#"
+		      >Foo</a
+		      > <a href="#"
+		      >*</a
+		      > <a href="#"
+		      >Y</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:id:Y:Foo:7" class="inst-details hide"
+		    ><div class="src"
+		      ><span class="keyword"
+			>type</span
+			> <a href="#"
+			>Foo</a
+			> <a href="#"
+			>*</a
+			> <a href="#"
+			>Y</a
+			> = <a href="#"
+			>X</a
+			></div
+		      ></div
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:id:Y:-60--62-:8" class="instance expander" onclick="toggleSection('i:id:Y:-60--62-:8')"
+		      ></span
+		      > <span class="keyword"
+		      >type</span
+		      > <a href="#"
+		      >(&lt;&gt;)</a
+		      > <a href="#"
+		      >*</a
+		      > <a href="#"
+		      >Y</a
+		      > a</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:id:Y:-60--62-:8" class="inst-details hide"
+		    ><div class="src"
+		      ><span class="keyword"
+			>type</span
+			> <a href="#"
+			>(&lt;&gt;)</a
+			> <a href="#"
+			>*</a
+			> <a href="#"
+			>Y</a
+			> a = a</div
+		      ></div
+		    ></td
+		  ></tr
+		></table
+	      ></div
+	    ></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"
+		></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		><a id="v:ZB" class="def"
+		  >ZB</a
+		  ></td
+		><td class="doc empty"
+		></td
+		></tr
+	      ></table
+	    ></div
+	  ><div class="subs instances"
+	  ><p id="control.i:Z" class="caption collapser" onclick="toggleSection('i:Z')"
+	    >Instances</p
+	    ><div id="section.i:Z" class="show"
+	    ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:id:Z:Bat:1" class="instance expander" onclick="toggleSection('i:id:Z:Bat:1')"
+		      ></span
+		      > <span class="keyword"
+		      >data</span
+		      > <a href="#"
+		      >Bat</a
+		      > <a href="#"
+		      >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"
+		  ><div id="section.i:id:Z:Bat:1" class="inst-details hide"
+		    ><div class="src"
+		      ><span class="keyword"
+			>data</span
+			> <a href="#"
+			>Bat</a
+			> <a href="#"
+			>Z</a
+			> <span class="keyword"
+			>where</span
+			><ul class="inst"
+			><li class="inst"
+			  ><a id="v:BatZ1" class="def"
+			    >BatZ1</a
+			    > :: <a href="#"
+			    >Bat</a
+			    > <a href="#"
+			    >Z</a
+			    > <a href="#"
+			    >ZA</a
+			    ></li
+			  ><li class="inst"
+			  ><a id="v:BatZ2" class="def"
+			    >BatZ2</a
+			    > :: <a href="#"
+			    >Bat</a
+			    > <a href="#"
+			    >Z</a
+			    > <a href="#"
+			    >ZB</a
+			    ></li
+			  ></ul
+			></div
+		      ></div
+		    ></td
+		  ></tr
+		></table
+	      ></div
+	    ></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"
+	  ><p id="control.i:Test" class="caption collapser" onclick="toggleSection('i:Test')"
+	    >Instances</p
+	    ><div id="section.i:Test" class="show"
+	    ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:ic:Test:Test:1" class="instance expander" onclick="toggleSection('i:ic:Test:Test:1')"
+		      ></span
+		      > <a href="#"
+		      >Test</a
+		      > <a href="#"
+		      >*</a
+		      > <a href="#"
+		      >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"
+		  ><div id="section.i:ic:Test:Test:1" class="inst-details hide"
+		    ></div
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:ic:Test:Test:2" class="instance expander" onclick="toggleSection('i:ic:Test:Test:2')"
+		      ></span
+		      > <a href="#"
+		      >Test</a
+		      > <a href="#"
+		      >*</a
+		      > <a href="#"
+		      >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"
+		  ><div id="section.i:ic:Test:Test:2" class="inst-details hide"
+		    ></div
+		    ></td
+		  ></tr
+		></table
+	      ></div
+	    ></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"
+	  ><p id="control.i:Foo" class="caption collapser" onclick="toggleSection('i:Foo')"
+	    >Instances</p
+	    ><div id="section.i:Foo" class="show"
+	    ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:if:Foo:Foo:1" class="instance expander" onclick="toggleSection('i:if:Foo:Foo:1')"
+		      ></span
+		      > <span class="keyword"
+		      >type</span
+		      > <a href="#"
+		      >Foo</a
+		      > <a href="#"
+		      >*</a
+		      > <a href="#"
+		      >Y</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:if:Foo:Foo:1" class="inst-details hide"
+		    ><div class="src"
+		      ><span class="keyword"
+			>type</span
+			> <a href="#"
+			>Foo</a
+			> <a href="#"
+			>*</a
+			> <a href="#"
+			>Y</a
+			> = <a href="#"
+			>X</a
+			></div
+		      ></div
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:if:Foo:Foo:2" class="instance expander" onclick="toggleSection('i:if:Foo:Foo:2')"
+		      ></span
+		      > <span class="keyword"
+		      >type</span
+		      > <a href="#"
+		      >Foo</a
+		      > <a href="#"
+		      >*</a
+		      > <a href="#"
+		      >X</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:if:Foo:Foo:2" class="inst-details hide"
+		    ><div class="src"
+		      ><span class="keyword"
+			>type</span
+			> <a href="#"
+			>Foo</a
+			> <a href="#"
+			>*</a
+			> <a href="#"
+			>X</a
+			> = <a href="#"
+			>Y</a
+			></div
+		      ></div
+		    ></td
+		  ></tr
+		></table
+	      ></div
+	    ></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="#"
+	    >*</a
+	    > <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="doc"
+	  ><p
+	    >Doc for: data family Bat a</p
+	    ></div
+	  ><div class="subs instances"
+	  ><p id="control.i:Bat" class="caption collapser" onclick="toggleSection('i:Bat')"
+	    >Instances</p
+	    ><div id="section.i:Bat" class="show"
+	    ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:if:Bat:Bat:1" class="instance expander" onclick="toggleSection('i:if:Bat:Bat:1')"
+		      ></span
+		      > <span class="keyword"
+		      >data</span
+		      > <a href="#"
+		      >Bat</a
+		      > <a href="#"
+		      >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"
+		  ><div id="section.i:if:Bat:Bat:1" class="inst-details hide"
+		    ><div class="src"
+		      ><span class="keyword"
+			>data</span
+			> <a href="#"
+			>Bat</a
+			> <a href="#"
+			>Z</a
+			> <span class="keyword"
+			>where</span
+			><ul class="inst"
+			><li class="inst"
+			  ><a id="v:BatZ1" class="def"
+			    >BatZ1</a
+			    > :: <a href="#"
+			    >Bat</a
+			    > <a href="#"
+			    >Z</a
+			    > <a href="#"
+			    >ZA</a
+			    ></li
+			  ><li class="inst"
+			  ><a id="v:BatZ2" class="def"
+			    >BatZ2</a
+			    > :: <a href="#"
+			    >Bat</a
+			    > <a href="#"
+			    >Z</a
+			    > <a href="#"
+			    >ZB</a
+			    ></li
+			  ></ul
+			></div
+		      ></div
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:if:Bat:Bat:2" class="instance expander" onclick="toggleSection('i:if:Bat:Bat:2')"
+		      ></span
+		      > <span class="keyword"
+		      >data</span
+		      > <a href="#"
+		      >Bat</a
+		      > <a href="#"
+		      >*</a
+		      > <a href="#"
+		      >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"
+		  ><div id="section.i:if:Bat:Bat:2" class="inst-details hide"
+		    ><div class="src"
+		      ><span class="keyword"
+			>data</span
+			> <a href="#"
+			>Bat</a
+			> <a href="#"
+			>*</a
+			> <a href="#"
+			>Y</a
+			> = <a id="v:BatY" class="def"
+			>BatY</a
+			> <a href="#"
+			>Y</a
+			></div
+		      ></div
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:if:Bat:Bat:3" class="instance expander" onclick="toggleSection('i:if:Bat:Bat:3')"
+		      ></span
+		      > <span class="keyword"
+		      >data</span
+		      > <a href="#"
+		      >Bat</a
+		      > <a href="#"
+		      >*</a
+		      > <a href="#"
+		      >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"
+		  ><div id="section.i:if:Bat:Bat:3" class="inst-details hide"
+		    ><div class="src"
+		      ><span class="keyword"
+			>data</span
+			> <a href="#"
+			>Bat</a
+			> <a href="#"
+			>*</a
+			> <a href="#"
+			>X</a
+			> <ul class="inst"
+			><li class="inst"
+			  >= <a id="v:BatX" class="def"
+			    >BatX</a
+			    > <a href="#"
+			    >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="#"
+				>X</a
+				></li
+			      ><li
+			      ><a id="v:bbb" class="def"
+				>bbb</a
+				> :: <a href="#"
+				>Y</a
+				></li
+			      ></ul
+			    > }</li
+			  ></ul
+			></div
+		      ></div
+		    ></td
+		  ></tr
+		></table
+	      ></div
+	    ></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="#"
+	      >*</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="#"
+	      >*</a
+	      > <a href="#" class="selflink"
+	      >#</a
+	      ></p
+	    ><div class="doc"
+	    ><p
+	      >Doc for: type AssocT a</p
+	      ></div
+	    ></div
+	  ><div class="subs instances"
+	  ><p id="control.i:Assoc" class="caption collapser" onclick="toggleSection('i:Assoc')"
+	    >Instances</p
+	    ><div id="section.i:Assoc" class="show"
+	    ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:ic:Assoc:Assoc:1" class="instance expander" onclick="toggleSection('i:ic:Assoc:Assoc:1')"
+		      ></span
+		      > <a href="#"
+		      >Assoc</a
+		      > <a href="#"
+		      >*</a
+		      > <a href="#"
+		      >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"
+		  ><div id="section.i:ic:Assoc:Assoc:1" class="inst-details hide"
+		    ><div class="subs associated-types"
+		      ><p class="caption"
+			>Associated Types</p
+			><p class="src"
+			><span class="keyword"
+			  >data</span
+			  > <a href="#"
+			  >AssocD</a
+			  > <a href="#"
+			  >Y</a
+			  > (a :: <a href="#"
+			  >Y</a
+			  >) :: <a href="#"
+			  >*</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><span class="keyword"
+			  >type</span
+			  > <a href="#"
+			  >AssocT</a
+			  > <a href="#"
+			  >Y</a
+			  > (a :: <a href="#"
+			  >Y</a
+			  >) :: <a href="#"
+			  >*</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></div
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:ic:Assoc:Assoc:2" class="instance expander" onclick="toggleSection('i:ic:Assoc:Assoc:2')"
+		      ></span
+		      > <a href="#"
+		      >Assoc</a
+		      > <a href="#"
+		      >*</a
+		      > <a href="#"
+		      >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"
+		  ><div id="section.i:ic:Assoc:Assoc:2" class="inst-details hide"
+		    ><div class="subs associated-types"
+		      ><p class="caption"
+			>Associated Types</p
+			><p class="src"
+			><span class="keyword"
+			  >data</span
+			  > <a href="#"
+			  >AssocD</a
+			  > <a href="#"
+			  >X</a
+			  > (a :: <a href="#"
+			  >X</a
+			  >) :: <a href="#"
+			  >*</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			><p class="src"
+			><span class="keyword"
+			  >type</span
+			  > <a href="#"
+			  >AssocT</a
+			  > <a href="#"
+			  >X</a
+			  > (a :: <a href="#"
+			  >X</a
+			  >) :: <a href="#"
+			  >*</a
+			  > <a href="#" class="selflink"
+			  >#</a
+			  ></p
+			></div
+		      ></div
+		    ></td
+		  ></tr
+		></table
+	      ></div
+	    ></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="#"
+		  >Bar</a
+		  > <a href="#"
+		  >X</a
+		  > = <a href="#"
+		  >X</a
+		  ></td
+		><td class="doc empty"
+		></td
+		></tr
+	      ><tr
+	      ><td class="src"
+		><a href="#"
+		  >Bar</a
+		  > y = <a href="#"
+		  >Y</a
+		  ></td
+		><td class="doc empty"
+		></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"
+	  ><p id="control.i:-60--62-" class="caption collapser" onclick="toggleSection('i:-60--62-')"
+	    >Instances</p
+	    ><div id="section.i:-60--62-" class="show"
+	    ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:if:-60--62-:-60--62-:1" class="instance expander" onclick="toggleSection('i:if:-60--62-:-60--62-:1')"
+		      ></span
+		      > <span class="keyword"
+		      >type</span
+		      > <a href="#"
+		      >(&lt;&gt;)</a
+		      > <a href="#"
+		      >X</a
+		      > <a href="#"
+		      >XXX</a
+		      > <a href="#"
+		      >XX</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:if:-60--62-:-60--62-:1" class="inst-details hide"
+		    ><div class="src"
+		      ><span class="keyword"
+			>type</span
+			> <a href="#"
+			>(&lt;&gt;)</a
+			> <a href="#"
+			>X</a
+			> <a href="#"
+			>XXX</a
+			> <a href="#"
+			>XX</a
+			> = <a href="#"
+			>X</a
+			></div
+		      ></div
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:if:-60--62-:-60--62-:2" class="instance expander" onclick="toggleSection('i:if:-60--62-:-60--62-:2')"
+		      ></span
+		      > <span class="keyword"
+		      >type</span
+		      > <a href="#"
+		      >(&lt;&gt;)</a
+		      > <a href="#"
+		      >*</a
+		      > <a href="#"
+		      >Y</a
+		      > a</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:if:-60--62-:-60--62-:2" class="inst-details hide"
+		    ><div class="src"
+		      ><span class="keyword"
+			>type</span
+			> <a href="#"
+			>(&lt;&gt;)</a
+			> <a href="#"
+			>*</a
+			> <a href="#"
+			>Y</a
+			> a = a</div
+		      ></div
+		    ></td
+		  ></tr
+		><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:if:-60--62-:-60--62-:3" class="instance expander" onclick="toggleSection('i:if:-60--62-:-60--62-:3')"
+		      ></span
+		      > <span class="keyword"
+		      >type</span
+		      > <a href="#"
+		      >(&lt;&gt;)</a
+		      > <a href="#"
+		      >*</a
+		      > <a href="#"
+		      >X</a
+		      > a</span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:if:-60--62-:-60--62-:3" class="inst-details hide"
+		    ><div class="src"
+		      ><span class="keyword"
+			>type</span
+			> <a href="#"
+			>(&lt;&gt;)</a
+			> <a href="#"
+			>*</a
+			> <a href="#"
+			>X</a
+			> a = <a href="#"
+			>X</a
+			></div
+		      ></div
+		    ></td
+		  ></tr
+		></table
+	      ></div
+	    ></div
+	  ></div
+	><div class="top"
+	><p class="src"
+	  ><span class="keyword"
+	    >class</span
+	    > a <a id="t:-62--60-" class="def"
+	    >&gt;&lt;</a
+	    > b <a href="#" class="selflink"
+	    >#</a
+	    ></p
+	  ><div class="subs instances"
+	  ><p id="control.i:-62--60-" class="caption collapser" onclick="toggleSection('i:-62--60-')"
+	    >Instances</p
+	    ><div id="section.i:-62--60-" class="show"
+	    ><table
+	      ><tr
+		><td class="src clearfix"
+		  ><span class="inst-left"
+		    ><span id="control.i:ic:-62--60-:-62--60-:1" class="instance expander" onclick="toggleSection('i:ic:-62--60-:-62--60-:1')"
+		      ></span
+		      > <a href="#"
+		      >(&gt;&lt;)</a
+		      > <a href="#"
+		      >X</a
+		      > <a href="#"
+		      >XX</a
+		      > <a href="#"
+		      >XXX</a
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
+		    ></td
+		  ><td class="doc empty"
+		  ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:ic:-62--60-:-62--60-:1" class="inst-details hide"
+		    ></div
+		    ></td
+		  ></tr
+		></table
+	      ></div
+	    ></div
+	  ></div
+	></div
+      ></div
+    ><div id="footer"
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/TypeFamilies2.html b/html-test/ref/TypeFamilies2.html
--- a/html-test/ref/TypeFamilies2.html
+++ b/html-test/ref/TypeFamilies2.html
@@ -1,32 +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
     >TypeFamilies2</title
-    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_TypeFamilies2.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_TypeFamilies2.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -48,19 +49,19 @@
 	><li class="src short"
 	  ><span class="keyword"
 	    >data</span
-	    > <a href=""
+	    > <a href="#"
 	    >W</a
 	    ></li
 	  ><li class="src short"
 	  ><span class="keyword"
 	    >type family</span
-	    > <a href=""
+	    > <a href="#"
 	    >Foo</a
 	    > a</li
 	  ><li class="src short"
 	  ><span class="keyword"
 	    >data family</span
-	    > <a href=""
+	    > <a href="#"
 	    >Bar</a
 	    > a</li
 	  ></ul
@@ -72,8 +73,10 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >data</span
-	    > <a name="t:W" class="def"
+	    > <a id="t:W" class="def"
 	    >W</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="doc"
 	  ><p
@@ -87,15 +90,17 @@
 	      ><tr
 		><td class="src clearfix"
 		  ><span class="inst-left"
-		    ><span class="keyword"
+		    ><span id="control.i:id:W:Bar:1" class="instance expander" onclick="toggleSection('i:id:W:Bar:1')"
+		      ></span
+		      > <span class="keyword"
 		      >data</span
-		      > <a href=""
+		      > <a href="#"
 		      >Bar</a
-		      > <a href=""
+		      > <a href="#"
 		      >W</a
-		      > = <a name="v:BarX" class="def"
-		      >BarX</a
-		      > Z</span
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
 		    ></td
 		  ><td class="doc"
 		  ><p
@@ -103,19 +108,51 @@
 		    ></td
 		  ></tr
 		><tr
+		><td colspan="2"
+		  ><div id="section.i:id:W:Bar:1" class="inst-details hide"
+		    ><div class="src"
+		      ><span class="keyword"
+			>data</span
+			> <a href="#"
+			>Bar</a
+			> <a href="#"
+			>W</a
+			> = <a id="v:BarX" class="def"
+			>BarX</a
+			> Z</div
+		      ></div
+		    ></td
+		  ></tr
+		><tr
 		><td class="src clearfix"
 		  ><span class="inst-left"
-		    ><span class="keyword"
+		    ><span id="control.i:id:W:Foo:2" class="instance expander" onclick="toggleSection('i:id:W:Foo:2')"
+		      ></span
+		      > <span class="keyword"
 		      >type</span
-		      > <a href=""
+		      > <a href="#"
 		      >Foo</a
-		      > <a href=""
+		      > <a href="#"
 		      >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 class="doc empty"
+		  ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:id:W:Foo:2" class="inst-details hide"
+		    ><div class="src"
+		      ><span class="keyword"
+			>type</span
+			> <a href="#"
+			>Foo</a
+			> <a href="#"
+			>W</a
+			></div
+		      ></div
 		    ></td
 		  ></tr
 		></table
@@ -126,9 +163,11 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >type family</span
-	    > <a name="t:Foo" class="def"
+	    > <a id="t:Foo" class="def"
 	    >Foo</a
-	    > a</p
+	    > a <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ><div class="doc"
 	  ><p
 	    >Exported type family</p
@@ -141,35 +180,67 @@
 	      ><tr
 		><td class="src clearfix"
 		  ><span class="inst-left"
-		    ><span class="keyword"
+		    ><span id="control.i:if:Foo:Foo:1" class="instance expander" onclick="toggleSection('i:if:Foo:Foo:1')"
+		      ></span
+		      > <span class="keyword"
 		      >type</span
-		      > <a href=""
+		      > <a href="#"
 		      >Foo</a
-		      > <a href=""
+		      > <a href="#"
 		      >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 class="doc empty"
+		  ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:if:Foo:Foo:1" class="inst-details hide"
+		    ><div class="src"
+		      ><span class="keyword"
+			>type</span
+			> <a href="#"
+			>Foo</a
+			> <a href="#"
+			>W</a
+			></div
+		      ></div
 		    ></td
 		  ></tr
 		><tr
 		><td class="src clearfix"
 		  ><span class="inst-left"
-		    ><span class="keyword"
+		    ><span id="control.i:if:Foo:Foo:2" class="instance expander" onclick="toggleSection('i:if:Foo:Foo:2')"
+		      ></span
+		      > <span class="keyword"
 		      >type</span
-		      > <a href=""
+		      > <a href="#"
 		      >Foo</a
-		      > <a href=""
+		      > <a href="#"
 		      >X</a
-		      > = <a href=""
-		      >Y</a
 		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
 		    ></td
-		  ><td class="doc"
-		  ><p
-		    >External instance</p
+		  ><td class="doc empty"
+		  ></td
+		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:if:Foo:Foo:2" class="inst-details hide"
+		    ><div class="src"
+		      ><span class="keyword"
+			>type</span
+			> <a href="#"
+			>Foo</a
+			> <a href="#"
+			>X</a
+			> = <a href="#"
+			>Y</a
+			></div
+		      ></div
 		    ></td
 		  ></tr
 		></table
@@ -180,9 +251,11 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >data family</span
-	    > <a name="t:Bar" class="def"
+	    > <a id="t:Bar" class="def"
 	    >Bar</a
-	    > a</p
+	    > a <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ><div class="doc"
 	  ><p
 	    >Exported data family</p
@@ -195,15 +268,17 @@
 	      ><tr
 		><td class="src clearfix"
 		  ><span class="inst-left"
-		    ><span class="keyword"
+		    ><span id="control.i:if:Bar:Bar:1" class="instance expander" onclick="toggleSection('i:if:Bar:Bar:1')"
+		      ></span
+		      > <span class="keyword"
 		      >data</span
-		      > <a href=""
+		      > <a href="#"
 		      >Bar</a
-		      > <a href=""
+		      > <a href="#"
 		      >W</a
-		      > = <a name="v:BarX" class="def"
-		      >BarX</a
-		      > Z</span
+		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
 		    ></td
 		  ><td class="doc"
 		  ><p
@@ -211,19 +286,53 @@
 		    ></td
 		  ></tr
 		><tr
+		><td colspan="2"
+		  ><div id="section.i:if:Bar:Bar:1" class="inst-details hide"
+		    ><div class="src"
+		      ><span class="keyword"
+			>data</span
+			> <a href="#"
+			>Bar</a
+			> <a href="#"
+			>W</a
+			> = <a id="v:BarX" class="def"
+			>BarX</a
+			> Z</div
+		      ></div
+		    ></td
+		  ></tr
+		><tr
 		><td class="src clearfix"
 		  ><span class="inst-left"
-		    ><span class="keyword"
+		    ><span id="control.i:if:Bar:Bar:2" class="instance expander" onclick="toggleSection('i:if:Bar:Bar:2')"
+		      ></span
+		      > <span class="keyword"
 		      >data</span
-		      > <a href=""
+		      > <a href="#"
 		      >Bar</a
-		      > <a href=""
+		      > <a href="#"
 		      >Y</a
 		      ></span
+		    > <a href="#" class="selflink"
+		    >#</a
 		    ></td
 		  ><td class="doc empty"
-		  >&nbsp;</td
+		  ></td
 		  ></tr
+		><tr
+		><td colspan="2"
+		  ><div id="section.i:if:Bar:Bar:2" class="inst-details hide"
+		    ><div class="src"
+		      ><span class="keyword"
+			>data</span
+			> <a href="#"
+			>Bar</a
+			> <a href="#"
+			>Y</a
+			></div
+		      ></div
+		    ></td
+		  ></tr
 		></table
 	      ></div
 	    ></div
@@ -231,11 +340,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.16.1</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/TypeOperators.html b/html-test/ref/TypeOperators.html
--- a/html-test/ref/TypeOperators.html
+++ b/html-test/ref/TypeOperators.html
@@ -1,32 +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
     >TypeOperators</title
-    ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_TypeOperators.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_TypeOperators.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -48,60 +49,68 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >data</span
-	    > a <a name="t::-45-:" class="def"
+	    > a <a id="t::-45-:" class="def"
 	    >:-:</a
-	    > b</p
+	    > b <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ></div
 	><div class="top"
 	><p class="src"
 	  ><span class="keyword"
 	    >data</span
-	    > (a <a name="t::-43-:" class="def"
+	    > (a <a id="t::-43-:" class="def"
 	    >:+:</a
-	    > b) c</p
+	    > b) c <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ></div
 	><div class="top"
 	><p class="src"
 	  ><span class="keyword"
 	    >data</span
-	    > <a name="t:Op" class="def"
+	    > <a id="t:Op" class="def"
 	    >Op</a
-	    > a b</p
+	    > a b <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ></div
 	><div class="top"
 	><p class="src"
 	  ><span class="keyword"
 	    >newtype</span
-	    > <a name="t:O" class="def"
+	    > <a id="t:O" class="def"
 	    >O</a
-	    > g f a</p
+	    > g f a <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ><div class="subs constructors"
 	  ><p class="caption"
 	    >Constructors</p
 	    ><table
 	    ><tr
 	      ><td class="src"
-		><a name="v:O" class="def"
+		><a id="v:O" class="def"
 		  >O</a
 		  ></td
 		><td class="doc empty"
-		>&nbsp;</td
+		></td
 		></tr
 	      ><tr
 	      ><td colspan="2"
 		><div class="subs fields"
 		  ><p class="caption"
 		    >Fields</p
-		    ><dl
-		    ><dt class="src"
-		      ><a name="v:unO" class="def"
-			>unO</a
-			> :: g (f a)</dt
-		      ><dd class="doc empty"
-		      >&nbsp;</dd
-		      ></dl
-		    ><div class="clear"
-		    ></div
+		    ><ul
+		    ><li
+		      ><dfn class="src"
+			><a id="v:unO" class="def"
+			  >unO</a
+			  > :: g (f a)</dfn
+			><div class="doc empty"
+			></div
+			></li
+		      ></ul
 		    ></div
 		  ></td
 		></tr
@@ -112,62 +121,70 @@
 	><p class="src"
 	  ><span class="keyword"
 	    >class</span
-	    > a <a name="t:-60--61--62-" class="def"
+	    > a <a id="t:-60--61--62-" class="def"
 	    >&lt;=&gt;</a
-	    > b</p
+	    > b <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ></div
 	><div class="top"
 	><p class="src"
-	  ><a name="v:biO" class="def"
+	  ><a id="v:biO" class="def"
 	    >biO</a
-	    > :: (g <a href=""
+	    > :: (g <a href="#"
 	    >`O`</a
-	    > f) a</p
+	    > f) a <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ></div
 	><div class="top"
 	><p class="src"
-	  ><a name="v:f" class="def"
+	  ><a id="v:f" class="def"
 	    >f</a
-	    > :: (a ~ b) =&gt; a -&gt; b</p
+	    > :: a ~ b =&gt; a -&gt; b <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ></div
 	><div class="top"
 	><p class="src"
-	  ><a name="v:g" class="def"
+	  ><a id="v:g" class="def"
 	    >g</a
-	    > :: (a ~ b, b ~ c) =&gt; a -&gt; c</p
+	    > :: (a ~ b, b ~ c) =&gt; a -&gt; c <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ></div
 	><div class="top"
 	><p class="src"
-	  ><a name="v:x" class="def"
+	  ><a id="v:x" class="def"
 	    >x</a
-	    > :: (a <a href=""
+	    > :: (a <a href="#"
 	    >:-:</a
-	    > a) <a href=""
+	    > a) <a href="#"
 	    >&lt;=&gt;</a
-	    > (a <a href=""
+	    > (a <a href="#"
 	    >`Op`</a
-	    > a) =&gt; a</p
+	    > a) =&gt; a <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ></div
 	><div class="top"
 	><p class="src"
-	  ><a name="v:y" class="def"
+	  ><a id="v:y" class="def"
 	    >y</a
-	    > :: (a <a href=""
+	    > :: (a <a href="#"
 	    >&lt;=&gt;</a
-	    > a, (a <a href=""
+	    > a, (a <a href="#"
 	    >`Op`</a
-	    > a) <a href=""
+	    > a) <a href="#"
 	    >&lt;=&gt;</a
-	    > a) =&gt; a</p
+	    > a) =&gt; a <a href="#" class="selflink"
+	    >#</a
+	    ></p
 	  ></div
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.15.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/Unicode.html b/html-test/ref/Unicode.html
--- a/html-test/ref/Unicode.html
+++ b/html-test/ref/Unicode.html
@@ -1,32 +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"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_Unicode.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_Unicode.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -46,9 +47,9 @@
 	>Synopsis</p
 	><ul id="section.syn" class="hide" onclick="toggleSection('syn')"
 	><li class="src short"
-	  ><a href=""
+	  ><a href="#"
 	    >x</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
 	    ></li
 	  ></ul
@@ -58,10 +59,12 @@
 	>Documentation</h1
 	><div class="top"
 	><p class="src"
-	  ><a name="v:x" class="def"
+	  ><a id="v:x" class="def"
 	    >x</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ><div class="doc"
 	  ><p
@@ -71,11 +74,7 @@
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.15.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/Visible.html b/html-test/ref/Visible.html
--- a/html-test/ref/Visible.html
+++ b/html-test/ref/Visible.html
@@ -1,32 +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"
+    ><link href="#" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
-    >//<![CDATA[
-window.onload = function () {pageLoad();setSynopsis("mini_Visible.html");};
-//]]>
+    >//
+window.onload = function () {pageLoad();setSynopsis(&quot;mini_Visible.html&quot;);};
+//
 </script
     ></head
   ><body
   ><div id="package-header"
     ><ul class="links" id="page-menu"
       ><li
-	><a href=""
+	><a href="#"
 	  >Contents</a
 	  ></li
 	><li
-	><a href=""
+	><a href="#"
 	  >Index</a
 	  ></li
 	></ul
       ><p class="caption empty"
-      >&nbsp;</p
+      ></p
       ></div
     ><div id="content"
     ><div id="module-header"
@@ -46,22 +47,20 @@
 	>Documentation</h1
 	><div class="top"
 	><p class="src"
-	  ><a name="v:visible" class="def"
+	  ><a id="v:visible" class="def"
 	    >visible</a
-	    > :: <a href=""
+	    > :: <a href="#"
 	    >Int</a
-	    > -&gt; <a href=""
+	    > -&gt; <a href="#"
 	    >Int</a
+	    > <a href="#" class="selflink"
+	    >#</a
 	    ></p
 	  ></div
 	></div
       ></div
     ><div id="footer"
-    ><p
-      >Produced by <a href=""
-	>Haddock</a
-	> version 2.15.0</p
-      ></div
+    ></div
     ></body
   ></html
 >
diff --git a/html-test/ref/frames.html b/html-test/ref/frames.html
--- a/html-test/ref/frames.html
+++ b/html-test/ref/frames.html
@@ -1,4 +1,4 @@
-<!DOCTYPE html 
+<!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">
diff --git a/html-test/ref/mini_A.html b/html-test/ref/mini_A.html
--- a/html-test/ref/mini_A.html
+++ b/html-test/ref/mini_A.html
@@ -7,6 +7,8 @@
     ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
     >//<![CDATA[
 window.onload = function () {pageLoad();};
diff --git a/html-test/ref/mini_AdvanceTypes.html b/html-test/ref/mini_AdvanceTypes.html
--- a/html-test/ref/mini_AdvanceTypes.html
+++ b/html-test/ref/mini_AdvanceTypes.html
@@ -7,6 +7,8 @@
     ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
     >//<![CDATA[
 window.onload = function () {pageLoad();};
diff --git a/html-test/ref/mini_B.html b/html-test/ref/mini_B.html
--- a/html-test/ref/mini_B.html
+++ b/html-test/ref/mini_B.html
@@ -7,6 +7,8 @@
     ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
     >//<![CDATA[
 window.onload = function () {pageLoad();};
diff --git a/html-test/ref/mini_Bug1.html b/html-test/ref/mini_Bug1.html
--- a/html-test/ref/mini_Bug1.html
+++ b/html-test/ref/mini_Bug1.html
@@ -7,6 +7,8 @@
     ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
     >//<![CDATA[
 window.onload = function () {pageLoad();};
diff --git a/html-test/ref/mini_Bug2.html b/html-test/ref/mini_Bug2.html
--- a/html-test/ref/mini_Bug2.html
+++ b/html-test/ref/mini_Bug2.html
@@ -7,6 +7,8 @@
     ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
     >//<![CDATA[
 window.onload = function () {pageLoad();};
diff --git a/html-test/ref/mini_Bug3.html b/html-test/ref/mini_Bug3.html
--- a/html-test/ref/mini_Bug3.html
+++ b/html-test/ref/mini_Bug3.html
@@ -7,6 +7,8 @@
     ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
     >//<![CDATA[
 window.onload = function () {pageLoad();};
diff --git a/html-test/ref/mini_Bug4.html b/html-test/ref/mini_Bug4.html
--- a/html-test/ref/mini_Bug4.html
+++ b/html-test/ref/mini_Bug4.html
@@ -7,6 +7,8 @@
     ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
     >//<![CDATA[
 window.onload = function () {pageLoad();};
diff --git a/html-test/ref/mini_Bug6.html b/html-test/ref/mini_Bug6.html
--- a/html-test/ref/mini_Bug6.html
+++ b/html-test/ref/mini_Bug6.html
@@ -7,6 +7,8 @@
     ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
     >//<![CDATA[
 window.onload = function () {pageLoad();};
diff --git a/html-test/ref/mini_Bug7.html b/html-test/ref/mini_Bug7.html
--- a/html-test/ref/mini_Bug7.html
+++ b/html-test/ref/mini_Bug7.html
@@ -7,6 +7,8 @@
     ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
     >//<![CDATA[
 window.onload = function () {pageLoad();};
diff --git a/html-test/ref/mini_Bug8.html b/html-test/ref/mini_Bug8.html
--- a/html-test/ref/mini_Bug8.html
+++ b/html-test/ref/mini_Bug8.html
@@ -7,6 +7,8 @@
     ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
     >//<![CDATA[
 window.onload = function () {pageLoad();};
diff --git a/html-test/ref/mini_BugDeprecated.html b/html-test/ref/mini_BugDeprecated.html
--- a/html-test/ref/mini_BugDeprecated.html
+++ b/html-test/ref/mini_BugDeprecated.html
@@ -7,6 +7,8 @@
     ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
     >//<![CDATA[
 window.onload = function () {pageLoad();};
diff --git a/html-test/ref/mini_BugExportHeadings.html b/html-test/ref/mini_BugExportHeadings.html
--- a/html-test/ref/mini_BugExportHeadings.html
+++ b/html-test/ref/mini_BugExportHeadings.html
@@ -7,6 +7,8 @@
     ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
     >//<![CDATA[
 window.onload = function () {pageLoad();};
diff --git a/html-test/ref/mini_Bugs.html b/html-test/ref/mini_Bugs.html
--- a/html-test/ref/mini_Bugs.html
+++ b/html-test/ref/mini_Bugs.html
@@ -7,6 +7,8 @@
     ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
     >//<![CDATA[
 window.onload = function () {pageLoad();};
diff --git a/html-test/ref/mini_DeprecatedClass.html b/html-test/ref/mini_DeprecatedClass.html
--- a/html-test/ref/mini_DeprecatedClass.html
+++ b/html-test/ref/mini_DeprecatedClass.html
@@ -7,6 +7,8 @@
     ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
     >//<![CDATA[
 window.onload = function () {pageLoad();};
diff --git a/html-test/ref/mini_DeprecatedData.html b/html-test/ref/mini_DeprecatedData.html
--- a/html-test/ref/mini_DeprecatedData.html
+++ b/html-test/ref/mini_DeprecatedData.html
@@ -7,6 +7,8 @@
     ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
     >//<![CDATA[
 window.onload = function () {pageLoad();};
diff --git a/html-test/ref/mini_DeprecatedFunction.html b/html-test/ref/mini_DeprecatedFunction.html
--- a/html-test/ref/mini_DeprecatedFunction.html
+++ b/html-test/ref/mini_DeprecatedFunction.html
@@ -7,6 +7,8 @@
     ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
     >//<![CDATA[
 window.onload = function () {pageLoad();};
diff --git a/html-test/ref/mini_DeprecatedFunction2.html b/html-test/ref/mini_DeprecatedFunction2.html
--- a/html-test/ref/mini_DeprecatedFunction2.html
+++ b/html-test/ref/mini_DeprecatedFunction2.html
@@ -7,6 +7,8 @@
     ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
     >//<![CDATA[
 window.onload = function () {pageLoad();};
diff --git a/html-test/ref/mini_DeprecatedFunction3.html b/html-test/ref/mini_DeprecatedFunction3.html
--- a/html-test/ref/mini_DeprecatedFunction3.html
+++ b/html-test/ref/mini_DeprecatedFunction3.html
@@ -7,6 +7,8 @@
     ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
     >//<![CDATA[
 window.onload = function () {pageLoad();};
diff --git a/html-test/ref/mini_DeprecatedModule.html b/html-test/ref/mini_DeprecatedModule.html
--- a/html-test/ref/mini_DeprecatedModule.html
+++ b/html-test/ref/mini_DeprecatedModule.html
@@ -7,6 +7,8 @@
     ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
     >//<![CDATA[
 window.onload = function () {pageLoad();};
diff --git a/html-test/ref/mini_DeprecatedModule2.html b/html-test/ref/mini_DeprecatedModule2.html
--- a/html-test/ref/mini_DeprecatedModule2.html
+++ b/html-test/ref/mini_DeprecatedModule2.html
@@ -7,6 +7,8 @@
     ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
     >//<![CDATA[
 window.onload = function () {pageLoad();};
diff --git a/html-test/ref/mini_DeprecatedNewtype.html b/html-test/ref/mini_DeprecatedNewtype.html
--- a/html-test/ref/mini_DeprecatedNewtype.html
+++ b/html-test/ref/mini_DeprecatedNewtype.html
@@ -7,6 +7,8 @@
     ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
     >//<![CDATA[
 window.onload = function () {pageLoad();};
diff --git a/html-test/ref/mini_DeprecatedReExport.html b/html-test/ref/mini_DeprecatedReExport.html
--- a/html-test/ref/mini_DeprecatedReExport.html
+++ b/html-test/ref/mini_DeprecatedReExport.html
@@ -7,6 +7,8 @@
     ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
     >//<![CDATA[
 window.onload = function () {pageLoad();};
diff --git a/html-test/ref/mini_DeprecatedRecord.html b/html-test/ref/mini_DeprecatedRecord.html
--- a/html-test/ref/mini_DeprecatedRecord.html
+++ b/html-test/ref/mini_DeprecatedRecord.html
@@ -7,6 +7,8 @@
     ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
     >//<![CDATA[
 window.onload = function () {pageLoad();};
diff --git a/html-test/ref/mini_DeprecatedTypeFamily.html b/html-test/ref/mini_DeprecatedTypeFamily.html
--- a/html-test/ref/mini_DeprecatedTypeFamily.html
+++ b/html-test/ref/mini_DeprecatedTypeFamily.html
@@ -7,6 +7,8 @@
     ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
     >//<![CDATA[
 window.onload = function () {pageLoad();};
diff --git a/html-test/ref/mini_DeprecatedTypeSynonym.html b/html-test/ref/mini_DeprecatedTypeSynonym.html
--- a/html-test/ref/mini_DeprecatedTypeSynonym.html
+++ b/html-test/ref/mini_DeprecatedTypeSynonym.html
@@ -7,6 +7,8 @@
     ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
     >//<![CDATA[
 window.onload = function () {pageLoad();};
diff --git a/html-test/ref/mini_Examples.html b/html-test/ref/mini_Examples.html
--- a/html-test/ref/mini_Examples.html
+++ b/html-test/ref/mini_Examples.html
@@ -7,6 +7,8 @@
     ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
     >//<![CDATA[
 window.onload = function () {pageLoad();};
diff --git a/html-test/ref/mini_FunArgs.html b/html-test/ref/mini_FunArgs.html
--- a/html-test/ref/mini_FunArgs.html
+++ b/html-test/ref/mini_FunArgs.html
@@ -7,6 +7,8 @@
     ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
     >//<![CDATA[
 window.onload = function () {pageLoad();};
@@ -29,6 +31,24 @@
       ><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
diff --git a/html-test/ref/mini_GADTRecords.html b/html-test/ref/mini_GADTRecords.html
--- a/html-test/ref/mini_GADTRecords.html
+++ b/html-test/ref/mini_GADTRecords.html
@@ -7,6 +7,8 @@
     ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
     >//<![CDATA[
 window.onload = function () {pageLoad();};
diff --git a/html-test/ref/mini_Hash.html b/html-test/ref/mini_Hash.html
--- a/html-test/ref/mini_Hash.html
+++ b/html-test/ref/mini_Hash.html
@@ -7,6 +7,8 @@
     ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
     >//<![CDATA[
 window.onload = function () {pageLoad();};
diff --git a/html-test/ref/mini_HiddenInstances.html b/html-test/ref/mini_HiddenInstances.html
--- a/html-test/ref/mini_HiddenInstances.html
+++ b/html-test/ref/mini_HiddenInstances.html
@@ -7,6 +7,8 @@
     ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
     >//<![CDATA[
 window.onload = function () {pageLoad();};
diff --git a/html-test/ref/mini_HiddenInstancesB.html b/html-test/ref/mini_HiddenInstancesB.html
--- a/html-test/ref/mini_HiddenInstancesB.html
+++ b/html-test/ref/mini_HiddenInstancesB.html
@@ -7,6 +7,8 @@
     ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
     >//<![CDATA[
 window.onload = function () {pageLoad();};
diff --git a/html-test/ref/mini_Hyperlinks.html b/html-test/ref/mini_Hyperlinks.html
--- a/html-test/ref/mini_Hyperlinks.html
+++ b/html-test/ref/mini_Hyperlinks.html
@@ -7,6 +7,8 @@
     ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
     >//<![CDATA[
 window.onload = function () {pageLoad();};
diff --git a/html-test/ref/mini_IgnoreExports.html b/html-test/ref/mini_IgnoreExports.html
--- a/html-test/ref/mini_IgnoreExports.html
+++ b/html-test/ref/mini_IgnoreExports.html
@@ -7,6 +7,8 @@
     ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
     >//<![CDATA[
 window.onload = function () {pageLoad();};
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://cdn.mathjax.org/mathjax/latest/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
--- a/html-test/ref/mini_ModuleWithWarning.html
+++ b/html-test/ref/mini_ModuleWithWarning.html
@@ -7,6 +7,8 @@
     ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
     >//<![CDATA[
 window.onload = function () {pageLoad();};
diff --git a/html-test/ref/mini_NamedDoc.html b/html-test/ref/mini_NamedDoc.html
--- a/html-test/ref/mini_NamedDoc.html
+++ b/html-test/ref/mini_NamedDoc.html
@@ -7,6 +7,8 @@
     ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
     >//<![CDATA[
 window.onload = function () {pageLoad();};
diff --git a/html-test/ref/mini_NoLayout.html b/html-test/ref/mini_NoLayout.html
--- a/html-test/ref/mini_NoLayout.html
+++ b/html-test/ref/mini_NoLayout.html
@@ -7,6 +7,8 @@
     ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
     >//<![CDATA[
 window.onload = function () {pageLoad();};
diff --git a/html-test/ref/mini_NonGreedy.html b/html-test/ref/mini_NonGreedy.html
--- a/html-test/ref/mini_NonGreedy.html
+++ b/html-test/ref/mini_NonGreedy.html
@@ -7,6 +7,8 @@
     ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
     >//<![CDATA[
 window.onload = function () {pageLoad();};
diff --git a/html-test/ref/mini_Properties.html b/html-test/ref/mini_Properties.html
--- a/html-test/ref/mini_Properties.html
+++ b/html-test/ref/mini_Properties.html
@@ -7,6 +7,8 @@
     ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
     >//<![CDATA[
 window.onload = function () {pageLoad();};
diff --git a/html-test/ref/mini_PruneWithWarning.html b/html-test/ref/mini_PruneWithWarning.html
--- a/html-test/ref/mini_PruneWithWarning.html
+++ b/html-test/ref/mini_PruneWithWarning.html
@@ -7,6 +7,8 @@
     ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
     >//<![CDATA[
 window.onload = function () {pageLoad();};
diff --git a/html-test/ref/mini_QuasiExpr.html b/html-test/ref/mini_QuasiExpr.html
--- a/html-test/ref/mini_QuasiExpr.html
+++ b/html-test/ref/mini_QuasiExpr.html
@@ -7,6 +7,8 @@
     ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
     >//<![CDATA[
 window.onload = function () {pageLoad();};
diff --git a/html-test/ref/mini_QuasiQuote.html b/html-test/ref/mini_QuasiQuote.html
--- a/html-test/ref/mini_QuasiQuote.html
+++ b/html-test/ref/mini_QuasiQuote.html
@@ -7,6 +7,8 @@
     ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
     >//<![CDATA[
 window.onload = function () {pageLoad();};
diff --git a/html-test/ref/mini_SpuriousSuperclassConstraints.html b/html-test/ref/mini_SpuriousSuperclassConstraints.html
--- a/html-test/ref/mini_SpuriousSuperclassConstraints.html
+++ b/html-test/ref/mini_SpuriousSuperclassConstraints.html
@@ -7,6 +7,8 @@
     ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
     >//<![CDATA[
 window.onload = function () {pageLoad();};
diff --git a/html-test/ref/mini_TH.html b/html-test/ref/mini_TH.html
--- a/html-test/ref/mini_TH.html
+++ b/html-test/ref/mini_TH.html
@@ -7,6 +7,8 @@
     ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
     >//<![CDATA[
 window.onload = function () {pageLoad();};
diff --git a/html-test/ref/mini_TH2.html b/html-test/ref/mini_TH2.html
--- a/html-test/ref/mini_TH2.html
+++ b/html-test/ref/mini_TH2.html
@@ -7,6 +7,8 @@
     ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
     >//<![CDATA[
 window.onload = function () {pageLoad();};
diff --git a/html-test/ref/mini_Test.html b/html-test/ref/mini_Test.html
--- a/html-test/ref/mini_Test.html
+++ b/html-test/ref/mini_Test.html
@@ -7,6 +7,8 @@
     ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
     >//<![CDATA[
 window.onload = function () {pageLoad();};
diff --git a/html-test/ref/mini_Ticket112.html b/html-test/ref/mini_Ticket112.html
--- a/html-test/ref/mini_Ticket112.html
+++ b/html-test/ref/mini_Ticket112.html
@@ -7,6 +7,8 @@
     ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
     >//<![CDATA[
 window.onload = function () {pageLoad();};
diff --git a/html-test/ref/mini_Ticket61.html b/html-test/ref/mini_Ticket61.html
--- a/html-test/ref/mini_Ticket61.html
+++ b/html-test/ref/mini_Ticket61.html
@@ -7,6 +7,8 @@
     ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
     >//<![CDATA[
 window.onload = function () {pageLoad();};
diff --git a/html-test/ref/mini_Ticket75.html b/html-test/ref/mini_Ticket75.html
--- a/html-test/ref/mini_Ticket75.html
+++ b/html-test/ref/mini_Ticket75.html
@@ -7,6 +7,8 @@
     ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
     >//<![CDATA[
 window.onload = function () {pageLoad();};
diff --git a/html-test/ref/mini_TitledPicture.html b/html-test/ref/mini_TitledPicture.html
--- a/html-test/ref/mini_TitledPicture.html
+++ b/html-test/ref/mini_TitledPicture.html
@@ -7,6 +7,8 @@
     ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
     >//<![CDATA[
 window.onload = function () {pageLoad();};
diff --git a/html-test/ref/mini_TypeFamilies.html b/html-test/ref/mini_TypeFamilies.html
--- a/html-test/ref/mini_TypeFamilies.html
+++ b/html-test/ref/mini_TypeFamilies.html
@@ -7,6 +7,8 @@
     ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
     >//<![CDATA[
 window.onload = function () {pageLoad();};
diff --git a/html-test/ref/mini_TypeOperators.html b/html-test/ref/mini_TypeOperators.html
--- a/html-test/ref/mini_TypeOperators.html
+++ b/html-test/ref/mini_TypeOperators.html
@@ -7,6 +7,8 @@
     ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
     >//<![CDATA[
 window.onload = function () {pageLoad();};
diff --git a/html-test/ref/mini_Unicode.html b/html-test/ref/mini_Unicode.html
--- a/html-test/ref/mini_Unicode.html
+++ b/html-test/ref/mini_Unicode.html
@@ -7,6 +7,8 @@
     ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
     >//<![CDATA[
 window.onload = function () {pageLoad();};
diff --git a/html-test/ref/mini_Visible.html b/html-test/ref/mini_Visible.html
--- a/html-test/ref/mini_Visible.html
+++ b/html-test/ref/mini_Visible.html
@@ -7,6 +7,8 @@
     ><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean"
      /><script src="haddock-util.js" type="text/javascript"
     ></script
+    ><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"
+    ></script
     ><script type="text/javascript"
     >//<![CDATA[
 window.onload = function () {pageLoad();};
diff --git a/html-test/run.lhs b/html-test/run.lhs
deleted file mode 100644
--- a/html-test/run.lhs
+++ /dev/null
@@ -1,191 +0,0 @@
-#!/usr/bin/env runhaskell
-\begin{code}
-{-# LANGUAGE CPP #-}
-import Prelude hiding (mod)
-import Control.Monad
-import Control.Applicative
-import Data.List
-import Data.Maybe
-import Distribution.InstalledPackageInfo
-import Distribution.Package (PackageName (..))
-import Distribution.Simple.Compiler
-import Distribution.Simple.GHC
-import Distribution.Simple.PackageIndex
-import Distribution.Simple.Program
-import Distribution.Simple.Utils
-import Distribution.Verbosity
-import System.IO
-import System.Directory
-import System.Environment
-import System.Exit
-import System.FilePath
-import System.Process (ProcessHandle, runProcess, waitForProcess, system)
-
-packageRoot, dataDir, haddockPath, baseDir, testDir, outDir :: FilePath
-baseDir = takeDirectory __FILE__
-testDir       = baseDir </> "src"
-refDir        = baseDir </> "ref"
-outDir        = baseDir </> "out"
-packageRoot   = baseDir </> ".."
-dataDir       = packageRoot </> "resources"
-haddockPath   = packageRoot </> "dist" </> "build" </> "haddock" </> "haddock"
-
-
-main :: IO ()
-main = do
-  test
-  putStrLn "All tests passed!"
-
-
-test :: IO ()
-test = do
-  x <- doesFileExist haddockPath
-  unless x $ System.Exit.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
-          y:_ | y /= "all" -> [y ++ ".hs"]
-          _ -> filter ((==) ".hs" . takeExtension) contents
-
-  let mods' = map (testDir </>) mods
-
-  -- add haddock_datadir to environment for subprocesses
-  env <- Just . (:) ("haddock_datadir", Main.dataDir) <$> getEnvironment
-
-  putStrLn ""
-  putStrLn "Haddock version: "
-  h1 <- runProcess haddockPath ["--version"] Nothing
-                   env Nothing Nothing Nothing
-  wait h1 "*** Running `haddock --version' failed!"
-  putStrLn ""
-  putStrLn "GHC version: "
-  h2 <- runProcess haddockPath ["--ghc-version"] Nothing
-                   env Nothing Nothing Nothing
-  wait h2 "*** Running `haddock --ghc-version' failed!"
-  putStrLn ""
-
-  -- TODO: maybe do something more clever here using haddock.cabal
-  ghcPath <- fmap init $ rawSystemStdout normal haddockPath ["--print-ghc-path"]
-  (_, _, conf) <- configure normal (Just ghcPath) Nothing defaultProgramConfiguration
-  pkgIndex <- getInstalledPackages normal [GlobalPackageDB] conf
-  let mkDep pkgName =
-        fromMaybe (error "Couldn't find test dependencies") $ do
-          let pkgs = lookupPackageName pkgIndex (PackageName pkgName)
-          (_, pkgs') <- listToMaybe pkgs
-          pkg <- listToMaybe pkgs'
-          ifacePath <- listToMaybe (haddockInterfaces pkg)
-          htmlPath <- listToMaybe (haddockHTMLs pkg)
-          return ("-i " ++ htmlPath ++ "," ++ ifacePath)
-
-  let base    = mkDep "base"
-      process = mkDep "process"
-      ghcprim = mkDep "ghc-prim"
-
-  putStrLn "Running tests..."
-  handle <- runProcess haddockPath
-                       (["-w", "-o", outDir, "-h", "--pretty-html"
-                        , "--optghc=-w", base, process, ghcprim] ++ opts ++ mods')
-                       Nothing env Nothing
-                       Nothing Nothing
-
-  wait handle "*** Haddock run failed! Exiting."
-  check mods (if not (null args) && args !! 0 == "all" then False else True)
-  where
-    wait :: ProcessHandle -> String -> IO ()
-    wait h msg = do
-      r <- waitForProcess h
-      unless (r == ExitSuccess) $ do
-        hPutStrLn stderr msg
-        exitFailure
-
-check :: [FilePath] -> Bool -> IO ()
-check modules strict = do
-  forM_ modules $ \mod -> do
-    let outfile = outDir </> dropExtension mod ++ ".html"
-    let reffile = refDir </> dropExtension mod ++ ".html"
-    b <- doesFileExist reffile
-    if b
-      then do
-        out <- readFile outfile
-        ref <- readFile reffile
-        if not $ haddockEq (outfile, out) (reffile, ref)
-          then do
-            putStrLn $ "Output for " ++ mod ++ " has changed! Exiting with diff:"
-            let ref' = maybeStripLinks outfile ref
-                out' = maybeStripLinks reffile out
-            let reffile' = outDir </> takeFileName reffile ++ ".nolinks"
-                outfile' = outDir </> takeFileName outfile ++ ".ref.nolinks"
-            writeFile reffile' ref'
-            writeFile outfile' out'
-            r <- programOnPath "colordiff"
-            code <- if r
-              then system $ "colordiff " ++ reffile' ++ " " ++ outfile'
-              else system $ "diff " ++ reffile' ++ " " ++ outfile'
-            if strict then exitFailure else return ()
-            unless (code == ExitSuccess) $ do
-              hPutStrLn stderr "*** Running diff failed!"
-              exitFailure
-          else do
-            putStrLn $ "Pass: " ++ mod
-      else do
-        putStrLn $ "Pass: " ++ mod ++ " (no .ref file)"
-
--- | List of modules in which we don't 'stripLinks'
-preserveLinksModules :: [String]
-preserveLinksModules = map (++ ".html") ["Bug253"]
-
--- | A rather nasty way to drop the Haddock version string from the
--- end of the generated HTML files so that we don't have to change
--- every single test every time we change versions. We rely on the the
--- last paragraph of the document to be the version. We end up with
--- malformed HTML but we don't care as we never look at it ourselves.
-dropVersion :: String -> String
-dropVersion = reverse . dropTillP . reverse
-  where
-    dropTillP [] = []
-    dropTillP ('p':'<':xs) = xs
-    dropTillP (_:xs) = dropTillP xs
-
-haddockEq :: (FilePath, String) -> (FilePath, String) -> Bool
-haddockEq (fn1, file1) (fn2, file2) =
-  maybeStripLinks fn1 (dropVersion file1)
-  == maybeStripLinks fn2 (dropVersion file2)
-
-maybeStripLinks :: String -- ^ Module we're considering for stripping
-                -> String -> String
-maybeStripLinks m = if any (`isSuffixOf` m) preserveLinksModules
-                    then id
-                    else stripLinks
-
-stripLinks :: String -> String
-stripLinks str =
-  let prefix = "<a href=\"" in
-  case stripPrefix prefix str of
-    Just str' -> case dropWhile (/= '>') (dropWhile (/= '"') str') of
-      [] -> []
-      x:xs -> stripLinks (stripHrefEnd xs)
-    Nothing ->
-      case str of
-        [] -> []
-        x : xs -> x : stripLinks xs
-
-stripHrefEnd :: String -> String
-stripHrefEnd s =
-  let pref = "</a" in
-  case stripPrefix pref s of
-    Just str' -> case dropWhile (/= '>') str' of
-      [] -> []
-      x:xs -> xs
-    Nothing ->
-      case s of
-        [] -> []
-        x : xs -> x : stripHrefEnd xs
-
-programOnPath :: FilePath -> IO Bool
-programOnPath p = do
-  result <- findProgramLocation silent p
-  return (isJust result)
-\end{code}
diff --git a/html-test/src/AdvanceTypes.hs b/html-test/src/AdvanceTypes.hs
deleted file mode 100644
--- a/html-test/src/AdvanceTypes.hs
+++ /dev/null
@@ -1,9 +0,0 @@
-{-# LANGUAGE DataKinds #-}
-{-# LANGUAGE GADTs #-}
-{-# LANGUAGE KindSignatures #-}
-{-# LANGUAGE TypeOperators #-}
-module AdvanceTypes where
-
-data Pattern :: [*] -> * where
-  Nil :: Pattern '[]
-  Cons :: Maybe h -> Pattern t -> Pattern (h ': t)
diff --git a/html-test/src/Bugs.hs b/html-test/src/Bugs.hs
--- a/html-test/src/Bugs.hs
+++ b/html-test/src/Bugs.hs
@@ -1,3 +1,3 @@
 module Bugs where
 
-data A a = A a (a -> Int) 
+data A a = A a (a -> Int)
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,99 @@
+{-# 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/Math.hs b/html-test/src/Math.hs
new file mode 100644
--- /dev/null
+++ b/html-test/src/Math.hs
@@ -0,0 +1,14 @@
+-- | 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/Operators.hs b/html-test/src/Operators.hs
--- a/html-test/src/Operators.hs
+++ b/html-test/src/Operators.hs
@@ -1,4 +1,6 @@
 {-# LANGUAGE PatternSynonyms, TypeOperators, TypeFamilies, MultiParamTypeClasses, GADTs #-}
+{-# LANGUAGE FunctionalDependencies #-}
+
 -- | Test operators with or without fixity declarations
 module Operators where
 
@@ -42,7 +44,9 @@
 infix 9 **
 
 -- | Class with fixity, including associated types
-class a ><> b where
+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 -> ()
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,8 @@
+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,4 @@
+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,3 @@
+module OrphanInstancesType (AType(..)) where
+
+data AType = AType Int
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,25 @@
+{-# 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/hypsrc-test/Main.hs b/hypsrc-test/Main.hs
new file mode 100644
--- /dev/null
+++ b/hypsrc-test/Main.hs
@@ -0,0 +1,52 @@
+{-# LANGUAGE CPP #-}
+
+
+import Data.Char
+import Data.List
+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' . stripFooter
+    stripLinks' = stripLinksWhen $ \href -> "#local-" `isPrefixOf` href
+    stripAnchors' = stripAnchorsWhen $ \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/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,1044 @@
+<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-keyword"
+      >module</span
+      ><span
+      > </span
+      ><span class="hs-identifier"
+      >Classes</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >where</span
+      ><span
+      >
+</span
+      ><a name="line-2"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-3"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-4"
+      ></a
+      ><span class="hs-keyword"
+      >class</span
+      ><span
+      > </span
+      ><a name="Foo"
+      ><a href="Classes.html#Foo"
+	><span class="hs-identifier"
+	  >Foo</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >a</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >where</span
+      ><span
+      >
+</span
+      ><a name="line-5"
+      ></a
+      ><span
+      >    </span
+      ><span class="hs-identifier"
+      >bar</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-type"
+      >Int</span
+      ><span
+      >
+</span
+      ><a name="line-6"
+      ></a
+      ><span
+      >    </span
+      ><span class="hs-identifier"
+      >baz</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-type"
+      >Int</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span
+      >
+</span
+      ><a name="line-7"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-8"
+      ></a
+      ><span class="hs-keyword"
+      >instance</span
+      ><span
+      > </span
+      ><a href="Classes.html#Foo"
+      ><span class="hs-identifier hs-type"
+	>Foo</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-identifier hs-type"
+      >Int</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >where</span
+      ><span
+      >
+</span
+      ><a name="line-9"
+      ></a
+      ><span
+      >    </span
+      ><a name=""
+      ><a href="Classes.html#bar"
+	><span class="hs-identifier"
+	  >bar</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-var"
+      >id</span
+      ><span
+      >
+</span
+      ><a name="line-10"
+      ></a
+      ><span
+      >    </span
+      ><a name=""
+      ><a href="Classes.html#baz"
+	><span class="hs-identifier"
+	  >baz</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >x</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>x</span
+	></a
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>x</span
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span
+      >
+</span
+      ><a name="line-11"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-12"
+      ></a
+      ><span class="hs-keyword"
+      >instance</span
+      ><span
+      > </span
+      ><a href="Classes.html#Foo"
+      ><span class="hs-identifier hs-type"
+	>Foo</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-special"
+      >[</span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span class="hs-special"
+      >]</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >where</span
+      ><span
+      >
+</span
+      ><a name="line-13"
+      ></a
+      ><span
+      >    </span
+      ><a name=""
+      ><a href="Classes.html#bar"
+	><span class="hs-identifier"
+	  >bar</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-var"
+      >length</span
+      ><span
+      >
+</span
+      ><a name="line-14"
+      ></a
+      ><span
+      >    </span
+      ><a name=""
+      ><a href="Classes.html#baz"
+	><span class="hs-identifier"
+	  >baz</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-identifier"
+      >_</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
+      ><a name="line-15"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-16"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-17"
+      ></a
+      ><span class="hs-keyword"
+      >class</span
+      ><span
+      > </span
+      ><a href="Classes.html#Foo"
+      ><span class="hs-identifier hs-type"
+	>Foo</span
+	></a
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=&gt;</span
+      ><span
+      > </span
+      ><a name="Foo%27"
+      ><a href="Classes.html#Foo%27"
+	><span class="hs-identifier"
+	  >Foo'</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >a</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >where</span
+      ><span
+      >
+</span
+      ><a name="line-18"
+      ></a
+      ><span
+      >    </span
+      ><span class="hs-identifier"
+      >quux</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-19"
+      ></a
+      ><span
+      >    </span
+      ><a name=""
+      ><a href="Classes.html#quux"
+	><span class="hs-identifier"
+	  >quux</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >x</span
+	  ></a
+	></a
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >y</span
+	  ></a
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><a href="Classes.html#norf"
+      ><span class="hs-identifier hs-var"
+	>norf</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-special"
+      >[</span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>x</span
+	></a
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>y</span
+	></a
+      ><span class="hs-special"
+      >]</span
+      ><span
+      >
+</span
+      ><a name="line-20"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-21"
+      ></a
+      ><span
+      >    </span
+      ><span class="hs-identifier"
+      >norf</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >[</span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span class="hs-special"
+      >]</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-22"
+      ></a
+      ><span
+      >    </span
+      ><a name=""
+      ><a href="Classes.html#norf"
+	><span class="hs-identifier"
+	  >norf</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><a href="Classes.html#quux"
+      ><span class="hs-identifier hs-var"
+	>quux</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-operator hs-var"
+      >.</span
+      ><span
+      > </span
+      ><a href="Classes.html#baz"
+      ><span class="hs-identifier hs-var"
+	>baz</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-operator hs-var"
+      >.</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-var"
+      >sum</span
+      ><span
+      > </span
+      ><span class="hs-operator hs-var"
+      >.</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-var"
+      >map</span
+      ><span
+      > </span
+      ><a href="Classes.html#bar"
+      ><span class="hs-identifier hs-var"
+	>bar</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-23"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-24"
+      ></a
+      ><span class="hs-keyword"
+      >instance</span
+      ><span
+      > </span
+      ><a href="Classes.html#Foo%27"
+      ><span class="hs-identifier hs-type"
+	>Foo'</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-identifier hs-type"
+      >Int</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >where</span
+      ><span
+      >
+</span
+      ><a name="line-25"
+      ></a
+      ><span
+      >    </span
+      ><a name=""
+      ><a href="Classes.html#norf"
+	><span class="hs-identifier"
+	  >norf</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-var"
+      >sum</span
+      ><span
+      >
+</span
+      ><a name="line-26"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-27"
+      ></a
+      ><span class="hs-keyword"
+      >instance</span
+      ><span
+      > </span
+      ><a href="Classes.html#Foo%27"
+      ><span class="hs-identifier hs-type"
+	>Foo'</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-special"
+      >[</span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span class="hs-special"
+      >]</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >where</span
+      ><span
+      >
+</span
+      ><a name="line-28"
+      ></a
+      ><span
+      >    </span
+      ><a name=""
+      ><a href="Classes.html#quux"
+	><span class="hs-identifier"
+	  >quux</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-var"
+      >uncurry</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-operator hs-var"
+      >++</span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      >
+</span
+      ><a name="line-29"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-30"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-31"
+      ></a
+      ><span class="hs-keyword"
+      >class</span
+      ><span
+      > </span
+      ><a name="Plugh"
+      ><a href="Classes.html#Plugh"
+	><span class="hs-identifier"
+	  >Plugh</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >p</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >where</span
+      ><span
+      >
+</span
+      ><a name="line-32"
+      ></a
+      ><span
+      >    </span
+      ><span class="hs-identifier"
+      >plugh</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>p</span
+	></a
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>p</span
+	></a
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>b</span
+	></a
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>b</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>p</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>b</span
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>b</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span
+      >
+</span
+      ><a name="line-33"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-34"
+      ></a
+      ><span class="hs-keyword"
+      >instance</span
+      ><span
+      > </span
+      ><a href="Classes.html#Plugh"
+      ><span class="hs-identifier hs-type"
+	>Plugh</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-identifier hs-type"
+      >Either</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >where</span
+      ><span
+      >
+</span
+      ><a name="line-35"
+      ></a
+      ><span
+      >    </span
+      ><a name=""
+      ><a href="Classes.html#plugh"
+	><span class="hs-identifier"
+	  >plugh</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-identifier hs-var"
+      >Left</span
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >a</span
+	  ></a
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-identifier"
+      >_</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-var"
+      >Right</span
+      ><span
+      > </span
+      ><span class="hs-operator hs-var"
+      >$</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-var"
+      >const</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>a</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-36"
+      ></a
+      ><span
+      >    </span
+      ><span class="hs-identifier"
+      >plugh</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-identifier hs-var"
+      >Right</span
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >a</span
+	  ></a
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-identifier"
+      >_</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-var"
+      >Right</span
+      ><span
+      > </span
+      ><span class="hs-operator hs-var"
+      >$</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-var"
+      >const</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>a</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-37"
+      ></a
+      ><span
+      >    </span
+      ><span class="hs-identifier"
+      >plugh</span
+      ><span
+      > </span
+      ><span class="hs-identifier"
+      >_</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-identifier hs-var"
+      >Left</span
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >b</span
+	  ></a
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-var"
+      >Left</span
+      ><span
+      > </span
+      ><span class="hs-operator hs-var"
+      >$</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-var"
+      >const</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>b</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-38"
+      ></a
+      ><span
+      >    </span
+      ><span class="hs-identifier"
+      >plugh</span
+      ><span
+      > </span
+      ><span class="hs-identifier"
+      >_</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-identifier hs-var"
+      >Right</span
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >b</span
+	  ></a
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-var"
+      >Left</span
+      ><span
+      > </span
+      ><span class="hs-operator hs-var"
+      >$</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-var"
+      >const</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>b</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-39"
+      ></a
+      ></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,939 @@
+<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-keyword"
+      >module</span
+      ><span
+      > </span
+      ><span class="hs-identifier"
+      >Constructors</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >where</span
+      ><span
+      >
+</span
+      ><a name="line-2"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-3"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-4"
+      ></a
+      ><span class="hs-keyword"
+      >data</span
+      ><span
+      > </span
+      ><a name="Foo"
+      ><a href="Constructors.html#Foo"
+	><span class="hs-identifier"
+	  >Foo</span
+	  ></a
+	></a
+      ><span
+      >
+</span
+      ><a name="line-5"
+      ></a
+      ><span
+      >    </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><a name="Bar"
+      ><a href="Constructors.html#Bar"
+	><span class="hs-identifier"
+	  >Bar</span
+	  ></a
+	></a
+      ><span
+      >
+</span
+      ><a name="line-6"
+      ></a
+      ><span
+      >    </span
+      ><span class="hs-glyph"
+      >|</span
+      ><span
+      > </span
+      ><a name="Baz"
+      ><a href="Constructors.html#Baz"
+	><span class="hs-identifier"
+	  >Baz</span
+	  ></a
+	></a
+      ><span
+      >
+</span
+      ><a name="line-7"
+      ></a
+      ><span
+      >    </span
+      ><span class="hs-glyph"
+      >|</span
+      ><span
+      > </span
+      ><a name="Quux"
+      ><a href="Constructors.html#Quux"
+	><span class="hs-identifier"
+	  >Quux</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a href="Constructors.html#Foo"
+      ><span class="hs-identifier hs-type"
+	>Foo</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-identifier hs-type"
+      >Int</span
+      ><span
+      >
+</span
+      ><a name="line-8"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-9"
+      ></a
+      ><span class="hs-keyword"
+      >newtype</span
+      ><span
+      > </span
+      ><a name="Norf"
+      ><a href="Constructors.html#Norf"
+	><span class="hs-identifier"
+	  >Norf</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><a name="Norf"
+      ><a href="Constructors.html#Norf"
+	><span class="hs-identifier"
+	  >Norf</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><a href="Constructors.html#Foo"
+      ><span class="hs-identifier hs-type"
+	>Foo</span
+	></a
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >[</span
+      ><a href="Constructors.html#Foo"
+      ><span class="hs-identifier hs-type"
+	>Foo</span
+	></a
+      ><span class="hs-special"
+      >]</span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><a href="Constructors.html#Foo"
+      ><span class="hs-identifier hs-type"
+	>Foo</span
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span
+      >
+</span
+      ><a name="line-10"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-11"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-12"
+      ></a
+      ><span class="hs-identifier"
+      >bar</span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="hs-identifier"
+      >baz</span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="hs-identifier"
+      >quux</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><a href="Constructors.html#Foo"
+      ><span class="hs-identifier hs-type"
+	>Foo</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-13"
+      ></a
+      ><a name="bar"
+      ><a href="Constructors.html#bar"
+	><span class="hs-identifier"
+	  >bar</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><a href="Constructors.html#Bar"
+      ><span class="hs-identifier hs-var"
+	>Bar</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-14"
+      ></a
+      ><a name="baz"
+      ><a href="Constructors.html#baz"
+	><span class="hs-identifier"
+	  >baz</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><a href="Constructors.html#Baz"
+      ><span class="hs-identifier hs-var"
+	>Baz</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-15"
+      ></a
+      ><a name="quux"
+      ><a href="Constructors.html#quux"
+	><span class="hs-identifier"
+	  >quux</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><a href="Constructors.html#Quux"
+      ><span class="hs-identifier hs-var"
+	>Quux</span
+	></a
+      ><span
+      > </span
+      ><a href="Constructors.html#quux"
+      ><span class="hs-identifier hs-var"
+	>quux</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-number"
+      >0</span
+      ><span
+      >
+</span
+      ><a name="line-16"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-17"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-18"
+      ></a
+      ><span class="hs-identifier"
+      >unfoo</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><a href="Constructors.html#Foo"
+      ><span class="hs-identifier hs-type"
+	>Foo</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-type"
+      >Int</span
+      ><span
+      >
+</span
+      ><a name="line-19"
+      ></a
+      ><a name="unfoo"
+      ><a href="Constructors.html#unfoo"
+	><span class="hs-identifier"
+	  >unfoo</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a href="Constructors.html#Bar"
+      ><span class="hs-identifier hs-var"
+	>Bar</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-number"
+      >0</span
+      ><span
+      >
+</span
+      ><a name="line-20"
+      ></a
+      ><span class="hs-identifier"
+      >unfoo</span
+      ><span
+      > </span
+      ><a href="Constructors.html#Baz"
+      ><span class="hs-identifier hs-var"
+	>Baz</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-number"
+      >0</span
+      ><span
+      >
+</span
+      ><a name="line-21"
+      ></a
+      ><span class="hs-identifier"
+      >unfoo</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><a href="Constructors.html#Quux"
+      ><span class="hs-identifier hs-var"
+	>Quux</span
+	></a
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >foo</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >n</span
+	  ></a
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-number"
+      >42</span
+      ><span
+      > </span
+      ><span class="hs-operator hs-var"
+      >*</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>n</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-operator hs-var"
+      >+</span
+      ><span
+      > </span
+      ><a href="Constructors.html#unfoo"
+      ><span class="hs-identifier hs-var"
+	>unfoo</span
+	></a
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>foo</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-22"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-23"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-24"
+      ></a
+      ><span class="hs-identifier"
+      >unnorf</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><a href="Constructors.html#Norf"
+      ><span class="hs-identifier hs-type"
+	>Norf</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >[</span
+      ><a href="Constructors.html#Foo"
+      ><span class="hs-identifier hs-type"
+	>Foo</span
+	></a
+      ><span class="hs-special"
+      >]</span
+      ><span
+      >
+</span
+      ><a name="line-25"
+      ></a
+      ><a name="unnorf"
+      ><a href="Constructors.html#unnorf"
+	><span class="hs-identifier"
+	  >unnorf</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><a href="Constructors.html#Norf"
+      ><span class="hs-identifier hs-var"
+	>Norf</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><a href="Constructors.html#Bar"
+      ><span class="hs-identifier hs-var"
+	>Bar</span
+	></a
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >xs</span
+	  ></a
+	></a
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><a href="Constructors.html#Bar"
+      ><span class="hs-identifier hs-var"
+	>Bar</span
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>xs</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-26"
+      ></a
+      ><span class="hs-identifier"
+      >unnorf</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><a href="Constructors.html#Norf"
+      ><span class="hs-identifier hs-var"
+	>Norf</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><a href="Constructors.html#Baz"
+      ><span class="hs-identifier hs-var"
+	>Baz</span
+	></a
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >xs</span
+	  ></a
+	></a
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><a href="Constructors.html#Baz"
+      ><span class="hs-identifier hs-var"
+	>Baz</span
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-var"
+      >reverse</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>xs</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-27"
+      ></a
+      ><span class="hs-identifier"
+      >unnorf</span
+      ><span
+      > </span
+      ><span class="hs-identifier"
+      >_</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-var"
+      >undefined</span
+      ><span
+      >
+</span
+      ><a name="line-28"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-29"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-30"
+      ></a
+      ><span class="hs-identifier"
+      >unnorf'</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><a href="Constructors.html#Norf"
+      ><span class="hs-identifier hs-type"
+	>Norf</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-type"
+      >Int</span
+      ><span
+      >
+</span
+      ><a name="line-31"
+      ></a
+      ><a name="unnorf%27"
+      ><a href="Constructors.html#unnorf%27"
+	><span class="hs-identifier"
+	  >unnorf'</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >x</span
+	  ></a
+	></a
+      ><span class="hs-glyph"
+      >@</span
+      ><span class="hs-special"
+      >(</span
+      ><a href="Constructors.html#Norf"
+      ><span class="hs-identifier hs-var"
+	>Norf</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >f1</span
+	  ></a
+	></a
+      ><span class="hs-glyph"
+      >@</span
+      ><span class="hs-special"
+      >(</span
+      ><a href="Constructors.html#Quux"
+      ><span class="hs-identifier hs-var"
+	>Quux</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-identifier"
+      >_</span
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >n</span
+	  ></a
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="hs-identifier"
+      >_</span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >f2</span
+	  ></a
+	></a
+      ><span class="hs-glyph"
+      >@</span
+      ><span class="hs-special"
+      >(</span
+      ><a href="Constructors.html#Quux"
+      ><span class="hs-identifier hs-var"
+	>Quux</span
+	></a
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >f3</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-identifier"
+      >_</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
+      ><a name="line-32"
+      ></a
+      ><span
+      >    </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>x'</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-operator hs-var"
+      >+</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>n</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-operator hs-var"
+      >*</span
+      ><span
+      > </span
+      ><a href="Constructors.html#unfoo"
+      ><span class="hs-identifier hs-var"
+	>unfoo</span
+	></a
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>f1</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-operator hs-var"
+      >+</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>aux</span
+	></a
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>f3</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-33"
+      ></a
+      ><span
+      >  </span
+      ><span class="hs-keyword"
+      >where</span
+      ><span
+      >
+</span
+      ><a name="line-34"
+      ></a
+      ><span
+      >    </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >aux</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >fx</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><a href="Constructors.html#unfoo"
+      ><span class="hs-identifier hs-var"
+	>unfoo</span
+	></a
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>f2</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-operator hs-var"
+      >*</span
+      ><span
+      > </span
+      ><a href="Constructors.html#unfoo"
+      ><span class="hs-identifier hs-var"
+	>unfoo</span
+	></a
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>fx</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-operator hs-var"
+      >*</span
+      ><span
+      > </span
+      ><a href="Constructors.html#unfoo"
+      ><span class="hs-identifier hs-var"
+	>unfoo</span
+	></a
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>f3</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-35"
+      ></a
+      ><span
+      >    </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >x'</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-var"
+      >sum</span
+      ><span
+      > </span
+      ><span class="hs-operator hs-var"
+      >.</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-var"
+      >map</span
+      ><span
+      > </span
+      ><a href="Constructors.html#unfoo"
+      ><span class="hs-identifier hs-var"
+	>unfoo</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-operator hs-var"
+      >.</span
+      ><span
+      > </span
+      ><a href="Constructors.html#unnorf"
+      ><span class="hs-identifier hs-var"
+	>unnorf</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-operator hs-var"
+      >$</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>x</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-36"
+      ></a
+      ></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,934 @@
+<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-keyword"
+      >module</span
+      ><span
+      > </span
+      ><span class="hs-identifier"
+      >Identifiers</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >where</span
+      ><span
+      >
+</span
+      ><a name="line-2"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-3"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-4"
+      ></a
+      ><span class="hs-identifier"
+      >foo</span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="hs-identifier"
+      >bar</span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="hs-identifier"
+      >baz</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-type"
+      >Int</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-type"
+      >Int</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-type"
+      >Int</span
+      ><span
+      >
+</span
+      ><a name="line-5"
+      ></a
+      ><a name="foo"
+      ><a href="Identifiers.html#foo"
+	><span class="hs-identifier"
+	  >foo</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >x</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >y</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>x</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-operator hs-var"
+      >+</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>x</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-operator hs-var"
+      >*</span
+      ><span
+      > </span
+      ><a href="Identifiers.html#bar"
+      ><span class="hs-identifier hs-var"
+	>bar</span
+	></a
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>y</span
+	></a
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>x</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-operator hs-var"
+      >*</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>y</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-operator hs-var"
+      >+</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>y</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-6"
+      ></a
+      ><a name="bar"
+      ><a href="Identifiers.html#bar"
+	><span class="hs-identifier"
+	  >bar</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >x</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >y</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>y</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-operator hs-var"
+      >+</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>x</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-</span
+      ><span
+      > </span
+      ><a href="Identifiers.html#baz"
+      ><span class="hs-identifier hs-var"
+	>baz</span
+	></a
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>x</span
+	></a
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>y</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>x</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-operator hs-var"
+      >+</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>y</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-7"
+      ></a
+      ><a name="baz"
+      ><a href="Identifiers.html#baz"
+	><span class="hs-identifier"
+	  >baz</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >x</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >y</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>x</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-operator hs-var"
+      >*</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>y</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-operator hs-var"
+      >*</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>y</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-operator hs-var"
+      >*</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>y</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-operator hs-var"
+      >*</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>x</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-8"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-9"
+      ></a
+      ><span class="hs-identifier"
+      >quux</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-type"
+      >Int</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-type"
+      >Int</span
+      ><span
+      >
+</span
+      ><a name="line-10"
+      ></a
+      ><a name="quux"
+      ><a href="Identifiers.html#quux"
+	><span class="hs-identifier"
+	  >quux</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >x</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><a href="Identifiers.html#foo"
+      ><span class="hs-identifier hs-var"
+	>foo</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><a href="Identifiers.html#bar"
+      ><span class="hs-identifier hs-var"
+	>bar</span
+	></a
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>x</span
+	></a
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>x</span
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><a href="Identifiers.html#bar"
+      ><span class="hs-identifier hs-var"
+	>bar</span
+	></a
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>x</span
+	></a
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>x</span
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span
+      >
+</span
+      ><a name="line-11"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-12"
+      ></a
+      ><span class="hs-identifier"
+      >norf</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-type"
+      >Int</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-type"
+      >Int</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-type"
+      >Int</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-type"
+      >Int</span
+      ><span
+      >
+</span
+      ><a name="line-13"
+      ></a
+      ><a name="norf"
+      ><a href="Identifiers.html#norf"
+	><span class="hs-identifier"
+	  >norf</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >x</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >y</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >z</span
+	  ></a
+	></a
+      ><span
+      >
+</span
+      ><a name="line-14"
+      ></a
+      ><span
+      >    </span
+      ><span class="hs-glyph"
+      >|</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>x</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-operator hs-var"
+      >&lt;</span
+      ><span
+      > </span
+      ><span class="hs-number"
+      >0</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><a href="Identifiers.html#quux"
+      ><span class="hs-identifier hs-var"
+	>quux</span
+	></a
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>x</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-15"
+      ></a
+      ><span
+      >    </span
+      ><span class="hs-glyph"
+      >|</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>y</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-operator hs-var"
+      >&lt;</span
+      ><span
+      > </span
+      ><span class="hs-number"
+      >0</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><a href="Identifiers.html#quux"
+      ><span class="hs-identifier hs-var"
+	>quux</span
+	></a
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>y</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-16"
+      ></a
+      ><span
+      >    </span
+      ><span class="hs-glyph"
+      >|</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>z</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-operator hs-var"
+      >&lt;</span
+      ><span
+      > </span
+      ><span class="hs-number"
+      >0</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><a href="Identifiers.html#quux"
+      ><span class="hs-identifier hs-var"
+	>quux</span
+	></a
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>z</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-17"
+      ></a
+      ><span
+      >    </span
+      ><span class="hs-glyph"
+      >|</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-var"
+      >otherwise</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><a href="Identifiers.html#norf"
+      ><span class="hs-identifier hs-var"
+	>norf</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-glyph"
+      >-</span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>x</span
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-glyph"
+      >-</span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>y</span
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-glyph"
+      >-</span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>z</span
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span
+      >
+</span
+      ><a name="line-18"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-19"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-20"
+      ></a
+      ><span class="hs-identifier"
+      >main</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-type"
+      >IO</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      >
+</span
+      ><a name="line-21"
+      ></a
+      ><a name="main"
+      ><a href="Identifiers.html#main"
+	><span class="hs-identifier"
+	  >main</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >do</span
+      ><span
+      >
+</span
+      ><a name="line-22"
+      ></a
+      ><span
+      >    </span
+      ><span class="hs-identifier hs-var"
+      >putStrLn</span
+      ><span
+      > </span
+      ><span class="hs-operator hs-var"
+      >.</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-var"
+      >show</span
+      ><span
+      > </span
+      ><span class="hs-operator hs-var"
+      >$</span
+      ><span
+      > </span
+      ><a href="Identifiers.html#foo"
+      ><span class="hs-identifier hs-var"
+	>foo</span
+	></a
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>x</span
+	></a
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>y</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-23"
+      ></a
+      ><span
+      >    </span
+      ><span class="hs-identifier hs-var"
+      >putStrLn</span
+      ><span
+      > </span
+      ><span class="hs-operator hs-var"
+      >.</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-var"
+      >show</span
+      ><span
+      > </span
+      ><span class="hs-operator hs-var"
+      >$</span
+      ><span
+      > </span
+      ><a href="Identifiers.html#quux"
+      ><span class="hs-identifier hs-var"
+	>quux</span
+	></a
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>z</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-24"
+      ></a
+      ><span
+      >    </span
+      ><span class="hs-identifier hs-var"
+      >putStrLn</span
+      ><span
+      > </span
+      ><span class="hs-operator hs-var"
+      >.</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-var"
+      >show</span
+      ><span
+      > </span
+      ><span class="hs-operator hs-var"
+      >$</span
+      ><span
+      > </span
+      ><a href="Identifiers.html#norf"
+      ><span class="hs-identifier hs-var"
+	>Identifiers</span
+	><span class="hs-operator hs-var"
+	>.</span
+	><span class="hs-identifier hs-var"
+	>norf</span
+	></a
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>x</span
+	></a
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>y</span
+	></a
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>z</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-25"
+      ></a
+      ><span
+      >  </span
+      ><span class="hs-keyword"
+      >where</span
+      ><span
+      >
+</span
+      ><a name="line-26"
+      ></a
+      ><span
+      >    </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >x</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-number"
+      >10</span
+      ><span
+      >
+</span
+      ><a name="line-27"
+      ></a
+      ><span
+      >    </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >y</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-number"
+      >20</span
+      ><span
+      >
+</span
+      ><a name="line-28"
+      ></a
+      ><span
+      >    </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >z</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-number"
+      >30</span
+      ><span
+      >
+</span
+      ><a name="line-29"
+      ></a
+      ></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,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-keyword"
+      >module</span
+      ><span
+      > </span
+      ><span class="hs-identifier"
+      >Literals</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >where</span
+      ><span
+      >
+</span
+      ><a name="line-2"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-3"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-4"
+      ></a
+      ><span class="hs-identifier"
+      >str</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-type"
+      >String</span
+      ><span
+      >
+</span
+      ><a name="line-5"
+      ></a
+      ><a name="str"
+      ><a href="Literals.html#str"
+	><span class="hs-identifier"
+	  >str</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-string"
+      >&quot;str literal&quot;</span
+      ><span
+      >
+</span
+      ><a name="line-6"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-7"
+      ></a
+      ><span class="hs-identifier"
+      >num</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-type"
+      >Num</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=&gt;</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-8"
+      ></a
+      ><a name="num"
+      ><a href="Literals.html#num"
+	><span class="hs-identifier"
+	  >num</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-number"
+      >0</span
+      ><span
+      > </span
+      ><span class="hs-operator hs-var"
+      >+</span
+      ><span
+      > </span
+      ><span class="hs-number"
+      >1</span
+      ><span
+      > </span
+      ><span class="hs-operator hs-var"
+      >+</span
+      ><span
+      > </span
+      ><span class="hs-number"
+      >1010011</span
+      ><span
+      > </span
+      ><span class="hs-operator hs-var"
+      >*</span
+      ><span
+      > </span
+      ><span class="hs-number"
+      >41231</span
+      ><span
+      > </span
+      ><span class="hs-operator hs-var"
+      >+</span
+      ><span
+      > </span
+      ><span class="hs-number"
+      >12131</span
+      ><span
+      >
+</span
+      ><a name="line-9"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-10"
+      ></a
+      ><span class="hs-identifier"
+      >frac</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-type"
+      >Fractional</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=&gt;</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-11"
+      ></a
+      ><a name="frac"
+      ><a href="Literals.html#frac"
+	><span class="hs-identifier"
+	  >frac</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-number"
+      >42.0000001</span
+      ><span
+      >
+</span
+      ><a name="line-12"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-13"
+      ></a
+      ><span class="hs-identifier"
+      >list</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
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span class="hs-special"
+      >]</span
+      ><span class="hs-special"
+      >]</span
+      ><span class="hs-special"
+      >]</span
+      ><span class="hs-special"
+      >]</span
+      ><span
+      >
+</span
+      ><a name="line-14"
+      ></a
+      ><a name="list"
+      ><a href="Literals.html#list"
+	><span class="hs-identifier"
+	  >list</span
+	  ></a
+	></a
+      ><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
+      ><a name="line-15"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-16"
+      ></a
+      ><span class="hs-identifier"
+      >pair</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
+      ><a name="line-17"
+      ></a
+      ><a name="pair"
+      ><a href="Literals.html#pair"
+	><span class="hs-identifier"
+	  >pair</span
+	  ></a
+	></a
+      ><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
+      ><a name="line-18"
+      ></a
+      ></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,836 @@
+<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-keyword"
+      >module</span
+      ><span
+      > </span
+      ><span class="hs-identifier"
+      >Operators</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >where</span
+      ><span
+      >
+</span
+      ><a name="line-2"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-3"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-4"
+      ></a
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-operator"
+      >+++</span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >[</span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span class="hs-special"
+      >]</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >[</span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span class="hs-special"
+      >]</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >[</span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span class="hs-special"
+      >]</span
+      ><span
+      >
+</span
+      ><a name="line-5"
+      ></a
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >a</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a name="%2B%2B%2B"
+      ><a href="Operators.html#%2B%2B%2B"
+	><span class="hs-operator"
+	  >+++</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >b</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>a</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-operator hs-var"
+      >++</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>b</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-operator hs-var"
+      >++</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>a</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-6"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-7"
+      ></a
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-operator"
+      >$$$</span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >[</span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span class="hs-special"
+      >]</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >[</span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span class="hs-special"
+      >]</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >[</span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span class="hs-special"
+      >]</span
+      ><span
+      >
+</span
+      ><a name="line-8"
+      ></a
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >a</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a name="%24%24%24"
+      ><a href="Operators.html#%24%24%24"
+	><span class="hs-operator"
+	  >$$$</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >b</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>b</span
+	></a
+      ><span
+      > </span
+      ><a href="Operators.html#%2B%2B%2B"
+      ><span class="hs-operator hs-var"
+	>+++</span
+	></a
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>a</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-9"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-10"
+      ></a
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-operator"
+      >***</span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >[</span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span class="hs-special"
+      >]</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >[</span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span class="hs-special"
+      >]</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >[</span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span class="hs-special"
+      >]</span
+      ><span
+      >
+</span
+      ><a name="line-11"
+      ></a
+      ><span class="hs-special"
+      >(</span
+      ><a name="%2A%2A%2A"
+      ><a href="Operators.html#%2A%2A%2A"
+	><span class="hs-operator"
+	  >***</span
+	  ></a
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >a</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-special"
+      >[</span
+      ><span class="hs-special"
+      >]</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>a</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-12"
+      ></a
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-operator"
+      >***</span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >a</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-identifier"
+      >_</span
+      ><span class="hs-glyph"
+      >:</span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >b</span
+	  ></a
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>a</span
+	></a
+      ><span
+      > </span
+      ><a href="Operators.html#%2B%2B%2B"
+      ><span class="hs-operator hs-var"
+	>+++</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>a</span
+	></a
+      ><span
+      > </span
+      ><a href="Operators.html#%2A%2A%2A"
+      ><span class="hs-operator hs-var"
+	>***</span
+	></a
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>b</span
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span
+      >
+</span
+      ><a name="line-13"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-14"
+      ></a
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-operator"
+      >*/\*</span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >[</span
+      ><span class="hs-special"
+      >[</span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><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
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span class="hs-special"
+      >]</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >[</span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span class="hs-special"
+      >]</span
+      ><span
+      >
+</span
+      ><a name="line-15"
+      ></a
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >a</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a name="%2A%2F%5C%2A"
+      ><a href="Operators.html#%2A%2F%5C%2A"
+	><span class="hs-operator"
+	  >*/\*</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >b</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-var"
+      >concatMap</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><a href="Operators.html#%2A%2A%2A"
+      ><span class="hs-operator hs-var"
+	>***</span
+	></a
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>b</span
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>a</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-16"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-17"
+      ></a
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-operator"
+      >**/\**</span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >[</span
+      ><span class="hs-special"
+      >[</span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><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
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><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
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span class="hs-special"
+      >]</span
+      ><span class="hs-special"
+      >]</span
+      ><span
+      >
+</span
+      ><a name="line-18"
+      ></a
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >a</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a name="%2A%2A%2F%5C%2A%2A"
+      ><a href="Operators.html#%2A%2A%2F%5C%2A%2A"
+	><span class="hs-operator"
+	  >**/\**</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >b</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-var"
+      >zipWith</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><a href="Operators.html#%2A%2F%5C%2A"
+      ><span class="hs-operator hs-var"
+	>*/\*</span
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >[</span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>a</span
+	></a
+      ><span
+      > </span
+      ><a href="Operators.html#%2B%2B%2B"
+      ><span class="hs-operator hs-var"
+	>+++</span
+	></a
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>b</span
+	></a
+      ><span class="hs-special"
+      >]</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>a</span
+	></a
+      ><span
+      > </span
+      ><a href="Operators.html#%24%24%24"
+      ><span class="hs-operator hs-var"
+	>$$$</span
+	></a
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>b</span
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span
+      >
+</span
+      ><a name="line-19"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-20"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-21"
+      ></a
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-operator"
+      >#.#</span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>b</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>c</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>b</span
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      >
+</span
+      ><a name="line-22"
+      ></a
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >a</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a name="%23.%23"
+      ><a href="Operators.html#%23.%23"
+	><span class="hs-operator"
+	  >#.#</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >b</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-var"
+      >const</span
+      ><span
+      > </span
+      ><span class="hs-operator hs-var"
+      >$</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>a</span
+	></a
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>b</span
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span
+      >
+</span
+      ><a name="line-23"
+      ></a
+      ></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,2036 @@
+<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 RankNTypes #-}</span
+      ><span
+      >
+</span
+      ><a name="line-2"
+      ></a
+      ><span class="hs-pragma"
+      >{-# LANGUAGE ScopedTypeVariables #-}</span
+      ><span
+      >
+</span
+      ><a name="line-3"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-4"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-5"
+      ></a
+      ><span class="hs-keyword"
+      >module</span
+      ><span
+      > </span
+      ><span class="hs-identifier"
+      >Polymorphism</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >where</span
+      ><span
+      >
+</span
+      ><a name="line-6"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-7"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-8"
+      ></a
+      ><span class="hs-identifier"
+      >foo</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-9"
+      ></a
+      ><a name="foo"
+      ><a href="Polymorphism.html#foo"
+	><span class="hs-identifier"
+	  >foo</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-var"
+      >undefined</span
+      ><span
+      >
+</span
+      ><a name="line-10"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-11"
+      ></a
+      ><span class="hs-identifier"
+      >foo'</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >forall</span
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >a</span
+	  ></a
+	></a
+      ><span class="hs-operator"
+      >.</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-12"
+      ></a
+      ><a name="foo%27"
+      ><a href="Polymorphism.html#foo%27"
+	><span class="hs-identifier"
+	  >foo'</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-var"
+      >undefined</span
+      ><span
+      >
+</span
+      ><a name="line-13"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-14"
+      ></a
+      ><span class="hs-identifier"
+      >bar</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>b</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>b</span
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span
+      >
+</span
+      ><a name="line-15"
+      ></a
+      ><a name="bar"
+      ><a href="Polymorphism.html#bar"
+	><span class="hs-identifier"
+	  >bar</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-var"
+      >undefined</span
+      ><span
+      >
+</span
+      ><a name="line-16"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-17"
+      ></a
+      ><span class="hs-identifier"
+      >bar'</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >forall</span
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >a</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >b</span
+	  ></a
+	></a
+      ><span class="hs-operator"
+      >.</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>b</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>b</span
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span
+      >
+</span
+      ><a name="line-18"
+      ></a
+      ><a name="bar%27"
+      ><a href="Polymorphism.html#bar%27"
+	><span class="hs-identifier"
+	  >bar'</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-var"
+      >undefined</span
+      ><span
+      >
+</span
+      ><a name="line-19"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-20"
+      ></a
+      ><span class="hs-identifier"
+      >baz</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >[</span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span class="hs-special"
+      >]</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>b</span
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>b</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-21"
+      ></a
+      ><a name="baz"
+      ><a href="Polymorphism.html#baz"
+	><span class="hs-identifier"
+	  >baz</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-var"
+      >undefined</span
+      ><span
+      >
+</span
+      ><a name="line-22"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-23"
+      ></a
+      ><span class="hs-identifier"
+      >baz'</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >forall</span
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >a</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >b</span
+	  ></a
+	></a
+      ><span class="hs-operator"
+      >.</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >[</span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span class="hs-special"
+      >]</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>b</span
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>b</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-24"
+      ></a
+      ><a name="baz%27"
+      ><a href="Polymorphism.html#baz%27"
+	><span class="hs-identifier"
+	  >baz'</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-var"
+      >undefined</span
+      ><span
+      >
+</span
+      ><a name="line-25"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-26"
+      ></a
+      ><span class="hs-identifier"
+      >quux</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-keyword"
+      >forall</span
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >a</span
+	  ></a
+	></a
+      ><span class="hs-operator"
+      >.</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-27"
+      ></a
+      ><a name="quux"
+      ><a href="Polymorphism.html#quux"
+	><span class="hs-identifier"
+	  >quux</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >x</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >f</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>f</span
+	></a
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>x</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-28"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-29"
+      ></a
+      ><span class="hs-identifier"
+      >quux'</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >forall</span
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >a</span
+	  ></a
+	></a
+      ><span class="hs-operator"
+      >.</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-keyword"
+      >forall</span
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >a</span
+	  ></a
+	></a
+      ><span class="hs-operator"
+      >.</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-30"
+      ></a
+      ><a name="quux%27"
+      ><a href="Polymorphism.html#quux%27"
+	><span class="hs-identifier"
+	  >quux'</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >x</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >f</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>f</span
+	></a
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>x</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-31"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-32"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-33"
+      ></a
+      ><span class="hs-identifier"
+      >num</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-type"
+      >Num</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=&gt;</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-34"
+      ></a
+      ><a name="num"
+      ><a href="Polymorphism.html#num"
+	><span class="hs-identifier"
+	  >num</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-var"
+      >undefined</span
+      ><span
+      >
+</span
+      ><a name="line-35"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-36"
+      ></a
+      ><span class="hs-identifier"
+      >num'</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >forall</span
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >a</span
+	  ></a
+	></a
+      ><span class="hs-operator"
+      >.</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-type"
+      >Num</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=&gt;</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-37"
+      ></a
+      ><a name="num%27"
+      ><a href="Polymorphism.html#num%27"
+	><span class="hs-identifier"
+	  >num'</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-var"
+      >undefined</span
+      ><span
+      >
+</span
+      ><a name="line-38"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-39"
+      ></a
+      ><span class="hs-identifier"
+      >eq</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-identifier hs-type"
+      >Eq</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-type"
+      >Eq</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>b</span
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=&gt;</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >[</span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span class="hs-special"
+      >]</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >[</span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>b</span
+	></a
+      ><span class="hs-special"
+      >]</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>b</span
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span
+      >
+</span
+      ><a name="line-40"
+      ></a
+      ><a name="eq"
+      ><a href="Polymorphism.html#eq"
+	><span class="hs-identifier"
+	  >eq</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-var"
+      >undefined</span
+      ><span
+      >
+</span
+      ><a name="line-41"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-42"
+      ></a
+      ><span class="hs-identifier"
+      >eq'</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >forall</span
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >a</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >b</span
+	  ></a
+	></a
+      ><span class="hs-operator"
+      >.</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-identifier hs-type"
+      >Eq</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-type"
+      >Eq</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>b</span
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=&gt;</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >[</span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span class="hs-special"
+      >]</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >[</span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>b</span
+	></a
+      ><span class="hs-special"
+      >]</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>b</span
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span
+      >
+</span
+      ><a name="line-43"
+      ></a
+      ><a name="eq%27"
+      ><a href="Polymorphism.html#eq%27"
+	><span class="hs-identifier"
+	  >eq'</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-var"
+      >undefined</span
+      ><span
+      >
+</span
+      ><a name="line-44"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-45"
+      ></a
+      ><span class="hs-identifier"
+      >mon</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-type"
+      >Monad</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>m</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=&gt;</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>m</span
+	></a
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>m</span
+	></a
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-46"
+      ></a
+      ><a name="mon"
+      ><a href="Polymorphism.html#mon"
+	><span class="hs-identifier"
+	  >mon</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-var"
+      >undefined</span
+      ><span
+      >
+</span
+      ><a name="line-47"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-48"
+      ></a
+      ><span class="hs-identifier"
+      >mon'</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >forall</span
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >m</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >a</span
+	  ></a
+	></a
+      ><span class="hs-operator"
+      >.</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-type"
+      >Monad</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>m</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=&gt;</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>m</span
+	></a
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>m</span
+	></a
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-49"
+      ></a
+      ><a name="mon%27"
+      ><a href="Polymorphism.html#mon%27"
+	><span class="hs-identifier"
+	  >mon'</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-var"
+      >undefined</span
+      ><span
+      >
+</span
+      ><a name="line-50"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-51"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-52"
+      ></a
+      ><span class="hs-identifier"
+      >norf</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-keyword"
+      >forall</span
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >a</span
+	  ></a
+	></a
+      ><span class="hs-operator"
+      >.</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-type"
+      >Ord</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=&gt;</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-53"
+      ></a
+      ><a name="norf"
+      ><a href="Polymorphism.html#norf"
+	><span class="hs-identifier"
+	  >norf</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >x</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >f</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>x</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-54"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-55"
+      ></a
+      ><span class="hs-identifier"
+      >norf'</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >forall</span
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >a</span
+	  ></a
+	></a
+      ><span class="hs-operator"
+      >.</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-keyword"
+      >forall</span
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >a</span
+	  ></a
+	></a
+      ><span class="hs-operator"
+      >.</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-type"
+      >Ord</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=&gt;</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-56"
+      ></a
+      ><a name="norf%27"
+      ><a href="Polymorphism.html#norf%27"
+	><span class="hs-identifier"
+	  >norf'</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >x</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >f</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>x</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-57"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-58"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-59"
+      ></a
+      ><span class="hs-identifier"
+      >plugh</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >forall</span
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >a</span
+	  ></a
+	></a
+      ><span class="hs-operator"
+      >.</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-60"
+      ></a
+      ><a name="plugh"
+      ><a href="Polymorphism.html#plugh"
+	><span class="hs-identifier"
+	  >plugh</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >x</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>x</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-61"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-62"
+      ></a
+      ><span class="hs-identifier"
+      >thud</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >forall</span
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >a</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >b</span
+	  ></a
+	></a
+      ><span class="hs-operator"
+      >.</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>b</span
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>b</span
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span
+      >
+</span
+      ><a name="line-63"
+      ></a
+      ><a name="thud"
+      ><a href="Polymorphism.html#thud"
+	><span class="hs-identifier"
+	  >thud</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >f</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >x</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      >
+</span
+      ><a name="line-64"
+      ></a
+      ><span
+      >    </span
+      ><span class="hs-special"
+      >(</span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>x</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>y</span
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>b</span
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span
+      >
+</span
+      ><a name="line-65"
+      ></a
+      ><span
+      >  </span
+      ><span class="hs-keyword"
+      >where</span
+      ><span
+      >
+</span
+      ><a name="line-66"
+      ></a
+      ><span
+      >    </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >y</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>f</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>a</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>b</span
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>x</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-type"
+	>b</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-67"
+      ></a
+      ></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,976 @@
+<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 NamedFieldPuns #-}</span
+      ><span
+      >
+</span
+      ><a name="line-2"
+      ></a
+      ><span class="hs-pragma"
+      >{-# LANGUAGE RecordWildCards #-}</span
+      ><span
+      >
+</span
+      ><a name="line-3"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-4"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-5"
+      ></a
+      ><span class="hs-keyword"
+      >module</span
+      ><span
+      > </span
+      ><span class="hs-identifier"
+      >Records</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >where</span
+      ><span
+      >
+</span
+      ><a name="line-6"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-7"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-8"
+      ></a
+      ><span class="hs-keyword"
+      >data</span
+      ><span
+      > </span
+      ><a name="Point"
+      ><a href="Records.html#Point"
+	><span class="hs-identifier"
+	  >Point</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><a name="Point"
+      ><a href="Records.html#Point"
+	><span class="hs-identifier"
+	  >Point</span
+	  ></a
+	></a
+      ><span
+      >
+</span
+      ><a name="line-9"
+      ></a
+      ><span
+      >    </span
+      ><span class="hs-special"
+      >{</span
+      ><span
+      > </span
+      ><a name="x"
+      ><a href="Records.html#x"
+	><span class="hs-identifier"
+	  >x</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >!</span
+      ><span class="hs-identifier hs-type"
+      >Int</span
+      ><span
+      >
+</span
+      ><a name="line-10"
+      ></a
+      ><span
+      >    </span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><a name="y"
+      ><a href="Records.html#y"
+	><span class="hs-identifier"
+	  >y</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >!</span
+      ><span class="hs-identifier hs-type"
+      >Int</span
+      ><span
+      >
+</span
+      ><a name="line-11"
+      ></a
+      ><span
+      >    </span
+      ><span class="hs-special"
+      >}</span
+      ><span
+      >
+</span
+      ><a name="line-12"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-13"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-14"
+      ></a
+      ><span class="hs-identifier"
+      >point</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-type"
+      >Int</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-type"
+      >Int</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><a href="Records.html#Point"
+      ><span class="hs-identifier hs-type"
+	>Point</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-15"
+      ></a
+      ><a name="point"
+      ><a href="Records.html#point"
+	><span class="hs-identifier"
+	  >point</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >x</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >y</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><a href="Records.html#Point"
+      ><span class="hs-identifier hs-var"
+	>Point</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-special"
+      >{</span
+      ><span
+      > </span
+      ><span class="hs-identifier"
+      >x</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>x</span
+	></a
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="hs-identifier"
+      >y</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>y</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-special"
+      >}</span
+      ><span
+      >
+</span
+      ><a name="line-16"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-17"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-18"
+      ></a
+      ><span class="hs-identifier"
+      >lengthSqr</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><a href="Records.html#Point"
+      ><span class="hs-identifier hs-type"
+	>Point</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-type"
+      >Int</span
+      ><span
+      >
+</span
+      ><a name="line-19"
+      ></a
+      ><a name="lengthSqr"
+      ><a href="Records.html#lengthSqr"
+	><span class="hs-identifier"
+	  >lengthSqr</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><a href="Records.html#Point"
+      ><span class="hs-identifier hs-var"
+	>Point</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-special"
+      >{</span
+      ><span
+      > </span
+      ><span class="hs-identifier"
+      >x</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >x</span
+	  ></a
+	></a
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="hs-identifier"
+      >y</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >y</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-special"
+      >}</span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>x</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-operator hs-var"
+      >*</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>x</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-operator hs-var"
+      >+</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>y</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-operator hs-var"
+      >*</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>y</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-20"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-21"
+      ></a
+      ><span class="hs-identifier"
+      >lengthSqr'</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><a href="Records.html#Point"
+      ><span class="hs-identifier hs-type"
+	>Point</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-type"
+      >Int</span
+      ><span
+      >
+</span
+      ><a name="line-22"
+      ></a
+      ><a name="lengthSqr%27"
+      ><a href="Records.html#lengthSqr%27"
+	><span class="hs-identifier"
+	  >lengthSqr'</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><a href="Records.html#Point"
+      ><span class="hs-identifier hs-var"
+	>Point</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-special"
+      >{</span
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >x</span
+	  ></a
+	></a
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >y</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-special"
+      >}</span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>y</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-operator hs-var"
+      >*</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>y</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-operator hs-var"
+      >+</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>x</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-operator hs-var"
+      >*</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>x</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-23"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-24"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-25"
+      ></a
+      ><span class="hs-identifier"
+      >translateX</span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="hs-identifier"
+      >translateY</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><a href="Records.html#Point"
+      ><span class="hs-identifier hs-type"
+	>Point</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-type"
+      >Int</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><a href="Records.html#Point"
+      ><span class="hs-identifier hs-type"
+	>Point</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-26"
+      ></a
+      ><a name="translateX"
+      ><a href="Records.html#translateX"
+	><span class="hs-identifier"
+	  >translateX</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >p</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >d</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>p</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-special"
+      >{</span
+      ><span
+      > </span
+      ><span class="hs-identifier"
+      >x</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-identifier"
+      >x</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>p</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-operator hs-var"
+      >+</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>d</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-special"
+      >}</span
+      ><span
+      >
+</span
+      ><a name="line-27"
+      ></a
+      ><a name="translateY"
+      ><a href="Records.html#translateY"
+	><span class="hs-identifier"
+	  >translateY</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >p</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >d</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>p</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-special"
+      >{</span
+      ><span
+      > </span
+      ><span class="hs-identifier"
+      >y</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-identifier"
+      >y</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>p</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-operator hs-var"
+      >+</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>d</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-special"
+      >}</span
+      ><span
+      >
+</span
+      ><a name="line-28"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-29"
+      ></a
+      ><span class="hs-identifier"
+      >translate</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-type"
+      >Int</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-type"
+      >Int</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><a href="Records.html#Point"
+      ><span class="hs-identifier hs-type"
+	>Point</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><a href="Records.html#Point"
+      ><span class="hs-identifier hs-type"
+	>Point</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-30"
+      ></a
+      ><a name="translate"
+      ><a href="Records.html#translate"
+	><span class="hs-identifier"
+	  >translate</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >x</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >y</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >p</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      >
+</span
+      ><a name="line-31"
+      ></a
+      ><span
+      >    </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>aux</span
+	></a
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>p</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-32"
+      ></a
+      ><span
+      >  </span
+      ><span class="hs-keyword"
+      >where</span
+      ><span
+      >
+</span
+      ><a name="line-33"
+      ></a
+      ><span
+      >    </span
+      ><span class="hs-special"
+      >(</span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >dx</span
+	  ></a
+	></a
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >dy</span
+	  ></a
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>x</span
+	></a
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>y</span
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span
+      >
+</span
+      ><a name="line-34"
+      ></a
+      ><span
+      >    </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >aux</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a href="Records.html#Point"
+      ><span class="hs-identifier hs-var"
+	>Point</span
+	></a
+      ><span class="hs-special"
+      >{</span
+      ><span class="hs-glyph"
+      >..</span
+      ><span class="hs-special"
+      >}</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>p</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-special"
+      >{</span
+      ><span
+      > </span
+      ><span class="hs-identifier"
+      >x</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>x</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-operator hs-var"
+      >+</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>dx</span
+	></a
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><span class="hs-identifier"
+      >y</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>y</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-operator hs-var"
+      >+</span
+      ><span
+      > </span
+      ><a href="#"
+      ><span class="hs-identifier hs-var"
+	>dy</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-special"
+      >}</span
+      ><span
+      >
+</span
+      ><a name="line-35"
+      ></a
+      ></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,1056 @@
+<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 TypeFamilies #-}</span
+      ><span
+      >
+</span
+      ><a name="line-2"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-3"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-4"
+      ></a
+      ><span class="hs-keyword"
+      >module</span
+      ><span
+      > </span
+      ><span class="hs-identifier"
+      >Types</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >where</span
+      ><span
+      >
+</span
+      ><a name="line-5"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-6"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-7"
+      ></a
+      ><span class="hs-keyword"
+      >data</span
+      ><span
+      > </span
+      ><a name="Quux"
+      ><a href="Types.html#Quux"
+	><span class="hs-identifier"
+	  >Quux</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><a name="Bar"
+      ><a href="Types.html#Bar"
+	><span class="hs-identifier"
+	  >Bar</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >|</span
+      ><span
+      > </span
+      ><a name="Baz"
+      ><a href="Types.html#Baz"
+	><span class="hs-identifier"
+	  >Baz</span
+	  ></a
+	></a
+      ><span
+      >
+</span
+      ><a name="line-8"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-9"
+      ></a
+      ><span class="hs-keyword"
+      >newtype</span
+      ><span
+      > </span
+      ><a name="Foo"
+      ><a href="Types.html#Foo"
+	><span class="hs-identifier"
+	  >Foo</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><a name="Foo"
+      ><a href="Types.html#Foo"
+	><span class="hs-identifier"
+	  >Foo</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      >
+</span
+      ><a name="line-10"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-11"
+      ></a
+      ><span class="hs-keyword"
+      >type</span
+      ><span
+      > </span
+      ><a name="FooQuux"
+      ><a href="Types.html#FooQuux"
+	><span class="hs-identifier"
+	  >FooQuux</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><a href="Types.html#Foo"
+      ><span class="hs-identifier hs-type"
+	>Foo</span
+	></a
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><a href="Types.html#Quux"
+      ><span class="hs-identifier hs-type"
+	>Quux</span
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span
+      >
+</span
+      ><a name="line-12"
+      ></a
+      ><span class="hs-keyword"
+      >type</span
+      ><span
+      > </span
+      ><a name="QuuxFoo"
+      ><a href="Types.html#QuuxFoo"
+	><span class="hs-identifier"
+	  >QuuxFoo</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><a href="Types.html#Quux"
+      ><span class="hs-identifier hs-type"
+	>Quux</span
+	></a
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><a href="Types.html#Foo"
+      ><span class="hs-identifier hs-type"
+	>Foo</span
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span
+      >
+</span
+      ><a name="line-13"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-14"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-15"
+      ></a
+      ><span class="hs-keyword"
+      >data</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >family</span
+      ><span
+      > </span
+      ><a name="Norf"
+      ><a href="Types.html#Norf"
+	><span class="hs-identifier"
+	  >Norf</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >a</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >b</span
+	  ></a
+	></a
+      ><span
+      >
+</span
+      ><a name="line-16"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-17"
+      ></a
+      ><span class="hs-keyword"
+      >data</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >instance</span
+      ><span
+      > </span
+      ><a href="Types.html#Norf"
+      ><span class="hs-identifier hs-type"
+	>Norf</span
+	></a
+      ><span
+      > </span
+      ><a href="Types.html#Foo"
+      ><span class="hs-identifier hs-type"
+	>Foo</span
+	></a
+      ><span
+      > </span
+      ><a href="Types.html#Quux"
+      ><span class="hs-identifier hs-type"
+	>Quux</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><a name="NFQ"
+      ><a href="Types.html#NFQ"
+	><span class="hs-identifier"
+	  >NFQ</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a href="Types.html#Foo"
+      ><span class="hs-identifier hs-type"
+	>Foo</span
+	></a
+      ><span
+      > </span
+      ><a href="Types.html#Quux"
+      ><span class="hs-identifier hs-type"
+	>Quux</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-18"
+      ></a
+      ><span class="hs-keyword"
+      >data</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >instance</span
+      ><span
+      > </span
+      ><a href="Types.html#Norf"
+      ><span class="hs-identifier hs-type"
+	>Norf</span
+	></a
+      ><span
+      > </span
+      ><a href="Types.html#Quux"
+      ><span class="hs-identifier hs-type"
+	>Quux</span
+	></a
+      ><span
+      > </span
+      ><a href="Types.html#Foo"
+      ><span class="hs-identifier hs-type"
+	>Foo</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><a name="NQF"
+      ><a href="Types.html#NQF"
+	><span class="hs-identifier"
+	  >NQF</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a href="Types.html#Quux"
+      ><span class="hs-identifier hs-type"
+	>Quux</span
+	></a
+      ><span
+      > </span
+      ><a href="Types.html#Foo"
+      ><span class="hs-identifier hs-type"
+	>Foo</span
+	></a
+      ><span
+      >
+</span
+      ><a name="line-19"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-20"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-21"
+      ></a
+      ><span class="hs-keyword"
+      >type</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >family</span
+      ><span
+      > </span
+      ><a name="Norf%27"
+      ><a href="Types.html#Norf%27"
+	><span class="hs-identifier"
+	  >Norf'</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >a</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><a name=""
+      ><a href="#"
+	><span class="hs-identifier"
+	  >b</span
+	  ></a
+	></a
+      ><span
+      >
+</span
+      ><a name="line-22"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-23"
+      ></a
+      ><span class="hs-keyword"
+      >type</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >instance</span
+      ><span
+      > </span
+      ><a href="Types.html#Norf%27"
+      ><span class="hs-identifier hs-type"
+	>Norf'</span
+	></a
+      ><span
+      > </span
+      ><a href="Types.html#Foo"
+      ><span class="hs-identifier hs-type"
+	>Foo</span
+	></a
+      ><span
+      > </span
+      ><a href="Types.html#Quux"
+      ><span class="hs-identifier hs-type"
+	>Quux</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><a href="Types.html#Foo"
+      ><span class="hs-identifier hs-type"
+	>Foo</span
+	></a
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><a href="Types.html#Quux"
+      ><span class="hs-identifier hs-type"
+	>Quux</span
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span
+      >
+</span
+      ><a name="line-24"
+      ></a
+      ><span class="hs-keyword"
+      >type</span
+      ><span
+      > </span
+      ><span class="hs-keyword"
+      >instance</span
+      ><span
+      > </span
+      ><a href="Types.html#Norf%27"
+      ><span class="hs-identifier hs-type"
+	>Norf'</span
+	></a
+      ><span
+      > </span
+      ><a href="Types.html#Quux"
+      ><span class="hs-identifier hs-type"
+	>Quux</span
+	></a
+      ><span
+      > </span
+      ><a href="Types.html#Foo"
+      ><span class="hs-identifier hs-type"
+	>Foo</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><a href="Types.html#Quux"
+      ><span class="hs-identifier hs-type"
+	>Quux</span
+	></a
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><a href="Types.html#Foo"
+      ><span class="hs-identifier hs-type"
+	>Foo</span
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span
+      >
+</span
+      ><a name="line-25"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-26"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-27"
+      ></a
+      ><span class="hs-identifier"
+      >norf1</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><a href="Types.html#Norf"
+      ><span class="hs-identifier hs-type"
+	>Norf</span
+	></a
+      ><span
+      > </span
+      ><a href="Types.html#Foo"
+      ><span class="hs-identifier hs-type"
+	>Foo</span
+	></a
+      ><span
+      > </span
+      ><a href="Types.html#Quux"
+      ><span class="hs-identifier hs-type"
+	>Quux</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-type"
+      >Int</span
+      ><span
+      >
+</span
+      ><a name="line-28"
+      ></a
+      ><a name="norf1"
+      ><a href="Types.html#norf1"
+	><span class="hs-identifier"
+	  >norf1</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><a href="Types.html#NFQ"
+      ><span class="hs-identifier hs-var"
+	>NFQ</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><a href="Types.html#Foo"
+      ><span class="hs-identifier hs-var"
+	>Foo</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-special"
+      >)</span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><a href="Types.html#Bar"
+      ><span class="hs-identifier hs-var"
+	>Bar</span
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-number"
+      >0</span
+      ><span
+      >
+</span
+      ><a name="line-29"
+      ></a
+      ><span class="hs-identifier"
+      >norf1</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><a href="Types.html#NFQ"
+      ><span class="hs-identifier hs-var"
+	>NFQ</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><a href="Types.html#Foo"
+      ><span class="hs-identifier hs-var"
+	>Foo</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-special"
+      >)</span
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><a href="Types.html#Baz"
+      ><span class="hs-identifier hs-var"
+	>Baz</span
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-number"
+      >1</span
+      ><span
+      >
+</span
+      ><a name="line-30"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-31"
+      ></a
+      ><span class="hs-identifier"
+      >norf2</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><a href="Types.html#Norf"
+      ><span class="hs-identifier hs-type"
+	>Norf</span
+	></a
+      ><span
+      > </span
+      ><a href="Types.html#Quux"
+      ><span class="hs-identifier hs-type"
+	>Quux</span
+	></a
+      ><span
+      > </span
+      ><a href="Types.html#Foo"
+      ><span class="hs-identifier hs-type"
+	>Foo</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-type"
+      >Int</span
+      ><span
+      >
+</span
+      ><a name="line-32"
+      ></a
+      ><a name="norf2"
+      ><a href="Types.html#norf2"
+	><span class="hs-identifier"
+	  >norf2</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><a href="Types.html#NQF"
+      ><span class="hs-identifier hs-var"
+	>NQF</span
+	></a
+      ><span
+      > </span
+      ><a href="Types.html#Bar"
+      ><span class="hs-identifier hs-var"
+	>Bar</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><a href="Types.html#Foo"
+      ><span class="hs-identifier hs-var"
+	>Foo</span
+	></a
+      ><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="hs-number"
+      >0</span
+      ><span
+      >
+</span
+      ><a name="line-33"
+      ></a
+      ><span class="hs-identifier"
+      >norf2</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><a href="Types.html#NQF"
+      ><span class="hs-identifier hs-var"
+	>NQF</span
+	></a
+      ><span
+      > </span
+      ><a href="Types.html#Baz"
+      ><span class="hs-identifier hs-var"
+	>Baz</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><a href="Types.html#Foo"
+      ><span class="hs-identifier hs-var"
+	>Foo</span
+	></a
+      ><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="hs-number"
+      >1</span
+      ><span
+      >
+</span
+      ><a name="line-34"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-35"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-36"
+      ></a
+      ><span class="hs-identifier"
+      >norf1'</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><a href="Types.html#Norf%27"
+      ><span class="hs-identifier hs-type"
+	>Norf'</span
+	></a
+      ><span
+      > </span
+      ><a href="Types.html#Foo"
+      ><span class="hs-identifier hs-type"
+	>Foo</span
+	></a
+      ><span
+      > </span
+      ><a href="Types.html#Quux"
+      ><span class="hs-identifier hs-type"
+	>Quux</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-type"
+      >Int</span
+      ><span
+      >
+</span
+      ><a name="line-37"
+      ></a
+      ><a name="norf1%27"
+      ><a href="Types.html#norf1%27"
+	><span class="hs-identifier"
+	  >norf1'</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><a href="Types.html#Foo"
+      ><span class="hs-identifier hs-var"
+	>Foo</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-special"
+      >)</span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><a href="Types.html#Bar"
+      ><span class="hs-identifier hs-var"
+	>Bar</span
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-number"
+      >0</span
+      ><span
+      >
+</span
+      ><a name="line-38"
+      ></a
+      ><span class="hs-identifier"
+      >norf1'</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><a href="Types.html#Foo"
+      ><span class="hs-identifier hs-var"
+	>Foo</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><span class="hs-special"
+      >)</span
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><a href="Types.html#Baz"
+      ><span class="hs-identifier hs-var"
+	>Baz</span
+	></a
+      ><span class="hs-special"
+      >)</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >=</span
+      ><span
+      > </span
+      ><span class="hs-number"
+      >1</span
+      ><span
+      >
+</span
+      ><a name="line-39"
+      ></a
+      ><span
+      >
+</span
+      ><a name="line-40"
+      ></a
+      ><span class="hs-identifier"
+      >norf2'</span
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >::</span
+      ><span
+      > </span
+      ><a href="Types.html#Norf%27"
+      ><span class="hs-identifier hs-type"
+	>Norf'</span
+	></a
+      ><span
+      > </span
+      ><a href="Types.html#Quux"
+      ><span class="hs-identifier hs-type"
+	>Quux</span
+	></a
+      ><span
+      > </span
+      ><a href="Types.html#Foo"
+      ><span class="hs-identifier hs-type"
+	>Foo</span
+	></a
+      ><span
+      > </span
+      ><span class="hs-glyph"
+      >-&gt;</span
+      ><span
+      > </span
+      ><span class="hs-identifier hs-type"
+      >Int</span
+      ><span
+      >
+</span
+      ><a name="line-41"
+      ></a
+      ><a name="norf2%27"
+      ><a href="Types.html#norf2%27"
+	><span class="hs-identifier"
+	  >norf2'</span
+	  ></a
+	></a
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><a href="Types.html#Bar"
+      ><span class="hs-identifier hs-var"
+	>Bar</span
+	></a
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><a href="Types.html#Foo"
+      ><span class="hs-identifier hs-var"
+	>Foo</span
+	></a
+      ><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="hs-number"
+      >0</span
+      ><span
+      >
+</span
+      ><a name="line-42"
+      ></a
+      ><span class="hs-identifier"
+      >norf2'</span
+      ><span
+      > </span
+      ><span class="hs-special"
+      >(</span
+      ><a href="Types.html#Baz"
+      ><span class="hs-identifier hs-var"
+	>Baz</span
+	></a
+      ><span class="hs-special"
+      >,</span
+      ><span
+      > </span
+      ><a href="Types.html#Foo"
+      ><span class="hs-identifier hs-var"
+	>Foo</span
+	></a
+      ><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="hs-number"
+      >1</span
+      ><span
+      >
+</span
+      ><a name="line-43"
+      ></a
+      ></pre
+    ></body
+  ></html
+>
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,38 @@
+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,35 @@
+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,28 @@
+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/Literals.hs b/hypsrc-test/src/Literals.hs
new file mode 100644
--- /dev/null
+++ b/hypsrc-test/src/Literals.hs
@@ -0,0 +1,17 @@
+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,22 @@
+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,66 @@
+{-# 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/Records.hs b/hypsrc-test/src/Records.hs
new file mode 100644
--- /dev/null
+++ b/hypsrc-test/src/Records.hs
@@ -0,0 +1,34 @@
+{-# 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/Types.hs b/hypsrc-test/src/Types.hs
new file mode 100644
--- /dev/null
+++ b/hypsrc-test/src/Types.hs
@@ -0,0 +1,42 @@
+{-# 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/latex-test/Main.hs b/latex-test/Main.hs
new file mode 100644
--- /dev/null
+++ b/latex-test/Main.hs
@@ -0,0 +1,28 @@
+{-# LANGUAGE CPP #-}
+
+
+import System.Environment
+import System.FilePath
+
+import Test.Haddock
+
+
+checkConfig :: CheckConfig String
+checkConfig = CheckConfig
+    { ccfgRead = Just
+    , ccfgClean = \_ -> id
+    , ccfgDump = id
+    , ccfgEqual = (==)
+    }
+
+
+dirConfig :: DirConfig
+dirConfig = defaultDirConfig $ takeDirectory __FILE__
+
+
+main :: IO ()
+main = do
+    cfg <- parseArgs checkConfig dirConfig =<< getArgs
+    runAndCheck $ cfg
+        { cfgHaddockArgs = cfgHaddockArgs cfg ++ ["--latex"]
+        }
diff --git a/latex-test/ref/Simple/Simple.tex b/latex-test/ref/Simple/Simple.tex
--- a/latex-test/ref/Simple/Simple.tex
+++ b/latex-test/ref/Simple/Simple.tex
@@ -11,7 +11,6 @@
 \item[\begin{tabular}{@{}l}
 foo\ ::\ t
 \end{tabular}]\haddockbegindoc
-This is foo.
-\par
+This is foo.\par
 
 \end{haddockdesc}
diff --git a/latex-test/run.lhs b/latex-test/run.lhs
deleted file mode 100644
--- a/latex-test/run.lhs
+++ /dev/null
@@ -1,162 +0,0 @@
-#!/usr/bin/env runhaskell
-\begin{code}
-{-# LANGUAGE CPP #-}
-import Prelude hiding (mod)
-import Control.Monad
-import Control.Applicative
-import Data.List
-import Data.Maybe
-import Distribution.InstalledPackageInfo hiding (dataDir)
-import Distribution.Package (PackageName (..))
-import Distribution.Simple.Compiler
-import Distribution.Simple.GHC
-import Distribution.Simple.PackageIndex
-import Distribution.Simple.Program
-import Distribution.Simple.Utils
-import Distribution.Verbosity
-import System.IO
-import System.Directory
-import System.Environment
-import System.Exit
-import System.FilePath
-import System.Process (ProcessHandle, runProcess, waitForProcess, system)
-
-
-packageRoot, dataDir, haddockPath, baseDir, testDir, outDir, refDir :: FilePath
-baseDir = takeDirectory __FILE__
-testDir       = baseDir </> "src"
-refDir        = baseDir </> "ref"
-outDir        = baseDir </> "out"
-packageRoot   = baseDir </> ".."
-dataDir       = packageRoot </> "resources"
-haddockPath   = packageRoot </> "dist" </> "build" </> "haddock" </> "haddock"
-
-
-main :: IO ()
-main = do
-  test
-  putStrLn "All tests passed!"
-
-
-test :: IO ()
-test = do
-  x <- doesFileExist haddockPath
-  unless x $ System.Exit.die "you need to run 'cabal build' successfully first"
-
-  contents <- getDirectoryContents testDir
-
-  args <- getArgs
-  let (opts, spec) = span ("-" `isPrefixOf`) args
-      isDir x' = liftM2 (&&) (doesDirectoryExist $ testDir </> x')
-                             (return $ x' /= "." && x' /= "..")
-  modDirs <- case spec of
-    y:_ | y /= "all" -> return [y]
-    _ -> filterM isDir contents
-
-  let modDirs' = map (testDir </>) modDirs
-
-  -- add haddock_datadir to environment for subprocesses
-  env <- Just . (:) ("haddock_datadir", dataDir) <$> getEnvironment
-
-  putStrLn ""
-  putStrLn "Haddock version: "
-  h1 <- runProcess haddockPath ["--version"] Nothing
-                   env Nothing Nothing Nothing
-  wait h1 "*** Running `haddock --version' failed!"
-  putStrLn ""
-  putStrLn "GHC version: "
-  h2 <- runProcess haddockPath ["--ghc-version"] Nothing
-                   env Nothing Nothing Nothing
-  wait h2 "*** Running `haddock --ghc-version' failed!"
-  putStrLn ""
-
-  -- TODO: maybe do something more clever here using haddock.cabal
-  ghcPath <- fmap init $ rawSystemStdout normal haddockPath ["--print-ghc-path"]
-  (_, _, conf) <- configure normal (Just ghcPath) Nothing defaultProgramConfiguration
-  pkgIndex <- getInstalledPackages normal [GlobalPackageDB] conf
-  let mkDep pkgName =
-        fromMaybe (error "Couldn't find test dependencies") $ do
-          let pkgs = lookupPackageName pkgIndex (PackageName pkgName)
-          (_, pkgs') <- listToMaybe pkgs
-          pkg <- listToMaybe pkgs'
-          ifacePath <- listToMaybe (haddockInterfaces pkg)
-          htmlPath <- listToMaybe (haddockHTMLs pkg)
-          return ("-i " ++ htmlPath ++ "," ++ ifacePath)
-
-  let base    = mkDep "base"
-      process = mkDep "process"
-      ghcprim = mkDep "ghc-prim"
-
-  putStrLn "Running tests..."
-
-  forM_ modDirs' $ \modDir -> do
-    testModules <- getDirectoryContents modDir
-
-    let mods = filter ((==) ".hs" . takeExtension) testModules
-        mods' = map (modDir </>) mods
-
-    unless (null mods') $ do
-      handle <- runProcess haddockPath
-                (["-w", "-o", outDir </> last (splitPath modDir), "--latex"
-                 , "--optghc=-fglasgow-exts"
-                 , "--optghc=-w", base, process, ghcprim] ++ opts ++ mods')
-                Nothing env Nothing
-                Nothing Nothing
-
-      wait handle "*** Haddock run failed! Exiting."
-
-  check modDirs (if not (null args) && args !! 0 == "all" then False else True)
-  where
-    wait :: ProcessHandle -> String -> IO ()
-    wait h msg = do
-      r <- waitForProcess h
-      unless (r == ExitSuccess) $ do
-        hPutStrLn stderr msg
-        exitFailure
-
-check :: [FilePath] -> Bool -> IO ()
-check modDirs strict = do
-  forM_ modDirs $ \modDir -> do
-    let oDir = outDir </> modDir
-        rDir = refDir </> modDir
-
-    refDirExists <- doesDirectoryExist rDir
-    when refDirExists $ do
-      -- we're not creating sub-directories, I think.
-      refFiles <- getDirectoryContents rDir >>= filterM doesFileExist
-
-      forM_ refFiles $ \rFile -> do
-        let refFile = rDir </> rFile
-            outFile = oDir </> rFile
-        oe <- doesFileExist outFile
-        if oe
-          then do
-            out <- readFile outFile
-            ref <- readFile refFile
-
-            if out /= ref
-               then do
-                 putStrLn $ "Output for " ++ modDir ++ " has changed! Exiting with diff:"
-
-                 let reffile' = outDir </> takeFileName refFile ++ ".nolinks"
-                     outfile' = outDir </> takeFileName outFile ++ ".ref.nolinks"
-                 writeFile reffile' ref
-                 writeFile outfile' out
-                 r <- programOnPath "colordiff"
-                 code <- if r
-                   then system $ "colordiff " ++ reffile' ++ " " ++ outfile'
-                   else system $ "diff " ++ reffile' ++ " " ++ outfile'
-                 if strict then exitFailure else return ()
-                 unless (code == ExitSuccess) $ do
-                   hPutStrLn stderr "*** Running diff failed!"
-                   exitFailure
-               else do
-                 putStrLn $ "Pass: " ++ modDir
-           else do
-             putStrLn $ "Pass: " ++ modDir ++ " (no .ref file)"
-
-programOnPath :: FilePath -> IO Bool
-programOnPath p = do
-  result <- findProgramLocation silent p
-  return (isJust result)
-\end{code}
