[m-users.] A neater way to call chained init functions?

emacstheviking objitsu at gmail.com
Fri Jul 26 18:26:07 AEST 2019


Julian, thank you!

As usual you've provided seriously good feedback; that last suggestion
looks particularly cool as it seems to be the mercury equivant of haskells
">>=" i.e. you've implemented a maybe monad for real. Excellent educational
material. I have however opted to understand and user the "mapping a list
of predicates" solution as it will be a nice segway into using "inst" for
the first time ever.

Thanks again,
Sean.


On Fri, 26 Jul 2019 at 01:09, Julian Fondren <jfondren at minimaltype.com>
wrote:

> On 2019-07-25 11:43, emacstheviking wrote:
> > is there a more idiomatic / efficient / less $%^&*( ugly way to do
> > this please...
>
> I'd like to point out that I have no idea as far as idiomatic
> and efficient goes.
>
> Especially so with this option:
>
>    :- module initall.
>    :- interface.
>    :- import_module io.
>    :- pred main(io::di, io::uo) is det.
>    :- implementation.
>    :- import_module list, bool.
>
>    :- type initializer == (pred(bool, io, io)).
>    :- inst initializer == (pred(out, di, uo) is det).
>
>    :- func initializer >> initializer = initializer.
>    :- mode in(initializer) >> in(initializer) = out(initializer).
>    A >> B = C :-
>        C = (pred(R::out, !.IO::di, !:IO::uo) is det :-
>            A(R1, !IO),
>            ( R1 = yes, B(R, !IO) ; R1 = no, R = no)).
>
>    :- 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.
>    :- pred setup_sdlmaybe(bool::in, bool::out, io::di, io::uo) is det.
>
>    setup_sdl(yes, !IO) :- io.write_string("at sdl\n", !IO).
>    setup_sdlmix(yes, !IO) :- io.write_string("at sdlmix\n", !IO).
>    setup_sdlimg(yes, !IO) :- io.write_string("at sdlimg\n", !IO).
>    setup_sdlmaybe(B, B, !IO) :-
>        io.write_string("at sdlmaybe: ", !IO),
>        io.write_line(B, !IO).
>
>    main(!IO) :-
>        Init = setup_sdl
>            >> setup_sdlmaybe(no)
>            >> setup_sdlmix
>            >> setup_sdlimg,
>        Init(Res, !IO),
>        io.write_line(Res, !IO).
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurylang.org/archives/users/attachments/20190726/baf3af73/attachment.html>


More information about the users mailing list