Copyright | (c) Iavor S. Diatchki 2009 |
---|---|
License | MIT |
Maintainer | iavor.diatchki@gmail.com |
Stability | provisional |
Portability | Haskell 98 |
Safe Haskell | Safe |
Language | Haskell98 |
Functions for human-readable derived Show
instances.
Synopsis
- data Value
- type Name = String
- valToStr :: Value -> String
- valToDoc :: Value -> Doc
- 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 ()
- 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
Generic representation of values
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)])]
.
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 |
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.
Values using the Show
class
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.
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.
Preprocessing of values
This type is used to allow pre-processing of values before showing them.
ppHide :: (Name -> Bool) -> a -> PreProc a Source #
Hide the given constructors when showing a value.