27 lines
693 B
Text
27 lines
693 B
Text
:- module comparable.
|
|
:- interface.
|
|
:- import_module int, float, integer, list.
|
|
|
|
:- typeclass comparable(T) where [
|
|
pred '<'(T::in, T::in) is semidet,
|
|
pred '=<'(T::in, T::in) is semidet
|
|
].
|
|
:- instance comparable(int).
|
|
:- instance comparable(float).
|
|
:- instance comparable(integer).
|
|
:- instance comparable(list(T)) <= comparable(T).
|
|
|
|
:- implementation.
|
|
|
|
:- instance comparable(int) where [
|
|
pred('<'/2) is int.(<),
|
|
pred('=<'/2) is int.(=<)
|
|
].
|
|
% likewise for float and integer...
|
|
:- instance comparable(list(T)) <= comparable(T) where [
|
|
pred('<'/2) is lt, % the 'lt' above.
|
|
pred('=<'/2) is lte % 'lt' with: lte([], []).
|
|
].
|
|
|
|
% pred lt
|
|
% pred lte
|