tfausak / cabal-gild

:crown: Format Haskell package descriptions.
https://hackage.haskell.org/package/cabal-gild
MIT License
48 stars 5 forks source link

Extensions starting with "No" get ordered last #31

Closed nikita-volkov closed 8 months ago

nikita-volkov commented 8 months ago

E.g.,

common base-settings
  default-extensions:
    TypeOperators
    UnboxedTuples
    NoImplicitPrelude
    NoMonomorphismRestriction

Possible solution: sort them by their renderings using sortWith.

tfausak commented 8 months ago

I did this on purpose. See #30 and https://github.com/tweag/ormolu/pull/471. My thought was that No* extensions need to be sorted after everything else. Otherwise you may not be able to disable an extension that's implied by another one. For example you wouldn't be able to have default-extensions: ScopedTypeVariables NoExplicitForAll (if for some weird reason you wanted that).

In practice I don't think people are likely to run into issues like that. Disabling extensions that are implied by other extensions is (I think) not that common, and it seems especially unlikely in default-extensions. I could be convinced to simply sort these by name without any special care for No* extensions. It would make the code simpler too:

https://github.com/tfausak/cabal-gild/blob/c86aba2fb7d048666a3e80cc3dfe412b57a88f13/source/library/CabalGild/Type/Extension.hs#L18-L19

nikita-volkov commented 8 months ago

It doesn't seem to be that the No prefix is only used with a meaning of disabling extensions. E.g., with the mentioned NoImplicitPrelude and NoMonomorphismRestriction there seem to be no extensions that these would be disabling.

I could be convinced to simply sort these by name without any special care for No* extensions.

That's what I was implying actually. Sorry for not making it clear :)

tfausak commented 8 months ago

I know they're documented that way, but extensions like NoImplicitPrelude really do just mean "disable ImplicitPrelude. It's just that most extensions are disabled by default, so only a few are typically written as No*.

However I'm realizing now that my motivation is a little flimsy. Yeah, someone may want to have -XScopedTypeVariables and -XNoExplicitForAll, but they could just as well want -XRebindableSyntax and -XImplicitPrelude. This is what Ormolu tackles with its LanguagePragmaClass. I'm not crazy about adding something like that to Gild.

Fortunately Gild has an escape hatch that Ormolu doesn't: You can have multiple default-extensions blocks and they will be concatenated. So if you find yourself in a situation where one extension really needs to come before (or after) another, you can do this:

default-extensions: ScopedTypeVariables
default-extensions: NoExplicitForAll

That works because Gild doesn't merge values or reorder them.

tfausak commented 8 months ago

Fixed in version 1.0.2.3.