What to do to ignore unused returned values

When a function returns a value and it is ignored, Rescript generates a warning. How to deal with it, I’ve seen more than one way to do it:

  1. let () = funReturningValue(foo, bar)

  2. funReturningValue(foo, bar) |> ignore

  3. funReturningValue(foo, bar) -> ignore

  4. Is there a directive to ignore the warning?

Which one of these is more idiomatic?

The best way to deal with it is to ask why a returned value is being ignored. That usually points to a bug in the code.

2 Likes

Option 3 is strictly better than option 2 (ignore has some special treatment in the compiler that was not available for option 2)

A more pedantic version is (fn (a,b) : type) -> ignore so when you add a new argument to fn, the partial application could be caught by the compiler. Note the special treatment I mentioned above could catch some partial application even without such type annotation, but you are using a more defensive style with type annotation.

2 Likes