[m-users.] State variables

Sean Charles (emacstheviking) objitsu at gmail.com
Sat Sep 18 07:04:50 AEST 2021


Hi,

I am now working on an SDL wrapper I started back in 2019 and I have this type and predicate in the interface declaration of my wrapper:

:- type gfx_state.
:- pred startup(maybe.maybe(gfx_state)::out, io::di, io::uo) is det.
:- pred shutdown(gfx_state::in, io::di, io::uo) is det.
:- pred wnd_up(string::in, point::in, size::in, gfx_state::di, gfx_state::uo, io::di, io::uo) is det.

and in my main code where I start things up I have this code so far:

 27 main(!IO) :-
 28     io.format("ui using gfx around sdl2\n", [], !IO),
 29
 30     gfx.startup(GM, !IO),
 31     (   GM = yes(G),
 32         io.format("GFX initialised OK\n", [], !IO),
 33
 34         gfx.wnd_up("Test", sdl2.point(0,0), sdl2.size(800,600),
 35             G, G1, !IO),
 36
 37         gfx.shutdown(G1, !IO),
 38         io.format("GFX halted OK\n", [], !IO)
 39     ;
 40         GM = no,
 41         io.format("GFX failed to start\n", [], !IO)
 42     ).

The sentiment was to call the startup predicate, if that returns yes(G) then G is the initial state of my graphics context. which like the IO state, I want to be able to use with !G etc, the above code produces these errors:

mmc -s hlc.gc -O4 -lsdl2 -lSDL2_mixer -lSDL2_image --make main
Making Mercury/int3s/main.int3
Making Mercury/ints/main.int
Making Mercury/cs/main.c
main.m:034: In clause for `main(di, uo)':
main.m:034:   in argument 4 of call to predicate `gfx.wnd_up'/7:
main.m:034:   mode error: variable `G' has instantiatedness `ground',
main.m:034:   expected instantiatedness was `unique'.
For more information, recompile with `-E'.
** Error making `Mercury/cs/main.c'.
make: *** [main] Error 1

I guess what I am asking is, how do I start the process of, creating the state variable in scope, the reference says that they have to be introduced into the head scope (like IO in my main is) but how do you do that in the body of codeā€¦ I vaguely recollect some [Var] ringing a bell but I am confused a little by the terminology and hence exactly what to do about it!

Thank you.
Sean.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurylang.org/archives/users/attachments/20210917/7a257762/attachment.html>


More information about the users mailing list