非常简单的否定操作功能.
let negation (value:option<bool>) =
match value with
|Some true -> Some false
|Some false -> Some true
|None -> failwith "OOPS"
Run Code Online (Sandbox Code Playgroud)
但是当我打电话给它时:
negation Some true
Run Code Online (Sandbox Code Playgroud)
它抱怨说
This value is not a function and cannot be applied
Run Code Online (Sandbox Code Playgroud)
你需要一些parens:
negation (Some true)
Run Code Online (Sandbox Code Playgroud)
要么:
negation <| Some true
Run Code Online (Sandbox Code Playgroud)
没有像那样的P#编译器会理解该行为
(negation Some) true
Run Code Online (Sandbox Code Playgroud)
因为函数应用程序是左绑定的,然后类型不匹配:否定需要是类型:('a -> option 'a) -> bool -> bool显然不是(类型bool option -> bool option)
另外:(包括意见)
调用否定函数not : bool -> bool.你试图在选项包装的bool上使用它,所以也许这应该足够了:
let negation : bool option -> bool option = Option.map not
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3130 次 |
| 最近记录: |