Constraint

In general, a constraint is something that must hold between values, like "the discount is at most a fifth of the total". A validator is the simplest use of one: all the values are there, and you ask yes or no.

In Bondy, constraint is also one of the roles a value can play: a fact you add to a store for rules to act on. Rules match constraints, keep them, or replace them. The role and its rules come from Constraint Handling Rules (CHR), the language Thom Frühwirth created in 1991.[1]

bondy
constraint Bucket = {id: String, tokens: Int, max_tokens: Int}

A constraint can do more than check. Given discount ≤ total × 0.20 and discount = 50, it follows that total ≥ 250: the same fact, used in the other direction. In Bondy, a condition on a type is checked one way, when a value is built. Rules over a constraint store are how you work in other directions.

Not to be confused with a relation: a relation holds facts you look up, a store of constraints holds facts that rules act on.


  1. Thom Frühwirth, "Theory and Practice of Constraint Handling Rules", Journal of Logic Programming 37(1–3), 1998, and Constraint Handling Rules, Cambridge University Press, 2009. ↩︎