pretty

Pretty-printing library http://github.com/haskell/pretty

Version on this page:1.1.2.0
LTS Haskell 9.14:1.1.3.3
Stackage Nightly 2017-11-25:1.1.3.3
Latest on Hackage:1.1.3.5
BSD3 licensed
Maintained by David Terei

Module documentation for 1.1.2.0

There are no documented modules for this package.

Pretty : A Haskell Pretty-printer library

Hackage Hackage Dependencies BSD3 License Build

https://tldrlegal.com/license/bsd-3-clause-license-(revised) "BSD3 License"

Pretty is a pretty-printing library, a set of API's that provides a way to easily print out text in a consistent format of your choosing. This is useful for compilers and related tools.

It is based on the pretty-printer outlined in the paper 'The Design of a Pretty-printing Library' by John Hughes in Advanced Functional Programming, 1995. It can be found here.

Licensing

This library is BSD-licensed.

Building

The library uses the Cabal build system, so building is simply a matter of running:

cabal sandbox init
cabal install "QuickCheck >= 2.5 && < 3"
cabal install --only-dependencies
cabal configure --enable-tests
cabal build
cabal test

We have to install QuickCheck manually as otherwise Cabal currently throws an error due to the cyclic dependency between pretty and QuickCheck.

If cabal test freezes, then run cabal test --show-details=streaming instead. This is due to a bug in certain versions of Cabal.

Get involved!

We are happy to receive bug reports, fixes, documentation enhancements, and other improvements.

Please report bugs via the github issue tracker.

Master git repository:

  • git clone git://github.com/haskell/pretty.git

Authors

This library is maintained by David Terei, . It was originally designed by John Hughes's and since heavily modified by Simon Peyton Jones.

Changes

Pretty library change log

1.1.3.5 -- 1st February, 2017

  • Fix documentation formatting bug (by Ivan Lazar Miljenovic)
  • Fix missing git tag on Github for v1.1.3.4 release.

1.1.3.4 -- 3rd June, 2016

  • Fix over-zeleaous use of strictness causing stack allocation, fixes part of issue #32 (by Neil Mitchell).

1.1.3.3 -- 29th February, 2016

  • Improve documentation.

1.1.3.2 -- 19th March, 2015

  • Fix bug with haddock documentation.
  • Clean up module intro documentation.

1.1.3.1 -- 11th March, 2015

  • Add support for annotations in pretty (by Trevor Elliott).

1.1.2.1 -- 25th December, 2014

  • Fix overly-strict issue preventing use of pretty for very large docs (by Eyal Lotem).

1.1.2.0 -- 25th December, 2014

  • Merge in prettyclass package -- new Text.PrettyPrint.HughesPHClass.
  • Add in 'maybe*' variants of various bracket functins.
  • Add Generic instances for appropriate data types.
  • Fix compilation under GHC 7.10

1.1.1.3 -- 21st December, 2014

  • Remove upper bound on deepseq package to fix build issues with latest GHC.

1.1.1.2 -- 18th August, 2014

  • Add NFData and Eq instances (by Ivan Lazar Miljenovic).

1.1.1.1 -- 27th October, 2013

  • Update pretty cabal file and readme.
  • Fix tests to work with latest quickcheck.

Version 3.0, 28 May 1987

  • Cured massive performance bug. If you write:

    foldl <> empty (map (text.show) [1..10000])

    You get quadratic behaviour with V2.0. Why? For just the same reason as you get quadratic behaviour with left-associated (++) chains.

    This is really bad news. One thing a pretty-printer abstraction should certainly guarantee is insensitivity to associativity. It matters: suddenly GHC's compilation times went up by a factor of 100 when I switched to the new pretty printer.

    I fixed it with a bit of a hack (because I wanted to get GHC back on the road). I added two new constructors to the Doc type, Above and Beside:

    <> = Beside $$ = Above

    Then, where I need to get to a "TextBeside" or "NilAbove" form I "force" the Doc to squeeze out these suspended calls to Beside and Above; but in so doing I re-associate. It's quite simple, but I'm not satisfied that I've done the best possible job. I'll send you the code if you are interested.

  • Added new exports: punctuate, hang int, integer, float, double, rational, lparen, rparen, lbrack, rbrack, lbrace, rbrace,

  • fullRender's type signature has changed. Rather than producing a string it now takes an extra couple of arguments that tells it how to glue fragments of output together:

    fullRender :: Mode -> Int -- Line length -> Float -- Ribbons per line -> (TextDetails -> a -> a) -- What to do with text -> a -- What to do at the end -> Doc -> a -- Result

    The "fragments" are encapsulated in the TextDetails data type:

    data TextDetails = Chr Char | Str String | PStr FAST_STRING

    The Chr and Str constructors are obvious enough. The PStr constructor has a packed string (FAST_STRING) inside it. It's generated by using the new "ptext" export.

    An advantage of this new setup is that you can get the renderer to do output directly (by passing in a function of type (TextDetails -> IO () -> IO ()), rather than producing a string that you then print.

Version 3.0, 28 May 1987

  • Made empty into a left unit for <> as well as a right unit; it is also now true that nest k empty = empty which wasn't true before.

  • Fixed an obscure bug in sep that occasionally gave very weird behaviour

  • Added $+$

  • Corrected and tidied up the laws and invariants

Version 1.0

Relative to John's original paper, there are the following new features:

  1. There's an empty document, "empty". It's a left and right unit for both <> and $$, and anywhere in the argument list for sep, hcat, hsep, vcat, fcat etc.

    It is Really Useful in practice.

  2. There is a paragraph-fill combinator, fsep, that's much like sep, only it keeps fitting things on one line until it can't fit any more.

  3. Some random useful extra combinators are provided. <+> puts its arguments beside each other with a space between them, unless either argument is empty in which case it returns the other

    hcat is a list version of <> hsep is a list version of <+> vcat is a list version of $$

    sep (separate) is either like hsep or like vcat, depending on what fits

    cat behaves like sep, but it uses <> for horizontal composition fcat behaves like fsep, but it uses <> for horizontal composition

    These new ones do the obvious things: char, semi, comma, colon, space, parens, brackets, braces, quotes, doubleQuotes

  4. The "above" combinator, $$, now overlaps its two arguments if the last line of the top argument stops before the first line of the second begins.

    For example: text "hi" $$ nest 5 (text "there") lays out as hi there rather than hi there

    There are two places this is really useful

    a) When making labelled blocks, like this: Left -> code for left Right -> code for right LongLongLongLabel -> code for longlonglonglabel The block is on the same line as the label if the label is short, but on the next line otherwise.

    b) When laying out lists like this: [ first , second , third ] which some people like. But if the list fits on one line you want [first, second, third]. You can't do this with John's original combinators, but it's quite easy with the new $$.

    The combinator $+$ gives the original "never-overlap" behaviour.

  5. Several different renderers are provided:
    • a standard one
    • one that uses cut-marks to avoid deeply-nested documents simply piling up in the right-hand margin
    • one that ignores indentation (fewer chars output; good for machines)
    • one that ignores indentation and newlines (ditto, only more so)
  6. Numerous implementation tidy-ups Use of unboxed data types to speed up the implementation

Depends on:
Used by 417 packages:
accelerate-cuda, accelerate-llvm-ptx, acme-http, adobe-swatch-exchange, Agda, ajhc, algebra-sql, AlgorithmW, alms, ALUT, anatomy, AndroidViewHierarchyImporter, arbb-vm, archive, archlinux, archlinux-web, asil, ASN1, asn1-codec, atomo, atp-haskell, Aurochs, azure-service-api, b9, bamse, baskell, bayes-stack, beam, bencoding, bibdb, bidirectionalization-combined, billeksah-forms, billeksah-main, billeksah-main-static, billeksah-pane, billeksah-services, bittorrent, blip, bliplib, Blobs, BNFC, brittany, buildbox, buster, buster-gtk, buster-network, butcher, c2ats, c2hs, c2hsc, Cabal, cabal2arch, cabal2nix, cabal-db, cabal-debian, cabal-dev, cabal-file-th, cabalgraph, Cabal-ide-backend, cabal-install, cabal-install-bundle, cabal-install-ghc72, cabal-install-ghc74, cabalQuery, cao, cash, chp, chp-plus, chp-spec, clash, clash-lib, clua, cmdtheline, cnc-spec-compiler, Coadjute, codec-rpm, Combinatorrent, complexity, conffmt, config-schema, configurator-export, config-value, conjure, context-free-grammar, copilot-c99, copilot-cbmc, copilot-core, copilot-sbv, copilot-theorem, core, CoreDump, CoreErlang, Crypto, crypto-cipher-benchmarks, cryptol, CSPM-ToProlog, cspretty, cuda, curry-base, curry-frontend, datalog, data-pprint, data-tree-print, dawdle, dclabel-eci11, debian, derive, derive-gadt, dicom, Diff, diffcabal, DisTract, distribution-nixpkgs, djinn, djinn-lib, dph-base, dph-lifted-base, dph-lifted-vseg, DPM, DrHylo, dtab, dwarfadt, EditTimeReport, Elm, elm-compiler, elm-package, estimators, ethereum-analyzer, event-monad, ewe, exference, exherbo-cabal, extcore, Extra, feldspar-compiler, FerryCore, ffeed, fig, flat, ForSyDe, fortran-src, foscam-directory, frame, freesect, free-theorems, free-theorems-counterexamples, free-theorems-seq, free-theorems-seq-webui, fsmActions, ftshell, funsat, GenericPretty, gf, ghc-dump-tree, ginsu, git-checklist, gitit, GLFW-b-demo, gll, gps, greencard, greencard-lib, gtk2hs-buildtools, H, hackage-security, hackage-server, hackport, haddock-leksah, hakaru, handa-gdata, HAppS-Data, happstack-data, happstack-yui, happs-tutorial, hardware-edsl, harpy, haskelldb, HaskellNet, haskell-platform-test, haskell-spacegoo, haskell-src, haskell-src-exts, haskell-src-meta, haskell-src-meta-mwotton, haskell-token-utils, haskell-tools-daemon, HaskellTorrent, haskell-type-exts, haskell-xmpp, haskelm, haskelzinc, haskhol-core, haxl, HaXml, hbayes, hburg, hcron, hdirect, hdo, Hedi, helf, hellnet, hfmt, hfusion, Hieroglyph, HJavaScript, hLLVM, hol, hoq, hpack, hpack-convert, hpc-tracer, hsmagick, Hsmtlib, HsParrot, hspec-setup, hssqlppp, HStringTemplate, hs-twitterarchiver, HTF, httpspec, HulkImport, hydrogen, hylolib, hyperdrive, idris, imperative-edsl-vhdl, INblobs, inch, inline-r, ivory, ivory-examples, ivory-opts, java-adt, JsContracts, json, json2, json-autotype, jukebox, jvm-parser, lambdabot-haskell-plugins, LambdaCalculator, lambdacube, language-bash, language-boogie, language-c, language-conf, language-css, language-dart, language-dockerfile, language-dot, language-eiffel, language-elm, language-hcl, language-java, language-mixal, language-nix, language-objc, language-python, language-qux, language-typescript, language-vhdl, leksah, leksah-server, lhc, libcspm, lighttpd-conf, linux-perf, liquid-fixpoint, liquidhaskell, live-sequencer, llsd, llvm-base-types, llvm-pretty, llvm-pretty-bc-parser, loch-th, logic-classes, LogicGrowsOnTrees, LogicGrowsOnTrees-network, lscabal, ltext, ltk, lua-bc, luachunk, MagicHaskeller, marxup, MazesOfMonad, mediawiki, MiniAgda, ministg, mkcabal, ml-w, model, module-management, monadiccp, monadloc-pp, morfette, mprover, multifile, multifocal, mushu, musicxml, mxnet, nanoAgda, netlist-to-vhdl, network-data, nextstep-plist, ntha, ofx, omega, opaleye, opaleye-sqlite, open-pandoc, origami, pango, paragon, parsec-pratt, passage, picologic, pi-forall, polynomial, polyseq, pptable, presburger, prettyclass, pretty-class, pretty-ncols, pretty-show, preview, Printf-TH, proto-lens, Pugs, pugs-DrIFT, qux, remarks, rest-gen, risc386, roundtrip, roundtrip-xml, SableCC2Hs, sat-micro-hs, sbv, scyther-proof, selenium, seqloc-datafiles, sequor, servant-quickcheck, sexpr, shivers-cfg, simple-sql-parser, slim, smallcheck, smartword, smtLib, sonic-visualiser, soyuz, sqlcipher, sqlite, sr-extra, stack, stackage2nix, stackage-metadata, staversion, Strafunski-Sdf2Haskell, strict-data, structural-induction, subleq-toolchain, SVD2HS, svg2q, SVG2Q, swearjure, swf, syntax-pretty, Sysmon, TableAlgebra, tal, tamarin-prover-utils, target, template-haskell, text-plus, text-printer, text-show-instances, th-context, thih, th-pprint, th-typegraph, timberc, tip-haskell-frontend, tip-lib, tkhs, top, to-string-instances, traced, tree-diff, tsparse, twee, typelevel, type-spec, uAgda, unjson, vacuum-cairo, vacuum-opengl, vhdl, visual-graphrewrite, visual-prof, WebBits, WebBits-Html, webidl, why3, windowslive, wlc-hs, xcb-types, XSaiga, yhccore, yices-painless, zip-archive, zm
comments powered byDisqus