[m-users.] Adding impurity to Mercury code: Backtracking in IO states
barthwal
barthwal at protonmail.com
Sun Jun 28 12:35:11 AEST 2015
Hi,
In one of the module, I am trying to add impurity to Mercury. I code looks like below and I get the following error:
ex2.m:023: In clause for predicate `ex2.print'/2:
ex2.m:023: warning: variable `IOState_out' occurs only once in this scope.
ex2.m:025: In clause for `print(in, out)':
ex2.m:025: in argument 2 of call to predicate `io.write_string'/3:
ex2.m:025: mode error: variable `IOState_in' has instantiatedness `ground',
ex2.m:025: expected instantiatedness was `unique'.
ex2.m:034: In clause for `main(di, uo)':
ex2.m:034: in argument 2 of call to predicate `io.write_string'/3:
ex2.m:034: mode error: variable `IOState_temp' has instantiatedness `ground',
ex2.m:034: expected instantiatedness was `unique'.
How do I solve it?
I don't want to use the All solutions predicate or even Foreign language interface!
:- module ex2.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
:- implementation.
:- pred text(string::out) is multi.
:- pred print(io::in, io::out) is det.
text("A").
text("B").
text("C").
text("D").
text("E").
text("F").
print(IOState_in, IOState_out) :-
text(X),
io.write_string(X, IOState_in, _),
X = "D".
print(IOState_in, IOState_out) :-
IOState_out = IOState_in.
main(IOState_in, IOState_out) :-
print(IOState_in, IOState_temp),
io.write_string("Hello, World!\n", IOState_temp, IOState_out).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurylang.org/archives/users/attachments/20150627/9c28017b/attachment.html>
More information about the users
mailing list