    {-# LANGUAGE GeneralizedNewtypeDeriving, DeriveDataTypeable, DeriveFunctor, ViewPatterns #-}
    {-# LANGUAGE RecordWildCards, OverloadedStrings, PatternGuards, ScopedTypeVariables #-}

    -- | Types used to generate the input.
    module Input.Item(
        Sig(..), Ctx(..), Ty(..), prettySig,
        Item(..), itemName,
        Target(..), targetExpandURL, TargetId(..),
        splitIPackage, splitIModule,
        hseToSig, hseToItem, item_test,
        unHTMLTarget
        ) where

    import Numeric
    import Control.Applicative
    import Data.Tuple.Extra
    import Language.Haskell.Exts
    import Data.Char
    import Data.List.Extra
    import Data.Maybe
    import Data.Ix
    import Data.Binary
    import Foreign.Storable
    import Control.DeepSeq
    import Data.Data
    import General.Util
    import General.Str
    import General.IString
    import Prelude
    import qualified Data.Aeson as J
    import Data.Aeson.Types
    import Test.QuickCheck
    ---------------------------------------------------------------------
    -- TYPES

    data Sig n = Sig {forall n. Sig n -> [Ctx n]
    sigCtx :: [Ctx n], forall n. Sig n -> [Ty n]
    sigTy :: [Ty n]} deriving (Int -> Sig n -> ShowS
    [Sig n] -> ShowS
    Sig n -> [Char]
    (Int -> Sig n -> ShowS)
    -> (Sig n -> [Char]) -> ([Sig n] -> ShowS) -> Show (Sig n)
    forall n. Show n => Int -> Sig n -> ShowS
    forall n. Show n => [Sig n] -> ShowS
    forall n. Show n => Sig n -> [Char]
    forall a.
    (Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: forall n. Show n => Int -> Sig n -> ShowS
    showsPrec :: Int -> Sig n -> ShowS
    $cshow :: forall n. Show n => Sig n -> [Char]
    show :: Sig n -> [Char]
    $cshowList :: forall n. Show n => [Sig n] -> ShowS
    showList :: [Sig n] -> ShowS
    Show,Sig n -> Sig n -> Bool
    (Sig n -> Sig n -> Bool) -> (Sig n -> Sig n -> Bool) -> Eq (Sig n)
    forall n. Eq n => Sig n -> Sig n -> Bool
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: forall n. Eq n => Sig n -> Sig n -> Bool
    == :: Sig n -> Sig n -> Bool
    $c/= :: forall n. Eq n => Sig n -> Sig n -> Bool
    /= :: Sig n -> Sig n -> Bool
    Eq,Eq (Sig n)
    Eq (Sig n)
    -> (Sig n -> Sig n -> Ordering)
    -> (Sig n -> Sig n -> Bool)
    -> (Sig n -> Sig n -> Bool)
    -> (Sig n -> Sig n -> Bool)
    -> (Sig n -> Sig n -> Bool)
    -> (Sig n -> Sig n -> Sig n)
    -> (Sig n -> Sig n -> Sig n)
    -> Ord (Sig n)
    Sig n -> Sig n -> Bool
    Sig n -> Sig n -> Ordering
    Sig n -> Sig n -> Sig n
    forall a.
    Eq a
    -> (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    forall {n}. Ord n => Eq (Sig n)
    forall n. Ord n => Sig n -> Sig n -> Bool
    forall n. Ord n => Sig n -> Sig n -> Ordering
    forall n. Ord n => Sig n -> Sig n -> Sig n
    $ccompare :: forall n. Ord n => Sig n -> Sig n -> Ordering
    compare :: Sig n -> Sig n -> Ordering
    $c< :: forall n. Ord n => Sig n -> Sig n -> Bool
    < :: Sig n -> Sig n -> Bool
    $c<= :: forall n. Ord n => Sig n -> Sig n -> Bool
    <= :: Sig n -> Sig n -> Bool
    $c> :: forall n. Ord n => Sig n -> Sig n -> Bool
    > :: Sig n -> Sig n -> Bool
    $c>= :: forall n. Ord n => Sig n -> Sig n -> Bool
    >= :: Sig n -> Sig n -> Bool
    $cmax :: forall n. Ord n => Sig n -> Sig n -> Sig n
    max :: Sig n -> Sig n -> Sig n
    $cmin :: forall n. Ord n => Sig n -> Sig n -> Sig n
    min :: Sig n -> Sig n -> Sig n
    Ord,Typeable,Typeable (Sig n)
    Typeable (Sig n)
    -> (forall (c :: * -> *).
        (forall d b. Data d => c (d -> b) -> d -> c b)
        -> (forall g. g -> c g) -> Sig n -> c (Sig n))
    -> (forall (c :: * -> *).
        (forall b r. Data b => c (b -> r) -> c r)
        -> (forall r. r -> c r) -> Constr -> c (Sig n))
    -> (Sig n -> Constr)
    -> (Sig n -> DataType)
    -> (forall (t :: * -> *) (c :: * -> *).
        Typeable t =>
        (forall d. Data d => c (t d)) -> Maybe (c (Sig n)))
    -> (forall (t :: * -> * -> *) (c :: * -> *).
        Typeable t =>
        (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Sig n)))
    -> ((forall b. Data b => b -> b) -> Sig n -> Sig n)
    -> (forall r r'.
        (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Sig n -> r)
    -> (forall r r'.
        (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Sig n -> r)
    -> (forall u. (forall d. Data d => d -> u) -> Sig n -> [u])
    -> (forall u. Int -> (forall d. Data d => d -> u) -> Sig n -> u)
    -> (forall (m :: * -> *).
        Monad m =>
        (forall d. Data d => d -> m d) -> Sig n -> m (Sig n))
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> Sig n -> m (Sig n))
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> Sig n -> m (Sig n))
    -> Data (Sig n)
    Sig n -> Constr
    Sig n -> DataType
    (forall b. Data b => b -> b) -> Sig n -> Sig n
    forall {n}. Data n => Typeable (Sig n)
    forall n. Data n => Sig n -> Constr
    forall n. Data n => Sig n -> DataType
    forall n. Data n => (forall b. Data b => b -> b) -> Sig n -> Sig n
    forall n u.
    Data n =>
    Int -> (forall d. Data d => d -> u) -> Sig n -> u
    forall n u. Data n => (forall d. Data d => d -> u) -> Sig n -> [u]
    forall n r r'.
    Data n =>
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Sig n -> r
    forall n r r'.
    Data n =>
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Sig n -> r
    forall n (m :: * -> *).
    (Data n, Monad m) =>
    (forall d. Data d => d -> m d) -> Sig n -> m (Sig n)
    forall n (m :: * -> *).
    (Data n, MonadPlus m) =>
    (forall d. Data d => d -> m d) -> Sig n -> m (Sig n)
    forall n (c :: * -> *).
    Data n =>
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (Sig n)
    forall n (c :: * -> *).
    Data n =>
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Sig n -> c (Sig n)
    forall n (t :: * -> *) (c :: * -> *).
    (Data n, Typeable t) =>
    (forall d. Data d => c (t d)) -> Maybe (c (Sig n))
    forall n (t :: * -> * -> *) (c :: * -> *).
    (Data n, Typeable t) =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Sig n))
    forall a.
    Typeable a
    -> (forall (c :: * -> *).
        (forall d b. Data d => c (d -> b) -> d -> c b)
        -> (forall g. g -> c g) -> a -> c a)
    -> (forall (c :: * -> *).
        (forall b r. Data b => c (b -> r) -> c r)
        -> (forall r. r -> c r) -> Constr -> c a)
    -> (a -> Constr)
    -> (a -> DataType)
    -> (forall (t :: * -> *) (c :: * -> *).
        Typeable t =>
        (forall d. Data d => c (t d)) -> Maybe (c a))
    -> (forall (t :: * -> * -> *) (c :: * -> *).
        Typeable t =>
        (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
    -> ((forall b. Data b => b -> b) -> a -> a)
    -> (forall r r'.
        (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
    -> (forall r r'.
        (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
    -> (forall u. (forall d. Data d => d -> u) -> a -> [u])
    -> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
    -> (forall (m :: * -> *).
        Monad m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> Data a
    forall u. Int -> (forall d. Data d => d -> u) -> Sig n -> u
    forall u. (forall d. Data d => d -> u) -> Sig n -> [u]
    forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Sig n -> r
    forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Sig n -> r
    forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Sig n -> m (Sig n)
    forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Sig n -> m (Sig n)
    forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (Sig n)
    forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Sig n -> c (Sig n)
    forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (Sig n))
    forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Sig n))
    $cgfoldl :: forall n (c :: * -> *).
    Data n =>
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Sig n -> c (Sig n)
    gfoldl :: forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Sig n -> c (Sig n)
    $cgunfold :: forall n (c :: * -> *).
    Data n =>
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (Sig n)
    gunfold :: forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (Sig n)
    $ctoConstr :: forall n. Data n => Sig n -> Constr
    toConstr :: Sig n -> Constr
    $cdataTypeOf :: forall n. Data n => Sig n -> DataType
    dataTypeOf :: Sig n -> DataType
    $cdataCast1 :: forall n (t :: * -> *) (c :: * -> *).
    (Data n, Typeable t) =>
    (forall d. Data d => c (t d)) -> Maybe (c (Sig n))
    dataCast1 :: forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (Sig n))
    $cdataCast2 :: forall n (t :: * -> * -> *) (c :: * -> *).
    (Data n, Typeable t) =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Sig n))
    dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Sig n))
    $cgmapT :: forall n. Data n => (forall b. Data b => b -> b) -> Sig n -> Sig n
    gmapT :: (forall b. Data b => b -> b) -> Sig n -> Sig n
    $cgmapQl :: forall n r r'.
    Data n =>
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Sig n -> r
    gmapQl :: forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Sig n -> r
    $cgmapQr :: forall n r r'.
    Data n =>
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Sig n -> r
    gmapQr :: forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Sig n -> r
    $cgmapQ :: forall n u. Data n => (forall d. Data d => d -> u) -> Sig n -> [u]
    gmapQ :: forall u. (forall d. Data d => d -> u) -> Sig n -> [u]
    $cgmapQi :: forall n u.
    Data n =>
    Int -> (forall d. Data d => d -> u) -> Sig n -> u
    gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Sig n -> u
    $cgmapM :: forall n (m :: * -> *).
    (Data n, Monad m) =>
    (forall d. Data d => d -> m d) -> Sig n -> m (Sig n)
    gmapM :: forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Sig n -> m (Sig n)
    $cgmapMp :: forall n (m :: * -> *).
    (Data n, MonadPlus m) =>
    (forall d. Data d => d -> m d) -> Sig n -> m (Sig n)
    gmapMp :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Sig n -> m (Sig n)
    $cgmapMo :: forall n (m :: * -> *).
    (Data n, MonadPlus m) =>
    (forall d. Data d => d -> m d) -> Sig n -> m (Sig n)
    gmapMo :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Sig n -> m (Sig n)
    Data,(forall a b. (a -> b) -> Sig a -> Sig b)
    -> (forall a b. a -> Sig b -> Sig a) -> Functor Sig
    forall a b. a -> Sig b -> Sig a
    forall a b. (a -> b) -> Sig a -> Sig b
    forall (f :: * -> *).
    (forall a b. (a -> b) -> f a -> f b)
    -> (forall a b. a -> f b -> f a) -> Functor f
    $cfmap :: forall a b. (a -> b) -> Sig a -> Sig b
    fmap :: forall a b. (a -> b) -> Sig a -> Sig b
    $c<$ :: forall a b. a -> Sig b -> Sig a
    <$ :: forall a b. a -> Sig b -> Sig a
    Functor) -- list of -> types
    data Ctx n = Ctx n n deriving (Int -> Ctx n -> ShowS
    [Ctx n] -> ShowS
    Ctx n -> [Char]
    (Int -> Ctx n -> ShowS)
    -> (Ctx n -> [Char]) -> ([Ctx n] -> ShowS) -> Show (Ctx n)
    forall n. Show n => Int -> Ctx n -> ShowS
    forall n. Show n => [Ctx n] -> ShowS
    forall n. Show n => Ctx n -> [Char]
    forall a.
    (Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: forall n. Show n => Int -> Ctx n -> ShowS
    showsPrec :: Int -> Ctx n -> ShowS
    $cshow :: forall n. Show n => Ctx n -> [Char]
    show :: Ctx n -> [Char]
    $cshowList :: forall n. Show n => [Ctx n] -> ShowS
    showList :: [Ctx n] -> ShowS
    Show,Ctx n -> Ctx n -> Bool
    (Ctx n -> Ctx n -> Bool) -> (Ctx n -> Ctx n -> Bool) -> Eq (Ctx n)
    forall n. Eq n => Ctx n -> Ctx n -> Bool
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: forall n. Eq n => Ctx n -> Ctx n -> Bool
    == :: Ctx n -> Ctx n -> Bool
    $c/= :: forall n. Eq n => Ctx n -> Ctx n -> Bool
    /= :: Ctx n -> Ctx n -> Bool
    Eq,Eq (Ctx n)
    Eq (Ctx n)
    -> (Ctx n -> Ctx n -> Ordering)
    -> (Ctx n -> Ctx n -> Bool)
    -> (Ctx n -> Ctx n -> Bool)
    -> (Ctx n -> Ctx n -> Bool)
    -> (Ctx n -> Ctx n -> Bool)
    -> (Ctx n -> Ctx n -> Ctx n)
    -> (Ctx n -> Ctx n -> Ctx n)
    -> Ord (Ctx n)
    Ctx n -> Ctx n -> Bool
    Ctx n -> Ctx n -> Ordering
    Ctx n -> Ctx n -> Ctx n
    forall a.
    Eq a
    -> (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    forall {n}. Ord n => Eq (Ctx n)
    forall n. Ord n => Ctx n -> Ctx n -> Bool
    forall n. Ord n => Ctx n -> Ctx n -> Ordering
    forall n. Ord n => Ctx n -> Ctx n -> Ctx n
    $ccompare :: forall n. Ord n => Ctx n -> Ctx n -> Ordering
    compare :: Ctx n -> Ctx n -> Ordering
    $c< :: forall n. Ord n => Ctx n -> Ctx n -> Bool
    < :: Ctx n -> Ctx n -> Bool
    $c<= :: forall n. Ord n => Ctx n -> Ctx n -> Bool
    <= :: Ctx n -> Ctx n -> Bool
    $c> :: forall n. Ord n => Ctx n -> Ctx n -> Bool
    > :: Ctx n -> Ctx n -> Bool
    $c>= :: forall n. Ord n => Ctx n -> Ctx n -> Bool
    >= :: Ctx n -> Ctx n -> Bool
    $cmax :: forall n. Ord n => Ctx n -> Ctx n -> Ctx n
    max :: Ctx n -> Ctx n -> Ctx n
    $cmin :: forall n. Ord n => Ctx n -> Ctx n -> Ctx n
    min :: Ctx n -> Ctx n -> Ctx n
    Ord,Typeable,Typeable (Ctx n)
    Typeable (Ctx n)
    -> (forall (c :: * -> *).
        (forall d b. Data d => c (d -> b) -> d -> c b)
        -> (forall g. g -> c g) -> Ctx n -> c (Ctx n))
    -> (forall (c :: * -> *).
        (forall b r. Data b => c (b -> r) -> c r)
        -> (forall r. r -> c r) -> Constr -> c (Ctx n))
    -> (Ctx n -> Constr)
    -> (Ctx n -> DataType)
    -> (forall (t :: * -> *) (c :: * -> *).
        Typeable t =>
        (forall d. Data d => c (t d)) -> Maybe (c (Ctx n)))
    -> (forall (t :: * -> * -> *) (c :: * -> *).
        Typeable t =>
        (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Ctx n)))
    -> ((forall b. Data b => b -> b) -> Ctx n -> Ctx n)
    -> (forall r r'.
        (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Ctx n -> r)
    -> (forall r r'.
        (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Ctx n -> r)
    -> (forall u. (forall d. Data d => d -> u) -> Ctx n -> [u])
    -> (forall u. Int -> (forall d. Data d => d -> u) -> Ctx n -> u)
    -> (forall (m :: * -> *).
        Monad m =>
        (forall d. Data d => d -> m d) -> Ctx n -> m (Ctx n))
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> Ctx n -> m (Ctx n))
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> Ctx n -> m (Ctx n))
    -> Data (Ctx n)
    Ctx n -> Constr
    Ctx n -> DataType
    (forall b. Data b => b -> b) -> Ctx n -> Ctx n
    forall {n}. Data n => Typeable (Ctx n)
    forall n. Data n => Ctx n -> Constr
    forall n. Data n => Ctx n -> DataType
    forall n. Data n => (forall b. Data b => b -> b) -> Ctx n -> Ctx n
    forall n u.
    Data n =>
    Int -> (forall d. Data d => d -> u) -> Ctx n -> u
    forall n u. Data n => (forall d. Data d => d -> u) -> Ctx n -> [u]
    forall n r r'.
    Data n =>
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Ctx n -> r
    forall n r r'.
    Data n =>
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Ctx n -> r
    forall n (m :: * -> *).
    (Data n, Monad m) =>
    (forall d. Data d => d -> m d) -> Ctx n -> m (Ctx n)
    forall n (m :: * -> *).
    (Data n, MonadPlus m) =>
    (forall d. Data d => d -> m d) -> Ctx n -> m (Ctx n)
    forall n (c :: * -> *).
    Data n =>
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (Ctx n)
    forall n (c :: * -> *).
    Data n =>
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Ctx n -> c (Ctx n)
    forall n (t :: * -> *) (c :: * -> *).
    (Data n, Typeable t) =>
    (forall d. Data d => c (t d)) -> Maybe (c (Ctx n))
    forall n (t :: * -> * -> *) (c :: * -> *).
    (Data n, Typeable t) =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Ctx n))
    forall a.
    Typeable a
    -> (forall (c :: * -> *).
        (forall d b. Data d => c (d -> b) -> d -> c b)
        -> (forall g. g -> c g) -> a -> c a)
    -> (forall (c :: * -> *).
        (forall b r. Data b => c (b -> r) -> c r)
        -> (forall r. r -> c r) -> Constr -> c a)
    -> (a -> Constr)
    -> (a -> DataType)
    -> (forall (t :: * -> *) (c :: * -> *).
        Typeable t =>
        (forall d. Data d => c (t d)) -> Maybe (c a))
    -> (forall (t :: * -> * -> *) (c :: * -> *).
        Typeable t =>
        (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
    -> ((forall b. Data b => b -> b) -> a -> a)
    -> (forall r r'.
        (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
    -> (forall r r'.
        (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
    -> (forall u. (forall d. Data d => d -> u) -> a -> [u])
    -> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
    -> (forall (m :: * -> *).
        Monad m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> Data a
    forall u. Int -> (forall d. Data d => d -> u) -> Ctx n -> u
    forall u. (forall d. Data d => d -> u) -> Ctx n -> [u]
    forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Ctx n -> r
    forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Ctx n -> r
    forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Ctx n -> m (Ctx n)
    forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Ctx n -> m (Ctx n)
    forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (Ctx n)
    forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Ctx n -> c (Ctx n)
    forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (Ctx n))
    forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Ctx n))
    $cgfoldl :: forall n (c :: * -> *).
    Data n =>
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Ctx n -> c (Ctx n)
    gfoldl :: forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Ctx n -> c (Ctx n)
    $cgunfold :: forall n (c :: * -> *).
    Data n =>
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (Ctx n)
    gunfold :: forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (Ctx n)
    $ctoConstr :: forall n. Data n => Ctx n -> Constr
    toConstr :: Ctx n -> Constr
    $cdataTypeOf :: forall n. Data n => Ctx n -> DataType
    dataTypeOf :: Ctx n -> DataType
    $cdataCast1 :: forall n (t :: * -> *) (c :: * -> *).
    (Data n, Typeable t) =>
    (forall d. Data d => c (t d)) -> Maybe (c (Ctx n))
    dataCast1 :: forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (Ctx n))
    $cdataCast2 :: forall n (t :: * -> * -> *) (c :: * -> *).
    (Data n, Typeable t) =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Ctx n))
    dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Ctx n))
    $cgmapT :: forall n. Data n => (forall b. Data b => b -> b) -> Ctx n -> Ctx n
    gmapT :: (forall b. Data b => b -> b) -> Ctx n -> Ctx n
    $cgmapQl :: forall n r r'.
    Data n =>
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Ctx n -> r
    gmapQl :: forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Ctx n -> r
    $cgmapQr :: forall n r r'.
    Data n =>
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Ctx n -> r
    gmapQr :: forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Ctx n -> r
    $cgmapQ :: forall n u. Data n => (forall d. Data d => d -> u) -> Ctx n -> [u]
    gmapQ :: forall u. (forall d. Data d => d -> u) -> Ctx n -> [u]
    $cgmapQi :: forall n u.
    Data n =>
    Int -> (forall d. Data d => d -> u) -> Ctx n -> u
    gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Ctx n -> u
    $cgmapM :: forall n (m :: * -> *).
    (Data n, Monad m) =>
    (forall d. Data d => d -> m d) -> Ctx n -> m (Ctx n)
    gmapM :: forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Ctx n -> m (Ctx n)
    $cgmapMp :: forall n (m :: * -> *).
    (Data n, MonadPlus m) =>
    (forall d. Data d => d -> m d) -> Ctx n -> m (Ctx n)
    gmapMp :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Ctx n -> m (Ctx n)
    $cgmapMo :: forall n (m :: * -> *).
    (Data n, MonadPlus m) =>
    (forall d. Data d => d -> m d) -> Ctx n -> m (Ctx n)
    gmapMo :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Ctx n -> m (Ctx n)
    Data,(forall a b. (a -> b) -> Ctx a -> Ctx b)
    -> (forall a b. a -> Ctx b -> Ctx a) -> Functor Ctx
    forall a b. a -> Ctx b -> Ctx a
    forall a b. (a -> b) -> Ctx a -> Ctx b
    forall (f :: * -> *).
    (forall a b. (a -> b) -> f a -> f b)
    -> (forall a b. a -> f b -> f a) -> Functor f
    $cfmap :: forall a b. (a -> b) -> Ctx a -> Ctx b
    fmap :: forall a b. (a -> b) -> Ctx a -> Ctx b
    $c<$ :: forall a b. a -> Ctx b -> Ctx a
    <$ :: forall a b. a -> Ctx b -> Ctx a
    Functor) -- context, second will usually be a free variable
    data Ty n = TCon n [Ty n] | TVar n [Ty n] deriving (Int -> Ty n -> ShowS
    [Ty n] -> ShowS
    Ty n -> [Char]
    (Int -> Ty n -> ShowS)
    -> (Ty n -> [Char]) -> ([Ty n] -> ShowS) -> Show (Ty n)
    forall n. Show n => Int -> Ty n -> ShowS
    forall n. Show n => [Ty n] -> ShowS
    forall n. Show n => Ty n -> [Char]
    forall a.
    (Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: forall n. Show n => Int -> Ty n -> ShowS
    showsPrec :: Int -> Ty n -> ShowS
    $cshow :: forall n. Show n => Ty n -> [Char]
    show :: Ty n -> [Char]
    $cshowList :: forall n. Show n => [Ty n] -> ShowS
    showList :: [Ty n] -> ShowS
    Show,Ty n -> Ty n -> Bool
    (Ty n -> Ty n -> Bool) -> (Ty n -> Ty n -> Bool) -> Eq (Ty n)
    forall n. Eq n => Ty n -> Ty n -> Bool
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: forall n. Eq n => Ty n -> Ty n -> Bool
    == :: Ty n -> Ty n -> Bool
    $c/= :: forall n. Eq n => Ty n -> Ty n -> Bool
    /= :: Ty n -> Ty n -> Bool
    Eq,Eq (Ty n)
    Eq (Ty n)
    -> (Ty n -> Ty n -> Ordering)
    -> (Ty n -> Ty n -> Bool)
    -> (Ty n -> Ty n -> Bool)
    -> (Ty n -> Ty n -> Bool)
    -> (Ty n -> Ty n -> Bool)
    -> (Ty n -> Ty n -> Ty n)
    -> (Ty n -> Ty n -> Ty n)
    -> Ord (Ty n)
    Ty n -> Ty n -> Bool
    Ty n -> Ty n -> Ordering
    Ty n -> Ty n -> Ty n
    forall a.
    Eq a
    -> (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    forall {n}. Ord n => Eq (Ty n)
    forall n. Ord n => Ty n -> Ty n -> Bool
    forall n. Ord n => Ty n -> Ty n -> Ordering
    forall n. Ord n => Ty n -> Ty n -> Ty n
    $ccompare :: forall n. Ord n => Ty n -> Ty n -> Ordering
    compare :: Ty n -> Ty n -> Ordering
    $c< :: forall n. Ord n => Ty n -> Ty n -> Bool
    < :: Ty n -> Ty n -> Bool
    $c<= :: forall n. Ord n => Ty n -> Ty n -> Bool
    <= :: Ty n -> Ty n -> Bool
    $c> :: forall n. Ord n => Ty n -> Ty n -> Bool
    > :: Ty n -> Ty n -> Bool
    $c>= :: forall n. Ord n => Ty n -> Ty n -> Bool
    >= :: Ty n -> Ty n -> Bool
    $cmax :: forall n. Ord n => Ty n -> Ty n -> Ty n
    max :: Ty n -> Ty n -> Ty n
    $cmin :: forall n. Ord n => Ty n -> Ty n -> Ty n
    min :: Ty n -> Ty n -> Ty n
    Ord,Typeable,Typeable (Ty n)
    Typeable (Ty n)
    -> (forall (c :: * -> *).
        (forall d b. Data d => c (d -> b) -> d -> c b)
        -> (forall g. g -> c g) -> Ty n -> c (Ty n))
    -> (forall (c :: * -> *).
        (forall b r. Data b => c (b -> r) -> c r)
        -> (forall r. r -> c r) -> Constr -> c (Ty n))
    -> (Ty n -> Constr)
    -> (Ty n -> DataType)
    -> (forall (t :: * -> *) (c :: * -> *).
        Typeable t =>
        (forall d. Data d => c (t d)) -> Maybe (c (Ty n)))
    -> (forall (t :: * -> * -> *) (c :: * -> *).
        Typeable t =>
        (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Ty n)))
    -> ((forall b. Data b => b -> b) -> Ty n -> Ty n)
    -> (forall r r'.
        (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Ty n -> r)
    -> (forall r r'.
        (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Ty n -> r)
    -> (forall u. (forall d. Data d => d -> u) -> Ty n -> [u])
    -> (forall u. Int -> (forall d. Data d => d -> u) -> Ty n -> u)
    -> (forall (m :: * -> *).
        Monad m =>
        (forall d. Data d => d -> m d) -> Ty n -> m (Ty n))
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> Ty n -> m (Ty n))
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> Ty n -> m (Ty n))
    -> Data (Ty n)
    Ty n -> Constr
    Ty n -> DataType
    (forall b. Data b => b -> b) -> Ty n -> Ty n
    forall {n}. Data n => Typeable (Ty n)
    forall n. Data n => Ty n -> Constr
    forall n. Data n => Ty n -> DataType
    forall n. Data n => (forall b. Data b => b -> b) -> Ty n -> Ty n
    forall n u.
    Data n =>
    Int -> (forall d. Data d => d -> u) -> Ty n -> u
    forall n u. Data n => (forall d. Data d => d -> u) -> Ty n -> [u]
    forall n r r'.
    Data n =>
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Ty n -> r
    forall n r r'.
    Data n =>
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Ty n -> r
    forall n (m :: * -> *).
    (Data n, Monad m) =>
    (forall d. Data d => d -> m d) -> Ty n -> m (Ty n)
    forall n (m :: * -> *).
    (Data n, MonadPlus m) =>
    (forall d. Data d => d -> m d) -> Ty n -> m (Ty n)
    forall n (c :: * -> *).
    Data n =>
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (Ty n)
    forall n (c :: * -> *).
    Data n =>
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Ty n -> c (Ty n)
    forall n (t :: * -> *) (c :: * -> *).
    (Data n, Typeable t) =>
    (forall d. Data d => c (t d)) -> Maybe (c (Ty n))
    forall n (t :: * -> * -> *) (c :: * -> *).
    (Data n, Typeable t) =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Ty n))
    forall a.
    Typeable a
    -> (forall (c :: * -> *).
        (forall d b. Data d => c (d -> b) -> d -> c b)
        -> (forall g. g -> c g) -> a -> c a)
    -> (forall (c :: * -> *).
        (forall b r. Data b => c (b -> r) -> c r)
        -> (forall r. r -> c r) -> Constr -> c a)
    -> (a -> Constr)
    -> (a -> DataType)
    -> (forall (t :: * -> *) (c :: * -> *).
        Typeable t =>
        (forall d. Data d => c (t d)) -> Maybe (c a))
    -> (forall (t :: * -> * -> *) (c :: * -> *).
        Typeable t =>
        (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
    -> ((forall b. Data b => b -> b) -> a -> a)
    -> (forall r r'.
        (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
    -> (forall r r'.
        (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
    -> (forall u. (forall d. Data d => d -> u) -> a -> [u])
    -> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
    -> (forall (m :: * -> *).
        Monad m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> Data a
    forall u. Int -> (forall d. Data d => d -> u) -> Ty n -> u
    forall u. (forall d. Data d => d -> u) -> Ty n -> [u]
    forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Ty n -> r
    forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Ty n -> r
    forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Ty n -> m (Ty n)
    forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Ty n -> m (Ty n)
    forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (Ty n)
    forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Ty n -> c (Ty n)
    forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (Ty n))
    forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Ty n))
    $cgfoldl :: forall n (c :: * -> *).
    Data n =>
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Ty n -> c (Ty n)
    gfoldl :: forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Ty n -> c (Ty n)
    $cgunfold :: forall n (c :: * -> *).
    Data n =>
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (Ty n)
    gunfold :: forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (Ty n)
    $ctoConstr :: forall n. Data n => Ty n -> Constr
    toConstr :: Ty n -> Constr
    $cdataTypeOf :: forall n. Data n => Ty n -> DataType
    dataTypeOf :: Ty n -> DataType
    $cdataCast1 :: forall n (t :: * -> *) (c :: * -> *).
    (Data n, Typeable t) =>
    (forall d. Data d => c (t d)) -> Maybe (c (Ty n))
    dataCast1 :: forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (Ty n))
    $cdataCast2 :: forall n (t :: * -> * -> *) (c :: * -> *).
    (Data n, Typeable t) =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Ty n))
    dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Ty n))
    $cgmapT :: forall n. Data n => (forall b. Data b => b -> b) -> Ty n -> Ty n
    gmapT :: (forall b. Data b => b -> b) -> Ty n -> Ty n
    $cgmapQl :: forall n r r'.
    Data n =>
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Ty n -> r
    gmapQl :: forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Ty n -> r
    $cgmapQr :: forall n r r'.
    Data n =>
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Ty n -> r
    gmapQr :: forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Ty n -> r
    $cgmapQ :: forall n u. Data n => (forall d. Data d => d -> u) -> Ty n -> [u]
    gmapQ :: forall u. (forall d. Data d => d -> u) -> Ty n -> [u]
    $cgmapQi :: forall n u.
    Data n =>
    Int -> (forall d. Data d => d -> u) -> Ty n -> u
    gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Ty n -> u
    $cgmapM :: forall n (m :: * -> *).
    (Data n, Monad m) =>
    (forall d. Data d => d -> m d) -> Ty n -> m (Ty n)
    gmapM :: forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Ty n -> m (Ty n)
    $cgmapMp :: forall n (m :: * -> *).
    (Data n, MonadPlus m) =>
    (forall d. Data d => d -> m d) -> Ty n -> m (Ty n)
    gmapMp :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Ty n -> m (Ty n)
    $cgmapMo :: forall n (m :: * -> *).
    (Data n, MonadPlus m) =>
    (forall d. Data d => d -> m d) -> Ty n -> m (Ty n)
    gmapMo :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Ty n -> m (Ty n)
    Data,(forall a b. (a -> b) -> Ty a -> Ty b)
    -> (forall a b. a -> Ty b -> Ty a) -> Functor Ty
    forall a b. a -> Ty b -> Ty a
    forall a b. (a -> b) -> Ty a -> Ty b
    forall (f :: * -> *).
    (forall a b. (a -> b) -> f a -> f b)
    -> (forall a b. a -> f b -> f a) -> Functor f
    $cfmap :: forall a b. (a -> b) -> Ty a -> Ty b
    fmap :: forall a b. (a -> b) -> Ty a -> Ty b
    $c<$ :: forall a b. a -> Ty b -> Ty a
    <$ :: forall a b. a -> Ty b -> Ty a
    Functor) -- type application, vectorised, all symbols may occur at multiple kinds

    instance NFData n => NFData (Sig n) where rnf :: Sig n -> ()
    rnf (Sig [Ctx n]
    x [Ty n]
    y) = [Ctx n] -> ()
    forall a. NFData a => a -> ()
    rnf [Ctx n]
    x () -> () -> ()
    forall a b. a -> b -> b
    `seq` [Ty n] -> ()
    forall a. NFData a => a -> ()
    rnf [Ty n]
    y
    instance NFData n => NFData (Ctx n) where rnf :: Ctx n -> ()
    rnf (Ctx n
    x n
    y) = n -> ()
    forall a. NFData a => a -> ()
    rnf n
    x () -> () -> ()
    forall a b. a -> b -> b
    `seq` n -> ()
    forall a. NFData a => a -> ()
    rnf n
    y
    instance NFData n => NFData (Ty  n) where
        rnf :: Ty n -> ()
    rnf (TCon n
    x [Ty n]
    y) = n -> ()
    forall a. NFData a => a -> ()
    rnf n
    x () -> () -> ()
    forall a b. a -> b -> b
    `seq` [Ty n] -> ()
    forall a. NFData a => a -> ()
    rnf [Ty n]
    y
        rnf (TVar n
    x [Ty n]
    y) = n -> ()
    forall a. NFData a => a -> ()
    rnf n
    x () -> () -> ()
    forall a b. a -> b -> b
    `seq` [Ty n] -> ()
    forall a. NFData a => a -> ()
    rnf [Ty n]
    y

    instance Binary n => Binary (Sig n) where
        put :: Sig n -> Put
    put (Sig [Ctx n]
    a [Ty n]
    b) = [Ctx n] -> Put
    forall t. Binary t => t -> Put
    put [Ctx n]
    a Put -> Put -> Put
    forall a b. PutM a -> PutM b -> PutM b
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> [Ty n] -> Put
    forall t. Binary t => t -> Put
    put [Ty n]
    b
        get :: Get (Sig n)
    get = ([Ctx n] -> [Ty n] -> Sig n)
    -> Get [Ctx n] -> Get [Ty n] -> Get (Sig n)
    forall a b c. (a -> b -> c) -> Get a -> Get b -> Get c
    forall (f :: * -> *) a b c.
    Applicative f =>
    (a -> b -> c) -> f a -> f b -> f c
    liftA2 [Ctx n] -> [Ty n] -> Sig n
    forall n. [Ctx n] -> [Ty n] -> Sig n
    Sig Get [Ctx n]
    forall t. Binary t => Get t
    get Get [Ty n]
    forall t. Binary t => Get t
    get

    instance Binary n => Binary (Ctx n) where
        put :: Ctx n -> Put
    put (Ctx n
    a n
    b) = n -> Put
    forall t. Binary t => t -> Put
    put n
    a Put -> Put -> Put
    forall a b. PutM a -> PutM b -> PutM b
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> n -> Put
    forall t. Binary t => t -> Put
    put n
    b
        get :: Get (Ctx n)
    get = (n -> n -> Ctx n) -> Get n -> Get n -> Get (Ctx n)
    forall a b c. (a -> b -> c) -> Get a -> Get b -> Get c
    forall (f :: * -> *) a b c.
    Applicative f =>
    (a -> b -> c) -> f a -> f b -> f c
    liftA2 n -> n -> Ctx n
    forall n. n -> n -> Ctx n
    Ctx Get n
    forall t. Binary t => Get t
    get Get n
    forall t. Binary t => Get t
    get

    instance Binary n => Binary (Ty n) where
        put :: Ty n -> Put
    put (TCon n
    x [Ty n]
    y) = Word8 -> Put
    forall t. Binary t => t -> Put
    put (Word8
    0 :: Word8) Put -> Put -> Put
    forall a b. PutM a -> PutM b -> PutM b
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> n -> Put
    forall t. Binary t => t -> Put
    put n
    x Put -> Put -> Put
    forall a b. PutM a -> PutM b -> PutM b
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> [Ty n] -> Put
    forall t. Binary t => t -> Put
    put [Ty n]
    y
        put (TVar n
    x [Ty n]
    y) = Word8 -> Put
    forall t. Binary t => t -> Put
    put (Word8
    1 :: Word8) Put -> Put -> Put
    forall a b. PutM a -> PutM b -> PutM b
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> n -> Put
    forall t. Binary t => t -> Put
    put n
    x Put -> Put -> Put
    forall a b. PutM a -> PutM b -> PutM b
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> [Ty n] -> Put
    forall t. Binary t => t -> Put
    put [Ty n]
    y
        get :: Get (Ty n)
    get = do Word8
    i :: Word8 <- Get Word8
    forall t. Binary t => Get t
    get; (n -> [Ty n] -> Ty n) -> Get n -> Get [Ty n] -> Get (Ty n)
    forall a b c. (a -> b -> c) -> Get a -> Get b -> Get c
    forall (f :: * -> *) a b c.
    Applicative f =>
    (a -> b -> c) -> f a -> f b -> f c
    liftA2 (case Word8
    i of Word8
    0 -> n -> [Ty n] -> Ty n
    forall n. n -> [Ty n] -> Ty n
    TCon; Word8
    1 -> n -> [Ty n] -> Ty n
    forall n. n -> [Ty n] -> Ty n
    TVar) Get n
    forall t. Binary t => Get t
    get Get [Ty n]
    forall t. Binary t => Get t
    get

    prettySig :: Sig String -> String
    prettySig :: Sig [Char] -> [Char]
    prettySig Sig{[Ty [Char]]
    [Ctx [Char]]
    sigCtx :: forall n. Sig n -> [Ctx n]
    sigTy :: forall n. Sig n -> [Ty n]
    sigCtx :: [Ctx [Char]]
    sigTy :: [Ty [Char]]
    ..} =
            (if [Char] -> Int
    forall a. [a] -> Int
    forall (t :: * -> *) a. Foldable t => t a -> Int
    length [Char]
    ctx Int -> Int -> Bool
    forall a. Ord a => a -> a -> Bool
    > Int
    1 then [Char]
    "(" [Char] -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ [Char]
    ctx [Char] -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ [Char]
    ") => "
             else if [Char] -> Bool
    forall a. [a] -> Bool
    forall (t :: * -> *) a. Foldable t => t a -> Bool
    null [Char]
    ctx then [Char]
    "" else [Char]
    ctx [Char] -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ [Char]
    " => ") [Char] -> ShowS
    forall a. [a] -> [a] -> [a]
    ++
            [Char] -> [[Char]] -> [Char]
    forall a. [a] -> [[a]] -> [a]
    intercalate [Char]
    " -> " ((Ty [Char] -> [Char]) -> [Ty [Char]] -> [[Char]]
    forall a b. (a -> b) -> [a] -> [b]
    map Ty [Char] -> [Char]
    f [Ty [Char]]
    sigTy)
        where
            ctx :: [Char]
    ctx = [Char] -> [[Char]] -> [Char]
    forall a. [a] -> [[a]] -> [a]
    intercalate [Char]
    ", " [[Char]
    a [Char] -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ [Char]
    " " [Char] -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ [Char]
    b | Ctx [Char]
    a [Char]
    b <- [Ctx [Char]]
    sigCtx]

            f :: Ty [Char] -> [Char]
    f (TVar [Char]
    x [Ty [Char]]
    xs) = Ty [Char] -> [Char]
    f (Ty [Char] -> [Char]) -> Ty [Char] -> [Char]
    forall a b. (a -> b) -> a -> b
    $ [Char] -> [Ty [Char]] -> Ty [Char]
    forall n. n -> [Ty n] -> Ty n
    TCon [Char]
    x [Ty [Char]]
    xs
            f (TCon [Char]
    x []) = [Char]
    x
            f (TCon [Char]
    x [Ty [Char]]
    xs) = [Char]
    "(" [Char] -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ [[Char]] -> [Char]
    unwords ([Char]
    x [Char] -> [[Char]] -> [[Char]]
    forall a. a -> [a] -> [a]
    : (Ty [Char] -> [Char]) -> [Ty [Char]] -> [[Char]]
    forall a b. (a -> b) -> [a] -> [b]
    map Ty [Char] -> [Char]
    f [Ty [Char]]
    xs) [Char] -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ [Char]
    ")"

    ---------------------------------------------------------------------
    -- ITEMS

    data Item
        = IPackage PkgName
        | IModule ModName
        | IName Str
        | ISignature (Sig IString)
        | IAlias Str [IString] (Sig IString)
        | IInstance (Sig IString)
          deriving (Int -> Item -> ShowS
    [Item] -> ShowS
    Item -> [Char]
    (Int -> Item -> ShowS)
    -> (Item -> [Char]) -> ([Item] -> ShowS) -> Show Item
    forall a.
    (Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> Item -> ShowS
    showsPrec :: Int -> Item -> ShowS
    $cshow :: Item -> [Char]
    show :: Item -> [Char]
    $cshowList :: [Item] -> ShowS
    showList :: [Item] -> ShowS
    Show,Item -> Item -> Bool
    (Item -> Item -> Bool) -> (Item -> Item -> Bool) -> Eq Item
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: Item -> Item -> Bool
    == :: Item -> Item -> Bool
    $c/= :: Item -> Item -> Bool
    /= :: Item -> Item -> Bool
    Eq,Eq Item
    Eq Item
    -> (Item -> Item -> Ordering)
    -> (Item -> Item -> Bool)
    -> (Item -> Item -> Bool)
    -> (Item -> Item -> Bool)
    -> (Item -> Item -> Bool)
    -> (Item -> Item -> Item)
    -> (Item -> Item -> Item)
    -> Ord Item
    Item -> Item -> Bool
    Item -> Item -> Ordering
    Item -> Item -> Item
    forall a.
    Eq a
    -> (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    $ccompare :: Item -> Item -> Ordering
    compare :: Item -> Item -> Ordering
    $c< :: Item -> Item -> Bool
    < :: Item -> Item -> Bool
    $c<= :: Item -> Item -> Bool
    <= :: Item -> Item -> Bool
    $c> :: Item -> Item -> Bool
    > :: Item -> Item -> Bool
    $c>= :: Item -> Item -> Bool
    >= :: Item -> Item -> Bool
    $cmax :: Item -> Item -> Item
    max :: Item -> Item -> Item
    $cmin :: Item -> Item -> Item
    min :: Item -> Item -> Item
    Ord,Typeable,Typeable Item
    Typeable Item
    -> (forall (c :: * -> *).
        (forall d b. Data d => c (d -> b) -> d -> c b)
        -> (forall g. g -> c g) -> Item -> c Item)
    -> (forall (c :: * -> *).
        (forall b r. Data b => c (b -> r) -> c r)
        -> (forall r. r -> c r) -> Constr -> c Item)
    -> (Item -> Constr)
    -> (Item -> DataType)
    -> (forall (t :: * -> *) (c :: * -> *).
        Typeable t =>
        (forall d. Data d => c (t d)) -> Maybe (c Item))
    -> (forall (t :: * -> * -> *) (c :: * -> *).
        Typeable t =>
        (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Item))
    -> ((forall b. Data b => b -> b) -> Item -> Item)
    -> (forall r r'.
        (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Item -> r)
    -> (forall r r'.
        (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Item -> r)
    -> (forall u. (forall d. Data d => d -> u) -> Item -> [u])
    -> (forall u. Int -> (forall d. Data d => d -> u) -> Item -> u)
    -> (forall (m :: * -> *).
        Monad m =>
        (forall d. Data d => d -> m d) -> Item -> m Item)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> Item -> m Item)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> Item -> m Item)
    -> Data Item
    Item -> Constr
    Item -> DataType
    (forall b. Data b => b -> b) -> Item -> Item
    forall a.
    Typeable a
    -> (forall (c :: * -> *).
        (forall d b. Data d => c (d -> b) -> d -> c b)
        -> (forall g. g -> c g) -> a -> c a)
    -> (forall (c :: * -> *).
        (forall b r. Data b => c (b -> r) -> c r)
        -> (forall r. r -> c r) -> Constr -> c a)
    -> (a -> Constr)
    -> (a -> DataType)
    -> (forall (t :: * -> *) (c :: * -> *).
        Typeable t =>
        (forall d. Data d => c (t d)) -> Maybe (c a))
    -> (forall (t :: * -> * -> *) (c :: * -> *).
        Typeable t =>
        (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
    -> ((forall b. Data b => b -> b) -> a -> a)
    -> (forall r r'.
        (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
    -> (forall r r'.
        (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
    -> (forall u. (forall d. Data d => d -> u) -> a -> [u])
    -> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
    -> (forall (m :: * -> *).
        Monad m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> Data a
    forall u. Int -> (forall d. Data d => d -> u) -> Item -> u
    forall u. (forall d. Data d => d -> u) -> Item -> [u]
    forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Item -> r
    forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Item -> r
    forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Item -> m Item
    forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Item -> m Item
    forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Item
    forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Item -> c Item
    forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Item)
    forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Item)
    $cgfoldl :: forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Item -> c Item
    gfoldl :: forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Item -> c Item
    $cgunfold :: forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Item
    gunfold :: forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Item
    $ctoConstr :: Item -> Constr
    toConstr :: Item -> Constr
    $cdataTypeOf :: Item -> DataType
    dataTypeOf :: Item -> DataType
    $cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Item)
    dataCast1 :: forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Item)
    $cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Item)
    dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Item)
    $cgmapT :: (forall b. Data b => b -> b) -> Item -> Item
    gmapT :: (forall b. Data b => b -> b) -> Item -> Item
    $cgmapQl :: forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Item -> r
    gmapQl :: forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Item -> r
    $cgmapQr :: forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Item -> r
    gmapQr :: forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Item -> r
    $cgmapQ :: forall u. (forall d. Data d => d -> u) -> Item -> [u]
    gmapQ :: forall u. (forall d. Data d => d -> u) -> Item -> [u]
    $cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Item -> u
    gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Item -> u
    $cgmapM :: forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Item -> m Item
    gmapM :: forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Item -> m Item
    $cgmapMp :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Item -> m Item
    gmapMp :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Item -> m Item
    $cgmapMo :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Item -> m Item
    gmapMo :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Item -> m Item
    Data)

    instance NFData Item where
        rnf :: Item -> ()
    rnf (IPackage PkgName
    x) = PkgName -> ()
    forall a. NFData a => a -> ()
    rnf PkgName
    x
        rnf (IModule PkgName
    x) = PkgName -> ()
    forall a. NFData a => a -> ()
    rnf PkgName
    x
        rnf (IName PkgName
    x) = PkgName
    x PkgName -> () -> ()
    forall a b. a -> b -> b
    `seq` ()
        rnf (ISignature Sig IString
    x) = Sig IString -> ()
    forall a. NFData a => a -> ()
    rnf Sig IString
    x
        rnf (IAlias PkgName
    a [IString]
    b Sig IString
    c) = (PkgName, [IString], Sig IString) -> ()
    forall a. NFData a => a -> ()
    rnf (PkgName
    a,[IString]
    b,Sig IString
    c)
        rnf (IInstance Sig IString
    a) = Sig IString -> ()
    forall a. NFData a => a -> ()
    rnf Sig IString
    a

    itemName :: Item -> Maybe Str
    itemName :: Item -> Maybe PkgName
    itemName (IPackage PkgName
    x) = PkgName -> Maybe PkgName
    forall a. a -> Maybe a
    Just PkgName
    x
    itemName (IModule PkgName
    x) = PkgName -> Maybe PkgName
    forall a. a -> Maybe a
    Just PkgName
    x
    itemName (IName PkgName
    x) = PkgName -> Maybe PkgName
    forall a. a -> Maybe a
    Just PkgName
    x
    itemName (ISignature Sig IString
    _) = Maybe PkgName
    forall a. Maybe a
    Nothing
    itemName (IAlias PkgName
    x [IString]
    _ Sig IString
    _) = PkgName -> Maybe PkgName
    forall a. a -> Maybe a
    Just PkgName
    x
    itemName (IInstance Sig IString
    _) = Maybe PkgName
    forall a. Maybe a
    Nothing

    ---------------------------------------------------------------------
    -- DATABASE

    newtype TargetId = TargetId Word32 deriving (TargetId -> TargetId -> Bool
    (TargetId -> TargetId -> Bool)
    -> (TargetId -> TargetId -> Bool) -> Eq TargetId
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: TargetId -> TargetId -> Bool
    == :: TargetId -> TargetId -> Bool
    $c/= :: TargetId -> TargetId -> Bool
    /= :: TargetId -> TargetId -> Bool
    Eq,Eq TargetId
    Eq TargetId
    -> (TargetId -> TargetId -> Ordering)
    -> (TargetId -> TargetId -> Bool)
    -> (TargetId -> TargetId -> Bool)
    -> (TargetId -> TargetId -> Bool)
    -> (TargetId -> TargetId -> Bool)
    -> (TargetId -> TargetId -> TargetId)
    -> (TargetId -> TargetId -> TargetId)
    -> Ord TargetId
    TargetId -> TargetId -> Bool
    TargetId -> TargetId -> Ordering
    TargetId -> TargetId -> TargetId
    forall a.
    Eq a
    -> (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    $ccompare :: TargetId -> TargetId -> Ordering
    compare :: TargetId -> TargetId -> Ordering
    $c< :: TargetId -> TargetId -> Bool
    < :: TargetId -> TargetId -> Bool
    $c<= :: TargetId -> TargetId -> Bool
    <= :: TargetId -> TargetId -> Bool
    $c> :: TargetId -> TargetId -> Bool
    > :: TargetId -> TargetId -> Bool
    $c>= :: TargetId -> TargetId -> Bool
    >= :: TargetId -> TargetId -> Bool
    $cmax :: TargetId -> TargetId -> TargetId
    max :: TargetId -> TargetId -> TargetId
    $cmin :: TargetId -> TargetId -> TargetId
    min :: TargetId -> TargetId -> TargetId
    Ord,Ptr TargetId -> IO TargetId
    Ptr TargetId -> Int -> IO TargetId
    Ptr TargetId -> Int -> TargetId -> IO ()
    Ptr TargetId -> TargetId -> IO ()
    TargetId -> Int
    (TargetId -> Int)
    -> (TargetId -> Int)
    -> (Ptr TargetId -> Int -> IO TargetId)
    -> (Ptr TargetId -> Int -> TargetId -> IO ())
    -> (forall b. Ptr b -> Int -> IO TargetId)
    -> (forall b. Ptr b -> Int -> TargetId -> IO ())
    -> (Ptr TargetId -> IO TargetId)
    -> (Ptr TargetId -> TargetId -> IO ())
    -> Storable TargetId
    forall b. Ptr b -> Int -> IO TargetId
    forall b. Ptr b -> Int -> TargetId -> IO ()
    forall a.
    (a -> Int)
    -> (a -> Int)
    -> (Ptr a -> Int -> IO a)
    -> (Ptr a -> Int -> a -> IO ())
    -> (forall b. Ptr b -> Int -> IO a)
    -> (forall b. Ptr b -> Int -> a -> IO ())
    -> (Ptr a -> IO a)
    -> (Ptr a -> a -> IO ())
    -> Storable a
    $csizeOf :: TargetId -> Int
    sizeOf :: TargetId -> Int
    $calignment :: TargetId -> Int
    alignment :: TargetId -> Int
    $cpeekElemOff :: Ptr TargetId -> Int -> IO TargetId
    peekElemOff :: Ptr TargetId -> Int -> IO TargetId
    $cpokeElemOff :: Ptr TargetId -> Int -> TargetId -> IO ()
    pokeElemOff :: Ptr TargetId -> Int -> TargetId -> IO ()
    $cpeekByteOff :: forall b. Ptr b -> Int -> IO TargetId
    peekByteOff :: forall b. Ptr b -> Int -> IO TargetId
    $cpokeByteOff :: forall b. Ptr b -> Int -> TargetId -> IO ()
    pokeByteOff :: forall b. Ptr b -> Int -> TargetId -> IO ()
    $cpeek :: Ptr TargetId -> IO TargetId
    peek :: Ptr TargetId -> IO TargetId
    $cpoke :: Ptr TargetId -> TargetId -> IO ()
    poke :: Ptr TargetId -> TargetId -> IO ()
    Storable,TargetId -> ()
    (TargetId -> ()) -> NFData TargetId
    forall a. (a -> ()) -> NFData a
    $crnf :: TargetId -> ()
    rnf :: TargetId -> ()
    NFData,Ord TargetId
    Ord TargetId
    -> ((TargetId, TargetId) -> [TargetId])
    -> ((TargetId, TargetId) -> TargetId -> Int)
    -> ((TargetId, TargetId) -> TargetId -> Int)
    -> ((TargetId, TargetId) -> TargetId -> Bool)
    -> ((TargetId, TargetId) -> Int)
    -> ((TargetId, TargetId) -> Int)
    -> Ix TargetId
    (TargetId, TargetId) -> Int
    (TargetId, TargetId) -> [TargetId]
    (TargetId, TargetId) -> TargetId -> Bool
    (TargetId, TargetId) -> TargetId -> Int
    forall a.
    Ord a
    -> ((a, a) -> [a])
    -> ((a, a) -> a -> Int)
    -> ((a, a) -> a -> Int)
    -> ((a, a) -> a -> Bool)
    -> ((a, a) -> Int)
    -> ((a, a) -> Int)
    -> Ix a
    $crange :: (TargetId, TargetId) -> [TargetId]
    range :: (TargetId, TargetId) -> [TargetId]
    $cindex :: (TargetId, TargetId) -> TargetId -> Int
    index :: (TargetId, TargetId) -> TargetId -> Int
    $cunsafeIndex :: (TargetId, TargetId) -> TargetId -> Int
    unsafeIndex :: (TargetId, TargetId) -> TargetId -> Int
    $cinRange :: (TargetId, TargetId) -> TargetId -> Bool
    inRange :: (TargetId, TargetId) -> TargetId -> Bool
    $crangeSize :: (TargetId, TargetId) -> Int
    rangeSize :: (TargetId, TargetId) -> Int
    $cunsafeRangeSize :: (TargetId, TargetId) -> Int
    unsafeRangeSize :: (TargetId, TargetId) -> Int
    Ix,Typeable)

    instance Show TargetId where
        show :: TargetId -> [Char]
    show (TargetId Word32
    x) = Word32 -> ShowS
    forall a. Integral a => a -> ShowS
    showHex Word32
    x [Char]
    ""

    -- | A location of documentation.
    data Target = Target
        {Target -> [Char]
    targetURL :: URL -- ^ URL where this thing is located
        ,Target -> Maybe ([Char], [Char])
    targetPackage :: Maybe (String, URL) -- ^ Name and URL of the package it is in (Nothing if it is a package)
        ,Target -> Maybe ([Char], [Char])
    targetModule :: Maybe (String, URL) -- ^ Name and URL of the module it is in (Nothing if it is a package or module)
        ,Target -> [Char]
    targetType :: String -- ^ One of package, module or empty string
        ,Target -> [Char]
    targetItem :: String -- ^ HTML span of the item, using @\<s0\>@ for the name and @\<s1\>@ onwards for arguments
        ,Target -> [Char]
    targetDocs :: String -- ^ HTML documentation to show, a sequence of block level elements
        } deriving (Int -> Target -> ShowS
    [Target] -> ShowS
    Target -> [Char]
    (Int -> Target -> ShowS)
    -> (Target -> [Char]) -> ([Target] -> ShowS) -> Show Target
    forall a.
    (Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> Target -> ShowS
    showsPrec :: Int -> Target -> ShowS
    $cshow :: Target -> [Char]
    show :: Target -> [Char]
    $cshowList :: [Target] -> ShowS
    showList :: [Target] -> ShowS
    Show,Target -> Target -> Bool
    (Target -> Target -> Bool)
    -> (Target -> Target -> Bool) -> Eq Target
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: Target -> Target -> Bool
    == :: Target -> Target -> Bool
    $c/= :: Target -> Target -> Bool
    /= :: Target -> Target -> Bool
    Eq,Eq Target
    Eq Target
    -> (Target -> Target -> Ordering)
    -> (Target -> Target -> Bool)
    -> (Target -> Target -> Bool)
    -> (Target -> Target -> Bool)
    -> (Target -> Target -> Bool)
    -> (Target -> Target -> Target)
    -> (Target -> Target -> Target)
    -> Ord Target
    Target -> Target -> Bool
    Target -> Target -> Ordering
    Target -> Target -> Target
    forall a.
    Eq a
    -> (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    $ccompare :: Target -> Target -> Ordering
    compare :: Target -> Target -> Ordering
    $c< :: Target -> Target -> Bool
    < :: Target -> Target -> Bool
    $c<= :: Target -> Target -> Bool
    <= :: Target -> Target -> Bool
    $c> :: Target -> Target -> Bool
    > :: Target -> Target -> Bool
    $c>= :: Target -> Target -> Bool
    >= :: Target -> Target -> Bool
    $cmax :: Target -> Target -> Target
    max :: Target -> Target -> Target
    $cmin :: Target -> Target -> Target
    min :: Target -> Target -> Target
    Ord)

    instance NFData Target where
        rnf :: Target -> ()
    rnf (Target [Char]
    a Maybe ([Char], [Char])
    b Maybe ([Char], [Char])
    c [Char]
    d [Char]
    e [Char]
    f) = [Char] -> ()
    forall a. NFData a => a -> ()
    rnf [Char]
    a () -> () -> ()
    forall a b. a -> b -> b
    `seq` Maybe ([Char], [Char]) -> ()
    forall a. NFData a => a -> ()
    rnf Maybe ([Char], [Char])
    b () -> () -> ()
    forall a b. a -> b -> b
    `seq` Maybe ([Char], [Char]) -> ()
    forall a. NFData a => a -> ()
    rnf Maybe ([Char], [Char])
    c () -> () -> ()
    forall a b. a -> b -> b
    `seq` [Char] -> ()
    forall a. NFData a => a -> ()
    rnf [Char]
    d () -> () -> ()
    forall a b. a -> b -> b
    `seq` [Char] -> ()
    forall a. NFData a => a -> ()
    rnf [Char]
    e () -> () -> ()
    forall a b. a -> b -> b
    `seq` [Char] -> ()
    forall a. NFData a => a -> ()
    rnf [Char]
    f

    instance ToJSON Target where
        toJSON :: Target -> Value
    toJSON (Target [Char]
    a Maybe ([Char], [Char])
    b Maybe ([Char], [Char])
    c [Char]
    d [Char]
    e [Char]
    f) = [Pair] -> Value
    object [
          (Key
    "url", [Char] -> Value
    forall a. ToJSON a => a -> Value
    toJSON [Char]
    a),
          (Key
    "package", Maybe ([Char], [Char]) -> Value
    forall {a} {a}. (ToJSON a, ToJSON a) => Maybe (a, a) -> Value
    maybeNamedURL Maybe ([Char], [Char])
    b),
          (Key
    "module", Maybe ([Char], [Char]) -> Value
    forall {a} {a}. (ToJSON a, ToJSON a) => Maybe (a, a) -> Value
    maybeNamedURL Maybe ([Char], [Char])
    c),
          (Key
    "type", [Char] -> Value
    forall a. ToJSON a => a -> Value
    toJSON [Char]
    d),
          (Key
    "item", [Char] -> Value
    forall a. ToJSON a => a -> Value
    toJSON [Char]
    e),
          (Key
    "docs", [Char] -> Value
    forall a. ToJSON a => a -> Value
    toJSON [Char]
    f)
          ]
          where
            maybeNamedURL :: Maybe (a, a) -> Value
    maybeNamedURL Maybe (a, a)
    m = Value -> ((a, a) -> Value) -> Maybe (a, a) -> Value
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe Value
    emptyObject (a, a) -> Value
    forall {a} {a}. (ToJSON a, ToJSON a) => (a, a) -> Value
    namedURL Maybe (a, a)
    m
            namedURL :: (a, a) -> Value
    namedURL (a
    name, a
    url) = [Pair] -> Value
    object [(Key
    "name", a -> Value
    forall a. ToJSON a => a -> Value
    toJSON a
    name), (Key
    "url", a -> Value
    forall a. ToJSON a => a -> Value
    toJSON a
    url)]

    instance FromJSON Target where
      parseJSON :: Value -> Parser Target
    parseJSON = [Char] -> (Object -> Parser Target) -> Value -> Parser Target
    forall a. [Char] -> (Object -> Parser a) -> Value -> Parser a
    withObject [Char]
    "Target" ((Object -> Parser Target) -> Value -> Parser Target)
    -> (Object -> Parser Target) -> Value -> Parser Target
    forall a b. (a -> b) -> a -> b
    $ \Object
    o ->
        [Char]
    -> Maybe ([Char], [Char])
    -> Maybe ([Char], [Char])
    -> [Char]
    -> [Char]
    -> [Char]
    -> Target
    Target ([Char]
     -> Maybe ([Char], [Char])
     -> Maybe ([Char], [Char])
     -> [Char]
     -> [Char]
     -> [Char]
     -> Target)
    -> Parser [Char]
    -> Parser
         (Maybe ([Char], [Char])
          -> Maybe ([Char], [Char]) -> [Char] -> [Char] -> [Char] -> Target)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Object
    o Object -> Key -> Parser [Char]
    forall a. FromJSON a => Object -> Key -> Parser a
    .: Key
    "url"
               Parser
      (Maybe ([Char], [Char])
       -> Maybe ([Char], [Char]) -> [Char] -> [Char] -> [Char] -> Target)
    -> Parser (Maybe ([Char], [Char]))
    -> Parser
         (Maybe ([Char], [Char]) -> [Char] -> [Char] -> [Char] -> Target)
    forall a b. Parser (a -> b) -> Parser a -> Parser b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> Object
    o Object -> Key -> Parser (Maybe ([Char], [Char]))
    forall {a} {b}.
    (FromJSON a, FromJSON b) =>
    Object -> Key -> Parser (Maybe (a, b))
    `namedUrl` Key
    "package"
               Parser
      (Maybe ([Char], [Char]) -> [Char] -> [Char] -> [Char] -> Target)
    -> Parser (Maybe ([Char], [Char]))
    -> Parser ([Char] -> [Char] -> [Char] -> Target)
    forall a b. Parser (a -> b) -> Parser a -> Parser b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> Object
    o Object -> Key -> Parser (Maybe ([Char], [Char]))
    forall {a} {b}.
    (FromJSON a, FromJSON b) =>
    Object -> Key -> Parser (Maybe (a, b))
    `namedUrl` Key
    "module"
               Parser ([Char] -> [Char] -> [Char] -> Target)
    -> Parser [Char] -> Parser ([Char] -> [Char] -> Target)
    forall a b. Parser (a -> b) -> Parser a -> Parser b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> Object
    o Object -> Key -> Parser [Char]
    forall a. FromJSON a => Object -> Key -> Parser a
    .: Key
    "type"
               Parser ([Char] -> [Char] -> Target)
    -> Parser [Char] -> Parser ([Char] -> Target)
    forall a b. Parser (a -> b) -> Parser a -> Parser b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> Object
    o Object -> Key -> Parser [Char]
    forall a. FromJSON a => Object -> Key -> Parser a
    .: Key
    "item"
               Parser ([Char] -> Target) -> Parser [Char] -> Parser Target
    forall a b. Parser (a -> b) -> Parser a -> Parser b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> Object
    o Object -> Key -> Parser [Char]
    forall a. FromJSON a => Object -> Key -> Parser a
    .: Key
    "docs"
        where namedUrl :: Object -> Key -> Parser (Maybe (a, b))
    namedUrl Object
    o' Key
    n = do
                 Object
    mObj <- Object
    o' Object -> Key -> Parser Object
    forall a. FromJSON a => Object -> Key -> Parser a
    .: Key
    n
                 if Object -> Bool
    forall a. KeyMap a -> Bool
    forall (t :: * -> *) a. Foldable t => t a -> Bool
    null Object
    mObj then Maybe (a, b) -> Parser (Maybe (a, b))
    forall a. a -> Parser a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure Maybe (a, b)
    forall a. Maybe a
    Nothing
                            else do
                               a
    pkName <- Object
    mObj Object -> Key -> Parser a
    forall a. FromJSON a => Object -> Key -> Parser a
    .: Key
    "name"
                               b
    pkUrl  <- Object
    mObj Object -> Key -> Parser b
    forall a. FromJSON a => Object -> Key -> Parser a
    .: Key
    "url"
                               Maybe (a, b) -> Parser (Maybe (a, b))
    forall a. a -> Parser a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure (Maybe (a, b) -> Parser (Maybe (a, b)))
    -> Maybe (a, b) -> Parser (Maybe (a, b))
    forall a b. (a -> b) -> a -> b
    $ (a, b) -> Maybe (a, b)
    forall a. a -> Maybe a
    Just (a
    pkName, b
    pkUrl)

    instance Arbitrary Target where
      arbitrary :: Gen Target
    arbitrary = [Char]
    -> Maybe ([Char], [Char])
    -> Maybe ([Char], [Char])
    -> [Char]
    -> [Char]
    -> [Char]
    -> Target
    Target ([Char]
     -> Maybe ([Char], [Char])
     -> Maybe ([Char], [Char])
     -> [Char]
     -> [Char]
     -> [Char]
     -> Target)
    -> Gen [Char]
    -> Gen
         (Maybe ([Char], [Char])
          -> Maybe ([Char], [Char]) -> [Char] -> [Char] -> [Char] -> Target)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Gen [Char]
    a
                         Gen
      (Maybe ([Char], [Char])
       -> Maybe ([Char], [Char]) -> [Char] -> [Char] -> [Char] -> Target)
    -> Gen (Maybe ([Char], [Char]))
    -> Gen
         (Maybe ([Char], [Char]) -> [Char] -> [Char] -> [Char] -> Target)
    forall a b. Gen (a -> b) -> Gen a -> Gen b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> Gen (Maybe ([Char], [Char]))
    mNurl
                         Gen
      (Maybe ([Char], [Char]) -> [Char] -> [Char] -> [Char] -> Target)
    -> Gen (Maybe ([Char], [Char]))
    -> Gen ([Char] -> [Char] -> [Char] -> Target)
    forall a b. Gen (a -> b) -> Gen a -> Gen b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> Gen (Maybe ([Char], [Char]))
    mNurl
                         Gen ([Char] -> [Char] -> [Char] -> Target)
    -> Gen [Char] -> Gen ([Char] -> [Char] -> Target)
    forall a b. Gen (a -> b) -> Gen a -> Gen b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> Gen [Char]
    a
                         Gen ([Char] -> [Char] -> Target)
    -> Gen [Char] -> Gen ([Char] -> Target)
    forall a b. Gen (a -> b) -> Gen a -> Gen b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> Gen [Char]
    a
                         Gen ([Char] -> Target) -> Gen [Char] -> Gen Target
    forall a b. Gen (a -> b) -> Gen a -> Gen b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> Gen [Char]
    a
        where a :: Gen [Char]
    a = Gen [Char]
    forall a. Arbitrary a => Gen a
    arbitrary
              mNurl :: Gen (Maybe ([Char], [Char]))
    mNurl = do
                [Gen (Maybe ([Char], [Char]))] -> Gen (Maybe ([Char], [Char]))
    forall a. [Gen a] -> Gen a
    oneof [Maybe ([Char], [Char]) -> Gen (Maybe ([Char], [Char]))
    forall a. a -> Gen a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure Maybe ([Char], [Char])
    forall a. Maybe a
    Nothing
                     , ([Char], [Char]) -> Maybe ([Char], [Char])
    forall a. a -> Maybe a
    Just (([Char], [Char]) -> Maybe ([Char], [Char]))
    -> Gen ([Char], [Char]) -> Gen (Maybe ([Char], [Char]))
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ([Char] -> [Char] -> ([Char], [Char]))
    -> Gen [Char] -> Gen [Char] -> Gen ([Char], [Char])
    forall a b c. (a -> b -> c) -> Gen a -> Gen b -> Gen c
    forall (f :: * -> *) a b c.
    Applicative f =>
    (a -> b -> c) -> f a -> f b -> f c
    liftA2 (,) Gen [Char]
    a Gen [Char]
    a]

    targetExpandURL :: Target -> Target
    targetExpandURL :: Target -> Target
    targetExpandURL t :: Target
    t@Target{[Char]
    Maybe ([Char], [Char])
    targetURL :: Target -> [Char]
    targetPackage :: Target -> Maybe ([Char], [Char])
    targetModule :: Target -> Maybe ([Char], [Char])
    targetType :: Target -> [Char]
    targetItem :: Target -> [Char]
    targetDocs :: Target -> [Char]
    targetURL :: [Char]
    targetPackage :: Maybe ([Char], [Char])
    targetModule :: Maybe ([Char], [Char])
    targetType :: [Char]
    targetItem :: [Char]
    targetDocs :: [Char]
    ..} = Target
    t{targetURL :: [Char]
    targetURL = [Char]
    url, targetModule :: Maybe ([Char], [Char])
    targetModule = ShowS -> ([Char], [Char]) -> ([Char], [Char])
    forall b b' a. (b -> b') -> (a, b) -> (a, b')
    second ([Char] -> ShowS
    forall a b. a -> b -> a
    const [Char]
    mod) (([Char], [Char]) -> ([Char], [Char]))
    -> Maybe ([Char], [Char]) -> Maybe ([Char], [Char])
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Maybe ([Char], [Char])
    targetModule}
        where
            pkg :: [Char]
    pkg = [Char]
    -> (([Char], [Char]) -> [Char]) -> Maybe ([Char], [Char]) -> [Char]
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe [Char]
    "" ([Char], [Char]) -> [Char]
    forall a b. (a, b) -> b
    snd Maybe ([Char], [Char])
    targetPackage
            mod :: [Char]
    mod = [Char]
    -> (([Char], [Char]) -> [Char]) -> Maybe ([Char], [Char]) -> [Char]
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe [Char]
    pkg ([Char] -> ShowS
    plus [Char]
    pkg ShowS -> (([Char], [Char]) -> [Char]) -> ([Char], [Char]) -> [Char]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ([Char], [Char]) -> [Char]
    forall a b. (a, b) -> b
    snd) Maybe ([Char], [Char])
    targetModule
            url :: [Char]
    url = [Char] -> ShowS
    plus [Char]
    mod [Char]
    targetURL

            plus :: [Char] -> ShowS
    plus [Char]
    a [Char]
    b | [Char]
    b [Char] -> [Char] -> Bool
    forall a. Eq a => a -> a -> Bool
    == [Char]
    "" = [Char]
    ""
                     | Char
    ':':[Char]
    _ <- (Char -> Bool) -> ShowS
    forall a. (a -> Bool) -> [a] -> [a]
    dropWhile Char -> Bool
    isAsciiLower [Char]
    b = [Char]
    b -- match http: etc
                     | Bool
    otherwise = [Char]
    a [Char] -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ [Char]
    b

    unHTMLTarget :: Target -> Target
    unHTMLTarget :: Target -> Target
    unHTMLTarget t :: Target
    t@Target {[Char]
    Maybe ([Char], [Char])
    targetURL :: Target -> [Char]
    targetPackage :: Target -> Maybe ([Char], [Char])
    targetModule :: Target -> Maybe ([Char], [Char])
    targetType :: Target -> [Char]
    targetItem :: Target -> [Char]
    targetDocs :: Target -> [Char]
    targetURL :: [Char]
    targetPackage :: Maybe ([Char], [Char])
    targetModule :: Maybe ([Char], [Char])
    targetType :: [Char]
    targetItem :: [Char]
    targetDocs :: [Char]
    ..} = Target
    t{targetItem :: [Char]
    targetItem=ShowS
    unHTML [Char]
    targetItem, targetDocs :: [Char]
    targetDocs=ShowS
    unHTML [Char]
    targetDocs}

    splitIPackage, splitIModule :: [(a, Item)] -> [(Str, [(a, Item)])]
    splitIPackage :: forall a. [(a, Item)] -> [(PkgName, [(a, Item)])]
    splitIPackage = ((a, Item) -> Maybe PkgName)
    -> [(a, Item)] -> [(PkgName, [(a, Item)])]
    forall a. (a -> Maybe PkgName) -> [a] -> [(PkgName, [a])]
    splitUsing (((a, Item) -> Maybe PkgName)
     -> [(a, Item)] -> [(PkgName, [(a, Item)])])
    -> ((a, Item) -> Maybe PkgName)
    -> [(a, Item)]
    -> [(PkgName, [(a, Item)])]
    forall a b. (a -> b) -> a -> b
    $ \(a, Item)
    x -> case (a, Item) -> Item
    forall a b. (a, b) -> b
    snd (a, Item)
    x of IPackage PkgName
    x -> PkgName -> Maybe PkgName
    forall a. a -> Maybe a
    Just PkgName
    x; Item
    _ -> Maybe PkgName
    forall a. Maybe a
    Nothing
    splitIModule :: forall a. [(a, Item)] -> [(PkgName, [(a, Item)])]
    splitIModule = ((a, Item) -> Maybe PkgName)
    -> [(a, Item)] -> [(PkgName, [(a, Item)])]
    forall a. (a -> Maybe PkgName) -> [a] -> [(PkgName, [a])]
    splitUsing (((a, Item) -> Maybe PkgName)
     -> [(a, Item)] -> [(PkgName, [(a, Item)])])
    -> ((a, Item) -> Maybe PkgName)
    -> [(a, Item)]
    -> [(PkgName, [(a, Item)])]
    forall a b. (a -> b) -> a -> b
    $ \(a, Item)
    x -> case (a, Item) -> Item
    forall a b. (a, b) -> b
    snd (a, Item)
    x of IModule PkgName
    x -> PkgName -> Maybe PkgName
    forall a. a -> Maybe a
    Just PkgName
    x; Item
    _ -> Maybe PkgName
    forall a. Maybe a
    Nothing

    splitUsing :: (a -> Maybe Str) -> [a] -> [(Str, [a])]
    splitUsing :: forall a. (a -> Maybe PkgName) -> [a] -> [(PkgName, [a])]
    splitUsing a -> Maybe PkgName
    f = ([a] -> ((PkgName, [a]), [a])) -> [a] -> [(PkgName, [a])]
    forall a b. ([a] -> (b, [a])) -> [a] -> [b]
    repeatedly (([a] -> ((PkgName, [a]), [a])) -> [a] -> [(PkgName, [a])])
    -> ([a] -> ((PkgName, [a]), [a])) -> [a] -> [(PkgName, [a])]
    forall a b. (a -> b) -> a -> b
    $ \(a
    x:[a]
    xs) ->
        let ([a]
    a,[a]
    b) = (a -> Bool) -> [a] -> ([a], [a])
    forall a. (a -> Bool) -> [a] -> ([a], [a])
    break (Maybe PkgName -> Bool
    forall a. Maybe a -> Bool
    isJust (Maybe PkgName -> Bool) -> (a -> Maybe PkgName) -> a -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . a -> Maybe PkgName
    f) [a]
    xs
        in ((PkgName -> Maybe PkgName -> PkgName
    forall a. a -> Maybe a -> a
    fromMaybe PkgName
    forall a. Monoid a => a
    mempty (Maybe PkgName -> PkgName) -> Maybe PkgName -> PkgName
    forall a b. (a -> b) -> a -> b
    $ a -> Maybe PkgName
    f a
    x, a
    xa -> [a] -> [a]
    forall a. a -> [a] -> [a]
    :[a]
    a), [a]
    b)

    item_test :: IO ()
    item_test :: IO ()
    item_test = [Char] -> IO () -> IO ()
    testing [Char]
    "Input.Item.Target JSON (encode . decode = id) " (IO () -> IO ()) -> IO () -> IO ()
    forall a b. (a -> b) -> a -> b
    $ do
      (Target -> Bool) -> IO ()
    forall prop. Testable prop => prop -> IO ()
    quickCheck ((Target -> Bool) -> IO ()) -> (Target -> Bool) -> IO ()
    forall a b. (a -> b) -> a -> b
    $ \(Target
    t :: Target) -> case ByteString -> Either [Char] Target
    forall a. FromJSON a => ByteString -> Either [Char] a
    J.eitherDecode (ByteString -> Either [Char] Target)
    -> ByteString -> Either [Char] Target
    forall a b. (a -> b) -> a -> b
    $ Target -> ByteString
    forall a. ToJSON a => a -> ByteString
    J.encode Target
    t of
        (Left  [Char]
    e ) -> Bool
    False
        (Right Target
    t') -> Target
    t Target -> Target -> Bool
    forall a. Eq a => a -> a -> Bool
    == Target
    t'

    ---------------------------------------------------------------------
    -- HSE CONVERSION

    hseToSig :: Type a -> Sig String
    hseToSig :: forall a. Type a -> Sig [Char]
    hseToSig = Type a -> Sig [Char]
    forall a. Type a -> Sig [Char]
    tyForall
        where
            -- forall at the top is different
            tyForall :: Type a -> Sig [Char]
    tyForall (TyParen a
    _ Type a
    x) = Type a -> Sig [Char]
    tyForall Type a
    x
            tyForall (TyForall a
    _ Maybe [TyVarBind a]
    _ Maybe (Context a)
    c Type a
    t) | Sig [Ctx [Char]]
    cs [Ty [Char]]
    ts <- Type a -> Sig [Char]
    tyForall Type a
    t =
                [Ctx [Char]] -> [Ty [Char]] -> Sig [Char]
    forall n. [Ctx n] -> [Ty n] -> Sig n
    Sig ([Ctx [Char]]
    -> (Context a -> [Ctx [Char]]) -> Maybe (Context a) -> [Ctx [Char]]
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe [] ((Asst a -> [Ctx [Char]]) -> [Asst a] -> [Ctx [Char]]
    forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
    concatMap Asst a -> [Ctx [Char]]
    forall {a}. Asst a -> [Ctx [Char]]
    ctx ([Asst a] -> [Ctx [Char]])
    -> (Context a -> [Asst a]) -> Context a -> [Ctx [Char]]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Context a -> [Asst a]
    forall a. Context a -> [Asst a]
    fromContext) Maybe (Context a)
    c [Ctx [Char]] -> [Ctx [Char]] -> [Ctx [Char]]
    forall a. [a] -> [a] -> [a]
    ++ [Ctx [Char]]
    cs) [Ty [Char]]
    ts
            tyForall Type a
    x = [Ctx [Char]] -> [Ty [Char]] -> Sig [Char]
    forall n. [Ctx n] -> [Ty n] -> Sig n
    Sig [] ([Ty [Char]] -> Sig [Char]) -> [Ty [Char]] -> Sig [Char]
    forall a b. (a -> b) -> a -> b
    $ Type a -> [Ty [Char]]
    forall {a}. Type a -> [Ty [Char]]
    tyFun Type a
    x

            tyFun :: Type a -> [Ty [Char]]
    tyFun (TyParen a
    _ Type a
    x) = Type a -> [Ty [Char]]
    tyFun Type a
    x
            tyFun (TyFun a
    _ Type a
    a Type a
    b) = Type a -> Ty [Char]
    ty Type a
    a Ty [Char] -> [Ty [Char]] -> [Ty [Char]]
    forall a. a -> [a] -> [a]
    : Type a -> [Ty [Char]]
    tyFun Type a
    b
            tyFun Type a
    x = [Type a -> Ty [Char]
    ty Type a
    x]

            ty :: Type a -> Ty [Char]
    ty (TyForall a
    _ Maybe [TyVarBind a]
    _ Maybe (Context a)
    _ Type a
    x) = [Char] -> [Ty [Char]] -> Ty [Char]
    forall n. n -> [Ty n] -> Ty n
    TCon [Char]
    "\\/" [Type a -> Ty [Char]
    ty Type a
    x]
            ty x :: Type a
    x@TyFun{} = [Char] -> [Ty [Char]] -> Ty [Char]
    forall n. n -> [Ty n] -> Ty n
    TCon [Char]
    "->" ([Ty [Char]] -> Ty [Char]) -> [Ty [Char]] -> Ty [Char]
    forall a b. (a -> b) -> a -> b
    $ Type a -> [Ty [Char]]
    tyFun Type a
    x
            ty (TyTuple a
    an Boxed
    box [Type a]
    ts) = [Char] -> [Ty [Char]] -> Ty [Char]
    forall n. n -> [Ty n] -> Ty n
    TCon (QName a -> [Char]
    forall a. QName a -> [Char]
    fromQName (QName a -> [Char]) -> QName a -> [Char]
    forall a b. (a -> b) -> a -> b
    $ a -> SpecialCon a -> QName a
    forall l. l -> SpecialCon l -> QName l
    Special a
    an (SpecialCon a -> QName a) -> SpecialCon a -> QName a
    forall a b. (a -> b) -> a -> b
    $ a -> Boxed -> Int -> SpecialCon a
    forall l. l -> Boxed -> Int -> SpecialCon l
    TupleCon a
    an Boxed
    box (Int -> SpecialCon a) -> Int -> SpecialCon a
    forall a b. (a -> b) -> a -> b
    $ [Type a] -> Int
    forall a. [a] -> Int
    forall (t :: * -> *) a. Foldable t => t a -> Int
    length [Type a]
    ts Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - Int
    1) ((Type a -> Ty [Char]) -> [Type a] -> [Ty [Char]]
    forall a b. (a -> b) -> [a] -> [b]
    map Type a -> Ty [Char]
    ty [Type a]
    ts)
            ty (TyList a
    _ Type a
    x) = [Char] -> [Ty [Char]] -> Ty [Char]
    forall n. n -> [Ty n] -> Ty n
    TCon [Char]
    "[]" [Type a -> Ty [Char]
    ty Type a
    x]
            ty (TyParArray a
    _ Type a
    x) = [Char] -> [Ty [Char]] -> Ty [Char]
    forall n. n -> [Ty n] -> Ty n
    TCon [Char]
    "[::]" [Type a -> Ty [Char]
    ty Type a
    x]
            ty (TyApp a
    _ Type a
    x Type a
    y) = case Type a -> Ty [Char]
    ty Type a
    x of
                TCon [Char]
    a [Ty [Char]]
    b -> [Char] -> [Ty [Char]] -> Ty [Char]
    forall n. n -> [Ty n] -> Ty n
    TCon [Char]
    a ([Ty [Char]]
    b [Ty [Char]] -> [Ty [Char]] -> [Ty [Char]]
    forall a. [a] -> [a] -> [a]
    ++ [Type a -> Ty [Char]
    ty Type a
    y])
                TVar [Char]
    a [Ty [Char]]
    b -> [Char] -> [Ty [Char]] -> Ty [Char]
    forall n. n -> [Ty n] -> Ty n
    TVar [Char]
    a ([Ty [Char]]
    b [Ty [Char]] -> [Ty [Char]] -> [Ty [Char]]
    forall a. [a] -> [a] -> [a]
    ++ [Type a -> Ty [Char]
    ty Type a
    y])
            ty (TyVar a
    _ Name a
    x) = [Char] -> [Ty [Char]] -> Ty [Char]
    forall n. n -> [Ty n] -> Ty n
    TVar (Name a -> [Char]
    forall a. Name a -> [Char]
    fromName Name a
    x) []
            ty (TyCon a
    _ QName a
    x) = [Char] -> [Ty [Char]] -> Ty [Char]
    forall n. n -> [Ty n] -> Ty n
    TCon (QName a -> [Char]
    forall a. QName a -> [Char]
    fromQName QName a
    x) []
            ty (TyInfix a
    an Type a
    a (UnpromotedName a
    _ QName a
    b) Type a
    c) = Type a -> Ty [Char]
    ty (Type a -> Ty [Char]) -> Type a -> Ty [Char]
    forall a b. (a -> b) -> a -> b
    $ let ap :: Type a -> Type a -> Type a
    ap = a -> Type a -> Type a -> Type a
    forall l. l -> Type l -> Type l -> Type l
    TyApp a
    an in a -> QName a -> Type a
    forall l. l -> QName l -> Type l
    TyCon a
    an QName a
    b Type a -> Type a -> Type a
    `ap` Type a
    a Type a -> Type a -> Type a
    `ap` Type a
    c
            ty (TyKind a
    _ Type a
    x Type a
    _) = Type a -> Ty [Char]
    ty Type a
    x
            ty (TyBang a
    _ BangType a
    _ Unpackedness a
    _ Type a
    x) = Type a -> Ty [Char]
    ty Type a
    x
            ty (TyParen a
    _ Type a
    x) = Type a -> Ty [Char]
    ty Type a
    x
            ty Type a
    _ = [Char] -> [Ty [Char]] -> Ty [Char]
    forall n. n -> [Ty n] -> Ty n
    TVar [Char]
    "_" []

            ctx :: Asst a -> [Ctx [Char]]
    ctx (ParenA a
    _ Asst a
    x) = Asst a -> [Ctx [Char]]
    ctx Asst a
    x
            ctx (TypeA a
    _ Type a
    x)  = Type a -> [Ctx [Char]]
    forall {a}. Type a -> [Ctx [Char]]
    ctxTy Type a
    x
            ctx Asst a
    _ = []

            ctxTy :: Type a -> [Ctx [Char]]
    ctxTy (TyInfix a
    an Type a
    a (UnpromotedName a
    _ QName a
    con) Type a
    b) = Type a -> [Ctx [Char]]
    ctxTy (Type a -> [Ctx [Char]]) -> Type a -> [Ctx [Char]]
    forall a b. (a -> b) -> a -> b
    $ a -> Type a -> Type a -> Type a
    forall l. l -> Type l -> Type l -> Type l
    TyApp a
    an (a -> Type a -> Type a -> Type a
    forall l. l -> Type l -> Type l -> Type l
    TyApp a
    an (a -> QName a -> Type a
    forall l. l -> QName l -> Type l
    TyCon a
    an QName a
    con) Type a
    a) Type a
    b
            ctxTy (Type a -> [Type a]
    forall {l}. Type l -> [Type l]
    fromTyApps -> TyCon a
    _ QName a
    con:TyVar a
    _ Name a
    var:[Type a]
    _) = [[Char] -> [Char] -> Ctx [Char]
    forall n. n -> n -> Ctx n
    Ctx (QName a -> [Char]
    forall a. QName a -> [Char]
    fromQName QName a
    con) (Name a -> [Char]
    forall a. Name a -> [Char]
    fromName Name a
    var)]
            ctxTy Type a
    _ = []

            fromTyApps :: Type l -> [Type l]
    fromTyApps (TyApp l
    _ Type l
    x Type l
    y) = Type l -> [Type l]
    fromTyApps Type l
    x [Type l] -> [Type l] -> [Type l]
    forall a. [a] -> [a] -> [a]
    ++ [Type l
    y]
            fromTyApps Type l
    x = [Type l
    x]

    hseToItem :: Decl a -> [Item]
    hseToItem :: forall a. Decl a -> [Item]
    hseToItem (TypeSig a
    _ [Name a]
    names Type a
    ty) = Sig IString -> Item
    ISignature (PkgName -> IString
    toIString (PkgName -> IString) -> ([Char] -> PkgName) -> [Char] -> IString
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Char] -> PkgName
    strPack ([Char] -> IString) -> Sig [Char] -> Sig IString
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Type a -> Sig [Char]
    forall a. Type a -> Sig [Char]
    hseToSig Type a
    ty) Item -> [Item] -> [Item]
    forall a. a -> [a] -> [a]
    : (Name a -> Item) -> [Name a] -> [Item]
    forall a b. (a -> b) -> [a] -> [b]
    map (PkgName -> Item
    IName (PkgName -> Item) -> (Name a -> PkgName) -> Name a -> Item
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Char] -> PkgName
    strPack ([Char] -> PkgName) -> (Name a -> [Char]) -> Name a -> PkgName
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Name a -> [Char]
    forall a. Name a -> [Char]
    fromName) [Name a]
    names
    hseToItem (TypeDecl a
    _ (DeclHead a -> (Name a, [TyVarBind a])
    forall a. DeclHead a -> (Name a, [TyVarBind a])
    fromDeclHead -> (Name a
    name, [TyVarBind a]
    bind)) Type a
    rhs) = [PkgName -> [IString] -> Sig IString -> Item
    IAlias ([Char] -> PkgName
    strPack ([Char] -> PkgName) -> [Char] -> PkgName
    forall a b. (a -> b) -> a -> b
    $ Name a -> [Char]
    forall a. Name a -> [Char]
    fromName Name a
    name) ((TyVarBind a -> IString) -> [TyVarBind a] -> [IString]
    forall a b. (a -> b) -> [a] -> [b]
    map (PkgName -> IString
    toIString (PkgName -> IString)
    -> (TyVarBind a -> PkgName) -> TyVarBind a -> IString
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Char] -> PkgName
    strPack ([Char] -> PkgName)
    -> (TyVarBind a -> [Char]) -> TyVarBind a -> PkgName
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Name a -> [Char]
    forall a. Name a -> [Char]
    fromName (Name a -> [Char])
    -> (TyVarBind a -> Name a) -> TyVarBind a -> [Char]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . TyVarBind a -> Name a
    forall a. TyVarBind a -> Name a
    fromTyVarBind) [TyVarBind a]
    bind) (PkgName -> IString
    toIString (PkgName -> IString) -> ([Char] -> PkgName) -> [Char] -> IString
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Char] -> PkgName
    strPack ([Char] -> IString) -> Sig [Char] -> Sig IString
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Type a -> Sig [Char]
    forall a. Type a -> Sig [Char]
    hseToSig Type a
    rhs)]
    hseToItem (InstDecl a
    an Maybe (Overlap a)
    _ (InstRule a -> InstRule a
    forall a. InstRule a -> InstRule a
    fromIParen -> IRule a
    _ Maybe [TyVarBind a]
    _ Maybe (Context a)
    ctx (InstHead a -> (QName a, [Type a])
    forall a. InstHead a -> (QName a, [Type a])
    fromInstHead -> (QName a
    name, [Type a]
    args))) Maybe [InstDecl a]
    _) = [Sig IString -> Item
    IInstance (Sig IString -> Item) -> Sig IString -> Item
    forall a b. (a -> b) -> a -> b
    $ ([Char] -> IString) -> Sig [Char] -> Sig IString
    forall a b. (a -> b) -> Sig a -> Sig b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap (PkgName -> IString
    toIString (PkgName -> IString) -> ([Char] -> PkgName) -> [Char] -> IString
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Char] -> PkgName
    strPack) (Sig [Char] -> Sig IString) -> Sig [Char] -> Sig IString
    forall a b. (a -> b) -> a -> b
    $ Type a -> Sig [Char]
    forall a. Type a -> Sig [Char]
    hseToSig (Type a -> Sig [Char]) -> Type a -> Sig [Char]
    forall a b. (a -> b) -> a -> b
    $ a -> Maybe [TyVarBind a] -> Maybe (Context a) -> Type a -> Type a
    forall l.
    l -> Maybe [TyVarBind l] -> Maybe (Context l) -> Type l -> Type l
    TyForall a
    an Maybe [TyVarBind a]
    forall a. Maybe a
    Nothing Maybe (Context a)
    ctx (Type a -> Type a) -> Type a -> Type a
    forall a b. (a -> b) -> a -> b
    $ Type a -> [Type a] -> Type a
    forall a. Type a -> [Type a] -> Type a
    applyType (a -> QName a -> Type a
    forall l. l -> QName l -> Type l
    TyCon a
    an QName a
    name) [Type a]
    args]
    hseToItem Decl a
    x = ([Char] -> Item) -> [[Char]] -> [Item]
    forall a b. (a -> b) -> [a] -> [b]
    map (PkgName -> Item
    IName (PkgName -> Item) -> ([Char] -> PkgName) -> [Char] -> Item
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Char] -> PkgName
    strPack) ([[Char]] -> [Item]) -> [[Char]] -> [Item]
    forall a b. (a -> b) -> a -> b
    $ Decl a -> [[Char]]
    forall a. Decl a -> [[Char]]
    declNames Decl a
    x