    -- | The core logic of @futhark doc@.
    module Futhark.Doc.Generator (renderFiles) where

    import CMarkGFM qualified as GFM
    import Control.Arrow ((***))
    import Control.Monad
    import Control.Monad.Reader
    import Control.Monad.Writer (Writer, WriterT, runWriter, runWriterT, tell)
    import Data.Bifunctor (second)
    import Data.Char (isAlpha, isSpace, toUpper)
    import Data.List (find, groupBy, inits, intersperse, isPrefixOf, partition, sort, sortOn, tails)
    import Data.Map qualified as M
    import Data.Maybe
    import Data.Ord
    import Data.Set qualified as S
    import Data.String (fromString)
    import Data.Text qualified as T
    import Data.Version
    import Futhark.Util.Pretty (Doc, docText, pretty)
    import Futhark.Version
    import Language.Futhark
    import Language.Futhark.Semantic
    import Language.Futhark.Warnings
    import System.FilePath (makeRelative, splitPath, (-<.>), (</>))
    import Text.Blaze.Html5 (AttributeValue, Html, toHtml, (!))
    import Text.Blaze.Html5 qualified as H
    import Text.Blaze.Html5.Attributes qualified as A
    import Prelude hiding (abs, mod)

    docToHtml :: Doc a -> Html
    docToHtml :: forall a. Doc a -> Html
    docToHtml = Text -> Html
    forall a. ToMarkup a => a -> Html
    toHtml (Text -> Html) -> (Doc a -> Text) -> Doc a -> Html
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Doc a -> Text
    forall a. Doc a -> Text
    docText

    primTypeHtml :: PrimType -> Html
    primTypeHtml :: PrimType -> Html
    primTypeHtml = Doc (ZonkAny 0) -> Html
    forall a. Doc a -> Html
    docToHtml (Doc (ZonkAny 0) -> Html)
    -> (PrimType -> Doc (ZonkAny 0)) -> PrimType -> Html
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . PrimType -> Doc (ZonkAny 0)
    forall a ann. Pretty a => a -> Doc ann
    forall ann. PrimType -> Doc ann
    pretty

    prettyU :: Uniqueness -> Html
    prettyU :: Uniqueness -> Html
    prettyU = Doc (ZonkAny 1) -> Html
    forall a. Doc a -> Html
    docToHtml (Doc (ZonkAny 1) -> Html)
    -> (Uniqueness -> Doc (ZonkAny 1)) -> Uniqueness -> Html
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Uniqueness -> Doc (ZonkAny 1)
    forall a ann. Pretty a => a -> Doc ann
    forall ann. Uniqueness -> Doc ann
    pretty

    renderName :: Name -> Html
    renderName :: Name -> Html
    renderName Name
    name = Doc (ZonkAny 2) -> Html
    forall a. Doc a -> Html
    docToHtml (Name -> Doc (ZonkAny 2)
    forall a ann. Pretty a => a -> Doc ann
    forall ann. Name -> Doc ann
    pretty Name
    name)

    joinBy :: Html -> [Html] -> Html
    joinBy :: Html -> [Html] -> Html
    joinBy Html
    _ [] = Html
    forall a. Monoid a => a
    mempty
    joinBy Html
    _ [Html
    x] = Html
    x
    joinBy Html
    sep (Html
    x : [Html]
    xs) = Html
    x Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <> (Html -> Html) -> [Html] -> Html
    forall m a. Monoid m => (a -> m) -> [a] -> m
    forall (t :: * -> *) m a.
    (Foldable t, Monoid m) =>
    (a -> m) -> t a -> m
    foldMap (Html
    sep Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <>) [Html]
    xs

    commas :: [Html] -> Html
    commas :: [Html] -> Html
    commas = Html -> [Html] -> Html
    joinBy Html
    ", "

    parens :: Html -> Html
    parens :: Html -> Html
    parens Html
    x = Html
    "(" Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <> Html
    x Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <> Html
    ")"

    braces :: Html -> Html
    braces :: Html -> Html
    braces Html
    x = Html
    "{" Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <> Html
    x Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <> Html
    "}"

    brackets :: Html -> Html
    brackets :: Html -> Html
    brackets Html
    x = Html
    "[" Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <> Html
    x Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <> Html
    "]"

    pipes :: [Html] -> Html
    pipes :: [Html] -> Html
    pipes = Html -> [Html] -> Html
    joinBy Html
    " | "

    -- | A set of names that we should not generate links to, because they
    -- are uninteresting.  These are for example type parameters.
    type NoLink = S.Set VName

    -- | A mapping from unique names to the file in which they exist, and
    -- the anchor (not necessarily globally unique) for linking to that
    -- name.
    type FileMap = M.Map VName (FilePath, String)

    vnameToFileMap :: Imports -> FileMap
    vnameToFileMap :: Imports -> FileMap
    vnameToFileMap = [FileMap] -> FileMap
    forall a. Monoid a => [a] -> a
    mconcat ([FileMap] -> FileMap)
    -> (Imports -> [FileMap]) -> Imports -> FileMap
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ((ImportName, FileModule) -> FileMap) -> Imports -> [FileMap]
    forall a b. (a -> b) -> [a] -> [b]
    map (ImportName, FileModule) -> FileMap
    forFile
      where
        forFile :: (ImportName, FileModule) -> FileMap
    forFile (ImportName
    file, FileModule TySet
    _ Env
    file_env Prog
    _prog Env
    _) =
          [Char] -> Env -> FileMap
    forEnv [Char]
    "" Env
    file_env
          where
            file' :: [Char]
    file' = [Char] -> [Char] -> [Char]
    makeRelative [Char]
    "/" ([Char] -> [Char]) -> [Char] -> [Char]
    forall a b. (a -> b) -> a -> b
    $ ImportName -> [Char]
    includeToFilePath ImportName
    file
            vname :: [Char] -> Namespace -> QualName VName -> FileMap
    vname [Char]
    prefix Namespace
    ns QualName VName
    v =
              VName -> ([Char], [Char]) -> FileMap
    forall k a. k -> a -> Map k a
    M.singleton (QualName VName -> VName
    forall vn. QualName vn -> vn
    qualLeaf QualName VName
    v) ([Char]
    file', Namespace -> [Char] -> [Char]
    forall {a}. (Semigroup a, IsString a) => Namespace -> a -> a
    canon Namespace
    ns ([Char] -> [Char]) -> [Char] -> [Char]
    forall a b. (a -> b) -> a -> b
    $ [Char]
    prefix [Char] -> [Char] -> [Char]
    forall a. Semigroup a => a -> a -> a
    <> VName -> [Char]
    baseString (QualName VName -> VName
    forall vn. QualName vn -> vn
    qualLeaf QualName VName
    v))
            vname' :: [Char] -> ((Namespace, b), QualName VName) -> FileMap
    vname' [Char]
    prefix ((Namespace
    ns, b
    _), QualName VName
    v) = [Char] -> Namespace -> QualName VName -> FileMap
    vname [Char]
    prefix Namespace
    ns QualName VName
    v
            canon :: Namespace -> a -> a
    canon Namespace
    Term a
    s = a
    "term:" a -> a -> a
    forall a. Semigroup a => a -> a -> a
    <> a
    s
            canon Namespace
    Type a
    s = a
    "type:" a -> a -> a
    forall a. Semigroup a => a -> a -> a
    <> a
    s
            canon Namespace
    Signature a
    s = a
    "modtype:" a -> a -> a
    forall a. Semigroup a => a -> a -> a
    <> a
    s

            forEnv :: [Char] -> Env -> FileMap
    forEnv [Char]
    prefix Env
    env =
              [FileMap] -> FileMap
    forall a. Monoid a => [a] -> a
    mconcat (((VName, TypeBinding) -> FileMap)
    -> [(VName, TypeBinding)] -> [FileMap]
    forall a b. (a -> b) -> [a] -> [b]
    map ([Char] -> (VName, TypeBinding) -> FileMap
    forall {b}. [Char] -> (VName, b) -> FileMap
    forType [Char]
    prefix) ([(VName, TypeBinding)] -> [FileMap])
    -> [(VName, TypeBinding)] -> [FileMap]
    forall a b. (a -> b) -> a -> b
    $ Map VName TypeBinding -> [(VName, TypeBinding)]
    forall k a. Map k a -> [(k, a)]
    M.toList (Map VName TypeBinding -> [(VName, TypeBinding)])
    -> Map VName TypeBinding -> [(VName, TypeBinding)]
    forall a b. (a -> b) -> a -> b
    $ Env -> Map VName TypeBinding
    envTypeTable Env
    env)
                FileMap -> FileMap -> FileMap
    forall a. Semigroup a => a -> a -> a
    <> [FileMap] -> FileMap
    forall a. Monoid a => [a] -> a
    mconcat (((VName, Mod) -> FileMap) -> [(VName, Mod)] -> [FileMap]
    forall a b. (a -> b) -> [a] -> [b]
    map ([Char] -> (VName, Mod) -> FileMap
    forMod [Char]
    prefix) ([(VName, Mod)] -> [FileMap]) -> [(VName, Mod)] -> [FileMap]
    forall a b. (a -> b) -> a -> b
    $ Map VName Mod -> [(VName, Mod)]
    forall k a. Map k a -> [(k, a)]
    M.toList (Map VName Mod -> [(VName, Mod)])
    -> Map VName Mod -> [(VName, Mod)]
    forall a b. (a -> b) -> a -> b
    $ Env -> Map VName Mod
    envModTable Env
    env)
                FileMap -> FileMap -> FileMap
    forall a. Semigroup a => a -> a -> a
    <> [FileMap] -> FileMap
    forall a. Monoid a => [a] -> a
    mconcat (((VName, MTy) -> FileMap) -> [(VName, MTy)] -> [FileMap]
    forall a b. (a -> b) -> [a] -> [b]
    map ([Char] -> (VName, MTy) -> FileMap
    forMty [Char]
    prefix) ([(VName, MTy)] -> [FileMap]) -> [(VName, MTy)] -> [FileMap]
    forall a b. (a -> b) -> a -> b
    $ Map VName MTy -> [(VName, MTy)]
    forall k a. Map k a -> [(k, a)]
    M.toList (Map VName MTy -> [(VName, MTy)])
    -> Map VName MTy -> [(VName, MTy)]
    forall a b. (a -> b) -> a -> b
    $ Env -> Map VName MTy
    envModTypeTable Env
    env)
                FileMap -> FileMap -> FileMap
    forall a. Semigroup a => a -> a -> a
    <> [FileMap] -> FileMap
    forall a. Monoid a => [a] -> a
    mconcat ((((Namespace, Name), QualName VName) -> FileMap)
    -> [((Namespace, Name), QualName VName)] -> [FileMap]
    forall a b. (a -> b) -> [a] -> [b]
    map ([Char] -> ((Namespace, Name), QualName VName) -> FileMap
    forall {b}. [Char] -> ((Namespace, b), QualName VName) -> FileMap
    vname' [Char]
    prefix) ([((Namespace, Name), QualName VName)] -> [FileMap])
    -> [((Namespace, Name), QualName VName)] -> [FileMap]
    forall a b. (a -> b) -> a -> b
    $ Map (Namespace, Name) (QualName VName)
    -> [((Namespace, Name), QualName VName)]
    forall k a. Map k a -> [(k, a)]
    M.toList (Map (Namespace, Name) (QualName VName)
     -> [((Namespace, Name), QualName VName)])
    -> Map (Namespace, Name) (QualName VName)
    -> [((Namespace, Name), QualName VName)]
    forall a b. (a -> b) -> a -> b
    $ Env -> Map (Namespace, Name) (QualName VName)
    envNameMap Env
    env)
            forMod :: [Char] -> (VName, Mod) -> FileMap
    forMod [Char]
    prefix (VName
    name, ModEnv Env
    env) =
              [Char] -> Env -> FileMap
    forEnv ([Char]
    prefix [Char] -> [Char] -> [Char]
    forall a. Semigroup a => a -> a -> a
    <> VName -> [Char]
    baseString VName
    name [Char] -> [Char] -> [Char]
    forall a. Semigroup a => a -> a -> a
    <> [Char]
    ".") Env
    env
            forMod [Char]
    _ (VName
    _, ModFun {}) = FileMap
    forall a. Monoid a => a
    mempty
            forMty :: [Char] -> (VName, MTy) -> FileMap
    forMty [Char]
    prefix (VName
    name, MTy TySet
    abs Mod
    mod) =
              [Char] -> (VName, Mod) -> FileMap
    forMod [Char]
    prefix (VName
    name, Mod
    mod)
                FileMap -> FileMap -> FileMap
    forall a. Semigroup a => a -> a -> a
    <> [FileMap] -> FileMap
    forall a. Monoid a => [a] -> a
    mconcat ((QualName VName -> FileMap) -> [QualName VName] -> [FileMap]
    forall a b. (a -> b) -> [a] -> [b]
    map ([Char] -> Namespace -> QualName VName -> FileMap
    vname [Char]
    prefix Namespace
    Type) (TySet -> [QualName VName]
    forall k a. Map k a -> [k]
    M.keys TySet
    abs))
            forType :: [Char] -> (VName, b) -> FileMap
    forType [Char]
    prefix = [Char] -> Namespace -> QualName VName -> FileMap
    vname [Char]
    prefix Namespace
    Type (QualName VName -> FileMap)
    -> ((VName, b) -> QualName VName) -> (VName, b) -> FileMap
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . VName -> QualName VName
    forall v. v -> QualName v
    qualName (VName -> QualName VName)
    -> ((VName, b) -> VName) -> (VName, b) -> QualName VName
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (VName, b) -> VName
    forall a b. (a, b) -> a
    fst

    data Context = Context
      { Context -> [Char]
    ctxCurrent :: String,
        Context -> FileModule
    ctxFileMod :: FileModule,
        Context -> Imports
    ctxImports :: Imports,
        Context -> NoLink
    ctxNoLink :: NoLink,
        Context -> FileMap
    ctxFileMap :: FileMap,
        -- | Local module types that show up in the interface. These
        -- should be documented, but clearly marked local.
        Context -> NoLink
    ctxVisibleMTys :: S.Set VName
      }

    -- | We keep a mapping of the names we have actually documented, so we
    -- can generate an index.
    type Documented = M.Map VName IndexWhat

    type DocM = ReaderT Context (WriterT Documented (Writer Warnings))

    data IndexWhat = IndexValue | IndexFunction | IndexModule | IndexModuleType | IndexType

    warn :: Loc -> Doc () -> DocM ()
    warn :: Loc -> Doc () -> DocM ()
    warn Loc
    loc Doc ()
    s = WriterT Documented (Writer Warnings) () -> DocM ()
    forall (m :: * -> *) a. Monad m => m a -> ReaderT Context m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (WriterT Documented (Writer Warnings) () -> DocM ())
    -> WriterT Documented (Writer Warnings) () -> DocM ()
    forall a b. (a -> b) -> a -> b
    $ Writer Warnings () -> WriterT Documented (Writer Warnings) ()
    forall (m :: * -> *) a. Monad m => m a -> WriterT Documented m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (Writer Warnings () -> WriterT Documented (Writer Warnings) ())
    -> Writer Warnings () -> WriterT Documented (Writer Warnings) ()
    forall a b. (a -> b) -> a -> b
    $ Warnings -> Writer Warnings ()
    forall w (m :: * -> *). MonadWriter w m => w -> m ()
    tell (Warnings -> Writer Warnings ()) -> Warnings -> Writer Warnings ()
    forall a b. (a -> b) -> a -> b
    $ Loc -> Doc () -> Warnings
    singleWarning Loc
    loc Doc ()
    s

    document :: VName -> IndexWhat -> DocM ()
    document :: VName -> IndexWhat -> DocM ()
    document VName
    v IndexWhat
    what = Documented -> DocM ()
    forall w (m :: * -> *). MonadWriter w m => w -> m ()
    tell (Documented -> DocM ()) -> Documented -> DocM ()
    forall a b. (a -> b) -> a -> b
    $ VName -> IndexWhat -> Documented
    forall k a. k -> a -> Map k a
    M.singleton VName
    v IndexWhat
    what

    noLink :: [VName] -> DocM a -> DocM a
    noLink :: forall a. [VName] -> DocM a -> DocM a
    noLink [VName]
    names = (Context -> Context)
    -> ReaderT Context (WriterT Documented (Writer Warnings)) a
    -> ReaderT Context (WriterT Documented (Writer Warnings)) a
    forall a.
    (Context -> Context)
    -> ReaderT Context (WriterT Documented (Writer Warnings)) a
    -> ReaderT Context (WriterT Documented (Writer Warnings)) a
    forall r (m :: * -> *) a. MonadReader r m => (r -> r) -> m a -> m a
    local ((Context -> Context)
     -> ReaderT Context (WriterT Documented (Writer Warnings)) a
     -> ReaderT Context (WriterT Documented (Writer Warnings)) a)
    -> (Context -> Context)
    -> ReaderT Context (WriterT Documented (Writer Warnings)) a
    -> ReaderT Context (WriterT Documented (Writer Warnings)) a
    forall a b. (a -> b) -> a -> b
    $ \Context
    ctx ->
      Context
    ctx {ctxNoLink = S.fromList names <> ctxNoLink ctx}

    selfLink :: AttributeValue -> Html -> Html
    selfLink :: AttributeValue -> Html -> Html
    selfLink AttributeValue
    s = Html -> Html
    H.a (Html -> Html) -> Attribute -> Html -> Html
    forall h. Attributable h => h -> Attribute -> h
    ! AttributeValue -> Attribute
    A.id AttributeValue
    s (Html -> Html) -> Attribute -> Html -> Html
    forall h. Attributable h => h -> Attribute -> h
    ! AttributeValue -> Attribute
    A.href (AttributeValue
    "#" AttributeValue -> AttributeValue -> AttributeValue
    forall a. Semigroup a => a -> a -> a
    <> AttributeValue
    s) (Html -> Html) -> Attribute -> Html -> Html
    forall h. Attributable h => h -> Attribute -> h
    ! AttributeValue -> Attribute
    A.class_ AttributeValue
    "self_link"

    fullRow :: Html -> Html
    fullRow :: Html -> Html
    fullRow = Html -> Html
    H.tr (Html -> Html) -> (Html -> Html) -> Html -> Html
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Html -> Html
    H.td (Html -> Html) -> Attribute -> Html -> Html
    forall h. Attributable h => h -> Attribute -> h
    ! AttributeValue -> Attribute
    A.colspan AttributeValue
    "3")

    emptyRow :: Html
    emptyRow :: Html
    emptyRow = Html -> Html
    H.tr (Html -> Html) -> Html -> Html
    forall a b. (a -> b) -> a -> b
    $ Html -> Html
    H.td Html
    forall a. Monoid a => a
    mempty Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <> Html -> Html
    H.td Html
    forall a. Monoid a => a
    mempty Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <> Html -> Html
    H.td Html
    forall a. Monoid a => a
    mempty

    specRow :: Html -> Html -> Html -> Html
    specRow :: Html -> Html -> Html -> Html
    specRow Html
    a Html
    b Html
    c =
      Html -> Html
    H.tr (Html -> Html) -> Html -> Html
    forall a b. (a -> b) -> a -> b
    $
        (Html -> Html
    H.td (Html -> Html) -> Attribute -> Html -> Html
    forall h. Attributable h => h -> Attribute -> h
    ! AttributeValue -> Attribute
    A.class_ AttributeValue
    "spec_lhs") Html
    a
          Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <> (Html -> Html
    H.td (Html -> Html) -> Attribute -> Html -> Html
    forall h. Attributable h => h -> Attribute -> h
    ! AttributeValue -> Attribute
    A.class_ AttributeValue
    "spec_eql") Html
    b
          Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <> (Html -> Html
    H.td (Html -> Html) -> Attribute -> Html -> Html
    forall h. Attributable h => h -> Attribute -> h
    ! AttributeValue -> Attribute
    A.class_ AttributeValue
    "spec_rhs") Html
    c

    -- | The header documentation (which need not be present) can contain
    -- an abstract and further sections.
    headerDoc :: Prog -> DocM (Html, Html, Html)
    headerDoc :: Prog -> DocM (Html, Html, Html)
    headerDoc Prog
    prog =
      case Prog -> Maybe DocComment
    forall (f :: * -> *) vn. ProgBase f vn -> Maybe DocComment
    progDoc Prog
    prog of
        Just (DocComment Text
    doc SrcLoc
    loc) -> do
          let ([Char]
    abstract, [Char]
    more_sections) = [Char] -> ([Char], [Char])
    splitHeaderDoc ([Char] -> ([Char], [Char])) -> [Char] -> ([Char], [Char])
    forall a b. (a -> b) -> a -> b
    $ Text -> [Char]
    T.unpack Text
    doc
          first_paragraph <- Maybe DocComment -> DocM Html
    docHtml (Maybe DocComment -> DocM Html) -> Maybe DocComment -> DocM Html
    forall a b. (a -> b) -> a -> b
    $ DocComment -> Maybe DocComment
    forall a. a -> Maybe a
    Just (DocComment -> Maybe DocComment) -> DocComment -> Maybe DocComment
    forall a b. (a -> b) -> a -> b
    $ Text -> SrcLoc -> DocComment
    DocComment ([Char] -> Text
    firstParagraph [Char]
    abstract) SrcLoc
    loc
          abstract' <- docHtml $ Just $ DocComment (T.pack abstract) loc
          more_sections' <- docHtml $ Just $ DocComment (T.pack more_sections) loc
          pure
            ( first_paragraph,
              selfLink "abstract" (H.h2 "Abstract") <> abstract',
              more_sections'
            )
        Maybe DocComment
    _ -> (Html, Html, Html) -> DocM (Html, Html, Html)
    forall a.
    a -> ReaderT Context (WriterT Documented (Writer Warnings)) a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure (Html, Html, Html)
    forall a. Monoid a => a
    mempty
      where
        splitHeaderDoc :: [Char] -> ([Char], [Char])
    splitHeaderDoc [Char]
    s =
          ([Char], [Char]) -> Maybe ([Char], [Char]) -> ([Char], [Char])
    forall a. a -> Maybe a -> a
    fromMaybe ([Char]
    s, [Char]
    forall a. Monoid a => a
    mempty) (Maybe ([Char], [Char]) -> ([Char], [Char]))
    -> Maybe ([Char], [Char]) -> ([Char], [Char])
    forall a b. (a -> b) -> a -> b
    $
            (([Char], [Char]) -> Bool)
    -> [([Char], [Char])] -> Maybe ([Char], [Char])
    forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
    find (([Char]
    "\n##" [Char] -> [Char] -> Bool
    forall a. Eq a => [a] -> [a] -> Bool
    `isPrefixOf`) ([Char] -> Bool)
    -> (([Char], [Char]) -> [Char]) -> ([Char], [Char]) -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ([Char], [Char]) -> [Char]
    forall a b. (a, b) -> b
    snd) ([([Char], [Char])] -> Maybe ([Char], [Char]))
    -> [([Char], [Char])] -> Maybe ([Char], [Char])
    forall a b. (a -> b) -> a -> b
    $
              [[Char]] -> [[Char]] -> [([Char], [Char])]
    forall a b. [a] -> [b] -> [(a, b)]
    zip ([Char] -> [[Char]]
    forall a. [a] -> [[a]]
    inits [Char]
    s) ([Char] -> [[Char]]
    forall a. [a] -> [[a]]
    tails [Char]
    s)
        firstParagraph :: [Char] -> Text
    firstParagraph = [Char] -> Text
    T.pack ([Char] -> Text) -> ([Char] -> [Char]) -> [Char] -> Text
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [[Char]] -> [Char]
    unlines ([[Char]] -> [Char]) -> ([Char] -> [[Char]]) -> [Char] -> [Char]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ([Char] -> Bool) -> [[Char]] -> [[Char]]
    forall a. (a -> Bool) -> [a] -> [a]
    takeWhile (Bool -> Bool
    not (Bool -> Bool) -> ([Char] -> Bool) -> [Char] -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Char] -> Bool
    paragraphSeparator) ([[Char]] -> [[Char]])
    -> ([Char] -> [[Char]]) -> [Char] -> [[Char]]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Char] -> [[Char]]
    lines
        paragraphSeparator :: [Char] -> Bool
    paragraphSeparator = (Char -> Bool) -> [Char] -> Bool
    forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
    all Char -> Bool
    isSpace

    contentsPage :: [ImportName] -> [(ImportName, Html)] -> Html
    contentsPage :: [ImportName] -> [(ImportName, Html)] -> Html
    contentsPage [ImportName]
    important_imports [(ImportName, Html)]
    pages =
      Html -> Html
    H.docTypeHtml (Html -> Html) -> Html -> Html
    forall a b. (a -> b) -> a -> b
    $
        [Char] -> [Char] -> Html -> Html
    addBoilerplate [Char]
    "index.html" [Char]
    "Futhark Library Documentation" (Html -> Html) -> Html -> Html
    forall a b. (a -> b) -> a -> b
    $
          Html -> Html
    H.main (Html -> Html) -> Html -> Html
    forall a b. (a -> b) -> a -> b
    $
            ( if [(ImportName, Html)] -> Bool
    forall a. [a] -> Bool
    forall (t :: * -> *) a. Foldable t => t a -> Bool
    null [(ImportName, Html)]
    important_pages
                then Html
    forall a. Monoid a => a
    mempty
                else Html -> Html
    H.h2 Html
    "Main libraries" Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <> [(ImportName, Html)] -> Html
    fileList [(ImportName, Html)]
    important_pages
            )
              Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <> ( if [(ImportName, Html)] -> Bool
    forall a. [a] -> Bool
    forall (t :: * -> *) a. Foldable t => t a -> Bool
    null [(ImportName, Html)]
    unimportant_pages
                     then Html
    forall a. Monoid a => a
    mempty
                     else Html -> Html
    H.h2 Html
    "Supporting libraries" Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <> [(ImportName, Html)] -> Html
    fileList [(ImportName, Html)]
    unimportant_pages
                 )
      where
        ([(ImportName, Html)]
    important_pages, [(ImportName, Html)]
    unimportant_pages) =
          ((ImportName, Html) -> Bool)
    -> [(ImportName, Html)]
    -> ([(ImportName, Html)], [(ImportName, Html)])
    forall a. (a -> Bool) -> [a] -> ([a], [a])
    partition ((ImportName -> [ImportName] -> Bool
    forall a. Eq a => a -> [a] -> Bool
    forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
    `elem` [ImportName]
    important_imports) (ImportName -> Bool)
    -> ((ImportName, Html) -> ImportName) -> (ImportName, Html) -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (ImportName, Html) -> ImportName
    forall a b. (a, b) -> a
    fst) [(ImportName, Html)]
    pages

        fileList :: [(ImportName, Html)] -> Html
    fileList [(ImportName, Html)]
    pages' =
          Html -> Html
    H.dl (Html -> Html) -> Attribute -> Html -> Html
    forall h. Attributable h => h -> Attribute -> h
    ! AttributeValue -> Attribute
    A.class_ AttributeValue
    "file_list" (Html -> Html) -> Html -> Html
    forall a b. (a -> b) -> a -> b
    $
            [Html] -> Html
    forall a. Monoid a => [a] -> a
    mconcat ([Html] -> Html) -> [Html] -> Html
    forall a b. (a -> b) -> a -> b
    $
              ((ImportName, Html) -> Html) -> [(ImportName, Html)] -> [Html]
    forall a b. (a -> b) -> [a] -> [b]
    map (ImportName, Html) -> Html
    linkTo ([(ImportName, Html)] -> [Html]) -> [(ImportName, Html)] -> [Html]
    forall a b. (a -> b) -> a -> b
    $
                ((ImportName, Html) -> ImportName)
    -> [(ImportName, Html)] -> [(ImportName, Html)]
    forall b a. Ord b => (a -> b) -> [a] -> [a]
    sortOn (ImportName, Html) -> ImportName
    forall a b. (a, b) -> a
    fst [(ImportName, Html)]
    pages'

        linkTo :: (ImportName, Html) -> Html
    linkTo (ImportName
    name, Html
    maybe_abstract) =
          Html -> Html
    H.div (Html -> Html) -> Attribute -> Html -> Html
    forall h. Attributable h => h -> Attribute -> h
    ! AttributeValue -> Attribute
    A.class_ AttributeValue
    "file_desc" (Html -> Html) -> Html -> Html
    forall a b. (a -> b) -> a -> b
    $
            (Html -> Html
    H.dt (Html -> Html) -> Attribute -> Html -> Html
    forall h. Attributable h => h -> Attribute -> h
    ! AttributeValue -> Attribute
    A.class_ AttributeValue
    "desc_header") ([Char] -> ImportName -> Html
    importLink [Char]
    "index.html" ImportName
    name)
              Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <> (Html -> Html
    H.dd (Html -> Html) -> Attribute -> Html -> Html
    forall h. Attributable h => h -> Attribute -> h
    ! AttributeValue -> Attribute
    A.class_ AttributeValue
    "desc_doc") Html
    maybe_abstract

    importLink :: FilePath -> ImportName -> Html
    importLink :: [Char] -> ImportName -> Html
    importLink [Char]
    current ImportName
    name =
      let file :: [Char]
    file =
            [Char] -> [Char] -> [Char]
    relativise
              ([Char]
    "doc" [Char] -> [Char] -> [Char]
    </> [Char] -> [Char] -> [Char]
    makeRelative [Char]
    "/" (ImportName -> [Char]
    includeToFilePath ImportName
    name) [Char] -> [Char] -> [Char]
    -<.> [Char]
    "html")
              [Char]
    current
       in (Html -> Html
    H.a (Html -> Html) -> Attribute -> Html -> Html
    forall h. Attributable h => h -> Attribute -> h
    ! AttributeValue -> Attribute
    A.href ([Char] -> AttributeValue
    forall a. IsString a => [Char] -> a
    fromString [Char]
    file) (Html -> Html) -> Html -> Html
    forall a b. (a -> b) -> a -> b
    $ [Char] -> Html
    forall a. IsString a => [Char] -> a
    fromString (ImportName -> [Char]
    includeToString ImportName
    name))

    indexPage :: [ImportName] -> Imports -> Documented -> FileMap -> Html
    indexPage :: [ImportName] -> Imports -> Documented -> FileMap -> Html
    indexPage [ImportName]
    important_imports Imports
    imports Documented
    documented FileMap
    fm =
      Html -> Html
    H.docTypeHtml (Html -> Html) -> Html -> Html
    forall a b. (a -> b) -> a -> b
    $
        [ImportName] -> Imports -> [Char] -> [Char] -> Html -> Html
    addBoilerplateWithNav [ImportName]
    important_imports Imports
    imports [Char]
    "doc-index.html" [Char]
    "Index" (Html -> Html) -> Html -> Html
    forall a b. (a -> b) -> a -> b
    $
          Html -> Html
    H.main (Html -> Html) -> Html -> Html
    forall a b. (a -> b) -> a -> b
    $
            ( Html -> Html
    H.ul (Html -> Html) -> Attribute -> Html -> Html
    forall h. Attributable h => h -> Attribute -> h
    ! AttributeValue -> Attribute
    A.id AttributeValue
    "doc_index_list" (Html -> Html) -> Html -> Html
    forall a b. (a -> b) -> a -> b
    $
                [Html] -> Html
    forall a. Monoid a => [a] -> a
    mconcat ([Html] -> Html) -> [Html] -> Html
    forall a b. (a -> b) -> a -> b
    $
                  ([Char] -> Html) -> [[Char]] -> [Html]
    forall a b. (a -> b) -> [a] -> [b]
    map [Char] -> Html
    initialListEntry ([[Char]] -> [Html]) -> [[Char]] -> [Html]
    forall a b. (a -> b) -> a -> b
    $
                    [[Char]]
    letter_group_links [[Char]] -> [[Char]] -> [[Char]]
    forall a. [a] -> [a] -> [a]
    ++ [[Char]
    symbol_group_link]
            )
              Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <> ( Html -> Html
    H.table (Html -> Html) -> Attribute -> Html -> Html
    forall h. Attributable h => h -> Attribute -> h
    ! AttributeValue -> Attribute
    A.id AttributeValue
    "doc_index" (Html -> Html) -> Html -> Html
    forall a b. (a -> b) -> a -> b
    $
                     Html -> Html
    H.thead (Html -> Html
    H.tr (Html -> Html) -> Html -> Html
    forall a b. (a -> b) -> a -> b
    $ Html -> Html
    H.td Html
    "Who" Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <> Html -> Html
    H.td Html
    "What" Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <> Html -> Html
    H.td Html
    "Where")
                       Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <> [Html] -> Html
    forall a. Monoid a => [a] -> a
    mconcat ([Html]
    letter_groups [Html] -> [Html] -> [Html]
    forall a. [a] -> [a] -> [a]
    ++ [Html
    symbol_group])
                 )
      where
        ([(VName, ([Char], (IndexWhat, [Char])))]
    letter_names, [(VName, ([Char], (IndexWhat, [Char])))]
    sym_names) =
          ((VName, ([Char], (IndexWhat, [Char]))) -> Bool)
    -> [(VName, ([Char], (IndexWhat, [Char])))]
    -> ([(VName, ([Char], (IndexWhat, [Char])))],
        [(VName, ([Char], (IndexWhat, [Char])))])
    forall a. (a -> Bool) -> [a] -> ([a], [a])
    partition ([Char] -> Bool
    isLetterName ([Char] -> Bool)
    -> ((VName, ([Char], (IndexWhat, [Char]))) -> [Char])
    -> (VName, ([Char], (IndexWhat, [Char])))
    -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . VName -> [Char]
    baseString (VName -> [Char])
    -> ((VName, ([Char], (IndexWhat, [Char]))) -> VName)
    -> (VName, ([Char], (IndexWhat, [Char])))
    -> [Char]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (VName, ([Char], (IndexWhat, [Char]))) -> VName
    forall a b. (a, b) -> a
    fst) ([(VName, ([Char], (IndexWhat, [Char])))]
     -> ([(VName, ([Char], (IndexWhat, [Char])))],
         [(VName, ([Char], (IndexWhat, [Char])))]))
    -> [(VName, ([Char], (IndexWhat, [Char])))]
    -> ([(VName, ([Char], (IndexWhat, [Char])))],
        [(VName, ([Char], (IndexWhat, [Char])))])
    forall a b. (a -> b) -> a -> b
    $
            ((VName, ([Char], (IndexWhat, [Char]))) -> [Char])
    -> [(VName, ([Char], (IndexWhat, [Char])))]
    -> [(VName, ([Char], (IndexWhat, [Char])))]
    forall b a. Ord b => (a -> b) -> [a] -> [a]
    sortOn ((Char -> Char) -> [Char] -> [Char]
    forall a b. (a -> b) -> [a] -> [b]
    map Char -> Char
    toUpper ([Char] -> [Char])
    -> ((VName, ([Char], (IndexWhat, [Char]))) -> [Char])
    -> (VName, ([Char], (IndexWhat, [Char])))
    -> [Char]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . VName -> [Char]
    baseString (VName -> [Char])
    -> ((VName, ([Char], (IndexWhat, [Char]))) -> VName)
    -> (VName, ([Char], (IndexWhat, [Char])))
    -> [Char]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (VName, ([Char], (IndexWhat, [Char]))) -> VName
    forall a b. (a, b) -> a
    fst) ([(VName, ([Char], (IndexWhat, [Char])))]
     -> [(VName, ([Char], (IndexWhat, [Char])))])
    -> [(VName, ([Char], (IndexWhat, [Char])))]
    -> [(VName, ([Char], (IndexWhat, [Char])))]
    forall a b. (a -> b) -> a -> b
    $
              ((VName, ([Char], [Char]))
     -> Maybe (VName, ([Char], (IndexWhat, [Char]))))
    -> [(VName, ([Char], [Char]))]
    -> [(VName, ([Char], (IndexWhat, [Char])))]
    forall a b. (a -> Maybe b) -> [a] -> [b]
    mapMaybe (VName, ([Char], [Char]))
    -> Maybe (VName, ([Char], (IndexWhat, [Char])))
    forall {a} {b}.
    (VName, (a, b)) -> Maybe (VName, (a, (IndexWhat, b)))
    isDocumented ([(VName, ([Char], [Char]))]
     -> [(VName, ([Char], (IndexWhat, [Char])))])
    -> [(VName, ([Char], [Char]))]
    -> [(VName, ([Char], (IndexWhat, [Char])))]
    forall a b. (a -> b) -> a -> b
    $
                FileMap -> [(VName, ([Char], [Char]))]
    forall k a. Map k a -> [(k, a)]
    M.toList FileMap
    fm

        isDocumented :: (VName, (a, b)) -> Maybe (VName, (a, (IndexWhat, b)))
    isDocumented (VName
    k, (a
    file, b
    k_id)) = do
          what <- VName -> Documented -> Maybe IndexWhat
    forall k a. Ord k => k -> Map k a -> Maybe a
    M.lookup VName
    k Documented
    documented
          Just (k, (file, (what, k_id)))

        ([Html]
    letter_groups, [[Char]]
    letter_group_links) =
          [(Html, [Char])] -> ([Html], [[Char]])
    forall a b. [(a, b)] -> ([a], [b])
    unzip ([(Html, [Char])] -> ([Html], [[Char]]))
    -> [(Html, [Char])] -> ([Html], [[Char]])
    forall a b. (a -> b) -> a -> b
    $ ([(VName, ([Char], (IndexWhat, [Char])))] -> (Html, [Char]))
    -> [[(VName, ([Char], (IndexWhat, [Char])))]] -> [(Html, [Char])]
    forall a b. (a -> b) -> [a] -> [b]
    map [(VName, ([Char], (IndexWhat, [Char])))] -> (Html, [Char])
    tbodyForNames ([[(VName, ([Char], (IndexWhat, [Char])))]] -> [(Html, [Char])])
    -> [[(VName, ([Char], (IndexWhat, [Char])))]] -> [(Html, [Char])]
    forall a b. (a -> b) -> a -> b
    $ ((VName, ([Char], (IndexWhat, [Char])))
     -> (VName, ([Char], (IndexWhat, [Char]))) -> Bool)
    -> [(VName, ([Char], (IndexWhat, [Char])))]
    -> [[(VName, ([Char], (IndexWhat, [Char])))]]
    forall a. (a -> a -> Bool) -> [a] -> [[a]]
    groupBy (VName, ([Char], (IndexWhat, [Char])))
    -> (VName, ([Char], (IndexWhat, [Char]))) -> Bool
    forall {b} {b}. (VName, b) -> (VName, b) -> Bool
    sameInitial [(VName, ([Char], (IndexWhat, [Char])))]
    letter_names
        (Html
    symbol_group, [Char]
    symbol_group_link) =
          [Char]
    -> [(VName, ([Char], (IndexWhat, [Char])))] -> (Html, [Char])
    tbodyForInitial [Char]
    "Symbols" [(VName, ([Char], (IndexWhat, [Char])))]
    sym_names

        isLetterName :: [Char] -> Bool
    isLetterName [] = Bool
    False
        isLetterName (Char
    c : [Char]
    _) = Char -> Bool
    isAlpha Char
    c

        sameInitial :: (VName, b) -> (VName, b) -> Bool
    sameInitial (VName
    x, b
    _) (VName
    y, b
    _) =
          case (VName -> [Char]
    baseString VName
    x, VName -> [Char]
    baseString VName
    y) of
            (Char
    x' : [Char]
    _, Char
    y' : [Char]
    _) -> Char -> Char
    toUpper Char
    x' Char -> Char -> Bool
    forall a. Eq a => a -> a -> Bool
    == Char -> Char
    toUpper Char
    y'
            ([Char], [Char])
    _ -> Bool
    False

        tbodyForNames :: [(VName, ([Char], (IndexWhat, [Char])))] -> (Html, [Char])
    tbodyForNames names :: [(VName, ([Char], (IndexWhat, [Char])))]
    names@((VName
    s, ([Char], (IndexWhat, [Char]))
    _) : [(VName, ([Char], (IndexWhat, [Char])))]
    _) =
          [Char]
    -> [(VName, ([Char], (IndexWhat, [Char])))] -> (Html, [Char])
    tbodyForInitial ((Char -> Char) -> [Char] -> [Char]
    forall a b. (a -> b) -> [a] -> [b]
    map Char -> Char
    toUpper ([Char] -> [Char]) -> [Char] -> [Char]
    forall a b. (a -> b) -> a -> b
    $ Int -> [Char] -> [Char]
    forall a. Int -> [a] -> [a]
    take Int
    1 ([Char] -> [Char]) -> [Char] -> [Char]
    forall a b. (a -> b) -> a -> b
    $ VName -> [Char]
    baseString VName
    s) [(VName, ([Char], (IndexWhat, [Char])))]
    names
        tbodyForNames [(VName, ([Char], (IndexWhat, [Char])))]
    _ = (Html, [Char])
    forall a. Monoid a => a
    mempty

        tbodyForInitial :: [Char]
    -> [(VName, ([Char], (IndexWhat, [Char])))] -> (Html, [Char])
    tbodyForInitial [Char]
    initial [(VName, ([Char], (IndexWhat, [Char])))]
    names =
          ( Html -> Html
    H.tbody (Html -> Html) -> Html -> Html
    forall a b. (a -> b) -> a -> b
    $ [Html] -> Html
    forall a. Monoid a => [a] -> a
    mconcat ([Html] -> Html) -> [Html] -> Html
    forall a b. (a -> b) -> a -> b
    $ Html
    initial' Html -> [Html] -> [Html]
    forall a. a -> [a] -> [a]
    : ((VName, ([Char], (IndexWhat, [Char]))) -> Html)
    -> [(VName, ([Char], (IndexWhat, [Char])))] -> [Html]
    forall a b. (a -> b) -> [a] -> [b]
    map (VName, ([Char], (IndexWhat, [Char]))) -> Html
    linkTo [(VName, ([Char], (IndexWhat, [Char])))]
    names,
            [Char]
    initial
          )
          where
            initial' :: Html
    initial' =
              Html -> Html
    H.tr
                (Html -> Html) -> Html -> Html
    forall a b. (a -> b) -> a -> b
    $ Html -> Html
    H.td (Html -> Html) -> Attribute -> Html -> Html
    forall h. Attributable h => h -> Attribute -> h
    ! AttributeValue -> Attribute
    A.colspan AttributeValue
    "2" (Html -> Html) -> Attribute -> Html -> Html
    forall h. Attributable h => h -> Attribute -> h
    ! AttributeValue -> Attribute
    A.class_ AttributeValue
    "doc_index_initial"
                (Html -> Html) -> Html -> Html
    forall a b. (a -> b) -> a -> b
    $ Html -> Html
    H.a
                  (Html -> Html) -> Attribute -> Html -> Html
    forall h. Attributable h => h -> Attribute -> h
    ! AttributeValue -> Attribute
    A.id ([Char] -> AttributeValue
    forall a. IsString a => [Char] -> a
    fromString [Char]
    initial)
                  (Html -> Html) -> Attribute -> Html -> Html
    forall h. Attributable h => h -> Attribute -> h
    ! AttributeValue -> Attribute
    A.href ([Char] -> AttributeValue
    forall a. IsString a => [Char] -> a
    fromString ([Char] -> AttributeValue) -> [Char] -> AttributeValue
    forall a b. (a -> b) -> a -> b
    $ Char
    '#' Char -> [Char] -> [Char]
    forall a. a -> [a] -> [a]
    : [Char]
    initial)
                (Html -> Html) -> Html -> Html
    forall a b. (a -> b) -> a -> b
    $ [Char] -> Html
    forall a. IsString a => [Char] -> a
    fromString [Char]
    initial

        initialListEntry :: [Char] -> Html
    initialListEntry [Char]
    initial =
          Html -> Html
    H.li (Html -> Html) -> Html -> Html
    forall a b. (a -> b) -> a -> b
    $ Html -> Html
    H.a (Html -> Html) -> Attribute -> Html -> Html
    forall h. Attributable h => h -> Attribute -> h
    ! AttributeValue -> Attribute
    A.href ([Char] -> AttributeValue
    forall a. IsString a => [Char] -> a
    fromString ([Char] -> AttributeValue) -> [Char] -> AttributeValue
    forall a b. (a -> b) -> a -> b
    $ Char
    '#' Char -> [Char] -> [Char]
    forall a. a -> [a] -> [a]
    : [Char]
    initial) (Html -> Html) -> Html -> Html
    forall a b. (a -> b) -> a -> b
    $ [Char] -> Html
    forall a. IsString a => [Char] -> a
    fromString [Char]
    initial

        linkTo :: (VName, ([Char], (IndexWhat, [Char]))) -> Html
    linkTo (VName
    name, ([Char]
    file, (IndexWhat
    what, [Char]
    name_id))) =
          let file' :: [Char]
    file' = [Char] -> [Char] -> [Char]
    makeRelative [Char]
    "/" [Char]
    file
              name_link :: [Char]
    name_link = [Char] -> [Char] -> [Char] -> [Char]
    vnameLink' [Char]
    name_id [Char]
    "" [Char]
    file'
              link :: Html
    link =
                (Html -> Html
    H.a (Html -> Html) -> Attribute -> Html -> Html
    forall h. Attributable h => h -> Attribute -> h
    ! AttributeValue -> Attribute
    A.href ([Char] -> AttributeValue
    forall a. IsString a => [Char] -> a
    fromString ([Char] -> [Char] -> [Char]
    makeRelative [Char]
    "/" ([Char] -> [Char]) -> [Char] -> [Char]
    forall a b. (a -> b) -> a -> b
    $ [Char]
    "doc" [Char] -> [Char] -> [Char]
    </> [Char]
    name_link))) (Html -> Html) -> Html -> Html
    forall a b. (a -> b) -> a -> b
    $
                  [Char] -> Html
    forall a. IsString a => [Char] -> a
    fromString ([Char] -> Html) -> [Char] -> Html
    forall a b. (a -> b) -> a -> b
    $
                    VName -> [Char]
    baseString VName
    name
              what' :: Html
    what' = case IndexWhat
    what of
                IndexWhat
    IndexValue -> Html
    "value"
                IndexWhat
    IndexFunction -> Html
    "function"
                IndexWhat
    IndexType -> Html
    "type"
                IndexWhat
    IndexModuleType -> Html
    "module type"
                IndexWhat
    IndexModule -> Html
    "module"
              html_file :: [Char]
    html_file = [Char]
    "doc" [Char] -> [Char] -> [Char]
    </> [Char]
    file' [Char] -> [Char] -> [Char]
    -<.> [Char]
    "html"
           in Html -> Html
    H.tr (Html -> Html) -> Html -> Html
    forall a b. (a -> b) -> a -> b
    $
                (Html -> Html
    H.td (Html -> Html) -> Attribute -> Html -> Html
    forall h. Attributable h => h -> Attribute -> h
    ! AttributeValue -> Attribute
    A.class_ AttributeValue
    "doc_index_name" (Html -> Html) -> Html -> Html
    forall a b. (a -> b) -> a -> b
    $ Html
    link)
                  Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <> (Html -> Html
    H.td (Html -> Html) -> Attribute -> Html -> Html
    forall h. Attributable h => h -> Attribute -> h
    ! AttributeValue -> Attribute
    A.class_ AttributeValue
    "doc_index_namespace" (Html -> Html) -> Html -> Html
    forall a b. (a -> b) -> a -> b
    $ Html
    what')
                  Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <> ( Html -> Html
    H.td (Html -> Html) -> Attribute -> Html -> Html
    forall h. Attributable h => h -> Attribute -> h
    ! AttributeValue -> Attribute
    A.class_ AttributeValue
    "doc_index_file" (Html -> Html) -> Html -> Html
    forall a b. (a -> b) -> a -> b
    $
                         (Html -> Html
    H.a (Html -> Html) -> Attribute -> Html -> Html
    forall h. Attributable h => h -> Attribute -> h
    ! AttributeValue -> Attribute
    A.href ([Char] -> AttributeValue
    forall a. IsString a => [Char] -> a
    fromString [Char]
    html_file) (Html -> Html) -> Html -> Html
    forall a b. (a -> b) -> a -> b
    $ [Char] -> Html
    forall a. IsString a => [Char] -> a
    fromString [Char]
    file)
                     )

    addBoilerplate :: String -> String -> Html -> Html
    addBoilerplate :: [Char] -> [Char] -> Html -> Html
    addBoilerplate [Char]
    current [Char]
    titleText Html
    content =
      let headHtml :: Html
    headHtml =
            Html -> Html
    H.head (Html -> Html) -> Html -> Html
    forall a b. (a -> b) -> a -> b
    $
              Html
    H.meta
                Html -> Attribute -> Html
    forall h. Attributable h => h -> Attribute -> h
    ! AttributeValue -> Attribute
    A.charset AttributeValue
    "utf-8"
                Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <> Html -> Html
    H.title ([Char] -> Html
    forall a. IsString a => [Char] -> a
    fromString [Char]
    titleText)
                Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <> Html
    H.link
                  Html -> Attribute -> Html
    forall h. Attributable h => h -> Attribute -> h
    ! AttributeValue -> Attribute
    A.href ([Char] -> AttributeValue
    forall a. IsString a => [Char] -> a
    fromString ([Char] -> AttributeValue) -> [Char] -> AttributeValue
    forall a b. (a -> b) -> a -> b
    $ [Char] -> [Char] -> [Char]
    relativise [Char]
    "style.css" [Char]
    current)
                  Html -> Attribute -> Html
    forall h. Attributable h => h -> Attribute -> h
    ! AttributeValue -> Attribute
    A.rel AttributeValue
    "stylesheet"
                  Html -> Attribute -> Html
    forall h. Attributable h => h -> Attribute -> h
    ! AttributeValue -> Attribute
    A.type_ AttributeValue
    "text/css"

          navigation :: Html
    navigation =
            Html -> Html
    H.ul (Html -> Html) -> Attribute -> Html -> Html
    forall h. Attributable h => h -> Attribute -> h
    ! AttributeValue -> Attribute
    A.id AttributeValue
    "navigation" (Html -> Html) -> Html -> Html
    forall a b. (a -> b) -> a -> b
    $
              Html -> Html
    H.li (Html -> Html
    H.a (Html -> Html) -> Attribute -> Html -> Html
    forall h. Attributable h => h -> Attribute -> h
    ! AttributeValue -> Attribute
    A.href ([Char] -> AttributeValue
    forall a. IsString a => [Char] -> a
    fromString ([Char] -> AttributeValue) -> [Char] -> AttributeValue
    forall a b. (a -> b) -> a -> b
    $ [Char] -> [Char] -> [Char]
    relativise [Char]
    "index.html" [Char]
    current) (Html -> Html) -> Html -> Html
    forall a b. (a -> b) -> a -> b
    $ Html
    "Contents")
                Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <> Html -> Html
    H.li (Html -> Html
    H.a (Html -> Html) -> Attribute -> Html -> Html
    forall h. Attributable h => h -> Attribute -> h
    ! AttributeValue -> Attribute
    A.href ([Char] -> AttributeValue
    forall a. IsString a => [Char] -> a
    fromString ([Char] -> AttributeValue) -> [Char] -> AttributeValue
    forall a b. (a -> b) -> a -> b
    $ [Char] -> [Char] -> [Char]
    relativise [Char]
    "doc-index.html" [Char]
    current) (Html -> Html) -> Html -> Html
    forall a b. (a -> b) -> a -> b
    $ Html
    "Index")

          madeByHtml :: Html
    madeByHtml =
            Html
    "Generated by "
              Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <> (Html -> Html
    H.a (Html -> Html) -> Attribute -> Html -> Html
    forall h. Attributable h => h -> Attribute -> h
    ! AttributeValue -> Attribute
    A.href AttributeValue
    futhark_doc_url) Html
    "futhark-doc"
              Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <> Html
    " "
              Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <> [Char] -> Html
    forall a. IsString a => [Char] -> a
    fromString (Version -> [Char]
    showVersion Version
    version)
       in Html
    headHtml
            Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <> Html -> Html
    H.body
              ( (Html -> Html
    H.div (Html -> Html) -> Attribute -> Html -> Html
    forall h. Attributable h => h -> Attribute -> h
    ! AttributeValue -> Attribute
    A.id AttributeValue
    "header") (Html -> Html
    H.h1 ([Char] -> Html
    forall a. ToMarkup a => a -> Html
    toHtml [Char]
    titleText) Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <> Html
    navigation)
                  Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <> (Html -> Html
    H.div (Html -> Html) -> Attribute -> Html -> Html
    forall h. Attributable h => h -> Attribute -> h
    ! AttributeValue -> Attribute
    A.id AttributeValue
    "content") Html
    content
                  Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <> (Html -> Html
    H.div (Html -> Html) -> Attribute -> Html -> Html
    forall h. Attributable h => h -> Attribute -> h
    ! AttributeValue -> Attribute
    A.id AttributeValue
    "footer") Html
    madeByHtml
              )
      where
        futhark_doc_url :: AttributeValue
    futhark_doc_url =
          AttributeValue
    "https://futhark.readthedocs.io/en/latest/man/futhark-doc.html"

    addBoilerplateWithNav :: [ImportName] -> Imports -> String -> String -> Html -> Html
    addBoilerplateWithNav :: [ImportName] -> Imports -> [Char] -> [Char] -> Html -> Html
    addBoilerplateWithNav [ImportName]
    important_imports Imports
    imports [Char]
    current [Char]
    titleText Html
    content =
      [Char] -> [Char] -> Html -> Html
    addBoilerplate [Char]
    current [Char]
    titleText (Html -> Html) -> Html -> Html
    forall a b. (a -> b) -> a -> b
    $
        (Html -> Html
    H.nav (Html -> Html) -> Attribute -> Html -> Html
    forall h. Attributable h => h -> Attribute -> h
    ! AttributeValue -> Attribute
    A.id AttributeValue
    "filenav" (Html -> Html) -> Html -> Html
    forall a b. (a -> b) -> a -> b
    $ Html
    files) Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <> Html
    content
      where
        files :: Html
    files = Html -> Html
    H.ul (Html -> Html) -> Html -> Html
    forall a b. (a -> b) -> a -> b
    $ [Html] -> Html
    forall a. Monoid a => [a] -> a
    mconcat ([Html] -> Html) -> [Html] -> Html
    forall a b. (a -> b) -> a -> b
    $ (ImportName -> Html) -> [ImportName] -> [Html]
    forall a b. (a -> b) -> [a] -> [b]
    map ImportName -> Html
    pp ([ImportName] -> [Html]) -> [ImportName] -> [Html]
    forall a b. (a -> b) -> a -> b
    $ [ImportName] -> [ImportName]
    forall a. Ord a => [a] -> [a]
    sort ([ImportName] -> [ImportName]) -> [ImportName] -> [ImportName]
    forall a b. (a -> b) -> a -> b
    $ (ImportName -> Bool) -> [ImportName] -> [ImportName]
    forall a. (a -> Bool) -> [a] -> [a]
    filter ImportName -> Bool
    visible [ImportName]
    important_imports
        pp :: ImportName -> Html
    pp ImportName
    name = Html -> Html
    H.li (Html -> Html) -> Html -> Html
    forall a b. (a -> b) -> a -> b
    $ [Char] -> ImportName -> Html
    importLink [Char]
    current ImportName
    name
        visible :: ImportName -> Bool
    visible = (ImportName -> [ImportName] -> Bool
    forall a. Eq a => a -> [a] -> Bool
    forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
    `elem` ((ImportName, FileModule) -> ImportName) -> Imports -> [ImportName]
    forall a b. (a -> b) -> [a] -> [b]
    map (ImportName, FileModule) -> ImportName
    forall a b. (a, b) -> a
    fst Imports
    imports)

    synopsisDecs :: [Dec] -> DocM Html
    synopsisDecs :: [Dec] -> DocM Html
    synopsisDecs [Dec]
    decs = do
      visible <- (Context -> NoLink)
    -> ReaderT Context (WriterT Documented (Writer Warnings)) NoLink
    forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
    asks Context -> NoLink
    ctxVisibleMTys
      fm <- asks ctxFileMod
      -- We add an empty row to avoid generating invalid HTML in cases
      -- where all rows are otherwise colspan=2.
      (H.table ! A.class_ "specs") . (emptyRow <>) . mconcat
        <$> sequence (mapMaybe (synopsisDec visible fm) decs)

    synopsisDec :: S.Set VName -> FileModule -> Dec -> Maybe (DocM Html)
    synopsisDec :: NoLink -> FileModule -> Dec -> Maybe (DocM Html)
    synopsisDec NoLink
    visible FileModule
    fm Dec
    dec = case Dec
    dec of
      ModTypeDec ModTypeBindBase Info VName
    s -> Html -> ModTypeBindBase Info VName -> Maybe (DocM Html)
    synopsisModType Html
    forall a. Monoid a => a
    mempty ModTypeBindBase Info VName
    s
      ModDec ModBindBase Info VName
    m -> FileModule -> ModBindBase Info VName -> Maybe (DocM Html)
    synopsisMod FileModule
    fm ModBindBase Info VName
    m
      ValDec ValBindBase Info VName
    v -> ValBindBase Info VName -> Maybe (DocM Html)
    synopsisValBind ValBindBase Info VName
    v
      TypeDec TypeBindBase Info VName
    t -> TypeBindBase Info VName -> Maybe (DocM Html)
    synopsisType TypeBindBase Info VName
    t
      OpenDec ModExpBase Info VName
    x SrcLoc
    _
        | Just DocM Html
    opened <- ModExpBase Info VName -> Maybe (DocM Html)
    synopsisOpened ModExpBase Info VName
    x -> DocM Html -> Maybe (DocM Html)
    forall a. a -> Maybe a
    Just (DocM Html -> Maybe (DocM Html)) -> DocM Html -> Maybe (DocM Html)
    forall a b. (a -> b) -> a -> b
    $ do
            opened' <- DocM Html
    opened
            pure $ fullRow $ keyword "open " <> opened'
        | Bool
    otherwise ->
            DocM Html -> Maybe (DocM Html)
    forall a. a -> Maybe a
    Just (DocM Html -> Maybe (DocM Html)) -> DocM Html -> Maybe (DocM Html)
    forall a b. (a -> b) -> a -> b
    $
              Html -> DocM Html
    forall a.
    a -> ReaderT Context (WriterT Documented (Writer Warnings)) a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure (Html -> DocM Html) -> Html -> DocM Html
    forall a b. (a -> b) -> a -> b
    $
                Html -> Html
    fullRow (Html -> Html) -> Html -> Html
    forall a b. (a -> b) -> a -> b
    $
                  [Char] -> Html
    keyword [Char]
    "open" Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <> [Char] -> Html
    forall a. IsString a => [Char] -> a
    fromString ([Char]
    " <" [Char] -> [Char] -> [Char]
    forall a. Semigroup a => a -> a -> a
    <> ModExpBase Info VName -> [Char]
    forall a. Pretty a => a -> [Char]
    prettyString ModExpBase Info VName
    x [Char] -> [Char] -> [Char]
    forall a. Semigroup a => a -> a -> a
    <> [Char]
    ">")
      LocalDec (ModTypeDec ModTypeBindBase Info VName
    s) SrcLoc
    _
        | ModTypeBindBase Info VName -> VName
    forall (f :: * -> *) vn. ModTypeBindBase f vn -> vn
    modTypeName ModTypeBindBase Info VName
    s VName -> NoLink -> Bool
    forall a. Ord a => a -> Set a -> Bool
    `S.member` NoLink
    visible ->
            Html -> ModTypeBindBase Info VName -> Maybe (DocM Html)
    synopsisModType ([Char] -> Html
    keyword [Char]
    "local" Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <> Html
    " ") ModTypeBindBase Info VName
    s
      LocalDec {} -> Maybe (DocM Html)
    forall a. Maybe a
    Nothing
      ImportDec {} -> Maybe (DocM Html)
    forall a. Maybe a
    Nothing

    synopsisOpened :: ModExp -> Maybe (DocM Html)
    synopsisOpened :: ModExpBase Info VName -> Maybe (DocM Html)
    synopsisOpened (ModVar QualName VName
    qn SrcLoc
    _) = DocM Html -> Maybe (DocM Html)
    forall a. a -> Maybe a
    Just (DocM Html -> Maybe (DocM Html)) -> DocM Html -> Maybe (DocM Html)
    forall a b. (a -> b) -> a -> b
    $ QualName VName -> DocM Html
    qualNameHtml QualName VName
    qn
    synopsisOpened (ModParens ModExpBase Info VName
    me SrcLoc
    _) = do
      me' <- ModExpBase Info VName -> Maybe (DocM Html)
    synopsisOpened ModExpBase Info VName
    me
      Just $ parens <$> me'
    synopsisOpened (ModImport [Char]
    _ (Info ImportName
    file) SrcLoc
    _) = DocM Html -> Maybe (DocM Html)
    forall a. a -> Maybe a
    Just (DocM Html -> Maybe (DocM Html)) -> DocM Html -> Maybe (DocM Html)
    forall a b. (a -> b) -> a -> b
    $ do
      current <- (Context -> [Char])
    -> ReaderT Context (WriterT Documented (Writer Warnings)) [Char]
    forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
    asks Context -> [Char]
    ctxCurrent
      let dest = [Char] -> AttributeValue
    forall a. IsString a => [Char] -> a
    fromString ([Char] -> AttributeValue) -> [Char] -> AttributeValue
    forall a b. (a -> b) -> a -> b
    $ [Char] -> [Char] -> [Char]
    relativise (ImportName -> [Char]
    includeToFilePath ImportName
    file) [Char]
    current [Char] -> [Char] -> [Char]
    -<.> [Char]
    "html"
      pure $
        keyword "import "
          <> (H.a ! A.href dest) (fromString (show (includeToString file)))
    synopsisOpened (ModAscript ModExpBase Info VName
    _ ModTypeExpBase Info VName
    se Info (Map VName VName)
    _ SrcLoc
    _) = DocM Html -> Maybe (DocM Html)
    forall a. a -> Maybe a
    Just (DocM Html -> Maybe (DocM Html)) -> DocM Html -> Maybe (DocM Html)
    forall a b. (a -> b) -> a -> b
    $ do
      se' <- ModTypeExpBase Info VName -> DocM Html
    synopsisModTypeExp ModTypeExpBase Info VName
    se
      pure $ "... : " <> se'
    synopsisOpened ModExpBase Info VName
    _ = Maybe (DocM Html)
    forall a. Maybe a
    Nothing

    vnameSynopsisDef :: VName -> DocM Html
    vnameSynopsisDef :: VName -> DocM Html
    vnameSynopsisDef VName
    vname = do
      (_, vname_id) <- VName -> DocM ([Char], [Char])
    vnameId VName
    vname
      pure $
        H.span ! A.id (fromString ("synopsis:" <> vname_id)) $
          H.a ! A.href (fromString ("#" ++ vname_id)) $
            if symbolName (baseName vname)
              then parens (renderName (baseName vname))
              else renderName (baseName vname)

    synopsisValBind :: ValBind -> Maybe (DocM Html)
    synopsisValBind :: ValBindBase Info VName -> Maybe (DocM Html)
    synopsisValBind ValBindBase Info VName
    vb = DocM Html -> Maybe (DocM Html)
    forall a. a -> Maybe a
    Just (DocM Html -> Maybe (DocM Html)) -> DocM Html -> Maybe (DocM Html)
    forall a b. (a -> b) -> a -> b
    $ do
      name' <- VName -> DocM Html
    vnameSynopsisDef (VName -> DocM Html) -> VName -> DocM Html
    forall a b. (a -> b) -> a -> b
    $ ValBindBase Info VName -> VName
    forall (f :: * -> *) vn. ValBindBase f vn -> vn
    valBindName ValBindBase Info VName
    vb
      (lhs, mhs, rhs) <- valBindHtml name' vb
      pure $ specRow lhs (mhs <> " : ") rhs

    valBindHtml :: Html -> ValBind -> DocM (Html, Html, Html)
    valBindHtml :: Html -> ValBindBase Info VName -> DocM (Html, Html, Html)
    valBindHtml Html
    name (ValBind Maybe (Info EntryPoint)
    _ VName
    _ Maybe (TypeExp Size VName)
    retdecl (Info ResRetType
    rettype) [TypeParamBase VName]
    tparams [PatBase Info VName ParamType]
    params Size
    _ Maybe DocComment
    _ [AttrInfo VName]
    _ SrcLoc
    _) = do
      tparams' <- [Html] -> Html
    forall a. Monoid a => [a] -> a
    mconcat ([Html] -> Html)
    -> ReaderT Context (WriterT Documented (Writer Warnings)) [Html]
    -> DocM Html
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> (TypeParamBase VName -> DocM Html)
    -> [TypeParamBase VName]
    -> ReaderT Context (WriterT Documented (Writer Warnings)) [Html]
    forall (t :: * -> *) (m :: * -> *) a b.
    (Traversable t, Monad m) =>
    (a -> m b) -> t a -> m (t b)
    forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
    mapM ((Html -> Html) -> DocM Html -> DocM Html
    forall a b.
    (a -> b)
    -> ReaderT Context (WriterT Documented (Writer Warnings)) a
    -> ReaderT Context (WriterT Documented (Writer Warnings)) b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap (Html
    " " Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <>) (DocM Html -> DocM Html)
    -> (TypeParamBase VName -> DocM Html)
    -> TypeParamBase VName
    -> DocM Html
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . TypeParamBase VName -> DocM Html
    typeParamHtml) [TypeParamBase VName]
    tparams
      let noLink' = [VName] -> DocM a -> DocM a
    forall a. [VName] -> DocM a -> DocM a
    noLink ([VName] -> DocM a -> DocM a) -> [VName] -> DocM a -> DocM a
    forall a b. (a -> b) -> a -> b
    $ (TypeParamBase VName -> VName) -> [TypeParamBase VName] -> [VName]
    forall a b. (a -> b) -> [a] -> [b]
    map TypeParamBase VName -> VName
    forall vn. TypeParamBase vn -> vn
    typeParamName [TypeParamBase VName]
    tparams [VName] -> [VName] -> [VName]
    forall a. Semigroup a => a -> a -> a
    <> (PatBase Info VName ParamType -> [VName])
    -> [PatBase Info VName ParamType] -> [VName]
    forall m a. Monoid m => (a -> m) -> [a] -> m
    forall (t :: * -> *) m a.
    (Foldable t, Monoid m) =>
    (a -> m) -> t a -> m
    foldMap PatBase Info VName ParamType -> [VName]
    forall t. Pat t -> [VName]
    patNames [PatBase Info VName ParamType]
    params
      rettype' <- noLink' $ maybe (retTypeHtml rettype) typeExpHtml retdecl
      params' <- noLink' $ mapM paramHtml params
      pure
        ( keyword "val " <> (H.span ! A.class_ "decl_name") name,
          tparams',
          mconcat (intersperse " -> " $ params' ++ [rettype'])
        )

    synopsisModType :: Html -> ModTypeBind -> Maybe (DocM Html)
    synopsisModType :: Html -> ModTypeBindBase Info VName -> Maybe (DocM Html)
    synopsisModType Html
    prefix ModTypeBindBase Info VName
    sb = DocM Html -> Maybe (DocM Html)
    forall a. a -> Maybe a
    Just (DocM Html -> Maybe (DocM Html)) -> DocM Html -> Maybe (DocM Html)
    forall a b. (a -> b) -> a -> b
    $ do
      name' <- VName -> DocM Html
    vnameSynopsisDef (VName -> DocM Html) -> VName -> DocM Html
    forall a b. (a -> b) -> a -> b
    $ ModTypeBindBase Info VName -> VName
    forall (f :: * -> *) vn. ModTypeBindBase f vn -> vn
    modTypeName ModTypeBindBase Info VName
    sb
      fullRow <$> do
        se' <- synopsisModTypeExp $ modTypeExp sb
        pure $ prefix <> keyword "module type " <> name' <> " = " <> se'

    synopsisMod :: FileModule -> ModBind -> Maybe (DocM Html)
    synopsisMod :: FileModule -> ModBindBase Info VName -> Maybe (DocM Html)
    synopsisMod FileModule
    fm (ModBind VName
    name [ModParamBase Info VName]
    ps Maybe (ModTypeExpBase Info VName, Info (Map VName VName))
    sig ModExpBase Info VName
    _ Maybe DocComment
    _ SrcLoc
    _) =
      case Maybe (ModTypeExpBase Info VName, Info (Map VName VName))
    sig of
        Maybe (ModTypeExpBase Info VName, Info (Map VName VName))
    Nothing -> (Html -> DocM Html
    proceed (Html -> DocM Html) -> (Mod -> DocM Html) -> Mod -> DocM Html
    forall (m :: * -> *) b c a.
    Monad m =>
    (b -> m c) -> (a -> m b) -> a -> m c
    <=< Mod -> DocM Html
    envModType) (Mod -> DocM Html) -> Maybe Mod -> Maybe (DocM Html)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> VName -> Map VName Mod -> Maybe Mod
    forall k a. Ord k => k -> Map k a -> Maybe a
    M.lookup VName
    name Map VName Mod
    modtable
        Just (ModTypeExpBase Info VName
    s, Info (Map VName VName)
    _) -> DocM Html -> Maybe (DocM Html)
    forall a. a -> Maybe a
    Just (DocM Html -> Maybe (DocM Html)) -> DocM Html -> Maybe (DocM Html)
    forall a b. (a -> b) -> a -> b
    $ Html -> DocM Html
    proceed (Html -> DocM Html) -> DocM Html -> DocM Html
    forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
    =<< ModTypeExpBase Info VName -> DocM Html
    synopsisModTypeExp ModTypeExpBase Info VName
    s
      where
        proceed :: Html -> DocM Html
    proceed Html
    sig' = do
          name' <- VName -> DocM Html
    vnameSynopsisDef VName
    name
          ps' <- modParamHtml ps
          pure $ specRow (keyword "module " <> name') ": " (ps' <> sig')

        FileModule TySet
    _abs Env {envModTable :: Env -> Map VName Mod
    envModTable = Map VName Mod
    modtable} Prog
    _ Env
    _ = FileModule
    fm
        envModType :: Mod -> DocM Html
    envModType (ModEnv Env
    e) = Env -> DocM Html
    renderEnv Env
    e
        envModType (ModFun (FunModType TySet
    _ Mod
    _ (MTy TySet
    _ Mod
    m))) = Mod -> DocM Html
    envModType Mod
    m

    synopsisType :: TypeBind -> Maybe (DocM Html)
    synopsisType :: TypeBindBase Info VName -> Maybe (DocM Html)
    synopsisType TypeBindBase Info VName
    tb = DocM Html -> Maybe (DocM Html)
    forall a. a -> Maybe a
    Just (DocM Html -> Maybe (DocM Html)) -> DocM Html -> Maybe (DocM Html)
    forall a b. (a -> b) -> a -> b
    $ do
      name' <- VName -> DocM Html
    vnameSynopsisDef (VName -> DocM Html) -> VName -> DocM Html
    forall a b. (a -> b) -> a -> b
    $ TypeBindBase Info VName -> VName
    forall (f :: * -> *) vn. TypeBindBase f vn -> vn
    typeAlias TypeBindBase Info VName
    tb
      fullRow <$> typeBindHtml name' tb

    typeBindHtml :: Html -> TypeBind -> DocM Html
    typeBindHtml :: Html -> TypeBindBase Info VName -> DocM Html
    typeBindHtml Html
    name' (TypeBind VName
    _ Liftedness
    l [TypeParamBase VName]
    tparams TypeExp Size VName
    t Info StructRetType
    _ Maybe DocComment
    _ SrcLoc
    _) = do
      t' <- [VName] -> DocM Html -> DocM Html
    forall a. [VName] -> DocM a -> DocM a
    noLink ((TypeParamBase VName -> VName) -> [TypeParamBase VName] -> [VName]
    forall a b. (a -> b) -> [a] -> [b]
    map TypeParamBase VName -> VName
    forall vn. TypeParamBase vn -> vn
    typeParamName [TypeParamBase VName]
    tparams) (DocM Html -> DocM Html) -> DocM Html -> DocM Html
    forall a b. (a -> b) -> a -> b
    $ TypeExp Size VName -> DocM Html
    typeExpHtml TypeExp Size VName
    t
      abbrev <- typeAbbrevHtml l name' tparams
      pure $ abbrev <> " = " <> t'

    renderEnv :: Env -> DocM Html
    renderEnv :: Env -> DocM Html
    renderEnv (Env Map VName BoundV
    vtable Map VName TypeBinding
    ttable Map VName MTy
    sigtable Map VName Mod
    modtable Map (Namespace, Name) (QualName VName)
    _) = do
      typeBinds <- ((VName, TypeBinding) -> DocM Html)
    -> [(VName, TypeBinding)]
    -> ReaderT Context (WriterT Documented (Writer Warnings)) [Html]
    forall (t :: * -> *) (m :: * -> *) a b.
    (Traversable t, Monad m) =>
    (a -> m b) -> t a -> m (t b)
    forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
    mapM (VName, TypeBinding) -> DocM Html
    renderTypeBind (Map VName TypeBinding -> [(VName, TypeBinding)]
    forall k a. Map k a -> [(k, a)]
    M.toList Map VName TypeBinding
    ttable)
      valBinds <- mapM renderValBind (M.toList vtable)
      sigBinds <- mapM renderModType (M.toList sigtable)
      modBinds <- mapM renderMod (M.toList modtable)
      pure $ braces $ mconcat $ typeBinds ++ valBinds ++ sigBinds ++ modBinds

    renderModType :: (VName, MTy) -> DocM Html
    renderModType :: (VName, MTy) -> DocM Html
    renderModType (VName
    name, MTy
    _sig) =
      ([Char] -> Html
    keyword [Char]
    "module type " Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <>) (Html -> Html) -> DocM Html -> DocM Html
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> QualName VName -> DocM Html
    qualNameHtml (VName -> QualName VName
    forall v. v -> QualName v
    qualName VName
    name)

    renderMod :: (VName, Mod) -> DocM Html
    renderMod :: (VName, Mod) -> DocM Html
    renderMod (VName
    name, Mod
    _mod) =
      ([Char] -> Html
    keyword [Char]
    "module " Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <>) (Html -> Html) -> DocM Html -> DocM Html
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> QualName VName -> DocM Html
    qualNameHtml (VName -> QualName VName
    forall v. v -> QualName v
    qualName VName
    name)

    renderValBind :: (VName, BoundV) -> DocM Html
    renderValBind :: (VName, BoundV) -> DocM Html
    renderValBind = (Html -> Html) -> DocM Html -> DocM Html
    forall a b.
    (a -> b)
    -> ReaderT Context (WriterT Documented (Writer Warnings)) a
    -> ReaderT Context (WriterT Documented (Writer Warnings)) b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap Html -> Html
    H.div (DocM Html -> DocM Html)
    -> ((VName, BoundV) -> DocM Html) -> (VName, BoundV) -> DocM Html
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (VName, BoundV) -> DocM Html
    synopsisValBindBind

    renderTypeBind :: (VName, TypeBinding) -> DocM Html
    renderTypeBind :: (VName, TypeBinding) -> DocM Html
    renderTypeBind (VName
    name, TypeAbbr Liftedness
    l [TypeParamBase VName]
    tps StructRetType
    tp) = do
      tp' <- ResRetType -> DocM Html
    retTypeHtml (ResRetType -> DocM Html) -> ResRetType -> DocM Html
    forall a b. (a -> b) -> a -> b
    $ Uniqueness -> StructRetType -> ResRetType
    forall u. Uniqueness -> RetTypeBase Size u -> ResRetType
    toResRet Uniqueness
    Nonunique StructRetType
    tp
      name' <- vnameHtml name
      abbrev <- typeAbbrevHtml l name' tps
      pure $ H.div $ abbrev <> " = " <> tp'

    synopsisValBindBind :: (VName, BoundV) -> DocM Html
    synopsisValBindBind :: (VName, BoundV) -> DocM Html
    synopsisValBindBind (VName
    name, BoundV [TypeParamBase VName]
    tps StructType
    t) = do
      tps' <- (TypeParamBase VName -> DocM Html)
    -> [TypeParamBase VName]
    -> ReaderT Context (WriterT Documented (Writer Warnings)) [Html]
    forall (t :: * -> *) (m :: * -> *) a b.
    (Traversable t, Monad m) =>
    (a -> m b) -> t a -> m (t b)
    forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
    mapM TypeParamBase VName -> DocM Html
    typeParamHtml [TypeParamBase VName]
    tps
      t' <- typeHtml $ second (const Nonunique) t
      name' <- vnameHtml name
      pure $ keyword "val " <> name' <> mconcat (map (" " <>) tps') <> ": " <> t'

    dietHtml :: Diet -> Html
    dietHtml :: Diet -> Html
    dietHtml Diet
    Consume = Html
    "*"
    dietHtml Diet
    Observe = Html
    ""

    typeHtml :: TypeBase Size Uniqueness -> DocM Html
    typeHtml :: TypeBase Size Uniqueness -> DocM Html
    typeHtml TypeBase Size Uniqueness
    t = case TypeBase Size Uniqueness
    t of
      Array Uniqueness
    u Shape Size
    shape ScalarTypeBase Size NoUniqueness
    et -> do
        shape' <- Shape Size -> DocM Html
    prettyShape Shape Size
    shape
        et' <- typeHtml $ Scalar $ second (const Nonunique) et
        pure $ prettyU u <> shape' <> et'
      Scalar (Prim PrimType
    et) -> Html -> DocM Html
    forall a.
    a -> ReaderT Context (WriterT Documented (Writer Warnings)) a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure (Html -> DocM Html) -> Html -> DocM Html
    forall a b. (a -> b) -> a -> b
    $ PrimType -> Html
    primTypeHtml PrimType
    et
      Scalar (Record Map Name (TypeBase Size Uniqueness)
    fs)
        | Just [TypeBase Size Uniqueness]
    ts <- Map Name (TypeBase Size Uniqueness)
    -> Maybe [TypeBase Size Uniqueness]
    forall a. Map Name a -> Maybe [a]
    areTupleFields Map Name (TypeBase Size Uniqueness)
    fs ->
            Html -> Html
    parens (Html -> Html) -> ([Html] -> Html) -> [Html] -> Html
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Html] -> Html
    commas ([Html] -> Html)
    -> ReaderT Context (WriterT Documented (Writer Warnings)) [Html]
    -> DocM Html
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> (TypeBase Size Uniqueness -> DocM Html)
    -> [TypeBase Size Uniqueness]
    -> ReaderT Context (WriterT Documented (Writer Warnings)) [Html]
    forall (t :: * -> *) (m :: * -> *) a b.
    (Traversable t, Monad m) =>
    (a -> m b) -> t a -> m (t b)
    forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
    mapM TypeBase Size Uniqueness -> DocM Html
    typeHtml [TypeBase Size Uniqueness]
    ts
        | Bool
    otherwise ->
            Html -> Html
    braces (Html -> Html) -> ([Html] -> Html) -> [Html] -> Html
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Html] -> Html
    commas ([Html] -> Html)
    -> ReaderT Context (WriterT Documented (Writer Warnings)) [Html]
    -> DocM Html
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ((Name, TypeBase Size Uniqueness) -> DocM Html)
    -> [(Name, TypeBase Size Uniqueness)]
    -> ReaderT Context (WriterT Documented (Writer Warnings)) [Html]
    forall (t :: * -> *) (m :: * -> *) a b.
    (Traversable t, Monad m) =>
    (a -> m b) -> t a -> m (t b)
    forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
    mapM (Name, TypeBase Size Uniqueness) -> DocM Html
    ppField (Map Name (TypeBase Size Uniqueness)
    -> [(Name, TypeBase Size Uniqueness)]
    forall k a. Map k a -> [(k, a)]
    M.toList Map Name (TypeBase Size Uniqueness)
    fs)
        where
          ppField :: (Name, TypeBase Size Uniqueness) -> DocM Html
    ppField (Name
    name, TypeBase Size Uniqueness
    tp) = do
            tp' <- TypeBase Size Uniqueness -> DocM Html
    typeHtml TypeBase Size Uniqueness
    tp
            pure $ toHtml (nameToString name) <> ": " <> tp'
      Scalar (TypeVar Uniqueness
    u QualName VName
    et [TypeArg Size]
    targs) -> do
        targs' <- (TypeArg Size -> DocM Html)
    -> [TypeArg Size]
    -> ReaderT Context (WriterT Documented (Writer Warnings)) [Html]
    forall (t :: * -> *) (m :: * -> *) a b.
    (Traversable t, Monad m) =>
    (a -> m b) -> t a -> m (t b)
    forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
    mapM TypeArg Size -> DocM Html
    typeArgHtml [TypeArg Size]
    targs
        et' <- qualNameHtml et
        pure $ prettyU u <> et' <> mconcat (map (" " <>) targs')
      Scalar (Arrow Uniqueness
    _ PName
    pname Diet
    d StructType
    t1 ResRetType
    t2) -> do
        t1' <- TypeBase Size Uniqueness -> DocM Html
    typeHtml (TypeBase Size Uniqueness -> DocM Html)
    -> TypeBase Size Uniqueness -> DocM Html
    forall a b. (a -> b) -> a -> b
    $ (NoUniqueness -> Uniqueness)
    -> StructType -> TypeBase Size Uniqueness
    forall b c a. (b -> c) -> TypeBase a b -> TypeBase a c
    forall (p :: * -> * -> *) b c a.
    Bifunctor p =>
    (b -> c) -> p a b -> p a c
    second (Uniqueness -> NoUniqueness -> Uniqueness
    forall a b. a -> b -> a
    const Uniqueness
    Nonunique) StructType
    t1
        t2' <- retTypeHtml t2
        case pname of
          Named VName
    v -> do
            v' <- VName -> DocM Html
    vnameHtml VName
    v
            pure $ parens (v' <> ": " <> dietHtml d <> t1') <> " -> " <> t2'
          PName
    Unnamed ->
            Html -> DocM Html
    forall a.
    a -> ReaderT Context (WriterT Documented (Writer Warnings)) a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure (Html -> DocM Html) -> Html -> DocM Html
    forall a b. (a -> b) -> a -> b
    $ Diet -> Html
    dietHtml Diet
    d Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <> Html
    t1' Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <> Html
    " -> " Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <> Html
    t2'
      Scalar (Sum Map Name [TypeBase Size Uniqueness]
    cs) -> [Html] -> Html
    pipes ([Html] -> Html)
    -> ReaderT Context (WriterT Documented (Writer Warnings)) [Html]
    -> DocM Html
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ((Name, [TypeBase Size Uniqueness]) -> DocM Html)
    -> [(Name, [TypeBase Size Uniqueness])]
    -> ReaderT Context (WriterT Documented (Writer Warnings)) [Html]
    forall (t :: * -> *) (m :: * -> *) a b.
    (Traversable t, Monad m) =>
    (a -> m b) -> t a -> m (t b)
    forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
    mapM (Name, [TypeBase Size Uniqueness]) -> DocM Html
    ppClause (Map Name [TypeBase Size Uniqueness]
    -> [(Name, [TypeBase Size Uniqueness])]
    forall a. Map Name a -> [(Name, a)]
    sortConstrs Map Name [TypeBase Size Uniqueness]
    cs)
        where
          ppClause :: (Name, [TypeBase Size Uniqueness]) -> DocM Html
    ppClause (Name
    n, [TypeBase Size Uniqueness]
    ts) = Html -> [Html] -> Html
    joinBy Html
    " " ([Html] -> Html) -> ([Html] -> [Html]) -> [Html] -> Html
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Name -> Html
    ppConstr Name
    n Html -> [Html] -> [Html]
    forall a. a -> [a] -> [a]
    :) ([Html] -> Html)
    -> ReaderT Context (WriterT Documented (Writer Warnings)) [Html]
    -> DocM Html
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> (TypeBase Size Uniqueness -> DocM Html)
    -> [TypeBase Size Uniqueness]
    -> ReaderT Context (WriterT Documented (Writer Warnings)) [Html]
    forall (t :: * -> *) (m :: * -> *) a b.
    (Traversable t, Monad m) =>
    (a -> m b) -> t a -> m (t b)
    forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
    mapM TypeBase Size Uniqueness -> DocM Html
    typeHtml [TypeBase Size Uniqueness]
    ts
          ppConstr :: Name -> Html
    ppConstr Name
    name = Html
    "#" Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <> [Char] -> Html
    forall a. ToMarkup a => a -> Html
    toHtml (Name -> [Char]
    nameToString Name
    name)

    retTypeHtml :: ResRetType -> DocM Html
    retTypeHtml :: ResRetType -> DocM Html
    retTypeHtml (RetType [] TypeBase Size Uniqueness
    t) = TypeBase Size Uniqueness -> DocM Html
    typeHtml TypeBase Size Uniqueness
    t
    retTypeHtml (RetType [VName]
    dims TypeBase Size Uniqueness
    t) = do
      t' <- TypeBase Size Uniqueness -> DocM Html
    typeHtml TypeBase Size Uniqueness
    t
      dims' <- mapM vnameHtml dims
      pure $ "?" <> mconcat (map brackets dims') <> "." <> t'

    prettyShape :: Shape Size -> DocM Html
    prettyShape :: Shape Size -> DocM Html
    prettyShape (Shape [Size]
    ds) =
      [Html] -> Html
    forall a. Monoid a => [a] -> a
    mconcat ([Html] -> Html)
    -> ReaderT Context (WriterT Documented (Writer Warnings)) [Html]
    -> DocM Html
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> (Size -> DocM Html)
    -> [Size]
    -> ReaderT Context (WriterT Documented (Writer Warnings)) [Html]
    forall (t :: * -> *) (m :: * -> *) a b.
    (Traversable t, Monad m) =>
    (a -> m b) -> t a -> m (t b)
    forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
    mapM Size -> DocM Html
    dimDeclHtml [Size]
    ds

    typeArgHtml :: TypeArg Size -> DocM Html
    typeArgHtml :: TypeArg Size -> DocM Html
    typeArgHtml (TypeArgDim Size
    d) = Size -> DocM Html
    dimDeclHtml Size
    d
    typeArgHtml (TypeArgType StructType
    t) = TypeBase Size Uniqueness -> DocM Html
    typeHtml (TypeBase Size Uniqueness -> DocM Html)
    -> TypeBase Size Uniqueness -> DocM Html
    forall a b. (a -> b) -> a -> b
    $ (NoUniqueness -> Uniqueness)
    -> StructType -> TypeBase Size Uniqueness
    forall b c a. (b -> c) -> TypeBase a b -> TypeBase a c
    forall (p :: * -> * -> *) b c a.
    Bifunctor p =>
    (b -> c) -> p a b -> p a c
    second (Uniqueness -> NoUniqueness -> Uniqueness
    forall a b. a -> b -> a
    const Uniqueness
    Nonunique) StructType
    t

    modParamHtml :: [ModParamBase Info VName] -> DocM Html
    modParamHtml :: [ModParamBase Info VName] -> DocM Html
    modParamHtml [] = Html -> DocM Html
    forall a.
    a -> ReaderT Context (WriterT Documented (Writer Warnings)) a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure Html
    forall a. Monoid a => a
    mempty
    modParamHtml (ModParam VName
    pname ModTypeExpBase Info VName
    psig Info [VName]
    _ SrcLoc
    _ : [ModParamBase Info VName]
    mps) = do
      pname' <- VName -> DocM Html
    vnameHtml VName
    pname
      psig' <- synopsisModTypeExp psig
      mps' <- modParamHtml mps
      pure $ "(" <> pname' <> ": " <> psig' <> ") -> " <> mps'

    synopsisModTypeExp :: ModTypeExpBase Info VName -> DocM Html
    synopsisModTypeExp :: ModTypeExpBase Info VName -> DocM Html
    synopsisModTypeExp ModTypeExpBase Info VName
    e = case ModTypeExpBase Info VName
    e of
      ModTypeVar QualName VName
    v Info (Map VName VName)
    _ SrcLoc
    _ -> QualName VName -> DocM Html
    qualNameHtml QualName VName
    v
      ModTypeParens ModTypeExpBase Info VName
    e' SrcLoc
    _ -> Html -> Html
    parens (Html -> Html) -> DocM Html -> DocM Html
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ModTypeExpBase Info VName -> DocM Html
    synopsisModTypeExp ModTypeExpBase Info VName
    e'
      ModTypeSpecs [SpecBase Info VName]
    ss SrcLoc
    _ -> Html -> Html
    braces (Html -> Html) -> ([Html] -> Html) -> [Html] -> Html
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Html -> Html
    H.table (Html -> Html) -> Attribute -> Html -> Html
    forall h. Attributable h => h -> Attribute -> h
    ! AttributeValue -> Attribute
    A.class_ AttributeValue
    "specs") (Html -> Html) -> ([Html] -> Html) -> [Html] -> Html
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Html] -> Html
    forall a. Monoid a => [a] -> a
    mconcat ([Html] -> Html)
    -> ReaderT Context (WriterT Documented (Writer Warnings)) [Html]
    -> DocM Html
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> (SpecBase Info VName -> DocM Html)
    -> [SpecBase Info VName]
    -> ReaderT Context (WriterT Documented (Writer Warnings)) [Html]
    forall (t :: * -> *) (m :: * -> *) a b.
    (Traversable t, Monad m) =>
    (a -> m b) -> t a -> m (t b)
    forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
    mapM SpecBase Info VName -> DocM Html
    synopsisSpec [SpecBase Info VName]
    ss
      ModTypeWith ModTypeExpBase Info VName
    s (TypeRef QualName VName
    v [TypeParamBase VName]
    ps TypeExp Size VName
    t SrcLoc
    _) SrcLoc
    _ -> do
        s' <- ModTypeExpBase Info VName -> DocM Html
    synopsisModTypeExp ModTypeExpBase Info VName
    s
        t' <- typeExpHtml t
        v' <- qualNameHtml v
        ps' <- mconcat <$> mapM (fmap (" " <>) . typeParamHtml) ps
        pure $ s' <> keyword " with " <> v' <> ps' <> " = " <> t'
      ModTypeArrow Maybe VName
    Nothing ModTypeExpBase Info VName
    e1 ModTypeExpBase Info VName
    e2 SrcLoc
    _ ->
        (Html -> Html -> Html) -> DocM Html -> DocM Html -> DocM Html
    forall (m :: * -> *) a1 a2 r.
    Monad m =>
    (a1 -> a2 -> r) -> m a1 -> m a2 -> m r
    liftM2 Html -> Html -> Html
    forall {a}. (Semigroup a, IsString a) => a -> a -> a
    f (ModTypeExpBase Info VName -> DocM Html
    synopsisModTypeExp ModTypeExpBase Info VName
    e1) (ModTypeExpBase Info VName -> DocM Html
    synopsisModTypeExp ModTypeExpBase Info VName
    e2)
        where
          f :: a -> a -> a
    f a
    e1' a
    e2' = a
    e1' a -> a -> a
    forall a. Semigroup a => a -> a -> a
    <> a
    " -> " a -> a -> a
    forall a. Semigroup a => a -> a -> a
    <> a
    e2'
      ModTypeArrow (Just VName
    v) ModTypeExpBase Info VName
    e1 ModTypeExpBase Info VName
    e2 SrcLoc
    _ ->
        do
          name <- VName -> DocM Html
    vnameHtml VName
    v
          e1' <- synopsisModTypeExp e1
          e2' <- noLink [v] $ synopsisModTypeExp e2
          pure $ "(" <> name <> ": " <> e1' <> ") -> " <> e2'

    keyword :: String -> Html
    keyword :: [Char] -> Html
    keyword = (Html -> Html
    H.span (Html -> Html) -> Attribute -> Html -> Html
    forall h. Attributable h => h -> Attribute -> h
    ! AttributeValue -> Attribute
    A.class_ AttributeValue
    "keyword") (Html -> Html) -> ([Char] -> Html) -> [Char] -> Html
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Char] -> Html
    forall a. IsString a => [Char] -> a
    fromString

    vnameHtml :: VName -> DocM Html
    vnameHtml :: VName -> DocM Html
    vnameHtml VName
    vname = do
      (_, vname_id) <- VName -> DocM ([Char], [Char])
    vnameId VName
    vname
      pure $ H.span ! A.id (fromString vname_id) $ renderName $ baseName vname

    -- | The canonical (in-file) anchor ID for a VName, along with the
    -- file in which it is defined.
    vnameId :: VName -> DocM (FilePath, String)
    vnameId :: VName -> DocM ([Char], [Char])
    vnameId VName
    vname = do
      current <- (Context -> [Char])
    -> ReaderT Context (WriterT Documented (Writer Warnings)) [Char]
    forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
    asks Context -> [Char]
    ctxCurrent
      asks $ fromMaybe (current, show (baseTag vname)) . M.lookup vname . ctxFileMap

    vnameDescDef :: VName -> IndexWhat -> DocM Html
    vnameDescDef :: VName -> IndexWhat -> DocM Html
    vnameDescDef VName
    v IndexWhat
    what = do
      VName -> IndexWhat -> DocM ()
    document VName
    v IndexWhat
    what
      (_, v_id) <- VName -> DocM ([Char], [Char])
    vnameId VName
    v
      pure $ H.a ! A.id (fromString v_id) $ renderName (baseName v)

    vnameSynopsisRef :: VName -> DocM Html
    vnameSynopsisRef :: VName -> DocM Html
    vnameSynopsisRef VName
    v = do
      (_, v_id) <- VName -> DocM ([Char], [Char])
    vnameId VName
    v
      pure
        $ H.a
          ! A.class_ "synopsis_link"
          ! A.href (fromString ("#" <> "synopsis:" <> v_id))
        $ "↑"

    synopsisSpec :: SpecBase Info VName -> DocM Html
    synopsisSpec :: SpecBase Info VName -> DocM Html
    synopsisSpec SpecBase Info VName
    spec = case SpecBase Info VName
    spec of
      TypeAbbrSpec TypeBindBase Info VName
    tpsig -> do
        def <- VName -> DocM Html
    vnameSynopsisDef (VName -> DocM Html) -> VName -> DocM Html
    forall a b. (a -> b) -> a -> b
    $ TypeBindBase Info VName -> VName
    forall (f :: * -> *) vn. TypeBindBase f vn -> vn
    typeAlias TypeBindBase Info VName
    tpsig
        fullRow <$> typeBindHtml def tpsig
      TypeSpec Liftedness
    l VName
    name [TypeParamBase VName]
    ps Maybe DocComment
    _ SrcLoc
    _ -> do
        name' <- VName -> DocM Html
    vnameSynopsisDef VName
    name
        ps' <- mconcat <$> mapM (fmap (" " <>) . typeParamHtml) ps
        pure $ fullRow $ keyword l' <> name' <> ps'
        where
          l' :: [Char]
    l' = case Liftedness
    l of
            Liftedness
    Unlifted -> [Char]
    "type "
            Liftedness
    SizeLifted -> [Char]
    "type~ "
            Liftedness
    Lifted -> [Char]
    "type^ "
      ValSpec VName
    name [TypeParamBase VName]
    tparams TypeExp Size VName
    rettype Info StructType
    _ Maybe DocComment
    _ SrcLoc
    _ -> do
        tparams' <- (TypeParamBase VName -> DocM Html)
    -> [TypeParamBase VName]
    -> ReaderT Context (WriterT Documented (Writer Warnings)) [Html]
    forall (t :: * -> *) (m :: * -> *) a b.
    (Traversable t, Monad m) =>
    (a -> m b) -> t a -> m (t b)
    forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
    mapM TypeParamBase VName -> DocM Html
    typeParamHtml [TypeParamBase VName]
    tparams
        rettype' <- noLink (map typeParamName tparams) $ typeExpHtml rettype
        name' <- vnameSynopsisDef name
        pure $
          specRow
            (keyword "val " <> name')
            (mconcat (map (" " <>) tparams') <> ": ")
            rettype'
      ModSpec VName
    name ModTypeExpBase Info VName
    sig Maybe DocComment
    _ SrcLoc
    _ -> do
        name' <- VName -> DocM Html
    vnameSynopsisDef VName
    name
        specRow (keyword "module " <> name') ": " <$> synopsisModTypeExp sig
      IncludeSpec ModTypeExpBase Info VName
    e SrcLoc
    _ -> Html -> Html
    fullRow (Html -> Html) -> (Html -> Html) -> Html -> Html
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ([Char] -> Html
    keyword [Char]
    "include " Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <>) (Html -> Html) -> DocM Html -> DocM Html
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ModTypeExpBase Info VName -> DocM Html
    synopsisModTypeExp ModTypeExpBase Info VName
    e

    typeExpHtml :: TypeExp Exp VName -> DocM Html
    typeExpHtml :: TypeExp Size VName -> DocM Html
    typeExpHtml TypeExp Size VName
    e = case TypeExp Size VName
    e of
      TEUnique TypeExp Size VName
    t SrcLoc
    _ -> (Html
    "*" Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <>) (Html -> Html) -> DocM Html -> DocM Html
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> TypeExp Size VName -> DocM Html
    typeExpHtml TypeExp Size VName
    t
      TEArray SizeExp Size
    d TypeExp Size VName
    at SrcLoc
    _ -> do
        at' <- TypeExp Size VName -> DocM Html
    typeExpHtml TypeExp Size VName
    at
        d' <- dimExpHtml d
        pure $ d' <> at'
      TETuple [TypeExp Size VName]
    ts SrcLoc
    _ -> Html -> Html
    parens (Html -> Html) -> ([Html] -> Html) -> [Html] -> Html
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Html] -> Html
    commas ([Html] -> Html)
    -> ReaderT Context (WriterT Documented (Writer Warnings)) [Html]
    -> DocM Html
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> (TypeExp Size VName -> DocM Html)
    -> [TypeExp Size VName]
    -> ReaderT Context (WriterT Documented (Writer Warnings)) [Html]
    forall (t :: * -> *) (m :: * -> *) a b.
    (Traversable t, Monad m) =>
    (a -> m b) -> t a -> m (t b)
    forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
    mapM TypeExp Size VName -> DocM Html
    typeExpHtml [TypeExp Size VName]
    ts
      TERecord [(L Name, TypeExp Size VName)]
    fs SrcLoc
    _ -> Html -> Html
    braces (Html -> Html) -> ([Html] -> Html) -> [Html] -> Html
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Html] -> Html
    commas ([Html] -> Html)
    -> ReaderT Context (WriterT Documented (Writer Warnings)) [Html]
    -> DocM Html
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ((L Name, TypeExp Size VName) -> DocM Html)
    -> [(L Name, TypeExp Size VName)]
    -> ReaderT Context (WriterT Documented (Writer Warnings)) [Html]
    forall (t :: * -> *) (m :: * -> *) a b.
    (Traversable t, Monad m) =>
    (a -> m b) -> t a -> m (t b)
    forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
    mapM (L Name, TypeExp Size VName) -> DocM Html
    ppField [(L Name, TypeExp Size VName)]
    fs
        where
          ppField :: (L Name, TypeExp Size VName) -> DocM Html
    ppField (L Loc
    _ Name
    name, TypeExp Size VName
    t) = do
            t' <- TypeExp Size VName -> DocM Html
    typeExpHtml TypeExp Size VName
    t
            pure $ toHtml (nameToString name) <> ": " <> t'
      TEVar QualName VName
    name SrcLoc
    _ -> QualName VName -> DocM Html
    qualNameHtml QualName VName
    name
      TEParens TypeExp Size VName
    te SrcLoc
    _ -> Html -> Html
    parens (Html -> Html) -> DocM Html -> DocM Html
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> TypeExp Size VName -> DocM Html
    typeExpHtml TypeExp Size VName
    te
      TEApply TypeExp Size VName
    t TypeArgExp Size VName
    arg SrcLoc
    _ -> do
        t' <- TypeExp Size VName -> DocM Html
    typeExpHtml TypeExp Size VName
    t
        arg' <- typeArgExpHtml arg
        pure $ t' <> " " <> arg'
      TEArrow Maybe VName
    pname TypeExp Size VName
    t1 TypeExp Size VName
    t2 SrcLoc
    _ -> do
        t1' <- case TypeExp Size VName
    t1 of
          TEArrow {} -> Html -> Html
    parens (Html -> Html) -> DocM Html -> DocM Html
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> TypeExp Size VName -> DocM Html
    typeExpHtml TypeExp Size VName
    t1
          TypeExp Size VName
    _ -> TypeExp Size VName -> DocM Html
    typeExpHtml TypeExp Size VName
    t1
        t2' <- typeExpHtml t2
        case pname of
          Just VName
    v -> do
            v' <- VName -> DocM Html
    vnameHtml VName
    v
            pure $ parens (v' <> ": " <> t1') <> " -> " <> t2'
          Maybe VName
    Nothing ->
            Html -> DocM Html
    forall a.
    a -> ReaderT Context (WriterT Documented (Writer Warnings)) a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure (Html -> DocM Html) -> Html -> DocM Html
    forall a b. (a -> b) -> a -> b
    $ Html
    t1' Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <> Html
    " -> " Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <> Html
    t2'
      TESum [(Name, [TypeExp Size VName])]
    cs SrcLoc
    _ -> [Html] -> Html
    pipes ([Html] -> Html)
    -> ReaderT Context (WriterT Documented (Writer Warnings)) [Html]
    -> DocM Html
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ((Name, [TypeExp Size VName]) -> DocM Html)
    -> [(Name, [TypeExp Size VName])]
    -> ReaderT Context (WriterT Documented (Writer Warnings)) [Html]
    forall (t :: * -> *) (m :: * -> *) a b.
    (Traversable t, Monad m) =>
    (a -> m b) -> t a -> m (t b)
    forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
    mapM (Name, [TypeExp Size VName]) -> DocM Html
    ppClause [(Name, [TypeExp Size VName])]
    cs
        where
          ppClause :: (Name, [TypeExp Size VName]) -> DocM Html
    ppClause (Name
    n, [TypeExp Size VName]
    ts) = Html -> [Html] -> Html
    joinBy Html
    " " ([Html] -> Html) -> ([Html] -> [Html]) -> [Html] -> Html
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Name -> Html
    ppConstr Name
    n Html -> [Html] -> [Html]
    forall a. a -> [a] -> [a]
    :) ([Html] -> Html)
    -> ReaderT Context (WriterT Documented (Writer Warnings)) [Html]
    -> DocM Html
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> (TypeExp Size VName -> DocM Html)
    -> [TypeExp Size VName]
    -> ReaderT Context (WriterT Documented (Writer Warnings)) [Html]
    forall (t :: * -> *) (m :: * -> *) a b.
    (Traversable t, Monad m) =>
    (a -> m b) -> t a -> m (t b)
    forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
    mapM TypeExp Size VName -> DocM Html
    typeExpHtml [TypeExp Size VName]
    ts
          ppConstr :: Name -> Html
    ppConstr Name
    name = Html
    "#" Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <> [Char] -> Html
    forall a. ToMarkup a => a -> Html
    toHtml (Name -> [Char]
    nameToString Name
    name)
      TEDim [VName]
    dims TypeExp Size VName
    t SrcLoc
    _ -> do
        t' <- TypeExp Size VName -> DocM Html
    typeExpHtml TypeExp Size VName
    t
        pure $ "?" <> mconcat (map (brackets . renderName . baseName) dims) <> "." <> t'

    qualNameHtml :: QualName VName -> DocM Html
    qualNameHtml :: QualName VName -> DocM Html
    qualNameHtml (QualName [VName]
    names vname :: VName
    vname@(VName Name
    name Int
    tag)) =
      if Int
    tag Int -> Int -> Bool
    forall a. Ord a => a -> a -> Bool
    <= Int
    maxIntrinsicTag
        then Html -> DocM Html
    forall a.
    a -> ReaderT Context (WriterT Documented (Writer Warnings)) a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure (Html -> DocM Html) -> Html -> DocM Html
    forall a b. (a -> b) -> a -> b
    $ Name -> Html
    renderName Name
    name
        else Maybe [Char] -> Html
    f (Maybe [Char] -> Html)
    -> ReaderT
         Context (WriterT Documented (Writer Warnings)) (Maybe [Char])
    -> DocM Html
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ReaderT
      Context (WriterT Documented (Writer Warnings)) (Maybe [Char])
    ref
      where
        prefix :: Html
        prefix :: Html
    prefix = (VName -> Html) -> [VName] -> Html
    forall (t :: * -> *) (m :: * -> *) a b.
    (Foldable t, Monad m) =>
    (a -> m b) -> t a -> m ()
    mapM_ ((Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <> Html
    ".") (Html -> Html) -> (VName -> Html) -> VName -> Html
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Name -> Html
    renderName (Name -> Html) -> (VName -> Name) -> VName -> Html
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . VName -> Name
    baseName) [VName]
    names
        f :: Maybe [Char] -> Html
    f (Just [Char]
    s) = Html -> Html
    H.a (Html -> Html) -> Attribute -> Html -> Html
    forall h. Attributable h => h -> Attribute -> h
    ! AttributeValue -> Attribute
    A.href ([Char] -> AttributeValue
    forall a. IsString a => [Char] -> a
    fromString [Char]
    s) (Html -> Html) -> Html -> Html
    forall a b. (a -> b) -> a -> b
    $ Html
    prefix Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <> Name -> Html
    renderName Name
    name
        f Maybe [Char]
    Nothing = Html
    prefix Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <> Name -> Html
    renderName Name
    name

        ref :: ReaderT
      Context (WriterT Documented (Writer Warnings)) (Maybe [Char])
    ref = do
          boring <- (Context -> Bool)
    -> ReaderT Context (WriterT Documented (Writer Warnings)) Bool
    forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
    asks ((Context -> Bool)
     -> ReaderT Context (WriterT Documented (Writer Warnings)) Bool)
    -> (Context -> Bool)
    -> ReaderT Context (WriterT Documented (Writer Warnings)) Bool
    forall a b. (a -> b) -> a -> b
    $ VName -> NoLink -> Bool
    forall a. Ord a => a -> Set a -> Bool
    S.member VName
    vname (NoLink -> Bool) -> (Context -> NoLink) -> Context -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Context -> NoLink
    ctxNoLink
          if boring
            then pure Nothing
            else Just <$> vnameLink vname

    -- | The link for a VName.
    vnameLink :: VName -> DocM String
    vnameLink :: VName
    -> ReaderT Context (WriterT Documented (Writer Warnings)) [Char]
    vnameLink VName
    vname = do
      current <- (Context -> [Char])
    -> ReaderT Context (WriterT Documented (Writer Warnings)) [Char]
    forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
    asks Context -> [Char]
    ctxCurrent
      (file, tag) <- vnameId vname
      pure $ vnameLink' tag current file

    vnameLink' :: String -> FilePath -> FilePath -> String
    vnameLink' :: [Char] -> [Char] -> [Char] -> [Char]
    vnameLink' [Char]
    tag [Char]
    current [Char]
    file =
      if [Char]
    file [Char] -> [Char] -> Bool
    forall a. Eq a => a -> a -> Bool
    == [Char]
    current
        then [Char]
    "#" [Char] -> [Char] -> [Char]
    forall a. [a] -> [a] -> [a]
    ++ [Char]
    tag
        else [Char] -> [Char] -> [Char]
    relativise [Char]
    file [Char]
    current [Char] -> [Char] -> [Char]
    -<.> [Char]
    ".html#" [Char] -> [Char] -> [Char]
    forall a. [a] -> [a] -> [a]
    ++ [Char]
    tag

    paramHtml :: Pat ParamType -> DocM Html
    paramHtml :: PatBase Info VName ParamType -> DocM Html
    paramHtml PatBase Info VName ParamType
    pat = do
      let (PName
    pat_param, Diet
    d, StructType
    t) = PatBase Info VName ParamType -> (PName, Diet, StructType)
    patternParam PatBase Info VName ParamType
    pat
      t' <- TypeBase Size Uniqueness -> DocM Html
    typeHtml (TypeBase Size Uniqueness -> DocM Html)
    -> TypeBase Size Uniqueness -> DocM Html
    forall a b. (a -> b) -> a -> b
    $ (NoUniqueness -> Uniqueness)
    -> StructType -> TypeBase Size Uniqueness
    forall b c a. (b -> c) -> TypeBase a b -> TypeBase a c
    forall (p :: * -> * -> *) b c a.
    Bifunctor p =>
    (b -> c) -> p a b -> p a c
    second (Uniqueness -> NoUniqueness -> Uniqueness
    forall a b. a -> b -> a
    const Uniqueness
    Nonunique) StructType
    t
      case pat_param of
        Named VName
    v -> do
          v' <- VName -> DocM Html
    vnameHtml VName
    v
          pure $ parens $ v' <> ": " <> dietHtml d <> t'
        PName
    Unnamed -> Html -> DocM Html
    forall a.
    a -> ReaderT Context (WriterT Documented (Writer Warnings)) a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure Html
    t'

    relativise :: FilePath -> FilePath -> FilePath
    relativise :: [Char] -> [Char] -> [Char]
    relativise [Char]
    dest [Char]
    src =
      [[Char]] -> [Char]
    forall (t :: * -> *) a. Foldable t => t [a] -> [a]
    concat (Int -> [Char] -> [[Char]]
    forall a. Int -> a -> [a]
    replicate ([[Char]] -> Int
    forall a. [a] -> Int
    forall (t :: * -> *) a. Foldable t => t a -> Int
    length ([Char] -> [[Char]]
    splitPath [Char]
    src) Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - Int
    1) [Char]
    "../") [Char] -> [Char] -> [Char]
    forall a. [a] -> [a] -> [a]
    ++ [Char] -> [Char] -> [Char]
    makeRelative [Char]
    "/" [Char]
    dest

    dimDeclHtml :: Size -> DocM Html
    dimDeclHtml :: Size -> DocM Html
    dimDeclHtml = Html -> DocM Html
    forall a.
    a -> ReaderT Context (WriterT Documented (Writer Warnings)) a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure (Html -> DocM Html) -> (Size -> Html) -> Size -> DocM Html
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Html -> Html
    brackets (Html -> Html) -> (Size -> Html) -> Size -> Html
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Char] -> Html
    forall a. ToMarkup a => a -> Html
    toHtml ([Char] -> Html) -> (Size -> [Char]) -> Size -> Html
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Size -> [Char]
    forall a. Pretty a => a -> [Char]
    prettyString

    dimExpHtml :: SizeExp Exp -> DocM Html
    dimExpHtml :: SizeExp Size -> DocM Html
    dimExpHtml (SizeExpAny SrcLoc
    _) = Html -> DocM Html
    forall a.
    a -> ReaderT Context (WriterT Documented (Writer Warnings)) a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure (Html -> DocM Html) -> Html -> DocM Html
    forall a b. (a -> b) -> a -> b
    $ Html -> Html
    brackets Html
    forall a. Monoid a => a
    mempty
    dimExpHtml (SizeExp Size
    e SrcLoc
    _) = Html -> DocM Html
    forall a.
    a -> ReaderT Context (WriterT Documented (Writer Warnings)) a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure (Html -> DocM Html) -> Html -> DocM Html
    forall a b. (a -> b) -> a -> b
    $ Html -> Html
    brackets (Html -> Html) -> Html -> Html
    forall a b. (a -> b) -> a -> b
    $ [Char] -> Html
    forall a. ToMarkup a => a -> Html
    toHtml ([Char] -> Html) -> [Char] -> Html
    forall a b. (a -> b) -> a -> b
    $ Size -> [Char]
    forall a. Pretty a => a -> [Char]
    prettyString Size
    e

    typeArgExpHtml :: TypeArgExp Exp VName -> DocM Html
    typeArgExpHtml :: TypeArgExp Size VName -> DocM Html
    typeArgExpHtml (TypeArgExpSize SizeExp Size
    d) = SizeExp Size -> DocM Html
    dimExpHtml SizeExp Size
    d
    typeArgExpHtml (TypeArgExpType TypeExp Size VName
    d) = TypeExp Size VName -> DocM Html
    typeExpHtml TypeExp Size VName
    d

    typeParamHtml :: TypeParam -> DocM Html
    typeParamHtml :: TypeParamBase VName -> DocM Html
    typeParamHtml (TypeParamDim VName
    name SrcLoc
    _) = do
      name' <- VName -> DocM Html
    vnameHtml VName
    name
      pure $ brackets name'
    typeParamHtml (TypeParamType Liftedness
    l VName
    name SrcLoc
    _) = do
      name' <- VName -> DocM Html
    vnameHtml VName
    name
      pure $ "'" <> fromString (prettyString l) <> name'

    typeAbbrevHtml :: Liftedness -> Html -> [TypeParam] -> DocM Html
    typeAbbrevHtml :: Liftedness -> Html -> [TypeParamBase VName] -> DocM Html
    typeAbbrevHtml Liftedness
    l Html
    name [TypeParamBase VName]
    params = do
      params' <- [Html] -> Html
    forall a. Monoid a => [a] -> a
    mconcat ([Html] -> Html)
    -> ReaderT Context (WriterT Documented (Writer Warnings)) [Html]
    -> DocM Html
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> (TypeParamBase VName -> DocM Html)
    -> [TypeParamBase VName]
    -> ReaderT Context (WriterT Documented (Writer Warnings)) [Html]
    forall (t :: * -> *) (m :: * -> *) a b.
    (Traversable t, Monad m) =>
    (a -> m b) -> t a -> m (t b)
    forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
    mapM ((Html -> Html) -> DocM Html -> DocM Html
    forall a b.
    (a -> b)
    -> ReaderT Context (WriterT Documented (Writer Warnings)) a
    -> ReaderT Context (WriterT Documented (Writer Warnings)) b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap (Html
    " " Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <>) (DocM Html -> DocM Html)
    -> (TypeParamBase VName -> DocM Html)
    -> TypeParamBase VName
    -> DocM Html
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . TypeParamBase VName -> DocM Html
    typeParamHtml) [TypeParamBase VName]
    params
      pure $ what <> name <> params'
      where
        what :: Html
    what = [Char] -> Html
    keyword ([Char] -> Html) -> [Char] -> Html
    forall a b. (a -> b) -> a -> b
    $ [Char]
    "type" [Char] -> [Char] -> [Char]
    forall a. Semigroup a => a -> a -> a
    <> Liftedness -> [Char]
    forall a. Pretty a => a -> [Char]
    prettyString Liftedness
    l [Char] -> [Char] -> [Char]
    forall a. Semigroup a => a -> a -> a
    <> [Char]
    " "

    docHtml :: Maybe DocComment -> DocM Html
    docHtml :: Maybe DocComment -> DocM Html
    docHtml (Just (DocComment Text
    doc SrcLoc
    loc)) =
      Text -> Html
    H.preEscapedText
        (Text -> Html) -> ([Char] -> Text) -> [Char] -> Html
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [CMarkOption] -> [CMarkExtension] -> Text -> Text
    GFM.commonmarkToHtml [] [CMarkExtension
    GFM.extAutolink]
        (Text -> Text) -> ([Char] -> Text) -> [Char] -> Text
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Char] -> Text
    T.pack
        ([Char] -> Html)
    -> ReaderT Context (WriterT Documented (Writer Warnings)) [Char]
    -> DocM Html
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Loc
    -> [Char]
    -> ReaderT Context (WriterT Documented (Writer Warnings)) [Char]
    identifierLinks (SrcLoc -> Loc
    forall a. Located a => a -> Loc
    locOf SrcLoc
    loc) (Text -> [Char]
    T.unpack Text
    doc)
    docHtml Maybe DocComment
    Nothing = Html -> DocM Html
    forall a.
    a -> ReaderT Context (WriterT Documented (Writer Warnings)) a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure Html
    forall a. Monoid a => a
    mempty

    identifierLinks :: Loc -> String -> DocM String
    identifierLinks :: Loc
    -> [Char]
    -> ReaderT Context (WriterT Documented (Writer Warnings)) [Char]
    identifierLinks Loc
    _ [] = [Char]
    -> ReaderT Context (WriterT Documented (Writer Warnings)) [Char]
    forall a.
    a -> ReaderT Context (WriterT Documented (Writer Warnings)) a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure []
    identifierLinks Loc
    loc [Char]
    s
      | Just (([Char]
    name, [Char]
    namespace, Maybe [Char]
    file), [Char]
    s') <- [Char] -> Maybe (([Char], [Char], Maybe [Char]), [Char])
    identifierReference [Char]
    s = do
          let proceed :: [Char]
    -> ReaderT Context (WriterT Documented (Writer Warnings)) [Char]
    proceed [Char]
    x = ([Char]
    x [Char] -> [Char] -> [Char]
    forall a. Semigroup a => a -> a -> a
    <>) ([Char] -> [Char])
    -> ReaderT Context (WriterT Documented (Writer Warnings)) [Char]
    -> ReaderT Context (WriterT Documented (Writer Warnings)) [Char]
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Loc
    -> [Char]
    -> ReaderT Context (WriterT Documented (Writer Warnings)) [Char]
    identifierLinks Loc
    loc [Char]
    s'
              unknown :: ReaderT Context (WriterT Documented (Writer Warnings)) [Char]
    unknown = [Char]
    -> ReaderT Context (WriterT Documented (Writer Warnings)) [Char]
    proceed ([Char]
     -> ReaderT Context (WriterT Documented (Writer Warnings)) [Char])
    -> [Char]
    -> ReaderT Context (WriterT Documented (Writer Warnings)) [Char]
    forall a b. (a -> b) -> a -> b
    $ [Char]
    "`" [Char] -> [Char] -> [Char]
    forall a. Semigroup a => a -> a -> a
    <> [Char]
    name [Char] -> [Char] -> [Char]
    forall a. Semigroup a => a -> a -> a
    <> [Char]
    "`"
          case [Char] -> Maybe Namespace
    forall {a}. (Eq a, IsString a) => a -> Maybe Namespace
    knownNamespace [Char]
    namespace of
            Just Namespace
    namespace' -> do
              maybe_v <- (Namespace, [Char], Maybe [Char]) -> DocM (Maybe VName)
    lookupName (Namespace
    namespace', [Char]
    name, Maybe [Char]
    file)
              case maybe_v of
                Maybe VName
    Nothing -> do
                  Loc -> Doc () -> DocM ()
    warn Loc
    loc (Doc () -> DocM ()) -> Doc () -> DocM ()
    forall a b. (a -> b) -> a -> b
    $
                    Doc ()
    "Identifier '"
                      Doc () -> Doc () -> Doc ()
    forall a. Semigroup a => a -> a -> a
    <> [Char] -> Doc ()
    forall a. IsString a => [Char] -> a
    fromString [Char]
    name
                      Doc () -> Doc () -> Doc ()
    forall a. Semigroup a => a -> a -> a
    <> Doc ()
    "' not found in namespace '"
                      Doc () -> Doc () -> Doc ()
    forall a. Semigroup a => a -> a -> a
    <> [Char] -> Doc ()
    forall a. IsString a => [Char] -> a
    fromString [Char]
    namespace
                      Doc () -> Doc () -> Doc ()
    forall a. Semigroup a => a -> a -> a
    <> Doc ()
    "'"
                      Doc () -> Doc () -> Doc ()
    forall a. Semigroup a => a -> a -> a
    <> [Char] -> Doc ()
    forall a. IsString a => [Char] -> a
    fromString ([Char] -> ([Char] -> [Char]) -> Maybe [Char] -> [Char]
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe [Char]
    "" ([Char]
    " in file " [Char] -> [Char] -> [Char]
    forall a. Semigroup a => a -> a -> a
    <>) Maybe [Char]
    file)
                      Doc () -> Doc () -> Doc ()
    forall a. Semigroup a => a -> a -> a
    <> Doc ()
    "."
                  ReaderT Context (WriterT Documented (Writer Warnings)) [Char]
    unknown
                Just VName
    v' -> do
                  link <- VName
    -> ReaderT Context (WriterT Documented (Writer Warnings)) [Char]
    vnameLink VName
    v'
                  proceed $ "[`" <> name <> "`](" <> link <> ")"
            Maybe Namespace
    _ -> do
              Loc -> Doc () -> DocM ()
    warn Loc
    loc (Doc () -> DocM ()) -> Doc () -> DocM ()
    forall a b. (a -> b) -> a -> b
    $ Doc ()
    "Unknown namespace '" Doc () -> Doc () -> Doc ()
    forall a. Semigroup a => a -> a -> a
    <> [Char] -> Doc ()
    forall a. IsString a => [Char] -> a
    fromString [Char]
    namespace Doc () -> Doc () -> Doc ()
    forall a. Semigroup a => a -> a -> a
    <> Doc ()
    "'."
              ReaderT Context (WriterT Documented (Writer Warnings)) [Char]
    unknown
      where
        knownNamespace :: a -> Maybe Namespace
    knownNamespace a
    "term" = Namespace -> Maybe Namespace
    forall a. a -> Maybe a
    Just Namespace
    Term
        knownNamespace a
    "mtype" = Namespace -> Maybe Namespace
    forall a. a -> Maybe a
    Just Namespace
    Signature
        knownNamespace a
    "type" = Namespace -> Maybe Namespace
    forall a. a -> Maybe a
    Just Namespace
    Type
        knownNamespace a
    _ = Maybe Namespace
    forall a. Maybe a
    Nothing
    identifierLinks Loc
    loc (Char
    c : [Char]
    s') = (Char
    c Char -> [Char] -> [Char]
    forall a. a -> [a] -> [a]
    :) ([Char] -> [Char])
    -> ReaderT Context (WriterT Documented (Writer Warnings)) [Char]
    -> ReaderT Context (WriterT Documented (Writer Warnings)) [Char]
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Loc
    -> [Char]
    -> ReaderT Context (WriterT Documented (Writer Warnings)) [Char]
    identifierLinks Loc
    loc [Char]
    s'

    lookupName :: (Namespace, String, Maybe FilePath) -> DocM (Maybe VName)
    lookupName :: (Namespace, [Char], Maybe [Char]) -> DocM (Maybe VName)
    lookupName (Namespace
    namespace, [Char]
    name, Maybe [Char]
    file) = do
      current <- (Context -> [Char])
    -> ReaderT Context (WriterT Documented (Writer Warnings)) [Char]
    forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
    asks Context -> [Char]
    ctxCurrent
      let file' = ImportName -> [Char] -> ImportName
    mkImportFrom ([Char] -> ImportName
    mkInitialImport [Char]
    current) ([Char] -> ImportName) -> Maybe [Char] -> Maybe ImportName
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Maybe [Char]
    file
      env <- lookupEnvForFile file'
      case M.lookup (namespace, nameFromString name) . envNameMap =<< env of
        Maybe (QualName VName)
    Nothing -> Maybe VName -> DocM (Maybe VName)
    forall a.
    a -> ReaderT Context (WriterT Documented (Writer Warnings)) a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure Maybe VName
    forall a. Maybe a
    Nothing
        Just QualName VName
    qn -> Maybe VName -> DocM (Maybe VName)
    forall a.
    a -> ReaderT Context (WriterT Documented (Writer Warnings)) a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure (Maybe VName -> DocM (Maybe VName))
    -> Maybe VName -> DocM (Maybe VName)
    forall a b. (a -> b) -> a -> b
    $ VName -> Maybe VName
    forall a. a -> Maybe a
    Just (VName -> Maybe VName) -> VName -> Maybe VName
    forall a b. (a -> b) -> a -> b
    $ QualName VName -> VName
    forall vn. QualName vn -> vn
    qualLeaf QualName VName
    qn

    lookupEnvForFile :: Maybe ImportName -> DocM (Maybe Env)
    lookupEnvForFile :: Maybe ImportName -> DocM (Maybe Env)
    lookupEnvForFile Maybe ImportName
    Nothing = (Context -> Maybe Env) -> DocM (Maybe Env)
    forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
    asks ((Context -> Maybe Env) -> DocM (Maybe Env))
    -> (Context -> Maybe Env) -> DocM (Maybe Env)
    forall a b. (a -> b) -> a -> b
    $ Env -> Maybe Env
    forall a. a -> Maybe a
    Just (Env -> Maybe Env) -> (Context -> Env) -> Context -> Maybe Env
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . FileModule -> Env
    fileEnv (FileModule -> Env) -> (Context -> FileModule) -> Context -> Env
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Context -> FileModule
    ctxFileMod
    lookupEnvForFile (Just ImportName
    file) = (Context -> Maybe Env) -> DocM (Maybe Env)
    forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
    asks ((Context -> Maybe Env) -> DocM (Maybe Env))
    -> (Context -> Maybe Env) -> DocM (Maybe Env)
    forall a b. (a -> b) -> a -> b
    $ (FileModule -> Env) -> Maybe FileModule -> Maybe Env
    forall a b. (a -> b) -> Maybe a -> Maybe b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap FileModule -> Env
    fileEnv (Maybe FileModule -> Maybe Env)
    -> (Context -> Maybe FileModule) -> Context -> Maybe Env
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ImportName -> Imports -> Maybe FileModule
    forall a b. Eq a => a -> [(a, b)] -> Maybe b
    lookup ImportName
    file (Imports -> Maybe FileModule)
    -> (Context -> Imports) -> Context -> Maybe FileModule
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Context -> Imports
    ctxImports

    describeGeneric ::
      VName ->
      IndexWhat ->
      Maybe DocComment ->
      (Html -> DocM Html) ->
      DocM Html
    describeGeneric :: VName
    -> IndexWhat
    -> Maybe DocComment
    -> (Html -> DocM Html)
    -> DocM Html
    describeGeneric VName
    name IndexWhat
    what Maybe DocComment
    doc Html -> DocM Html
    f = do
      name' <- Html -> Html
    H.span (Html -> Html) -> Attribute -> Html -> Html
    forall h. Attributable h => h -> Attribute -> h
    ! AttributeValue -> Attribute
    A.class_ AttributeValue
    "decl_name" (Html -> Html) -> DocM Html -> DocM Html
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> VName -> IndexWhat -> DocM Html
    vnameDescDef VName
    name IndexWhat
    what
      decl_type <- f name'
      doc' <- docHtml doc
      ref <- vnameSynopsisRef name
      let decl_doc = Html -> Html
    H.dd (Html -> Html) -> Attribute -> Html -> Html
    forall h. Attributable h => h -> Attribute -> h
    ! AttributeValue -> Attribute
    A.class_ AttributeValue
    "desc_doc" (Html -> Html) -> Html -> Html
    forall a b. (a -> b) -> a -> b
    $ Html
    doc'
          decl_header = (Html -> Html
    H.dt (Html -> Html) -> Attribute -> Html -> Html
    forall h. Attributable h => h -> Attribute -> h
    ! AttributeValue -> Attribute
    A.class_ AttributeValue
    "desc_header") (Html
    ref Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <> Html
    decl_type)
      pure $ decl_header <> decl_doc

    describeGenericMod ::
      VName ->
      IndexWhat ->
      ModTypeExp ->
      Maybe DocComment ->
      (Html -> DocM Html) ->
      DocM Html
    describeGenericMod :: VName
    -> IndexWhat
    -> ModTypeExpBase Info VName
    -> Maybe DocComment
    -> (Html -> DocM Html)
    -> DocM Html
    describeGenericMod VName
    name IndexWhat
    what ModTypeExpBase Info VName
    se Maybe DocComment
    doc Html -> DocM Html
    f = do
      name' <- Html -> Html
    H.span (Html -> Html) -> Attribute -> Html -> Html
    forall h. Attributable h => h -> Attribute -> h
    ! AttributeValue -> Attribute
    A.class_ AttributeValue
    "decl_name" (Html -> Html) -> DocM Html -> DocM Html
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> VName -> IndexWhat -> DocM Html
    vnameDescDef VName
    name IndexWhat
    what

      decl_type <- f name'

      doc' <- case se of
        ModTypeSpecs [SpecBase Info VName]
    specs SrcLoc
    _ -> Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    (<>) (Html -> Html -> Html)
    -> DocM Html
    -> ReaderT
         Context (WriterT Documented (Writer Warnings)) (Html -> Html)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Maybe DocComment -> DocM Html
    docHtml Maybe DocComment
    doc ReaderT
      Context (WriterT Documented (Writer Warnings)) (Html -> Html)
    -> DocM Html -> DocM Html
    forall a b.
    ReaderT Context (WriterT Documented (Writer Warnings)) (a -> b)
    -> ReaderT Context (WriterT Documented (Writer Warnings)) a
    -> ReaderT Context (WriterT Documented (Writer Warnings)) b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> [SpecBase Info VName] -> DocM Html
    describeSpecs [SpecBase Info VName]
    specs
        ModTypeExpBase Info VName
    _ -> Maybe DocComment -> DocM Html
    docHtml Maybe DocComment
    doc

      ref <- vnameSynopsisRef name

      let decl_doc = Html -> Html
    H.dd (Html -> Html) -> Attribute -> Html -> Html
    forall h. Attributable h => h -> Attribute -> h
    ! AttributeValue -> Attribute
    A.class_ AttributeValue
    "desc_doc" (Html -> Html) -> Html -> Html
    forall a b. (a -> b) -> a -> b
    $ Html
    doc'
          decl_header = (Html -> Html
    H.dt (Html -> Html) -> Attribute -> Html -> Html
    forall h. Attributable h => h -> Attribute -> h
    ! AttributeValue -> Attribute
    A.class_ AttributeValue
    "desc_header") (Html -> Html) -> Html -> Html
    forall a b. (a -> b) -> a -> b
    $ Html
    ref Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <> Html
    decl_type
      pure $ decl_header <> decl_doc

    describeDecs :: [Dec] -> DocM Html
    describeDecs :: [Dec] -> DocM Html
    describeDecs [Dec]
    decs = do
      visible <- (Context -> NoLink)
    -> ReaderT Context (WriterT Documented (Writer Warnings)) NoLink
    forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
    asks Context -> NoLink
    ctxVisibleMTys
      H.dl . mconcat
        <$> mapM
          (fmap $ H.div ! A.class_ "decl_description")
          (mapMaybe (describeDec visible) decs)

    describeDec :: S.Set VName -> Dec -> Maybe (DocM Html)
    describeDec :: NoLink -> Dec -> Maybe (DocM Html)
    describeDec NoLink
    _ (ValDec ValBindBase Info VName
    vb) = DocM Html -> Maybe (DocM Html)
    forall a. a -> Maybe a
    Just (DocM Html -> Maybe (DocM Html)) -> DocM Html -> Maybe (DocM Html)
    forall a b. (a -> b) -> a -> b
    $
      VName
    -> IndexWhat
    -> Maybe DocComment
    -> (Html -> DocM Html)
    -> DocM Html
    describeGeneric (ValBindBase Info VName -> VName
    forall (f :: * -> *) vn. ValBindBase f vn -> vn
    valBindName ValBindBase Info VName
    vb) (ValBindBase Info VName -> IndexWhat
    valBindWhat ValBindBase Info VName
    vb) (ValBindBase Info VName -> Maybe DocComment
    forall (f :: * -> *) vn. ValBindBase f vn -> Maybe DocComment
    valBindDoc ValBindBase Info VName
    vb) ((Html -> DocM Html) -> DocM Html)
    -> (Html -> DocM Html) -> DocM Html
    forall a b. (a -> b) -> a -> b
    $ \Html
    name -> do
        (lhs, mhs, rhs) <- Html -> ValBindBase Info VName -> DocM (Html, Html, Html)
    valBindHtml Html
    name ValBindBase Info VName
    vb
        pure $ lhs <> mhs <> ": " <> rhs
    describeDec NoLink
    _ (TypeDec TypeBindBase Info VName
    vb) =
      DocM Html -> Maybe (DocM Html)
    forall a. a -> Maybe a
    Just (DocM Html -> Maybe (DocM Html)) -> DocM Html -> Maybe (DocM Html)
    forall a b. (a -> b) -> a -> b
    $
        VName
    -> IndexWhat
    -> Maybe DocComment
    -> (Html -> DocM Html)
    -> DocM Html
    describeGeneric (TypeBindBase Info VName -> VName
    forall (f :: * -> *) vn. TypeBindBase f vn -> vn
    typeAlias TypeBindBase Info VName
    vb) IndexWhat
    IndexType (TypeBindBase Info VName -> Maybe DocComment
    forall (f :: * -> *) vn. TypeBindBase f vn -> Maybe DocComment
    typeDoc TypeBindBase Info VName
    vb) (Html -> TypeBindBase Info VName -> DocM Html
    `typeBindHtml` TypeBindBase Info VName
    vb)
    describeDec NoLink
    _ (ModTypeDec (ModTypeBind VName
    name ModTypeExpBase Info VName
    se Maybe DocComment
    doc SrcLoc
    _)) = DocM Html -> Maybe (DocM Html)
    forall a. a -> Maybe a
    Just (DocM Html -> Maybe (DocM Html)) -> DocM Html -> Maybe (DocM Html)
    forall a b. (a -> b) -> a -> b
    $
      VName
    -> IndexWhat
    -> ModTypeExpBase Info VName
    -> Maybe DocComment
    -> (Html -> DocM Html)
    -> DocM Html
    describeGenericMod VName
    name IndexWhat
    IndexModuleType ModTypeExpBase Info VName
    se Maybe DocComment
    doc ((Html -> DocM Html) -> DocM Html)
    -> (Html -> DocM Html) -> DocM Html
    forall a b. (a -> b) -> a -> b
    $ \Html
    name' ->
        Html -> DocM Html
    forall a.
    a -> ReaderT Context (WriterT Documented (Writer Warnings)) a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure (Html -> DocM Html) -> Html -> DocM Html
    forall a b. (a -> b) -> a -> b
    $ [Char] -> Html
    keyword [Char]
    "module type " Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <> Html
    name'
    describeDec NoLink
    _ (ModDec ModBindBase Info VName
    mb) = DocM Html -> Maybe (DocM Html)
    forall a. a -> Maybe a
    Just (DocM Html -> Maybe (DocM Html)) -> DocM Html -> Maybe (DocM Html)
    forall a b. (a -> b) -> a -> b
    $
      VName
    -> IndexWhat
    -> Maybe DocComment
    -> (Html -> DocM Html)
    -> DocM Html
    describeGeneric (ModBindBase Info VName -> VName
    forall (f :: * -> *) vn. ModBindBase f vn -> vn
    modName ModBindBase Info VName
    mb) IndexWhat
    IndexModule (ModBindBase Info VName -> Maybe DocComment
    forall (f :: * -> *) vn. ModBindBase f vn -> Maybe DocComment
    modDoc ModBindBase Info VName
    mb) ((Html -> DocM Html) -> DocM Html)
    -> (Html -> DocM Html) -> DocM Html
    forall a b. (a -> b) -> a -> b
    $ \Html
    name' ->
        Html -> DocM Html
    forall a.
    a -> ReaderT Context (WriterT Documented (Writer Warnings)) a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure (Html -> DocM Html) -> Html -> DocM Html
    forall a b. (a -> b) -> a -> b
    $ [Char] -> Html
    keyword [Char]
    "module " Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <> Html
    name'
    describeDec NoLink
    _ OpenDec {} = Maybe (DocM Html)
    forall a. Maybe a
    Nothing
    describeDec NoLink
    visible (LocalDec (ModTypeDec (ModTypeBind VName
    name ModTypeExpBase Info VName
    se Maybe DocComment
    doc SrcLoc
    _)) SrcLoc
    _)
      | VName
    name VName -> NoLink -> Bool
    forall a. Ord a => a -> Set a -> Bool
    `S.member` NoLink
    visible = DocM Html -> Maybe (DocM Html)
    forall a. a -> Maybe a
    Just (DocM Html -> Maybe (DocM Html)) -> DocM Html -> Maybe (DocM Html)
    forall a b. (a -> b) -> a -> b
    $
          VName
    -> IndexWhat
    -> ModTypeExpBase Info VName
    -> Maybe DocComment
    -> (Html -> DocM Html)
    -> DocM Html
    describeGenericMod VName
    name IndexWhat
    IndexModuleType ModTypeExpBase Info VName
    se Maybe DocComment
    doc ((Html -> DocM Html) -> DocM Html)
    -> (Html -> DocM Html) -> DocM Html
    forall a b. (a -> b) -> a -> b
    $ \Html
    name' ->
            Html -> DocM Html
    forall a.
    a -> ReaderT Context (WriterT Documented (Writer Warnings)) a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure (Html -> DocM Html) -> Html -> DocM Html
    forall a b. (a -> b) -> a -> b
    $ [Char] -> Html
    keyword [Char]
    "local module type " Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <> Html
    name'
    describeDec NoLink
    _ LocalDec {} = Maybe (DocM Html)
    forall a. Maybe a
    Nothing
    describeDec NoLink
    _ ImportDec {} = Maybe (DocM Html)
    forall a. Maybe a
    Nothing

    valBindWhat :: ValBind -> IndexWhat
    valBindWhat :: ValBindBase Info VName -> IndexWhat
    valBindWhat ValBindBase Info VName
    vb
      | [PatBase Info VName ParamType] -> Bool
    forall a. [a] -> Bool
    forall (t :: * -> *) a. Foldable t => t a -> Bool
    null (ValBindBase Info VName -> [PatBase Info VName ParamType]
    forall (f :: * -> *) vn.
    ValBindBase f vn -> [PatBase f vn ParamType]
    valBindParams ValBindBase Info VName
    vb),
        RetType [VName]
    _ TypeBase Size Uniqueness
    t <- Info ResRetType -> ResRetType
    forall a. Info a -> a
    unInfo (Info ResRetType -> ResRetType) -> Info ResRetType -> ResRetType
    forall a b. (a -> b) -> a -> b
    $ ValBindBase Info VName -> Info ResRetType
    forall (f :: * -> *) vn. ValBindBase f vn -> f ResRetType
    valBindRetType ValBindBase Info VName
    vb,
        TypeBase Size Uniqueness -> Bool
    forall dim as. TypeBase dim as -> Bool
    orderZero TypeBase Size Uniqueness
    t =
          IndexWhat
    IndexValue
      | Bool
    otherwise =
          IndexWhat
    IndexFunction

    describeSpecs :: [Spec] -> DocM Html
    describeSpecs :: [SpecBase Info VName] -> DocM Html
    describeSpecs [SpecBase Info VName]
    specs =
      Html -> Html
    H.dl (Html -> Html) -> ([Html] -> Html) -> [Html] -> Html
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Html] -> Html
    forall a. Monoid a => [a] -> a
    mconcat ([Html] -> Html)
    -> ReaderT Context (WriterT Documented (Writer Warnings)) [Html]
    -> DocM Html
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> (SpecBase Info VName -> DocM Html)
    -> [SpecBase Info VName]
    -> ReaderT Context (WriterT Documented (Writer Warnings)) [Html]
    forall (t :: * -> *) (m :: * -> *) a b.
    (Traversable t, Monad m) =>
    (a -> m b) -> t a -> m (t b)
    forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
    mapM SpecBase Info VName -> DocM Html
    describeSpec [SpecBase Info VName]
    specs

    describeSpec :: Spec -> DocM Html
    describeSpec :: SpecBase Info VName -> DocM Html
    describeSpec (ValSpec VName
    name [TypeParamBase VName]
    tparams TypeExp Size VName
    t Info StructType
    _ Maybe DocComment
    doc SrcLoc
    _) =
      VName
    -> IndexWhat
    -> Maybe DocComment
    -> (Html -> DocM Html)
    -> DocM Html
    describeGeneric VName
    name IndexWhat
    what Maybe DocComment
    doc ((Html -> DocM Html) -> DocM Html)
    -> (Html -> DocM Html) -> DocM Html
    forall a b. (a -> b) -> a -> b
    $ \Html
    name' -> do
        tparams' <- [Html] -> Html
    forall a. Monoid a => [a] -> a
    mconcat ([Html] -> Html)
    -> ReaderT Context (WriterT Documented (Writer Warnings)) [Html]
    -> DocM Html
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> (TypeParamBase VName -> DocM Html)
    -> [TypeParamBase VName]
    -> ReaderT Context (WriterT Documented (Writer Warnings)) [Html]
    forall (t :: * -> *) (m :: * -> *) a b.
    (Traversable t, Monad m) =>
    (a -> m b) -> t a -> m (t b)
    forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
    mapM ((Html -> Html) -> DocM Html -> DocM Html
    forall a b.
    (a -> b)
    -> ReaderT Context (WriterT Documented (Writer Warnings)) a
    -> ReaderT Context (WriterT Documented (Writer Warnings)) b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap (Html
    " " Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <>) (DocM Html -> DocM Html)
    -> (TypeParamBase VName -> DocM Html)
    -> TypeParamBase VName
    -> DocM Html
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . TypeParamBase VName -> DocM Html
    typeParamHtml) [TypeParamBase VName]
    tparams
        t' <- noLink (map typeParamName tparams) $ typeExpHtml t
        pure $ keyword "val " <> name' <> tparams' <> ": " <> t'
      where
        what :: IndexWhat
    what =
          case TypeExp Size VName
    t of
            TEArrow {} -> IndexWhat
    IndexFunction
            TypeExp Size VName
    _ -> IndexWhat
    IndexValue
    describeSpec (TypeAbbrSpec TypeBindBase Info VName
    vb) =
      VName
    -> IndexWhat
    -> Maybe DocComment
    -> (Html -> DocM Html)
    -> DocM Html
    describeGeneric (TypeBindBase Info VName -> VName
    forall (f :: * -> *) vn. TypeBindBase f vn -> vn
    typeAlias TypeBindBase Info VName
    vb) IndexWhat
    IndexType (TypeBindBase Info VName -> Maybe DocComment
    forall (f :: * -> *) vn. TypeBindBase f vn -> Maybe DocComment
    typeDoc TypeBindBase Info VName
    vb) (Html -> TypeBindBase Info VName -> DocM Html
    `typeBindHtml` TypeBindBase Info VName
    vb)
    describeSpec (TypeSpec Liftedness
    l VName
    name [TypeParamBase VName]
    tparams Maybe DocComment
    doc SrcLoc
    _) =
      VName
    -> IndexWhat
    -> Maybe DocComment
    -> (Html -> DocM Html)
    -> DocM Html
    describeGeneric VName
    name IndexWhat
    IndexType Maybe DocComment
    doc ((Html -> DocM Html) -> DocM Html)
    -> (Html -> DocM Html) -> DocM Html
    forall a b. (a -> b) -> a -> b
    $ \Html
    name' -> Liftedness -> Html -> [TypeParamBase VName] -> DocM Html
    typeAbbrevHtml Liftedness
    l Html
    name' [TypeParamBase VName]
    tparams
    describeSpec (ModSpec VName
    name ModTypeExpBase Info VName
    se Maybe DocComment
    doc SrcLoc
    _) =
      VName
    -> IndexWhat
    -> ModTypeExpBase Info VName
    -> Maybe DocComment
    -> (Html -> DocM Html)
    -> DocM Html
    describeGenericMod VName
    name IndexWhat
    IndexModule ModTypeExpBase Info VName
    se Maybe DocComment
    doc ((Html -> DocM Html) -> DocM Html)
    -> (Html -> DocM Html) -> DocM Html
    forall a b. (a -> b) -> a -> b
    $ \Html
    name' ->
        case ModTypeExpBase Info VName
    se of
          ModTypeSpecs {} -> Html -> DocM Html
    forall a.
    a -> ReaderT Context (WriterT Documented (Writer Warnings)) a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure (Html -> DocM Html) -> Html -> DocM Html
    forall a b. (a -> b) -> a -> b
    $ [Char] -> Html
    keyword [Char]
    "module " Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <> Html
    name'
          ModTypeExpBase Info VName
    _ -> do
            se' <- ModTypeExpBase Info VName -> DocM Html
    synopsisModTypeExp ModTypeExpBase Info VName
    se
            pure $ keyword "module " <> name' <> ": " <> se'
    describeSpec (IncludeSpec ModTypeExpBase Info VName
    sig SrcLoc
    _) = do
      sig' <- ModTypeExpBase Info VName -> DocM Html
    synopsisModTypeExp ModTypeExpBase Info VName
    sig
      doc' <- docHtml Nothing
      let decl_header =
            (Html -> Html
    H.dt (Html -> Html) -> Attribute -> Html -> Html
    forall h. Attributable h => h -> Attribute -> h
    ! AttributeValue -> Attribute
    A.class_ AttributeValue
    "desc_header") (Html -> Html) -> Html -> Html
    forall a b. (a -> b) -> a -> b
    $
              (Html -> Html
    H.span (Html -> Html) -> Attribute -> Html -> Html
    forall h. Attributable h => h -> Attribute -> h
    ! AttributeValue -> Attribute
    A.class_ AttributeValue
    "synopsis_link") Html
    forall a. Monoid a => a
    mempty
                Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <> [Char] -> Html
    keyword [Char]
    "include "
                Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <> Html
    sig'
          decl_doc = Html -> Html
    H.dd (Html -> Html) -> Attribute -> Html -> Html
    forall h. Attributable h => h -> Attribute -> h
    ! AttributeValue -> Attribute
    A.class_ AttributeValue
    "desc_doc" (Html -> Html) -> Html -> Html
    forall a b. (a -> b) -> a -> b
    $ Html
    doc'
      pure $ decl_header <> decl_doc

    -- | @renderFiles important_imports imports@ produces HTML files
    -- documenting the type-checked program @imports@, with the files in
    -- @important_imports@ considered most important. The HTML files must
    -- be written to the specific locations indicated in the return value,
    -- or the relative links will be wrong.
    renderFiles :: [ImportName] -> Imports -> ([(FilePath, Html)], Warnings)
    renderFiles :: [ImportName] -> Imports -> ([([Char], Html)], Warnings)
    renderFiles [ImportName]
    important_imports Imports
    imports = Writer Warnings [([Char], Html)] -> ([([Char], Html)], Warnings)
    forall w a. Writer w a -> (a, w)
    runWriter (Writer Warnings [([Char], Html)] -> ([([Char], Html)], Warnings))
    -> Writer Warnings [([Char], Html)] -> ([([Char], Html)], Warnings)
    forall a b. (a -> b) -> a -> b
    $ do
      (import_pages, documented) <- WriterT Documented (Writer Warnings) [(ImportName, (Html, Html))]
    -> WriterT
         Warnings Identity ([(ImportName, (Html, Html))], Documented)
    forall w (m :: * -> *) a. WriterT w m a -> m (a, w)
    runWriterT (WriterT Documented (Writer Warnings) [(ImportName, (Html, Html))]
     -> WriterT
          Warnings Identity ([(ImportName, (Html, Html))], Documented))
    -> WriterT
         Documented (Writer Warnings) [(ImportName, (Html, Html))]
    -> WriterT
         Warnings Identity ([(ImportName, (Html, Html))], Documented)
    forall a b. (a -> b) -> a -> b
    $ Imports
    -> ((ImportName, FileModule)
        -> WriterT Documented (Writer Warnings) (ImportName, (Html, Html)))
    -> WriterT
         Documented (Writer Warnings) [(ImportName, (Html, Html))]
    forall (t :: * -> *) (m :: * -> *) a b.
    (Traversable t, Monad m) =>
    t a -> (a -> m b) -> m (t b)
    forM Imports
    imports (((ImportName, FileModule)
      -> WriterT Documented (Writer Warnings) (ImportName, (Html, Html)))
     -> WriterT
          Documented (Writer Warnings) [(ImportName, (Html, Html))])
    -> ((ImportName, FileModule)
        -> WriterT Documented (Writer Warnings) (ImportName, (Html, Html)))
    -> WriterT
         Documented (Writer Warnings) [(ImportName, (Html, Html))]
    forall a b. (a -> b) -> a -> b
    $ \(ImportName
    current, FileModule
    fm) -> do
        let ctx :: Context
    ctx =
              Context
                { ctxCurrent :: [Char]
    ctxCurrent = [Char] -> [Char] -> [Char]
    makeRelative [Char]
    "/" ([Char] -> [Char]) -> [Char] -> [Char]
    forall a b. (a -> b) -> a -> b
    $ ImportName -> [Char]
    includeToFilePath ImportName
    current,
                  ctxFileMod :: FileModule
    ctxFileMod = FileModule
    fm,
                  ctxImports :: Imports
    ctxImports = Imports
    imports,
                  ctxNoLink :: NoLink
    ctxNoLink = NoLink
    forall a. Monoid a => a
    mempty,
                  ctxFileMap :: FileMap
    ctxFileMap = FileMap
    file_map,
                  ctxVisibleMTys :: NoLink
    ctxVisibleMTys = Prog -> NoLink
    progModuleTypes (Prog -> NoLink) -> Prog -> NoLink
    forall a b. (a -> b) -> a -> b
    $ FileModule -> Prog
    fileProg FileModule
    fm
                }
        (ReaderT
       Context
       (WriterT Documented (Writer Warnings))
       (ImportName, (Html, Html))
     -> Context
     -> WriterT Documented (Writer Warnings) (ImportName, (Html, Html)))
    -> Context
    -> ReaderT
         Context
         (WriterT Documented (Writer Warnings))
         (ImportName, (Html, Html))
    -> WriterT Documented (Writer Warnings) (ImportName, (Html, Html))
    forall a b c. (a -> b -> c) -> b -> a -> c
    flip ReaderT
      Context
      (WriterT Documented (Writer Warnings))
      (ImportName, (Html, Html))
    -> Context
    -> WriterT Documented (Writer Warnings) (ImportName, (Html, Html))
    forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
    runReaderT Context
    ctx (ReaderT
       Context
       (WriterT Documented (Writer Warnings))
       (ImportName, (Html, Html))
     -> WriterT Documented (Writer Warnings) (ImportName, (Html, Html)))
    -> ReaderT
         Context
         (WriterT Documented (Writer Warnings))
         (ImportName, (Html, Html))
    -> WriterT Documented (Writer Warnings) (ImportName, (Html, Html))
    forall a b. (a -> b) -> a -> b
    $ do
          (first_paragraph, maybe_abstract, maybe_sections) <- Prog -> DocM (Html, Html, Html)
    headerDoc (Prog -> DocM (Html, Html, Html))
    -> Prog -> DocM (Html, Html, Html)
    forall a b. (a -> b) -> a -> b
    $ FileModule -> Prog
    fileProg FileModule
    fm

          synopsis <- (H.div ! A.id "module") <$> synopsisDecs (progDecs $ fileProg fm)

          description <- describeDecs $ progDecs $ fileProg fm

          pure
            ( current,
              ( H.docTypeHtml ! A.lang "en"
                  $ addBoilerplateWithNav
                    important_imports
                    imports
                    ("doc" </> includeToFilePath current)
                    (includeToString current)
                  $ H.main
                  $ maybe_abstract
                    <> selfLink "synopsis" (H.h2 "Synopsis")
                    <> (H.div ! A.id "overview") synopsis
                    <> selfLink "description" (H.h2 "Description")
                    <> description
                    <> maybe_sections,
                first_paragraph
              )
            )

      pure $
        [ ("index.html", contentsPage important_imports $ map (fmap snd) import_pages),
          ("doc-index.html", indexPage important_imports imports documented file_map)
        ]
          ++ map (importHtml *** fst) import_pages
      where
        file_map :: FileMap
    file_map = Imports -> FileMap
    vnameToFileMap Imports
    imports
        importHtml :: ImportName -> [Char]
    importHtml ImportName
    import_name =
          [Char]
    "doc" [Char] -> [Char] -> [Char]
    </> [Char] -> [Char] -> [Char]
    makeRelative [Char]
    "/" ([Char] -> [Char]
    forall a. IsString a => [Char] -> a
    fromString (ImportName -> [Char]
    includeToString ImportName
    import_name)) [Char] -> [Char] -> [Char]
    -<.> [Char]
    "html"