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

Cannot have two messages with the same parameter name of different types #272

Open
NorfairKing opened this issue Feb 9, 2023 · 3 comments

Comments

@NorfairKing
Copy link

Test1 a@Text: #{a}
Test2 a@Int: #{show a}

Results in:

    • Constructors MsgTest1 and MsgTest2
      give different types for field
      ‘appMessageA’
    • In the data type declaration for ‘AppMessage’
@parsonsmatt
Copy link
Collaborator

That's a GHC restriction, actually - it's trying to generate a record like:

data AppMessage 
    = MsgTest1 { appMessageA :: Text }
    | MsgTest2 { appMessageA :: Int }

which GHC rejects, since the term appMessageA now has two conflicting types (as a field accessor).

shakespeare could probably throw a more informative error if it detects this case, or provide a "field name customization option" that would make these distinct, or simply not generate field labels like this, or expect DuplicateRecordFields + NoFieldSelectors and nested datatypes instead of a single sum.

@NorfairKing
Copy link
Author

@parsonsmatt
Thanks for the explanation.
What is the appMessageA field used for?
Perhaps it could just be an unnamed field?
This would be safer as well.

@parsonsmatt
Copy link
Collaborator

I'm not familiar with the codebase really, but I'd guess that the templating uses a record field name to access the value, since that tends to be easier to generate code for than pattern matching with fresh names

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants