mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-15 22:03:26 +00:00
Estimated hours taken: 0.1
tests/valid/typeclasses/func_method.m:
Add a test case for a function as a typeclass method. The non-locals
were not being set correctly, which caused a software error in this
case.
tests/valid/typeclasses/Mmakefile:
Turn this test on.
23 lines
493 B
Mathematica
23 lines
493 B
Mathematica
%-----------------------------------------------------------------------------%
|
|
:- module func_method.
|
|
:- interface.
|
|
|
|
:- type pair(A, B) ---> pair(A, B).
|
|
|
|
:- typeclass c(A) where [
|
|
func op(pair(A, B)) = pair(A, B),
|
|
mode op(in) = out is det
|
|
].
|
|
|
|
:- instance c(int) where [
|
|
func(op/1) is op_int
|
|
].
|
|
|
|
:- implementation.
|
|
|
|
:- func op_int(pair(int, T)) = pair(int, T).
|
|
:- mode op_int(in) = out is det.
|
|
op_int(X) = X.
|
|
|
|
%-----------------------------------------------------------------------------%
|