{-# 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 qualified Data.Text as T
import Test.QuickCheck
---------------------------------------------------------------------
-- TYPES

data Sig n = Sig {Sig n -> [Ctx n]
sigCtx :: [Ctx n], Sig n -> [Ty n]
sigTy :: [Ty n]} deriving (Int -> Sig n -> ShowS
[Sig n] -> ShowS
Sig n -> String
(Int -> Sig n -> ShowS)
-> (Sig n -> String) -> ([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 -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Sig n] -> ShowS
$cshowList :: forall n. Show n => [Sig n] -> ShowS
show :: Sig n -> String
$cshow :: forall n. Show n => Sig n -> String
showsPrec :: Int -> Sig n -> ShowS
$cshowsPrec :: forall n. Show n => Int -> 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
/= :: Sig n -> Sig n -> Bool
$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
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
min :: Sig n -> Sig n -> Sig n
$cmin :: forall n. Ord n => Sig n -> Sig n -> Sig n
max :: Sig n -> Sig n -> Sig n
$cmax :: forall n. Ord n => Sig n -> Sig n -> Sig n
>= :: 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
$c< :: forall n. Ord n => Sig n -> Sig n -> Bool
compare :: Sig n -> Sig n -> Ordering
$ccompare :: forall n. Ord n => Sig n -> Sig n -> Ordering
$cp1Ord :: forall n. Ord n => Eq (Sig n)
Ord,Typeable,Typeable (Sig n)
Constr
DataType
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 d. Data d => c (t d)) -> Maybe (c (Sig n))
(forall b. Data b => b -> b) -> Sig n -> Sig n
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Sig n -> c (Sig n)
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (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))
$cSig :: Constr
$tSig :: DataType
gmapMo :: (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)
gmapMp :: (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)
gmapM :: (forall d. Data d => d -> m d) -> Sig n -> m (Sig n)
$cgmapM :: forall n (m :: * -> *).
(Data n, Monad m) =>
(forall d. Data d => d -> m d) -> Sig n -> m (Sig n)
gmapQi :: Int -> (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
gmapQ :: (forall d. Data d => d -> u) -> Sig n -> [u]
$cgmapQ :: forall n u. Data n => (forall d. Data d => d -> u) -> Sig n -> [u]
gmapQr :: (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
gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Sig n -> r
$cgmapQl :: forall n r r'.
Data n =>
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Sig n -> r
gmapT :: (forall b. Data b => b -> b) -> Sig n -> Sig n
$cgmapT :: forall n. Data n => (forall b. Data b => b -> b) -> Sig n -> Sig n
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e)) -> 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))
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c (Sig n))
$cdataCast1 :: forall n (t :: * -> *) (c :: * -> *).
(Data n, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (Sig n))
dataTypeOf :: Sig n -> DataType
$cdataTypeOf :: forall n. Data n => Sig n -> DataType
toConstr :: Sig n -> Constr
$ctoConstr :: forall n. Data n => Sig n -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> 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)
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Sig n -> 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)
$cp1Data :: forall n. Data n => Typeable (Sig n)
Data,a -> Sig b -> Sig a
(a -> b) -> Sig a -> Sig b
(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
<$ :: a -> Sig b -> Sig a
$c<$ :: forall a b. a -> Sig b -> Sig a
fmap :: (a -> b) -> Sig a -> Sig b
$cfmap :: forall a b. (a -> b) -> Sig a -> Sig b
Functor) -- list of -> types
data Ctx n = Ctx n n deriving (Int -> Ctx n -> ShowS
[Ctx n] -> ShowS
Ctx n -> String
(Int -> Ctx n -> ShowS)
-> (Ctx n -> String) -> ([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 -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Ctx n] -> ShowS
$cshowList :: forall n. Show n => [Ctx n] -> ShowS
show :: Ctx n -> String
$cshow :: forall n. Show n => Ctx n -> String
showsPrec :: Int -> Ctx n -> ShowS
$cshowsPrec :: forall n. Show n => Int -> 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
/= :: Ctx n -> Ctx n -> Bool
$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
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
min :: Ctx n -> Ctx n -> Ctx n
$cmin :: forall n. Ord n => Ctx n -> Ctx n -> Ctx n
max :: Ctx n -> Ctx n -> Ctx n
$cmax :: forall n. Ord n => Ctx n -> Ctx n -> Ctx n
>= :: 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
$c< :: forall n. Ord n => Ctx n -> Ctx n -> Bool
compare :: Ctx n -> Ctx n -> Ordering
$ccompare :: forall n. Ord n => Ctx n -> Ctx n -> Ordering
$cp1Ord :: forall n. Ord n => Eq (Ctx n)
Ord,Typeable,Typeable (Ctx n)
Constr
DataType
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 d. Data d => c (t d)) -> Maybe (c (Ctx n))
(forall b. Data b => b -> b) -> Ctx n -> Ctx n
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Ctx n -> c (Ctx n)
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (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))
$cCtx :: Constr
$tCtx :: DataType
gmapMo :: (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)
gmapMp :: (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)
gmapM :: (forall d. Data d => d -> m d) -> Ctx n -> m (Ctx n)
$cgmapM :: forall n (m :: * -> *).
(Data n, Monad m) =>
(forall d. Data d => d -> m d) -> Ctx n -> m (Ctx n)
gmapQi :: Int -> (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
gmapQ :: (forall d. Data d => d -> u) -> Ctx n -> [u]
$cgmapQ :: forall n u. Data n => (forall d. Data d => d -> u) -> Ctx n -> [u]
gmapQr :: (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
gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Ctx n -> r
$cgmapQl :: forall n r r'.
Data n =>
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Ctx n -> r
gmapT :: (forall b. Data b => b -> b) -> Ctx n -> Ctx n
$cgmapT :: forall n. Data n => (forall b. Data b => b -> b) -> Ctx n -> Ctx n
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e)) -> 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))
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c (Ctx n))
$cdataCast1 :: forall n (t :: * -> *) (c :: * -> *).
(Data n, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (Ctx n))
dataTypeOf :: Ctx n -> DataType
$cdataTypeOf :: forall n. Data n => Ctx n -> DataType
toConstr :: Ctx n -> Constr
$ctoConstr :: forall n. Data n => Ctx n -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> 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)
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Ctx n -> 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)
$cp1Data :: forall n. Data n => Typeable (Ctx n)
Data,a -> Ctx b -> Ctx a
(a -> b) -> Ctx a -> Ctx b
(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
<$ :: a -> Ctx b -> Ctx a
$c<$ :: forall a b. a -> Ctx b -> Ctx a
fmap :: (a -> b) -> Ctx a -> Ctx b
$cfmap :: forall a b. (a -> b) -> Ctx a -> Ctx b
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 -> String
(Int -> Ty n -> ShowS)
-> (Ty n -> String) -> ([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 -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Ty n] -> ShowS
$cshowList :: forall n. Show n => [Ty n] -> ShowS
show :: Ty n -> String
$cshow :: forall n. Show n => Ty n -> String
showsPrec :: Int -> Ty n -> ShowS
$cshowsPrec :: forall n. Show n => Int -> 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
/= :: Ty n -> Ty n -> Bool
$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
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
min :: Ty n -> Ty n -> Ty n
$cmin :: forall n. Ord n => Ty n -> Ty n -> Ty n
max :: Ty n -> Ty n -> Ty n
$cmax :: forall n. Ord n => Ty n -> Ty n -> Ty n
>= :: 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
$c< :: forall n. Ord n => Ty n -> Ty n -> Bool
compare :: Ty n -> Ty n -> Ordering
$ccompare :: forall n. Ord n => Ty n -> Ty n -> Ordering
$cp1Ord :: forall n. Ord n => Eq (Ty n)
Ord,Typeable,Typeable (Ty n)
Constr
DataType
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 d. Data d => c (t d)) -> Maybe (c (Ty n))
(forall b. Data b => b -> b) -> Ty n -> Ty n
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Ty n -> c (Ty n)
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (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))
$cTVar :: Constr
$cTCon :: Constr
$tTy :: DataType
gmapMo :: (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)
gmapMp :: (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)
gmapM :: (forall d. Data d => d -> m d) -> Ty n -> m (Ty n)
$cgmapM :: forall n (m :: * -> *).
(Data n, Monad m) =>
(forall d. Data d => d -> m d) -> Ty n -> m (Ty n)
gmapQi :: Int -> (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
gmapQ :: (forall d. Data d => d -> u) -> Ty n -> [u]
$cgmapQ :: forall n u. Data n => (forall d. Data d => d -> u) -> Ty n -> [u]
gmapQr :: (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
gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Ty n -> r
$cgmapQl :: forall n r r'.
Data n =>
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Ty n -> r
gmapT :: (forall b. Data b => b -> b) -> Ty n -> Ty n
$cgmapT :: forall n. Data n => (forall b. Data b => b -> b) -> Ty n -> Ty n
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e)) -> 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))
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c (Ty n))
$cdataCast1 :: forall n (t :: * -> *) (c :: * -> *).
(Data n, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (Ty n))
dataTypeOf :: Ty n -> DataType
$cdataTypeOf :: forall n. Data n => Ty n -> DataType
toConstr :: Ty n -> Constr
$ctoConstr :: forall n. Data n => Ty n -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> 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)
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Ty n -> 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)
$cp1Data :: forall n. Data n => Typeable (Ty n)
Data,a -> Ty b -> Ty a
(a -> b) -> Ty a -> Ty b
(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
<$ :: a -> Ty b -> Ty a
$c<$ :: forall a b. a -> Ty b -> Ty a
fmap :: (a -> b) -> Ty a -> Ty b
$cfmap :: forall a b. (a -> b) -> Ty a -> Ty b
Functor) -- type application, vectorised, all symbols may occur at multiple kinds

instance NFData n => NFData (Sig n) where rnf :: Sig n -> ()
rnf (Sig x :: [Ctx n]
x y :: [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 x :: n
x y :: 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 x :: n
x y :: [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 x :: n
x y :: [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 a :: [Ctx n]
a b :: [Ty n]
b) = [Ctx n] -> Put
forall t. Binary t => t -> Put
put [Ctx n]
a Put -> Put -> Put
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 (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 a :: n
a b :: n
b) = n -> Put
forall t. Binary t => t -> Put
put n
a Put -> Put -> Put
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 (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 x :: n
x y :: [Ty n]
y) = Word8 -> Put
forall t. Binary t => t -> Put
put (0 :: Word8) Put -> Put -> Put
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 (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 x :: n
x y :: [Ty n]
y) = Word8 -> Put
forall t. Binary t => t -> Put
put (1 :: Word8) Put -> Put -> Put
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 (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 (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 (case Word8
i of 0 -> n -> [Ty n] -> Ty n
forall n. n -> [Ty n] -> Ty n
TCon; 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 String -> String
prettySig Sig{..} =
        (if String -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length String
ctx Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> 1 then "(" String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
ctx String -> ShowS
forall a. [a] -> [a] -> [a]
++ ") => "
         else if String -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null String
ctx then "" else String
ctx String -> ShowS
forall a. [a] -> [a] -> [a]
++ " => ") String -> ShowS
forall a. [a] -> [a] -> [a]
++
        String -> [String] -> String
forall a. [a] -> [[a]] -> [a]
intercalate " -> " ((Ty String -> String) -> [Ty String] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map Ty String -> String
f [Ty String]
sigTy)
    where
        ctx :: String
ctx = String -> [String] -> String
forall a. [a] -> [[a]] -> [a]
intercalate ", " [String
a String -> ShowS
forall a. [a] -> [a] -> [a]
++ " " String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
b | Ctx a :: String
a b :: String
b <- [Ctx String]
sigCtx]

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


---------------------------------------------------------------------
-- 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 -> String
(Int -> Item -> ShowS)
-> (Item -> String) -> ([Item] -> ShowS) -> Show Item
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Item] -> ShowS
$cshowList :: [Item] -> ShowS
show :: Item -> String
$cshow :: Item -> String
showsPrec :: Int -> Item -> ShowS
$cshowsPrec :: Int -> Item -> ShowS
Show,Item -> Item -> Bool
(Item -> Item -> Bool) -> (Item -> Item -> Bool) -> Eq Item
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Item -> Item -> Bool
$c/= :: Item -> Item -> Bool
== :: Item -> Item -> Bool
$c== :: 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
min :: Item -> Item -> Item
$cmin :: Item -> Item -> Item
max :: Item -> Item -> Item
$cmax :: Item -> Item -> Item
>= :: Item -> Item -> Bool
$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
compare :: Item -> Item -> Ordering
$ccompare :: Item -> Item -> Ordering
$cp1Ord :: Eq Item
Ord,Typeable,Typeable Item
Constr
DataType
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 d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Item -> c Item
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c 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)
$cIInstance :: Constr
$cIAlias :: Constr
$cISignature :: Constr
$cIName :: Constr
$cIModule :: Constr
$cIPackage :: Constr
$tItem :: DataType
gmapMo :: (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
gmapMp :: (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
gmapM :: (forall d. Data d => d -> m d) -> Item -> m Item
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Item -> m Item
gmapQi :: Int -> (forall d. Data d => d -> u) -> Item -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Item -> u
gmapQ :: (forall d. Data d => d -> u) -> Item -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Item -> [u]
gmapQr :: (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
gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Item -> r
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Item -> r
gmapT :: (forall b. Data b => b -> b) -> Item -> Item
$cgmapT :: (forall b. Data b => b -> b) -> Item -> Item
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Item)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Item)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c Item)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Item)
dataTypeOf :: Item -> DataType
$cdataTypeOf :: Item -> DataType
toConstr :: Item -> Constr
$ctoConstr :: Item -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Item
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Item
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Item -> c Item
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Item -> c Item
$cp1Data :: Typeable Item
Data)

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

itemName :: Item -> Maybe Str
itemName :: Item -> Maybe PkgName
itemName (IPackage x :: PkgName
x) = PkgName -> Maybe PkgName
forall a. a -> Maybe a
Just PkgName
x
itemName (IModule x :: PkgName
x) = PkgName -> Maybe PkgName
forall a. a -> Maybe a
Just PkgName
x
itemName (IName x :: PkgName
x) = PkgName -> Maybe PkgName
forall a. a -> Maybe a
Just PkgName
x
itemName (ISignature _) = Maybe PkgName
forall a. Maybe a
Nothing
itemName (IAlias x :: PkgName
x _ _) = PkgName -> Maybe PkgName
forall a. a -> Maybe a
Just PkgName
x
itemName (IInstance _) = 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
/= :: TargetId -> TargetId -> Bool
$c/= :: TargetId -> TargetId -> Bool
== :: TargetId -> TargetId -> Bool
$c== :: 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
min :: TargetId -> TargetId -> TargetId
$cmin :: TargetId -> TargetId -> TargetId
max :: TargetId -> TargetId -> TargetId
$cmax :: TargetId -> TargetId -> TargetId
>= :: TargetId -> TargetId -> Bool
$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
compare :: TargetId -> TargetId -> Ordering
$ccompare :: TargetId -> TargetId -> Ordering
$cp1Ord :: Eq TargetId
Ord,Ptr b -> Int -> IO TargetId
Ptr b -> Int -> TargetId -> IO ()
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
poke :: Ptr TargetId -> TargetId -> IO ()
$cpoke :: Ptr TargetId -> TargetId -> IO ()
peek :: Ptr TargetId -> IO TargetId
$cpeek :: Ptr TargetId -> IO TargetId
pokeByteOff :: Ptr b -> Int -> TargetId -> IO ()
$cpokeByteOff :: forall b. Ptr b -> Int -> TargetId -> IO ()
peekByteOff :: Ptr b -> Int -> IO TargetId
$cpeekByteOff :: forall b. Ptr b -> Int -> IO TargetId
pokeElemOff :: Ptr TargetId -> Int -> TargetId -> IO ()
$cpokeElemOff :: Ptr TargetId -> Int -> TargetId -> IO ()
peekElemOff :: Ptr TargetId -> Int -> IO TargetId
$cpeekElemOff :: Ptr TargetId -> Int -> IO TargetId
alignment :: TargetId -> Int
$calignment :: TargetId -> Int
sizeOf :: TargetId -> Int
$csizeOf :: TargetId -> Int
Storable,TargetId -> ()
(TargetId -> ()) -> NFData TargetId
forall a. (a -> ()) -> NFData a
rnf :: TargetId -> ()
$crnf :: 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
unsafeRangeSize :: (TargetId, TargetId) -> Int
$cunsafeRangeSize :: (TargetId, TargetId) -> Int
rangeSize :: (TargetId, TargetId) -> Int
$crangeSize :: (TargetId, TargetId) -> Int
inRange :: (TargetId, TargetId) -> TargetId -> Bool
$cinRange :: (TargetId, TargetId) -> TargetId -> Bool
unsafeIndex :: (TargetId, TargetId) -> TargetId -> Int
$cunsafeIndex :: (TargetId, TargetId) -> TargetId -> Int
index :: (TargetId, TargetId) -> TargetId -> Int
$cindex :: (TargetId, TargetId) -> TargetId -> Int
range :: (TargetId, TargetId) -> [TargetId]
$crange :: (TargetId, TargetId) -> [TargetId]
$cp1Ix :: Ord TargetId
Ix,Typeable)

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

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

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

instance ToJSON Target where
    toJSON :: Target -> Value
toJSON (Target a :: String
a b :: Maybe (String, String)
b c :: Maybe (String, String)
c d :: String
d e :: String
e f :: String
f) = [Pair] -> Value
object [
      ("url" :: T.Text, String -> Value
forall a. ToJSON a => a -> Value
toJSON String
a),
      ("package" :: T.Text, Maybe (String, String) -> Value
forall a a. (ToJSON a, ToJSON a) => Maybe (a, a) -> Value
maybeNamedURL Maybe (String, String)
b),
      ("module" :: T.Text, Maybe (String, String) -> Value
forall a a. (ToJSON a, ToJSON a) => Maybe (a, a) -> Value
maybeNamedURL Maybe (String, String)
c),
      ("type" :: T.Text, String -> Value
forall a. ToJSON a => a -> Value
toJSON String
d),
      ("item" :: T.Text, String -> Value
forall a. ToJSON a => a -> Value
toJSON String
e),
      ("docs" :: T.Text, String -> Value
forall a. ToJSON a => a -> Value
toJSON String
f)
      ]
      where
        maybeNamedURL :: Maybe (a, a) -> Value
maybeNamedURL m :: 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 (name :: a
name, url :: a
url) = [Pair] -> Value
object [("name" :: T.Text, a -> Value
forall a. ToJSON a => a -> Value
toJSON a
name), ("url" :: T.Text, a -> Value
forall a. ToJSON a => a -> Value
toJSON a
url)]

instance FromJSON Target where
  parseJSON :: Value -> Parser Target
parseJSON = String -> (Object -> Parser Target) -> Value -> Parser Target
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject "Target" ((Object -> Parser Target) -> Value -> Parser Target)
-> (Object -> Parser Target) -> Value -> Parser Target
forall a b. (a -> b) -> a -> b
$ \o :: Object
o ->
    String
-> Maybe (String, String)
-> Maybe (String, String)
-> String
-> String
-> String
-> Target
Target (String
 -> Maybe (String, String)
 -> Maybe (String, String)
 -> String
 -> String
 -> String
 -> Target)
-> Parser String
-> Parser
     (Maybe (String, String)
      -> Maybe (String, String) -> String -> String -> String -> Target)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Text -> Parser String
forall a. FromJSON a => Object -> Text -> Parser a
.: ("url" :: T.Text)
           Parser
  (Maybe (String, String)
   -> Maybe (String, String) -> String -> String -> String -> Target)
-> Parser (Maybe (String, String))
-> Parser
     (Maybe (String, String) -> String -> String -> String -> Target)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Text -> Parser (Maybe (String, String))
forall a b.
(FromJSON a, FromJSON b) =>
Object -> Text -> Parser (Maybe (a, b))
`namedUrl` ("package" :: T.Text)
           Parser
  (Maybe (String, String) -> String -> String -> String -> Target)
-> Parser (Maybe (String, String))
-> Parser (String -> String -> String -> Target)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Text -> Parser (Maybe (String, String))
forall a b.
(FromJSON a, FromJSON b) =>
Object -> Text -> Parser (Maybe (a, b))
`namedUrl` ("module" :: T.Text)
           Parser (String -> String -> String -> Target)
-> Parser String -> Parser (String -> String -> Target)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Text -> Parser String
forall a. FromJSON a => Object -> Text -> Parser a
.: ("type" :: T.Text)
           Parser (String -> String -> Target)
-> Parser String -> Parser (String -> Target)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Text -> Parser String
forall a. FromJSON a => Object -> Text -> Parser a
.: ("item" :: T.Text)
           Parser (String -> Target) -> Parser String -> Parser Target
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Text -> Parser String
forall a. FromJSON a => Object -> Text -> Parser a
.: ("docs" :: T.Text)
    where namedUrl :: Object -> Text -> Parser (Maybe (a, b))
namedUrl o' :: Object
o' n :: Text
n = do
             Object
mObj <- Object
o' Object -> Text -> Parser Object
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
n
             if Object -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null Object
mObj then Maybe (a, b) -> Parser (Maybe (a, b))
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (a, b)
forall a. Maybe a
Nothing
                        else do
                           a
pkName <- Object
mObj Object -> Text -> Parser a
forall a. FromJSON a => Object -> Text -> Parser a
.: ("name" :: T.Text)
                           b
pkUrl  <- Object
mObj Object -> Text -> Parser b
forall a. FromJSON a => Object -> Text -> Parser a
.: ("url" :: T.Text)
                           Maybe (a, b) -> Parser (Maybe (a, b))
forall (m :: * -> *) a. Monad m => a -> m a
return (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 = String
-> Maybe (String, String)
-> Maybe (String, String)
-> String
-> String
-> String
-> Target
Target (String
 -> Maybe (String, String)
 -> Maybe (String, String)
 -> String
 -> String
 -> String
 -> Target)
-> Gen String
-> Gen
     (Maybe (String, String)
      -> Maybe (String, String) -> String -> String -> String -> Target)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen String
a
                     Gen
  (Maybe (String, String)
   -> Maybe (String, String) -> String -> String -> String -> Target)
-> Gen (Maybe (String, String))
-> Gen
     (Maybe (String, String) -> String -> String -> String -> Target)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen (Maybe (String, String))
mNurl
                     Gen
  (Maybe (String, String) -> String -> String -> String -> Target)
-> Gen (Maybe (String, String))
-> Gen (String -> String -> String -> Target)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen (Maybe (String, String))
mNurl
                     Gen (String -> String -> String -> Target)
-> Gen String -> Gen (String -> String -> Target)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen String
a
                     Gen (String -> String -> Target)
-> Gen String -> Gen (String -> Target)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen String
a
                     Gen (String -> Target) -> Gen String -> Gen Target
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen String
a
    where a :: Gen String
a = Gen String
forall a. Arbitrary a => Gen a
arbitrary
          mNurl :: Gen (Maybe (String, String))
mNurl = do
            [Gen (Maybe (String, String))] -> Gen (Maybe (String, String))
forall a. [Gen a] -> Gen a
oneof [Maybe (String, String) -> Gen (Maybe (String, String))
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (String, String)
forall a. Maybe a
Nothing
                 , (String, String) -> Maybe (String, String)
forall a. a -> Maybe a
Just ((String, String) -> Maybe (String, String))
-> Gen (String, String) -> Gen (Maybe (String, String))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> String -> (String, String))
-> Gen String -> Gen String -> Gen (String, String)
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 (,) Gen String
a Gen String
a]

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

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

unHTMLTarget :: Target -> Target
unHTMLTarget :: Target -> Target
unHTMLTarget t :: Target
t@Target {..} = Target
t{targetItem :: String
targetItem=ShowS
unHTML String
targetItem, targetDocs :: String
targetDocs=ShowS
unHTML String
targetDocs}

splitIPackage, splitIModule :: [(a, Item)] -> [(Str, [(a, Item)])]
splitIPackage :: [(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
$ \x :: (a, Item)
x -> case (a, Item) -> Item
forall a b. (a, b) -> b
snd (a, Item)
x of IPackage x :: PkgName
x -> PkgName -> Maybe PkgName
forall a. a -> Maybe a
Just PkgName
x; _ -> Maybe PkgName
forall a. Maybe a
Nothing
splitIModule :: [(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
$ \x :: (a, Item)
x -> case (a, Item) -> Item
forall a b. (a, b) -> b
snd (a, Item)
x of IModule x :: PkgName
x -> PkgName -> Maybe PkgName
forall a. a -> Maybe a
Just PkgName
x; _ -> Maybe PkgName
forall a. Maybe a
Nothing

splitUsing :: (a -> Maybe Str) -> [a] -> [(Str, [a])]
splitUsing :: (a -> Maybe PkgName) -> [a] -> [(PkgName, [a])]
splitUsing f :: 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
$ \(x :: a
x:xs :: [a]
xs) ->
    let (a :: [a]
a,b :: [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 = String -> IO () -> IO ()
testing "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 String Target
forall a. FromJSON a => ByteString -> Either String a
J.eitherDecode (ByteString -> Either String Target)
-> ByteString -> Either String Target
forall a b. (a -> b) -> a -> b
$ Target -> ByteString
forall a. ToJSON a => a -> ByteString
J.encode Target
t of
    (Left  e :: String
e ) -> Bool
False
    (Right t' :: Target
t') -> Target
t Target -> Target -> Bool
forall a. Eq a => a -> a -> Bool
== Target
t'

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

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

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

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

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

        ctxTy :: Type a -> [Ctx String]
ctxTy (TyInfix an :: a
an a :: Type a
a (UnpromotedName _ con :: QName a
con) b :: Type a
b) = Type a -> [Ctx String]
ctxTy (Type a -> [Ctx String]) -> Type a -> [Ctx String]
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 _ con :: QName a
con:TyVar _ var :: Name a
var:_) = [String -> String -> Ctx String
forall n. n -> n -> Ctx n
Ctx (QName a -> String
forall a. QName a -> String
fromQName QName a
con) (Name a -> String
forall a. Name a -> String
fromName Name a
var)]
        ctxTy _ = []

        fromTyApps :: Type l -> [Type l]
fromTyApps (TyApp _ x :: Type l
x y :: 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 x :: Type l
x = [Type l
x]


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