[mercury-users] inst problem

Holger Krug hkrug at rationalizer.com
Fri Jul 27 17:18:31 AEST 2001


Below there is code where I think mmc should infer a tighter inst than
it actually does. I do not understand, why the tighter inst isn't
inferred.

% The types

:- typeclass lexer_state(T) where [
	pred get_token(lexer_token, T, T),
	mode get_token(out, in, out) is det
].

:- type lexer_result(Token) = ok(Token)
			    ; eof
			    ; error(int).

:- type lexer_token == lexer_result(token).

% The inst at issue

:- inst non_error_lexer_token ---> ok(ground) ; eof.

% The calling predicate

:- pred parse(P, P, statestack, symbolstack,  presult) 
      <= lexer_state(P).
:- mode parse(in, out, in(statestack), in, out) is det.

% The predicate called

:- pred process_token(P, P, statestack, symbolstack, 
	      lexer_token, presult) 
      <= lexer_state(P).
:- mode process_token(in, out, in(statestack), in, 
		      in(non_error_lexer_token), out) is det.

% The code how it works

parse(Lex0, Lex, St, Sy, Res) :-
    (
        get_token(Tok, Lex0, Lex1),

        ( 
	    Tok = error(_)
            Res = error("lexer error"),
            Lex = Lex1
	;
	    Tok = ok(_),
	    process_token(Lex1, Lex, St, Sy, Tok, Res)
	;
	    Tok = eof,
	    process_token(Lex1, Lex, St, Sy, Tok, Res)
        )
    ).

% The code how is doesn't work. Why ?

parse(Lex0, Lex, St, Sy, Res) :-
    (
        get_token(Tok, Lex0, Lex1),

        ( 
	    Tok = error(_)
	->
            Res = error("lexer error"),
            Lex = Lex1
	;
	    process_token(Lex1, Lex, St, Sy, Tok, Res)
        )
    ).

mmc claimes:

expr.m:102: In clause for `parse(in, out, in((expr:statestack)), in, out)':
expr.m:102:   in argument 5 of call to predicate `expr:process_token/6':
expr.m:102:   mode error: variable `Tok' has instantiatedness `ground',
expr.m:102:   expected instantiatedness was `(expr:non_error_lexer_token)'.

Why isn't mmc able to infer, that `Tok' in the call to process_token/6
has the inst demanded ?

-- 
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