tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
|
|
@ -0,0 +1,3 @@
|
|||
:- pred lt(list(int)::in, list(int)::in) is semidet.
|
||||
lt([], [_|_]).
|
||||
lt([H1|T1], [H2|T2]) :- H1 =< H2, T1 `lt` T2.
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
:- pred lt(list(T)::in, list(T)::in) is semidet <= comparable(T).
|
||||
lt([], [_|_]).
|
||||
lt([H1|T1], [H2|T2]) :- H1 =< H2, T1 `lt` T2.
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
:- 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
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
:- pred test(list(T), list(T), io, io) <= comparable(T).
|
||||
:- mode test(in, in, di, uo) is det.
|
||||
test(A, B) -->
|
||||
io.write(A), io.write_string(" < "), io.write(B),
|
||||
io.write_string(" : "), io.write_string(S), io.nl,
|
||||
{ A < B -> S = "yes" ; S = "no" }.
|
||||
Loading…
Add table
Add a link
Reference in a new issue