我有一个函数,我认为应该返回一个类型T.然而,它报告返回(T - > T),这对我来说肯定似乎是函数.这是代码:
let setContent content cell = { cell with Content = content }
let destroy = setContent Crater
let detonateMine cell =
function
| { Content = Mine } ->
destroy cell
| { Content = Crater } ->
let errMessage = sprintf "The cell has already been denotated. (%i, %i)" cell.Location.X cell.Location.Y
invalidOp errMessage
| _ ->
let errMessage =
sprintf "The cell cannot be denotated. It does not contain a mine. (%i, %i)" cell.Location.X
cell.Location.Y
invalidOp errMessage
Run Code Online (Sandbox Code Playgroud)
setContent是T - > T.
毁灭是T - > T.
我有破坏测试,返回的值是T.
但是,引爆的类型是cell:T -> _arg1:T -> T._arg1来自哪里?
在这里,这个词function没有做你想要的.相反,它基本上创建了一个匿名函数.
一般来说
function | ...
Run Code Online (Sandbox Code Playgroud)
相当于
fun y -> match y with | ...
Run Code Online (Sandbox Code Playgroud)
(_arg1对应于y我添加的)
在你的情况下function改为:
match cell with
Run Code Online (Sandbox Code Playgroud)
应该做你想做的事.