pretty-show-1.2: Tools for working with derived Show instances.

Portability | Haskell 98
Stability | provisional
Maintainer | iavor.diatchki@gmail.com
Safe Haskell | None

Text.Show.Pretty

Description

Functions for human-readable derived `Show` instances.

Synopsis

- type Name = String
- data Value
  - = Con Name [Value]
  - | Rec Name [(Name, Value)]
  - | Tuple [Value]
  - | List [Value]
  - | Neg Value
  - | Ratio Value Value
  - | Integer String
  - | Float String
  - | Char String
  - | String String
- parseValue :: String -> Maybe Value
- reify :: Show a => a -> Maybe Value
- ppValue :: Value -> Doc
- ppDoc :: Show a => a -> Doc
- ppShow :: Show a => a -> String

# Documentation

type Name = String Source

A name.

data Value Source

Generic Haskell values. `NaN` and `Infinity` are represented as constructors. The `String` in the literals is the text for the literals "as is".

Constructors

Con Name [Value] | Data constructor
Rec Name [(Name, Value)] | Record value
Tuple [Value] | Tuple
List [Value] | List
Neg Value | Negated value
Ratio Value Value | Rational
Integer String | Non-negative integer
Float String | Non-negative floating num.
Char String | Character
String String | String

Instances

Eq Value |
Show Value |

parseValue :: String -> Maybe Value Source

reify :: Show a => a -> Maybe Value Source

ppValue :: Value -> Doc Source

Pretty print a generic value. Our intention is that the result is equivalent to the `Show` instance for the original value, except possibly easier to understand by a human.

ppDoc :: Show a => a -> Doc Source

Try to show a value, prettily. If we do not understand the value, then we just use its standard `Show` instance.

ppShow :: Show a => a -> String Source

Convert a generic value into a pretty `String`, if possible.