yesodweb / shakespeare

Haml-like template files that are compile-time checked
http://www.yesodweb.com/book/shakespearean-templates
MIT License
136 stars 76 forks source link

OverloadedRecordDot-style record access #274

Closed spencerjanssen closed 1 year ago

spencerjanssen commented 1 year ago

This PR adds OverloadedRecordDot support to templates on compilers that support that extension.

I believe this will not break existing templates because the parser for infix operator expressions requires spaces around the operator: x.y was previously rejected; x . y parses to (.) x y.

I'm not sure how best to handle record dot expressions on older compilers. The solution I landed on is to allow them in the parser and throw an exception when building the Template Haskell Exp.

parsonsmatt commented 1 year ago

We could do the desugaring manually and generate getField @"fieldName" x, or, to avoid needing TypeApplications, possibly (getField :: HasField "fieldName" s t => s -> t) x (though that probably also requires some extensions)

spencerjanssen commented 1 year ago

Looks like we could go as far back as GHC 8.2.1/base 4.10.0.0/template-haskell 2.12.0.0 with the type application approach. I'm happy to implement that if you'd prefer.

snoyberg commented 1 year ago

Only question from me: based on the comments, this looks like it's a backwards-compatible change. If so, do we need the major version bump present in the PR right now?

spencerjanssen commented 1 year ago

I bumped the major version because we're adding a new constructor to the Deref type exported from Text.Shakespeare.Base.

snoyberg commented 1 year ago

Got it, thanks!