Skip to content

Commit 07b96a2

Browse files
authored
Merge pull request #11821 from haskell/require-applicative-for-FieldGrammar
Require Applicative (g s) as a superclass of FieldGrammar
2 parents 67f85b0 + 4e2cbec commit 07b96a2

8 files changed

Lines changed: 22 additions & 35 deletions

File tree

Cabal-syntax/src/Distribution/FieldGrammar/Class.hs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{-# LANGUAGE ConstraintKinds #-}
22
{-# LANGUAGE FunctionalDependencies #-}
3+
{-# LANGUAGE KindSignatures #-}
4+
{-# LANGUAGE QuantifiedConstraints #-}
35
{-# LANGUAGE RankNTypes #-}
46
{-# LANGUAGE ScopedTypeVariables #-}
57
{-# LANGUAGE UndecidableSuperClasses #-}
@@ -13,6 +15,7 @@ module Distribution.FieldGrammar.Class
1315
, defaultFreeTextFieldDefST
1416
) where
1517

18+
import Data.Kind (Constraint, Type)
1619
import Distribution.Compat.Lens
1720
import Distribution.Compat.Prelude
1821
import Prelude ()
@@ -23,23 +26,22 @@ import Distribution.FieldGrammar.Newtypes
2326
import Distribution.Fields.Field
2427
import Distribution.Utils.ShortText
2528

26-
-- | 'FieldGrammar' is parametrised by
29+
-- | @g@ is parametrised by
2730
--
2831
-- * @s@ which is a structure we are parsing. We need this to provide prettyprinter
2932
-- functionality
3033
--
3134
-- * @a@ type of the field.
32-
--
33-
-- /Note:/ We'd like to have @forall s. Applicative (f s)@ context.
3435
class
3536
( c SpecVersion
3637
, c TestedWith
3738
, c SpecLicense
3839
, c Token
3940
, c Token'
4041
, c FilePathNT
42+
, forall s. Applicative (g s)
4143
) =>
42-
FieldGrammar c g
44+
FieldGrammar (c :: Type -> Constraint) (g :: Type -> Type -> Type)
4345
| g -> c
4446
where
4547
-- | Unfocus, zoom out, /blur/ 'FieldGrammar'.
@@ -231,7 +233,7 @@ monoidalField fn l = monoidalFieldAla fn Identity l
231233

232234
-- | Default implementation for 'freeTextFieldDefST'.
233235
defaultFreeTextFieldDefST
234-
:: (Functor (g s), FieldGrammar c g)
236+
:: FieldGrammar c g
235237
=> FieldName
236238
-> ALens' s ShortText
237239
-- ^ lens into the field

Cabal-syntax/src/Distribution/PackageDescription/FieldGrammar.hs

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,6 @@ import qualified Distribution.Types.Lens as L
9595

9696
packageDescriptionFieldGrammar
9797
:: ( FieldGrammar c g
98-
, Applicative (g PackageDescription)
99-
, Applicative (g PackageIdentifier)
10098
, c (Identity BuildType)
10199
, c (Identity PackageName)
102100
, c (Identity Version)
@@ -166,8 +164,6 @@ packageDescriptionFieldGrammar =
166164

167165
libraryFieldGrammar
168166
:: ( FieldGrammar c g
169-
, Applicative (g Library)
170-
, Applicative (g BuildInfo)
171167
, c (Identity LibraryVisibility)
172168
, c (List CommaFSep (Identity ExeDependency) ExeDependency)
173169
, c (List CommaFSep (Identity LegacyExeDependency) LegacyExeDependency)
@@ -218,8 +214,6 @@ libraryFieldGrammar n =
218214

219215
foreignLibFieldGrammar
220216
:: ( FieldGrammar c g
221-
, Applicative (g ForeignLib)
222-
, Applicative (g BuildInfo)
223217
, c (Identity ForeignLibType)
224218
, c (Identity LibVersionInfo)
225219
, c (Identity Version)
@@ -264,8 +258,6 @@ foreignLibFieldGrammar n =
264258

265259
executableFieldGrammar
266260
:: ( FieldGrammar c g
267-
, Applicative (g Executable)
268-
, Applicative (g BuildInfo)
269261
, c (Identity ExecutableScope)
270262
, c (List CommaFSep (Identity ExeDependency) ExeDependency)
271263
, c (List CommaFSep (Identity LegacyExeDependency) LegacyExeDependency)
@@ -339,8 +331,6 @@ testStanzaCodeGenerators f s = fmap (\x -> s{_testStanzaCodeGenerators = x}) (f
339331

340332
testSuiteFieldGrammar
341333
:: ( FieldGrammar c g
342-
, Applicative (g TestSuiteStanza)
343-
, Applicative (g BuildInfo)
344334
, c (Identity ModuleName)
345335
, c (Identity TestType)
346336
, c (List CommaFSep (Identity ExeDependency) ExeDependency)
@@ -488,8 +478,6 @@ benchmarkStanzaBuildInfo f s = fmap (\x -> s{_benchmarkStanzaBuildInfo = x}) (f
488478

489479
benchmarkFieldGrammar
490480
:: ( FieldGrammar c g
491-
, Applicative (g BenchmarkStanza)
492-
, Applicative (g BuildInfo)
493481
, c (Identity BenchmarkType)
494482
, c (Identity ModuleName)
495483
, c (List CommaFSep (Identity ExeDependency) ExeDependency)
@@ -597,7 +585,6 @@ unvalidateBenchmark b =
597585

598586
buildInfoFieldGrammar
599587
:: ( FieldGrammar c g
600-
, Applicative (g BuildInfo)
601588
, c (List CommaFSep (Identity ExeDependency) ExeDependency)
602589
, c (List CommaFSep (Identity LegacyExeDependency) LegacyExeDependency)
603590
, c (List CommaFSep (Identity PkgconfigDependency) PkgconfigDependency)
@@ -710,7 +697,6 @@ buildInfoFieldGrammar =
710697

711698
hsSourceDirsGrammar
712699
:: ( FieldGrammar c g
713-
, Applicative (g BuildInfo)
714700
, c (List FSep (SymbolicPathNT Pkg (Dir Source)) (SymbolicPath Pkg (Dir Source)))
715701
)
716702
=> g BuildInfo [SymbolicPath Pkg (Dir Source)]
@@ -727,7 +713,7 @@ hsSourceDirsGrammar =
727713
wrongLens f bi = (\fps -> set L.hsSourceDirs fps bi) <$> f []
728714

729715
optionsFieldGrammar
730-
:: (FieldGrammar c g, Applicative (g BuildInfo), c (List NoCommaFSep Token' String))
716+
:: (FieldGrammar c g, c (List NoCommaFSep Token' String))
731717
=> g BuildInfo (PerCompilerFlavor [String])
732718
optionsFieldGrammar =
733719
PerCompilerFlavor
@@ -744,7 +730,7 @@ optionsFieldGrammar =
744730
extract flavor = L.options . lookupLens flavor
745731

746732
profOptionsFieldGrammar
747-
:: (FieldGrammar c g, Applicative (g BuildInfo), c (List NoCommaFSep Token' String))
733+
:: (FieldGrammar c g, c (List NoCommaFSep Token' String))
748734
=> g BuildInfo (PerCompilerFlavor [String])
749735
profOptionsFieldGrammar =
750736
PerCompilerFlavor
@@ -755,7 +741,7 @@ profOptionsFieldGrammar =
755741
extract flavor = L.profOptions . lookupLens flavor
756742

757743
sharedOptionsFieldGrammar
758-
:: (FieldGrammar c g, Applicative (g BuildInfo), c (List NoCommaFSep Token' String))
744+
:: (FieldGrammar c g, c (List NoCommaFSep Token' String))
759745
=> g BuildInfo (PerCompilerFlavor [String])
760746
sharedOptionsFieldGrammar =
761747
PerCompilerFlavor
@@ -766,7 +752,7 @@ sharedOptionsFieldGrammar =
766752
extract flavor = L.sharedOptions . lookupLens flavor
767753

768754
profSharedOptionsFieldGrammar
769-
:: (FieldGrammar c g, Applicative (g BuildInfo), c (List NoCommaFSep Token' String))
755+
:: (FieldGrammar c g, c (List NoCommaFSep Token' String))
770756
=> g BuildInfo (PerCompilerFlavor [String])
771757
profSharedOptionsFieldGrammar =
772758
PerCompilerFlavor
@@ -789,7 +775,7 @@ lookupLens k f p@(PerCompilerFlavor ghc ghcjs)
789775
-------------------------------------------------------------------------------
790776

791777
flagFieldGrammar
792-
:: (FieldGrammar c g, Applicative (g PackageFlag))
778+
:: FieldGrammar c g
793779
=> FlagName
794780
-> g PackageFlag PackageFlag
795781
flagFieldGrammar name =
@@ -805,7 +791,7 @@ flagFieldGrammar name =
805791
-------------------------------------------------------------------------------
806792

807793
sourceRepoFieldGrammar
808-
:: (FieldGrammar c g, Applicative (g SourceRepo), c (Identity RepoType))
794+
:: (FieldGrammar c g, c (Identity RepoType))
809795
=> RepoKind
810796
-> g SourceRepo SourceRepo
811797
sourceRepoFieldGrammar kind =
@@ -824,7 +810,7 @@ sourceRepoFieldGrammar kind =
824810
-------------------------------------------------------------------------------
825811

826812
setupBInfoFieldGrammar
827-
:: (FieldGrammar c g, Functor (g SetupBuildInfo), c (List CommaVCat (Identity Dependency) Dependency))
813+
:: (FieldGrammar c g, c (List CommaVCat (Identity Dependency) Dependency))
828814
=> Bool
829815
-> g SetupBuildInfo SetupBuildInfo
830816
setupBInfoFieldGrammar def =

Cabal-syntax/src/Distribution/Types/InstalledPackageInfo/FieldGrammar.hs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ f <@> x = f <*> x
5555

5656
ipiFieldGrammar
5757
:: ( FieldGrammar c g
58-
, Applicative (g InstalledPackageInfo)
59-
, Applicative (g Basic)
6058
, c (Identity AbiHash)
6159
, c (Identity LibraryVisibility)
6260
, c (Identity PackageName)
@@ -301,7 +299,6 @@ basicLibVisibility f b =
301299

302300
basicFieldGrammar
303301
:: ( FieldGrammar c g
304-
, Applicative (g Basic)
305302
, c (Identity LibraryVisibility)
306303
, c (Identity PackageName)
307304
, c (Identity UnqualComponentName)

cabal-install/src/Distribution/Client/BuildReports/Anonymous.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,7 @@ cabalInstallID =
111111
-------------------------------------------------------------------------------
112112

113113
fieldDescrs
114-
:: ( Applicative (g BuildReport)
115-
, FieldGrammar c g
114+
:: ( FieldGrammar c g
116115
, c (Identity Arch)
117116
, c (Identity CompilerId)
118117
, c (Identity FlagAssignment)

cabal-install/src/Distribution/Client/CmdInstall/ClientInstallFlags.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ clientInstallOptions _ =
123123

124124
clientInstallFlagsGrammar
125125
:: ( FieldGrammar c g
126-
, Applicative (g ClientInstallFlags)
127126
, c (Identity (Flag Bool))
128127
, c (Flag' FilePathNT FilePath)
129128
, c (Identity (Flag OverwritePolicy))

cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1779,7 +1779,6 @@ legacyPackageConfigFieldDescrs =
17791779

17801780
legacyPackageConfigFGSectionDescrs
17811781
:: ( FieldGrammar c g
1782-
, Applicative (g SourceRepoList)
17831782
, c (Identity RepoType)
17841783
, c (List NoCommaFSep FilePathNT String)
17851784
, c (NonEmpty' NoCommaFSep Token String)
@@ -1811,7 +1810,6 @@ legacyPackageConfigSectionDescrs =
18111810

18121811
packageRepoSectionDescr
18131812
:: ( FieldGrammar c g
1814-
, Applicative (g SourceRepoList)
18151813
, c (Identity RepoType)
18161814
, c (List NoCommaFSep FilePathNT String)
18171815
, c (NonEmpty' NoCommaFSep Token String)

cabal-install/src/Distribution/Client/Types/SourceRepo.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ srpCommandLensNE f s = fmap (\x -> s{srpCommand = maybe [] toList x}) (f (nonEmp
102102

103103
sourceRepositoryPackageGrammar
104104
:: ( FieldGrammar c g
105-
, Applicative (g SourceRepoList)
106105
, c (Identity RepoType)
107106
, c (List NoCommaFSep FilePathNT String)
108107
, c (NonEmpty' NoCommaFSep Token String)

changelog.d/pr-11821.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
synopsis: Require `Applicative (g s)` as a superclass of `FieldGrammar`
3+
packages: [Cabal-syntax,cabal-install]
4+
prs: 11821
5+
---
6+
7+
This allows us to scrap a bit of boilerplate.

0 commit comments

Comments
 (0)