type Ordering = (_EQ, _LT, _GT); Eq = abstract class public function equal(x, y: T): boolean; virtual; begin Result := not notEqual(x, y); end; function notEqual(x, y: T) :boolean; virtual; begin Result := not equal(x, y); end; end; Ord = abstract class where EqT: Eq; public function compare(x, y: T): Ordering; virtual; begin var eqInst := __ConceptSingleton&.&Instance; if eqInst.equal(x, y) then Result := _EQ else if less(x, y) then Result := _LT else Result := _GT; end; function less(x, y: T): boolean; virtual; begin Result := compare(x, y) = _LT; end; function lessEqual(x, y: T): boolean; virtual; begin Result := compare(x, y) <> _GT; end; function greater(x, y: T): boolean; virtual; begin Result := compare(x, y) = _GT; end; function greaterEqual(x, y: T): boolean; virtual; begin Result := compare(x, y) <> _LT; end; function min(x, y: T): T; virtual; begin Result := lessEqual(x, y) ? x : y; end; function max(x, y: T): T; virtual; begin Result := lessEqual(x, y) ? y : x; end; end; Eq_integer = class(Eq) public function equal(x, y: integer): boolean; override; begin Result := x = y; end; end; Ord_integer = class(Ord) where EqT: Eq, constructor; public function compare(x, y:integer): Ordering; override; begin var eqInst := __ConceptSingleton&.&Instance; if eqInst.equal(x, y) then Result := _EQ else if x < y then Result := _LT else Result := _GT; end; end; function Max3(v1, v2, v3: T): T; where EqT: Eq, constructor; where OrdT: Ord, constructor; begin var eqInst := __ConceptSingleton&.&Instance; var ordInst := __ConceptSingleton&.&Instance; Result := ordInst.max(v1, ordInst.max(v2, v3)); end; begin writeln(Max3&>(1, 2, 3)) end.