[m-dev.] type classes and the color blue
Ralph Becket
rbeck at microsoft.com
Sun Jan 9 03:56:24 AEDT 2000
> Does the following code make any sense at all:
>
> :- typeclass thing(T) where
> [
> pred is_blue,
> mode is_blue is semidet
> ].
>
> :- instance thing(sky) where
> [
> pred(is_blue/1) is semidet_succeed
> ].
>
> :- instance thing(sun) where
> [
> pred(is_blue/1) is semidet_fail
> ].
I can't see anything wrong, except that I don't
think semidet_succeed and semidet_fail take any
arguments (I haven't got the reference manual
handy at the mo.) But wrapping them up should
work:
:- instance thing(sky) where
[
pred(is_blue/1) is sky_is_blue
].
sky_is_blue(_) :- semidet_succeed.
> :- pred both_blue(A, B) <= (thing(A), thing(B)).
> :- mode both_blue(in, in) is semidet.
>
> both_blue(A, B) :- ... what can go here? ...
both_blue(A, B) :- is_blue(A), is_blue(B).
should do the trick.
> Is there a way to qualify methods by variable name?
Method calls are decided on a per-instance basis, so
what happens at runtime depends upon what type of thing/1
arguments are passed to both_blue/2. Each argument A
and B is accompanied by a hidden extra argument which
is used to work out which procedure to call for which
method.
Cheers,
Ralph
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions: mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------
More information about the developers
mailing list