[mercury-users] Higher-order types using typeclasses

Ondrej Bojar bojar at csse.unimelb.edu.au
Fri Mar 16 13:16:55 AEDT 2007


Hi,

I would like to abstract over container implementation when I am already 
abstracting over the element type.

If successful, I would be able to implement:

:- pred my_sample_predicate(ContainerOfX::in, X::out, ...)
        <= (container(ContainerOfX, X)) is ...

The container typeclass defines required operations on the container:

:- typeclass container(Cont, Elem) <= (Cont->Elem) where [
         pred get_a_member(Elem::out, Cont::in, Cont::out) is nondet,
         func count(Cont) = int
    ].

And I would instantiate the typeclass for various containers:

:- instance container(bag(X), X) where [
      pred(get_a_member/3) is bag_nondet_member,
      func(count/1) is bag_count
    ].

However, the intended instantiation is not possible:

t_drop_fr_reins.m:492: Error: types in instance declarations must be functors wi
th distinct variables as arguments: container(bag(_1), _1).

Are there any fundamental reasons for the restriction?
Is there a way to overcome the restriction in the current Mercury implementation?

Thanks, Ondrej.

-- 
Ondrej Bojar (mailto:obo at cuni.cz / bojar at ufal.mff.cuni.cz)
http://www.cuni.cz/~obo
--------------------------------------------------------------------------
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