[mercury-users] Re-ordering and getters/setters

Peter Schachte schachte at csse.unimelb.edu.au
Tue Aug 8 12:50:03 AEST 2006

On Fri, Aug 04, 2006 at 12:44:16PM +1000, Jonathan Morgan wrote:
> On 04/08/06, Peter Schachte <schachte at csse.unimelb.edu.au> wrote:
> >One little enhancement, discussed recently on this list, would allow
> >you to write
> >
> >    !Obj ^ property := Val0,
> >    A = !.Obj ^ property,
> >    !Obj ^ property := Val1,
> >    B = !.Obj ^ property,
> >
> >Which looks more natural to me than the code you wanted to write
> >above.
> It does.  However, consider a data structure like a widget.  Many of
> the calls that I make that set a property of the widget will also
> affect the state of the world (often it will cause the widget to
> re-draw itself).

Ah, sorry, I didn't realize this was about communicating with external
entities (like humans).  In that case, you really do need to consider
reading properties of widgets to be an IO operation.  You may be
reading a text widget as the user is typing into it; two calls to read
the content of a text widget with no intervening IO (or impure) goals
may still get different values.

I think in current Mercury, you're stuck with either threading the IO
state everywhere, or making setting and getting properties impure.  I
don't even think you can get away with making reading semipure,
because getting isn't even even functional between calls to setting

Peter Schachte              The towels were so thick there I could hardly
schachte at cs.mu.OZ.AU        close my suitcase.
www.cs.mu.oz.au/~schachte/      -- Yogi Berra 
Phone: +61 3 8344 1338      
mercury-users mailing list
Post messages to:       mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions:          mercury-users-request at csse.unimelb.edu.au

More information about the users mailing list