[ghc-steering-committee] Modifiers (Was: #512: NoFieldSelectors as datatype annotation)

Richard Eisenberg lists at richarde.dev
Thu Dec 22 13:45:48 UTC 2022


Georgi (the volunteer implementer) and I just had a nice chat about modifiers. See notes at https://gitlab.haskell.org/ghc/ghc/-/issues/22624#note_469566

Richard

> On Dec 21, 2022, at 8:12 AM, Richard Eisenberg <lists at richarde.dev> wrote:
> 
> Some collected thoughts on modifiers (which I have spent quite a bit of time mulling on over the past week):
> 
> - Yes, the current design struggles with changes affecting early stages.
> 
> - Modifiers affecting renaming are not entirely impossible though; they're just different. Normal, type-based modifiers allow the full expressiveness of the type system, including import/export, synonyms, and even computation via type families. However, even during renaming, we have identifiers with original names (that is, we can know the actual module where an identifier was initially declared, ignoring re-exports). So we could say that, in `%NoFieldSelectors data Rec = MkRec { field :: Int }`, NoFieldSelectors must be the actual modifier, not via any type synonym. That's unfortunate, but it's far from impossible.
> 
> - The key part of the design, for me, is uniform syntax. We use % to introduce a modifier. And it appears before the thing modified. Other aspects are nice-to-have, and so I decided to piggy-back on our expressive types to allow for some abstraction.
> 
> - One possibility is to have % introduce type-based modifiers, using some other symbol (possibly %%) to introduce string-y modifiers. Or we could say that e.g. %(of blah) is string-y -- note that it begins with a keyword.
> 
> Regardless of these design aspects, I think the initial roll-out can proceed, and then we can embellish as we learn from experience.
> 
> Richard
> 
>> On Dec 16, 2022, at 9:54 AM, Arnaud Spiwack <arnaud.spiwack at tweag.io <mailto:arnaud.spiwack at tweag.io>> wrote:
>> 
>> To be frank, my initial reaction to the modifiers proposal was not dissimilar to Joachim's. But I mellowed up to the type-based approach because of things like linear types (which need to be type-level values) and matchability (which also needs to for inference). As I understand it, adding arguments to the functional arrow (and, correspondingly, to binders) was one of the prime motivations for the design of modifiers. And as long as you annotate within expression, it seems to be a pretty reasonable design. Where maybe the proposal is overly enthusiastic (and I say “maybe” quite honestly: I don't really have an opinion) is to apply type-based modifiers to whole declarations (overlappable instance, or deactivating warnings), where the benefits of types are less clear, and we run into situation like Joachim's pointing out where we want to change the behaviour of the renamer. We may very well want to treat the definition granularity and the expression granularity very differently.
>> 
>> In the prior art in this space, there are also Rust's attributes, which are at the definition granularity (they are essentially just strings).
>> 
>> On Thu, 15 Dec 2022 at 13:04, Simon Peyton Jones <simon.peytonjones at gmail.com <mailto:simon.peytonjones at gmail.com>> wrote:
>> Hmm.  
>> We have an accepted proposal for modifiers.  
>> As of today we have a willing implementer, Georgi: https://gitlab.haskell.org/ghc/ghc/-/issues/22624 <https://gitlab.haskell.org/ghc/ghc/-/issues/22624>
>> And yet some doubt is being expressed in this thread about whether the accepted proposal is the one we really want.  
>> 
>> @rae Georgi says you are going to mentor him.  Do you feel able to help us converge on a design we are all content with; quite possibly just reaffirming the current accepted proposal?
>> 
>> Simon
>> 
>> 
>> 
>> On Thu, 15 Dec 2022 at 09:43, Joachim Breitner <mail at joachim-breitner.de <mailto:mail at joachim-breitner.de>> wrote:
>> Hi Richard,
>> 
>> thanks, comparing Modifiers to the annotations and attributes in other
>> languages indeed puts this into a perspective that makes more sense to
>> me. It seems I have assumed a broader scope for modifiers (maybe
>> because “modify” sounds much stronger than “annotate” or
>> “attribut…ize”). So I conclude the goal is not to necessarily to remove
>> _all_ kind of  pragmas, but only maybe those that fit the pattern (e.g.
>> don’t affect parsing and renaming). Is that right?
>> 
>> So my straw man “could qualified imports be modifiers” is simply out of
>> scope (heh).
>> 
>> Especially the potential use case for plugins (which do benefit from an
>> extensible, namespaced scheme that does not require changes to parsing)
>> – essentially a variant of the ANN pragma – is convincing.
>> 
>> Turning back to NoFieldSelectors, however, I notice that
>> NoFieldSelectors _does_ affect renaming already, because it affects
>> whether a symbol with the field’s name is in scope (which, in
>> particular, has further effects with implicit binders etc…), doesn't
>> it? So would modifiers, if we had them, even work here?
>> 
>> 
>> Cheers,
>> Joachim
>> -- 
>> Joachim Breitner
>>   mail at joachim-breitner.de <mailto:mail at joachim-breitner.de>
>>   http://www.joachim-breitner.de/ <http://www.joachim-breitner.de/>
>> 
>> _______________________________________________
>> ghc-steering-committee mailing list
>> ghc-steering-committee at haskell.org <mailto:ghc-steering-committee at haskell.org>
>> https://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-steering-committee <https://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-steering-committee>
>> _______________________________________________
>> ghc-steering-committee mailing list
>> ghc-steering-committee at haskell.org <mailto:ghc-steering-committee at haskell.org>
>> https://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-steering-committee <https://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-steering-committee>
>> _______________________________________________
>> ghc-steering-committee mailing list
>> ghc-steering-committee at haskell.org <mailto:ghc-steering-committee at haskell.org>
>> https://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-steering-committee
> 
> _______________________________________________
> ghc-steering-committee mailing list
> ghc-steering-committee at haskell.org
> https://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-steering-committee

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-steering-committee/attachments/20221222/17e8776c/attachment.html>


More information about the ghc-steering-committee mailing list