{-# LANGUAGE UndecidableInstances #-}
module Data.Type.Pretty where
import Control.Monad.RWS hiding (tell)
import qualified Control.Monad.RWS
import GHC.TypeLits
import Data.Proxy
import Text.Printf
import Data.Word
import Data.Int
import Data.Tagged
import Data.Kind (type Type)
showPretty
:: forall k proxy (t :: k) . PrettyTypeShow (ToPretty t)
=> proxy t
-> String
showPretty :: proxy t -> String
showPretty proxy t
_ = ((), String) -> String
forall a b. (a, b) -> b
snd (((), String) -> String) -> ((), String) -> String
forall a b. (a -> b) -> a -> b
$ RWS Indentation String PTRenderState ()
-> Indentation -> PTRenderState -> ((), String)
forall r w s a. RWS r w s a -> r -> s -> (a, w)
evalRWS (Proxy (ToPretty t) -> RWS Indentation String PTRenderState ()
forall (p :: PrettyType) (proxy :: PrettyType -> *).
PrettyTypeShow p =>
proxy p -> RWS Indentation String PTRenderState ()
ptShow (Proxy (ToPretty t)
forall k (t :: k). Proxy t
Proxy :: Proxy (ToPretty t))) Indentation
0 PTRenderState
AtBeginningOfLine
type family ToPretty (a :: k) :: PrettyType
type instance ToPretty (t :: PrettyType) = t
type instance ToPretty (t :: Symbol) = PutStr t
type instance ToPretty (t :: Nat) = PutNat t
type instance ToPretty 'True = PutStr "'True"
type instance ToPretty 'False = PutStr "'False"
type instance ToPretty (t :: Maybe x) = ToPrettyMaybe t
type family ToPrettyMaybe (t :: Maybe x) :: PrettyType where
ToPrettyMaybe 'Nothing = 'PrettyEmpty
ToPrettyMaybe ('Just x) = ToPretty x
type instance ToPretty Word8 = PutStr "Word8"
type instance ToPretty Word16 = PutStr "Word16"
type instance ToPretty Word32 = PutStr "Word32"
type instance ToPretty Word64 = PutStr "Word64"
type instance ToPretty Int8 = PutStr "Int8"
type instance ToPretty Int16 = PutStr "Int16"
type instance ToPretty Int32 = PutStr "Int32"
type instance ToPretty Int64 = PutStr "Int64"
type instance ToPretty Int = PutStr "Int"
type instance ToPretty Integer = PutStr "Integer"
type instance ToPretty Bool = PutStr "Bool"
type instance ToPretty Float = PutStr "Float"
type instance ToPretty Double = PutStr "Double"
type PutStr str = 'PrettySymbol 'PrettyUnpadded 'PrettyPrecise str
type PutStrW width str =
'PrettySymbol ('PrettyPadded width) ('PrettyPrecision width) str
type PutStrLn str = PutStr str <++> PutStr "\n"
type PutNat x = 'PrettyNat 'PrettyUnpadded 'PrettyPrecise 'PrettyDec x
type PutNatW width x = 'PrettyNat ('PrettyPadded width) 'PrettyPrecise 'PrettyDec x
type PutHex x = 'PrettyNat 'PrettyUnpadded 'PrettyPrecise 'PrettyHex x
type PutHex8 x = 'PrettyNat 'PrettyUnpadded ('PrettyPrecision 2) 'PrettyHex x
type PutHex16 x = 'PrettyNat 'PrettyUnpadded ('PrettyPrecision 4) 'PrettyHex x
type PutHex32 x = 'PrettyNat 'PrettyUnpadded ('PrettyPrecision 8) 'PrettyHex x
type PutHex64 x = 'PrettyNat 'PrettyUnpadded ('PrettyPrecision 16) 'PrettyHex x
type PutHeX x = 'PrettyNat 'PrettyUnpadded 'PrettyPrecise 'PrettyHexU x
type PutHeX8 x = 'PrettyNat 'PrettyUnpadded ('PrettyPrecision 2) 'PrettyHexU x
type PutHeX16 x = 'PrettyNat 'PrettyUnpadded ('PrettyPrecision 4) 'PrettyHexU x
type PutHeX32 x = 'PrettyNat 'PrettyUnpadded ('PrettyPrecision 8) 'PrettyHexU x
type PutHeX64 x = 'PrettyNat 'PrettyUnpadded ('PrettyPrecision 16) 'PrettyHexU x
type PutBits x = 'PrettyNat 'PrettyUnpadded 'PrettyPrecise 'PrettyBit x
type PutBits8 x = 'PrettyNat 'PrettyUnpadded ('PrettyPrecision 8) 'PrettyBit x
type PutBits16 x = 'PrettyNat 'PrettyUnpadded ('PrettyPrecision 16) 'PrettyBit x
type PutBits32 x = 'PrettyNat 'PrettyUnpadded ('PrettyPrecision 32) 'PrettyBit x
type PutBits64 x = 'PrettyNat 'PrettyUnpadded ('PrettyPrecision 64) 'PrettyBit x
type (<:>) label body = 'PrettySuffix (PutStr ":") (PutStr label) <+> body
infixl 5 <:>
type (<:$$>) label body = 'PrettySuffix (PutStr ":") (PutStr label) <$$> body
infixl 5 <:$$>
type (<:$$-->) label body = 'PrettySuffix (PutStr ":") (PutStr label) <$$--> body
infixl 3 <:$$-->
type (<++>) l r = 'PrettyInfix 'PrettyEmpty l r
infixl 6 <++>
type (<+>) l r = 'PrettyInfix 'PrettySpace l r
infixl 5 <+>
type (<||>) l r = 'PrettyAlternative l r
infixl 5 <||>
type (<$$>) l r = 'PrettyInfix 'PrettyNewline l r
infixl 4 <$$>
type (<$$-->) l r = 'PrettyInfix 'PrettyNewline l ('PrettyIndent 2 r)
infixl 3 <$$-->
type PrettyParens doc = PrettySurrounded (PutStr "(") (PutStr ")") doc
type PrettySurrounded open close doc =
open <++> doc <++> close
type PrettyWide docs = PrettyMany 'PrettySpace docs
type PrettyHigh docs = PrettyMany 'PrettyNewline docs
type PrettyManyIn sep docs =
PrettySurrounded sep sep (PrettyMany sep docs)
type family
PrettyMany (sep :: PrettyType)(docs :: [PrettyType]) :: PrettyType where
PrettyMany sep '[] = 'PrettyEmpty
PrettyMany sep '[singleOne] = singleOne
PrettyMany sep (next ': rest) = next <++> sep <++> PrettyMany sep rest
type family PrettyOften (n :: Nat) (doc :: PrettyType) :: PrettyType where
PrettyOften 0 doc = 'PrettyEmpty
PrettyOften n doc = doc <++> PrettyOften (n-1) doc
type instance ToPretty (Tagged s b) = ToPretty b <+> PrettyParens (ToPretty s)
data PrettyType where
PrettyEmpty :: PrettyType
PrettySpace :: PrettyType
PrettyNewline :: PrettyType
PrettySymbol :: PrettyPadded -> PrettyPrecision -> Symbol -> PrettyType
PrettyNat :: PrettyPadded -> PrettyPrecision -> PrettyNatFormat -> Nat -> PrettyType
PrettyPrefix :: PrettyType -> PrettyType -> PrettyType
PrettyInfix :: PrettyType -> PrettyType -> PrettyType -> PrettyType
PrettySuffix :: PrettyType -> PrettyType -> PrettyType
PrettyIndent :: Nat -> PrettyType -> PrettyType
PrettyAlternative :: PrettyType -> PrettyType -> PrettyType
data PrettyPadded where
PrettyUnpadded :: PrettyPadded
PrettyPadded :: Nat -> PrettyPadded
data PrettyPrecision where
PrettyPrecise :: PrettyPrecision
PrettyPrecision :: Nat-> PrettyPrecision
data PrettyNatFormat =
PrettyHex
| PrettyHexU
| PrettyDec
| PrettyBit
type Prettifies t = Prettifier t -> Type
data Prettifier :: Type -> Type
type family PrettifyWith (f :: Prettifies k) (x :: k) :: PrettyType
data PrettyTitled (title :: PrettyType) (indentation :: Nat) :: Prettifies t
type instance PrettifyWith (PrettyTitled title indentation) body =
'PrettyInfix 'PrettyNewline title ('PrettyIndent indentation (ToPretty body))
class PrettyTypeShow (p :: PrettyType) where
ptShow :: proxy p -> PTM ()
ptHasContent :: proxy p -> PTM Bool
ptHasContent proxy p
_ = Bool -> PTM Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True
type PTM a = RWS Indentation String PTRenderState a
writeIndented :: String -> PTM ()
writeIndented :: String -> RWS Indentation String PTRenderState ()
writeIndented String
s = do
PTRenderState
st <- RWST Indentation String PTRenderState Identity PTRenderState
forall s (m :: * -> *). MonadState s m => m s
get
case PTRenderState
st of
PTRenderState
AtBeginningOfLine -> do
Indentation
i <- RWST Indentation String PTRenderState Identity Indentation
forall r (m :: * -> *). MonadReader r m => m r
ask
String -> RWS Indentation String PTRenderState ()
forall w (m :: * -> *). MonadWriter w m => w -> m ()
Control.Monad.RWS.tell (Indentation -> Char -> String
forall a. Indentation -> a -> [a]
replicate Indentation
i Char
' ')
PTRenderState -> RWS Indentation String PTRenderState ()
forall s (m :: * -> *). MonadState s m => s -> m ()
put PTRenderState
AlreadyIndented
PTRenderState
AlreadyIndented -> () -> RWS Indentation String PTRenderState ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
String -> RWS Indentation String PTRenderState ()
forall w (m :: * -> *). MonadWriter w m => w -> m ()
Control.Monad.RWS.tell String
s
type Indentation = Int
data PTRenderState = AtBeginningOfLine | AlreadyIndented
instance PrettyTypeShow 'PrettyEmpty where
ptShow :: proxy 'PrettyEmpty -> RWS Indentation String PTRenderState ()
ptShow proxy 'PrettyEmpty
_ = () -> RWS Indentation String PTRenderState ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
ptHasContent :: proxy 'PrettyEmpty -> PTM Bool
ptHasContent proxy 'PrettyEmpty
_ = Bool -> PTM Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
instance PrettyTypeShow 'PrettySpace where
ptShow :: proxy 'PrettySpace -> RWS Indentation String PTRenderState ()
ptShow proxy 'PrettySpace
_ = String -> RWS Indentation String PTRenderState ()
writeIndented String
" "
instance PrettyTypeShow 'PrettyNewline where
ptShow :: proxy 'PrettyNewline -> RWS Indentation String PTRenderState ()
ptShow proxy 'PrettyNewline
_ = do
PTRenderState -> RWS Indentation String PTRenderState ()
forall s (m :: * -> *). MonadState s m => s -> m ()
put PTRenderState
AtBeginningOfLine
String -> RWS Indentation String PTRenderState ()
forall w (m :: * -> *). MonadWriter w m => w -> m ()
Control.Monad.RWS.tell String
"\n"
instance forall t pad prec . (KnownSymbol t, PrintfArgModifier pad, PrintfArgModifier prec) =>
PrettyTypeShow ('PrettySymbol pad prec t) where
ptShow :: proxy ('PrettySymbol pad prec t)
-> RWS Indentation String PTRenderState ()
ptShow proxy ('PrettySymbol pad prec t)
_ = String -> RWS Indentation String PTRenderState ()
writeIndented (String -> RWS Indentation String PTRenderState ())
-> String -> RWS Indentation String PTRenderState ()
forall a b. (a -> b) -> a -> b
$
String -> String -> String
forall r. PrintfType r => String -> r
printf (String
"%" String -> String -> String
forall a. [a] -> [a] -> [a]
++
Proxy pad -> String
forall k (a :: k) (p :: k -> *).
PrintfArgModifier a =>
p a -> String
toPrintfArgModifier (Proxy pad
forall k (t :: k). Proxy t
Proxy :: Proxy pad)
String -> String -> String
forall a. [a] -> [a] -> [a]
++ Proxy prec -> String
forall k (a :: k) (p :: k -> *).
PrintfArgModifier a =>
p a -> String
toPrintfArgModifier (Proxy prec
forall k (t :: k). Proxy t
Proxy :: Proxy prec)
String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"s")
(Proxy t -> String
forall (n :: Symbol) (proxy :: Symbol -> *).
KnownSymbol n =>
proxy n -> String
symbolVal (Proxy t
forall k (t :: k). Proxy t
Proxy :: Proxy t))
ptHasContent :: proxy ('PrettySymbol pad prec t) -> PTM Bool
ptHasContent proxy ('PrettySymbol pad prec t)
_ = Bool -> PTM Bool
forall (m :: * -> *) a. Monad m => a -> m a
return (Proxy t -> String
forall (n :: Symbol) (proxy :: Symbol -> *).
KnownSymbol n =>
proxy n -> String
symbolVal (Proxy t
forall k (t :: k). Proxy t
Proxy :: Proxy t) String -> String -> Bool
forall a. Eq a => a -> a -> Bool
/= String
"")
instance forall fmt x pad prec . (KnownNat x, PrintfArgModifier fmt, PrintfArgModifier pad, PrintfArgModifier prec) =>
PrettyTypeShow ('PrettyNat pad prec fmt x) where
ptShow :: proxy ('PrettyNat pad prec fmt x)
-> RWS Indentation String PTRenderState ()
ptShow proxy ('PrettyNat pad prec fmt x)
_ = String -> RWS Indentation String PTRenderState ()
writeIndented (String -> RWS Indentation String PTRenderState ())
-> String -> RWS Indentation String PTRenderState ()
forall a b. (a -> b) -> a -> b
$
String -> Integer -> String
forall r. PrintfType r => String -> r
printf (String
"%" String -> String -> String
forall a. [a] -> [a] -> [a]
++
Proxy pad -> String
forall k (a :: k) (p :: k -> *).
PrintfArgModifier a =>
p a -> String
toPrintfArgModifier (Proxy pad
forall k (t :: k). Proxy t
Proxy :: Proxy pad)
String -> String -> String
forall a. [a] -> [a] -> [a]
++ Proxy prec -> String
forall k (a :: k) (p :: k -> *).
PrintfArgModifier a =>
p a -> String
toPrintfArgModifier (Proxy prec
forall k (t :: k). Proxy t
Proxy :: Proxy prec)
String -> String -> String
forall a. [a] -> [a] -> [a]
++ Proxy fmt -> String
forall k (a :: k) (p :: k -> *).
PrintfArgModifier a =>
p a -> String
toPrintfArgModifier (Proxy fmt
forall k (t :: k). Proxy t
Proxy :: Proxy fmt))
(Proxy x -> Integer
forall (n :: Nat) (proxy :: Nat -> *).
KnownNat n =>
proxy n -> Integer
natVal (Proxy x
forall k (t :: k). Proxy t
Proxy :: Proxy x))
instance forall l r sep . (PrettyTypeShow sep, PrettyTypeShow l, PrettyTypeShow r) =>
PrettyTypeShow ('PrettyInfix sep l r) where
ptShow :: proxy ('PrettyInfix sep l r)
-> RWS Indentation String PTRenderState ()
ptShow proxy ('PrettyInfix sep l r)
_ = do
Bool
leftHasContent <- Proxy l -> PTM Bool
forall (p :: PrettyType) (proxy :: PrettyType -> *).
PrettyTypeShow p =>
proxy p -> PTM Bool
ptHasContent (Proxy l
forall k (t :: k). Proxy t
Proxy :: Proxy l)
Bool
rightHasContent <- Proxy r -> PTM Bool
forall (p :: PrettyType) (proxy :: PrettyType -> *).
PrettyTypeShow p =>
proxy p -> PTM Bool
ptHasContent (Proxy r
forall k (t :: k). Proxy t
Proxy :: Proxy r)
Bool
-> RWS Indentation String PTRenderState ()
-> RWS Indentation String PTRenderState ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
leftHasContent (Proxy l -> RWS Indentation String PTRenderState ()
forall (p :: PrettyType) (proxy :: PrettyType -> *).
PrettyTypeShow p =>
proxy p -> RWS Indentation String PTRenderState ()
ptShow (Proxy l
forall k (t :: k). Proxy t
Proxy :: Proxy l))
Bool
-> RWS Indentation String PTRenderState ()
-> RWS Indentation String PTRenderState ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Bool
leftHasContent Bool -> Bool -> Bool
&& Bool
rightHasContent) (Proxy sep -> RWS Indentation String PTRenderState ()
forall (p :: PrettyType) (proxy :: PrettyType -> *).
PrettyTypeShow p =>
proxy p -> RWS Indentation String PTRenderState ()
ptShow (Proxy sep
forall k (t :: k). Proxy t
Proxy :: Proxy sep))
Bool
-> RWS Indentation String PTRenderState ()
-> RWS Indentation String PTRenderState ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
rightHasContent (Proxy r -> RWS Indentation String PTRenderState ()
forall (p :: PrettyType) (proxy :: PrettyType -> *).
PrettyTypeShow p =>
proxy p -> RWS Indentation String PTRenderState ()
ptShow (Proxy r
forall k (t :: k). Proxy t
Proxy :: Proxy r))
ptHasContent :: proxy ('PrettyInfix sep l r) -> PTM Bool
ptHasContent proxy ('PrettyInfix sep l r)
_ =
Bool -> Bool -> Bool
(||) (Bool -> Bool -> Bool)
-> PTM Bool
-> RWST Indentation String PTRenderState Identity (Bool -> Bool)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Proxy l -> PTM Bool
forall (p :: PrettyType) (proxy :: PrettyType -> *).
PrettyTypeShow p =>
proxy p -> PTM Bool
ptHasContent (Proxy l
forall k (t :: k). Proxy t
Proxy :: Proxy l)
RWST Indentation String PTRenderState Identity (Bool -> Bool)
-> PTM Bool -> PTM Bool
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Proxy r -> PTM Bool
forall (p :: PrettyType) (proxy :: PrettyType -> *).
PrettyTypeShow p =>
proxy p -> PTM Bool
ptHasContent (Proxy r
forall k (t :: k). Proxy t
Proxy :: Proxy r)
instance forall x sep . (PrettyTypeShow sep, PrettyTypeShow x) =>
PrettyTypeShow ('PrettyPrefix sep x) where
ptShow :: proxy ('PrettyPrefix sep x)
-> RWS Indentation String PTRenderState ()
ptShow proxy ('PrettyPrefix sep x)
_ = do
Bool
hasContent <- Proxy x -> PTM Bool
forall (p :: PrettyType) (proxy :: PrettyType -> *).
PrettyTypeShow p =>
proxy p -> PTM Bool
ptHasContent (Proxy x
forall k (t :: k). Proxy t
Proxy :: Proxy x)
Bool
-> RWS Indentation String PTRenderState ()
-> RWS Indentation String PTRenderState ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
hasContent (RWS Indentation String PTRenderState ()
-> RWS Indentation String PTRenderState ())
-> RWS Indentation String PTRenderState ()
-> RWS Indentation String PTRenderState ()
forall a b. (a -> b) -> a -> b
$ do
Proxy sep -> RWS Indentation String PTRenderState ()
forall (p :: PrettyType) (proxy :: PrettyType -> *).
PrettyTypeShow p =>
proxy p -> RWS Indentation String PTRenderState ()
ptShow (Proxy sep
forall k (t :: k). Proxy t
Proxy :: Proxy sep)
Proxy x -> RWS Indentation String PTRenderState ()
forall (p :: PrettyType) (proxy :: PrettyType -> *).
PrettyTypeShow p =>
proxy p -> RWS Indentation String PTRenderState ()
ptShow (Proxy x
forall k (t :: k). Proxy t
Proxy :: Proxy x)
ptHasContent :: proxy ('PrettyPrefix sep x) -> PTM Bool
ptHasContent proxy ('PrettyPrefix sep x)
_ = Proxy x -> PTM Bool
forall (p :: PrettyType) (proxy :: PrettyType -> *).
PrettyTypeShow p =>
proxy p -> PTM Bool
ptHasContent (Proxy x
forall k (t :: k). Proxy t
Proxy :: Proxy x)
instance forall x sep . (PrettyTypeShow sep, PrettyTypeShow x) =>
PrettyTypeShow ('PrettySuffix sep x) where
ptShow :: proxy ('PrettySuffix sep x)
-> RWS Indentation String PTRenderState ()
ptShow proxy ('PrettySuffix sep x)
_ = do
Bool
hasContent <- Proxy x -> PTM Bool
forall (p :: PrettyType) (proxy :: PrettyType -> *).
PrettyTypeShow p =>
proxy p -> PTM Bool
ptHasContent (Proxy x
forall k (t :: k). Proxy t
Proxy :: Proxy x)
Bool
-> RWS Indentation String PTRenderState ()
-> RWS Indentation String PTRenderState ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
hasContent (RWS Indentation String PTRenderState ()
-> RWS Indentation String PTRenderState ())
-> RWS Indentation String PTRenderState ()
-> RWS Indentation String PTRenderState ()
forall a b. (a -> b) -> a -> b
$ do
Proxy x -> RWS Indentation String PTRenderState ()
forall (p :: PrettyType) (proxy :: PrettyType -> *).
PrettyTypeShow p =>
proxy p -> RWS Indentation String PTRenderState ()
ptShow (Proxy x
forall k (t :: k). Proxy t
Proxy :: Proxy x)
Proxy sep -> RWS Indentation String PTRenderState ()
forall (p :: PrettyType) (proxy :: PrettyType -> *).
PrettyTypeShow p =>
proxy p -> RWS Indentation String PTRenderState ()
ptShow (Proxy sep
forall k (t :: k). Proxy t
Proxy :: Proxy sep)
ptHasContent :: proxy ('PrettySuffix sep x) -> PTM Bool
ptHasContent proxy ('PrettySuffix sep x)
_ = Proxy x -> PTM Bool
forall (p :: PrettyType) (proxy :: PrettyType -> *).
PrettyTypeShow p =>
proxy p -> PTM Bool
ptHasContent (Proxy x
forall k (t :: k). Proxy t
Proxy :: Proxy x)
instance forall l r . (PrettyTypeShow l, PrettyTypeShow r) =>
PrettyTypeShow ('PrettyAlternative l r) where
ptShow :: proxy ('PrettyAlternative l r)
-> RWS Indentation String PTRenderState ()
ptShow proxy ('PrettyAlternative l r)
_ = do
Bool
leftHasContent <- Proxy l -> PTM Bool
forall (p :: PrettyType) (proxy :: PrettyType -> *).
PrettyTypeShow p =>
proxy p -> PTM Bool
ptHasContent (Proxy l
forall k (t :: k). Proxy t
Proxy :: Proxy l)
if Bool
leftHasContent
then Proxy l -> RWS Indentation String PTRenderState ()
forall (p :: PrettyType) (proxy :: PrettyType -> *).
PrettyTypeShow p =>
proxy p -> RWS Indentation String PTRenderState ()
ptShow (Proxy l
forall k (t :: k). Proxy t
Proxy :: Proxy l)
else Proxy r -> RWS Indentation String PTRenderState ()
forall (p :: PrettyType) (proxy :: PrettyType -> *).
PrettyTypeShow p =>
proxy p -> RWS Indentation String PTRenderState ()
ptShow (Proxy r
forall k (t :: k). Proxy t
Proxy :: Proxy r)
ptHasContent :: proxy ('PrettyAlternative l r) -> PTM Bool
ptHasContent proxy ('PrettyAlternative l r)
_ =
Bool -> Bool -> Bool
(||) (Bool -> Bool -> Bool)
-> PTM Bool
-> RWST Indentation String PTRenderState Identity (Bool -> Bool)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Proxy l -> PTM Bool
forall (p :: PrettyType) (proxy :: PrettyType -> *).
PrettyTypeShow p =>
proxy p -> PTM Bool
ptHasContent (Proxy l
forall k (t :: k). Proxy t
Proxy :: Proxy l)
RWST Indentation String PTRenderState Identity (Bool -> Bool)
-> PTM Bool -> PTM Bool
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Proxy r -> PTM Bool
forall (p :: PrettyType) (proxy :: PrettyType -> *).
PrettyTypeShow p =>
proxy p -> PTM Bool
ptHasContent (Proxy r
forall k (t :: k). Proxy t
Proxy :: Proxy r)
instance forall n r . (PrettyTypeShow r, KnownNat n) =>
PrettyTypeShow ('PrettyIndent n r) where
ptShow :: proxy ('PrettyIndent n r)
-> RWS Indentation String PTRenderState ()
ptShow proxy ('PrettyIndent n r)
_ = (Indentation -> Indentation)
-> RWS Indentation String PTRenderState ()
-> RWS Indentation String PTRenderState ()
forall r (m :: * -> *) a. MonadReader r m => (r -> r) -> m a -> m a
local (Indentation -> Indentation -> Indentation
forall a. Num a => a -> a -> a
+ (Integer -> Indentation
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Proxy n -> Integer
forall (n :: Nat) (proxy :: Nat -> *).
KnownNat n =>
proxy n -> Integer
natVal (Proxy n
forall k (t :: k). Proxy t
Proxy :: Proxy n))))
(Proxy r -> RWS Indentation String PTRenderState ()
forall (p :: PrettyType) (proxy :: PrettyType -> *).
PrettyTypeShow p =>
proxy p -> RWS Indentation String PTRenderState ()
ptShow (Proxy r
forall k (t :: k). Proxy t
Proxy :: Proxy r))
ptHasContent :: proxy ('PrettyIndent n r) -> PTM Bool
ptHasContent proxy ('PrettyIndent n r)
_ = Proxy r -> PTM Bool
forall (p :: PrettyType) (proxy :: PrettyType -> *).
PrettyTypeShow p =>
proxy p -> PTM Bool
ptHasContent (Proxy r
forall k (t :: k). Proxy t
Proxy :: Proxy r)
class PrintfArgModifier a where
toPrintfArgModifier :: p a -> String
instance PrintfArgModifier 'PrettyHex where toPrintfArgModifier :: p 'PrettyHex -> String
toPrintfArgModifier p 'PrettyHex
_ = String
"x"
instance PrintfArgModifier 'PrettyHexU where toPrintfArgModifier :: p 'PrettyHexU -> String
toPrintfArgModifier p 'PrettyHexU
_ = String
"X"
instance PrintfArgModifier 'PrettyDec where toPrintfArgModifier :: p 'PrettyDec -> String
toPrintfArgModifier p 'PrettyDec
_ = String
"d"
instance PrintfArgModifier 'PrettyBit where toPrintfArgModifier :: p 'PrettyBit -> String
toPrintfArgModifier p 'PrettyBit
_ = String
"b"
instance PrintfArgModifier 'PrettyUnpadded where toPrintfArgModifier :: p 'PrettyUnpadded -> String
toPrintfArgModifier p 'PrettyUnpadded
_ = String
""
instance forall p. KnownNat p => PrintfArgModifier ('PrettyPadded p) where
toPrintfArgModifier :: p ('PrettyPadded p) -> String
toPrintfArgModifier p ('PrettyPadded p)
_ = Integer -> String
forall a. Show a => a -> String
show (Proxy p -> Integer
forall (n :: Nat) (proxy :: Nat -> *).
KnownNat n =>
proxy n -> Integer
natVal (Proxy p
forall k (t :: k). Proxy t
Proxy :: Proxy p))
instance PrintfArgModifier 'PrettyPrecise where toPrintfArgModifier :: p 'PrettyPrecise -> String
toPrintfArgModifier p 'PrettyPrecise
_ = String
""
instance forall p. KnownNat p => PrintfArgModifier ('PrettyPrecision p) where
toPrintfArgModifier :: p ('PrettyPrecision p) -> String
toPrintfArgModifier p ('PrettyPrecision p)
_ = String
"." String -> String -> String
forall a. [a] -> [a] -> [a]
++ Integer -> String
forall a. Show a => a -> String
show (Proxy p -> Integer
forall (n :: Nat) (proxy :: Nat -> *).
KnownNat n =>
proxy n -> Integer
natVal (Proxy p
forall k (t :: k). Proxy t
Proxy :: Proxy p))