How to structure modules providing instances

In this case, I would suggest moving Transformable into its own module, then importing it into the modules which define Sequence and Pattern:

  • As more methods are added to Transformable, it may be possible to make some methods into top-level definitions, which are defined using other Transformable methods - in time, you’ll (ideally) end up with a small set of Transformable methods, and a library’s worth of dependent definitions (the classic example of this approach being the Monad type class - only two basic methods, and yet so many ways they can be used).

  • If that many methods really are needed, having each Transformable instance co-located with its type means any changes to just one type are unlikely to require recompiling the instances for both types (if there were no changes to Transformable).

3 Likes