[mercury-users] Event handling in mercury

Ralph Becket rbeck at microsoft.com
Mon Jul 16 22:17:29 AEST 2001


> From: Holger Krug [mailto:hkrug at rationalizer.com]
> Sent: 16 July 2001 12:47
> 
> (But why to have only type-less globals ? I understand, that globals
> are somehow foreigners in a purely declarative world, but I think the
> Mercury language - as in a similar way Haskell, too - has very nice
> features to make a clean separation between declarative and imperative
> code.)

In Mercury you don't really have globals: the top-level of your program
can thread the io__state around which carries a slot (called "globals") 
solely for the purpose of carrying persistent application state.  But
without using impure facilities, there's no way of accessing persistent
state anywhere in your program without threading the means of access
(stores are good for this where you don't require IO - and get_mutvar
doesn't require a dynamic type cast).

Since the {set,get}_globals preds have to be defined in the io module,
they have to have their types defined there too.  The only thing that
fits the bill is to make it type univ (which *is* a bona fide type!)
and require dynamic casts to extract the value you want.  This shouldn't
be too bad since if you're using the io__state you're almost certainly
doing IO with it as well which is rarely cheap.

- Ralph
--------------------------------------------------------------------------
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