Am Mittwoch, 19. Februar 2014 17:52:12 UTC+1 schrieb Stefan Karpinski:
>
> Yeah, I pretty much agree with all of this. Once field access is
> overloadable, we can just create a Direction type and define
> (automatically) the following methods:
>
> getfield(::Type{Direction}, ::Field{:NORTH}) = Direction(0)
> getfield(::Type{Direction}, ::Field{:EAST}) = Direction(1)
> getfield(::Type{Direction}, ::Field{:WEST}) = Direction(2)
> getfield(::Type{Direction}, ::Field{:SOUTH}) = Direction(3)
>
>
> That would make Direction simultaneously a type and let it act like a
> "namespace" in the sense that you can do Direction.NORTH and get the value
> Direction(0). The definition of the type would be something like this:
>
> immutable Direction
> value::Cint
> end
>
>
> So that the values are completely memory compatible with C enums. Not sure
> if we need a new keyword for this – especially considering that we'll want
> something very similar for flags – i.e. enums where the values are powers
> of two. Having @enum and @flag macros may well be enough. But this
> definitely needs the ability to overload field access to make it work
> completely naturally.
>
Stefan, you got me, this looks like a nice proposal! One minor thing is
that these enum types shoud subtype from an abstract "Enum" type.
I am looking forward to this stuff.