[mercury-users] Det/Semidet

Jörg Roman Rudnick joerg.rudnick at t-online.de
Sat Dec 9 04:59:08 AEDT 2006


Hi Nigel,


I am afraid I do not understand what you intend to, but as long as comes 
to just embedding semidet's into main/2 - here a proposal:

:- module marray.

:- interface.

:- import_module io.

:- pred main(io::di, io::uo) is det.

:- implementation.

:- import_module list, string, array2d, int.

main(!IO) :-
    new(5,5,["XXX"]) = MyArray,
    MyList = ["the","cat","chased","the","dog"],
    (if add_input_string(MyList,MyArray, 0) then
        write_string("here could be a success handling...\n", !IO)
    else
        write_string("here could be a failure handling...\n", !IO)
    ).


:- pred add_input_string(list(string)::in, 
array2d(list(string))::array2d_di, int::in) is semidet.
add_input_string(TheList, Array, Number) :-
    TheList = [Head|Tail],
    ( Array ^ elem(0,Number) := [Head] ) = T3,
    NextNumber is Number + 1,
    add_input_string(Tail,T3,NextNumber).


Cheers,

    Nick
--------------------------------------------------------------------------
mercury-users mailing list
Post messages to:       mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions:          mercury-users-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the users mailing list