我有以下代码,它报告错误。我不明白错误信息。
module MonochromeHandler
open System.Drawing
let private transparent = Color.FromArgb(0, 0, 0, 0)
let private calculateAlpha currentAlpha greyValue =
match currentAlpha - greyValue with
| value when value < 0 -> 0
| value -> value
let private actionPixel(pixelColour:Color) =
match (pixelColour.A, pixelColour.R, pixelColour.G, pixelColour.B) with
| (0uy, _, _, _) -> transparent
| (alpha, red, green, blue) when red = blue && red = green && red <> 255uy ->
let newAlpha = calculateAlpha((int)alpha, (int)red)
Color.FromArgb(newAlpha, 0, 0, 0)
| _ -> pixelColour
我在“ Color.FromArgb(newAlpha, 0, 0, 0)
”行出现错误
Error 1 This expression was expected to have type
int
but here has type
'a -> int
该函数有两个参数,我提供并返回一个 int。那么为什么 newAlpha 的类型不是“ int
”,为什么是“ 'a -> int
”?
可能与此有关,因为我声明calculateAlpha
的参数没有括号或逗号,我对 F# 的(显然不充分的)理解是我应该能够这样使用它:
let newAlpha = calculateAlpha (int)alpha (int)red
如果我这样做,我会得到一个不同的错误calculateAlpha (int)alpha
:
Error 1 This value is not a function and cannot be applied
为什么我不能以这种方式调用该函数?