Search code examples
f#unit-type

F# how to write an empty statement


How can I write a no-op statement in F#?

Specifically, how can I improve the second clause of the following match statement:

match list with
    | [] -> printfn "Empty!"
    | _ -> ignore 0

Solution

  • Use unit for empty side effect:

    match list with
      | [] -> printfn "Empty!"
      | _ -> ()