如何在 F# 中枚举枚举/类型 [英] How to enumerate an enum/type in F#

查看:24
本文介绍了如何在 F# 中枚举枚举/类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像这样定义的枚举类型:

I've got an enumeration type defined like so:

type tags = 
    | ART  = 0
    | N    = 1
    | V    = 2 
    | P    = 3
    | NULL = 4

有没有办法做一个 for ... in tags do ?

is there a way to do a for ... in tags do ?

这是我得到的错误:

值、构造函数、命名空间或type tags 未定义

The value, constructor, namespace or type tags is not defined

推荐答案

使用 Enum.GetValues:

let allTags = Enum.GetValues(typeof<tags>)

这篇关于如何在 F# 中枚举枚举/类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆