-
Notifications
You must be signed in to change notification settings - Fork 217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modifying field names in generated Haskell types #2262
Comments
@mgoldenberg: Sorry for the delay in answering this! What if the generated code could optionally omit the generated |
IMHO something like aesons |
Thanks so much for the replies! I had not noticed the |
@Gabriel439, I had a chance to look at |
Thanks @mmhat , that's very useful! |
Thanks for implementing this, I really appreciate it! |
I have a set of Dhall types which I recently started generating in Haskell with
Dhall.TH.makeHaskellTypes
. This is a really handy tool, but there are certain cases where the mechanism breaks down. For example, Dhall and Haskell don't have the same restrictions on naming. Given that the Haskell types are generated without modification from the Dhall types, one can run into naming issues which prevent proper Haskell code from being generated.Consider the following (contrived) example. Given a Dhall file,
Foo.dhall
, with contents:when generating this type with
we get the following generated code
This code doesn't compile, of course, because
type
is a reserved word in Haskell. In some cases it may be easy to just rename the field to something that is a proper field name in Haskell; however, renaming a field in the Dhall type is not always straightforward if you're in later stages of a project and are already depending on a particular field name in other places prior to having generating the Haskell code.I was wondering if there is an easy way to modify the field name that is generated in the Haskell code. If not, perhaps there could be another function for doing so. For instance, one could add a prefix to all fields generated, like so:
which might generate
Or perhaps instead of a single function, one passes a record that has all sorts of settings for how to generate the Haskell type.
Any thoughts or help would be greatly appreciated!
The text was updated successfully, but these errors were encountered: