[mercury-users] Re: integer enumerations

Renaud Paquay rpa at miscrit.be
Thu Jul 27 22:46:04 AEST 2000



Fergus Henderson wrote:
> For enumerations where the enumeration values have been explicitly specified
> in the C code, it's probably best not to map them to Mercury enums.
> Instead, you can map them to `int' plus a set of constants in Mercury,
> e.g.
> 
>         :- type some_c_enum == int.
> 
>         :- func foo = some_c_enum.
>         :- func bar = some_c_enum.
>         :- func baz = some_c_enum.
>         foo = 1.
>         bar = 2.
>         baz = 17.

Using the COM tool we wrote a few months ago (actually almost 1 year, now),
it is possible to generate an enumeration from an (COM) IDL definition, 
exactly the way Fergus suggests.

See the attached files for an example.
test_enum.idl : The (COM) IDL definition of the enumeration
test_enum.m   : The generated Mercury module


Renaud Paquay
Mission Critical
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_enum.idl
Type: application/x-unknown-content-type-idlfile
Size: 96 bytes
Desc: not available
URL: <http://lists.mercurylang.org/archives/users/attachments/20000727/13cdc0b3/attachment.bin>
-------------- next part --------------
:- module test_enum.
:- interface.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Enum definition of enum_type
%
:- module enum_type.
:- interface.
:- import_module int.
:- type enum_type == int.   %%% enum_type
:- func e1 = (int::out) is det.    %%%% e1
:- func e2 = (int::out) is det.    %%%% e2
:- func e3 = (int::out) is det.    %%%% e3
:- end_module enum_type.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Typedef definition of enum_t
%
:- module enum_t.
:- interface.
:- import_module test_enum__enum_type.
:- type enum_t == enum_type.

:- end_module enum_t.

:- implementation.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Enum definition of enum_type
%
:- module enum_type.
:- implementation.
e1 = 20.    %%%% e1
e2 = 21.    %%%% e2
e3 = 46.    %%%% e3
:- end_module enum_type.

:- end_module test_enum.


More information about the users mailing list