Skip to content

Support constructors in rewrite rules #283

@celsobonutti

Description

@celsobonutti

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 😊

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions