RosettaCodeData/Task/Order-two-numerical-lists/Mercury/order-two-numerical-lists-3.mercury
Ingy döt Net b83f433714 tasks a-s
2013-04-10 23:57:08 -07:00

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