Holmusk / elm-street

:deciduous_tree: Crossing the road between Haskell and Elm
Mozilla Public License 2.0
88 stars 6 forks source link

Allow specifying custom code generation settings #131

Closed jhrcek closed 1 year ago

jhrcek commented 1 year ago

I'm playing with ways that would allow resolving https://github.com/Holmusk/elm-street/issues/129 while keeping the old behavior (stripping type name prefix) by default.

The important thing is that generated Elm encoders and decoders have to be compatible with ToJSON / FromJSON instances of Haskell types used across Haskell + Elm. This means that both Elm instance and ToJSON / FromJSON must use the same (what I call) CodeGenSettings that carry the "field label modifier" function (which for now is the only aspect of code generation that we allow to override).

See Type.hs for an example of how this could be used.

I'll need to think if this could be done more nicely over the next few days, but feel free to provide feedback if any.

jhrcek commented 1 year ago

Thanks, docs updated.

turboMaCk commented 1 year ago

Is anything blocking merge of this?

jhrcek commented 1 year ago

We didn't get any feedback from @silky who actually requested that change. Let me revisit this PR and make it mergeable within the next few days if we don't hear from him.

silky commented 1 year ago

Apologies for never getting around to responding to this; in the end I changed jobs since I needed it :)

But at a glance, it definitely does what I wanted, and I'll probably have cause to use it again at some point in the future; so that's great! Thanks :) 🙏🏻