[mercury-users] Event handling in mercury
Holger Krug
hkrug at rationalizer.com
Tue Jul 17 16:17:50 AEST 2001
> > 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:
>
> > :- module gstore. % compare module store
> > :- interface.
> >
> > :- type gstore (S).
> >
>
> What's the `gstore' type here used for?
> I don't think you need that.
I agree.
> 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.
I think, even further simplification is possible. To use your own words:
What's the `io_store' type here used for?
I don't think you need that. (You even cannot use that, because you have no
way to create values of type io_store.)
I think it would be enough to just do it like this:
:- module io_store. % compare module store
:- interface.
:- import_module io. % type io__state.
:- type gmutvar(T). % global mutvar, T is the type of values stored,
% there is no additional need to hold some further
% store qualifier like in module store
:- pred io_store__new_gmutvar(T,gmutvar(T), io__state, io__state).
:- mode io_store__new_gmutvar(in, out, di, uo) is det.
:- pred io_store__get_gmutvar(gmutvar(T), T, io__state, io__state).
:- mode io_store__get_gmutvar(in, out, di, uo) is det.
:- pred io_store__set_gmutvar(gmutvar(T), T, io__state, io__state).
:- mode io_store__set_gmutvar(in, in, di, uo) is det.
> There should also be a procedure analagous to store__new_cyclic_mutvar.
:- pred io_store__new_cyclic_gmutvar(
func(gmutvar(T))=T,gmutvar(T),io__state,io__state).
:- mode io_store__new_cyclic_gmutvar(in, out, di, uo) is det.
> 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.
Please first comment the additional changes proposed above.
--
Holger Krug
hkrug at rationalizer.com
--------------------------------------------------------------------------
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