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

Support constructors in rewrite rules #283

Open
celsobonutti opened this issue Feb 19, 2024 · 2 comments
Open

Support constructors in rewrite rules #283

celsobonutti opened this issue Feb 19, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@celsobonutti
Copy link

celsobonutti commented Feb 19, 2024

When trying to bind to an existing datatype (like Aeson.Value, for example), I believe I should add a custom rewrite rule, like:

rewrites:
  - from: "Data.AesonBind.Value"
    to: "Value"
    importing: "Data.Aeson"
  - from: "Data.AesonBind.Number"
    to: "Number"
    importing: "Data.Aeson"

When compiled, using Number will result in the following import:

import Data.Aeson (Number, Value)

But this results in a compile error, as the code should be

import Data.Aeson (Value(Number))

I'm not sure if support this kind of use-case makes sense for the project, but IMO it's a good feature to have when supporting binding to existing Haskell.

A possible solution I was thinking about would be adding an optional constructorOf field to the rewrite rules, so we could write it in the following way:

rewrites:
  - from: "Data.AesonBind.Value"
    to: "Value"
    importing: "Data.Aeson"
  - from: "Data.AesonBind.Number"
    to: "Number"
    importing: "Data.Aeson"
    constructorOf: "Value"

And it would generate the proper import.

I'd be happy to work on this if the feature makes sense 😊

@flupe
Copy link
Contributor

flupe commented Feb 22, 2024

I think agda2hs should definitely allow rewrite rules to constructors!

Though personally I would refrain from adding more fields to rewrite rules in the config file.

Perhaps we could make to : "Number.Value" mean "constructor Value of datatype Number" or something.

Waiting for @jespercockx to weigh in.

I don't know if we support rewrite rules over infix operators. In general we don't have any tests currently for rewrite rules, which should be fixed.

@jespercockx
Copy link
Member

I like the suggestion by @flupe , and I agree that we need test cases for rewrite rules.

@jespercockx jespercockx added the enhancement New feature or request label Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants