Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

F# if not condition

Tags:

f#

What is the best way in F# to write an if not condition?

Right now I'm writing it like this:

if condition <> true then do 

Is there any other shorter way to write it? Like using the ! operator?

like image 731
Frank Hale Avatar asked Dec 11 '10 20:12

Frank Hale


2 Answers

if you consider that not is also a function, then you can pipe your condition into it to avoid parenthesis like so:

if not <| condition param1 param2 then ... 

reason being is if your condition function takes arguments, you don't need to do

not (condition param1 param2)  

it's probably a little cleaner to do it the first way since it seems f# is in favor of pipes instead of parenthesis for operator precedence.

like image 121
Alex Avatar answered Nov 08 '22 01:11

Alex


In Ocaml, you can use the "not" keyword:

if not condition then ... 

Hopefully works too with F#.

like image 43
small_duck Avatar answered Nov 08 '22 00:11

small_duck