[mercury-users] Bit-fields in Mercury
Jonathan Morgan
jonmmorgan at gmail.com
Sat Jul 8 20:43:26 AEST 2006
In C/C++ it is fairly common to represent a set of options as
bitfields rather than a set of booleans, like the following:
#define OPT1 1
#define OPT2 2
#define OPT3 4
...
func(..., OPT1 | OPT3);
How (if at all) would this sort of thing be represented in Mercury?
The following is one possible representation.
:- type func_opt ---> func_opt(int).
:- func opt1 = int.
opt1 = 1.
:- func opt2 = int.
opt2 = 2.
:- func opt3 = int.
opt3 = 4.
...
func(..., func_opt(opt1 + opt3)).
This representation is not as type-safe as one might like. Is there a
better way?
Jon
--------------------------------------------------------------------------
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