[m-users.] STATE_VARIABLE_IO_0 has instantiatedness ddgame.m:042: mostly_unique

Julian Fondren jfondren at minimaltype.com
Sat Aug 17 00:54:40 AEST 2019


On 2019-08-16 09:27, emacstheviking wrote:
> Julian, thanks.
> 
> I have refactored / restructured my code and it's all good now...I
> kind of get the explanation but I kept the bad code so I can go back
> and study harder later.
> 
> I'm not really understanding your comment about ,
> 
>> The !IO there represents IO1 = IO2.
> 
> Thanks again.
> 

My answer was imprecise in a few other ways too.

1. !IO maps to a pair of parameters !.IO, !:IO,

2. which gets translated to (something like) IO1, IO2, where IO1 is
passed to the predicate and IO2 is a free variable that gets bound
as a result of the predicate.

3. all bindings established within conditional code are only still
set in the 'then' case. Again: if the conditional fails, none of
these bindings are set, so IO2 in particular isn't set, so you've
passed the 'io' value to a predicate but didn't get it back.

4. the 'else' case therefore must reuse IO1 (even if it doesn't
refer to !IO, because the !:IO paramter of the predicate the
conditional is in still needs to be satisfied).

the error tells you that IO1 in my explanation is actually named
STATE_VARIABLE_IO_0.

As a rule, don't use !IO in conditional code. I/O always succeeds,
even if it successfully reports an error. That you're told the copy
is 'mostly_unique' instead of 'ground' is a hint about a feature
(that isn't an option for io state):
https://mercurylang.org/information/doc-latest/mercury_ref/Backtrackable-destructive-update.html



More information about the users mailing list