Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Support template haskell for multiple datatypes #1664
Inspired by this discussion: https://discourse.dhall-lang.org/t/makehaskelltypefromunion-and-fields-with-sum-types/150
This adds a new
Inspired by this discussion: https://discourse.dhall-lang.org/t/makehaskelltypefromunion-and-fields-with-sum-types/150 This adds a new `makeHaskellTypes` utility which can generate multiple types which can refer to each other. The trick is that the type compares nested Dhall types against top-level ones and replaces them with Haskell datatype references when the types are judgmentally equivalent.
@Gabriel439 I'm using this to see how it works in my code base.
However, as briefly mentioned in Discourse, the only problematic parts are newtypes ... specifically newtypes over non-Dhall types.
The original types use two newtypes --
I also think needing to define parallel types that differ only in some fields using newtypes beats the point of generating the original type using TH. I don't know what a good solution to this would be. We could hack the arguments to the TH function to specify custom types for record fields, but this won't map well to sum type constructor arguments. Unfortunately newtypes are unavoidable if we are to parse some well-known types like dates.
@srid: This is a pretty common issue for IDLs in general (e.g. protocol buffers, thrift, etc.). Usually the generated code doesn't exactly match what you want and you have to perform some additional conversions to the actual types you want to use or settle for the default type