[m-dev.] Type classes

Mark Brown mark at csse.unimelb.edu.au
Tue May 22 15:57:31 AEST 2007


On 22-May-2007, Ralph Becket <rafe at csse.unimelb.edu.au> wrote:
> For G12 I've defined two type classes
> 
> :- typeclass high_level_linear_solver(Solver) where [...].
> :- typeclass low_level_linear_solver(Solver) where [...].
> 
> I'd like to say that all low_level_linear_solvers are
> high_level_linear_solvers with something like this:
> 
> :- instance high_level_linear_solver(Solver)
> 	<= low_level_linear_solver(Solver)
> 	where [
> 		... implementation ...
> 	].
> 
> Of course I can't say this because instance arguments have to take the
> form type_name(TypeVar, TypeVar, ...).
> 
> Would this a useful thing to allow?  Would it have bad consequences?

The problem is that you would not ever be able to have any other instances
of high_level_linear_solver -- any other instance would overlap with this one.
Since you can only have one implementation of the high_level_linear_solver
methods, there would be no advantage to making it a typeclass.  Instead
just define one (global) predicate/function for each method, and place
low_level_linear_solver constraints where required.

So no, it would not be useful, as far as I can see.

Cheers,
Mark.

--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at csse.unimelb.edu.au
Administrative Queries: owner-mercury-developers at csse.unimelb.edu.au
Subscriptions:          mercury-developers-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the developers mailing list