[mercury-users] Typeclasses & parameters

Peter Ross pro at missioncriticalit.com
Mon May 28 11:07:52 AEST 2007


On 5/25/07, Tomas By <tomas at basun.net> wrote:
> Hello everybody,
>
> Suppose I have two different types of trees:
>
> :- type tree1(V,E).
>
> :- type tree2(V,E).
>
> where V & E are vertex and edge labels, so it might be
> `tree1(string,string)' or enumeration types:
>
> :- type mytree == tree1(myvertex,myedge).
> :- type myvertex ---> a ; b ; c.
> :- type myedge ---> d ; e ; f.
>
> and I then define a typeclass, in order to write search functions etc
> that operate on all trees.
>
> :- typeclass tree(T) where [...].
> :- instance tree(tree1(_,_)).
> :- instance tree(tree2(_,_)).
>
> and that I also want a procedure such as:
>
> :- pred edge_label(T::in,E::out) is det.
>
> to get the edge label (of whatever type) from the tree (of whatever sort).
>
> Now, how do I tell the compiler that the E in the procedure is the
> same as the E in the type class?
>
I had a go at this, but no luck from my end.

I suspect that you need constructor classes

:-  constructorclass TREE(V, E) where [
    func edge_label(TREE(V, E)) = E
]
--------------------------------------------------------------------------
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