【发布时间】:2013-01-08 18:01:33
【问题描述】:
我想传递一个类型名称(例如int,或string,甚至是用户定义类型的名称)作为函数参数。目前我正在做以下事情:
type IntegerOrIntegerList =
| Integer of int
| IntegerList of int list
let f (n : int) (d : 'T) : IntegerOrIntegerList =
match (box d) with
| :? int as i -> Integer(n)
| _ -> IntegerList([0 .. n])
但是上面d 的存在是偶然的。表达上述逻辑的惯用 F# 方式是什么?
提前感谢您的帮助。
【问题讨论】:
标签: types parameters f#