Le jeudi 26 décembre 2013 à 16:39 -0500, Stefan Karpinski a écrit :
> There is no @flags macro but it would be pretty easy to write,
> analogous to @enum.
>
>
>
> The real questions to me here are:
> 1. Should these be defined in a module so that they are Foo.BAR,
> etc.?
> 2. Should it by default be possible to dispatch on each value?
> I.e. should Foo be a parametric type and should BAR be the
> unique instance of Foo{0}?
Regarding 2: using parameteric types as a way to implement enums could
prove useful for keyword arguments. If I'm not mistaken, specifying
different values of an enum keyword argument as different types means
that the function will be compiled separately for each value of the
argument, which means that the overhead associated with additional
optional arguments is greatly reduced (if not eliminated). This would
not happen when using @enum, or even when using booleans (for binary
choices).
If that's right, then maybe a convenience macro to create enums as
parameterized types would be useful for some cases where performance
really matters. But people can also write types manually, and if this
turns out to be used often the macro could be added later. The technique
of enums as parametric types would just need to be documented somewhere.
My two cents