[mercury-users] Present state of type classes - especially for parametrized types

Ralph Becket rafe at csse.unimelb.edu.au
Sun Oct 8 16:47:11 AEST 2006


J?rg Roman Rudnick, Saturday,  7 October 2006:
> 
> But a question remains: Frankly, I assume 'naked' type variables are not 
> acceptable by the instance declarations, so that the element type of a 
> collection needs either to be ground or some parametrized type. Ok, ok...

The reference manual is quite clear on this one, I thought.  A
declaration of the form

:- instance my_type_class(T) ...

would indicate that all types are instances of my_type_class since T
unifies with anything.

> But how about letting the collection be parametrized by the same type -- 
> e.g., in the example below 'list(container(T))'??
> 
> Of course, such a nesting appears illegal,

The current rules are as generous as we know how to enforce them.  One
of the problems with your request is how to handle cases where an
instance declaration in another module declares

:- instance fringe(list(T), ...) ...

How should the compiler reconcile this with a declaration

:- instance fringe(list(container(T)), ...) ...?

> but I hope there are ways to 
> write such an instance declaration like
> 
> :-instance fringe(list(T_1), container(T2)) ... ?? ...,
> 
> so that, maybe by setting a type class for T_1, a T_1 can be handled as 
> a container(T_2).
> 
> Has anybody any idea how to realize that?

Can you solve your problem using functional dependencies?
--------------------------------------------------------------------------
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