You basically answered your own question. You don't ever have to use it. The point is precisely to avoid the warning. If you write f x; ()
, the compiler assumes you probably did something wrong. Probably you thought f x
returns unit because you rarely want to ignore non-unit values.
However, sometimes that's not true, and you really want to ignore even non-unit values. Writing ignore (f x)
documents the fact that you know f x
returns something, but you are deliberately ignoring it.
Note that in real code f x
might be something more complex, so the chances of you being wrong about the return type of f x
are reasonably high. One example is partial application. Consider f : int -> int -> unit
. You might accidentally write f 1
, forgetting the second argument, and the warning will help you. Another example is if you do open Async
, then many functions from the Standard Library change from returning unit to returning unit Deferred.t
. Especially when first starting to use Async, it is quite likely that you'll accidentally think the semicolon operator is appropriate in places that you really need to use monadic bind.