"Sigbjorn Finne (Intl Vendor)" wrote:
> You could use 'const's for this, but I'd suggest using an
> 'enum' decl in IDL instead.
Uhmmm, I should have read the docs more closely... :-] But there's
a little bug when using -fenum-instances (missing returns):
...
marshallStatus :: Status -> Prelude.IO Int.Int32
marshallStatus v =
case v of
EXIT_FAILURE -> 0
EXIT_SUCCESS -> 1
...
> IDL 'enum' declarations are just like in C, but HDirect extends 'em
> a little by supporting the custom 'deriving()' attribute. For example,
>
> typedef [deriving("Eq")]
> enum { EXIT_FAILURE = 0, EXIT_SUCCESS } Status;
>
> gives
>
> data Status = EXIT_FAILURE | EXIT_SUCCESS
>
> instance Eq Status where {...}
> instance Enum Status where {...}
>
> which should be equal in power to %enum.
I don't get the Eq instance with my local hdirect-0.14. Are there any
special flags I forgot this time?
> (HDirect doesn't currently allow you to map enums to newtypes of Int
> (say), but it could. No big deal).
Hmm, IMHO it's not enum that should be mapped to newtype but a simple
typedef: Enums have a certain bounded set of possible values while
something like 'typedef unsigned long off_t' has not (at least
conceptually). I consider the automatic wrapping/unwrapping into
newtypes as a crucial feature of any kind of type-safe IDL, so it
should definitely included into H/Direct.
Cheers,
Sven
--
Sven Panne Tel.: +49/89/2178-2235
LMU, Institut fuer Informatik FAX : +49/89/2178-2211
LFE Programmier- und Modellierungssprachen Oettingenstr. 67
mailto:[EMAIL PROTECTED] D-80538 Muenchen
http://www.pms.informatik.uni-muenchen.de/mitarbeiter/panne