<div dir="ltr">Hi Peter,<div>I did wonder about that ...you can tell I am new to mercury for sure. My plan is to create as simple an interface to SDL2 as possible. I produced a full wrapper for GNU Prolog and it took ages...this time the "plan" is to produce something akin to a "display list" (my Atari days!) and then have a single C function that walks the display list and turns each entry into the appropriate SDL draw line, point, image etc etc</div><div><br></div><div>Can you explain why I need to pass in !IO if I am not actually going to modify it? I am a bit confused about the</div><div><br></div><div> sdl_up(Result::out, _IO0::di, _IO::uo)</div><div><br></div><div>Or is this something that the compiler will be making use of...like I say, I am new to mercury but I am pretty familiar with Haskell and Prolog if that helps to explain anything.</div><div><br></div><div>I will need some extra support for fonts and textures but that's the fun of exploratory hacking!</div><div><br></div><div>Thanks again,</div><div>Sean.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, 25 Jun 2019 at 11:42, Peter Wang <<a href="mailto:novalazy@gmail.com">novalazy@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Tue, 25 Jun 2019 11:03:53 +0100, emacstheviking <<a href="mailto:objitsu@gmail.com" target="_blank">objitsu@gmail.com</a>> wrote:<br>
> Hi,<br>
> I have these two lines of code...<br>
> <br>
> :- pragma foreign_decl("C", "#include <SDL/SDL.h>").<br>
> :- pragma foreign_decl("C", "#include <SDL/SDL_version.h>").<br>
> <br>
> at the top of my module in the implementation section and this code too:<br>
> :- func sdl_up = int.<br>
> :- pragma foreign_proc("C",<br>
> sdl_up = (Result::out),<br>
> [ will_not_call_mercury<br>
> , not_thread_safe<br>
> , promise_pure<br>
> ],<br>
> "Result = SDL_Init(SDL_INIT_EVERYTHING);").<br>
> <br>
<br>
Hi,<br>
<br>
SDL_Init() is impure, so wrapping it up in pure function is incorrect.<br>
Rather, you should wrap it in a predicate that takes the I/O state:<br>
<br>
:- pred sdl_up(int::out, io::di, io::uo) is det.<br>
<br>
:- pragma foreign_proc("C",<br>
sdl_up(Result::out, _IO0::di, _IO::uo),<br>
[will_not_call_mercury, promise_pure],<br>
"<br>
Result = SDL_Init(SDL_INIT_EVERYTHING);<br>
").<br>
<br>
Peter<br>
</blockquote></div>