如果写入if条件,F#中最好的方法是什么?
现在我写的是这样的:
if condition <> true then do
Run Code Online (Sandbox Code Playgroud)
有没有其他更短的方式来写它?喜欢用!运营商?
Ale*_*lex 27
如果你认为not也是一个函数,那么你可以将条件输入它中以避免括号如下:
if not <| condition param1 param2 then ...
Run Code Online (Sandbox Code Playgroud)
原因是如果你的条件函数接受参数,你不需要这样做
not (condition param1 param2)
Run Code Online (Sandbox Code Playgroud)
第一种方式可能有点干净,因为看起来f#支持管道而不是括号用于运算符优先级.
sma*_*uck 20
在Ocaml中,您可以使用"not"关键字:
if not condition then ...
Run Code Online (Sandbox Code Playgroud)
希望与F#一起工作.