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

Mark Brown mark at csse.unimelb.edu.au
Mon Jan 15 11:25:24 AEDT 2007


On 15-Jan-2007, Ondrej Bojar <obo at cuni.cz> wrote:
> 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).

One technical problem with this is that it could easily leading to an
exponential explosion in the amount of code generated.  If a predicate
has N state-variable pairs which can each be either (in, out) or (di, uo),
then this would lead to 2^N procedures in the compiled code.  3^N if you
allow mostly-unique insts.

Same problem occurs if you try inst variables rather than mode variables,
too.

Cheers,
Mark.

--------------------------------------------------------------------------
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