Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
F# 对表达的类型感到困惑_F# - Fatal编程技术网

F# 对表达的类型感到困惑

F# 对表达的类型感到困惑,f#,F#,我有一个函数,我认为它应该返回一个类型T。然而,它是返回T->T的报告,在我看来它本身就是s函数。代码如下: let setContent content cell = { cell with Content = content } let destroy = setContent Crater let detonateMine cell = function | { Content = Mine } -> destroy cell | {

我有一个函数,我认为它应该返回一个类型T。然而,它是返回T->T的报告,在我看来它本身就是s函数。代码如下:

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
设置内容为T->T

摧毁是T->T

我对destroy进行了测试,返回的值是T

但是,雷管的类型是cell:T->\u arg1:T->T.\u arg1从何而来?

这里,单词function并不是你想要的。相反,它本质上创建了一个匿名函数

大体上

function | ...
相当于

fun y -> match y with | ...
arg1对应于我添加的y

在您的情况下,将功能更改为:

你应该做你想做的

match cell with