Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Internal module with stability guarantees
This module exposes the internals of the
type so other libraries can
write adaptors to/from it. For all other uses, please use only the API
provided by non-internal modules.Doc
Although this module is internal, it follows the usual package versioning policy, AKA Haskell’s version of semantic versioning. In other words, this module is as stable as the public API.
Documentation
The abstract data type
represents pretty documents that have
been annotated with data of type Doc
annann
.
More specifically, a value of type
represents a non-empty set of
possible layouts of a document. The layout functions select one of these
possibilities, taking into account things like the width of the output
document.Doc
The annotation is an arbitrary piece of data associated with (part of) a document. Annotations may be used by the rendering backends in order to display output differently, such as
- color information (e.g. when rendering to the terminal)
- mouseover text (e.g. when rendering to rich HTML)
- whether to show something or not (to allow simple or detailed versions)
The simplest way to display a Doc
is via the Show
class.
>>>
putStrLn (show (vsep ["hello", "world"]))
hello world
Fail | Occurs when flattening a line. The layouter will reject this document, choosing a more suitable rendering. |
Empty | The empty document; conceptually the unit of |
Char !Char | invariant: not 'n' |
Text !Int !Text | Invariants: at least two characters long, does not contain 'n'. For
empty documents, there is Since the frequently used |
Line | Hard line break |
FlatAlt (Doc ann) (Doc ann) | Lay out the first The layout algorithms work under the assumption that the first alternative is less wide than the flattened second alternative. |
Cat (Doc ann) (Doc ann) | Concatenation of two documents |
Nest !Int (Doc ann) | Document indented by a number of columns |
Union (Doc ann) (Doc ann) | Invariant: The first lines of first document should be longer than the
first lines of the second one, so the layout algorithm can pick the one
that fits best. Used to implement layout alternatives for |
Column (Int -> Doc ann) | React on the current cursor position, see |
WithPageWidth (PageWidth -> Doc ann) | React on the document's width, see |
Nesting (Int -> Doc ann) | React on the current nesting level, see |
Annotated ann (Doc ann) | Add an annotation to the enclosed |