[mercury-users] Typeclass question
Chris King
colanderman at gmail.com
Sun Mar 6 14:51:35 AEDT 2011
Say I have a typeclass foo(A). Making a container type bar(A) for
items of this typeclass is easy, as I can place a universal typeclass
constraint foo(A) on all predicates over bar(A) which produce values
of type A. (Although it would be nice to be able to place the
constraint on the declaration of bar(A) itself as recently discussed
this is not supported.)
Now my question is: how do I abstract bar(A) as a typeclass itself?
Intuitively I should be able to write:
:- typeclass bar(Bar, A) <= (Bar -> A) where [...].
:- type bar_impl(A).
:- instance bar(bar_impl(A), A) <= foo(A).
but of course the compiler balks at the unadorned A in the instance
declaration. Instead one could try with existential types:
:- all [A] some [Bar] (pred create_bar(Bar::out) is det => bar(Bar,
A)) <= foo(A).
but now the compiler complains that A is "existentially constrained,
but is universally quantified." Which is true, but nonetheless
frustrating.
For reference, what I wish to achieve is easily representable with
functors in ML:
module type Foo: sig type a end
module Bar(F: Foo): sig type a = F.a ... end
What is the proper way to accomplish what I have in mind? If there is
none, is this a current limitation of the Mercury compiler or
something deeper and irreconcilable?
Thanks,
Chris
--------------------------------------------------------------------------
mercury-users mailing list
Post messages to: mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions: mercury-users-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the users
mailing list