非常简单的否定运算函数。
let negation (value:option<bool>) =
match value with
|Some true -> Some false
|Some false -> Some true
|None -> failwith "OOPS"
但是当我调用它时:
negation Some true
它提示说
This value is not a function and cannot be applied
最佳答案
那里需要一些 parent :
negation (Some true)
或者:
negation <| Some true
如果没有这样的括号,F# 编译器会将该行理解为
(negation Some) true
因为函数应用程序是左绑定(bind)的,然后类型不匹配:否定需要是类型:('a -> option 'a) -> bool -> bool
这显然不是't(类型为 bool option -> bool option
)
此外:(包括意见)
否定函数称为 not : bool -> bool
。您正在尝试在选项包装的 bool 上使用它,所以也许这就足够了:
let negation : bool option -> bool option = Option.map not
关于f# - 该值不是函数,无法应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34615815/