[m-users.] Using one out parameter to compute another

Philip White philipwhite at cedarville.edu
Sat Aug 24 05:24:23 AEST 2019


Below is my code:

:- pred parse_statement(src::in,
                        ast_statement::out,
                        ps::in, ps::out) is semidet.
parse_statement(Src, Statement, InitialPS, OutPS) :-
  current_offset(Src, Start, InitialPS, _),
  current_offset(Src, End, OutPS, _), <--- error is right here.
  Range = range(Start, End),
  (
    if
      parse_identifier(Src, Identifier, InitialPS, IdentPS),
      punct("=", Src, _, IdentPS, PunctPS),
      parse_term(Src, Term, PunctPS, TermPS)
    then
      OutPS = TermPS,
      Statement = definition(Identifier, Term, Range)
    else
      parse_term(Src, Term, InitialPS, OutPS),
      Statement = term(Term, Range)
  ).

I am receiving the error:

In clause for `parse_statement(in, out, in, out)': 
in argument 3 of call to predicate `parsing_utils.current_offset'/4: 
mode error: variable `OutPS' has instantiatedness     `free', 
                        expected instantiatedness was `ground'.

I understand the error, but I'm suprised that I am disappointed that I
am not allowed to do this. The resulting value of `ast_statement`
depends on the resulting value of `ps` because I want statements to
track what part of the file they span. Although the instantiatedness of
`OutPS` is free, can't the compiler tell that it will "eventually become
ground" (that's probably not proper terminology) and that there are no
cyclic dependencies between variables?

Am I missing some logical error in my code, or is it just a limitation
of the compiler?

- Philip


More information about the users mailing list