pretty-show-1.6.15: 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
- 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
- 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
- class PrettyVal a where
- 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
- ppValue :: Value -> Doc

# Generic representation of values

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".

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

Instances

Eq Value Source # |
Methods (==) :: Value -> Value -> Bool # (/=) :: Value -> Value -> Bool #
Show Value Source # |
Methods showsPrec :: Int -> Value -> ShowS # show :: Value -> String # showList :: [Value] -> ShowS #

type Name = String Source #

A name.

valToStr :: Value -> String 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.

valToDoc :: 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.

valToHtmlPage :: HtmlOpts -> Value -> String Source #

Make an Html page representing the given value.

# Values using the `Show` class

parseValue :: String -> Maybe Value Source #

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

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.

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

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

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

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 () Source #

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

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

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

class PrettyVal a where Source #

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

Methods

prettyVal :: a -> Value Source #

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

Instances

PrettyVal Bool Source # |
Methods prettyVal :: Bool -> Value Source # listValue :: [Bool] -> Value
PrettyVal Char Source # |
Methods prettyVal :: Char -> Value Source # listValue :: [Char] -> Value
PrettyVal Double Source # |
Methods prettyVal :: Double -> Value Source # listValue :: [Double] -> Value
PrettyVal Float Source # |
Methods prettyVal :: Float -> Value Source # listValue :: [Float] -> Value
PrettyVal Int Source # |
Methods prettyVal :: Int -> Value Source # listValue :: [Int] -> Value
PrettyVal Int8 Source # |
Methods prettyVal :: Int8 -> Value Source # listValue :: [Int8] -> Value
PrettyVal Int16 Source # |
Methods prettyVal :: Int16 -> Value Source # listValue :: [Int16] -> Value
PrettyVal Int32 Source # |
Methods prettyVal :: Int32 -> Value Source # listValue :: [Int32] -> Value
PrettyVal Int64 Source # |
Methods prettyVal :: Int64 -> Value Source # listValue :: [Int64] -> Value
PrettyVal Integer Source # |
Methods prettyVal :: Integer -> Value Source # listValue :: [Integer] -> Value
PrettyVal Ordering Source # |
Methods prettyVal :: Ordering -> Value Source # listValue :: [Ordering] -> Value
PrettyVal Word8 Source # |
Methods prettyVal :: Word8 -> Value Source # listValue :: [Word8] -> Value
PrettyVal Word16 Source # |
Methods prettyVal :: Word16 -> Value Source # listValue :: [Word16] -> Value
PrettyVal Word32 Source # |
Methods prettyVal :: Word32 -> Value Source # listValue :: [Word32] -> Value
PrettyVal Word64 Source # |
Methods prettyVal :: Word64 -> Value Source # listValue :: [Word64] -> Value
PrettyVal a => PrettyVal [a] Source # |
Methods prettyVal :: [a] -> Value Source # listValue :: [[a]] -> Value
PrettyVal a => PrettyVal (Maybe a) Source # |
Methods prettyVal :: Maybe a -> Value Source # listValue :: [Maybe a] -> Value
(PrettyVal a, Integral a) => PrettyVal (Ratio a) Source # |
Methods prettyVal :: Ratio a -> Value Source # listValue :: [Ratio a] -> Value
(PrettyVal a, PrettyVal b) => PrettyVal (Either a b) Source # |
Methods prettyVal :: Either a b -> Value Source # listValue :: [Either a b] -> Value
(PrettyVal a1, PrettyVal a2) => PrettyVal (a1, a2) Source # |
Methods prettyVal :: (a1, a2) -> Value Source # listValue :: [(a1, a2)] -> Value
(PrettyVal a1, PrettyVal a2, PrettyVal a3) => PrettyVal (a1, a2, a3) Source # |
Methods prettyVal :: (a1, a2, a3) -> Value Source # listValue :: [(a1, a2, a3)] -> Value
(PrettyVal a1, PrettyVal a2, PrettyVal a3, PrettyVal a4) => PrettyVal (a1, a2, a3, a4) Source # |
Methods prettyVal :: (a1, a2, a3, a4) -> Value Source # listValue :: [(a1, a2, a3, a4)] -> Value
(PrettyVal a1, PrettyVal a2, PrettyVal a3, PrettyVal a4, PrettyVal a5) => PrettyVal (a1, a2, a3, a4, a5) Source # |
Methods prettyVal :: (a1, a2, a3, a4, a5) -> Value Source # 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) Source # |
Methods prettyVal :: (a1, a2, a3, a4, a5, a6) -> Value Source # 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) Source # |
Methods prettyVal :: (a1, a2, a3, a4, a5, a6, a7) -> Value Source # listValue :: [(a1, a2, a3, a4, a5, a6, a7)] -> Value

# Rendering values to Html

valToHtml :: HtmlOpts -> Value -> Html Source #

Convert a value into an Html fragment.

data HtmlOpts Source #

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

Show HtmlOpts Source # |
Methods showsPrec :: Int -> HtmlOpts -> ShowS # show :: HtmlOpts -> String # showList :: [HtmlOpts] -> ShowS #

defaultHtmlOpts :: HtmlOpts Source #

Default options.

htmlPage :: HtmlOpts -> Html -> String Source #

Wrap an Html fragment to make an Html page.

newtype Html Source #

Constructors

Html |

Fields

- exportHtml :: String

# Get location of data files

getDataDir :: IO FilePath Source #

# Deprecated

ppValue :: Value -> Doc Source #

Deprecated: Please use `valToDoc` instead.