module Text.Show.Text.Data.OldTypeable (showbTyCon, showbTypeRepPrec) where
import Data.OldTypeable.Internal (TyCon(TyCon, tyConName), TypeRep(..),
funTc, listTc)
import Data.Text.Lazy.Builder (Builder, fromString)
import Prelude hiding (Show)
import Text.Show.Text.Classes (Show(showb, showbPrec), showbParen, showbSpace)
import Text.Show.Text.Data.Typeable.Utils (showbArgs, showbTuple)
import Text.Show.Text.Utils ((<>), isTupleString, s)
showbTyCon :: TyCon -> Builder
showbTyCon = fromString . tyConName
showbTypeRepPrec :: Int -> TypeRep -> Builder
showbTypeRepPrec p (TypeRep _ tycon tys) =
case tys of
[] -> showbTyCon tycon
[x] | tycon == listTc -> s '[' <> showb x <> s ']'
[a,r] | tycon == funTc -> showbParen (p > 8) $
showbPrec 9 a
<> " -> "
<> showbPrec 8 r
xs | isTupleTyCon tycon -> showbTuple xs
| otherwise -> showbParen (p > 9) $
showbPrec p tycon
<> showbSpace
<> showbArgs showbSpace tys
isTupleTyCon :: TyCon -> Bool
isTupleTyCon (TyCon _ _ _ str) = isTupleString str
instance Show TyCon where
showb = showbTyCon
instance Show TypeRep where
showbPrec = showbTypeRepPrec