DEV Community

Discussion on: OCaml interface files–hero or menace?

Collapse
 
anler profile image
Anler • Edited

In other words–a module can wear many masks, depending on who is using it. I'll explore this technique more in a future post.

Do you know if there's a way of telling the compiler which interface file to use depending on the environment? For example:

  • testing: keep all definitions public to allow unit testing
  • release: use a more strict/production-oriented interface file

This is one of the things I miss most from Rust

Collapse
 
yawaramin profile image
Yawar Amin

Yes–apply the signature to the module at its point of use, not its point of definition. This keeps the module definition as general as possible but you can expose different facets of the module to different consumers.

Personally I don't recommend that, however. I think that unit tests should test using the exact same interface that's exposed in production. They shouldn't become deeply coupled to implementation details, because that leads to fragile tests.