[mercury-users] Event handling in mercury
Holger Krug
hkrug at rationalizer.com
Mon Jul 23 22:53:24 AEST 2001
> If you really need to access the io__state to initialize it, you
> can always use a maybe(T) type or equivalent, e.g.
>
> :- type initialized(T) ---> initialized(T) ; uninitialized.
>
> define the variable as `foo := no' / `foo := uninitialized',
> and then initialize it in main/2. That way it is up to
> the programmer to deal with the order of evaluation issues.
OK.
>
> > So one would have 2 different forms of `:=', one only used to
> > initialize a static mutvar, the other to set it's value in io_state
> > related operations.
>
> Yes, in my example I was assuming that `:=' would just be used for
> static initialization, and that if dynamic initialization based on the
> io__state is required then you'd use `io_store__set_mutvar' to override
> the static initializer.
`:=/2' is used for initialization.
Why not to use `:=/4' in DCG-rules as follows:
:- interface.
% static variable foo accessible only in IO-related operations
:- static foo = int.
:- import_module io.
:- pred main(io__state, io__state).
:- mode main(di, uo) is cc_multi.
:- implementation
%%% initializer `:=/2' %%%
foo := 42.
main -->
%%% update `:=/4' %%%
foo := 43.
--
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