Support constructors in rewrite rules
celsobonutti opened this issue · 2 comments
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 😊
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.
I like the suggestion by @flupe , and I agree that we need test cases for rewrite rules.