prettyprinter-interp-0.2.0.0: Efficient interpolation for Prettyprinter

Copyright | (C) 2022-2023 Peter Lebbing
License | BSD2 (see the file LICENSE)
Maintainer | Peter Lebbing <peter@digitalbrains.com>
Safe Haskell | Safe-Inferred
Language | Haskell2010

Prettyprinter.Interpolate

Contents

- Deprecated

Description

# Efficient interpolation for Prettyprinter

This module provides efficient interpolation of `string-interpolate` quasi quoters when used with `prettyprinter`s `Doc`uments.

The normal quasi quoters from `string-interpolate` do work when used as a `Doc`. Newlines are even converted to `Prettyprinter.``line`. However, this method is inefficient. The following code functions correctly:

     {-# LANGUAGE OverloadedStrings #-}
     {-# LANGUAGE QuasiQuotes #-}

     module Main where

     import Data.String.Interpolate
     import Data.Text (Text)
     import Prettyprinter

     f :: Text
     f = "world"

     g :: Doc ()
     g = [i|Hello #{f}!|]

     main :: IO ()
     main = print g

However, what happens under the hood is that `f` is converted to `String`, the interpolated string is built manipulating `String`s, and then the output is converted to `Text` in `prettyprinter`. The following code is much better:

     g = pretty ([i|Hello #{f}!|] :: Text)

Now, the interpolated string is constructed as `Text`, and this is passed cleanly into `Doc` which also uses `Text` as its underlying type for representation of text. At no point is `f` converted to `String`, and the string construction benefits from the performance of `Text`. And again, newlines are converted to `line`.

This module defines wrapper quasi quoters that automatically perform the `pretty` invocation, and can simply be used as:

     g = [di|Hello #{f}!|]

Synopsis

- di :: QuasiQuoter
- __di :: QuasiQuoter
- diii :: QuasiQuoter
- __di'E :: QuasiQuoter
- __di'L :: QuasiQuoter
- diii'E :: QuasiQuoter
- diii'L :: QuasiQuoter
- d__i'E :: QuasiQuoter
- d__i'L :: QuasiQuoter

# Documentation

di :: QuasiQuoter Source #

Wrapper around the `i` quasi quoter, producing a `Doc`

Newlines in the text are converted to `line`.

__di :: QuasiQuoter Source #

Wrapper around the `__i` quasi quoter, producing a `Doc`

Newlines in the text are converted to `line`.

diii :: QuasiQuoter Source #

Wrapper around the `iii` quasi quoter, producing a `Doc`

Newlines in the text are converted to `line`.

__di'E :: QuasiQuoter Source #

Wrapper around the `__i'E` quasi quoter, producing a `Doc`

Newlines in the text are converted to `line`.

__di'L :: QuasiQuoter Source #

Wrapper around the `__i'L` quasi quoter, producing a `Doc`

Newlines in the text are converted to `line`.

diii'E :: QuasiQuoter Source #

Wrapper around the `iii'E` quasi quoter, producing a `Doc`

Newlines in the text are converted to `line`.

diii'L :: QuasiQuoter Source #

Wrapper around the `iii'L` quasi quoter, producing a `Doc`

Newlines in the text are converted to `line`.

## Deprecated

d__i'E :: QuasiQuoter Source #

Deprecated: `d__i'E` is a deprecated alias for `__di'E` and will be removed in prettyprinter-interp 0.3

d__i'L :: QuasiQuoter Source #

Deprecated: `d__i'L` is a deprecated alias for `__di'L` and will be removed in prettyprinter-interp 0.3