Generate per-type term coders in Haskell
Often, it is necessary to take an instance of a generated type like LatLon and encode it as a term, or conversely to take a term representing a LatLon and decode it to an instance of the generated type. This encoding is logically defined, but is not materialized as actual Haskell or Java code which can do the encoding/decoding for you.
In many cases, it would be helpful if Hydra were to generate these coders along with the type definition. In other cases, however, this would be overkill, and result in a large amount of code which is never used. The open problem is not so much how to generate the coders, which should be straightfoward, but when to generate them.
One option here is to add a boolean tag field like generateCoders to the DSL from which the type is being generated. That way the user is able to decide when they want to generate a coder.
What a great suggestion. That would be a boolean annotation.
Some other notes:
- If TypeA depends on TypeB, and TypeA is marked for coder generation, then a coder must be generated for TypeB as well.
- Not all types are encodable. E.g. function types
- The serialization variant of the "epsilon encoding" which maps types to terms and back (see CoreEncoding/CoreDecoding) would be a special case of these generated coders.