[m-users.] Confused my det/multi error message, full disjunction of type in place.

Julien Fischer jfischer at opturion.com
Sun Dec 4 22:04:53 AEDT 2022


Hi again,

On Sun, 4 Dec 2022, Sean Charles (emacstheviking) wrote:

A few other notes about this:

>      59 :- pred write_(fstate::in, fstate::out, fi::in, io::di, io::uo) is det.
>      60
>      61 write_(!S, nl, !IO) :-
>      62     io.nl(!IO),
>      63     !:S = !.S ^nl_written := yes.

That last line can be more concisely written as:

       !S ^ nl_writtern := yes

>      64
>      65 write_(!S, brace_o, !IO) :-
>      66     write_(!S, s("{"), !IO),
>      67     !:S = !.S ^tab_size := !.S ^tab_size+1.
>      68     write_(!S, nl, !IO).
>      69
>      70 write_(!S, brace_c, !IO) :-
>      71     write_(!S, s("}"), !IO),
>      72     !:S = !.S ^tab_size := !.S ^tab_size-1.
>      73
>      74 write_(!S, s(Text), !IO) :-
>      75     io.print(Text, !IO).
>      76
>      77 write_(!S, blk(FIs), !IO) :-
>      78     P = (pred(FI::in, !.St::in, !:St::out, !.IO::di, !:IO::uo) is det :-
>      79         write_(!St, FI, !IO)
>      80     ),
>      81     list.foldl2(P, FIs, !S, !IO).

If you rearrange the arguments of write_/5 to be

      :- pred write_(fi::in, fstate::in, fstate::out, io::di, io::uo) is det.

then the above lambda expression becomes unnecessary and you can just
call foldl/2 directly, e.g. list.foldl2(write_, FIs, !S, !IO).
(That said, you may have good reasons for using the ordering you did,
but note that all of the fold style predicates in the standard library
place their accumulator pairs at the end of the argument list.)

>      83 write_(!S, csv(FIs), !IO) :-
>      84     write_(!S, seq(s(", "), FIs), !IO).
>      85
>      86 write_(!S, ssv(FIs), !IO) :-
>      87     write_(!S, seq(s(" "), FIs), !IO).
>      88
>      89 write_(!_, seq(_, []), !IO).
>      90 write_(!S, seq(With, [ FI | FIs ]), !IO) :-
>      91     write_(!S, FI, !IO),
>      92     ( if list.is_empty(FIs) then
>      93         true
>      94     else
>      95         write_(!S, With, !IO),
>      96         write_(!S, seq(With, FIs), !IO)
>      97     ).

Why not just switch on FIs there?

Julien.


More information about the users mailing list