| 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
Description
Functions for human-readable derived Show instances.
Synopsis
- data Value
- 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
- 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
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 |
| Date String | 01-02-2003 |
| Time String | 08:30:21 |
| Quote 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.
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 #
Try to show a value, prettily. If we do not understand the value, then we
just use its standard Show instance.
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
dumpIO :: PrettyVal a => a -> IO () #
Render a value using the PrettyVal class and show it to standard out.
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
Instances
Rendering values to Html
Options on how to generate Html (more to come).
Constructors
| HtmlOpts | |
Fields
| |
Default options.
Constructors
| Html | |
Fields
| |
Get location of data files
getDataDir :: IO FilePath #
Preprocessing of values
This type is used to allow pre-processing of values before showing them.
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.