In OCaml, modules can structurally conform to many module types. I think this is kind of widely and implicitly understood to be the way to make data types or APIs conform to various ‘protocols’ or ‘typeclasses’, but can anyone point to any reading materials which walk through this? E.g., something that explores writing a module with types/functions that make it automatically conform to various signatures. So far I’ve been able to find materials that only allude to this rather than emphasizing it. E.g. in https://v1.realworldocaml.org/v1/en/html/functors.html
This works because many modules in Core, including
Int
andString
, satisfy an extended version of theComparable
signature described previously. Such standardized signatures are good practice, both because they make functors easier to use, and because they encourage standardization that makes your codebase easier to navigate.