From e17a800817a370fd198831f12cff35122376fa8d Mon Sep 17 00:00:00 2001 From: "simonpj@microsoft.com" Date: Wed, 7 Oct 2009 15:52:51 +0000 Subject: [PATCH] Add flag -XExplicitForAll and document it This implements the Haskell Prime proposal http://hackage.haskell.org/trac/haskell-prime/wiki/ExplicitForall Flag is -XExplicitForAll Implied by Opt_RankNTypes, Opt_Rank2Types, Opt_ScopedTypeVariables, Opt_LiberalTypeSynonyms, Opt_ExistentialQuantification, Opt_PolymorphicComponents --- compiler/main/DynFlags.hs | 11 +++++++- compiler/parser/Lexer.x | 35 +++++++++++------------- compiler/rename/RnEnv.lhs | 2 +- docs/users_guide/flags.xml | 13 +++++++++ docs/users_guide/glasgow_exts.xml | 54 +++++++++++++++++++------------------ 5 files changed, 67 insertions(+), 48 deletions(-) diff --git a/compiler/main/DynFlags.hs b/compiler/main/DynFlags.hs index 46c9d20..3188658 100644 --- a/compiler/main/DynFlags.hs +++ b/compiler/main/DynFlags.hs @@ -256,6 +256,7 @@ data DynFlag | Opt_TypeOperators | Opt_PackageImports | Opt_NewQualifiedOperators + | Opt_ExplicitForAll | Opt_PrintExplicitForalls @@ -1816,6 +1817,7 @@ xFlags = [ ( "NPlusKPatterns", Opt_NPlusKPatterns, const Supported ), -- On by default (which is not strictly H98): ( "MonoPatBinds", Opt_MonoPatBinds, const Supported ), + ( "ExplicitForAll", Opt_ExplicitForAll, const Supported ), ( "MonoLocalBinds", Opt_MonoLocalBinds, const Supported ), ( "RelaxedPolyRec", Opt_RelaxedPolyRec, const Supported ), ( "ExtendedDefaultRules", Opt_ExtendedDefaultRules, const Supported ), @@ -1847,7 +1849,14 @@ xFlags = [ impliedFlags :: [(DynFlag, DynFlag)] impliedFlags - = [ (Opt_GADTs, Opt_RelaxedPolyRec) -- We want type-sig variables to + = [ (Opt_RankNTypes, Opt_ExplicitForAll) + , (Opt_Rank2Types, Opt_ExplicitForAll) + , (Opt_ScopedTypeVariables, Opt_ExplicitForAll) + , (Opt_LiberalTypeSynonyms, Opt_ExplicitForAll) + , (Opt_ExistentialQuantification, Opt_ExplicitForAll) + , (Opt_PolymorphicComponents, Opt_ExplicitForAll) + + , (Opt_GADTs, Opt_RelaxedPolyRec) -- We want type-sig variables to -- be completely rigid for GADTs , (Opt_TypeFamilies, Opt_RelaxedPolyRec) -- Trac #2944 gives a nice example diff --git a/compiler/parser/Lexer.x b/compiler/parser/Lexer.x index 675b4d6..fe5c693 100644 --- a/compiler/parser/Lexer.x +++ b/compiler/parser/Lexer.x @@ -1753,26 +1753,21 @@ mkPState buf loc flags = } where bitmap = genericsBit `setBitIf` dopt Opt_Generics flags - .|. ffiBit `setBitIf` dopt Opt_ForeignFunctionInterface flags - .|. parrBit `setBitIf` dopt Opt_PArr flags - .|. arrowsBit `setBitIf` dopt Opt_Arrows flags - .|. thBit `setBitIf` dopt Opt_TemplateHaskell flags - .|. qqBit `setBitIf` dopt Opt_QuasiQuotes flags - .|. ipBit `setBitIf` dopt Opt_ImplicitParams flags - .|. explicitForallBit `setBitIf` dopt Opt_ScopedTypeVariables flags - .|. explicitForallBit `setBitIf` dopt Opt_LiberalTypeSynonyms flags - .|. explicitForallBit `setBitIf` dopt Opt_PolymorphicComponents flags - .|. explicitForallBit `setBitIf` dopt Opt_ExistentialQuantification flags - .|. explicitForallBit `setBitIf` dopt Opt_Rank2Types flags - .|. explicitForallBit `setBitIf` dopt Opt_RankNTypes flags - .|. bangPatBit `setBitIf` dopt Opt_BangPatterns flags - .|. tyFamBit `setBitIf` dopt Opt_TypeFamilies flags - .|. haddockBit `setBitIf` dopt Opt_Haddock flags - .|. magicHashBit `setBitIf` dopt Opt_MagicHash flags - .|. kindSigsBit `setBitIf` dopt Opt_KindSignatures flags - .|. recursiveDoBit `setBitIf` dopt Opt_RecursiveDo flags - .|. unicodeSyntaxBit `setBitIf` dopt Opt_UnicodeSyntax flags - .|. unboxedTuplesBit `setBitIf` dopt Opt_UnboxedTuples flags + .|. ffiBit `setBitIf` dopt Opt_ForeignFunctionInterface flags + .|. parrBit `setBitIf` dopt Opt_PArr flags + .|. arrowsBit `setBitIf` dopt Opt_Arrows flags + .|. thBit `setBitIf` dopt Opt_TemplateHaskell flags + .|. qqBit `setBitIf` dopt Opt_QuasiQuotes flags + .|. ipBit `setBitIf` dopt Opt_ImplicitParams flags + .|. explicitForallBit `setBitIf` dopt Opt_ExplicitForAll flags + .|. bangPatBit `setBitIf` dopt Opt_BangPatterns flags + .|. tyFamBit `setBitIf` dopt Opt_TypeFamilies flags + .|. haddockBit `setBitIf` dopt Opt_Haddock flags + .|. magicHashBit `setBitIf` dopt Opt_MagicHash flags + .|. kindSigsBit `setBitIf` dopt Opt_KindSignatures flags + .|. recursiveDoBit `setBitIf` dopt Opt_RecursiveDo flags + .|. unicodeSyntaxBit `setBitIf` dopt Opt_UnicodeSyntax flags + .|. unboxedTuplesBit `setBitIf` dopt Opt_UnboxedTuples flags .|. standaloneDerivingBit `setBitIf` dopt Opt_StandaloneDeriving flags .|. transformComprehensionsBit `setBitIf` dopt Opt_TransformListComp flags .|. rawTokenStreamBit `setBitIf` dopt Opt_KeepRawTokenStream flags diff --git a/compiler/rename/RnEnv.lhs b/compiler/rename/RnEnv.lhs index 64e299e..20d2218 100644 --- a/compiler/rename/RnEnv.lhs +++ b/compiler/rename/RnEnv.lhs @@ -1089,7 +1089,7 @@ unknownNameErr rdr_name perhapsForallMsg :: SDoc perhapsForallMsg - = vcat [ ptext (sLit "Perhaps you intended to use -XRankNTypes or similar flag") + = vcat [ ptext (sLit "Perhaps you intended to use -XExplicitForAll or similar flag") , ptext (sLit "to enable explicit-forall syntax: forall . ")] unknownSubordinateErr :: SDoc -> RdrName -> SDoc diff --git a/docs/users_guide/flags.xml b/docs/users_guide/flags.xml index b87044f..aae0f59 100644 --- a/docs/users_guide/flags.xml +++ b/docs/users_guide/flags.xml @@ -820,6 +820,19 @@ + + Enable explicit universal quantification. + Implied by , + , + , + , + , + + + dynamic + + + Enable polymorphic components for data constructors. dynamic diff --git a/docs/users_guide/glasgow_exts.xml b/docs/users_guide/glasgow_exts.xml index befb416..093858b 100644 --- a/docs/users_guide/glasgow_exts.xml +++ b/docs/users_guide/glasgow_exts.xml @@ -78,6 +78,7 @@ documentation describes all the libraries that come with GHC. , , , + , , , , @@ -1664,7 +1665,8 @@ The following syntax is stolen: forall - Stolen (in types) by: , + Stolen (in types) by: , and hence by + , , , , @@ -4713,10 +4715,30 @@ might be in another module, or even in a module that is not yet written. Other type system extensions - -Type signatures +Explicit universal quantification (forall) + +Haskell type signatures are implicitly quantified. When the language option +is used, the keyword forall +allows us to say exactly what this means. For example: + + + + g :: b -> b + +means this: + + g :: forall b. (b -> b) + +The two are treated identically. + + +Of course forall becomes a keyword; you can't use forall as +a type variable any more! + + + -The context of a type signature +The context of a type signature The flag lifts the Haskell 98 restriction that the type-class constraints in a type signature must have the @@ -4745,7 +4767,7 @@ Consider the type: language omits them; in Haskell 98, all the free type variables of an explicit source-language type signature are universally quantified, except for the class type variables in a class declaration. However, -in GHC, you can give the foralls if you want. See ). +in GHC, you can give the foralls if you want. See ). @@ -4833,9 +4855,6 @@ territory free in case we need it later. - - - @@ -5313,22 +5332,7 @@ The parentheses are required. -Haskell type signatures are implicitly quantified. The new keyword forall -allows us to say exactly what this means. For example: - - - - g :: b -> b - -means this: - - g :: forall b. (b -> b) - -The two are treated identically. - - - -However, GHC's type system supports arbitrary-rank +GHC's type system supports arbitrary-rank explicit universal quantification in types. For example, all the following types are legal: @@ -5383,8 +5387,6 @@ field type signatures. -Of course forall becomes a keyword; you can't use forall as -a type variable any more! -- 1.7.10.4