mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-18 10:53:40 +00:00
31 lines
656 B
Mathematica
31 lines
656 B
Mathematica
%---------------------------------------------------------------------------%
|
|
% vim: ts=4 sw=4 et ft=mercury
|
|
%---------------------------------------------------------------------------%
|
|
%
|
|
% Test of switch detection with explicit existential quantification.
|
|
|
|
:- module some_switch.
|
|
:- interface.
|
|
|
|
:- type nat
|
|
---> o
|
|
; s(nat).
|
|
|
|
:- func add(nat, nat) = nat.
|
|
:- mode add(in, in) = in is semidet.
|
|
:- mode add(out, out) = in is multi.
|
|
:- mode add(in, in) = out is det.
|
|
|
|
:- implementation.
|
|
|
|
add(X, Y) = Z :-
|
|
(
|
|
X = o,
|
|
Z = Y
|
|
;
|
|
some [Xp] (
|
|
X = s(Xp),
|
|
Z = s(add(Xp, Y))
|
|
)
|
|
).
|