concept constraint in category probabilistic programming

This is an excerpt from Manning's book Practical Probabilistic Programming.
Figaro provides a rich framework for specifying evidence by using its conditions and constraints.
This is achieved using a constraint. A constraint is a function from the value of an element to a Double. Although this isn’t enforced by Figaro, constraints work best when the value of this function is always between 0 and 1 (inclusive). For example, to express evidence that my mood appears to be grumpy but you’re not sure, you could add a constraint to goodMood that produces a value of 0.5 when goodMood is true and 1.0 when goodMood is false:
Now let’s add the constraints. You’ll define a makeStreaky function that takes two results and adds a streakiness constraint to them:
def makeStreaky(r1: Element[Boolean], r2: Element[Boolean]) { val pair = Apply(r1, r2, (b1: Boolean, b2: Boolean) => (b1, b2)) pair.setConstraint((bb: (Boolean, Boolean)) => if (bb._1 == bb._2) 1.0; else 0.5 )}This function takes two Boolean elements as arguments, representing the results of two games. Because a constraint can be applied to only a single element, and you want to use a constraint to create a relationship between both elements, you first package the two elements into a single element whose value is a pair. This is achieved by Apply(r1, r2, (b1: Boolean, b2: Boolean) => (b1, b2)). Now you have a single element whose value is a pair of the results of the two games. You then set the constraint of the pair to the function that takes a pair bb of Booleans and returns 1.0 if bb._1 == bb._2 (the first and second components of the pair are equal), and returns 0.5 otherwise. This constraint says that, all else being equal, the two results are twice as likely to be the same as different.
By now, I’ve gone into a fair amount of detail about how to build models. Much of your energy when using Figaro will be spent on creating models. But let’s not ignore specifying evidence. Figaro provides three mechanisms for specifying evidence: observations, conditions, and constraints.