[m-users.] Inst error on !IO mode in DCG rule

Sean Charles (emacstheviking) objitsu at gmail.com
Mon May 17 06:36:32 AEST 2021


I have an error that I get a notion for the problem but I cannot fully understand the rue cause and what the solution is. I have written a tokeniser that works fine and hands back a list of tokens so I had to change my primitive DCG to use a list of tokens as input and I thought that I may as well pass in the !IO state so that as each command was detected it could print the output there and then and finish.

HOwever, I get the following error message and I don’t truly understand what it is trying to tell me:

repl.m:096: In clause for `execute(in, di, uo)':
repl.m:096:   in argument 1 of call to predicate `repl.parse_cmd'/4:
repl.m:096:   mode error: variable `STATE_VARIABLE_IO_16' has instantiatedness
repl.m:096:   `mostly_unique',
repl.m:096:   expected instantiatedness was `unique’.



    :- pred execute(string::in, io::di, io::uo) is det.

    execute(Input, !IO) :-
        lexer.on_string(chomp(Input), Lx, !IO),
        % dump_lexer(Lx, !IO),
        ( if lex_error(Lx) = yes(ok_eob) then
              io.format("DCG this: %s\n", [s(string(tokens(Lx)))], !IO),
96 ===>       ( if parse_cmd(!IO, tokens(Lx), _) % do I care what's left?
              then io.format("DID IT\n", [], !IO)
              else io.format("PARSE FAILED\n", [], !IO)
              )
        else
            io.format("%sERROR! %s\n”,
                [s(prompt), s(string(lex_error(Lx)))], !IO)
        ).


:- pred parse_cmd(io::di, io::uo, list(token)::in, list(token)::out) is det.

parse_cmd(!IO) —>
    ( if [(tk(_, "help"))] then
        {io.format("read the manual :|\n", [], !IO)}
    else
       {io.format("whatever.\n", [], !IO)},
       []
    ).

I tried using `mui` but that just elicited a different error so I realised I was playing in the dark at this point.
Any advice would be greatly appreciated at this point!

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurylang.org/archives/users/attachments/20210516/9d21cebc/attachment.html>


More information about the users mailing list