10.22.4.2 Restricted Term Classes

The intention of the rgb_color class presented above is to represent a
color as a triple of floating point numbers between 0.0 and 1.0.
But the above definition does not restrict the arguments of the
color term in any way: anycolor/3 term is considered
to be an instance of the rgb_color class.

The second form of term class declaration allows you to specify
constraints on instances of a term class. The form of such a
declaration is as follows:

:- class ClassName = term(Term, Constraint).

This declares that any term that unifies with Term and satisfies
Constraint is an instance of class ClassName. The
Constraint term is an ordinary Prolog goal, which will usually
share variables with Term.

To extend our rgb_color class example so that only color/3
terms whose arguments are all floats between 0.0 and 1.0 are instances
of rgb_color, we would instead begin the definition as follows: