Code Snippet:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
module Random =
  open System
  let private r = new Random()
  let coinToss = fun _ -> r.Next(0,2)

let printNumbers n =
  match n % 2 = 0 with
  | true  -> printfn "Even nr. %i" n
  | false -> printfn "Odd nr. %i" n

let printNumbers' n =
  // Missed "else" statement is found at runtime					
  if n % 2 = 0
  then printfn "Even nr. %i" n

List.init 10 (Random.coinToss)
|> List.iter printNumbers

List.init 10 (Random.coinToss)
|> List.iter printNumbers'

Code output:

>
module Random = begin
  val private r : System.Random
  val coinToss : 'a -> int
end
val printNumbers : n:int -> unit
val printNumbers' : n:int -> unit

> Even nr. 0
Odd nr. 1
Even nr. 0
Odd nr. 1
Even nr. 0
Odd nr. 1
Even nr. 0
Even nr. 0
Odd nr. 1
Odd nr. 1
val it : unit = ()

> Even nr. 0
Even nr. 0
Even nr. 0
Even nr. 0
Even nr. 0
val it : unit = ()

Code Snippet:

1
2
3
4
5
6
7
let printNumbers'' n =
  // Missed "false" match is found at compile-time
  match n % 2 = 0 with
  | true  -> printfn "Even nr. %i" n

List.init 10 (Random.coinToss)
|> List.iter printNumbers''

Code output:

>
/Users/mon/tmp/conditionalexpressionsVSpatternmatch.fsx(22,9): error FS0025: Incomplete pattern matches on this expression. For example, the value 'false' may indicate a case not covered by the pattern(s).

Configuration Emacs (~/.emacs.d/init.el):

All

Configuration Visual Studio:

All

References: