mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-22 04:43:53 +00:00
42 lines
794 B
Mathematica
42 lines
794 B
Mathematica
%---------------------------------------------------------------------------%
|
|
% vim: ts=4 sw=4 et ft=mercury
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- module coerce_instvar.
|
|
:- interface.
|
|
|
|
:- type foobar
|
|
---> foo
|
|
; bar.
|
|
|
|
:- type foo =< foobar
|
|
---> foo.
|
|
|
|
:- type fruit
|
|
---> apple
|
|
; orange
|
|
; lemon(foobar).
|
|
|
|
:- type citrus =< fruit
|
|
---> orange
|
|
; lemon(foo).
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
:- pred good(citrus::in(I), fruit::out(I)) is det.
|
|
|
|
good(X, Y) :-
|
|
Y = coerce(X),
|
|
(
|
|
Y = orange
|
|
;
|
|
Y = lemon(foo)
|
|
).
|
|
|
|
:- pred bad(fruit::in(I), citrus::out(I)) is det.
|
|
|
|
bad(X, Y) :-
|
|
Y = coerce(X).
|