Text.Show.Pretty

pretty-show-1.10: Tools for working with derived `Show` instances and generic inspection of values.

Copyright | (c) Iavor S. Diatchki 2009
License | MIT
Maintainer | iavor.diatchki@gmail.com
Stability | provisional
Portability | Haskell 98
Safe Haskell | Safe
Language | Haskell98

Text.Show.Pretty

Contents

- Generic representation of values
- Values using the `Show` class
- Working with listlike ("foldable") collections
- Values using the `PrettyVal` class
- Rendering values to Html
- Get location of data files
- Preprocessing of values
- Deprecated

Description

Functions for human-readable derived `Show` instances.

Synopsis

- data Value
  - = Con Name [Value]
  - | InfixCons Value [(Name, Value)]
  - | Rec Name [(Name, Value)]
  - | Tuple [Value]
  - | List [Value]
  - | Neg Value
  - | Ratio Value Value
  - | Integer String
  - | Float String
  - | Char String
  - | String String
  - | Date String
  - | Time String
  - | Quote String
- type Name = String
- valToStr :: Value -> String
- valToDoc :: Value -> Doc
- valToHtmlPage :: HtmlOpts -> Value -> String
- parseValue :: String -> Maybe Value
- reify :: Show a => a -> Maybe Value
- ppDoc :: Show a => a -> Doc
- ppShow :: Show a => a -> String
- pPrint :: Show a => a -> IO ()
- ppDocList :: (Foldable f, Show a) => f a -> Doc
- ppShowList :: (Foldable f, Show a) => f a -> String
- pPrintList :: (Foldable f, Show a) => f a -> IO ()
- dumpDoc :: PrettyVal a => a -> Doc
- dumpStr :: PrettyVal a => a -> String
- dumpIO :: PrettyVal a => a -> IO ()
- class PrettyVal a where
  - prettyVal :: a -> Value
- valToHtml :: HtmlOpts -> Value -> Html
- data HtmlOpts = HtmlOpts {
  - dataDir :: FilePath
  - wideListWidth :: Int
  }
- defaultHtmlOpts :: HtmlOpts
- htmlPage :: HtmlOpts -> Html -> String
- newtype Html = Html {
  - exportHtml :: String
  }
- getDataDir :: IO FilePath
- data PreProc a = PreProc (Value -> Value) a
- ppHide :: (Name -> Bool) -> a -> PreProc a
- ppHideNested :: (Name -> Bool) -> a -> PreProc a
- hideCon :: Bool -> (Name -> Bool) -> Value -> Value
- ppValue :: Value -> Doc

# Generic representation of values

data Value #

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

A chain of infix constructors means that they appeared in the input string without parentheses, i.e

`1 :+: 2 :*: 3` is represented with `InfixCons 1 [(":+:",2),(":*:",3)]`, whereas

`1 :+: (2 :*: 3)` is represented with `InfixCons 1 [(":+:",InfixCons 2 [(":*:",3)])]`.

Constructors

Con Name [Value] | Data constructor
InfixCons Value [(Name, Value)] | Infix data constructor chain
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
Date String | 01-02-2003
Time String | 08:30:21
Quote String | time|2003-02-01T08:30:21Z|

#### Instances

Instances details

Show Value # |
Instance details Defined in Text.Show.Value Methods showsPrec :: Int -> Value -> ShowS show :: Value -> String showList :: [Value] -> ShowS
Eq Value # |
Instance details Defined in Text.Show.Value Methods (==) :: Value -> Value -> Bool (/=) :: Value -> Value -> Bool

type Name = String #

A name.

valToStr :: Value -> String #

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.

valToDoc :: Value -> Doc #

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.

valToHtmlPage :: HtmlOpts -> Value -> String #

Make an Html page representing the given value.

# Values using the `Show` class

parseValue :: String -> Maybe Value #

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

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

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 #

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

pPrint :: Show a => a -> IO () #

Pretty print a generic value to stdout. This is particularly useful in the GHCi interactive environment.

# Working with listlike ("foldable") collections

ppDocList :: (Foldable f, Show a) => f a -> Doc #

Pretty print something that may be converted to a list as a list. Each entry is on a separate line, which means that we don't do clever pretty printing, and so this works well for large strucutures.

ppShowList :: (Foldable f, Show a) => f a -> String #

Pretty print something that may be converted to a list as a list. Each entry is on a separate line, which means that we don't do clever pretty printing, and so this works well for large strucutures.

pPrintList :: (Foldable f, Show a) => f a -> IO () #

Pretty print something that may be converted to a list as a list. Each entry is on a separate line, which means that we don't do clever pretty printing, and so this works well for large strucutures.

# Values using the `PrettyVal` class

dumpDoc :: PrettyVal a => a -> Doc #

Render a value in the `PrettyVal` class to a `Doc`. The benefit of this function is that `PrettyVal` instances may be derived automatically using generics.

dumpStr :: PrettyVal a => a -> String #

Render a value in the `PrettyVal` class to a `Value`. The benefit of this function is that `PrettyVal` instances may be derived automatically using generics.

dumpIO :: PrettyVal a => a -> IO () #

Render a value using the `PrettyVal` class and show it to standard out.

class PrettyVal a where #

A class for types that may be reified into a value. Instances of this class may be derived automatically, for datatypes that support `Generics`.

Minimal complete definition

Nothing

Methods

prettyVal :: a -> Value #

default prettyVal :: (GDump (Rep a), Generic a) => a -> Value #

#### Instances

Instances details

PrettyVal Int16 # |
Instance details Defined in Text.Show.PrettyVal Methods prettyVal :: Int16 -> Value # listValue :: [Int16] -> Value
PrettyVal Int32 # |
Instance details Defined in Text.Show.PrettyVal Methods prettyVal :: Int32 -> Value # listValue :: [Int32] -> Value
PrettyVal Int64 # |
Instance details Defined in Text.Show.PrettyVal Methods prettyVal :: Int64 -> Value # listValue :: [Int64] -> Value
PrettyVal Int8 # |
Instance details Defined in Text.Show.PrettyVal Methods prettyVal :: Int8 -> Value # listValue :: [Int8] -> Value
PrettyVal Word16 # |
Instance details Defined in Text.Show.PrettyVal Methods prettyVal :: Word16 -> Value # listValue :: [Word16] -> Value
PrettyVal Word32 # |
Instance details Defined in Text.Show.PrettyVal Methods prettyVal :: Word32 -> Value # listValue :: [Word32] -> Value
PrettyVal Word64 # |
Instance details Defined in Text.Show.PrettyVal Methods prettyVal :: Word64 -> Value # listValue :: [Word64] -> Value
PrettyVal Word8 # |
Instance details Defined in Text.Show.PrettyVal Methods prettyVal :: Word8 -> Value # listValue :: [Word8] -> Value
PrettyVal Ordering # |
Instance details Defined in Text.Show.PrettyVal Methods prettyVal :: Ordering -> Value # listValue :: [Ordering] -> Value
PrettyVal Text # |
Instance details Defined in Text.Show.PrettyVal Methods prettyVal :: Text -> Value # listValue :: [Text] -> Value
PrettyVal Integer # |
Instance details Defined in Text.Show.PrettyVal Methods prettyVal :: Integer -> Value # listValue :: [Integer] -> Value
PrettyVal Bool # |
Instance details Defined in Text.Show.PrettyVal Methods prettyVal :: Bool -> Value # listValue :: [Bool] -> Value
PrettyVal Char # |
Instance details Defined in Text.Show.PrettyVal Methods prettyVal :: Char -> Value # listValue :: [Char] -> Value
PrettyVal Double # |
Instance details Defined in Text.Show.PrettyVal Methods prettyVal :: Double -> Value # listValue :: [Double] -> Value
PrettyVal Float # |
Instance details Defined in Text.Show.PrettyVal Methods prettyVal :: Float -> Value # listValue :: [Float] -> Value
PrettyVal Int # |
Instance details Defined in Text.Show.PrettyVal Methods prettyVal :: Int -> Value # listValue :: [Int] -> Value
(PrettyVal a, Integral a) => PrettyVal (Ratio a) # |
Instance details Defined in Text.Show.PrettyVal Methods prettyVal :: Ratio a -> Value # listValue :: [Ratio a] -> Value
PrettyVal a => PrettyVal (Maybe a) # |
Instance details Defined in Text.Show.PrettyVal Methods prettyVal :: Maybe a -> Value # listValue :: [Maybe a] -> Value
PrettyVal a => PrettyVal [a] # |
Instance details Defined in Text.Show.PrettyVal Methods prettyVal :: [a] -> Value # listValue :: [[a]] -> Value
(PrettyVal a, PrettyVal b) => PrettyVal (Either a b) # |
Instance details Defined in Text.Show.PrettyVal Methods prettyVal :: Either a b -> Value # listValue :: [Either a b] -> Value
HasResolution p => PrettyVal (Fixed p) # |
Instance details Defined in Text.Show.PrettyVal Methods prettyVal :: Fixed p -> Value # listValue :: [Fixed p] -> Value
(PrettyVal a1, PrettyVal a2) => PrettyVal (a1, a2) # |
Instance details Defined in Text.Show.PrettyVal Methods prettyVal :: (a1, a2) -> Value # listValue :: [(a1, a2)] -> Value
(PrettyVal a1, PrettyVal a2, PrettyVal a3) => PrettyVal (a1, a2, a3) # |
Instance details Defined in Text.Show.PrettyVal Methods prettyVal :: (a1, a2, a3) -> Value # listValue :: [(a1, a2, a3)] -> Value
(PrettyVal a1, PrettyVal a2, PrettyVal a3, PrettyVal a4) => PrettyVal (a1, a2, a3, a4) # |
Instance details Defined in Text.Show.PrettyVal Methods prettyVal :: (a1, a2, a3, a4) -> Value # listValue :: [(a1, a2, a3, a4)] -> Value
(PrettyVal a1, PrettyVal a2, PrettyVal a3, PrettyVal a4, PrettyVal a5) => PrettyVal (a1, a2, a3, a4, a5) # |
Instance details Defined in Text.Show.PrettyVal Methods prettyVal :: (a1, a2, a3, a4, a5) -> Value # listValue :: [(a1, a2, a3, a4, a5)] -> Value
(PrettyVal a1, PrettyVal a2, PrettyVal a3, PrettyVal a4, PrettyVal a5, PrettyVal a6) => PrettyVal (a1, a2, a3, a4, a5, a6) # |
Instance details Defined in Text.Show.PrettyVal Methods prettyVal :: (a1, a2, a3, a4, a5, a6) -> Value # listValue :: [(a1, a2, a3, a4, a5, a6)] -> Value
(PrettyVal a1, PrettyVal a2, PrettyVal a3, PrettyVal a4, PrettyVal a5, PrettyVal a6, PrettyVal a7) => PrettyVal (a1, a2, a3, a4, a5, a6, a7) # |
Instance details Defined in Text.Show.PrettyVal Methods prettyVal :: (a1, a2, a3, a4, a5, a6, a7) -> Value # listValue :: [(a1, a2, a3, a4, a5, a6, a7)] -> Value

# Rendering values to Html

valToHtml :: HtmlOpts -> Value -> Html #

Convert a value into an Html fragment.

data HtmlOpts #

Options on how to generate Html (more to come).

Constructors

HtmlOpts |
Fields dataDir :: FilePath Path for extra files. If empty, we look in directory `style`, relative to document. wideListWidth :: Int Max. number of columns in wide lists.

#### Instances

Instances details

Show HtmlOpts # |
Instance details Defined in Text.Show.Html Methods showsPrec :: Int -> HtmlOpts -> ShowS show :: HtmlOpts -> String showList :: [HtmlOpts] -> ShowS

defaultHtmlOpts :: HtmlOpts #

Default options.

htmlPage :: HtmlOpts -> Html -> String #

Wrap an Html fragment to make an Html page.

newtype Html #

Constructors

Html |
Fields exportHtml :: String

# Get location of data files

getDataDir :: IO FilePath #

# Preprocessing of values

data PreProc a #

This type is used to allow pre-processing of values before showing them.

Constructors

PreProc (Value -> Value) a |

#### Instances

Instances details

Show a => Show (PreProc a) # |
Instance details Defined in Text.Show.Pretty Methods showsPrec :: Int -> PreProc a -> ShowS show :: PreProc a -> String showList :: [PreProc a] -> ShowS

ppHide :: (Name -> Bool) -> a -> PreProc a #

Hide the given constructors when showing a value.

ppHideNested :: (Name -> Bool) -> a -> PreProc a #

Hide the given constructors when showing a value. In addition, hide values if all of their children were hidden.

hideCon :: Bool -> (Name -> Bool) -> Value -> Value #

Hide constrcutros matching the given predicate. If the hidden value is in a record, we also hide the corresponding record field.

If the boolean flag is true, then we also hide constructors all of whose fields were hidden.

# Deprecated

ppValue :: Value -> Doc #

Deprecated: Please use `valToDoc` instead.