ocaml-ppx / ppx_import

Less redundancy in type declarations and signatures
MIT License
89 stars 29 forks source link

Handling of groups of types #43

Closed frank-emrich closed 5 years ago

frank-emrich commented 5 years ago

Hi,

I'm interested in using ppx_import for a group of recursive types at once and applying the same substitutions to all of them. Essentially, I would need a form of import for this where you provide a list of types and the same with clause applies to all of them. From looking at the code I guess this is currently unsupported and would be quite hacky to implement for the existing %import extension ... mostly because the current one is expected in place of a single type definition.

Instead of having to write

type foo = [%import: M.foo [@with very-long-with-clause ]]
and  moo = [%import: M.moo [@with very-long-with-clause ]]
and  bar = [%import: M.bar [@with very-long-with-clause ]]

it would be nice to have a form

[%%import_types 
  M.foo,
  M.moo,
  M.bar
  [@with very-long-with-clause ]
]

in a structure, equivalent to the above. Using a comma separated-list is a bit of a hack because the payload would then parse as an expression rather than a type, but at least it looks nice.

If people think that this is a good idea I would volunteer to try implementing it. I'm open to suggestions about the syntax if there's something nicer!

whitequark commented 5 years ago

This syntax seems seriously flawed to me.

frank-emrich commented 5 years ago

I agree it's far from ideal.... any idea for something nicer?