[mercury-users] Event handling in mercury

Fergus Henderson fjh at cs.mu.OZ.AU
Tue Jul 17 01:45:06 AEST 2001


On 16-Jul-2001, Holger Krug <hkrug at rationalizer.com> wrote:
> Obviously a global application state could be implemented in Mercury
> by using mercury-extras/references/, but that's not what one should be
> happy with, when starting to work with Mercury.
> 
> So why not to add global state handling to the Mercury libraries in a
> way which seems to conform with the fundamentals of the Mercury
> language:

That's a good idea.  It's one that has been on my to-do list for quite a while,
but for various reasons I haven't found time for it.

> :- module gstore.   % compare module store
> :- interface.
> 
> :- import_module store. % type store__mutvar(T,S).
> :- import_module io.    % type io__state.
> 
> :- type gstore (S).   
> 
> :- some [S] pred gstore__new(gstore(S),io__state,io__state).
> :- mode          gstore__new(out, di, uo) is det.
> 
> :- pred gstore__new_mutvar(T,mutvar(T,S), gstore(S), io__state, io__state).
> :- mode gstore__new_mutvar(in, out, in, di, uo) is det.
> 
> :- pred gstore__get_mutvar(mutvar(T,S), T, gstore(S), io__state, io__state). 
> :- mode gstore__get_mutvar(in, out, in, di, uo) is det.
> 
> :- pred gstore__set_mutvar(mutvar(T,S), T, gstore(S), io__state, io__state). 
> :- mode gstore__set_mutvar(in, in, in, di, uo) is det.

What's the `gstore' type here used for?
I don't think you need that.
I think it would be enough to just do it like this:

	:- module io_store.   % compare module store
	:- interface.

	:- import_module store. % type store__mutvar(T,S).
	:- import_module io.    % type io__state.

	:- type io_store.   

	:- pred io_store__new_mutvar(T,mutvar(T, io_store), io__state, io__state).
	:- mode io_store__new_mutvar(in, out, di, uo) is det.

	:- pred io_store__get_mutvar(mutvar(T, io_store), T, io__state, io__state). 
	:- mode io_store__get_mutvar(in, out, di, uo) is det.

	:- pred io_store__set_mutvar(mutvar(T, io_store), T, io__state, io__state). 
	:- mode io_store__set_mutvar(in, in, di, uo) is det.

There should also be a procedure analagous to store__new_cyclic_mutvar.

Anyway, if you want to go ahead and implement this, I'll be happy to review
the code and to include it in the Mercury standard library (presuming the
other Mercury developers don't have any objections).  The implementation can
be similar to the implementation of mutvar in the store module.

Cheers,
	Fergus.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list