[m-users.] A neater way to call chained init functions?
emacstheviking
objitsu at gmail.com
Fri Jul 26 02:43:40 AEST 2019
Given these three library init predicates...
:- pred setup_sdl(bool::out, io::di, io::uo) is det.
:- pred setup_sdlmix(bool::out, io::di, io::uo) is det.
:- pred setup_sdlimg(bool::out, io::di, io::uo) is det.
is there a more idiomatic / efficient / less $%^&*( ugly way to do this
please...
:- pred setup_app(bool::out, io::di, io::uo) is det.
setup_app(CanRun, !IO) :-
setup_sdl(SdlUp, !IO),
(
SdlUp = yes,
setup_sdlimg(ImgUp, !IO),
(
ImgUp = yes,
setup_sdlmix(MixUp, !IO),
(
MixUp = yes,
CanRun = yes
;
MixUp = no,
CanRun = no
)
;
ImgUp = no,
CanRun = no
)
;
SdlUp = no,
CanRun = no
).
IIUIC you can't have predicates being anything other than `det` if they
use IO ? The above code is classic staircase, in Haskell I'd hear "maybe
monads" screaming at me but I have not yet gotten exposure to the std_util
maybe wrapper...it seems to be just a normal type constructor with yes(T)
and no, and also maybe_error as well. All suggestions welcome!!
It's going well, I have sounds, images, lines, rectangles all in a window
but I am now trying to get away from the FFI and start to learn more
idiomatic Mercury.
Thanks,
Sean
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurylang.org/archives/users/attachments/20190725/adfdd28b/attachment.html>
More information about the users
mailing list