[m-users.] Error: non-abstract instance declaration in module interface.

Zoltan Somogyi zoltan.somogyi at runbox.com
Thu Feb 3 09:08:57 AEDT 2022


2022-02-03 08:39 GMT+11:00 "Sean Charles (emacstheviking)" <objitsu at gmail.com>:
> Here is my awful attempt,  syntax_error, error_msg are types defined elsewhere as is the function nowhere,

Actually, that attempt is not awful; it is in fact pretty good.

> :- typeclass tstring(T) where [
>     func make_error(T::in, error_msg::in) = (syntax_error::out) is det
> ].
>
> :- instance tstring(leaf) where [   LINE 73 <===
>     make_error(_X, E) = syntax_error(nowhere, error, E)
> ].
> 
> ...which gives this error:
> 
> datatypes.m:073: Error: non-abstract instance declaration in module interface.
> Making Mercury/ints/datatypes.int
> datatypes.m:073: Error: non-abstract instance declaration in module interface.
> ** Error making `Mercury/ints/datatypes.int'.
> make[2]: *** [felt] Error 1

If you got that error, then line 73 was in the interface section of its module.
Instance declarations that specify the implementations of the class methods
are allowed only in the implementation sections of their module; interface
sections may contain only *abstract* instance declarations, which do not do so.
In this case, you should move the instance declaration above to the implementation
section, and replace it in the interface with its abstract version, which is
just ":- instance tstring(leaf).".

This requirement should have been described in section 10.2 of the
reference manual, but I see it hasn't been. I will look into fixing that,
and will also add a mention of this fix to the above error message.

Zoltan.


More information about the users mailing list