HORIZON HASKELLDocslts/ghc-9.14.xd82dee82026-10-12Search names, modules, packages, or :: a typeCtrl K

GHC 9.14.1 · lts/ghc-9.14.x · d82dee8 · 2026-10-12

Moduleplutus-core-1.70.0.0

PlutusCore.Pretty

  • 36 types
  • 6 classes
  • 61 values
valuebotFixity :: Fixity
#

A fixity with the lowest precedence. When used as a part of an outer context, never causes addition of parens.

valuetopFixity :: Fixity
#

A fixity with the highest precedence. When used as a part of an outer context, always causes addition of parens.

valueunitFixity :: Fixity
#

The fixity of a unitary expression which is safe to render without parens in any context.

valueencloseIn
  1. :: Ord prec
  2. => (a -> a)

    Enclose a value of type a in parens.

  3. -> RenderContextOver prec

    An outer context.

  4. -> FixityOver prec

    An inner fixity.

  5. -> a
  6. -> a
#

Enclose an a (using the provided function) if required or leave it as is. The need for enclosing is determined from an outer RenderContext and the inner fixity.

valuedisplay :: (Pretty a, Render str) => a -> str
#

Pretty-print and render a value as a string type.

valuedisplayBy :: (PrettyBy config a, Render str) => config -> a -> str
#

Pretty-print and render a value as a string type in a configurable way.

valueencloseM
  1. :: MonadPrettyContext config env m
  2. => Fixity
  3. -> Doc ann
  4. -> m (Doc ann)
#

Enclose a Doc in parentheses if required or leave it as is. The need for enclosing is determined from an outer RenderContext (stored in the environment of the monad) and the inner fixity provided as an argument.

valueinContextM :: (a -> InContextM config (Doc ann)) -> config -> a -> Doc ann
#

Takes a monadic pretty-printer and turns it into one that receives a config explicitly. Useful for defining instances of PrettyBy monadically when writing precedence-aware pretty-printing code (and since all functions below are monadic, it's currenty the only option).

valueinfixDocM
  1. :: MonadPrettyContext config env m
  2. => Fixity
  3. -> AnyToDoc config ann -> AnyToDoc config ann -> Doc ann
  4. -> m (Doc ann)
#

Instantiate a supplied continuation with two pretty-printers (one is going in the ToTheLeft direction, the other is in the ToTheRight direction) specialized to supplied Fixity and apply encloseM, specialized to the same fixity, to the result. The idea is that to the outside an infix operator has the same inner fixity as it has the outer fixity to inner subexpressions.

valuedisplayM
  1. :: (MonadPretty config env m, PrettyBy config a, Render str)
  2. => a
  3. -> m str
#

Pretty-print and render a value as a string type in a configurable way in a monad holding a config.

valueprettyM :: (MonadPretty config env m, PrettyBy config a) => a -> m (Doc ann)
#

Pretty-print a value in a configurable way in a monad holding a config.

datadata PrettyConfigClassic configName
#
Instances10Show, HasPrettyConfigName, PrettyBy, HasPrettyDefaults, …
classclass HasPrettyConfigName config where
#
Instances5HasPrettyConfigName
newtypenewtype PrettyConfigName
#
Instances6Eq, Show, HasPrettyConfigName, PrettyBy, HasPrettyDefaults
datadata PrettyConfigPlc
#
Instances18Show, HasPrettyConfigName, PrettyBy, HasPrettyDefaults, …
Instances3Show, HasPrettyConfigName, PrettyBy
newtypenewtype ConstConfig
#
Instances25HasRenderContext, DefaultPrettyBy, NonDefaultPrettyBy, PrettyBy, HasPrettyDefaults, …
newtypenewtype AsReadable a
#

Constructors

Instances4PrettyBy, DefaultPrettyBy, Show, Pretty
datadata PrettyConfigReadable configName
#
Instances14Show, HasRenderContext, HasPrettyConfigName, PrettyBy, HasPrettyDefaults, …
datadata Doc ann
#

The abstract data type Doc ann represents pretty documents that have been annotated with data of type ann.

More specifically, a value of type Doc represents a non-empty set of possible layouts of a document. The layout functions select one of these possibilities, taking into account things like the width of the output document.

The annotation is an arbitrary piece of data associated with (part of) a document. Annotations may be used by the rendering backends in order to display output differently, such as

  • color information (e.g. when rendering to the terminal)

  • mouseover text (e.g. when rendering to rich HTML)

  • whether to show something or not (to allow simple or detailed versions)

The simplest way to display a Doc is via the Show class.

Example1 expression
putStrLn (show (vsep ["hello", "world"]))helloworld
Instances9Functor, PrettyAnn, Show, IsString, Generic, Semigroup, …
classclass Pretty a where
#

Overloaded conversion to Doc.

Laws:

  1. output should be pretty. :-)

Methods

  • pretty :: a -> Doc ann
    Example1 expression
    pretty 1 <+> pretty "hello" <+> pretty 1.2341 hello 1.234
  • prettyList :: [a] -> Doc ann

    prettyList is only used to define the instance Pretty a => Pretty [a]. In normal circumstances only the pretty function is used.

    Example1 expression
    prettyList [1, 23, 456][1, 23, 456]
Instances101Pretty, …
  • Pretty VoidDefined in prettyprinter-1.7.2 · Prettyprinter.Internal

    Finding a good example for printing something that does not exist is hard, so here is an example of printing a list full of nothing.

    Example1 expression
    pretty ([] :: [Void])[]
  • Pretty IntegerDefined in prettyprinter-1.7.2 · Prettyprinter.Internal
    Example1 expression
    pretty (2^123 :: Integer)10633823966279326983230456482242756608
  • Pretty NaturalDefined in prettyprinter-1.7.2 · Prettyprinter.Internal
  • Pretty Int16Defined in prettyprinter-1.7.2 · Prettyprinter.Internal
  • Pretty Int32Defined in prettyprinter-1.7.2 · Prettyprinter.Internal
  • Pretty Int64Defined in prettyprinter-1.7.2 · Prettyprinter.Internal
  • Pretty Int8Defined in prettyprinter-1.7.2 · Prettyprinter.Internal
  • Pretty BoolDefined in prettyprinter-1.7.2 · Prettyprinter.Internal
    Example1 expression
    pretty TrueTrue
  • Pretty CharDefined in prettyprinter-1.7.2 · Prettyprinter.Internal

    Instead of (pretty '\n'), consider using line as a more readable alternative.

    Example2 expressions
    pretty 'f' <> pretty 'o' <> pretty 'o'foopretty ("string" :: String)string
  • Pretty DoubleDefined in prettyprinter-1.7.2 · Prettyprinter.Internal
    Example1 expression
    pretty (exp 1 :: Double)2.71828182845904...
  • Pretty FloatDefined in prettyprinter-1.7.2 · Prettyprinter.Internal
    Example1 expression
    pretty (pi :: Float)3.1415927
  • Pretty IntDefined in prettyprinter-1.7.2 · Prettyprinter.Internal
    Example1 expression
    pretty (123 :: Int)123
  • Pretty WordDefined in prettyprinter-1.7.2 · Prettyprinter.Internal
  • Pretty Word16Defined in prettyprinter-1.7.2 · Prettyprinter.Internal
  • Pretty Word32Defined in prettyprinter-1.7.2 · Prettyprinter.Internal
  • Pretty Word64Defined in prettyprinter-1.7.2 · Prettyprinter.Internal
  • Pretty Word8Defined in prettyprinter-1.7.2 · Prettyprinter.Internal
  • Pretty SourcePosDefined in plutus-core-1.70.0.0 · PlutusCore.Error · orphan
  • Pretty DeserialiseFailureInfoDefined in plutus-core-1.70.0.0 · Codec.Extras.SerialiseViaFlat
  • Pretty DeserialiseFailureReasonDefined in plutus-core-1.70.0.0 · Codec.Extras.SerialiseViaFlat
  • Pretty AnnDefined in plutus-core-1.70.0.0 · PlutusCore.Annotation
  • Pretty SrcSpanDefined in plutus-core-1.70.0.0 · PlutusCore.Annotation
  • Pretty SrcSpansDefined in plutus-core-1.70.0.0 · PlutusCore.Annotation
  • Pretty ParamDefined in plutus-core-1.70.0.0 · PlutusCore.Arity
  • Pretty AstSizeDefined in plutus-core-1.70.0.0 · PlutusCore.AstSize
  • Pretty BuiltinErrorDefined in plutus-core-1.70.0.0 · PlutusCore.Builtin.Result
  • Pretty UnliftingErrorDefined in plutus-core-1.70.0.0 · PlutusCore.Builtin.Result
  • Pretty UnliftingEvaluationErrorDefined in plutus-core-1.70.0.0 · PlutusCore.Builtin.Result
  • Pretty NameAnnDefined in plutus-core-1.70.0.0 · PlutusCore.Check.Scoping
  • Pretty ScopeErrorDefined in plutus-core-1.70.0.0 · PlutusCore.Check.Scoping
  • Pretty ElementDefined in plutus-core-1.70.0.0 · PlutusCore.Crypto.BLS12_381.G1
  • Pretty ElementDefined in plutus-core-1.70.0.0 · PlutusCore.Crypto.BLS12_381.G2
  • Pretty MlResultDefined in plutus-core-1.70.0.0 · PlutusCore.Crypto.BLS12_381.Pairing
  • Pretty DataDefined in plutus-core-1.70.0.0 · PlutusCore.Data
  • Pretty FreeVariableErrorDefined in plutus-core-1.70.0.0 · PlutusCore.DeBruijn.Internal
  • Pretty IndexDefined in plutus-core-1.70.0.0 · PlutusCore.DeBruijn.Internal
  • Pretty DefaultFunDefined in plutus-core-1.70.0.0 · PlutusCore.Default.Builtins
  • Pretty ParserErrorDefined in plutus-core-1.70.0.0 · PlutusCore.Error
  • Pretty ParserErrorBundleDefined in plutus-core-1.70.0.0 · PlutusCore.Error
  • Pretty CkUserErrorDefined in plutus-core-1.70.0.0 · PlutusCore.Evaluation.Machine.Ck
  • Pretty CostModelApplyErrorDefined in plutus-core-1.70.0.0 · PlutusCore.Evaluation.Machine.CostModelInterface
  • Pretty CostModelApplyWarnDefined in plutus-core-1.70.0.0 · PlutusCore.Evaluation.Machine.CostModelInterface
  • Pretty ExBudgetDefined in plutus-core-1.70.0.0 · PlutusCore.Evaluation.Machine.ExBudget
  • Pretty ExRestrictingBudgetDefined in plutus-core-1.70.0.0 · PlutusCore.Evaluation.Machine.ExBudget
  • Pretty ExCPUDefined in plutus-core-1.70.0.0 · PlutusCore.Evaluation.Machine.ExMemory
  • Pretty ExMemoryDefined in plutus-core-1.70.0.0 · PlutusCore.Evaluation.Machine.ExMemory
  • Pretty ExtensionFunDefined in plutus-core-1.70.0.0 · PlutusCore.Examples.Builtins
  • Pretty NameDefined in plutus-core-1.70.0.0 · PlutusCore.Core.Instance.Pretty.Default · orphan
  • Pretty TyNameDefined in plutus-core-1.70.0.0 · PlutusCore.Core.Instance.Pretty.Default · orphan
  • Pretty UniqueDefined in plutus-core-1.70.0.0 · PlutusCore.Name.Unique
  • Pretty QuantityDefined in plutus-core-1.70.0.0 · PlutusCore.Value
  • Pretty ValueDefined in plutus-core-1.70.0.0 · PlutusCore.Value
  • Pretty VersionDefined in plutus-core-1.70.0.0 · PlutusCore.Version
  • Pretty CountingStDefined in plutus-core-1.70.0.0 · UntypedPlutusCore.Evaluation.Machine.Cek.ExBudgetMode
  • Pretty RestrictingStDefined in plutus-core-1.70.0.0 · UntypedPlutusCore.Evaluation.Machine.Cek.ExBudgetMode
  • Pretty CekUserErrorDefined in plutus-core-1.70.0.0 · UntypedPlutusCore.Evaluation.Machine.Cek.Internal
  • Pretty CseWhichSubtermsDefined in plutus-core-1.70.0.0 · UntypedPlutusCore.Optimize.Opts
  • Pretty PurityDefined in plutus-core-1.70.0.0 · UntypedPlutusCore.Purity
  • Pretty WorkFreedomDefined in plutus-core-1.70.0.0 · UntypedPlutusCore.Purity
  • Pretty TextDefined in prettyprinter-1.7.2 · Prettyprinter.Internal

    Automatically converts all newlines to line.

    Example1 expression
    pretty ("hello\nworld" :: Text)helloworld

    Note that line can be undone by group:

    Example1 expression
    group (pretty ("hello\nworld" :: Text))hello world

    Manually use hardline if you definitely want newlines.

  • Pretty TextDefined in prettyprinter-1.7.2 · Prettyprinter.Internal

    (lazy Text instance, identical to the strict version)

  • Pretty ()Defined in prettyprinter-1.7.2 · Prettyprinter.Internal
    Example1 expression
    pretty ()()

    The argument is not used:

    Example1 expression
    pretty (error "Strict?" :: ())()
  • Show fun => Pretty (ExBudgetCategory fun)Defined in plutus-core-1.70.0.0 · UntypedPlutusCore.Evaluation.Machine.Cek.Internal
  • PrettyClassic a => Pretty (EvaluationResult a)Defined in plutus-core-1.70.0.0 · PlutusCore.Evaluation.Result
  • PrettyReadable a => Pretty (AsReadable a)Defined in plutus-core-1.70.0.0 · PlutusCore.Pretty.Readable
  • Pretty (BuiltinSemanticsVariant DefaultFun)Defined in plutus-core-1.70.0.0 · PlutusCore.Default.Builtins
  • Pretty (DefaultUni a)Defined in plutus-core-1.70.0.0 · PlutusCore.Default.Universe
  • Pretty (SomeTypeIn DefaultUni)Defined in plutus-core-1.70.0.0 · PlutusCore.Default.Universe
  • Pretty (SomeTypeIn uni) => Pretty (SomeTypeIn (Kinded uni))Defined in plutus-core-1.70.0.0 · PlutusCore.Pretty.PrettyConst · orphan
  • Pretty a => Pretty (NonEmpty a)Defined in prettyprinter-1.7.2 · Prettyprinter.Internal
  • Pretty a => Pretty (Identity a)Defined in prettyprinter-1.7.2 · Prettyprinter.Internal
    Example1 expression
    pretty (Identity 1)1
  • Pretty a => Pretty (Maybe a)Defined in prettyprinter-1.7.2 · Prettyprinter.Internal

    Ignore Nothings, print Just contents.

    Example2 expressions
    pretty (Just True)Truebraces (pretty (Nothing :: Maybe Bool)){}
    Example1 expression
    pretty [Just 1, Nothing, Just 3, Nothing][1, 3]
  • Pretty a => Pretty (Spine a)Defined in plutus-core-1.70.0.0 · PlutusCore.Builtin.KnownType
  • Pretty a => Pretty (Normalized a)Defined in plutus-core-1.70.0.0 · PlutusCore.Core.Type
  • Pretty a => Pretty [a]Defined in prettyprinter-1.7.2 · Prettyprinter.Internal
    Example1 expression
    pretty [1,2,3][1, 2, 3]
  • Pretty ann => Pretty (Kind ann)Defined in plutus-core-1.70.0.0 · PlutusCore.Core.Instance.Pretty.Default · orphan
  • Pretty ann => Pretty (UniqueError ann)Defined in plutus-core-1.70.0.0 · PlutusCore.Error
  • (Show fun, Ord fun) => Pretty (CekExTally fun)Defined in plutus-core-1.70.0.0 · UntypedPlutusCore.Evaluation.Machine.Cek.ExBudgetMode
  • (Show fun, Ord fun) => Pretty (TallyingSt fun)Defined in plutus-core-1.70.0.0 · UntypedPlutusCore.Evaluation.Machine.Cek.ExBudgetMode
  • ann ~ Void => Pretty (Doc ann)Defined in prettyprinter-1.7.2 · Prettyprinter.Internal
  • DefaultPrettyBy config a => Pretty (AttachDefaultPrettyConfig config a)Defined in prettyprinter-configurable-1.36.0.0 · Text.PrettyBy.Internal
  • PrettyBy config a => Pretty (AttachPrettyConfig config a)Defined in prettyprinter-configurable-1.36.0.0 · Text.PrettyBy.Internal
    Example4 expressions
    data Cfg = Cfgdata D = Dinstance PrettyBy Cfg D where prettyBy Cfg D = "D"pretty $ AttachPrettyConfig Cfg DD
  • (Closed uni, Everywhere uni PrettyConst) => Pretty (ValueOf uni a)Defined in plutus-core-1.70.0.0 · PlutusCore.Pretty.PrettyConst · orphan
  • (Closed uni, Everywhere uni PrettyConst) => Pretty (Some (ValueOf uni))Defined in plutus-core-1.70.0.0 · PlutusCore.Pretty.PrettyConst · orphan
  • (Pretty a, Pretty b) => Pretty (Either a b)Defined in plutus-core-1.70.0.0 · PlutusPrelude · orphan
  • (Pretty a1, Pretty a2) => Pretty (a1, a2)Defined in prettyprinter-1.7.2 · Prettyprinter.Internal
    Example1 expression
    pretty (123, "hello")(123, hello)
  • (Pretty err, Pretty cause) => Pretty (ErrorWithCause err cause)Defined in plutus-core-1.70.0.0 · PlutusCore.Evaluation.ErrorWithCause
  • (Pretty structural, Pretty operational) => Pretty (EvaluationError structural operational)Defined in plutus-core-1.70.0.0 · PlutusCore.Evaluation.Error
  • Pretty (CekState uni fun ann)Defined in plutus-core-1.70.0.0 · UntypedPlutusCore.Evaluation.Machine.SteppableCek.Internal
  • Pretty a => Pretty (Const a b)Defined in prettyprinter-1.7.2 · Prettyprinter.Internal
  • (PrettyClassic tyname, PrettyParens (SomeTypeIn uni), Pretty ann) => Pretty (Type tyname uni ann)Defined in plutus-core-1.70.0.0 · PlutusCore.Core.Instance.Pretty.Default · orphan
  • (Pretty a1, Pretty a2, Pretty a3) => Pretty (a1, a2, a3)Defined in prettyprinter-1.7.2 · Prettyprinter.Internal
    Example1 expression
    pretty (123, "hello", False)(123, hello, False)
  • (Pretty err, Pretty a, Pretty b) => Pretty (HeadSpine err a b)Defined in plutus-core-1.70.0.0 · PlutusCore.Builtin.KnownType
  • (PrettyClassic name, PrettyUni uni, Pretty fun, Pretty ann) => Pretty (Program name uni fun ann)Defined in plutus-core-1.70.0.0 · UntypedPlutusCore.Core.Instance.Pretty.Default · orphan
  • (PrettyClassic name, PrettyUni uni, Pretty fun, Pretty ann) => Pretty (Term name uni fun ann)Defined in plutus-core-1.70.0.0 · UntypedPlutusCore.Core.Instance.Pretty.Default · orphan
  • (Pretty a1, Pretty a2, Pretty a3, Pretty a4) => Pretty (a1, a2, a3, a4)Defined in prettyprinter-1.7.2 · Prettyprinter.Internal
    Example1 expression
    pretty (123, "hello", False, ())(123, hello, False, ())
  • (PrettyClassic tyname, PrettyClassic name, PrettyUni uni, Pretty fun, Pretty ann) => Pretty (Program tyname name uni fun ann)Defined in plutus-core-1.70.0.0 · PlutusCore.Core.Instance.Pretty.Default · orphan
  • (PrettyClassic tyname, PrettyClassic name, PrettyUni uni, Pretty fun, Pretty ann) => Pretty (Term tyname name uni fun ann)Defined in plutus-core-1.70.0.0 · PlutusCore.Core.Instance.Pretty.Default · orphan
  • (Pretty a1, Pretty a2, Pretty a3, Pretty a4, Pretty a5) => Pretty (a1, a2, a3, a4, a5)Defined in prettyprinter-1.7.2 · Prettyprinter.Internal
    Example1 expression
    pretty (123, "hello", False, (), 3.14)(123, hello, False, (), 3.14)
  • (Pretty a1, Pretty a2, Pretty a3, Pretty a4, Pretty a5, Pretty a6) => Pretty (a1, a2, a3, a4, a5, a6)Defined in prettyprinter-1.7.2 · Prettyprinter.Internal
    Example1 expression
    pretty (123, "hello", False, (), 3.14, Just 2.71)(123, hello, False, (), 3.14, 2.71)
  • (Pretty a1, Pretty a2, Pretty a3, Pretty a4, Pretty a5, Pretty a6, Pretty a7) => Pretty (a1, a2, a3, a4, a5, a6, a7)Defined in prettyprinter-1.7.2 · Prettyprinter.Internal
    Example1 expression
    pretty (123, "hello", False, (), 3.14, Just 2.71, [1,2,3])(123, hello, False, (), 3.14, 2.71, [1, 2, 3])
typetype Precedence = Double
#

Fractional precedence, so that it's always possible to squeeze an operator precedence between two existing precedences. Ranges over [-20, 120]. A normal operator should have a precedence within [0, 100). It might be useful to have a negative precedence if you're trying to model some already existing system, for example in Haskell ($) has precedence 0, but clearly if b then y else f $ x should be rendered without any parens, hence the precedence of if_then_else_ is less than 0, i.e. negative.

The precedence of juxtaposition is 100. Normally you want juxtaposition to have the highest precedence, but some languages have operators that bind tighter than juxtaposition, e.g. Haskell's postfix _{_}: f z { x = y } means f (z {x = y}).

datadata Direction
#

Direction in which pretty-printing goes. For example in x + y x is pretty-printed to the left of + and y is pretty-printed to the right of +.

Instances2Eq, Show
  • Eq DirectionDefined in prettyprinter-configurable-1.36.0.0 · Text.Fixity.Internal
  • Show DirectionDefined in prettyprinter-configurable-1.36.0.0 · Text.Fixity.Internal
datadata FixityOver prec
#

Fixity of an operator.

We allow unary operators to have associativity, because it's useful to distinguish between an expression like -(-x) (unary minus, left-associative) and ~~b (boolean NOT, right-associative).

Associativity of unary operators also matters when pretty-printing expressions like (-x) + y, which is pretty-printed as -x + y, assuming unary minus has the same fixity as + (and both the operators are left-associative). I.e. unary minus is handled just like the binary one: (0 - x) + y is pretty-printed as 0 - x + y.

Postfix operators are handled similarly. E.g. if ! is left-associative, then (x!)! is pretty-printed as x!! and if it's right-associative -- (x!)!.

The data type is parameterized, so that the user can choose precedence to be integer/fractional, bounded/unbounded, etc (we could also allows operators to be partially or totally ordered, but at the moment prec is required to implement Ord, i.e. it has to be totally ordered). By default we go with bounded fractional precedence, see the main Text.Fixity module.

Instances2Eq, Show
  • Eq prec => Eq (FixityOver prec)Defined in prettyprinter-configurable-1.36.0.0 · Text.Fixity.Internal
  • Show prec => Show (FixityOver prec)Defined in prettyprinter-configurable-1.36.0.0 · Text.Fixity.Internal
datadata RenderContextOver prec
#

A context that an expression is being rendered in.

Instances3HasRenderContext, Eq, Show
classclass Render str where
#

A class for rendering Docs as string types.

Methods

Instances3Render
  • Render TextDefined in prettyprinter-configurable-1.36.0.0 · Text.PrettyBy.Default
  • Render TextDefined in prettyprinter-configurable-1.36.0.0 · Text.PrettyBy.Default
  • a ~ Char => Render [a]Defined in prettyprinter-configurable-1.36.0.0 · Text.PrettyBy.Default
typetype AnyToDoc config ann = forall a. PrettyBy config a => a -> Doc ann
#

The type of a general config-based pretty-printer.

newtypenewtype InContextM config a
#

A monad for precedence-aware pretty-printing.

Constructors

Instances6Profunctor, Monad, Functor, Applicative, MonadReader, IsString
newtypenewtype Sole a
#

A newtype wrapper around a introduced for its HasPrettyConfig instance.

Constructors

Instances4HasPrettyConfigName, HasPrettyConfig, MonadReader, HasPrettyDefaults
  • HasPrettyConfigName (Sole PrettyConfigName)Defined in plutus-core-1.70.0.0 · PlutusCore.Pretty.ConfigName
  • HasPrettyConfig (Sole config) configDefined in prettyprinter-configurable-1.36.0.0 · Text.PrettyBy.Fixity

    It's not possible to have HasPrettyConfig config config, because that would mean that every environment is a pretty-printing config on its own, which doesn't make sense. We could have an OVERLAPPABLE instance, but I'd rather not.

  • MonadReader (Sole config) (InContextM config)Defined in prettyprinter-configurable-1.36.0.0 · Text.PrettyBy.Fixity
  • type HasPrettyDefaults (Sole config) = HasPrettyDefaults configDefined in plutus-core-1.70.0.0 · PlutusCore.Pretty.Extra · orphan
datadata AttachPrettyConfig config a
#

A config together with some value. The point is to provide a Pretty instance for anything that has a PrettyBy config instance.

Constructors

Instances1Pretty
  • PrettyBy config a => Pretty (AttachPrettyConfig config a)Defined in prettyprinter-configurable-1.36.0.0 · Text.PrettyBy.Internal
    Example4 expressions
    data Cfg = Cfgdata D = Dinstance PrettyBy Cfg D where prettyBy Cfg D = "D"pretty $ AttachPrettyConfig Cfg DD
newtypenewtype IgnorePrettyConfig a
#

A newtype wrapper around a whose point is to provide a PrettyBy config instance for anything that has a Pretty instance.

Instances1PrettyBy
  • Pretty a => PrettyBy config (IgnorePrettyConfig a)Defined in prettyprinter-configurable-1.36.0.0 · Text.PrettyBy.Internal
    Example4 expressions
    data Cfg = Cfgdata D = Dinstance Pretty D where pretty D = "D"prettyBy Cfg $ IgnorePrettyConfig DD
classclass PrettyBy config a where
#

A class for pretty-printing values in a configurable manner.

A basic example:

Example5 expressions
data Case = UpperCase | LowerCasedata D = Dinstance PrettyBy Case D where prettyBy UpperCase D = "D"; prettyBy LowerCase D = "d"prettyBy UpperCase DDprettyBy LowerCase Dd

The library provides instances for common types like Integer or Bool, so you can't define your own PrettyBy SomeConfig Integer instance. And for the same reason you should not define instances like PrettyBy SomeAnotherConfig a for universally quantified a, because such an instance would overlap with the existing ones. Take for example

Example2 expressions
data ViaShow = ViaShowinstance Show a => PrettyBy ViaShow a where prettyBy ViaShow = pretty . show

with such an instance prettyBy ViaShow (1 :: Int) throws an error about overlapping instances:

• Overlapping instances for PrettyBy ViaShow Int
    arising from a use of ‘prettyBy’
  Matching instances:
    instance PrettyDefaultBy config Int => PrettyBy config Int
    instance [safe] Show a => PrettyBy ViaShow a

There's a newtype provided specifically for the purpose of defining a PrettyBy instance for any a: PrettyAny. Read its docs for details on when you might want to use it.

The PrettyBy instance for common types is defined in a way that allows to override default pretty-printing behaviour, read the docs of HasPrettyDefaults for details.

Methods

  • prettyBy :: config -> a -> Doc ann

    Pretty-print a value of type a the way a config specifies it. The default implementation of prettyBy is in terms of pretty, defaultPrettyFunctorBy or defaultPrettyBifunctorBy depending on the kind of the data type that you're providing an instance for. For example, the default implementation of prettyBy for a monomorphic type is going to be "ignore the config and call pretty over the value":

    Example3 expressions
    newtype N = N Int deriving newtype (Pretty)instance PrettyBy () NprettyBy () (N 42)42

    The default implementation of prettyBy for a Functor is going to be in terms of defaultPrettyFunctorBy:

    Example3 expressions
    newtype N a = N a deriving stock (Functor) deriving newtype (Pretty)instance PrettyBy () a => PrettyBy () (N a)prettyBy () (N (42 :: Int))42

    It's fine for the data type to have a phantom parameter as long as the data type is still a Functor (i.e. the parameter has to be of kind Type). Then defaultPrettyFunctorBy is used again:

    Example3 expressions
    newtype N a = N Int deriving stock (Functor) deriving newtype (Pretty)instance PrettyBy () (N b)prettyBy () (N 42)42

    If the data type has a single parameter of any other kind, then it's not a functor and so like in the monomorphic case pretty is used:

    Example3 expressions
    newtype N (b :: Bool) = N Int deriving newtype (Pretty)instance PrettyBy () (N b)prettyBy () (N 42)42

    Same applies to a data type with two parameters: if both the parameters are of kind Type, then the data type is assumed to be a Bifunctor and hence defaultPrettyBifunctorBy is used. If the right parameter is of kind Type and the left parameter is of any other kind, then we fallback to assuming the data type is a Functor and defining prettyBy as defaultPrettyFunctorBy. If both the parameters are not of kind Type, we fallback to implementing prettyBy in terms of pretty like in the monomorphic case.

    Note that in all those cases a Pretty instance for the data type has to already exist, so that we can derive a PrettyBy one in terms of it. If it doesn't exist or if your data type is not supported (for example, if it has three or more parameters of kind Type), then you'll need to provide the implementation manually.

  • prettyListBy :: config -> [a] -> Doc ann

    prettyListBy is used to define the default PrettyBy instance for [a] and NonEmpty a. In normal circumstances only the prettyBy function is used. The default implementation of prettyListBy is in terms of defaultPrettyFunctorBy.

Instances110PrettyBy, …
classclass HasPrettyConfig env config | env -> config where
#

A constraint for "config is a part of env".

Methods

Instances1HasPrettyConfig
  • HasPrettyConfig (Sole config) configDefined in prettyprinter-configurable-1.36.0.0 · Text.PrettyBy.Fixity

    It's not possible to have HasPrettyConfig config config, because that would mean that every environment is a pretty-printing config on its own, which doesn't make sense. We could have an OVERLAPPABLE instance, but I'd rather not.