HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Moduleprettyprinter-1.7.1Haskell2010

Prettyprinter.Render.Util.StackMachine

Definitions to write renderers based on looking at a SimpleDocStream as an instruction tape for a stack machine: text is written, annotations are added (pushed) and later removed (popped).

  • 1 type
  • 7 values

Simple, pre-defined stack machines

2 declarations

These cover most basic use cases where there is not too much special logic, and all that’s important is how to render text, and how to add/remove an annotation.

valuerenderSimplyDecorated
  1. :: Monoid out
  2. => (Text -> out)

    Render plain Text

  3. -> (ann -> out)

    How to render an annotation

  4. -> (ann -> out)

    How to render the removed annotation

  5. -> SimpleDocStream ann
  6. -> out
#

Simplest possible stack-based renderer.

For example, here is a document annotated with (), and the behaviour is to write »>>>« at the beginning, and »<<<« at the end of the annotated region:

Example3 expressions
let doc = "hello" <+> annotate () "world" <> "!"let sdoc = layoutPretty defaultLayoutOptions docT.putStrLn (renderSimplyDecorated id (\() -> ">>>") (\() -> "<<<") sdoc)hello >>>world<<<!

The monoid will be concatenated in a right associative fashion.

General stack machine

6 declarations

These definitions allow defining a full-blown stack machine renderer, allowing for arbitrary peeking, popping and what not.

newtypenewtype StackMachine output style a
#

Deprecated. Writing your own stack machine is probably more efficient and customizable; also consider using »renderSimplyDecorated(A)« instead

WriterT output StateT [style] a, but with a strict Writer value.

The output type is used to append data chunks to, the style is the member of a stack of styles to model nested styles with.

Instances3Monad, Functor, Applicative
  • Monoid output => Monad (StackMachine output style)Defined in prettyprinter-1.7.1 · Prettyprinter.Render.Util.StackMachine
  • Functor (StackMachine output style)Defined in prettyprinter-1.7.1 · Prettyprinter.Render.Util.StackMachine
  • Monoid output => Applicative (StackMachine output style)Defined in prettyprinter-1.7.1 · Prettyprinter.Render.Util.StackMachine