【发布时间】:2011-05-03 14:21:00
【问题描述】:
我已经阅读了有关 F# 中值限制的所有内容,但我仍然不明白。我有以下代码:
type tree<'a> =
| Nil
| Node of (tree<'a> * 'a * tree<'a>)
let rec flatten = function
| Nil -> []
| Node ( Nil, b, Nil ) -> [b]
| Node ( l, h, p ) -> List.concat [(flatten l);[h];(flatten p)]
并且编译器显示错误:
error FS0030: Value restriction. The value 'it' has been inferred to have generic type
val it : '_a list
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.
谁能帮帮我?非常感谢;)
【问题讨论】:
-
能否提供代码调用flatten?我可以很好地编译和运行这个示例
-
但是当我调用 flatten Nill;;有问题。
标签: f# value-restriction