tweag / cooked-validators

MIT License
39 stars 11 forks source link

Improve module structure for `Cooked.Pretty` #265

Closed florentc closed 1 year ago

florentc commented 1 year ago

Cooked.Pretty is currently a messy module. It contains helper functions, PrettyCooked instances for Plutus types, PrettyCooked instances for a few cooked types, and functions to pretty print cooked structures such as skeletons and chain state.

Problems

Proposed reorganization

Chosen compromise about orphaned instances

According to best practices, to avoid conflicting instances, instances should be implemented either:

  1. In the module the datatype/newtype is defined
  2. In the module the class is defined

For Plutus types: the only possible choice is option 2. This is what is done in Cooked.Pretty.Class. Future instances for types that are defined outside cooked should go there.

For our homemade types, option 2 is not possible because it would induce a cycle in imports (e.g. between Cooked.Skeleton and Cooked.Pretty.Class). The only "good practice" solution is therefore option 1. However, we decided early on to remove all pretty-printing matter from cooked outside of the Cooked.Pretty modules. Therefore, this PR compromises by keeping orphan instances for our homemade types. For now there are only 2 of those, in Cooked.Pretty.Cooked.