[mercury-users] Working with exported types
Peter Schachte
schachte at csse.unimelb.edu.au
Thu Jul 27 15:37:59 AEST 2006
On Thu, Jul 27, 2006 at 03:14:40PM +1000, Jonathan Morgan wrote:
> Say I have an enum something like the following.
>
> :- type my_enum --->
> value1 ;
> value2 ;
> value3.
>
> If I am working with such a type in foreign code there are a couple of
> ways I could do it.
>
> 1. Assume that value1, value2 and value3 map to the values 0, 1 and 2,
> and then just test against or assign these values. Efficient, but may
> be broken by change in representation.
>
> 2. Export Mercury predicates that work on this type, and use these
> exported predicate exclusively.
If you're only worried about enums, how about writing a little mercury
program to read the mercury source file and generate a C file
containing an enum declaration like
enum my_enum { value1, value2, value3 };
or maybe
typedef enum { value1, value2, value3 } my_enum;
Then use a little Makefile magic to keep this file up to date when you
change your mercury source file.
Better still: build this into the compiler, which knows for sure
which values are given to the enum constants.
--
Peter Schachte It has become appallingly obvious that our
schachte at cs.mu.OZ.AU technology has exceeded our humanity.
www.cs.mu.oz.au/~schachte/ -- Albert Einstein
Phone: +61 3 8344 1338
--------------------------------------------------------------------------
mercury-users mailing list
Post messages to: mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions: mercury-users-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the users
mailing list