[mercury-users] strange mmc behavior

Holger Krug hkrug at rationalizer.com
Thu Jul 26 07:04:45 AEST 2001


In modifying mercury-extras/lex I experienced some strange compiler
behavior. The modification of lex consists in introducing higher-order
functions into the lexemes. This makes it necessary to introduce
complicated modes for arguments containing lexemes. The problem I encountered
was the following:

:- module lex.

:- implementation.

:- pred live_lexeme_in_accepting_state(list(live_lexeme(Tok)),
                annotated_token(Tok)).
:- mode live_lexeme_in_accepting_state(in(live_lexeme_list),   
	                  out(annotated_token)) is semidet.

live_lexeme_in_accepting_state([L | Ls], Token) :-    % line 412
    ( if in_accepting_state(L)                        % line 413
      then Token = L ^ clxm_token
      else live_lexeme_in_accepting_state(Ls, Token)  % line 415
    ).

If the called predicate `in_accepting_state' is placed in module `lex'
all works fine. Difficulties arise immediately when I place
`in_accepting_state' into the separate sub-module `lex__lexeme'. In
this case the following error occurs:

lex.m:415: In clause for `live_lexeme_in_accepting_state(in((lex:live_lexeme_list)), out((lex:annotated_token)))':
lex.m:415:   mode error in conjunction. The next 2 error messages
lex.m:415:   indicate possible causes of this error.
lex.m:413: In clause for `live_lexeme_in_accepting_state(in((lex:live_lexeme_list)), out((lex:annotated_token)))':
lex.m:413:   in argument 1 of call to predicate `lex:lexeme:in_accepting_state/1':
lex.m:413:   mode error: variable `L' has instantiatedness `bound((lex:lexeme):compiled_lexeme(bound((lex:ignore) ; lex:t((func((ground -> ground)) = (free -> ground) is det))), ground, ground))',
lex.m:413:   expected instantiatedness was `(lex:live_lexeme)'.
lex.m:412: In clause for `live_lexeme_in_accepting_state(in((lex:live_lexeme_list)), out((lex:annotated_token)))':
lex.m:412:   in argument 2 of clause head:
lex.m:412:   mode error in unification of `HeadVar__2' and `Token'.
lex.m:412:   Variable `HeadVar__2' has instantiatedness `free',
lex.m:412:   variable `Token' has instantiatedness `free'.

What is strange in that error message is that both modes:
`(lex:live_lexeme)'
and
`bound((lex:lexeme):compiled_lexeme(bound((lex:ignore) ; lex:t((func((ground -> ground)) = (free -> ground) is det))), ground, ground))'
are exactly the same !

The second part of the error message: 
"mode error in unification of `HeadVar__2' and `Token'"
I also cannot understand.

-- 
Holger Krug
hkrug at rationalizer.com
--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list