首页 > 解决方案 > 如何在 Julia 中使模块中的自定义枚举类型可用

问题描述

我正在尝试在模块中定义枚举类型,以便可以在所有函数中使用它。导出模块时,只能获取枚举类型,但无法识别枚举类型的元素。

module testaux

greet() = print("Hello World!")
@enum Stortype colMajor rowMajor
@enum Sorttype ascend descend nosort

end # module

成功导入 testaux 后,我可以调用 greet() 并识别 Stortype。但是我没有使用 Stortype 通过以下定义来限制我的函数参数:

function t(a::Stortype)
    println(a)
end
t(colMajor)

会抱怨 colMajor 未定义。

标签: julia

解决方案


推荐阅读