One quite nice approach I have found in Gtk.jl is to define an Enum as:

baremodule Direction
  const NORTH = 0
  const EAST = 1
  const WEST = 2
  const SOUTH = 3
end

IMHO it behaves exactly how an enum should work
- The enum entries are in the namespace of the enum name (like in C# and 
new style C++ enums)
- One can change the values
- One can decide whether the enum is private or public in a module and 
export it in the later case.

Of course the syntax could be made a little more convenient but its already 
not to bad

Am Dienstag, 18. Februar 2014 22:12:27 UTC+1 schrieb Ivar Nesje:
>
> We do not currently have a standard Julia way to define enumerations, but 
> many approaches and a whish/issue about adding specialized support in base 
> julia: https://github.com/JuliaLang/julia/issues/3080.
>
> Please search the groups and github for earlier discussions.
>
> https://github.com/JuliaLang/julia/search?q=enum&ref=cmdform&type=Issues
> https://groups.google.com/forum/#!searchin/julia-users/enum
>
> Ivar
>
> kl. 21:53:25 UTC+1 tirsdag 18. februar 2014 skrev Gour følgende:
>>
>> Hello, 
>>
>> I've covered large part of Julia manual, but didn't encounter any 
>> example how is one supposed to declare Enumeration data type, iow. 
>> something like: 
>>
>> type 
>>   TDirection = enum 
>>     north, east, south, west 
>>
>> in Nimrod, or 
>>
>> data Direction = North | East | South | West 
>>
>>
>> in Haskell? 
>>
>> I've seen about TypeUnions, but wonder if there is some other solution 
>> for it? 
>>
>>
>> Sincerely, 
>> Gour 
>>
>> -- 
>> The humble sages, by virtue of true knowledge, see with equal 
>> vision a learned and gentle brāhmana, a cow, an elephant, a dog 
>> and a dog-eater. 
>>
>> http://www.atmarama.net | Hlapicina (Croatia) | GPG: 52B5C810 
>>
>>
>>

Reply via email to