Skip to content
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 #2285

Merged
merged 13 commits into from
Sep 12, 2021

Conversation

mmhat
Copy link
Collaborator

@mmhat mmhat commented Aug 21, 2021

This commit adds two fields to both constructors of
Dhall.TH.HaskellType:

  • One flag to control whether a FromDhall
    instance will be generated.
  • The other one controls whether a ToDhall instance will be generated.

Fixes: #2262

Copy link
Collaborator

@Gabriella439 Gabriella439 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first suggestion I would make is to leave the type of makeHaskellTypes the same, but create a new makeHaskellTypesWith function for this purpose, that takes a new Options argument

The second thing is that I just realized we probably would still need something like fieldModifier and constructorModifier here (except in the opposite direction as Dhall.Marshal.Internal, converting Dhall names to Haskell names). The reason why is that if the Dhall type uses reserved field names (like type) then the generated Haskell type will still be rejected, even if we don't generate FromDhall / ToDhall instances

This commit adds two fields to both constructors of
`Dhall.TH.HaskellType`: One flag to control whether a `FromDhall`
instance will be generated and one to control whether a `ToDhall`
instance will be generated.
This function controls how a Dhall union field is mapped to a Haskell
data constructor.
This function controls how a Dhall record field is mapped to a Haskell
record field.
@Gabriella439
Copy link
Collaborator

I just wanted to comment that this looks great so far!

@mmhat mmhat marked this pull request as ready for review September 10, 2021 19:29
dhall/src/Dhall/TH.hs Show resolved Hide resolved
dhall/src/Dhall/TH.hs Show resolved Hide resolved

toCases :: (Text -> Text) -> [Text] -> Q Exp
toCases f xs = do
err <- [| error $ "SHOULD NEVER HAPPEN: Unmatched " <> show $(pure nameE) |]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of adding a SHOULD NEVER HAPPEN: prefix, I would recommend using Dhall.Core.internalError here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the review; I'll do that.

@mmhat mmhat added the merge me label Sep 12, 2021
@mmhat mmhat merged commit ef579f3 into dhall-lang:master Sep 12, 2021
@mmhat mmhat deleted the 2262-configurable-hs-types branch October 25, 2023 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Modifying field names in generated Haskell types
2 participants