1 {-# LANGUAGE DeriveDataTypeable #-}
2 {-# LANGUAGE DeriveGeneric #-}
4 -----------------------------------------------------------------------------
6 -- Module : Language.Haskell.Extension
7 -- Copyright : Isaac Jones 2003-2004
10 -- Maintainer : libraries@haskell.org
11 -- Portability : portable
13 -- Haskell language dialects and extensions
15 module Language
.Haskell
.Extension
(
28 import Distribution
.Compat
.Prelude
30 import Distribution
.Text
31 import qualified Distribution
.Compat
.ReadP
as Parse
33 import qualified Text
.PrettyPrint
as Disp
34 import Data
.Array (Array, accumArray, bounds, Ix
(inRange), (!))
36 -- ------------------------------------------------------------
38 -- ------------------------------------------------------------
40 -- | This represents a Haskell language dialect.
42 -- Language 'Extension's are interpreted relative to one of these base
47 -- | The Haskell 98 language as defined by the Haskell 98 report.
48 -- <http://haskell.org/onlinereport/>
51 -- | The Haskell 2010 language as defined by the Haskell 2010 report.
52 -- <http://www.haskell.org/onlinereport/haskell2010>
55 -- | An unknown language, identified by its name.
56 | UnknownLanguage
String
57 deriving (Generic
, Show, Read, Eq
, Typeable
, Data
)
59 instance Binary Language
61 knownLanguages
:: [Language
]
62 knownLanguages
= [Haskell98
, Haskell2010
]
64 instance Text Language
where
65 disp
(UnknownLanguage other
) = Disp
.text other
66 disp other
= Disp
.text
(show other
)
69 lang
<- Parse
.munch1
isAlphaNum
70 return (classifyLanguage lang
)
72 classifyLanguage
:: String -> Language
73 classifyLanguage
= \str
-> case lookup str langTable
of
75 Nothing
-> UnknownLanguage str
77 langTable
= [ (show lang
, lang
)
78 | lang
<- knownLanguages
]
80 -- ------------------------------------------------------------
82 -- ------------------------------------------------------------
84 -- Note: if you add a new 'KnownExtension':
86 -- * also add it to the Distribution.Simple.X.languageExtensions lists
87 -- (where X is each compiler: GHC, JHC, LHC, UHC, HaskellSuite)
89 -- | This represents language extensions beyond a base 'Language' definition
90 -- (such as 'Haskell98') that are supported by some implementations, usually
91 -- in some special mode.
93 -- Where applicable, references are given to an implementation's
94 -- official documentation.
97 -- | Enable a known extension
98 EnableExtension KnownExtension
100 -- | Disable a known extension
101 | DisableExtension KnownExtension
103 -- | An unknown extension, identified by the name of its @LANGUAGE@
105 | UnknownExtension
String
107 deriving (Generic
, Show, Read, Eq
, Ord
, Typeable
, Data
)
109 instance Binary Extension
111 data KnownExtension
=
113 -- | Allow overlapping class instances, provided there is a unique
114 -- most specific instance for each use.
116 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XOverlappingInstances>
119 -- | Ignore structural rules guaranteeing the termination of class
120 -- instance resolution. Termination is guaranteed by a fixed-depth
121 -- recursion stack, and compilation may fail if this depth is
124 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XUndecidableInstances>
125 | UndecidableInstances
127 -- | Implies 'OverlappingInstances'. Allow the implementation to
128 -- choose an instance even when it is possible that further
129 -- instantiation of types will lead to a more specific instance
132 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XIncoherentInstances>
133 | IncoherentInstances
135 -- | /(deprecated)/ Deprecated in favour of 'RecursiveDo'.
137 -- Old description: Allow recursive bindings in @do@ blocks, using
138 -- the @rec@ keyword. See also 'RecursiveDo'.
141 -- | Allow recursive bindings in @do@ blocks, using the @rec@
142 -- keyword, or @mdo@, a variant of @do@.
144 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XRecursiveDo>
147 -- | Provide syntax for writing list comprehensions which iterate
148 -- over several lists together, like the 'zipWith' family of
151 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XParallelListComp>
154 -- | Allow multiple parameters in a type class.
156 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XMultiParamTypeClasses>
157 | MultiParamTypeClasses
159 -- | Enable the dreaded monomorphism restriction.
161 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XNoMonomorphismRestriction>
162 | MonomorphismRestriction
164 -- | Allow a specification attached to a multi-parameter type class
165 -- which indicates that some parameters are entirely determined by
166 -- others. The implementation will check that this property holds
167 -- for the declared instances, and will use this property to reduce
168 -- ambiguity in instance resolution.
170 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XFunctionalDependencies>
171 | FunctionalDependencies
173 -- | /(deprecated)/ A synonym for 'RankNTypes'.
175 -- Old description: Like 'RankNTypes' but does not allow a
176 -- higher-rank type to itself appear on the left of a function
179 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XRank2Types>
182 -- | Allow a universally-quantified type to occur on the left of a
185 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XRankNTypes>
188 -- | /(deprecated)/ A synonym for 'RankNTypes'.
190 -- Old description: Allow data constructors to have polymorphic
191 -- arguments. Unlike 'RankNTypes', does not allow this for ordinary
194 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#arbitrary-rank-polymorphism>
195 | PolymorphicComponents
197 -- | Allow existentially-quantified data constructors.
199 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XExistentialQuantification>
200 | ExistentialQuantification
202 -- | Cause a type variable in a signature, which has an explicit
203 -- @forall@ quantifier, to scope over the definition of the
204 -- accompanying value declaration.
206 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XScopedTypeVariables>
207 | ScopedTypeVariables
209 -- | Deprecated, use 'ScopedTypeVariables' instead.
212 -- | Enable implicit function parameters with dynamic scope.
214 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XImplicitParams>
217 -- | Relax some restrictions on the form of the context of a type
220 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XFlexibleContexts>
223 -- | Relax some restrictions on the form of the context of an
224 -- instance declaration.
226 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XFlexibleInstances>
229 -- | Allow data type declarations with no constructors.
231 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XEmptyDataDecls>
234 -- | Run the C preprocessor on Haskell source code.
236 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#language-pragma>
239 -- | Allow an explicit kind signature giving the kind of types over
240 -- which a type variable ranges.
242 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XKindSignatures>
245 -- | Enable a form of pattern which forces evaluation before an
246 -- attempted match, and a form of strict @let@/@where@ binding.
248 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XBangPatterns>
251 -- | Allow type synonyms in instance heads.
253 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XTypeSynonymInstances>
254 | TypeSynonymInstances
256 -- | Enable Template Haskell, a system for compile-time
259 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XTemplateHaskell>
262 -- | Enable the Foreign Function Interface. In GHC, implements the
263 -- standard Haskell 98 Foreign Function Interface Addendum, plus
264 -- some GHC-specific extensions.
266 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#language-pragma>
267 | ForeignFunctionInterface
269 -- | Enable arrow notation.
271 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XArrows>
274 -- | /(deprecated)/ Enable generic type classes, with default instances defined in
275 -- terms of the algebraic structure of a type.
277 -- * <https://haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#generic-classes>
280 -- | Enable the implicit importing of the module "Prelude". When
281 -- disabled, when desugaring certain built-in syntax into ordinary
282 -- identifiers, use whatever is in scope rather than the "Prelude"
285 -- * <https://haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#rebindable-syntax-and-the-implicit-prelude-import>
288 -- | Enable syntax for implicitly binding local names corresponding
289 -- to the field names of a record. Puns bind specific names, unlike
290 -- 'RecordWildCards'.
292 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XNamedFieldPuns>
295 -- | Enable a form of guard which matches a pattern and binds
298 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XPatternGuards>
301 -- | Allow a type declared with @newtype@ to use @deriving@ for any
302 -- class with an instance for the underlying type.
304 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XGeneralizedNewtypeDeriving>
305 | GeneralizedNewtypeDeriving
307 -- | Enable the \"Trex\" extensible records system.
309 -- * <http://haskell.org/hugs/pages/users_guide/hugs-only.html#TREX>
312 -- | Enable type synonyms which are transparent in some definitions
313 -- and opaque elsewhere, as a way of implementing abstract
316 -- * <http://haskell.org/hugs/pages/users_guide/restricted-synonyms.html>
317 | RestrictedTypeSynonyms
319 -- | Enable an alternate syntax for string literals,
320 -- with string templating.
322 -- * <http://haskell.org/hugs/pages/users_guide/here-documents.html>
325 -- | Allow the character @#@ as a postfix modifier on identifiers.
326 -- Also enables literal syntax for unboxed values.
328 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XMagicHash>
331 -- | Allow data types and type synonyms which are indexed by types,
332 -- i.e. ad-hoc polymorphism for types.
334 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XTypeFamilies>
337 -- | Allow a standalone declaration which invokes the type class
338 -- @deriving@ mechanism.
340 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XStandaloneDeriving>
343 -- | Allow certain Unicode characters to stand for certain ASCII
344 -- character sequences, e.g. keywords and punctuation.
346 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XUnicodeSyntax>
349 -- | Allow the use of unboxed types as foreign types, e.g. in
350 -- @foreign import@ and @foreign export@.
352 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#language-options>
355 -- | Enable interruptible FFI.
357 -- * <https://haskell.org/ghc/docs/latest/html/users_guide/ffi-chap.html#interruptible-foreign-calls>
360 -- | Allow use of CAPI FFI calling convention (@foreign import capi@).
362 -- * <https://haskell.org/ghc/docs/latest/html/users_guide/ffi-chap.html#the-capi-calling-convention>
365 -- | Defer validity checking of types until after expanding type
366 -- synonyms, relaxing the constraints on how synonyms may be used.
368 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XLiberalTypeSynonyms>
369 | LiberalTypeSynonyms
371 -- | Allow the name of a type constructor, type class, or type
372 -- variable to be an infix operator.
373 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XTypeOperators>
376 -- | Enable syntax for implicitly binding local names corresponding
377 -- to the field names of a record. A wildcard binds all unmentioned
378 -- names, unlike 'NamedFieldPuns'.
380 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XRecordWildCards>
383 -- | Deprecated, use 'NamedFieldPuns' instead.
386 -- | Allow a record field name to be disambiguated by the type of
387 -- the record it's in.
389 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XDisambiguateRecordFields>
390 | DisambiguateRecordFields
392 -- | Enable traditional record syntax (as supported by Haskell 98)
394 -- * <https://haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#traditional-record-syntax>
395 | TraditionalRecordSyntax
397 -- | Enable overloading of string literals using a type class, much
398 -- like integer literals.
400 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XOverloadedStrings>
403 -- | Enable generalized algebraic data types, in which type
404 -- variables may be instantiated on a per-constructor basis. Implies
407 -- * <https://haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#generalised-algebraic-data-types-gadts>
410 -- | Enable GADT syntax for declaring ordinary algebraic datatypes.
412 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XGADTSyntax>
415 -- | /(deprecated)/ Has no effect.
417 -- Old description: Make pattern bindings monomorphic.
419 -- * <https://downloads.haskell.org/~ghc/7.6.3/docs/html/users_guide/monomorphism.html>
422 -- | Relax the requirements on mutually-recursive polymorphic
425 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XRelaxedPolyRec>
428 -- | Allow default instantiation of polymorphic types in more
431 -- * <http://downloads.haskell.org/~ghc/latest/docs/html/users_guide/ghci.html#type-defaulting-in-ghci>
432 | ExtendedDefaultRules
434 -- | Enable unboxed tuples.
436 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XUnboxedTuples>
439 -- | Enable @deriving@ for classes 'Data.Typeable.Typeable' and
440 -- 'Data.Generics.Data'.
442 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XDeriveDataTypeable>
445 -- | Enable @deriving@ for 'GHC.Generics.Generic' and 'GHC.Generics.Generic1'.
447 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XDeriveGeneric>
450 -- | Enable support for default signatures.
452 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XDefaultSignatures>
455 -- | Allow type signatures to be specified in instance declarations.
457 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XInstanceSigs>
460 -- | Allow a class method's type to place additional constraints on
461 -- a class type variable.
463 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XConstrainedClassMethods>
464 | ConstrainedClassMethods
466 -- | Allow imports to be qualified by the package name the module is
467 -- intended to be imported from, e.g.
469 -- > import "network" Network.Socket
471 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XPackageImports>
474 -- | /(deprecated)/ Allow a type variable to be instantiated at a
477 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XImpredicativeTypes>
480 -- | /(deprecated)/ Change the syntax for qualified infix operators.
482 -- * <http://www.haskell.org/ghc/docs/6.12.3/html/users_guide/syntax-extns.html#new-qualified-operators>
483 | NewQualifiedOperators
485 -- | Relax the interpretation of left operator sections to allow
486 -- unary postfix operators.
488 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XPostfixOperators>
491 -- | Enable quasi-quotation, a mechanism for defining new concrete
492 -- syntax for expressions and patterns.
494 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XQuasiQuotes>
497 -- | Enable generalized list comprehensions, supporting operations
498 -- such as sorting and grouping.
500 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XTransformListComp>
503 -- | Enable monad comprehensions, which generalise the list
504 -- comprehension syntax to work for any monad.
506 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XMonadComprehensions>
507 | MonadComprehensions
509 -- | Enable view patterns, which match a value by applying a
510 -- function and matching on the result.
512 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XViewPatterns>
515 -- | Allow concrete XML syntax to be used in expressions and patterns,
516 -- as per the Haskell Server Pages extension language:
517 -- <http://www.haskell.org/haskellwiki/HSP>. The ideas behind it are
518 -- discussed in the paper \"Haskell Server Pages through Dynamic Loading\"
519 -- by Niklas Broberg, from Haskell Workshop '05.
522 -- | Allow regular pattern matching over lists, as discussed in the
523 -- paper \"Regular Expression Patterns\" by Niklas Broberg, Andreas Farre
524 -- and Josef Svenningsson, from ICFP '04.
527 -- | Enable the use of tuple sections, e.g. @(, True)@ desugars into
528 -- @\x -> (x, True)@.
530 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XTupleSections>
533 -- | Allow GHC primops, written in C--, to be imported into a Haskell
535 | GHCForeignImportPrim
537 -- | Support for patterns of the form @n + k@, where @k@ is an
540 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XNPlusKPatterns>
543 -- | Improve the layout rule when @if@ expressions are used in a @do@
547 -- | Enable support for multi-way @if@-expressions.
549 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XMultiWayIf>
552 -- | Enable support lambda-@case@ expressions.
554 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XLambdaCase>
557 -- | Makes much of the Haskell sugar be desugared into calls to the
558 -- function with a particular name that is in scope.
560 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XRebindableSyntax>
563 -- | Make @forall@ a keyword in types, which can be used to give the
564 -- generalisation explicitly.
566 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XExplicitForAll>
569 -- | Allow contexts to be put on datatypes, e.g. the @Eq a@ in
570 -- @data Eq a => Set a = NilSet | ConsSet a (Set a)@.
572 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XDatatypeContexts>
575 -- | Local (@let@ and @where@) bindings are monomorphic.
577 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XMonoLocalBinds>
580 -- | Enable @deriving@ for the 'Data.Functor.Functor' class.
582 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XDeriveFunctor>
585 -- | Enable @deriving@ for the 'Data.Traversable.Traversable' class.
587 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XDeriveTraversable>
590 -- | Enable @deriving@ for the 'Data.Foldable.Foldable' class.
592 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XDeriveFoldable>
595 -- | Enable non-decreasing indentation for @do@ blocks.
597 -- * <https://haskell.org/ghc/docs/latest/html/users_guide/bugs.html#context-free-syntax>
598 | NondecreasingIndentation
600 -- | Allow imports to be qualified with a safe keyword that requires
601 -- the imported module be trusted as according to the Safe Haskell
602 -- definition of trust.
604 -- > import safe Network.Socket
606 -- * <https://haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#safe-imports>
609 -- | Compile a module in the Safe, Safe Haskell mode -- a restricted
610 -- form of the Haskell language to ensure type safety.
612 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/safe_haskell.html#ghc-flag--XSafe>
615 -- | Compile a module in the Trustworthy, Safe Haskell mode -- no
616 -- restrictions apply but the module is marked as trusted as long as
617 -- the package the module resides in is trusted.
619 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/safe_haskell.html#ghc-flag--XTrustworthy>
622 -- | Compile a module in the Unsafe, Safe Haskell mode so that
623 -- modules compiled using Safe, Safe Haskell mode can't import it.
625 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/safe_haskell.html#ghc-flag--XUnsafe>
628 -- | Allow type class/implicit parameter/equality constraints to be
629 -- used as types with the special kind constraint. Also generalise
630 -- the @(ctxt => ty)@ syntax so that any type of kind constraint can
631 -- occur before the arrow.
633 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XConstraintKinds>
636 -- | Enable kind polymorphism.
638 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XPolyKinds>
641 -- | Enable datatype promotion.
643 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XDataKinds>
646 -- | Enable parallel arrays syntax (@[:@, @:]@) for /Data Parallel Haskell/.
648 -- * <http://www.haskell.org/haskellwiki/GHC/Data_Parallel_Haskell>
651 -- | Enable explicit role annotations, like in (@type role Foo representational representational@).
653 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XRoleAnnotations>
656 -- | Enable overloading of list literals, arithmetic sequences and
657 -- list patterns using the 'IsList' type class.
659 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XOverloadedLists>
662 -- | Enable case expressions that have no alternatives. Also applies to lambda-case expressions if they are enabled.
664 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XEmptyCase>
667 -- | /(deprecated)/ Deprecated in favour of 'DeriveDataTypeable'.
669 -- Old description: Triggers the generation of derived 'Typeable'
670 -- instances for every datatype and type class declaration.
672 -- * <https://haskell.org/ghc/docs/7.8.4/html/users_guide/deriving.html#auto-derive-typeable>
675 -- | Desugars negative literals directly (without using negate).
677 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XNegativeLiterals>
680 -- | Allow the use of binary integer literal syntax (e.g. @0b11001001@ to denote @201@).
682 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XBinaryLiterals>
685 -- | Allow the use of floating literal syntax for all instances of 'Num', including 'Int' and 'Integer'.
687 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XNumDecimals>
690 -- | Enable support for type classes with no type parameter.
692 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XNullaryTypeClasses>
695 -- | Enable explicit namespaces in module import/export lists.
697 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XExplicitNamespaces>
700 -- | Allow the user to write ambiguous types, and the type inference engine to infer them.
702 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XAllowAmbiguousTypes>
703 | AllowAmbiguousTypes
705 -- | Enable @foreign import javascript@.
708 -- | Allow giving names to and abstracting over patterns.
710 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XPatternSynonyms>
713 -- | Allow anonymous placeholders (underscore) inside type signatures. The
714 -- type inference engine will generate a message describing the type inferred
715 -- at the hole's location.
717 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XPartialTypeSignatures>
718 | PartialTypeSignatures
720 -- | Allow named placeholders written with a leading underscore inside type
721 -- signatures. Wildcards with the same name unify to the same type.
723 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XNamedWildCards>
726 -- | Enable @deriving@ for any class.
728 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XDeriveAnyClass>
731 -- | Enable @deriving@ for the 'Language.Haskell.TH.Syntax.Lift' class.
733 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XDeriveLift>
736 -- | Enable support for 'static pointers' (and the @static@
737 -- keyword) to refer to globally stable names, even across
738 -- different programs.
740 -- * <https://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#ghc-flag--XStaticPointers>
743 -- | Switches data type declarations to be strict by default (as if
744 -- they had a bang using @BangPatterns@), and allow opt-in field
745 -- laziness using @~@.
747 -- * <https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#ghc-flag--XStrictData>
750 -- | Switches all pattern bindings to be strict by default (as if
751 -- they had a bang using @BangPatterns@), ordinary patterns are
752 -- recovered using @~@. Implies @StrictData@.
754 -- * <https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#ghc-flag--XStrict>
757 -- | Allows @do@-notation for types that are @'Applicative'@ as well
758 -- as @'Monad'@. When enabled, desugaring @do@ notation tries to use
759 -- @(<*>)@ and @'fmap'@ and @'join'@ as far as possible.
762 -- | Allow records to use duplicated field labels for accessors.
763 | DuplicateRecordFields
765 -- | Enable explicit type applications with the syntax @id \@Int@.
768 -- | Dissolve the distinction between types and kinds, allowing the compiler
769 -- to reason about kind equality and therefore enabling GADTs to be promoted
770 -- to the type-level.
773 -- | Allow recursive (and therefore undecideable) super-class relationships.
774 | UndecidableSuperClasses
776 -- | A temporary extension to help library authors check if their
777 -- code will compile with the new planned desugaring of fail.
778 | MonadFailDesugaring
780 -- | A subset of @TemplateHaskell@ including only quasi-quoting.
781 | TemplateHaskellQuotes
783 -- | Allows use of the @#label@ syntax.
786 -- | Allow functional dependency annotations on type families to declare them
788 | TypeFamilyDependencies
790 deriving (Generic
, Show, Read, Eq
, Ord
, Enum
, Bounded
, Typeable
, Data
)
792 instance Binary KnownExtension
794 {-# DEPRECATED knownExtensions
795 "KnownExtension is an instance of Enum and Bounded, use those instead." #-}
796 knownExtensions
:: [KnownExtension
]
797 knownExtensions
= [minBound..maxBound]
799 -- | Extensions that have been deprecated, possibly paired with another
800 -- extension that replaces it.
802 deprecatedExtensions
:: [(Extension
, Maybe Extension
)]
803 deprecatedExtensions
=
804 [ (EnableExtension RecordPuns
, Just
(EnableExtension NamedFieldPuns
))
805 , (EnableExtension PatternSignatures
, Just
(EnableExtension ScopedTypeVariables
))
807 -- NOTE: when adding deprecated extensions that have new alternatives
808 -- we must be careful to make sure that the deprecation messages are
809 -- valid. We must not recommend aliases that cannot be used with older
810 -- compilers, perhaps by adding support in Cabal to translate the new
811 -- name to the old one for older compilers. Otherwise we are in danger
812 -- of the scenario in ticket #689.
814 instance Text Extension
where
815 disp
(UnknownExtension other
) = Disp
.text other
816 disp
(EnableExtension ke
) = Disp
.text
(show ke
)
817 disp
(DisableExtension ke
) = Disp
.text
("No" ++ show ke
)
820 extension
<- Parse
.munch1
isAlphaNum
821 return (classifyExtension extension
)
823 instance Text KnownExtension
where
824 disp ke
= Disp
.text
(show ke
)
827 extension
<- Parse
.munch1
isAlphaNum
828 case classifyKnownExtension extension
of
832 fail ("Can't parse " ++ show extension
++ " as KnownExtension")
834 classifyExtension
:: String -> Extension
835 classifyExtension
string
836 = case classifyKnownExtension
string of
837 Just ext
-> EnableExtension ext
841 case classifyKnownExtension
string' of
842 Just ext
-> DisableExtension ext
843 Nothing
-> UnknownExtension
string
844 _
-> UnknownExtension
string
846 -- | 'read' for 'KnownExtension's is really really slow so for the Text
848 -- what we do is make a simple table indexed off the first letter in the
849 -- extension name. The extension names actually cover the range @'A'-'Z'@
850 -- pretty densely and the biggest bucket is 7 so it's not too bad. We just do
851 -- a linear search within each bucket.
853 -- This gives an order of magnitude improvement in parsing speed, and it'll
854 -- also allow us to do case insensitive matches in future if we prefer.
856 classifyKnownExtension
:: String -> Maybe KnownExtension
857 classifyKnownExtension
"" = Nothing
858 classifyKnownExtension
string@(c
: _
)
859 |
inRange (bounds knownExtensionTable
) c
860 = lookup string (knownExtensionTable
! c
)
861 |
otherwise = Nothing
863 knownExtensionTable
:: Array Char [(String, KnownExtension
)]
864 knownExtensionTable
=
865 accumArray (flip (:)) [] ('A
', 'Z
')
866 [ (head str
, (str
, extension
))
867 | extension
<- [toEnum 0 ..]
868 , let str
= show extension
]