[mercury-users] cant import int altthough i have the import command...

Ralph Becket rafe at cs.mu.OZ.AU
Fri Mar 19 10:32:45 AEDT 2004

Hi Stefan,

Stefan Hinterstoisser, Thursday, 18 March 2004:
> Hi there!
> I wrote following program:
> :- module hello.
> :- interface.
> :- import_module io.
> :- pred main(io.state, io.state).
> :- mode main(di, uo) is det.
> :- implementation.
> :- import_module char.
> :- import_module int.
> :- pred bo( U :: int ).
> :- mode bo( in ) is semidet.

The `pred' declaration here is a syntax error.  What you should have
written is either

:- pred bo(int).
:- mode bo(in) is semidet.

or, as an abbreviation when you only have one mode, as in this case:

:- pred bo(int::in) is semidet.

which means the same thing as the first two lines I wrote.

> :- pred row( X :: int, Y :: int, Z :: int).
> :- mode row( in, in, in) is semidet.
> %:- mode row( out, in, in) is nondet.
> %:- mode row( in, out, in) is nondet.
> %:- mode row( in, in, out) is nondet.
> %:- mode row( in, out, out) is nondet.
> %:- mode row( out, out, in) is nondet.
> %:- mode row( out, in, out) is nondet.

Here you clearly want more than one mode (I'm assuming you also want the
modes you've commented out) so you can't use the (second) abbreviated
`predmode' syntax.  You have to write

:- pred row(int, int, int).
:- mode row(in, in, in) is semidet.
:- mode row(out, in, in) is nondet.
:- mode row(in, out, in) is nondet.

> :- pred column( A :: int, B :: int).
> :- mode column( in, in) is semidet.
> %:- mode column( out, in) is nondet.
> %:- mode column( in, out) is nondet.

Same problem here.

> [...]
> main( !IO ) :-
>     io.write_string("Start the Declarative Program!\n", !IO),
>     row( A1,A2,A3),
>     row(B1,B2,B3),
>     not( column(A1,B1) ),
>     column(A2,B2), 
>     not( column(A3,B3) ),
>     io.write_string("A1=", !IO),
>     io.write_string(char.to_int(A1), !IO),
>     io.nl(!IO),
>     [...].

You'll also have a problem with this definition of main since the first
five goals collectively are nondet, but main must be det (or cc_multi -
but don't worry about that for now.)

Another problem is 

>     io.write_string(char.to_int(A1), !IO),

since char.to_int(A1) returns an int (as its name suggests), not a
string (as io.write_string requires.)

A simpler way of writing your output is to use the io.format predicate:

	io.format("A1=%c\n", [c(A1)], !IO),

which is rather like C's printf, but is well typed

> but the compiler gives me the following error messages:hello.m:015: 
> In definition of predicate `hello.bo'/1:
> hello.m:015:   error: undefined mode `int'/0.

The error message is pretty clear: because of your syntax error the
Mercury compiler thinks you mean int as a mode here rather than a type.

Have you worked through the on-line tutorial?  It's a little
out-of-date, but should help clear up a few problems you have with

> And - if somebody knows can I state a
> declarative querie (like a SQL querie) like I did it in the middle part?
>     row( A1,A2,A3),
>     row(B1,B2,B3),
>     not( column(A1,B1) ),
>     column(A2,B2), 
>     not( column(A3,B3) ),
> Is it allowed or do I first have to instanciate A1,A2,... ???

Well, to make this work you'd need to add one or both of the
following modes to your program:

:- mode row(out, out, out) is multi.

:- mode column(out, out) is multi.

The compiler uses the mode declarations to work out how to reorder your
goal above so that every variable is output by some call before it is
used as an input for some other call.

> What I want to
> get is that the program backtracks all possible values that makes the
> statement come true (and gives them out). Maybe I should take bools, because he has
> to compute all values (-2000000 / +2000000). What do you think (sorry about
> these "silly" questions, but I am an absolute newby on this area...).

The best advice I can offer is to start with the Mercury tutorial and
get comfortable with the basic syntax, types and modes.  If you
understand these things, you'll find the answers to your questions very

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