-- | Pretty printer for Haskell declarations.
--   It provides functions to transform declarations and especially type
--   signatures into documents.
--
--   See the module \"Text.PrettyPrint\" for more details about the used
--   document type.

module Language.Haskell.FreeTheorems.PrettyTypes where

import Prelude hiding ((<>))

import Text.PrettyPrint

import Language.Haskell.FreeTheorems.BasicSyntax
import Language.Haskell.FreeTheorems.PrettyBase



------- Declarations ----------------------------------------------------------


-- | Pretty-prints a declaration.

prettyDeclaration :: Declaration -> Doc
prettyDeclaration :: Declaration -> Doc
prettyDeclaration (TypeDecl TypeDeclaration
decl)    = TypeDeclaration -> Doc
prettyTypeDeclaration TypeDeclaration
decl
prettyDeclaration (DataDecl DataDeclaration
decl)    = DataDeclaration -> Doc
prettyDataDeclaration DataDeclaration
decl
prettyDeclaration (NewtypeDecl NewtypeDeclaration
decl) = NewtypeDeclaration -> Doc
prettyNewtypeDeclaration NewtypeDeclaration
decl
prettyDeclaration (ClassDecl ClassDeclaration
decl)   = ClassDeclaration -> Doc
prettyClassDeclaration ClassDeclaration
decl
prettyDeclaration (TypeSig Signature
decl)     = Signature -> Doc
prettySignature Signature
decl


instance Show Declaration where
  show :: Declaration -> String
show = forall a. Show a => a -> String
show forall b c a. (b -> c) -> (a -> b) -> a -> c
. Declaration -> Doc
prettyDeclaration
  showList :: [Declaration] -> ShowS
showList [Declaration]
ds = forall a. [a] -> [a] -> [a]
(++) (forall a. Show a => a -> String
show forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Doc] -> Doc
vcat forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map Declaration -> Doc
prettyDeclaration forall a b. (a -> b) -> a -> b
$ [Declaration]
ds)



-- | Pretty-prints a type declaration.

prettyTypeDeclaration :: TypeDeclaration -> Doc
prettyTypeDeclaration :: TypeDeclaration -> Doc
prettyTypeDeclaration (Type Identifier
ident [TypeVariable]
vs TypeExpression
t) =
  Int -> [Doc] -> Doc
isep Int
2 (
    [String -> Doc
text String
"type", Identifier -> Doc
prettyIdentifier Identifier
ident]
    forall a. [a] -> [a] -> [a]
++ forall a b. (a -> b) -> [a] -> [b]
map TypeVariable -> Doc
prettyTypeVariable [TypeVariable]
vs
    forall a. [a] -> [a] -> [a]
++ [String -> Doc
text String
"=", Parens -> TypeExpression -> Doc
prettyTypeExpression Parens
NoParens TypeExpression
t])

instance Show TypeDeclaration where
  show :: TypeDeclaration -> String
show = forall a. Show a => a -> String
show forall b c a. (b -> c) -> (a -> b) -> a -> c
. TypeDeclaration -> Doc
prettyTypeDeclaration



-- | Pretty-prints a data declaration.

prettyDataDeclaration :: DataDeclaration -> Doc
prettyDataDeclaration :: DataDeclaration -> Doc
prettyDataDeclaration (Data Identifier
ident [TypeVariable]
vs [DataConstructorDeclaration]
ds) = 
  Int -> [Doc] -> Doc
isep Int
4 [ Int -> [Doc] -> Doc
isep Int
2 (
             [String -> Doc
text String
"data", Identifier -> Doc
prettyIdentifier Identifier
ident]
             forall a. [a] -> [a] -> [a]
++ (forall a b. (a -> b) -> [a] -> [b]
map TypeVariable -> Doc
prettyTypeVariable [TypeVariable]
vs))
         , [Doc] -> Doc
vcat (forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith Doc -> Doc -> Doc
(<+>) (Char -> Doc
char Char
'=' forall a. a -> [a] -> [a]
: forall a. a -> [a]
repeat (Char -> Doc
char Char
'|'))
                               (forall a b. (a -> b) -> [a] -> [b]
map DataConstructorDeclaration -> Doc
prettyDataConstructorDeclaration [DataConstructorDeclaration]
ds))]

instance Show DataDeclaration where
  show :: DataDeclaration -> String
show = forall a. Show a => a -> String
show forall b c a. (b -> c) -> (a -> b) -> a -> c
. DataDeclaration -> Doc
prettyDataDeclaration



-- | Pretty-prints a data constructor declaration.

prettyDataConstructorDeclaration :: DataConstructorDeclaration -> Doc
prettyDataConstructorDeclaration :: DataConstructorDeclaration -> Doc
prettyDataConstructorDeclaration (DataCon Identifier
ident [BangTypeExpression]
bs) = 
  Int -> [Doc] -> Doc
isep Int
2 forall a b. (a -> b) -> a -> b
$ [Identifier -> Doc
prettyIdentifier Identifier
ident] forall a. [a] -> [a] -> [a]
++ forall a b. (a -> b) -> [a] -> [b]
map BangTypeExpression -> Doc
prettyBangTypeExpression [BangTypeExpression]
bs

instance Show DataConstructorDeclaration where
  show :: DataConstructorDeclaration -> String
show = forall a. Show a => a -> String
show forall b c a. (b -> c) -> (a -> b) -> a -> c
. DataConstructorDeclaration -> Doc
prettyDataConstructorDeclaration



-- | Pretty-prints a type expression having an optional strictness flag.

prettyBangTypeExpression :: BangTypeExpression -> Doc
prettyBangTypeExpression :: BangTypeExpression -> Doc
prettyBangTypeExpression (Banged TypeExpression
t)   = Char -> Doc
char Char
'!'
                                        Doc -> Doc -> Doc
<> Parens -> TypeExpression -> Doc
prettyTypeExpression Parens
ParensFunOrCon TypeExpression
t
prettyBangTypeExpression (Unbanged TypeExpression
t) = Parens -> TypeExpression -> Doc
prettyTypeExpression Parens
ParensFunOrCon TypeExpression
t

instance Show BangTypeExpression where
  show :: BangTypeExpression -> String
show = forall a. Show a => a -> String
show forall b c a. (b -> c) -> (a -> b) -> a -> c
. BangTypeExpression -> Doc
prettyBangTypeExpression



-- | Pretty-prints a newtype declaration.

prettyNewtypeDeclaration :: NewtypeDeclaration -> Doc
prettyNewtypeDeclaration :: NewtypeDeclaration -> Doc
prettyNewtypeDeclaration (Newtype Identifier
ident [TypeVariable]
vs Identifier
con TypeExpression
t) =
  Int -> [Doc] -> Doc
isep Int
2 (
    [String -> Doc
text String
"newtype", Identifier -> Doc
prettyIdentifier Identifier
ident]
    forall a. [a] -> [a] -> [a]
++ forall a b. (a -> b) -> [a] -> [b]
map TypeVariable -> Doc
prettyTypeVariable [TypeVariable]
vs
    forall a. [a] -> [a] -> [a]
++ [Char -> Doc
char Char
'=', Identifier -> Doc
prettyIdentifier Identifier
con, Parens -> TypeExpression -> Doc
prettyTypeExpression Parens
ParensFunOrCon TypeExpression
t])

instance Show NewtypeDeclaration where
  show :: NewtypeDeclaration -> String
show = forall a. Show a => a -> String
show forall b c a. (b -> c) -> (a -> b) -> a -> c
. NewtypeDeclaration -> Doc
prettyNewtypeDeclaration



-- | Pretty-prints a class declaration.

prettyClassDeclaration :: ClassDeclaration -> Doc
prettyClassDeclaration :: ClassDeclaration -> Doc
prettyClassDeclaration (Class [TypeClass]
scs Identifier
ident TypeVariable
tv [Signature]
sigs) =
  let ctx :: [(TypeClass, TypeVariable)]
ctx = forall a b. [a] -> [b] -> [(a, b)]
zip [TypeClass]
scs (forall a. a -> [a]
repeat TypeVariable
tv)
   in Int -> [Doc] -> Doc
isep Int
2 [String -> Doc
text String
"class", [(TypeClass, TypeVariable)] -> Doc
prettyContext [(TypeClass, TypeVariable)]
ctx, Identifier -> Doc
prettyIdentifier Identifier
ident,
              TypeVariable -> Doc
prettyTypeVariable TypeVariable
tv,
              if forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Signature]
sigs then Doc
empty else String -> Doc
text String
"where"]
      Doc -> Doc -> Doc
$$ Int -> Doc -> Doc
nest Int
4 ([Doc] -> Doc
vcat (forall a b. (a -> b) -> [a] -> [b]
map Signature -> Doc
prettySignature [Signature]
sigs))

instance Show ClassDeclaration where
  show :: ClassDeclaration -> String
show = forall a. Show a => a -> String
show forall b c a. (b -> c) -> (a -> b) -> a -> c
. ClassDeclaration -> Doc
prettyClassDeclaration



-- | Pretty-prints a type signature.

prettySignature :: Signature -> Doc
prettySignature :: Signature -> Doc
prettySignature (Signature Identifier
ident TypeExpression
t) =
  Int -> [Doc] -> Doc
isep Int
2 [Identifier -> Doc
prettyIdentifier Identifier
ident, String -> Doc
text String
"::", Parens -> TypeExpression -> Doc
prettyTypeExpression Parens
NoParens TypeExpression
t]

instance Show Signature where
  show :: Signature -> String
show = forall a. Show a => a -> String
show forall b c a. (b -> c) -> (a -> b) -> a -> c
. Signature -> Doc
prettySignature



-- | Pretty-prints a class context constraining certain type variables.

prettyContext :: [(TypeClass, TypeVariable)] -> Doc
prettyContext :: [(TypeClass, TypeVariable)] -> Doc
prettyContext []  = Doc
empty
prettyContext [(TypeClass, TypeVariable)]
ctx =
  let prettyCV :: (TypeClass, TypeVariable) -> Doc
prettyCV (TypeClass
c,TypeVariable
v) = TypeClass -> Doc
prettyTypeClass TypeClass
c Doc -> Doc -> Doc
<+> TypeVariable -> Doc
prettyTypeVariable TypeVariable
v
   in [Doc] -> Doc
fsep (
        (Bool -> Doc -> Doc
parensIf ((forall (t :: * -> *) a. Foldable t => t a -> Int
length [(TypeClass, TypeVariable)]
ctx) forall a. Ord a => a -> a -> Bool
> Int
1) 
                  ([Doc] -> Doc
fsep forall a b. (a -> b) -> a -> b
$ Doc -> [Doc] -> [Doc]
punctuate Doc
comma forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map (TypeClass, TypeVariable) -> Doc
prettyCV [(TypeClass, TypeVariable)]
ctx))
        forall a. a -> [a] -> [a]
: [String -> Doc
text String
"=>"])



------- Type expressions ------------------------------------------------------


instance Show TypeExpression where
  showsPrec :: Int -> TypeExpression -> ShowS
showsPrec Int
d TypeExpression
t = 
    let p :: Parens
p = case Int
d of
              Int
0         -> Parens
NoParens
              Int
1         -> Parens
ParensFun
              Int
otherwise -> Parens
ParensFunOrCon
     in forall a. [a] -> [a] -> [a]
(++) (forall a. Show a => a -> String
show (Parens -> TypeExpression -> Doc
prettyTypeExpression Parens
p TypeExpression
t))



-- | Pretty-prints a type expression.

prettyTypeExpression :: Parens -> TypeExpression -> Doc

prettyTypeExpression :: Parens -> TypeExpression -> Doc
prettyTypeExpression Parens
_ (TypeVar TypeVariable
v) = TypeVariable -> Doc
prettyTypeVariable TypeVariable
v

prettyTypeExpression Parens
_ (TypeCon TypeConstructor
ConUnit [TypeExpression]
_) = TypeConstructor -> Doc
prettyTypeConstructor TypeConstructor
ConUnit

prettyTypeExpression Parens
_ (TypeCon TypeConstructor
ConList [TypeExpression
t]) =
  Doc -> Doc
brackets (Parens -> TypeExpression -> Doc
prettyTypeExpression Parens
NoParens TypeExpression
t)

    -- the following two cases are given to pretty-print also invalid
    -- type expressions, they should usually not occur
prettyTypeExpression Parens
_ (TypeCon TypeConstructor
ConList []) = TypeConstructor -> Doc
prettyTypeConstructor TypeConstructor
ConList
prettyTypeExpression Parens
_ (TypeCon TypeConstructor
ConList (TypeExpression
_:TypeExpression
_:[TypeExpression]
_)) = Doc -> Doc
brackets (String -> Doc
text String
"...")

prettyTypeExpression Parens
_ (TypeCon (ConTuple Int
_) [TypeExpression]
ts) = 
  Doc -> Doc
parens forall a b. (a -> b) -> a -> b
$ [Doc] -> Doc
fsep forall a b. (a -> b) -> a -> b
$ Doc -> [Doc] -> [Doc]
punctuate Doc
comma forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map (Parens -> TypeExpression -> Doc
prettyTypeExpression Parens
NoParens) [TypeExpression]
ts

prettyTypeExpression Parens
_ (TypeCon TypeConstructor
ConInt [TypeExpression]
_)     = TypeConstructor -> Doc
prettyTypeConstructor TypeConstructor
ConInt
prettyTypeExpression Parens
_ (TypeCon TypeConstructor
ConInteger [TypeExpression]
_) = TypeConstructor -> Doc
prettyTypeConstructor TypeConstructor
ConInteger
prettyTypeExpression Parens
_ (TypeCon TypeConstructor
ConFloat [TypeExpression]
_)   = TypeConstructor -> Doc
prettyTypeConstructor TypeConstructor
ConFloat
prettyTypeExpression Parens
_ (TypeCon TypeConstructor
ConDouble [TypeExpression]
_)  = TypeConstructor -> Doc
prettyTypeConstructor TypeConstructor
ConDouble
prettyTypeExpression Parens
_ (TypeCon TypeConstructor
ConChar [TypeExpression]
_)    = TypeConstructor -> Doc
prettyTypeConstructor TypeConstructor
ConChar

prettyTypeExpression Parens
p (TypeCon (Con Identifier
ident) [TypeExpression]
ts) =
  Bool -> Doc -> Doc
parensIf (Parens
p forall a. Ord a => a -> a -> Bool
>= Parens
ParensFunOrCon Bool -> Bool -> Bool
&& Bool -> Bool
not (forall (t :: * -> *) a. Foldable t => t a -> Bool
null [TypeExpression]
ts)) forall a b. (a -> b) -> a -> b
$
    Int -> [Doc] -> Doc
isep Int
2 forall a b. (a -> b) -> a -> b
$ (Identifier -> Doc
prettyIdentifier Identifier
ident) 
             forall a. a -> [a] -> [a]
: (forall a b. (a -> b) -> [a] -> [b]
map (Parens -> TypeExpression -> Doc
prettyTypeExpression Parens
ParensFunOrCon) [TypeExpression]
ts)

prettyTypeExpression Parens
p (TypeFun TypeExpression
t1 TypeExpression
t2) =
  Bool -> Doc -> Doc
parensIf (Parens
p forall a. Ord a => a -> a -> Bool
> Parens
NoParens) forall a b. (a -> b) -> a -> b
$ 
    [Doc] -> Doc
fsep (forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith Doc -> Doc -> Doc
(<+>) (Doc
empty forall a. a -> [a] -> [a]
: forall a. a -> [a]
repeat (String -> Doc
text String
"->")) 
                        (forall a b. (a -> b) -> [a] -> [b]
map (Parens -> TypeExpression -> Doc
prettyTypeExpression Parens
ParensFun) (TypeExpression
t1 forall a. a -> [a] -> [a]
: TypeExpression -> [TypeExpression]
funs TypeExpression
t2)))
  where
    funs :: TypeExpression -> [TypeExpression]
funs (TypeFun TypeExpression
t1 TypeExpression
t2) = TypeExpression
t1 forall a. a -> [a] -> [a]
: TypeExpression -> [TypeExpression]
funs TypeExpression
t2
    funs TypeExpression
t               = [TypeExpression
t]

prettyTypeExpression Parens
p (TypeFunLab TypeExpression
t1 TypeExpression
t2) =
  Bool -> Doc -> Doc
parensIf (Parens
p forall a. Ord a => a -> a -> Bool
> Parens
NoParens) forall a b. (a -> b) -> a -> b
$ 
    [Doc] -> Doc
fsep (forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith Doc -> Doc -> Doc
(<+>) (Doc
empty forall a. a -> [a] -> [a]
: forall a. a -> [a]
repeat (String -> Doc
text String
"->")) 
                        (forall a b. (a -> b) -> [a] -> [b]
map (Parens -> TypeExpression -> Doc
prettyTypeExpression Parens
ParensFun) (TypeExpression
t1 forall a. a -> [a] -> [a]
: TypeExpression -> [TypeExpression]
funs TypeExpression
t2)))
  where
    funs :: TypeExpression -> [TypeExpression]
funs (TypeFunLab TypeExpression
t1 TypeExpression
t2) = TypeExpression
t1 forall a. a -> [a] -> [a]
: TypeExpression -> [TypeExpression]
funs TypeExpression
t2
    funs TypeExpression
t                  = [TypeExpression
t]

prettyTypeExpression Parens
p (TypeAbs TypeVariable
v [TypeClass]
tcs TypeExpression
t) =
  let ([TypeVariable]
vs, [(TypeClass, TypeVariable)]
cx, TypeExpression
t') = TypeVariable
-> [TypeClass]
-> TypeExpression
-> ([TypeVariable], [(TypeClass, TypeVariable)], TypeExpression)
collectAbstractions TypeVariable
v [TypeClass]
tcs TypeExpression
t
   in Bool -> Doc -> Doc
parensIf (Parens
p forall a. Ord a => a -> a -> Bool
> Parens
NoParens) forall a b. (a -> b) -> a -> b
$
        [Doc] -> Doc
fsep forall a b. (a -> b) -> a -> b
$ 
          [String -> Doc
text String
"forall"] forall a. [a] -> [a] -> [a]
++ (forall a b. (a -> b) -> [a] -> [b]
map TypeVariable -> Doc
prettyTypeVariable [TypeVariable]
vs)
          forall a. [a] -> [a] -> [a]
++ [Char -> Doc
char Char
'.', [(TypeClass, TypeVariable)] -> Doc
prettyContext [(TypeClass, TypeVariable)]
cx, Parens -> TypeExpression -> Doc
prettyTypeExpression Parens
NoParens TypeExpression
t']

prettyTypeExpression Parens
p (TypeAbsLab TypeVariable
v [TypeClass]
tcs TypeExpression
t) =
  let ([TypeVariable]
vs, [(TypeClass, TypeVariable)]
cx, TypeExpression
t') = TypeVariable
-> [TypeClass]
-> TypeExpression
-> ([TypeVariable], [(TypeClass, TypeVariable)], TypeExpression)
collectAbstractions TypeVariable
v [TypeClass]
tcs TypeExpression
t
   in Bool -> Doc -> Doc
parensIf (Parens
p forall a. Ord a => a -> a -> Bool
> Parens
NoParens) forall a b. (a -> b) -> a -> b
$
        [Doc] -> Doc
fsep forall a b. (a -> b) -> a -> b
$ 
          [String -> Doc
text String
"forall"] forall a. [a] -> [a] -> [a]
++ (forall a b. (a -> b) -> [a] -> [b]
map TypeVariable -> Doc
prettyTypeVariable [TypeVariable]
vs)
          forall a. [a] -> [a] -> [a]
++ [Char -> Doc
char Char
'.', [(TypeClass, TypeVariable)] -> Doc
prettyContext [(TypeClass, TypeVariable)]
cx, Parens -> TypeExpression -> Doc
prettyTypeExpression Parens
NoParens TypeExpression
t']

prettyTypeExpression Parens
p (TypeExp FixedTypeExpression
te) = FixedTypeExpression -> Doc
prettyFixedTypeExpression FixedTypeExpression
te



-- | Collects all type abstractions which follow each other. This is used to get
--   a more compact output.

collectAbstractions :: 
    TypeVariable 
    -> [TypeClass] 
    -> TypeExpression 
    -> ([TypeVariable], [(TypeClass, TypeVariable)], TypeExpression)

collectAbstractions :: TypeVariable
-> [TypeClass]
-> TypeExpression
-> ([TypeVariable], [(TypeClass, TypeVariable)], TypeExpression)
collectAbstractions TypeVariable
v [TypeClass]
tcs TypeExpression
t =
  let cx :: [(TypeClass, TypeVariable)]
cx = forall a b. [a] -> [b] -> [(a, b)]
zip [TypeClass]
tcs (forall a. a -> [a]
repeat TypeVariable
v)
   in case TypeExpression
t of
        TypeAbs TypeVariable
v' [TypeClass]
tcs' TypeExpression
t'    -> 
          let ([TypeVariable]
vs, [(TypeClass, TypeVariable)]
cx', TypeExpression
t'') = TypeVariable
-> [TypeClass]
-> TypeExpression
-> ([TypeVariable], [(TypeClass, TypeVariable)], TypeExpression)
collectAbstractions TypeVariable
v' [TypeClass]
tcs' TypeExpression
t'
           in (TypeVariable
v forall a. a -> [a] -> [a]
: [TypeVariable]
vs, [(TypeClass, TypeVariable)]
cx forall a. [a] -> [a] -> [a]
++ [(TypeClass, TypeVariable)]
cx', TypeExpression
t'')
	TypeAbsLab TypeVariable
v' [TypeClass]
tcs' TypeExpression
t' -> 
          let ([TypeVariable]
vs, [(TypeClass, TypeVariable)]
cx', TypeExpression
t'') = TypeVariable
-> [TypeClass]
-> TypeExpression
-> ([TypeVariable], [(TypeClass, TypeVariable)], TypeExpression)
collectAbstractions TypeVariable
v' [TypeClass]
tcs' TypeExpression
t'
           in (TypeVariable
v forall a. a -> [a] -> [a]
: [TypeVariable]
vs, [(TypeClass, TypeVariable)]
cx forall a. [a] -> [a] -> [a]
++ [(TypeClass, TypeVariable)]
cx', TypeExpression
t'')
         
        TypeExpression
otherwise             -> ([TypeVariable
v], [(TypeClass, TypeVariable)]
cx, TypeExpression
t)



-- | Pretty-prints a type constructor.

prettyTypeConstructor :: TypeConstructor -> Doc
prettyTypeConstructor :: TypeConstructor -> Doc
prettyTypeConstructor TypeConstructor
ConUnit      = Doc -> Doc
parens (Doc
empty)  
prettyTypeConstructor TypeConstructor
ConList      = Doc -> Doc
brackets (Doc
empty)
prettyTypeConstructor (ConTuple Int
n) =
  Doc -> Doc
parens forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Doc] -> Doc
hcat forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> [Doc] -> [Doc]
punctuate Doc
comma forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Int -> [a] -> [a]
take Int
n forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> [a]
repeat forall a b. (a -> b) -> a -> b
$ Doc
empty
prettyTypeConstructor TypeConstructor
ConInt       = String -> Doc
text String
"Int"
prettyTypeConstructor TypeConstructor
ConInteger   = String -> Doc
text String
"Integer"
prettyTypeConstructor TypeConstructor
ConFloat     = String -> Doc
text String
"Float"
prettyTypeConstructor TypeConstructor
ConDouble    = String -> Doc
text String
"Double"
prettyTypeConstructor TypeConstructor
ConChar      = String -> Doc
text String
"Char"
prettyTypeConstructor (Con Identifier
c)      = Identifier -> Doc
prettyIdentifier Identifier
c 



-- | Pretty-prints a type variable.

prettyTypeVariable :: TypeVariable -> Doc
prettyTypeVariable :: TypeVariable -> Doc
prettyTypeVariable (TV Identifier
ident) = Identifier -> Doc
prettyIdentifier Identifier
ident

instance Show TypeVariable where
  show :: TypeVariable -> String
show = forall a. Show a => a -> String
show forall b c a. (b -> c) -> (a -> b) -> a -> c
. TypeVariable -> Doc
prettyTypeVariable



-- | Pretty-prints a type class.

prettyTypeClass :: TypeClass -> Doc
prettyTypeClass :: TypeClass -> Doc
prettyTypeClass (TC Identifier
ident) = Identifier -> Doc
prettyIdentifier Identifier
ident

instance Show TypeClass where
  show :: TypeClass -> String
show = forall a. Show a => a -> String
show forall b c a. (b -> c) -> (a -> b) -> a -> c
. TypeClass -> Doc
prettyTypeClass



-- | Pretty-prints a fixed type expression.

prettyFixedTypeExpression :: FixedTypeExpression -> Doc
prettyFixedTypeExpression :: FixedTypeExpression -> Doc
prettyFixedTypeExpression (TF Identifier
ident) = Identifier -> Doc
prettyIdentifier Identifier
ident

instance Show FixedTypeExpression where
  show :: FixedTypeExpression -> String
show = forall a. Show a => a -> String
show forall b c a. (b -> c) -> (a -> b) -> a -> c
. FixedTypeExpression -> Doc
prettyFixedTypeExpression



-- | Pretty-prints an identifier.

prettyIdentifier :: Identifier -> Doc
prettyIdentifier :: Identifier -> Doc
prettyIdentifier (Ident String
i) = String -> Doc
text String
i

instance Show Identifier where
  show :: Identifier -> String
show = forall a. Show a => a -> String
show forall b c a. (b -> c) -> (a -> b) -> a -> c
. Identifier -> Doc
prettyIdentifier