[m-users.] Error instance Mercury
jfischer at opturion.com
Wed Jun 27 00:50:39 AEST 2018
On Tue, 26 Jun 2018, Maxime Gautin wrote:
> I have a compilation fail with the code I am studying. It is about an instance
> :- type token_list == list(token).
> :- instance parser_state(token_list) where [
> get_token(T,[T | Ts], Ts),
> unget_token(T, Ts) = [T | Ts]
> token is a type defined on another file.
> The typeclass is also declared on another file :
> :- typeclass parser_state(T) where [
> pred get_token(token, T, T),
> mode get_token(out, in, out) is det,
> func unget_token(token, T) = T,
> mode unget_token(in, in) = out is det
> And this is the error :
> imputgen_bin.m:061: In instance declaration for
> imputgen_bin.m:061: `int_parser.parser_state(list.list(scanner.token))':
> imputgen_bin.m:061: the first argument is a type whose first argument is not
> imputgen_bin.m:061: a variable.
> imputgen_bin.m:061: (Types in instance declarations must be functors with
> imputgen_bin.m:061: variables as arguments.)
> I am not very familiar with instance in Mercury, and I don't understand what I have to modify. I hope you can help me.
As Tomas mentioned you will need to define the token_list/0 type in way
that conforms with what the language allows to appear in the head of
type class instance declarations, so:
:- type token_list ---> token_list(list(token)).
And then the instance would be something like:
:- instance parser_state(token_list) where [
get_token(T,token_list([T | Ts]), token_list(Ts)),
unget_token(T, token_list(Ts)) = token_list[T | Ts])
(Based on you previous post you were using the 0.13 release which
incorrectly did not detect the error in the instance declaration;
you're getting the error now because that has been fixed in one
of the intervening releases.)
More information about the users