pretty-types-0.4.0.0: A small pretty printing DSL for complex types.
Safe HaskellNone
LanguageHaskell2010

Data.Type.Pretty

Description

Type Pretty Printing

Printing Custom Types

The main usecase of this library is rendering one's own complex types to pretty String values, e.g. for debugging and tracing purposes.

One way to create PrettyType documents is to define ToPretty instances for your types by combining the promoted constructors of PrettyType.

If UndecidableInstances isn't holding you back, use the type aliases like PutStr, PutNat, PrettyInfix, etc in these instance definitions.

ToPretty is an open type family, that converts a custom type to a PrettyType.

showPretty eventually crafts a String value from a proxy to the custom type.

It might be helpful to overcome egoistic needs for guaranteed compiler termination (i.e. allowing UndecidableInstances) in order to be able to use type aliases like PutStr, PutNat, etc.

Example

Let's start with the output:

+-------+-----+------------+
|  col 1|col 2|       col 3|
+-------+-----+------------+
|   2423|  451|       21234|
| 242322|   42|         n/a|
|      0| 4351|      623562|
|   4351|  n/a|         n/a|
|      0| 4351|      623562|
+-------+-----+------------+

... of rendering this table:

type TestTable =
  'MyTable         '[MyCol "col 1" 7, MyCol "col 2" 5, MyCol "col 3" 12]
          '[ MyRow '[2423           ,451             ,21234]
           , MyRow '[242322         ,42]
           , MyRow '[0              ,4351            ,623562]
           , MyRow '[4351]
           , MyRow '[0              ,4351            ,623562]
           ]

...using this function:

prettyTestTable :: String
prettyTestTable = showPretty (Proxy :: Proxy TestTable)

...from these data types:

-- | A type with a list of columns and rows.
data MyTable = MyTable [Type] [Type]

-- | A row of a table, with a list of numbers, one each for every column.
data MyRow :: [Nat] -> Type

-- | The column of a table. It has a width and a column title.
data MyCol :: Symbol -> Nat -> Type

...converted to PrettyType using this ToPretty instance:

type instance ToPretty ('MyTable cols rows) =
           PrettyManyIn (PutStr "+") (RowSepLine cols)
      <$$> PrettyManyIn (PutStr "|") (TableHeading cols)
      <$$> PrettyManyIn (PutStr "+") (RowSepLine cols)
      <$$> PrettyHigh   (TableRows cols rows)
      <$$> PrettyManyIn (PutStr "+") (RowSepLine cols)

type family
  TableHeading (cols :: [Type]) :: [PrettyType] where
  TableHeading '[]                      = '[]
  TableHeading (MyCol title width ': r) = PutStrW width title  ': TableHeading  r

type family
   RowSepLine (cols :: [Type]) :: [PrettyType] where
   RowSepLine '[] = '[]
   RowSepLine (MyCol title width ': r) =
     PrettyOften width (PutStr "-") ': RowSepLine  r

type family
  TableRows (cols :: [Type]) (rows :: [Type]) :: [PrettyType] where
  TableRows cols '[] = '[]
  TableRows cols (MyRow cells ': rest ) =
    PrettyManyIn (PutStr "|") (TableCells cols cells) ': TableRows cols rest

type family
  TableCells (cols :: [Type]) (cells :: [Nat]) :: [PrettyType] where
  TableCells '[] cells = '[]
  TableCells (MyCol title width ': cols) (value ': cells) =
    PutNatW width value ':  TableCells cols cells
  TableCells (MyCol title width ': cols) '[] =
    PutStrW width "n/a" ':  TableCells cols '[]
Synopsis

Pretty Printing Types

showPretty Source #

Arguments

:: forall k proxy (t :: k). PrettyTypeShow (ToPretty t) 
=> proxy t

A proxy to the type to print. A ToPretty instance for t must exists.

-> String 

Pretty print either types of kind PrettyType or any other type with a ToPretty instance.

type family ToPretty (a :: k) :: PrettyType Source #

Create a PrettyType from a type.

This is a type-level equivalent of the Show class.

Write an instance of this for converting your type (preferrable of your kind also) to a promoted PrettyType.

Instances

Instances details
type ToPretty 'False Source #

Render False as PutStr "'False"

Since: 0.2.1.0

Instance details

Defined in Data.Type.Pretty

type ToPretty 'False = PutStr "'False"
type ToPretty 'True Source #

Render True as PutStr "'True"

Since: 0.2.1.0

Instance details

Defined in Data.Type.Pretty

type ToPretty 'True = PutStr "'True"
type ToPretty (t :: Nat) Source #

A type of kind Nat is translated to PutNat.

Since: 0.2.1.0

Instance details

Defined in Data.Type.Pretty

type ToPretty (t :: Nat) = PutNat t
type ToPretty (t :: Symbol) Source #

A type of kind Symbol is translated to PutStr.

Since: 0.2.1.0

Instance details

Defined in Data.Type.Pretty

type ToPretty (t :: Symbol) = PutStr t
type ToPretty (t :: PrettyType) Source #

A type of kind PrettyType has a trivial id-likeToPretty instance.

Instance details

Defined in Data.Type.Pretty

type ToPretty (t :: PrettyType) = t
type ToPretty (t :: Maybe x) Source #

Render a type of kind Maybe.

Since: 0.2.1.0

Instance details

Defined in Data.Type.Pretty

type ToPretty (t :: Maybe x) = ToPrettyMaybe t
type ToPretty Bool Source #

Render Bool as PutStr Bool

Since: 0.2.1.0

Instance details

Defined in Data.Type.Pretty

type ToPretty Bool = PutStr "Bool"
type ToPretty Double Source #

Render Double as PutStr Double

Since: 0.2.1.0

Instance details

Defined in Data.Type.Pretty

type ToPretty Double = PutStr "Double"
type ToPretty Float Source #

Render Float as PutStr Float

Since: 0.2.1.0

Instance details

Defined in Data.Type.Pretty

type ToPretty Float = PutStr "Float"
type ToPretty Int Source #

Render Int as PutStr Int

Since: 0.2.1.0

Instance details

Defined in Data.Type.Pretty

type ToPretty Int = PutStr "Int"
type ToPretty Int8 Source #

Render Int8 as PutStr Int8

Since: 0.2.1.0

Instance details

Defined in Data.Type.Pretty

type ToPretty Int8 = PutStr "Int8"
type ToPretty Int16 Source #

Render Int16 as PutStr Int16

Since: 0.2.1.0

Instance details

Defined in Data.Type.Pretty

type ToPretty Int16 = PutStr "Int16"
type ToPretty Int32 Source #

Render Int32 as PutStr Int32

Since: 0.2.1.0

Instance details

Defined in Data.Type.Pretty

type ToPretty Int32 = PutStr "Int32"
type ToPretty Int64 Source #

Render Int64 as PutStr Int64

Since: 0.2.1.0

Instance details

Defined in Data.Type.Pretty

type ToPretty Int64 = PutStr "Int64"
type ToPretty Integer Source #

Render Integer as PutStr Integer

Since: 0.2.1.0

Instance details

Defined in Data.Type.Pretty

type ToPretty Integer = PutStr "Integer"
type ToPretty Word8 Source #

Render Word8 as PutStr Word8

Since: 0.2.1.0

Instance details

Defined in Data.Type.Pretty

type ToPretty Word8 = PutStr "Word8"
type ToPretty Word16 Source #

Render Word16 as PutStr Word16

Since: 0.2.1.0

Instance details

Defined in Data.Type.Pretty

type ToPretty Word16 = PutStr "Word16"
type ToPretty Word32 Source #

Render Word32 as PutStr Word32

Since: 0.2.1.0

Instance details

Defined in Data.Type.Pretty

type ToPretty Word32 = PutStr "Word32"
type ToPretty Word64 Source #

Render Word64 as PutStr Word64

Since: 0.2.1.0

Instance details

Defined in Data.Type.Pretty

type ToPretty Word64 = PutStr "Word64"
type ToPretty (Tagged s b :: Type) Source #

Pretty print a Tagged value.

Since: 0.2.2.0

Instance details

Defined in Data.Type.Pretty

ToPretty instances for uninhabited types

type family ToPrettyMaybe (t :: Maybe x) :: PrettyType where ... Source #

Render a type of kind Maybe.

Since: 0.2.1.0

ToPretty instances for inhabited types

Pretty Printing

Pretty Printing Strings (Symbol)

type PutStrW width str = 'PrettySymbol ('PrettyPadded width) ('PrettyPrecision width) str Source #

A PrettyType for a string with the exact given width.

type PutStrLn str = PutStr str <++> PutStr "\n" Source #

A PrettyType for a string with a newline character at the end.

Pretty Printing Numbers (Nat)

type PutNatW width x = 'PrettyNat ('PrettyPadded width) 'PrettyPrecise 'PrettyDec x Source #

A PrettyType for a number with a width.

type PutHex x = 'PrettyNat 'PrettyUnpadded 'PrettyPrecise 'PrettyHex x Source #

Create PrettyType from a Nat formatted as hex number using lower-case letters for the hex digits.

type PutHex8 x = 'PrettyNat 'PrettyUnpadded ('PrettyPrecision 2) 'PrettyHex x Source #

Create PrettyType from a Nat formatted as 8 bit hex number using lower-case letters for the hex digits.

type PutHex16 x = 'PrettyNat 'PrettyUnpadded ('PrettyPrecision 4) 'PrettyHex x Source #

Create PrettyType from a Nat formatted as 16 bit hex number using lower-case letters for the hex digits.

type PutHex32 x = 'PrettyNat 'PrettyUnpadded ('PrettyPrecision 8) 'PrettyHex x Source #

Create PrettyType from a Nat formatted as 32 bit hex number using lower-case letters for the hex digits.

type PutHex64 x = 'PrettyNat 'PrettyUnpadded ('PrettyPrecision 16) 'PrettyHex x Source #

Create PrettyType from a Nat formatted as 64 bit hex number using lower-case letters for the hex digits.

type PutHeX x = 'PrettyNat 'PrettyUnpadded 'PrettyPrecise 'PrettyHexU x Source #

Create PrettyType from a Nat formatted as hex number using lower-case letters for the hex digits.

type PutHeX8 x = 'PrettyNat 'PrettyUnpadded ('PrettyPrecision 2) 'PrettyHexU x Source #

Create PrettyType from a Nat formatted as 8 bit hex number using uppercase letters for the hex digits.

type PutHeX16 x = 'PrettyNat 'PrettyUnpadded ('PrettyPrecision 4) 'PrettyHexU x Source #

Create PrettyType from a Nat formatted as 16 bit hex number using uppercase letters for the hex digits.

type PutHeX32 x = 'PrettyNat 'PrettyUnpadded ('PrettyPrecision 8) 'PrettyHexU x Source #

Create PrettyType from a Nat formatted as 32 bit hex number using uppercase letters for the hex digits.

type PutHeX64 x = 'PrettyNat 'PrettyUnpadded ('PrettyPrecision 16) 'PrettyHexU x Source #

Create PrettyType from a Nat formatted as 64 bit hex number using uppercase letters for the hex digits.

type PutBits x = 'PrettyNat 'PrettyUnpadded 'PrettyPrecise 'PrettyBit x Source #

Create PrettyType from a Nat formatted as bit representation,

>>> showPretty (Proxy :: Proxy (PutBits 5))
"101"

type PutBits8 x = 'PrettyNat 'PrettyUnpadded ('PrettyPrecision 8) 'PrettyBit x Source #

Create PrettyType from a Nat formatted as 8-bit bit representation,

>>> showPretty (Proxy :: Proxy (PutBits8 5))
"00000101"

type PutBits16 x = 'PrettyNat 'PrettyUnpadded ('PrettyPrecision 16) 'PrettyBit x Source #

Create PrettyType from a Nat formatted as 16-bit bit representation,

>>> showPretty (Proxy :: Proxy (PutBits16 5))
"00000000000000101"

type PutBits32 x = 'PrettyNat 'PrettyUnpadded ('PrettyPrecision 32) 'PrettyBit x Source #

Create PrettyType from a Nat formatted as 32-bit bit representation,

>>> showPretty (Proxy :: Proxy (PutBits32 5))
"00000000000000000000000000000000101"

type PutBits64 x = 'PrettyNat 'PrettyUnpadded ('PrettyPrecision 64) 'PrettyBit x Source #

Create PrettyType from a Nat formatted as 64-bit bit representation,

>>> showPretty (Proxy :: Proxy (PutBits64 5))
"00000000000000000000000000000000000000000000000000000000000000000000101"

Composing Pretty Printers

type (<:>) label body = 'PrettySuffix (PutStr ":") (PutStr label) <+> body infixl 5 Source #

A label followed by a colon and space : followed by another element.

>>> showPretty (Proxy :: Proxy ("foo" <:> PutStr "bar"))
@
foo: bar
@

Since: 0.2.0.0

type (<:$$>) label body = 'PrettySuffix (PutStr ":") (PutStr label) <$$> body infixl 5 Source #

Like <:> but begin the body on a new line.

>>> showPretty (Proxy :: Proxy (PutStr "foo" <:$$> PutStr "bar"))
@
foo:
bar
@

Since: 0.2.0.0

type (<:$$-->) label body = 'PrettySuffix (PutStr ":") (PutStr label) <$$--> body infixl 3 Source #

Like ':$$__' but indent the body with two spaces.

>>> showPretty (Proxy :: Proxy (PutStr "foo" <:$$--> PutStr "bar"))
@
foo:
  bar
@

Since: 0.2.0.0

type (<++>) l r = 'PrettyInfix 'PrettyEmpty l r infixl 6 Source #

Concatenate two PrettyType.

type (<+>) l r = 'PrettyInfix 'PrettySpace l r infixl 5 Source #

Concatenate two PrettyType using a PrettySpace.

type (<||>) l r = 'PrettyAlternative l r infixl 5 Source #

Choose the first non-empty from two PrettyTypes.

Since: 0.2.0.0

type (<$$>) l r = 'PrettyInfix 'PrettyNewline l r infixl 4 Source #

Concatenate two PrettyType using a PrettyNewline.

type (<$$-->) l r = 'PrettyInfix 'PrettyNewline l ('PrettyIndent 2 r) infixl 3 Source #

Concatenate two PrettyType using a PrettyNewline and indent the second.

Since: 0.2.0.0

type PrettyParens doc = PrettySurrounded (PutStr "(") (PutStr ")") doc Source #

Surround a pretty with parens

type PrettySurrounded open close doc = (open <++> doc) <++> close Source #

Surround a pretty with some pretties

Pretty Printing Lists

type PrettyWide docs = PrettyMany 'PrettySpace docs Source #

Combine a (type level) list of PrettyTypes next to each other using PrettySpace

type PrettyHigh docs = PrettyMany 'PrettyNewline docs Source #

Combine a (type level) list of PrettyTypes below each other using PrettyNewline

type PrettyManyIn sep docs = PrettySurrounded sep sep (PrettyMany sep docs) Source #

A combination of PrettySpace and PrettyMany, e.g.:

>>> showPretty (Proxy :: Proxy (PrettyManyIn (PutStr "|") '[PutStr "a", PutStr "b"]))
"|a|b|"

type family PrettyMany (sep :: PrettyType) (docs :: [PrettyType]) :: PrettyType where ... Source #

Combine a (type level) list of PrettyTypes seperated by a seperation element.

Equations

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 ... Source #

Repeat a PrettyType n-times and append the copies.

Equations

PrettyOften 0 doc = 'PrettyEmpty 
PrettyOften n doc = doc <++> PrettyOften (n - 1) doc 

Pretty Printing Tagged Values

Basic Building Blocks

data PrettyType where Source #

Combinators for type documents.

The basis for pretty printing is this eDSL. It is rendered via the PrettyTypeShow instances for its promoted constructors.

Only the promoted constructors are used, only they have instances for that class.

Constructors

PrettyEmpty :: PrettyType 
PrettySpace :: PrettyType 
PrettyNewline :: PrettyType

Begin a newline. Always use this otherwise indentation will not work!

PrettySymbol :: PrettyPadded -> PrettyPrecision -> Symbol -> PrettyType 
PrettyNat :: PrettyPadded -> PrettyPrecision -> PrettyNatFormat -> Nat -> PrettyType 
PrettyPrefix :: PrettyType -> PrettyType -> PrettyType

Prefix the second with the first argument, but only if it (the second) has content.

Since: 0.2.0.0

PrettyInfix :: PrettyType -> PrettyType -> PrettyType -> PrettyType

Combine the last to arguments with the first in between them, but only if both have content.

PrettySuffix :: PrettyType -> PrettyType -> PrettyType

Add a the first argument as suffix to the second argument, but only if the second has content.

Since: 0.2.0.0

PrettyIndent :: Nat -> PrettyType -> PrettyType

Indentation. Prefix any line using the given number of PrettySpace.

Since: 0.2.0.0

PrettyAlternative :: PrettyType -> PrettyType -> PrettyType

Alternative rendering, if the first document ist empty the second will be rendered.

Since: 0.2.0.0

Instances

Instances details
type ToPretty (t :: PrettyType) Source #

A type of kind PrettyType has a trivial id-likeToPretty instance.

Instance details

Defined in Data.Type.Pretty

type ToPretty (t :: PrettyType) = t

data PrettyPadded where Source #

Constructors

PrettyUnpadded :: PrettyPadded

No minimum or fixed width

PrettyPadded :: Nat -> PrettyPadded

Pad a PrettySymbol or PrettyNat with spaces or zeros. NOTE PrettyNats will never be shorter than the minimum number of digits, regardless of this padding.

Instances

Instances details
PrintfArgModifier 'PrettyUnpadded Source #

Translation of PrettyUnpadded to an empty modifier string

Instance details

Defined in Data.Type.Pretty

KnownNat p => PrintfArgModifier ('PrettyPadded p :: PrettyPadded) Source #

Translation of PrettyPadded to a string with the numeric padding value.

Instance details

Defined in Data.Type.Pretty

data PrettyPrecision where Source #

The precision for PrettySymbol and PrettyNat.

Constructors

PrettyPrecise :: PrettyPrecision

No minimum precision.

PrettyPrecision :: Nat -> PrettyPrecision

Precision, for Symbols the maximum width, for Nats the minimum digits. NOTEPrettyNats will never be shorter than the minimum number of digits, wheres PrettySymbols will be truncated if they are longer than the precision.

Instances

Instances details
PrintfArgModifier 'PrettyPrecise Source #

Translation of PrettyPrecise to an empty modifier string

Instance details

Defined in Data.Type.Pretty

KnownNat p => PrintfArgModifier ('PrettyPrecision p :: PrettyPrecision) Source #

Translation of PrettyPadded to a string with the numeric precision value, prependen by a dot ".".

Instance details

Defined in Data.Type.Pretty

data PrettyNatFormat Source #

PrettyNat formatting options.

Constructors

PrettyHex

Hexa decimal rendering:

>>> showPretty (Proxy::Proxy (PrettyNat PrettyUnpadded PrettyPrecise PrettyHex 51966))
"cafe"
PrettyHexU

Hexa decimal rendering (upper case):

>>> showPretty (Proxy::Proxy (PrettyNat PrettyUnpadded PrettyPrecise PrettyHexU 51966))
"CAFE"
PrettyDec

Decimal rendering:

>>> showPretty (Proxy::Proxy (PrettyNat PrettyUnpadded PrettyPrecise PrettyHexU 51966))
"51966"
PrettyBit

Binary rendering:

>>> showPretty (Proxy::Proxy (PrettyNat PrettyUnpadded PrettyPrecise PrettyHexU 51966))
"1100101011111110"

Instances

Instances details
PrintfArgModifier 'PrettyHex Source #

Translation of PrettyHex to printf format character: x

Instance details

Defined in Data.Type.Pretty

PrintfArgModifier 'PrettyHexU Source #

Translation of PrettyHexU to printf format character: X

Instance details

Defined in Data.Type.Pretty

PrintfArgModifier 'PrettyDec Source #

Translation of PrettyDec to printf format character: d

Instance details

Defined in Data.Type.Pretty

PrintfArgModifier 'PrettyBit Source #

Translation of PrettyBit to printf format character: b

Instance details

Defined in Data.Type.Pretty

PrettyType Functions

type Prettifies t = Prettifier t -> Type Source #

Kind of Prettifier data types.

The type that all data types share, such that they can be passed to PrettifyWith.

Sometimes it is desirable to pass around pretty-printing functions called Prettifier in this library. A Prettifier is a parameterized pretty-printer that accepts a parameter of a specific kind.

For example:

data PutStrIsh :: Prettifies Symbol

type instance PrettifyWith PutStrIsh str = PutStr str ++ PutStr "ish"
>>> showPretty (Proxy @(PrettifyWith PutStrIsh "That's pretty okay"))
"That's pretty okayish"

Since: 0.2.3.0

data Prettifier :: Type -> Type Source #

An abstract declaration of a pretty-printing (type-)function that takes a specific kind of types as parameter.

Since: 0.2.3.0

type family PrettifyWith (f :: Prettifies k) (x :: k) :: PrettyType Source #

Apply a Prettifier to a type in order to get a PrettyType

Since: 0.2.3.0

Instances

Instances details
type PrettifyWith (PrettyTitled title indentation :: Prettifier k -> Type) (body :: k) Source # 
Instance details

Defined in Data.Type.Pretty

type PrettifyWith (PrettyTitled title indentation :: Prettifier k -> Type) (body :: k) = 'PrettyInfix 'PrettyNewline title ('PrettyIndent indentation (ToPretty body))

Basic Prettifiers

data PrettyTitled (title :: PrettyType) (indentation :: Nat) :: Prettifies t Source #

Write a title and print the indented, ToPretty-fied body starting on the next line.

Since: 0.2.3.0

Instances

Instances details
type PrettifyWith (PrettyTitled title indentation :: Prettifier k -> Type) (body :: k) Source # 
Instance details

Defined in Data.Type.Pretty

type PrettifyWith (PrettyTitled title indentation :: Prettifier k -> Type) (body :: k) = 'PrettyInfix 'PrettyNewline title ('PrettyIndent indentation (ToPretty body))

Pretty Rendering

class PrettyTypeShow (p :: PrettyType) where Source #

An internal type class for rendering the types of kind PrettyType.

Minimal complete definition

ptShow

Methods

ptShow :: proxy p -> PTM () Source #

Given any proxy to a promoted constructor of PrettyType, generate a String.

ptHasContent :: proxy p -> PTM Bool Source #

Return True if contents would be writting to the output of rendered via ptShow

Since: 0.2.0.0

Instances

Instances details
PrettyTypeShow 'PrettyEmpty Source #

Print nothing.

Instance details

Defined in Data.Type.Pretty

Methods

ptShow :: proxy 'PrettyEmpty -> PTM () Source #

ptHasContent :: proxy 'PrettyEmpty -> PTM Bool Source #

PrettyTypeShow 'PrettySpace Source #

Print a single space character.

Instance details

Defined in Data.Type.Pretty

Methods

ptShow :: proxy 'PrettySpace -> PTM () Source #

ptHasContent :: proxy 'PrettySpace -> PTM Bool Source #

PrettyTypeShow 'PrettyNewline Source #

Print a single newline character.

Instance details

Defined in Data.Type.Pretty

(PrettyTypeShow sep, PrettyTypeShow x) => PrettyTypeShow ('PrettyPrefix sep x) Source #

Prefix a PrettyType to x, but only if ptHasContent of x holds.

Instance details

Defined in Data.Type.Pretty

Methods

ptShow :: proxy ('PrettyPrefix sep x) -> PTM () Source #

ptHasContent :: proxy ('PrettyPrefix sep x) -> PTM Bool Source #

(PrettyTypeShow sep, PrettyTypeShow x) => PrettyTypeShow ('PrettySuffix sep x) Source #

Add a PrettyType suffix to x, but only if ptHasContent holds.

Since: 0.2.0.0

Instance details

Defined in Data.Type.Pretty

Methods

ptShow :: proxy ('PrettySuffix sep x) -> PTM () Source #

ptHasContent :: proxy ('PrettySuffix sep x) -> PTM Bool Source #

(PrettyTypeShow r, KnownNat n) => PrettyTypeShow ('PrettyIndent n r) Source #

Render an indented, nested type.

Since: 0.2.0.0

Instance details

Defined in Data.Type.Pretty

Methods

ptShow :: proxy ('PrettyIndent n r) -> PTM () Source #

ptHasContent :: proxy ('PrettyIndent n r) -> PTM Bool Source #

(PrettyTypeShow l, PrettyTypeShow r) => PrettyTypeShow ('PrettyAlternative l r) Source #

Render the first document, and if it is empty, the second

Since: 0.2.0.0

Instance details

Defined in Data.Type.Pretty

Methods

ptShow :: proxy ('PrettyAlternative l r) -> PTM () Source #

ptHasContent :: proxy ('PrettyAlternative l r) -> PTM Bool Source #

(KnownSymbol t, PrintfArgModifier pad, PrintfArgModifier prec) => PrettyTypeShow ('PrettySymbol pad prec t) Source #

Print a Symbol using the printf and the given format parameters.

Instance details

Defined in Data.Type.Pretty

Methods

ptShow :: proxy ('PrettySymbol pad prec t) -> PTM () Source #

ptHasContent :: proxy ('PrettySymbol pad prec t) -> PTM Bool Source #

(PrettyTypeShow sep, PrettyTypeShow l, PrettyTypeShow r) => PrettyTypeShow ('PrettyInfix sep l r) Source #

Concatenate two PrettyTypes. If one of them is empty print the other without any seperation character.

Instance details

Defined in Data.Type.Pretty

Methods

ptShow :: proxy ('PrettyInfix sep l r) -> PTM () Source #

ptHasContent :: proxy ('PrettyInfix sep l r) -> PTM Bool Source #

(KnownNat x, PrintfArgModifier fmt, PrintfArgModifier pad, PrintfArgModifier prec) => PrettyTypeShow ('PrettyNat pad prec fmt x) Source #

Print a Nat using the printf and the given format parameters.

Instance details

Defined in Data.Type.Pretty

Methods

ptShow :: proxy ('PrettyNat pad prec fmt x) -> PTM () Source #

ptHasContent :: proxy ('PrettyNat pad prec fmt x) -> PTM Bool Source #

type PTM a = RWS Indentation String PTRenderState a Source #

The monad used by ptShow to keep track of indentation.

Since: 0.2.0.0

writeIndented :: String -> PTM () Source #

Internal; write a possibly indented string, and update the PTRenderState accordingly.

Since: 0.2.0.0

type Indentation = Int Source #

Internal type of the indentation used by ptShow in PTM

Since: 0.2.0.0

data PTRenderState Source #

Internal state used by ptShow in PTM

Since: 0.2.0.0

class PrintfArgModifier a where Source #

Internal printf format generation. Used internally by PrettyTypeShow instances to generate the format string piece by piece with the values for the instances of e.g. PrettyPrecise, PrettyNatFormat, or PrettyEmpty.

Methods

toPrintfArgModifier :: p a -> String Source #

Generate a piece of a printf format string from a proxy for a type.

Instances

Instances details
PrintfArgModifier 'PrettyHex Source #

Translation of PrettyHex to printf format character: x

Instance details

Defined in Data.Type.Pretty

PrintfArgModifier 'PrettyHexU Source #

Translation of PrettyHexU to printf format character: X

Instance details

Defined in Data.Type.Pretty

PrintfArgModifier 'PrettyDec Source #

Translation of PrettyDec to printf format character: d

Instance details

Defined in Data.Type.Pretty

PrintfArgModifier 'PrettyBit Source #

Translation of PrettyBit to printf format character: b

Instance details

Defined in Data.Type.Pretty

PrintfArgModifier 'PrettyPrecise Source #

Translation of PrettyPrecise to an empty modifier string

Instance details

Defined in Data.Type.Pretty

PrintfArgModifier 'PrettyUnpadded Source #

Translation of PrettyUnpadded to an empty modifier string

Instance details

Defined in Data.Type.Pretty

KnownNat p => PrintfArgModifier ('PrettyPrecision p :: PrettyPrecision) Source #

Translation of PrettyPadded to a string with the numeric precision value, prependen by a dot ".".

Instance details

Defined in Data.Type.Pretty

KnownNat p => PrintfArgModifier ('PrettyPadded p :: PrettyPadded) Source #

Translation of PrettyPadded to a string with the numeric padding value.

Instance details

Defined in Data.Type.Pretty