[m-dev.] Re: semidet predicate with io__state and state variable syntax bug

Ralph Becket rafe at cs.mu.OZ.AU
Wed Mar 24 11:00:43 AEDT 2004


I had a quick look at this one using the latest ROTD installed on ceres and
(a) it does indeed compile when it shouldn't, 
(b) the problem does not appear to be in the state variable
transformation.

Here is the desugared state variable version of main/2:

state.main(STATE_VARIABLE_IO_0_4, STATE_VARIABLE_IO_5) :-
        ( % conjunction
                (if
                        ( % conjunction
                                V_10 = 1 ,
                                V_12 = 2 ,
                                V_13 = list.[] ,
                                V_11 = list.[V_12 | V_13] ,
                                V_7 = list.[V_10 | V_11] ,
                                V_8 = STATE_VARIABLE_IO_0_4 ,
                                state.semidet_io(V_7, V_8, V_9) ,
                                V_9 = STATE_VARIABLE_IO_1_6
                        )
                then
                        STATE_VARIABLE_IO_3_19 = STATE_VARIABLE_IO_1_6
                else
                        ( % conjunction
                                V_15 = "Failed.\n" ,
                                V_16 = STATE_VARIABLE_IO_0_4 ,
                                io.write_string(V_15, V_16, V_17) ,
                                V_17 = STATE_VARIABLE_IO_1_21 ,
                                STATE_VARIABLE_IO_3_19 = STATE_VARIABLE_IO_1_21
                        )
                ) ,
                STATE_VARIABLE_IO_5 = STATE_VARIABLE_IO_3_19
        ).

I can't see anything wrong with this (although it does look like state
variable transformation might cause us to lose tail recursion in some 
cases...)

Here is the DCG version:

tate.main(DCG_0_3, DCG_3_6) :-
        (if
                ( % conjunction
                        V_8 = 1 ,
                        V_10 = 2 ,
                        V_11 = list.[] ,
                        V_9 = list.[V_10 | V_11] ,
                        V_7 = list.[V_8 | V_9] ,
                        state.semidet_io(V_7, DCG_0_3, DCG_1_4)
                )
        then
                DCG_1_4 = DCG_3_6
        else
                ( % conjunction
                        V_12 = "Failed.\n" ,
                        io.write_string(V_12, DCG_0_3, DCG_3_6)
                )
        ).

Up to variable renaming and having the final unification in the state
variable version folded into the arms of the if-then-else, these two
look identical to me.

I'm busy at the moment working on solver types - does anyone else have a
minute to look into this one?

-- Ralph

Peter Ross, Tuesday, 23 March 2004:
> See the attached file for a program which compiles, that shouldn't.
> 
>     mmake state.depend
>     mmake EXTRA_MCFLAGS=-O-1 state

> %------------------------------------------------------------------------------%
> 
> :- module state.
> :- interface.
> 
> :- import_module io.
> 
> :- pred main(io::di, io::uo) is det.
> 
> %------------------------------------------------------------------------------%
> 
> :- implementation.
> :- import_module list.
> 
> 
> % No mostly unique mode error reported.
> main(!IO) :-
> 	( semidet_io([1,2], !IO) ->
> 		true
> 	;
> 		io__write_string("Failed.\n", !IO)
> 	).
> /* XXX this does report an error.
> main -->
> 	( semidet_io([1,2]) ->
> 		[]
> 	;
> 		io__write_string("Failed.\n")
> 	).
> */
> 
> 	
> 
> :- pred semidet_io(list(int)::in, io::di, io::uo) is semidet.
> 
> semidet_io(L, !IO) :-
> 	L = [_],
> 	io__write_string("Success.\n", !IO).
> 
> %------------------------------------------------------------------------------%

--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list