[m-dev.] syntactic suggar suggestion for state variables

Ondrej Bojar obo at cuni.cz
Mon Jan 15 09:31:31 AEDT 2007


Hi,

I don't care much about the choice between !(in, out) and in!out. Both 
are nice (but see below). I would just definitely stick to the same 
symbol (!).

Ben Schmidt wrote:
>> What about something more like
>> :- pred p(mysvtype::!(ground)) is det.
> 
> I don't like that one, because it complicates doing things with unique 
> modes rather than normal modes (in!out, ui!uo and di!uo could all be 
> quite common to use what is now my preferred syntax :-)). Also because 
> insts are something the average Mercury programmer delves into somewhat 
> rarely (IMHO) and the construct for state variable types and modes was 

I definitely agree on this.

However I like the idea of mode variables (not inst variables), because 
the !(in, out) and !(di, uo) variants of the same predicate could then 
have the same !(Mode) mode declaration. This would however require 
further mode inference, especially once lambda expressions are used. Or 
maybe not more of mode inference, but an extra namespace for mode variables:

:- pred fold(pred(T, !Aku), myadt(T), !Aku) is det.
:- mode fold(pred(T, !(I, O)) is det, in, !(I, O)) is det.
fold(Pred, MyADT, !Aku) :-
   list__foldl(
     (pred(E::in, !A::!(I, O)) is det:-
        Pred(E, !A)
     ), MyADT^underlying_list_structure, !Aku).

With such a future extension in mind, I'd disfavor in!out or I!O (for 
rather unspecified style issues).

For extra lazy people, bimode variables could be allowed:

   !Aku::!IO

but this could make error messages incomprehensible if you forgot one of 
the (!) somewhere, or worse, if you forgot one in the mode and one in 
the type declarations:

meant:     pred(!aku1::!IO, !aku2::!IO)
written:   pred(!aku1::IO, aku2::!IO)

On the other hand, such messages would not be probably more complicated 
than those '...which does not match any of the predicate modes'.

O.

-- 
Ondrej Bojar (mailto:obo at cuni.cz)
http://www.cuni.cz/~obo
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at csse.unimelb.edu.au
Administrative Queries: owner-mercury-developers at csse.unimelb.edu.au
Subscriptions:          mercury-developers-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the developers mailing list