Here is an example of so-called phantom types and covariance in Scala to improve type safety and correctness. The example is a simplified version from a real project.
I present the example as source code so you can copy into an editor and play with it. References for further reading are given at the bottom of the post.
In summary, using a covariant phantom type has enabled the ActionPanel to enforce the types of its arguments more strongly and supporting a Disabled (default) implementation.
This was exactly what I needed in my real project, I hope its useful to you.
We encourage discussion of our blog posts on our Gitter channel.
Please review our Community Guidelines before posting there.
We encourage discussion in good faith, but do not allow combative, exclusionary, or harassing behaviour.
If you have any questions, contact us!