mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-18 02:43:40 +00:00
tests/accumulator/*.m:
tests/analysis_*/*.m:
tests/benchmarks*/*.m:
tests/debugger*/*.{m,exp,inp}:
tests/declarative_debugger*/*.{m,exp,inp}:
tests/dppd*/*.m:
tests/exceptions*/*.m:
tests/general*/*.m:
tests/grade_subdirs*/*.m:
tests/hard_coded*/*.m:
Make these tests use four-space indentation, and ensure that
each module is imported on its own line. (I intend to use the latter
to figure out which subdirectories' tests can be executed in parallel.)
These changes usually move code to different lines. For the debugger tests,
specify the new line numbers in .inp files and expect them in .exp files.
51 lines
1.0 KiB
Mathematica
51 lines
1.0 KiB
Mathematica
%---------------------------------------------------------------------------%
|
|
% vim: ts=4 sw=4 et ft=mercury
|
|
%---------------------------------------------------------------------------%
|
|
%
|
|
:- module implied_instance.
|
|
|
|
:- interface.
|
|
|
|
:- pred main(io__state::di, io__state::uo) is det.
|
|
|
|
:- import_module io.
|
|
|
|
:- implementation.
|
|
|
|
:- import_module int.
|
|
:- import_module list.
|
|
|
|
:- typeclass sumable(A) where [
|
|
pred p(A::in, int::out) is det
|
|
].
|
|
|
|
:- instance sumable(int) where [
|
|
pred(p/2) is copy_int
|
|
].
|
|
|
|
:- instance sumable(list(T)) <= sumable(T) where [
|
|
pred(p/2) is sum_int_list
|
|
].
|
|
|
|
main -->
|
|
{ p(2, SumA) },
|
|
{ p([42, 24, 1, 2, 3], SumB) },
|
|
io__write_int(SumA),
|
|
io__write_string("\n"),
|
|
io__write_int(SumB),
|
|
io__write_string("\n").
|
|
|
|
:- pred copy_int(int, int).
|
|
:- mode copy_int(in, out) is det.
|
|
|
|
copy_int(N, N).
|
|
|
|
:- pred sum_int_list(list(T), int) <= sumable(T).
|
|
:- mode sum_int_list(in, out) is det.
|
|
|
|
sum_int_list([], 0).
|
|
sum_int_list([X | Xs], Sum) :-
|
|
p(X, SumA),
|
|
sum_int_list(Xs, SumB),
|
|
Sum = SumA + SumB.
|