【发布时间】:2018-04-04 09:54:00
【问题描述】:
在Option模块上应用flatten函数时出错:
let flatten =
function
| None -> None
| Some innerOpt -> innerOpt
这仅适用于以下输入:Some Some 1。 但如果输入是“无”,那么我会收到此错误:
flatten None
error FS0030: Value restriction. The value 'it' has been inferred to have generic type
val it : '_a option
Either define 'it' as a simple data term, make it a function with explicit arguments or, if you do not intend for it to be generic, add a type annotation.
在 None 情况下,flatten 应该如何与泛型一起使用?
【问题讨论】: