HORIZON HASKELLDocslts/ghc-10.0.xfc4e5982026-10-11Search names, modules, packages, or :: a typeCtrl K

GHC 10.0.0.20260917 · lts/ghc-10.0.x · fc4e598 · 2026-10-11

Moduleprettyprinter-1.7.2Haskell2010

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.2 · Prettyprinter.Render.Util.StackMachine
  • Functor (StackMachine output style)Defined in prettyprinter-1.7.2 · Prettyprinter.Render.Util.StackMachine
  • Monoid output => Applicative (StackMachine output style)Defined in prettyprinter-1.7.2 · Prettyprinter.Render.Util.StackMachine