I was not aware of this, thanks! The final macro is
using MacroTools
"""
Define a singleton type with the given name and supertype (specified
as `name <: supertype`), and a constant which defaults to the name in
uppercase.
"""
macro define_singleton(name_and_supertype, constant = nothing)
@capture name_and_supertype name_ <: supertype_
if constant == nothing
constant = esc(Symbol(uppercase(string(name))))
end
quote
Core.@__doc__ immutable $name <: $supertype end
Core.@__doc__ const $(constant) = $name()
end
end