[mercury-users] some [T] ...
Mark Brown
dougl at cs.mu.OZ.AU
Mon Nov 18 16:39:20 AEDT 2002
On 18-Nov-2002, Michael Day <mikeday at yeslogic.com> wrote:
>
> > :- type abc ---> a ; b ; c.
> >
> > :- subtype ab < abc ---> a ; b.
>
> By "including those inside typeclass declarations" did you mean that I
> could declare the following type class:
>
> :- typeclass foo(T) where [ func foo(T) = string ].
>
> and make ab an instance of it?
>
> :- instance foo(ab).
No, that would be disallowed. What I mean is that you would be allowed to
refer to subtypes inside the pred/func declarations in the 'where [ ... ]'
part of a typeclass definition. So you could write:
:- typeclass bar(T) where [ func bar(T, ab) = string ].
While you would not be allowed to write something like
:- instance foo(ab),
you could still call a method of this typeclass on the subtype ab, provided
that abc is declared to be a instance of foo, and the method is
polymorphically moded. In this respect method calls are no different
to ordinary calls.
> > :- pred q(z(ab), io, io).
> > :- mode q(in, di, uo) is det.
> >
> > becomes
> >
> > :- pred q(z_rep(abc), io, io) is det.
> > :- mode q(in(bound(z(Z))), di, uo) is det.
>
> Wow, so does that mean I could have lists and maps and god knows what else
> all containing predicates? Is it possible to say:
>
> :- pred q(list(z(ab)), io, io).
> :- mode q(in, di, uo) is det.
>
> and everything just works?
Yes, provided the mode that results from propagating the subtype
information into the existing mode is a valid one. As Fergus mentioned,
though, you wouldn't easily be able to use lists/maps from the current
version of the standard library. See the recent discussion on the
mercury-developers mailing list for one proposal of how we may deal with
this.
Cheers,
Mark.
--------------------------------------------------------------------------
mercury-users mailing list
post: mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the users
mailing list