Associativity of an operator.
Instances2Eq, Show
Eq AssociativityDefined in prettyprinter-configurable-1.36.0.0 · Text.Fixity.InternalShow AssociativityDefined in prettyprinter-configurable-1.36.0.0 · Text.Fixity.Internal
:: a typeCtrl KGHC 9.14.1 · lts/ghc-9.14.x · d82dee8 · 2026-10-12
Moduleprettyprinter-configurable-1.36.0.0Haskell2010
Precedence-general machinery for deciding whether an expression needs to be wrapped in parentheses or not. Source code has comments on the approach used and how it compares to some other known approaches.
Associativity of an operator.
Eq AssociativityDefined in prettyprinter-configurable-1.36.0.0 · Text.Fixity.InternalShow AssociativityDefined in prettyprinter-configurable-1.36.0.0 · Text.Fixity.InternalFixity 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.
Fixity_fixityAssociativity :: !Associativity_fixityPrecedence :: !precEq prec => Eq (FixityOver prec)Defined in prettyprinter-configurable-1.36.0.0 · Text.Fixity.InternalShow prec => Show (FixityOver prec)Defined in prettyprinter-configurable-1.36.0.0 · Text.Fixity.InternalDirection 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 +.
A context that an expression is being rendered in.
HasRenderContext RenderContextDefined in prettyprinter-configurable-1.36.0.0 · Text.PrettyBy.FixityEq prec => Eq (RenderContextOver prec)Defined in prettyprinter-configurable-1.36.0.0 · Text.Fixity.InternalShow prec => Show (RenderContextOver prec)Defined in prettyprinter-configurable-1.36.0.0 · Text.Fixity.InternalencloseIn :: Ord prec=> (a -> a)Enclose a value of type a in parens.
-> RenderContextOver precAn outer context.
-> FixityOver precAn inner fixity.
-> a-> aEnclose 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.