[m-users.] Error: non-abstract instance declaration in module interface.
Sean Charles (emacstheviking)
objitsu at gmail.com
Thu Feb 3 08:39:26 AEDT 2022
I am trying t ouse typeclasses for the first time ever and, well, it's not been the happy time I wanted !
I have a bunch of types for the arguments for the various rendering instructions and I wanted to be able to have a uniform means to generate error messages and other actions across that set of types, for example:
:- type leaf
---> tk(location, string)
; kw(location, string)
; s1(location, string)
; s2(location, string).
:- type arglist_spec
---> arg_leaf(leaf)
; arg_def(ps, render_inst)
; arg_ref(ps).
:- type gencall_spec
---> gc_leaf(leaf)
; gc_arg(render_inst)
; gc_keyword(ps, render_inst) % python-like, foo=bar
; gc_ref(ps). % C or PHP: &foo
:- type call_term
---> ct_leaf(leaf)
; ct_inst(render_inst).
The plan was to be able to call something like `make_error` with one of the above, by supplying the error code and the instance that was being rejected, something like:
Error = make_error(TheInstance, incorrect_form_error)
and so I have tried many things, all of them wrong, but I seme to have exhausted the number of wrong ways of doing it without actually finding the correct way to do it. I am still not sure my use case is even what typeclasses are for but it feels correct, from the reference manual section 10.1,
A type class is a name for a set of types (or a set of sequences of types) for which cer- tain predicates and/or functions, called the methods of that type class, are defined. A ‘typeclass’ declaration defines a new type class, and specifies the set of predicates and/or functions that must be defined on a type (or sequence of types) for it (them) to be considered to be an instance of that type class.
so if I have understood it, my set of types are the ones listed above, and the methods (one so far) are make_error so far. I also want to have a function to return a string representation of each instance as well.
Here is my awful attempt, syntax_error, error_msg are types defined elsewhere as is the function nowhere,
:- 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
Thanks,
Sean.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurylang.org/archives/users/attachments/20220202/6e78f9ea/attachment.html>
More information about the users
mailing list