[RESOLVED] Suppress an unused variable warning



I’m having a weird issue. I have a library that has a functor. To use that functor I need to write a correct parameter module that has a specific signature.

That signature contains :
val some_fun : ?opt:a -> b -> c.

My implementation does not need the optional parameter opt.
Therefore, I get a Warning 27: Unused Variable opt. I can’t remove or rename that parameter to something that will be ignored by the compiler, otherwise, my module does not match the required signature.
Is there an elegant solution (other than [@@@ocaml.warning "-27"]) ?
For now I’m doing let _ = opt in ....

I searched but did not find anyone with that issue.

Thanks !



It’s an often overlooked feature, but you can use a different name for the formal parameter (the one that will appear in the type) and for the binding (the name in scope in the body of the function). The syntax is ?formal:local. In that case you want to ignore the local binding, so:

let some_fun ?opt:_ x =
  do_something_with x


Amazing, exactly what I was looking for, thank you very much ! :slight_smile:

1 Like