haskell-src-1.0.1.5: Support for manipulating Haskell source code

Portability | portable
Stability | experimental
Maintainer | libraries@haskell.org
Safe Haskell | None

Language.Haskell.Pretty

Contents

- Pretty printing
- Pretty-printing styles (from Text.PrettyPrint.HughesPJ)
- Haskell formatting modes

Description

Pretty printer for Haskell.

Synopsis

- class Pretty a
- prettyPrintStyleMode :: Pretty a => Style -> PPHsMode -> a -> String
- prettyPrintWithMode :: Pretty a => PPHsMode -> a -> String
- prettyPrint :: Pretty a => a -> String
- data Style = Style {
  - mode :: Mode
  - lineLength :: Int
  - ribbonsPerLine :: Float
  }
- style :: Style
- data Mode
  - = PageMode
  - | ZigZagMode
  - | LeftMode
  - | OneLineMode
- data PPHsMode = PPHsMode {
  - classIndent :: Indent
  - doIndent :: Indent
  - caseIndent :: Indent
  - letIndent :: Indent
  - whereIndent :: Indent
  - onsideIndent :: Indent
  - spacing :: Bool
  - layout :: PPLayout
  - linePragmas :: Bool
  - comments :: Bool
  }
- type Indent = Int
- data PPLayout
  - = PPOffsideRule
  - | PPSemiColon
  - | PPInLine
  - | PPNoLayout
- defaultMode :: PPHsMode

# Pretty printing

class Pretty a

Things that can be pretty-printed, including all the syntactic objects in Language.Haskell.Syntax.

Instances

Pretty HsGuardedAlt |
Pretty HsGuardedAlts |
Pretty HsAlt |
Pretty HsFieldUpdate |
Pretty HsStmt |
Pretty HsPatField |
Pretty HsPat |
Pretty HsExp |
Pretty HsLiteral |
Pretty HsType |
Pretty HsQualType |
Pretty HsSafety |
Pretty HsGuardedRhs |
Pretty HsRhs |
Pretty HsBangType |
Pretty HsConDecl |
Pretty HsMatch |
Pretty HsDecl |
Pretty HsAssoc |
Pretty HsImportSpec |
Pretty HsImportDecl |
Pretty HsExportSpec |
Pretty HsModule |
Pretty HsCName |
Pretty HsOp |
Pretty HsQOp |
Pretty HsName |
Pretty HsQName |
Pretty Module |

prettyPrintStyleMode :: Pretty a => Style -> PPHsMode -> a -> String

pretty-print with a given style and mode.

prettyPrintWithMode :: Pretty a => PPHsMode -> a -> String

pretty-print with the default style and a given mode.

prettyPrint :: Pretty a => a -> String

pretty-print with the default style and `defaultMode`.

# Pretty-printing styles (from Text.PrettyPrint.HughesPJ)

data Style

A rendering style.

Constructors

Style |

Fields

mode :: Mode

  The rendering mode

lineLength :: Int

  Length of line, in chars

ribbonsPerLine :: Float

  Ratio of ribbon length to line length

style :: Style

The default style (`mode=PageMode, lineLength=100, ribbonsPerLine=1.5`).

data Mode

Rendering mode.

Constructors

PageMode | Normal
ZigZagMode | With zig-zag cuts
LeftMode | No indentation, infinitely long lines
OneLineMode | All on one line

# Haskell formatting modes

data PPHsMode

Pretty-printing parameters.

Note: the `onsideIndent` must be positive and less than all other indents.

Constructors

PPHsMode |

Fields

classIndent :: Indent

  indentation of a class or instance

doIndent :: Indent

  indentation of a `do`-expression

caseIndent :: Indent

  indentation of the body of a `case` expression

letIndent :: Indent

  indentation of the declarations in a `let` expression

whereIndent :: Indent

  indentation of the declarations in a `where` clause

onsideIndent :: Indent

  indentation added for continuation lines that would otherwise be offside

spacing :: Bool

  blank lines between statements?

layout :: PPLayout

  Pretty-printing style to use

linePragmas :: Bool

  add GHC-style `LINE` pragmas to output?

comments :: Bool

  not implemented yet

type Indent = Int

data PPLayout

Varieties of layout we can use.

Constructors

PPOffsideRule | classical layout
PPSemiColon | classical layout made explicit
PPInLine | inline decls, with newlines between them
PPNoLayout | everything on a single line

Instances

Eq PPLayout |

defaultMode :: PPHsMode

The default mode: pretty-print using the offside rule and sensible defaults.