[mercury-users] type class bug?

Mark Brown mark at cs.mu.OZ.AU
Thu Jun 22 12:48:43 AEST 2006


Hi Nick,

On 22-Jun-2006, Nicholas Nethercote <njn at csse.unimelb.edu.au> wrote:
> I have these declarations:
> 
>   :- typeclass pstr(T) where [ func pstr(T) = string ].
> 
>   :- instance pstr(raw_item)  where [ func(pstr/1) is pstr_raw_item  ].
>   :- instance pstr(type_expr) where [ func(pstr/1) is pstr_type_expr ].
>   %:- instance pstr(expr)      where [ func(pstr/1) is pstr_expr      ].
> 
> This compiles fine.
> 
> If I uncomment the last line, I get this error:
> 
>   Mercury/cs/zinc.c:1144: error: redefinition of 
>   'mercury_data_base_typeclass_info_zinc__pstr__arity1__pair__pair__arity2__'
>   Mercury/cs/zinc.c:1135: error: previous definition of 
>   'mercury_data_base_typeclass_info_zinc__pstr__arity1__pair__pair__arity2__' was here
> 

...

> The types 'type_expr' and 'expr' look like this:
> 
>   :- type type_expr == pair(raw_type_expr, src_locn).
>   :- type expr == pair(raw_expr, src_locn).
> 
> It seems like these are similar enough that Mercury gets confused.
> 
> Is this a bug?  I'm using:

It's a known limitation in the typeclass system when using equivalence
types.  Unfortunately, Julien's suggestion won't work because of another
limitation: the arguments of instances must be of the form foo(A, B, ...).

Try defining the above types as:

	:- type type_expr ---> raw_type_expr - src_locn.
	:- type expr ---> raw_expr - src_locn.

Or something similar using a better constructor than '-'/2.

Cheers,
Mark.

--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list