How to get the individual element of a defined enum type?


#1

This should be a rather simple question. The following is the code:

Starting Julia...
               _
   _       _ _(_)_     |  A fresh approach to technical computing
  (_)     | (_) (_)    |  Documentation: https://docs.julialang.org
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 0.7.0 (2018-08-08 06:46 UTC)
 _/ |\__'_|_|_|\__'_|  |  Official http://julialang.org/ release
|__/                   |  x86_64-pc-linux-gnu

julia> @enum Priority n h m l

julia> Priority(0)
n::Priority = 0

julia> String(Priority(0))
ERROR: MethodError: Cannot `convert` an object of type Priority to an object of type String
Closest candidates are:
  convert(::Type{String}, ::Symbol) at deprecated.jl:53
  convert(::Type{String}, ::Array{UInt8,1}) at deprecated.jl:53
  convert(::Type{String}, ::AbstractArray{Char,1}) at deprecated.jl:53
  ...
Stacktrace:
 [1] String(::Priority) at ./deprecated.jl:473
 [2] top-level scope at none:0

julia> Int(Priority(0))
0

julia> typeof(n)
Enum Priority:
n = 0
h = 1
m = 2
l = 3

My question is, as you can see from the above, how to get the String counterpart of the Priority type? This should be doable easily, right? Did I miss something?


#2

Lowecase string is a different and more flexible function than String, which is the String constructor, and can convert most values to strings:

julia> string(Priority(0))
"n"

It is curious that there is an Int constructor for Enums but no String constructor.