HORIZON HASKELLDocslts/ghc-10.0.x8fef28d2026-11-02Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8fef28d · 2026-11-02

Nat expressions <-> SOP terms

newtypenewtype CType
#

Constructors

Instances3Eq, Ord, Outputable
  • Eq CTypeDefined in ghc-typelits-natnormalise-0.9.7 · GHC.TypeLits.Normalise.Unify
  • Ord CTypeDefined in ghc-typelits-natnormalise-0.9.7 · GHC.TypeLits.Normalise.Unify
  • Outputable CTypeDefined in ghc-typelits-natnormalise-0.9.7 · GHC.TypeLits.Normalise.Unify

Substitution on SOP terms

A substitution is essentially a list of (variable, SOP) pairs, but we keep the original Ct that lead to the substitution being made, for use when turning the substitution back into constraints.

Find unifiers

datadata UnifyResult

Result of comparing two SOP terms, returning a potential substitution list under which the two terms are equal.

Constructors

  • Win

    Two terms are equal

  • Lose

    Two terms are not equal

  • Draw [CoreUnify]

    Two terms are only equal if the given substitution holds

Instances1Outputable

Find unifiers for two SOP terms

Can find the following unifiers:

t ~ a + b          ==>  [t := a + b]
a + b ~ t          ==>  [t := a + b]
(a + c) ~ (b + c)  ==>  a := b
(2*a) ~ (2*b)      ==>  [a := b]
(2 + a) ~ 5        ==>  [a := 3]
(i * a) ~ j        ==>  [a := div j i], when (mod j i == 0)

However, given a wanted:

[W] t ~ a + b

this function returns [], or otherwise we "solve" the constraint by finding a unifier equal to the constraint.

However, given a wanted:

[W] (a + c) ~ (b + c)

we do return the unifier:

[a := b]

Free variables in SOP terms

Inequalities

Subtract an inequality, in order to either:

  • See if the smallest solution is a natural number

  • Cancel sums, i.e. monotonicity of addition

subtractIneq (2*y <=? 3*x ~ True)  = 3*x + (-2)*y
subtractIneq (2*y <=? 3*x ~ False) = -3*x + (-2)*y
valuesolveIneq
  1. :: Word

    Solving depth

  2. -> Ineq

    Inequality we want to solve

  3. -> Ineq

    Given/proven inequality

  4. -> WriterT (Set CType) Maybe Bool

    Solver result

    • Nothing: exhausted solver steps

    • Just True: inequality is solved

    • Just False: solver is unable to solve inequality, note that this does not mean the wanted inequality does not hold.

Try to solve inequalities

Properties

Is this a natural number?

  • Just True = definitely a natural number

  • Just False = definitely not a natural number

  • Nothing = not sure

The 'Set CType' writer accumulator returns inner types that must also be positive for the overall CoreSOP to be positive.