1{-# LANGUAGE DeriveDataTypeable #-}
2{-# LANGUAGE DeriveFoldable #-}
3{-# LANGUAGE DeriveTraversable #-}
4{-# LANGUAGE DeriveFunctor #-}
5{-# LANGUAGE DeriveGeneric #-}
6{-# LANGUAGE CPP #-}
7
8-----------------------------------------------------------------------------
9-- |
10-- Module      :  Language.Haskell.Exts.Syntax
11-- Copyright   :  (c) Niklas Broberg 2004-2009,
12--                (c) The GHC Team, 1997-2000
13-- License     :  BSD-style (see the file LICENSE.txt)
14--
15-- Maintainer  :  Niklas Broberg, d00nibro@chalmers.se
16-- Stability   :  stable
17-- Portability :  portable
18--
19-- A suite of datatypes describing the (semi-concrete) abstract syntax of Haskell 98
20-- <http://www.haskell.org/onlinereport/> plus registered extensions, including:
21--
22--   * multi-parameter type classes with functional dependencies (MultiParamTypeClasses, FunctionalDependencies)
23--
24--   * parameters of type class assertions are unrestricted (FlexibleContexts)
25--
26--   * 'forall' types as universal and existential quantification (RankNTypes, ExistentialQuantification, etc)
27--
28--   * pattern guards (PatternGuards)
29--
30--   * implicit parameters (ImplicitParameters)
31--
32--   * generalised algebraic data types (GADTs)
33--
34--   * template haskell (TemplateHaskell)
35--
36--   * empty data type declarations (EmptyDataDecls)
37--
38--   * unboxed tuples (UnboxedTuples)
39--
40--   * regular patterns (RegularPatterns)
41--
42--   * HSP-style XML expressions and patterns (XmlSyntax)
43--
44-- All nodes in the syntax tree are annotated with something of a user-definable data type.
45-- When parsing, this annotation will contain information about the source location that the
46-- particular node comes from.
47--
48-----------------------------------------------------------------------------
49
50module Language.Haskell.Exts.Syntax (
51    -- * Modules
52    Module(..), ModuleHead(..), WarningText(..), ExportSpecList(..), ExportSpec(..),
53    EWildcard(..),
54    ImportDecl(..), ImportSpecList(..), ImportSpec(..), Assoc(..), Namespace(..),
55    -- * Declarations
56    Decl(..), DeclHead(..), InstRule(..), InstHead(..), Binds(..), IPBind(..), PatternSynDirection(..),
57    InjectivityInfo(..), ResultSig(..),
58    -- ** Type classes and instances
59    ClassDecl(..), InstDecl(..), Deriving(..), DerivStrategy(..),
60    -- ** Data type declarations
61    DataOrNew(..), ConDecl(..), FieldDecl(..), QualConDecl(..), GadtDecl(..), BangType(..),
62    Unpackedness(..),
63    -- ** Function bindings
64    Match(..), Rhs(..), GuardedRhs(..),
65    -- * Class Assertions and Contexts
66    Context(..), FunDep(..), Asst(..),
67    -- * Types
68    Type(..), Boxed(..), Kind, TyVarBind(..), Promoted(..),
69    TypeEqn (..),
70    -- * Expressions
71    Exp(..), Stmt(..), QualStmt(..), FieldUpdate(..),
72    Alt(..), XAttr(..),
73    -- * Patterns
74    Pat(..), PatField(..), PXAttr(..), RPat(..), RPatOp(..),
75    -- * Literals
76    Literal(..), Sign(..),
77    -- * Variables, Constructors and Operators
78    ModuleName(..), QName(..), Name(..), QOp(..), Op(..),
79    SpecialCon(..), CName(..), IPName(..), XName(..), Role(..),
80    MaybePromotedName(..),
81
82    -- * Template Haskell
83    Bracket(..), Splice(..),
84
85    -- * FFI
86    Safety(..), CallConv(..),
87
88    -- * Pragmas
89    ModulePragma(..), Tool(..), Overlap(..),
90    Rule(..), RuleVar(..), Activation(..),
91    Annotation(..), BooleanFormula(..),
92
93    -- * Builtin names
94
95    -- ** Modules
96    prelude_mod, main_mod,
97    -- ** Main function of a program
98    main_name,
99    -- ** Constructors
100    unit_con_name, tuple_con_name, list_con_name, list_cons_name, unboxed_singleton_con_name,
101    unit_con, tuple_con, unboxed_singleton_con,
102    -- ** Special identifiers
103    as_name, qualified_name, hiding_name, minus_name, bang_name, dot_name, star_name,
104    export_name, safe_name, unsafe_name, interruptible_name, threadsafe_name,
105    stdcall_name, ccall_name, cplusplus_name, dotnet_name, jvm_name, js_name,
106    javascript_name, capi_name, forall_name, family_name, role_name, hole_name,
107    stock_name, anyclass_name, via_name,
108    -- ** Type constructors
109    unit_tycon_name, fun_tycon_name, list_tycon_name, tuple_tycon_name, unboxed_singleton_tycon_name,
110    unit_tycon, fun_tycon, list_tycon, tuple_tycon, unboxed_singleton_tycon,
111
112    -- * Source coordinates
113    -- SrcLoc(..),
114
115    -- * Annotated trees
116    Annotated(..), (=~=),
117  ) where
118
119import Prelude hiding (id)
120
121import Data.Data
122import GHC.Generics (Generic)
123#if __GLASGOW_HASKELL__ < 710
124import Data.Foldable (Foldable)
125import Data.Traversable (Traversable)
126#endif
127
128-- | The name of a Haskell module.
129data ModuleName l = ModuleName l String
130  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
131
132-- | Constructors with special syntax.
133-- These names are never qualified, and always refer to builtin type or
134-- data constructors.
135data SpecialCon l
136    = UnitCon l             -- ^ unit type and data constructor @()@
137    | ListCon l             -- ^ list type and data constructor @[]@
138    | FunCon  l             -- ^ function type constructor @->@
139    | TupleCon l Boxed Int  -- ^ /n/-ary tuple type and data
140                            --   constructors @(,)@ etc, possibly boxed @(\#,\#)@
141    | Cons l                -- ^ list data constructor @(:)@
142    | UnboxedSingleCon l    -- ^ unboxed singleton tuple constructor @(\# \#)@
143    | ExprHole l            -- ^ An expression hole _
144  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
145
146-- | This type is used to represent qualified variables, and also
147-- qualified constructors.
148data QName l
149    = Qual    l (ModuleName l) (Name l) -- ^ name qualified with a module name
150    | UnQual  l                (Name l) -- ^ unqualified local name
151    | Special l (SpecialCon l)          -- ^ built-in constructor with special syntax
152  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
153
154-- | This type is used to represent variables, and also constructors.
155data Name l
156    = Ident  l String   -- ^ /varid/ or /conid/.
157    | Symbol l String   -- ^ /varsym/ or /consym/
158  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
159
160-- | An implicit parameter name.
161data IPName l
162    = IPDup l String -- ^ ?/ident/, non-linear implicit parameter
163    | IPLin l String -- ^ %/ident/, linear implicit parameter
164  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
165
166-- | Possibly qualified infix operators (/qop/), appearing in expressions.
167data QOp l
168    = QVarOp l (QName l) -- ^ variable operator (/qvarop/)
169    | QConOp l (QName l) -- ^ constructor operator (/qconop/)
170  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
171
172-- | Operators appearing in @infix@ declarations are never qualified.
173data Op l
174    = VarOp l (Name l)    -- ^ variable operator (/varop/)
175    | ConOp l (Name l)    -- ^ constructor operator (/conop/)
176  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
177
178-- | A name (/cname/) of a component of a class or data type in an @import@
179-- or export specification.
180data CName l
181    = VarName l (Name l) -- ^ name of a method or field
182    | ConName l (Name l) -- ^ name of a data constructor
183  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
184
185-- | A complete Haskell source module.
186data Module l
187    = Module l (Maybe (ModuleHead l)) [ModulePragma l] [ImportDecl l] [Decl l]
188    -- ^ an ordinary Haskell module
189    | XmlPage l (ModuleName l) [ModulePragma l] (XName l) [XAttr l] (Maybe (Exp l)) [Exp l]
190    -- ^ a module consisting of a single XML document. The ModuleName never appears in the source
191    --   but is needed for semantic purposes, it will be the same as the file name.
192    | XmlHybrid l (Maybe (ModuleHead l)) [ModulePragma l] [ImportDecl l] [Decl l]
193                (XName l) [XAttr l] (Maybe (Exp l)) [Exp l]
194    -- ^ a hybrid module combining an XML document with an ordinary module
195  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
196
197-- | The head of a module, including the name and export specification.
198data ModuleHead l = ModuleHead l (ModuleName l) (Maybe (WarningText l)) (Maybe (ExportSpecList l))
199  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
200
201-- | An explicit export specification.
202data ExportSpecList l
203    = ExportSpecList l [ExportSpec l]
204  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
205
206-- | An item in a module's export specification.
207data ExportSpec l
208     = EVar l (QName l)                 -- ^ variable.
209     | EAbs l (Namespace l) (QName l)   -- ^ @T@:
210                                        --   a class or datatype exported abstractly,
211                                        --   or a type synonym.
212     | EThingWith l (EWildcard l) (QName l) [CName l] -- ^ @T(C_1,...,C_n)@:
213                                        --   a class exported with some of its methods, or
214                                        --   a datatype exported with some of its constructors.
215     | EModuleContents l (ModuleName l) -- ^ @module M@:
216                                        --   re-export a module.
217  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
218
219-- | Indicates the position of the wildcard in an export list
220data EWildcard l = NoWildcard l | EWildcard l Int
221  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
222
223-- | Namespaces for imports/exports.
224data Namespace l = NoNamespace l | TypeNamespace l | PatternNamespace l
225  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
226
227-- | An import declaration.
228data ImportDecl l = ImportDecl
229    { importAnn :: l                   -- ^ annotation, used by parser for position of the @import@ keyword.
230    , importModule :: ModuleName l     -- ^ name of the module imported.
231    , importQualified :: Bool          -- ^ imported @qualified@?
232    , importSrc :: Bool                -- ^ imported with @{-\# SOURCE \#-}@?
233    , importSafe :: Bool               -- ^ Import @safe@?
234    , importPkg :: Maybe String        -- ^ imported with explicit package name
235    , importAs :: Maybe (ModuleName l) -- ^ optional alias name in an @as@ clause.
236    , importSpecs :: Maybe (ImportSpecList l)
237            -- ^ optional list of import specifications.
238    }
239  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
240
241-- | An explicit import specification list.
242data ImportSpecList l
243    = ImportSpecList l Bool [ImportSpec l]
244            -- ^ A list of import specifications.
245            -- The 'Bool' is 'True' if the names are excluded
246            -- by @hiding@.
247  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
248
249-- | An import specification, representing a single explicit item imported
250--   (or hidden) from a module.
251data ImportSpec l
252     = IVar l (Name l)                  -- ^ variable
253     | IAbs l (Namespace l) (Name l)    -- ^ @T@:
254                                        --   the name of a class, datatype or type synonym.
255     | IThingAll l (Name l)             -- ^ @T(..)@:
256                                        --   a class imported with all of its methods, or
257                                        --   a datatype imported with all of its constructors.
258     | IThingWith l (Name l) [CName l]  -- ^ @T(C_1,...,C_n)@:
259                                        --   a class imported with some of its methods, or
260                                        --   a datatype imported with some of its constructors.
261  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
262
263-- | Associativity of an operator.
264data Assoc l
265     = AssocNone  l -- ^ non-associative operator (declared with @infix@)
266     | AssocLeft  l -- ^ left-associative operator (declared with @infixl@).
267     | AssocRight l -- ^ right-associative operator (declared with @infixr@)
268  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
269
270-- | A top-level declaration.
271data Decl l
272     = TypeDecl     l (DeclHead l) (Type l)
273     -- ^ A type declaration
274     | TypeFamDecl  l (DeclHead l) (Maybe (ResultSig l)) (Maybe (InjectivityInfo l))
275     -- ^ A type family declaration
276     | ClosedTypeFamDecl  l (DeclHead l) (Maybe (ResultSig l)) (Maybe (InjectivityInfo l)) [TypeEqn l]
277     -- ^ A closed type family declaration
278     | DataDecl     l (DataOrNew l) (Maybe (Context l)) (DeclHead l)                  [QualConDecl l] [Deriving l]
279     -- ^ A data OR newtype declaration
280     | GDataDecl    l (DataOrNew l) (Maybe (Context l)) (DeclHead l) (Maybe (Kind l)) [GadtDecl l]    [Deriving l]
281     -- ^ A data OR newtype declaration, GADT style
282     | DataFamDecl  l {-data-}      (Maybe (Context l)) (DeclHead l) (Maybe (ResultSig l))
283     -- ^ A data family declaration
284     | TypeInsDecl  l (Type l) (Type l)
285     -- ^ A type family instance declaration
286     | DataInsDecl  l (DataOrNew l) (Type l)                  [QualConDecl l] [Deriving l]
287     -- ^ A data family instance declaration
288     | GDataInsDecl l (DataOrNew l) (Type l) (Maybe (Kind l)) [GadtDecl l]    [Deriving l]
289     -- ^ A data family instance declaration, GADT style
290     | ClassDecl    l (Maybe (Context l)) (DeclHead l) [FunDep l] (Maybe [ClassDecl l])
291     -- ^ A declaration of a type class
292     | InstDecl     l (Maybe (Overlap l)) (InstRule l) (Maybe [InstDecl l])
293     -- ^ An declaration of a type class instance
294     | DerivDecl    l (Maybe (DerivStrategy l)) (Maybe (Overlap l)) (InstRule l)
295     -- ^ A standalone deriving declaration
296     | InfixDecl    l (Assoc l) (Maybe Int) [Op l]
297     -- ^ A declaration of operator fixity
298     | DefaultDecl  l [Type l]
299     -- ^ A declaration of default types
300     | SpliceDecl   l (Exp l)
301     -- ^ A Template Haskell splicing declaration
302     | TSpliceDecl  l (Exp l)
303     -- ^ A typed Template Haskell splicing declaration
304     | TypeSig      l [Name l] (Type l)
305     -- ^ A type signature declaration
306     | PatSynSig    l [Name l] (Maybe [TyVarBind l]) (Maybe (Context l))
307                               (Maybe [TyVarBind l]) (Maybe (Context l))
308                                                     (Type l)
309     -- ^ A pattern synonym signature declation
310     | FunBind      l [Match l]
311     -- ^ A set of function binding clauses
312     | PatBind      l (Pat l) (Rhs l) {-where-} (Maybe (Binds l))
313     -- ^ A pattern binding
314     | PatSyn l (Pat l) (Pat l) (PatternSynDirection l)
315     -- ^ A pattern synonym binding
316     | ForImp       l (CallConv l) (Maybe (Safety l)) (Maybe String) (Name l) (Type l)
317     -- ^ A foreign import declaration
318     | ForExp       l (CallConv l)                    (Maybe String) (Name l) (Type l)
319     -- ^ A foreign export declaration
320     | RulePragmaDecl   l [Rule l]
321     -- ^ A RULES pragma
322     | DeprPragmaDecl   l [([Name l], String)]
323     -- ^ A DEPRECATED pragma
324     | WarnPragmaDecl   l [([Name l], String)]
325     -- ^ A WARNING pragma
326     | InlineSig        l Bool (Maybe (Activation l)) (QName l)
327     -- ^ An INLINE pragma
328     | InlineConlikeSig l      (Maybe (Activation l)) (QName l)
329     -- ^ An INLINE CONLIKE pragma
330     | SpecSig          l      (Maybe (Activation l)) (QName l) [Type l]
331     -- ^ A SPECIALISE pragma
332     | SpecInlineSig    l Bool (Maybe (Activation l)) (QName l) [Type l]
333     -- ^ A SPECIALISE INLINE pragma
334     | InstSig          l      (InstRule l)
335     -- ^ A SPECIALISE instance pragma
336     | AnnPragma        l (Annotation l)
337     -- ^ An ANN pragma
338     | MinimalPragma    l (Maybe (BooleanFormula l))
339     -- ^ A MINIMAL pragma
340     | RoleAnnotDecl    l (QName l) [Role l]
341     -- ^ A role annotation
342     | CompletePragma l [Name l] (Maybe (QName l))
343     -- ^ A COMPLETE pragma
344  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
345
346data  PatternSynDirection l =
347      Unidirectional -- ^ A unidirectional pattern synonym with "<-"
348    | ImplicitBidirectional  -- ^ A bidirectional pattern synonym with "="
349    | ExplicitBidirectional l [Decl l]  -- ^ A birectional pattern synonym with the construction specified.
350    deriving (Eq, Ord, Show, Data, Typeable, Foldable, Traversable, Functor, Generic)
351
352-- | A type equation as found in closed type families.
353data TypeEqn l = TypeEqn l (Type l) (Type l) deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
354
355-- | An annotation through an ANN pragma.
356data Annotation l
357    = Ann       l (Name l)  (Exp l)
358    -- ^ An annotation for a declared name.
359    | TypeAnn   l (Name l)  (Exp l)
360    -- ^ An annotation for a declared type.
361    | ModuleAnn l           (Exp l)
362    -- ^ An annotation for the defining module.
363  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
364
365-- | A boolean formula for MINIMAL pragmas.
366data BooleanFormula l
367    = VarFormula l (Name l)              -- ^ A variable.
368    | AndFormula l [BooleanFormula l]    -- ^ And boolean formulas.
369    | OrFormula l [BooleanFormula l]     -- ^ Or boolean formulas.
370    | ParenFormula l (BooleanFormula l)  -- ^ Parenthesized boolean formulas.
371  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
372
373data Role l
374  = Nominal l
375  | Representational l
376  | Phantom l
377  | RoleWildcard l
378  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
379
380-- | A flag stating whether a declaration is a data or newtype declaration.
381data DataOrNew l = DataType l | NewType l
382  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
383
384
385-- | Injectivity info for injective type families
386data InjectivityInfo l = InjectivityInfo l (Name l) [Name l]
387  deriving (Eq, Ord, Show, Typeable, Data, Foldable, Traversable, Functor, Generic)
388
389data ResultSig l = KindSig l (Kind l) | TyVarSig l (TyVarBind l)
390  deriving (Eq, Ord, Show, Typeable, Data, Foldable, Traversable, Functor, Generic)
391
392-- | The head of a type or class declaration, which consists of the type
393-- or class name applied to some type variables
394--
395-- @class C a b@ is represented as
396--
397-- >DHApp
398-- >   ()
399-- >   (DHApp
400-- >      () (DHead () (Ident () "C")) (UnkindedVar () (Ident () "a")))
401-- >   (UnkindedVar () (Ident () "b"))
402--
403-- (where the annotation type @l@ is instantiated with @()@)
404--
405-- @class (a :< b) c@ is represented as
406--
407-- >DHApp
408-- >   ()
409-- >   (DHParen
410-- >      ()
411-- >      (DHApp
412-- >         ()
413-- >         (DHInfix () (UnkindedVar () (Ident () "a")) (Symbol () ":<"))
414-- >         (UnkindedVar () (Ident () "b"))))
415-- >   (UnkindedVar () (Ident () "c"))
416data DeclHead l
417    = DHead l (Name l) -- ^ type or class name
418    | DHInfix l (TyVarBind l) (Name l) -- ^ infix application of the type/class name to the left operand
419    | DHParen l (DeclHead l) -- ^ parenthesized declaration head
420    | DHApp   l (DeclHead l) (TyVarBind l) -- ^ application to one more type variable
421  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
422
423-- | The instance declaration rule, which is, roughly, the part of the instance declaration before the @where@ keyword.
424--
425-- Example: @instance Ord a => Ord (Maybe a)@ is represented as
426--
427-- >IRule
428-- >   ()
429-- >   Nothing
430-- >   (Just
431-- >      (CxSingle
432-- >         ()
433-- >         (ClassA
434-- >            () (UnQual () (Ident () "Ord")) [ TyVar () (Ident () "a") ])))
435-- >   (IHApp
436-- >      ()
437-- >      (IHCon () (UnQual () (Ident () "Ord")))
438-- >      (TyParen
439-- >         ()
440-- >         (TyApp
441-- >            ()
442-- >            (TyCon () (UnQual () (Ident () "Maybe")))
443-- >            (TyVar () (Ident () "a")))))
444--
445-- An optional explicit forall after @instance@ is supported:
446-- @instance forall a . Ord a => Ord (Maybe a) where@ becomes
447--
448-- >IRule
449-- >   ()
450-- >   (Just [ UnkindedVar () (Ident () "a") ])
451-- >   ...
452data InstRule l
453    = IRule l (Maybe [TyVarBind l]) (Maybe (Context l)) (InstHead l)
454    | IParen l (InstRule l)
455  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
456
457-- See bugs #7 and #31 for more details and use cases for the rationale
458-- of the split. DeclOrInstHead should be used by DeclHead as the name implies.
459
460-- | The instance head. The split between rule/head allow us to represent
461-- @instance (Bounded a => Bounded [a]) where@ faithfully.
462--
463-- The structure of 'InstHead' follows one of 'DeclHead'.
464--
465-- For example, @instance C (Maybe a) Int where@ is represented as
466--
467-- >IHApp
468-- >   ()
469-- >   (IHApp
470-- >      ()
471-- >      (IHCon () (UnQual () (Ident () "C")))
472-- >      (TyParen
473-- >         ()
474-- >         (TyApp
475-- >            ()
476-- >            (TyCon () (UnQual () (Ident () "Maybe")))
477-- >            (TyVar () (Ident () "a")))))
478-- >   (TyCon () (UnQual () (Ident () "Int")))))
479data InstHead l
480    = IHCon l (QName l) -- ^ type or class name
481    | IHInfix l (Type l) (QName l) -- ^ infix application of the type/class name to the left operand
482    | IHParen l (InstHead l) -- ^ parenthesized instance head
483    | IHApp   l (InstHead l) (Type l) -- ^ application to one more type
484  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
485
486-- | A deriving clause following a data type declaration.
487data Deriving l = Deriving l (Maybe (DerivStrategy l)) [InstRule l]
488  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
489
490-- | Which technique the user explicitly requested when deriving an instance.
491data DerivStrategy l
492  = DerivStock l        -- ^ GHC's \"standard\" strategy, which is to implement a
493                        --   custom instance for the data type. This only works for
494                        --   certain types that GHC knows about (e.g., 'Eq', 'Show',
495                        --   'Functor' when @-XDeriveFunctor@ is enabled, etc.)
496  | DerivAnyclass l     -- ^ @-XDeriveAnyClass@
497  | DerivNewtype l      -- ^ @-XGeneralizedNewtypeDeriving@
498  | DerivVia l (Type l) -- ^ @-XDerivingVia@
499  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
500
501-- | A binding group inside a @let@ or @where@ clause.
502data Binds l
503    = BDecls  l [Decl l]     -- ^ An ordinary binding group
504    | IPBinds l [IPBind l]   -- ^ A binding group for implicit parameters
505  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
506
507-- | A binding of an implicit parameter.
508data IPBind l = IPBind l (IPName l) (Exp l)
509  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
510
511-- | Clauses of a function binding.
512data Match l
513     = Match l      (Name l) [Pat l]         (Rhs l) {-where-} (Maybe (Binds l))
514        -- ^ A clause defined with prefix notation, i.e. the function name
515        --  followed by its argument patterns, the right-hand side and an
516        --  optional where clause.
517     | InfixMatch l (Pat l) (Name l) [Pat l] (Rhs l) {-where-} (Maybe (Binds l))
518        -- ^ A clause defined with infix notation, i.e. first its first argument
519        --  pattern, then the function name, then its following argument(s),
520        --  the right-hand side and an optional where clause.
521        --  Note that there can be more than two arguments to a function declared
522        --  infix, hence the list of pattern arguments.
523  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
524
525-- | A single constructor declaration within a data type declaration,
526--   which may have an existential quantification binding.
527data QualConDecl l
528    = QualConDecl l
529        {-forall-} (Maybe [TyVarBind l]) {- . -} (Maybe (Context l))
530        {- => -} (ConDecl l)
531  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
532
533-- | Declaration of an ordinary data constructor.
534data ConDecl l
535     = ConDecl l (Name l) [Type l]
536                -- ^ ordinary data constructor
537     | InfixConDecl l (Type l) (Name l) (Type l)
538                -- ^ infix data constructor
539     | RecDecl l (Name l) [FieldDecl l]
540                -- ^ record constructor
541  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
542
543-- | Declaration of a (list of) named field(s).
544data FieldDecl l = FieldDecl l [Name l] (Type l)
545  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
546
547
548-- | A single constructor declaration in a GADT data type declaration.
549--
550-- If the GADT is declared using the record syntax, e.g.
551--
552-- >data Ty where
553-- >  TCon :: { field1 :: Int, field2 :: Bool } -> Ty
554--
555-- then the fields are stored as a list of 'FieldDecl's, and the final type
556-- (@Ty@ in the above example) is stored in the last 'Type' field.
557--
558-- If the GADT is declared using the ordinary syntax, e.g.
559--
560-- >data Ty where
561-- >  TCon :: Int -> Bool -> Ty
562--
563-- then @'Maybe' ['FieldDecl' l]@ is 'Nothing', and the whole constructor's
564-- type (such as @Int -> Bool -> Ty@) is stored in the last 'Type' field.
565data GadtDecl l
566    = GadtDecl l (Name l)
567        {-forall-} (Maybe [TyVarBind l]) {- . -} (Maybe (Context l))
568        {- => -} (Maybe [FieldDecl l]) (Type l)
569  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
570
571-- | Declarations inside a class declaration.
572data ClassDecl l
573    = ClsDecl    l (Decl l)
574            -- ^ ordinary declaration
575    | ClsDataFam l (Maybe (Context l)) (DeclHead l) (Maybe (ResultSig l))
576            -- ^ declaration of an associated data type
577    | ClsTyFam   l                     (DeclHead l) (Maybe (ResultSig l)) (Maybe (InjectivityInfo l))
578            -- ^ declaration of an associated type synonym
579    | ClsTyDef   l (TypeEqn l)
580            -- ^ default choice for an associated type synonym
581    | ClsDefSig  l (Name l) (Type l)
582            -- ^ default signature
583  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
584
585-- | Declarations inside an instance declaration.
586data InstDecl l
587    = InsDecl   l (Decl l)
588            -- ^ ordinary declaration
589    | InsType   l (Type l) (Type l)
590            -- ^ an associated type definition
591    | InsData   l (DataOrNew l) (Type l) [QualConDecl l] [Deriving l]
592            -- ^ an associated data type implementation
593    | InsGData  l (DataOrNew l) (Type l) (Maybe (Kind l)) [GadtDecl l] [Deriving l]
594            -- ^ an associated data type implemented using GADT style
595  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
596
597-- | The type of a constructor argument or field, optionally including
598--   a strictness annotation.
599data BangType l
600     = BangedTy   l -- ^ strict component, marked with \"@!@\"
601     | LazyTy     l -- ^ lazy component, marked with \"@~@\"
602     | NoStrictAnnot l -- ^ No strictness information
603  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
604
605data Unpackedness l
606    = Unpack l -- ^ \"@{-\# UNPACK \#-}@\"
607    | NoUnpack l -- ^ \"@{-\# NOUNPACK \#-}@\"
608    | NoUnpackPragma l -- ^ No unpack pragma
609  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
610
611-- | The right hand side of a function binding, pattern binding, or a case
612--   alternative.
613data Rhs l
614     = UnGuardedRhs l (Exp l) -- ^ unguarded right hand side (/exp/)
615     | GuardedRhss  l [GuardedRhs l]
616                -- ^ guarded right hand side (/gdrhs/)
617  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
618
619-- | A guarded right hand side @|@ /stmts/ @=@ /exp/, or @|@ /stmts/ @->@ /exp/
620--   for case alternatives.
621--   The guard is a series of statements when using pattern guards,
622--   otherwise it will be a single qualifier expression.
623data GuardedRhs l
624     = GuardedRhs l [Stmt l] (Exp l)
625  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
626
627-- | A type qualified with a context.
628--   An unqualified type has an empty context.
629data Type l
630     = TyForall l
631        (Maybe [TyVarBind l])
632        (Maybe (Context l))
633        (Type l)                                -- ^ qualified type
634     | TyStar  l                                -- ^ @*@, the type of types
635     | TyFun   l (Type l) (Type l)              -- ^ function type
636     | TyTuple l Boxed [Type l]                 -- ^ tuple type, possibly boxed
637     | TyUnboxedSum l [Type l]                  -- ^ unboxed tuple type
638     | TyList  l (Type l)                       -- ^ list syntax, e.g. [a], as opposed to [] a
639     | TyParArray  l (Type l)                   -- ^ parallel array syntax, e.g. [:a:]
640     | TyApp   l (Type l) (Type l)              -- ^ application of a type constructor
641     | TyVar   l (Name l)                       -- ^ type variable
642     | TyCon   l (QName l)                      -- ^ named type or type constructor
643     | TyParen l (Type l)                       -- ^ type surrounded by parentheses
644     | TyInfix l (Type l) (MaybePromotedName l)
645                          (Type l)              -- ^ infix type constructor
646     | TyKind  l (Type l) (Kind l)              -- ^ type with explicit kind signature
647     | TyPromoted l (Promoted l)                -- ^ @'K@, a promoted data type (-XDataKinds).
648     | TyEquals l (Type l) (Type l)             -- ^ type equality predicate enabled by ConstraintKinds
649     | TySplice l (Splice l)                    -- ^ template haskell splice type
650     | TyBang l (BangType l) (Unpackedness l) (Type l)           -- ^ Strict type marked with \"@!@\" or type marked with UNPACK pragma.
651     | TyWildCard l (Maybe (Name l))            -- ^ Either an anonymous of named type wildcard
652     | TyQuasiQuote l String String             -- ^ @[$/name/| /string/ |]@
653  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
654
655data MaybePromotedName l = PromotedName l (QName l) | UnpromotedName l (QName l)
656  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
657
658-- | Bools here are True if there was a leading quote which may be
659-- left out. For example @'[k1,k2]@ means the same thing as @[k1,k2]@.
660data Promoted l
661        = PromotedInteger l Integer String -- ^ parsed value and raw string
662        | PromotedString l String String -- ^ parsed value and raw string
663        | PromotedCon l Bool (QName l)
664        | PromotedList l Bool [Type l]
665        | PromotedTuple l [Type l]
666        | PromotedUnit l
667  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
668
669-- | Flag denoting whether a tuple is boxed or unboxed.
670data Boxed = Boxed | Unboxed
671  deriving (Eq,Ord,Show,Typeable,Data,Generic)
672
673-- | A type variable declaration, optionally with an explicit kind annotation.
674data TyVarBind l
675    = KindedVar   l (Name l) (Kind l)  -- ^ variable binding with kind annotation
676    | UnkindedVar l (Name l)           -- ^ ordinary variable binding
677  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
678
679-- | An explicit kind annotation.
680type Kind = Type
681
682
683-- | A functional dependency, given on the form
684--   l1 l2 ... ln -> r2 r3 .. rn
685data FunDep l
686    = FunDep l [Name l] [Name l]
687  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
688
689-- | A context is a set of assertions
690data Context l
691    = CxSingle l (Asst l)
692    | CxTuple  l [Asst l]
693    | CxEmpty  l
694  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
695
696-- | Class assertions.
697data Asst l
698        = TypeA l (Type l)                      -- ^ type assertion
699        | IParam l (IPName l) (Type l)          -- ^ implicit parameter assertion
700        | ParenA l (Asst l)                     -- ^ parenthesised class assertion
701  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
702
703-- | /literal/
704-- Values of this type hold the abstract value of the literal, along with the
705-- precise string representation used.  For example, @10@, @0o12@ and @0xa@
706-- have the same value representation, but each carry a different string representation.
707data Literal l
708    = Char       l Char     String     -- ^ character literal
709    | String     l String   String     -- ^ string literal
710    | Int        l Integer  String     -- ^ integer literal
711    | Frac       l Rational String     -- ^ floating point literal
712    | PrimInt    l Integer  String     -- ^ unboxed integer literal
713    | PrimWord   l Integer  String     -- ^ unboxed word literal
714    | PrimFloat  l Rational String     -- ^ unboxed float literal
715    | PrimDouble l Rational String     -- ^ unboxed double literal
716    | PrimChar   l Char     String     -- ^ unboxed character literal
717    | PrimString l String   String     -- ^ unboxed string literal
718  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
719
720-- | An indication whether a literal pattern has been negated or not.
721data Sign l
722    = Signless l
723    | Negative l
724  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
725
726-- | Haskell expressions.
727data Exp l
728    = Var l (QName l)                       -- ^ variable
729    | OverloadedLabel l String              -- ^ Overloaded label #foo
730    | IPVar l (IPName l)                    -- ^ implicit parameter variable
731    | Con l (QName l)                       -- ^ data constructor
732    | Lit l (Literal l)                     -- ^ literal constant
733    | InfixApp l (Exp l) (QOp l) (Exp l)    -- ^ infix application
734    | App l (Exp l) (Exp l)                 -- ^ ordinary application
735    | NegApp l (Exp l)                      -- ^ negation expression @-/exp/@ (unary minus)
736    | Lambda l [Pat l] (Exp l)              -- ^ lambda expression
737    | Let l (Binds l) (Exp l)               -- ^ local declarations with @let@ ... @in@ ...
738    | If l (Exp l) (Exp l) (Exp l)          -- ^ @if@ /exp/ @then@ /exp/ @else@ /exp/
739    | MultiIf l [GuardedRhs l]              -- ^ @if@ @|@ /stmts/ @->@ /exp/ ...
740    | Case l (Exp l) [Alt l]                -- ^ @case@ /exp/ @of@ /alts/
741    | Do l [Stmt l]                         -- ^ @do@-expression:
742                                            --   the last statement in the list
743                                            --   should be an expression.
744    | MDo l [Stmt l]                        -- ^ @mdo@-expression
745    | Tuple l Boxed [Exp l]                 -- ^ tuple expression
746    | UnboxedSum l Int Int (Exp l)          -- ^ unboxed sum
747    | TupleSection l Boxed [Maybe (Exp l)]  -- ^ tuple section expression, e.g. @(,,3)@
748    | List l [Exp l]                        -- ^ list expression
749    | ParArray l [Exp l]                    -- ^ parallel array expression
750    | Paren l (Exp l)                       -- ^ parenthesised expression
751    | LeftSection l (Exp l) (QOp l)         -- ^ left section @(@/exp/ /qop/@)@
752    | RightSection l (QOp l) (Exp l)        -- ^ right section @(@/qop/ /exp/@)@
753    | RecConstr l (QName l) [FieldUpdate l] -- ^ record construction expression
754    | RecUpdate l (Exp l)   [FieldUpdate l] -- ^ record update expression
755    | EnumFrom l (Exp l)                    -- ^ unbounded arithmetic sequence,
756                                            --   incrementing by 1: @[from ..]@
757    | EnumFromTo l (Exp l) (Exp l)          -- ^ bounded arithmetic sequence,
758                                            --   incrementing by 1 @[from .. to]@
759    | EnumFromThen l (Exp l) (Exp l)        -- ^ unbounded arithmetic sequence,
760                                            --   with first two elements given @[from, then ..]@
761    | EnumFromThenTo l (Exp l) (Exp l) (Exp l)
762                                            -- ^ bounded arithmetic sequence,
763                                            --   with first two elements given @[from, then .. to]@
764    | ParArrayFromTo l (Exp l) (Exp l)      -- ^ Parallel array bounded arithmetic sequence,
765                                            --   incrementing by 1 @[:from .. to:]@
766    | ParArrayFromThenTo l (Exp l) (Exp l) (Exp l)
767                                            -- ^ bounded arithmetic sequence,
768                                            --   with first two elements given @[:from, then .. to:]@
769    | ListComp l (Exp l) [QualStmt l]       -- ^ ordinary list comprehension
770    | ParComp  l (Exp l) [[QualStmt l]]     -- ^ parallel list comprehension
771    | ParArrayComp  l (Exp l) [[QualStmt l]] -- ^ parallel array comprehension
772    | ExpTypeSig l (Exp l) (Type l)         -- ^ expression with explicit type signature
773
774    | VarQuote l (QName l)                  -- ^ @'x@ for template haskell reifying of expressions
775    | TypQuote l (QName l)                  -- ^ @''T@ for template haskell reifying of types
776    | BracketExp l (Bracket l)              -- ^ template haskell bracket expression
777    | SpliceExp l (Splice l)                -- ^ template haskell splice expression
778    | QuasiQuote l String String            -- ^ quasi-quotaion: @[$/name/| /string/ |]@
779    | TypeApp l (Type l)                    -- ^ Visible type application
780
781-- Hsx
782    | XTag l (XName l) [XAttr l] (Maybe (Exp l)) [Exp l]
783                                            -- ^ xml element, with attributes and children
784    | XETag l (XName l) [XAttr l] (Maybe (Exp l))
785                                            -- ^ empty xml element, with attributes
786    | XPcdata l String                      -- ^ PCDATA child element
787    | XExpTag l (Exp l)                     -- ^ escaped haskell expression inside xml
788    | XChildTag l [Exp l]                   -- ^ children of an xml element
789
790
791-- Pragmas
792    | CorePragma l      String (Exp l)      -- ^ CORE pragma
793    | SCCPragma  l      String (Exp l)      -- ^ SCC pragma
794    | GenPragma  l      String (Int, Int) (Int, Int) (Exp l)
795                                            -- ^ GENERATED pragma
796
797-- Arrows
798    | Proc            l (Pat l) (Exp l)     -- ^ arrows proc: @proc@ /pat/ @->@ /exp/
799    | LeftArrApp      l (Exp l) (Exp l)     -- ^ arrow application (from left): /exp/ @-<@ /exp/
800    | RightArrApp     l (Exp l) (Exp l)     -- ^ arrow application (from right): /exp/ @>-@ /exp/
801    | LeftArrHighApp  l (Exp l) (Exp l)     -- ^ higher-order arrow application (from left): /exp/ @-<<@ /exp/
802    | RightArrHighApp l (Exp l) (Exp l)     -- ^ higher-order arrow application (from right): /exp/ @>>-@ /exp/
803    | ArrOp           l (Exp l)             -- ^ arrow control operators: @(| /exp/ |)@
804
805-- LambdaCase
806    | LCase l [Alt l]                       -- ^ @\case@ /alts/
807
808  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
809
810-- | The name of an xml element or attribute,
811--   possibly qualified with a namespace.
812data XName l
813    = XName l String              -- <name ...
814    | XDomName l String String    -- <dom:name ...
815  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
816
817-- | An xml attribute, which is a name-expression pair.
818data XAttr l = XAttr l (XName l) (Exp l)
819  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
820
821-- | A template haskell bracket expression.
822data Bracket l
823    = ExpBracket l (Exp l)        -- ^ expression bracket: @[| ... |]@
824    | TExpBracket l (Exp l)       -- ^ typed expression bracket: @[|| ... ||]@
825    | PatBracket l (Pat l)        -- ^ pattern bracket: @[p| ... |]@
826    | TypeBracket l (Type l)      -- ^ type bracket: @[t| ... |]@
827    | DeclBracket l [Decl l]      -- ^ declaration bracket: @[d| ... |]@
828  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
829
830-- | A template haskell splice expression
831data Splice l
832    = IdSplice l String           -- ^ variable splice: @$var@
833    | TIdSplice l String          -- ^ typed variable splice: @$$var@
834    | ParenSplice l (Exp l)       -- ^ parenthesised expression splice: @$(/exp/)@
835    | TParenSplice l (Exp l)      -- ^ parenthesised typed expression splice: @$$(/exp/)@
836  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
837
838-- | The safety of a foreign function call.
839data Safety l
840    = PlayRisky l         -- ^ unsafe
841    | PlaySafe l Bool     -- ^ safe ('False') or threadsafe ('True')
842    | PlayInterruptible l -- ^ interruptible
843  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
844
845-- | The calling convention of a foreign function call.
846data CallConv l
847    = StdCall l
848    | CCall l
849    | CPlusPlus l
850    | DotNet l
851    | Jvm l
852    | Js l
853    | JavaScript l
854    | CApi l
855  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
856
857-- | A top level options pragma, preceding the module header.
858data ModulePragma l
859    = LanguagePragma   l [Name l]  -- ^ LANGUAGE pragma
860    | OptionsPragma    l (Maybe Tool) String
861                        -- ^ OPTIONS pragma, possibly qualified with a tool, e.g. OPTIONS_GHC
862    | AnnModulePragma  l (Annotation l)
863                        -- ^ ANN pragma with module scope
864  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
865
866-- | Recognised tools for OPTIONS pragmas.
867data Tool = GHC | HUGS | NHC98 | YHC | HADDOCK | UnknownTool String
868  deriving (Eq,Ord,Show,Typeable,Data,Generic)
869
870-- | Recognised overlaps for overlap pragmas.
871data Overlap l
872    = NoOverlap l   -- ^ NO_OVERLAP pragma
873    | Overlap l     -- ^ OVERLAP pragma
874    | Overlapping l
875    | Overlaps l
876    | Overlappable l
877    | Incoherent l  -- ^ INCOHERENT pragma
878  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
879
880-- | Activation clause of a RULES pragma.
881data Activation l
882    = ActiveFrom   l Int
883    | ActiveUntil  l Int
884  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
885
886-- | The body of a RULES pragma.
887data Rule l
888    = Rule l String (Maybe (Activation l)) (Maybe [RuleVar l]) (Exp l) (Exp l)
889  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
890
891-- | Variables used in a RULES pragma, optionally annotated with types
892data RuleVar l
893    = RuleVar l (Name l)
894    | TypedRuleVar l (Name l) (Type l)
895  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
896
897-- | Warning text to optionally use in the module header of e.g.
898--   a deprecated module.
899data WarningText l
900    = DeprText l String
901    | WarnText l String
902  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
903
904
905-- | A pattern, to be matched against a value.
906data Pat l
907    = PVar l (Name l)                       -- ^ variable
908    | PLit l (Sign l) (Literal l)           -- ^ literal constant
909    | PNPlusK l (Name l) Integer            -- ^ n+k pattern
910    | PInfixApp l (Pat l) (QName l) (Pat l) -- ^ pattern with an infix data constructor
911    | PApp l (QName l) [Pat l]              -- ^ data constructor and argument patterns
912    | PTuple l Boxed [Pat l]                -- ^ tuple pattern
913    | PUnboxedSum l Int Int (Pat l)         -- ^ unboxed sum
914    | PList l [Pat l]                       -- ^ list pattern
915    | PParen l (Pat l)                      -- ^ parenthesized pattern
916    | PRec l (QName l) [PatField l]         -- ^ labelled pattern, record style
917    | PAsPat l (Name l) (Pat l)             -- ^ @\@@-pattern
918    | PWildCard l                           -- ^ wildcard pattern: @_@
919    | PIrrPat l (Pat l)                     -- ^ irrefutable pattern: @~/pat/@
920    | PatTypeSig l (Pat l) (Type l)         -- ^ pattern with type signature
921    | PViewPat l (Exp l) (Pat l)            -- ^ view patterns of the form @(/exp/ -> /pat/)@
922    | PRPat l [RPat l]                      -- ^ regular list pattern
923    | PXTag l (XName l) [PXAttr l] (Maybe (Pat l)) [Pat l]
924                                            -- ^ XML element pattern
925    | PXETag l (XName l) [PXAttr l] (Maybe (Pat l))
926                                            -- ^ XML singleton element pattern
927    | PXPcdata l String                     -- ^ XML PCDATA pattern
928    | PXPatTag l (Pat l)                    -- ^ XML embedded pattern
929    | PXRPats  l [RPat l]                   -- ^ XML regular list pattern
930    | PSplice l (Splice l)                  -- ^ template haskell splice pattern
931    | PQuasiQuote l String String           -- ^ quasi quote pattern: @[$/name/| /string/ |]@
932    | PBangPat l (Pat l)                    -- ^ strict (bang) pattern: @f !x = ...@
933  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
934
935-- | An XML attribute in a pattern.
936data PXAttr l = PXAttr l (XName l) (Pat l)
937  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
938
939-- | A regular pattern operator.
940data RPatOp l
941    = RPStar  l  -- ^ @*@ = 0 or more
942    | RPStarG l  -- ^ @*!@ = 0 or more, greedy
943    | RPPlus  l  -- ^ @+@ = 1 or more
944    | RPPlusG l  -- ^ @+!@ = 1 or more, greedy
945    | RPOpt   l  -- ^ @?@ = 0 or 1
946    | RPOptG  l  -- ^ @?!@ = 0 or 1, greedy
947  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
948
949-- | An entity in a regular pattern.
950data RPat l
951    = RPOp l (RPat l) (RPatOp l)   -- ^ operator pattern, e.g. pat*
952    | RPEither l (RPat l) (RPat l) -- ^ choice pattern, e.g. (1 | 2)
953    | RPSeq l [RPat l]             -- ^ sequence pattern, e.g. (| 1, 2, 3 |)
954    | RPGuard l (Pat l) [Stmt l]   -- ^ guarded pattern, e.g. (| p | p < 3 |)
955    | RPCAs l (Name l) (RPat l)    -- ^ non-linear variable binding, e.g. (foo\@:(1 | 2))*
956    | RPAs l (Name l) (RPat l)     -- ^ linear variable binding, e.g. foo\@(1 | 2)
957    | RPParen l (RPat l)           -- ^ parenthesised pattern, e.g. (2*)
958    | RPPat l (Pat l)              -- ^ an ordinary pattern
959  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
960
961-- | An /fpat/ in a labeled record pattern.
962data PatField l
963    = PFieldPat l (QName l) (Pat l)     -- ^ ordinary label-pattern pair
964    | PFieldPun l (QName l)             -- ^ record field pun
965    | PFieldWildcard l                  -- ^ record field wildcard
966  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
967
968-- | A statement, representing both a /stmt/ in a @do@-expression,
969--   an ordinary /qual/ in a list comprehension, as well as a /stmt/
970--   in a pattern guard.
971data Stmt l
972    = Generator l (Pat l) (Exp l)
973                            -- ^ a generator: /pat/ @<-@ /exp/
974    | Qualifier l (Exp l)   -- ^ an /exp/ by itself: in a @do@-expression,
975                            --   an action whose result is discarded;
976                            --   in a list comprehension and pattern guard,
977                            --   a guard expression
978    | LetStmt l (Binds l)   -- ^ local bindings
979    | RecStmt l [Stmt l]    -- ^ a recursive binding group for arrows
980  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
981
982-- | A general /transqual/ in a list comprehension,
983--   which could potentially be a transform of the kind
984--   enabled by TransformListComp.
985data QualStmt l
986    = QualStmt     l (Stmt l)         -- ^ an ordinary statement
987    | ThenTrans    l (Exp l)          -- ^ @then@ /exp/
988    | ThenBy       l (Exp l) (Exp l)  -- ^ @then@ /exp/ @by@ /exp/
989    | GroupBy      l (Exp l)          -- ^ @then@ @group@ @by@ /exp/
990    | GroupUsing   l (Exp l)          -- ^ @then@ @group@ @using@ /exp/
991    | GroupByUsing l (Exp l) (Exp l)  -- ^ @then@ @group@ @by@ /exp/ @using@ /exp/
992  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
993
994-- | An /fbind/ in a labeled construction or update expression.
995data FieldUpdate l
996    = FieldUpdate l (QName l) (Exp l)    -- ^ ordinary label-expresion pair
997    | FieldPun l (QName l)               -- ^ record field pun
998    | FieldWildcard l                    -- ^ record field wildcard
999  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
1000
1001-- | An /alt/ alternative in a @case@ expression.
1002data Alt l
1003    = Alt l (Pat l) (Rhs l) (Maybe (Binds l))
1004  deriving (Eq,Ord,Show,Typeable,Data,Foldable,Traversable,Functor,Generic)
1005
1006-----------------------------------------------------------------------------
1007-- Builtin names.
1008
1009prelude_mod, main_mod :: l -> ModuleName l
1010prelude_mod l = ModuleName l "Prelude"
1011main_mod    l = ModuleName l "Main"
1012
1013main_name :: l -> Name l
1014main_name l = Ident l "main"
1015
1016unit_con_name :: l -> QName l
1017unit_con_name l = Special l (UnitCon l)
1018
1019tuple_con_name :: l -> Boxed -> Int -> QName l
1020tuple_con_name l b i = Special l (TupleCon l b (i+1))
1021
1022list_con_name :: l -> QName l
1023list_con_name l = Special l (ListCon l)
1024
1025list_cons_name :: l -> QName l
1026list_cons_name l = Special l (Cons l)
1027
1028unboxed_singleton_con_name :: l -> QName l
1029unboxed_singleton_con_name l = Special l (UnboxedSingleCon l)
1030
1031unit_con :: l -> Exp l
1032unit_con l = Con l $ unit_con_name l
1033
1034tuple_con :: l -> Boxed -> Int -> Exp l
1035tuple_con l b i = Con l (tuple_con_name l b i)
1036
1037unboxed_singleton_con :: l -> Exp l
1038unboxed_singleton_con l = Con l (unboxed_singleton_con_name l)
1039
1040as_name, qualified_name, hiding_name, minus_name, bang_name, dot_name, star_name :: l -> Name l
1041as_name        l = Ident  l "as"
1042qualified_name l = Ident  l "qualified"
1043hiding_name    l = Ident  l "hiding"
1044minus_name     l = Symbol l "-"
1045bang_name      l = Symbol l "!"
1046dot_name       l = Symbol l "."
1047star_name      l = Symbol l "*"
1048
1049hole_name :: l -> QName l
1050hole_name      l = Special l (ExprHole l)
1051
1052export_name, safe_name, unsafe_name, interruptible_name, threadsafe_name,
1053  stdcall_name, ccall_name, cplusplus_name, dotnet_name,
1054  jvm_name, js_name, javascript_name, capi_name, forall_name,
1055  family_name, role_name, stock_name, anyclass_name, via_name :: l -> Name l
1056export_name     l = Ident l "export"
1057safe_name       l = Ident l "safe"
1058unsafe_name     l = Ident l "unsafe"
1059interruptible_name l = Ident l "interruptible"
1060threadsafe_name l = Ident l "threadsafe"
1061stdcall_name    l = Ident l "stdcall"
1062ccall_name      l = Ident l "ccall"
1063cplusplus_name  l = Ident l "cplusplus"
1064dotnet_name     l = Ident l "dotnet"
1065jvm_name        l = Ident l "jvm"
1066js_name         l = Ident l "js"
1067javascript_name l = Ident l "javascript"
1068capi_name       l = Ident l "capi"
1069forall_name     l = Ident l "forall"
1070family_name     l = Ident l "family"
1071role_name       l = Ident l "role"
1072stock_name      l = Ident l "stock"
1073anyclass_name   l = Ident l "anyclass"
1074via_name        l = Ident l "via"
1075
1076unit_tycon_name, fun_tycon_name, list_tycon_name, unboxed_singleton_tycon_name :: l -> QName l
1077unit_tycon_name l = unit_con_name l
1078fun_tycon_name  l = Special l (FunCon l)
1079list_tycon_name l = Special l (ListCon l)
1080unboxed_singleton_tycon_name l = Special l (UnboxedSingleCon l)
1081
1082tuple_tycon_name :: l -> Boxed -> Int -> QName l
1083tuple_tycon_name l b i = tuple_con_name l b i
1084
1085unit_tycon, fun_tycon, list_tycon, unboxed_singleton_tycon :: l -> Type l
1086unit_tycon l = TyCon l $ unit_tycon_name l
1087fun_tycon  l = TyCon l $ fun_tycon_name  l
1088list_tycon l = TyCon l $ list_tycon_name l
1089unboxed_singleton_tycon l = TyCon l $ unboxed_singleton_tycon_name l
1090
1091tuple_tycon :: l -> Boxed -> Int -> Type l
1092tuple_tycon l b i = TyCon l (tuple_tycon_name l b i)
1093
1094-----------------------------------------------------------------------------
1095-- AST traversal, boiler-plate style
1096
1097-- | Test if two AST elements are equal modulo annotations.
1098(=~=) :: (Annotated a, Eq (a ())) => a l1 -> a l2 -> Bool
1099a =~= b = fmap (const ()) a == fmap (const ()) b
1100
1101-----------------------------------------------------------------------------
1102-- Reading annotations
1103
1104-- | AST nodes are annotated, and this class allows manipulation of the annotations.
1105class Functor ast => Annotated ast where
1106    -- | Retrieve the annotation of an AST node.
1107    ann :: ast l -> l
1108    -- | Change the annotation of an AST node. Note that only the annotation of
1109    --   the node itself is affected, and not the annotations of any child nodes.
1110    --   if all nodes in the AST tree are to be affected, use 'fmap'.
1111    amap :: (l -> l) -> ast l -> ast l
1112
1113instance Annotated ModuleName where
1114    ann (ModuleName l _) = l
1115    amap f (ModuleName l n) = ModuleName (f l) n
1116
1117instance Annotated SpecialCon where
1118    ann sc = case sc of
1119        UnitCon l   -> l
1120        ListCon l   -> l
1121        FunCon  l   -> l
1122        TupleCon l _ _  -> l
1123        Cons l      -> l
1124        UnboxedSingleCon l  -> l
1125        ExprHole l  -> l
1126    amap = fmap
1127
1128instance Annotated QName where
1129    ann qn = case qn of
1130        Qual    l _ _  -> l
1131        UnQual  l   _  -> l
1132        Special l _    -> l
1133    amap f qn = case qn of
1134        Qual    l mn n  -> Qual    (f l) mn n
1135        UnQual  l    n  -> UnQual  (f l)    n
1136        Special l sc    -> Special (f l) sc
1137
1138instance Annotated Name where
1139    ann (Ident  l _) = l
1140    ann (Symbol l _) = l
1141    amap = fmap
1142
1143instance Annotated IPName where
1144    ann (IPDup l _) = l
1145    ann (IPLin l _) = l
1146    amap = fmap
1147
1148instance Annotated QOp where
1149    ann (QVarOp l _) = l
1150    ann (QConOp l _) = l
1151    amap f (QVarOp l qn) = QVarOp (f l) qn
1152    amap f (QConOp l qn) = QConOp (f l) qn
1153
1154instance Annotated Op where
1155    ann (VarOp l _) = l
1156    ann (ConOp l _) = l
1157    amap f (VarOp l n) = VarOp (f l) n
1158    amap f (ConOp l n) = ConOp (f l) n
1159
1160instance Annotated CName where
1161    ann (VarName l _) = l
1162    ann (ConName l _) = l
1163    amap f (VarName l n) = VarName (f l) n
1164    amap f (ConName l n) = ConName (f l) n
1165
1166instance Annotated Module where
1167    ann (Module l _ _ _ _)            = l
1168    ann (XmlPage l _ _ _ _ _ _)       = l
1169    ann (XmlHybrid l _ _ _ _ _ _ _ _) = l
1170
1171    amap f (Module l mmh ops iss dcls) =
1172        Module (f l) mmh ops iss dcls
1173    amap f (XmlPage l mn os xn xas me es) =
1174        XmlPage (f l) mn os xn xas me es
1175    amap f (XmlHybrid l mmh ops iss dcls xn xas me es) =
1176        XmlHybrid (f l) mmh ops iss dcls xn xas me es
1177
1178instance Annotated ModuleHead where
1179    ann (ModuleHead l _ _ _)         = l
1180    amap f (ModuleHead l n mwt mesl) = ModuleHead (f l) n mwt mesl
1181
1182instance Annotated ExportSpecList where
1183    ann (ExportSpecList l _)      = l
1184    amap f (ExportSpecList l ess) = ExportSpecList (f l) ess
1185
1186instance Annotated ExportSpec where
1187    ann es = case es of
1188        EVar l _            -> l
1189        EAbs l _ _          -> l
1190        EThingWith l _ _ _    -> l
1191        EModuleContents l _ -> l
1192    amap f es = case es of
1193        EVar l qn     -> EVar (f l) qn
1194        EAbs l n qn       -> EAbs (f l) n qn
1195        EThingWith l wc qn cns -> EThingWith (f l) wc qn cns
1196        EModuleContents l mn    -> EModuleContents (f l) mn
1197
1198instance Annotated EWildcard where
1199  ann ewc = case ewc of
1200      NoWildcard l  -> l
1201      EWildcard l _ -> l
1202  amap f ewc = case ewc of
1203      NoWildcard l  -> NoWildcard (f l)
1204      EWildcard l n -> EWildcard (f l) n
1205
1206
1207
1208instance Annotated Namespace where
1209    ann es = case es of
1210        NoNamespace l   -> l
1211        TypeNamespace l -> l
1212        PatternNamespace l -> l
1213    amap f es = case es of
1214        NoNamespace l   -> NoNamespace (f l)
1215        TypeNamespace l -> TypeNamespace (f l)
1216        PatternNamespace l -> PatternNamespace (f l)
1217
1218instance Annotated ImportDecl where
1219    ann (ImportDecl l _ _ _ _ _ _ _) = l
1220    amap f (ImportDecl l mn qual src safe pkg mmn mis) =
1221        ImportDecl (f l) mn qual src safe pkg mmn mis
1222
1223instance Annotated ImportSpecList where
1224    ann (ImportSpecList l _ _)      = l
1225    amap f (ImportSpecList l b iss) = ImportSpecList (f l) b iss
1226
1227instance Annotated ImportSpec where
1228    ann is = case is of
1229        IVar l _         -> l
1230        IAbs l _ _       -> l
1231        IThingAll l _    -> l
1232        IThingWith l _ _ -> l
1233    amap f is = case is of
1234        IVar l n        -> IVar (f l) n
1235        IAbs l ns n     -> IAbs (f l) ns n
1236        IThingAll l n   -> IThingAll (f l) n
1237        IThingWith l n cns  -> IThingWith (f l) n cns
1238
1239instance Annotated Assoc where
1240    ann (AssocNone  l) = l
1241    ann (AssocLeft  l) = l
1242    ann (AssocRight l) = l
1243    amap = fmap
1244
1245instance Annotated Deriving where
1246    ann (Deriving l _ _)        = l
1247    amap f (Deriving l mds ihs) = Deriving (f l) mds ihs
1248
1249instance Annotated DerivStrategy where
1250    ann (DerivStock l)    = l
1251    ann (DerivAnyclass l) = l
1252    ann (DerivNewtype l)  = l
1253    ann (DerivVia l _)    = l
1254
1255    amap f (DerivStock l)    = DerivStock (f l)
1256    amap f (DerivAnyclass l) = DerivAnyclass (f l)
1257    amap f (DerivNewtype l)  = DerivNewtype (f l)
1258    amap f (DerivVia l t)    = DerivVia (f l) t
1259
1260instance Annotated TypeEqn where
1261    ann (TypeEqn l _ _) = l
1262    amap f (TypeEqn l a b) = TypeEqn (f l) a b
1263
1264instance Annotated InjectivityInfo where
1265  ann (InjectivityInfo l _ _) = l
1266  amap f (InjectivityInfo l to from) = InjectivityInfo (f l) to from
1267
1268instance Annotated ResultSig where
1269  ann (KindSig l _) = l
1270  ann (TyVarSig l _) = l
1271
1272  amap f (KindSig l k) = KindSig (f l) k
1273  amap f (TyVarSig l tv) = TyVarSig (f l) tv
1274
1275instance Annotated Decl where
1276    ann decl = case decl of
1277        TypeDecl     l _ _              -> l
1278        TypeFamDecl  l _ _ _            -> l
1279        ClosedTypeFamDecl  l _ _ _ _    -> l
1280        DataDecl     l _ _ _ _ _        -> l
1281        GDataDecl    l _ _ _ _ _ _      -> l
1282        DataFamDecl  l    _ _ _         -> l
1283        TypeInsDecl  l _  _             -> l
1284        DataInsDecl  l _ _ _ _          -> l
1285        GDataInsDecl l _ _ _ _ _        -> l
1286        ClassDecl    l _ _ _ _          -> l
1287        InstDecl     l _ _ _            -> l
1288        DerivDecl    l _ _ _            -> l
1289        InfixDecl    l _ _ _            -> l
1290        DefaultDecl  l _                -> l
1291        SpliceDecl   l _                -> l
1292        TSpliceDecl  l _                -> l
1293        TypeSig      l _ _              -> l
1294        PatSynSig    l _ _ _ _ _ _      -> l
1295        FunBind      l _                -> l
1296        PatBind      l _ _ _            -> l
1297        ForImp       l _ _ _ _ _        -> l
1298        ForExp       l _ _ _ _          -> l
1299        RulePragmaDecl   l _            -> l
1300        DeprPragmaDecl   l _            -> l
1301        WarnPragmaDecl   l _            -> l
1302        InlineSig        l _ _ _        -> l
1303        InlineConlikeSig l   _ _        -> l
1304        SpecSig          l   _ _ _      -> l
1305        SpecInlineSig    l _ _ _ _      -> l
1306        InstSig          l _            -> l
1307        AnnPragma        l _            -> l
1308        MinimalPragma    l _            -> l
1309        RoleAnnotDecl    l _ _          -> l
1310        PatSyn           l _ _ _        -> l
1311        CompletePragma l _ _            -> l
1312    amap f decl = case decl of
1313        TypeDecl     l dh t      -> TypeDecl    (f l) dh t
1314        TypeFamDecl  l dh mk mi  -> TypeFamDecl (f l) dh mk mi
1315        ClosedTypeFamDecl  l dh mk mi eqns  -> ClosedTypeFamDecl (f l) dh mk mi eqns
1316        DataDecl     l dn mcx dh cds ders ->
1317            DataDecl (f l) dn mcx dh cds ders
1318        GDataDecl    l dn mcx dh mk gds ders ->
1319            GDataDecl (f l) dn mcx dh mk gds ders
1320        DataFamDecl  l mcx dh mk         -> DataFamDecl (f l) mcx dh mk
1321        TypeInsDecl  l t1 t2             -> TypeInsDecl (f l) t1 t2
1322        DataInsDecl  l dn t cds ders     -> DataInsDecl (f l) dn t cds ders
1323        GDataInsDecl l dn t mk gds ders  -> GDataInsDecl (f l) dn t mk gds ders
1324        ClassDecl    l mcx dh fds cds    -> ClassDecl (f l) mcx dh fds cds
1325        InstDecl     l mo ih ids         -> InstDecl (f l) mo ih ids
1326        DerivDecl    l mds mo ih         -> DerivDecl (f l) mds mo ih
1327        InfixDecl    l a k ops           -> InfixDecl (f l) a k ops
1328        DefaultDecl  l ts                -> DefaultDecl (f l) ts
1329        SpliceDecl   l sp                -> SpliceDecl (f l) sp
1330        TSpliceDecl  l sp                -> TSpliceDecl (f l) sp
1331        TypeSig      l ns t              -> TypeSig (f l) ns t
1332        PatSynSig    l n dh c1 dh2 c2 t      -> PatSynSig (f l) n dh c1 dh2 c2 t
1333        FunBind      l ms                -> FunBind (f l) ms
1334        PatBind      l p rhs bs          -> PatBind (f l) p rhs bs
1335        ForImp       l cc msf s n t      -> ForImp (f l) cc msf s n t
1336        ForExp       l cc     s n t      -> ForExp (f l) cc     s n t
1337        RulePragmaDecl   l rs            -> RulePragmaDecl (f l) rs
1338        DeprPragmaDecl   l nss           -> DeprPragmaDecl (f l) nss
1339        WarnPragmaDecl   l nss           -> WarnPragmaDecl (f l) nss
1340        InlineSig        l b act qn      -> InlineSig (f l) b act qn
1341        InlineConlikeSig l   act qn      -> InlineConlikeSig (f l) act qn
1342        SpecSig          l   act qn ts   -> SpecSig       (f l)   act qn ts
1343        SpecInlineSig    l b act qn ts   -> SpecInlineSig (f l) b act qn ts
1344        InstSig          l ih            -> InstSig (f l) ih
1345        AnnPragma        l ann'          -> AnnPragma (f l) ann'
1346        MinimalPragma    l b             -> MinimalPragma (f l) b
1347        RoleAnnotDecl    l t rs          -> RoleAnnotDecl (f l) t rs
1348        PatSyn           l p r d         -> PatSyn (f l) p r d
1349        CompletePragma   l cs ty         -> CompletePragma (f l) cs ty
1350
1351instance Annotated Role where
1352    ann r = case r of
1353      RoleWildcard l -> l
1354      Representational l -> l
1355      Phantom l -> l
1356      Nominal l -> l
1357    amap f r = case r of
1358      RoleWildcard l -> RoleWildcard (f l)
1359      Representational l -> Representational (f l)
1360      Phantom l -> Phantom (f l)
1361      Nominal l -> Nominal (f l)
1362
1363instance Annotated Annotation where
1364    ann (Ann     l _ _) = l
1365    ann (TypeAnn l _ _) = l
1366    ann (ModuleAnn l _) = l
1367    amap f (Ann     l n e) = Ann     (f l) n e
1368    amap f (TypeAnn l n e) = TypeAnn (f l) n e
1369    amap f (ModuleAnn l e) = ModuleAnn (f l) e
1370
1371instance Annotated BooleanFormula where
1372    ann (VarFormula l _)   = l
1373    ann (AndFormula l _)   = l
1374    ann (OrFormula l _)    = l
1375    ann (ParenFormula l _) = l
1376    amap f (VarFormula l n)   = VarFormula (f l) n
1377    amap f (AndFormula l bs)  = AndFormula (f l) bs
1378    amap f (OrFormula l bs)   = OrFormula (f l) bs
1379    amap f (ParenFormula l b) = ParenFormula (f l) b
1380
1381instance Annotated DataOrNew where
1382    ann (DataType l) = l
1383    ann (NewType  l) = l
1384    amap = fmap
1385
1386instance Annotated DeclHead where
1387    ann (DHead l _)              = l
1388    ann (DHInfix l _ _)          = l
1389    ann (DHParen l _)            = l
1390    ann (DHApp l _ _)            = l
1391    amap f (DHead l n)           = DHead (f l) n
1392    amap f (DHInfix l tva n)     = DHInfix (f l) tva n
1393    amap f (DHParen l dh)        = DHParen (f l) dh
1394    amap f (DHApp l dh t)        = DHApp (f l) dh t
1395
1396instance Annotated InstRule where
1397    ann (IRule l _ _ _)         = l
1398    ann (IParen l _)            = l
1399    amap f (IRule l mtv cxt qn) = IRule (f l) mtv cxt qn
1400    amap f (IParen l ih)        = IParen (f l) ih
1401
1402instance Annotated InstHead where
1403    ann (IHCon l _)              = l
1404    ann (IHInfix l _ _)          = l
1405    ann (IHParen l _)            = l
1406    ann (IHApp l _ _)            = l
1407    amap f (IHCon l n)           = IHCon (f l) n
1408    amap f (IHInfix l tva n)     = IHInfix (f l) tva n
1409    amap f (IHParen l dh)        = IHParen (f l) dh
1410    amap f (IHApp l dh t)        = IHApp (f l) dh t
1411
1412instance Annotated Binds where
1413    ann (BDecls  l _) = l
1414    ann (IPBinds l _) = l
1415    amap f (BDecls  l decls) = BDecls (f l) decls
1416    amap f (IPBinds l ibs)   = IPBinds (f l) ibs
1417
1418instance Annotated IPBind where
1419    ann (IPBind l _ _) = l
1420    amap f (IPBind l ipn e) = IPBind (f l) ipn e
1421
1422instance Annotated Match where
1423    ann (Match l _ _ _ _)        = l
1424    ann (InfixMatch l _ _ _ _ _) = l
1425    amap f (Match l n ps rhs bs) = Match (f l) n ps rhs bs
1426    amap f (InfixMatch l a n b rhs bs) = InfixMatch (f l) a n b rhs bs
1427
1428instance Annotated QualConDecl where
1429    ann (QualConDecl l _ _ _) = l
1430    amap f (QualConDecl l tvs cx cd) = QualConDecl (f l) tvs cx cd
1431
1432instance Annotated ConDecl where
1433    ann (ConDecl l _ _)        = l
1434    ann (InfixConDecl l _ _ _) = l
1435    ann (RecDecl l _ _)        = l
1436    amap f (ConDecl l n bts) = ConDecl (f l) n bts
1437    amap f (InfixConDecl l ta n tb) = InfixConDecl (f l) ta n tb
1438    amap f (RecDecl l n fds) = RecDecl (f l) n fds
1439
1440instance Annotated FieldDecl where
1441    ann (FieldDecl l _ _) = l
1442    amap f (FieldDecl l ns t) = FieldDecl (f l) ns t
1443
1444instance Annotated GadtDecl where
1445    ann (GadtDecl l _ _ _ _ _) = l
1446    amap f (GadtDecl l n t1 t2 t3 t4) = GadtDecl (f l) n t1 t2 t3 t4
1447
1448instance Annotated ClassDecl where
1449    ann (ClsDecl    l _)      = l
1450    ann (ClsDataFam l _ _ _)  = l
1451    ann (ClsTyFam   l _ _ _) = l
1452    ann (ClsTyDef   l _)    = l
1453    ann (ClsDefSig  l _ _)    = l
1454    amap f (ClsDecl    l d) = ClsDecl (f l) d
1455    amap f (ClsDataFam l mcx dh mk) = ClsDataFam (f l) mcx dh mk
1456    amap f (ClsTyFam   l dh mk mi) = ClsTyFam (f l) dh mk mi
1457    amap f (ClsTyDef   l t ) = ClsTyDef (f l) t
1458    amap f (ClsDefSig  l n t) = ClsDefSig (f l) n t
1459
1460instance Annotated InstDecl where
1461    ann id = case id of
1462        InsDecl   l _            -> l
1463        InsType   l _ _          -> l
1464        InsData   l _ _  _ _     -> l
1465        InsGData  l _ _ _ _ _    -> l
1466--        InsInline l _ _ _    -> l
1467    amap f id = case id of
1468        InsDecl   l d           -> InsDecl (f l) d
1469        InsType   l t1 t2       -> InsType (f l) t1 t2
1470        InsData   l dn t    cds ders -> InsData  (f l) dn t    cds ders
1471        InsGData  l dn t mk gds ders -> InsGData (f l) dn t mk gds ders
1472--        InsInline l b act qn    -> InsInline (f l) b act qn
1473
1474instance Annotated BangType where
1475     ann (BangedTy   l)       = l
1476     ann (LazyTy   l)         = l
1477     ann (NoStrictAnnot l)    = l
1478
1479     amap f (BangedTy   l) = BangedTy (f l)
1480     amap f (LazyTy   l)   = LazyTy (f l)
1481     amap f (NoStrictAnnot l) = NoStrictAnnot (f l)
1482
1483instance Annotated Unpackedness where
1484    ann (Unpack l) = l
1485    ann (NoUnpack l) = l
1486    ann (NoUnpackPragma l) = l
1487
1488    amap f (Unpack l) = Unpack (f l)
1489    amap f (NoUnpack l) = Unpack (f l)
1490    amap f (NoUnpackPragma l) = Unpack (f l)
1491
1492instance Annotated Rhs where
1493     ann (UnGuardedRhs l _) = l
1494     ann (GuardedRhss  l _) = l
1495     amap f (UnGuardedRhs l e)     = UnGuardedRhs (f l) e
1496     amap f (GuardedRhss  l grhss) = GuardedRhss  (f l) grhss
1497
1498instance Annotated GuardedRhs where
1499     ann (GuardedRhs l _ _) = l
1500     amap f (GuardedRhs l ss e) = GuardedRhs (f l) ss e
1501
1502instance Annotated Type where
1503    ann t = case t of
1504      TyForall l _ _ _              -> l
1505      TyStar  l                     -> l
1506      TyFun   l _ _                 -> l
1507      TyTuple l _ _                 -> l
1508      TyUnboxedSum l _              -> l
1509      TyList  l _                   -> l
1510      TyParArray  l _               -> l
1511      TyApp   l _ _                 -> l
1512      TyVar   l _                   -> l
1513      TyCon   l _                   -> l
1514      TyParen l _                   -> l
1515      TyInfix l _ _ _               -> l
1516      TyKind  l _ _                 -> l
1517      TyPromoted l   _              -> l
1518      TyEquals l _ _                -> l
1519      TySplice l _                  -> l
1520      TyBang l _ _ _                  -> l
1521      TyWildCard l _                -> l
1522      TyQuasiQuote l _ _            -> l
1523    amap f t1 = case t1 of
1524      TyForall l mtvs mcx t         -> TyForall (f l) mtvs mcx t
1525      TyStar  l                     -> TyStar (f l)
1526      TyFun   l t1' t2              -> TyFun (f l) t1' t2
1527      TyTuple l b ts                -> TyTuple (f l) b ts
1528      TyUnboxedSum l s              -> TyUnboxedSum (f l) s
1529      TyList  l t                   -> TyList (f l) t
1530      TyParArray  l t               -> TyParArray (f l) t
1531      TyApp   l t1' t2              -> TyApp (f l) t1' t2
1532      TyVar   l n                   -> TyVar (f l) n
1533      TyCon   l qn                  -> TyCon (f l) qn
1534      TyParen l t                   -> TyParen (f l) t
1535      TyInfix l ta qn tb            -> TyInfix (f l) ta qn tb
1536      TyKind  l t k                 -> TyKind (f l) t k
1537      TyPromoted l   p              -> TyPromoted (f l)   p
1538      TyEquals l a b                -> TyEquals (f l) a b
1539      TySplice l s                  -> TySplice (f l) s
1540      TyBang l b u t                  -> TyBang (f l) b u t
1541      TyWildCard l n                -> TyWildCard (f l) n
1542      TyQuasiQuote l n s            -> TyQuasiQuote (f l) n s
1543
1544instance Annotated MaybePromotedName where
1545  ann t = case t of
1546    PromotedName l _ -> l
1547    UnpromotedName l _ -> l
1548  amap f tl =  case tl of
1549    PromotedName l q -> PromotedName (f l)     q
1550    UnpromotedName l q -> UnpromotedName (f l) q
1551
1552instance Annotated TyVarBind where
1553    ann (KindedVar   l _ _) = l
1554    ann (UnkindedVar l _)   = l
1555    amap f (KindedVar   l n k) = KindedVar   (f l) n k
1556    amap f (UnkindedVar l n)   = UnkindedVar (f l) n
1557
1558instance Annotated FunDep where
1559    ann (FunDep l _ _) = l
1560    amap f (FunDep l ns1 ns2) = FunDep (f l) ns1 ns2
1561
1562instance Annotated Context where
1563    ann (CxSingle l _) = l
1564    ann (CxTuple  l _) = l
1565    ann (CxEmpty  l)   = l
1566    amap f (CxSingle l asst ) = CxSingle (f l) asst
1567    amap f (CxTuple  l assts) = CxTuple  (f l) assts
1568    amap f (CxEmpty l) = CxEmpty (f l)
1569
1570instance Annotated Asst where
1571    ann asst = case asst of
1572        TypeA l _        -> l
1573        IParam l _ _     -> l
1574        ParenA l _       -> l
1575    amap f asst = case asst of
1576        TypeA l t           -> TypeA (f l) t
1577        IParam l ipn t      -> IParam (f l) ipn t
1578        ParenA l a          -> ParenA (f l) a
1579
1580instance Annotated Literal where
1581    ann lit = case lit of
1582        Char    l _    _  -> l
1583        String  l _    _  -> l
1584        Int     l _    _  -> l
1585        Frac    l _    _  -> l
1586        PrimInt    l _ _  -> l
1587        PrimWord   l _ _  -> l
1588        PrimFloat  l _ _  -> l
1589        PrimDouble l _ _  -> l
1590        PrimChar   l _ _  -> l
1591        PrimString l _ _  -> l
1592    amap = fmap
1593
1594instance Annotated Sign where
1595    ann sg = case sg of
1596        Signless l -> l
1597        Negative l -> l
1598    amap = fmap
1599
1600instance Annotated Exp where
1601    ann e = case e of
1602        Var l _                -> l
1603        OverloadedLabel l _    -> l
1604        IPVar l _              -> l
1605        Con l _                -> l
1606        Lit l _                -> l
1607        InfixApp l _ _ _       -> l
1608        App l _ _              -> l
1609        NegApp l _             -> l
1610        Lambda l _ _           -> l
1611        Let l _ _              -> l
1612        If l _ _ _             -> l
1613        MultiIf l _            -> l
1614        Case l _ _             -> l
1615        Do l _                 -> l
1616        MDo l _                -> l
1617        Tuple l _ _            -> l
1618        UnboxedSum l _ _ _     -> l
1619        TupleSection l _ _     -> l
1620        List l _               -> l
1621        ParArray l _           -> l
1622        Paren l _              -> l
1623        LeftSection l _ _      -> l
1624        RightSection l _ _     -> l
1625        RecConstr l _ _        -> l
1626        RecUpdate l _ _        -> l
1627        EnumFrom l _           -> l
1628        EnumFromTo l _ _       -> l
1629        EnumFromThen l _ _     -> l
1630        EnumFromThenTo l _ _ _ -> l
1631        ParArrayFromTo l _ _   -> l
1632        ParArrayFromThenTo l _ _ _ -> l
1633        ListComp l _ _         -> l
1634        ParComp  l _ _         -> l
1635        ParArrayComp  l _ _    -> l
1636        ExpTypeSig l _ _       -> l
1637        VarQuote l _           -> l
1638        TypQuote l _           -> l
1639        BracketExp l _         -> l
1640        SpliceExp l _          -> l
1641        QuasiQuote l _ _       -> l
1642        TypeApp l _            -> l
1643
1644        XTag  l _ _ _ _        -> l
1645        XETag l _ _ _          -> l
1646        XPcdata l _            -> l
1647        XExpTag l _            -> l
1648        XChildTag l _          -> l
1649
1650        CorePragma l _ _       -> l
1651        SCCPragma  l _ _       -> l
1652        GenPragma  l _ _ _ _   -> l
1653
1654        Proc            l _ _  -> l
1655        LeftArrApp      l _ _  -> l
1656        RightArrApp     l _ _  -> l
1657        LeftArrHighApp  l _ _  -> l
1658        RightArrHighApp l _ _  -> l
1659        ArrOp           l _    -> l
1660
1661        LCase l _              -> l
1662
1663    amap f e1 = case e1 of
1664        Var l qn        -> Var (f l) qn
1665        OverloadedLabel l qn -> OverloadedLabel (f l) qn
1666        IPVar l ipn     -> IPVar (f l) ipn
1667        Con l qn        -> Con (f l) qn
1668        Lit l lit       -> Lit (f l) lit
1669        InfixApp l e1' qop e2    -> InfixApp (f l) e1' qop e2
1670        App l e1' e2    -> App (f l) e1' e2
1671        NegApp l e      -> NegApp (f l) e
1672        Lambda l ps e   -> Lambda (f l) ps e
1673        Let l bs e      -> Let (f l) bs e
1674        If l ec et ee   -> If (f l) ec et ee
1675        Case l e alts   -> Case (f l) e alts
1676        Do l ss         -> Do (f l) ss
1677        MDo l ss        -> MDo (f l) ss
1678        Tuple l bx es   -> Tuple (f l) bx es
1679        UnboxedSum l b a es -> UnboxedSum (f l) b a es
1680        TupleSection l bx mes -> TupleSection (f l) bx mes
1681        List l es       -> List (f l) es
1682        ParArray l es   -> ParArray (f l) es
1683        Paren l e       -> Paren (f l) e
1684        LeftSection l e qop     -> LeftSection (f l) e qop
1685        RightSection l qop e    -> RightSection (f l) qop e
1686        RecConstr l qn fups     -> RecConstr (f l) qn fups
1687        RecUpdate l e  fups     -> RecUpdate (f l) e  fups
1688        EnumFrom l e            -> EnumFrom (f l) e
1689        EnumFromTo l ef et      -> EnumFromTo (f l) ef et
1690        EnumFromThen l ef et    -> EnumFromThen (f l) ef et
1691        EnumFromThenTo l ef eth eto -> EnumFromThenTo (f l) ef eth eto
1692        ParArrayFromTo l ef et  -> ParArrayFromTo (f l) ef et
1693        ParArrayFromThenTo l ef eth eto -> ParArrayFromThenTo (f l) ef eth eto
1694        ListComp l e qss        -> ListComp (f l) e qss
1695        ParComp  l e qsss       -> ParComp  (f l) e qsss
1696        ParArrayComp  l e qsss  -> ParArrayComp  (f l) e qsss
1697        ExpTypeSig l e t        -> ExpTypeSig (f l) e t
1698        VarQuote l qn           -> VarQuote (f l) qn
1699        TypQuote l qn           -> TypQuote (f l) qn
1700        BracketExp l br         -> BracketExp (f l) br
1701        SpliceExp l sp          -> SpliceExp (f l) sp
1702        QuasiQuote l sn se      -> QuasiQuote (f l) sn se
1703        TypeApp l t             -> TypeApp (f l) t
1704
1705        XTag  l xn xas me es     -> XTag  (f l) xn xas me es
1706        XETag l xn xas me        -> XETag (f l) xn xas me
1707        XPcdata l s              -> XPcdata (f l) s
1708        XExpTag l e              -> XExpTag (f l) e
1709        XChildTag l es           -> XChildTag (f l) es
1710
1711        CorePragma l s e   -> CorePragma (f l) s e
1712        SCCPragma  l s e   -> SCCPragma (f l) s e
1713        GenPragma  l s n12 n34 e -> GenPragma (f l) s n12 n34 e
1714
1715        Proc            l p e  -> Proc (f l) p e
1716        LeftArrApp      l e1' e2 -> LeftArrApp      (f l) e1' e2
1717        RightArrApp     l e1' e2 -> RightArrApp     (f l) e1' e2
1718        LeftArrHighApp  l e1' e2 -> LeftArrHighApp  (f l) e1' e2
1719        RightArrHighApp l e1' e2 -> RightArrHighApp (f l) e1' e2
1720        ArrOp           l e      -> ArrOp           (f l) e
1721
1722        LCase l alts -> LCase (f l) alts
1723        MultiIf l alts -> MultiIf (f l) alts
1724
1725
1726instance Annotated XName where
1727    ann (XName l _)      = l
1728    ann (XDomName l _ _) = l
1729    amap = fmap
1730
1731instance Annotated XAttr where
1732    ann (XAttr l _ _) = l
1733    amap f (XAttr l xn e) = XAttr (f l) xn e
1734
1735instance Annotated Bracket where
1736    ann (ExpBracket l _)  = l
1737    ann (TExpBracket l _) = l
1738    ann (PatBracket l _)  = l
1739    ann (TypeBracket l _) = l
1740    ann (DeclBracket l _) = l
1741    amap f (ExpBracket l e) = ExpBracket (f l) e
1742    amap f (TExpBracket l e) = TExpBracket (f l) e
1743    amap f (PatBracket l p) = PatBracket (f l) p
1744    amap f (TypeBracket l t) = TypeBracket (f l) t
1745    amap f (DeclBracket l ds) = DeclBracket (f l) ds
1746
1747instance Annotated Splice where
1748    ann (IdSplice l _)    = l
1749    ann (TIdSplice l _)   = l
1750    ann (ParenSplice l _) = l
1751    ann (TParenSplice l _) = l
1752    amap f (IdSplice l s) = IdSplice (f l) s
1753    amap f (TIdSplice l s) = TIdSplice (f l) s
1754    amap f (ParenSplice l e) = ParenSplice (f l) e
1755    amap f (TParenSplice l e) = TParenSplice (f l) e
1756
1757instance Annotated Safety where
1758    ann (PlayRisky l) = l
1759    ann (PlaySafe l _) = l
1760    ann (PlayInterruptible l) = l
1761    amap = fmap
1762
1763instance Annotated CallConv where
1764    ann (StdCall l) = l
1765    ann (CCall l) = l
1766    ann (CPlusPlus l) = l
1767    ann (DotNet l) = l
1768    ann (Jvm l) = l
1769    ann (Js l) = l
1770    ann (JavaScript l) = l
1771    ann (CApi l) = l
1772    amap = fmap
1773
1774instance Annotated ModulePragma where
1775    ann (LanguagePragma   l _)   = l
1776    ann (OptionsPragma    l _ _) = l
1777    ann (AnnModulePragma  l _)   = l
1778    amap f (LanguagePragma   l ns) = LanguagePragma (f l) ns
1779    amap f (AnnModulePragma  l a) = AnnModulePragma (f l) a
1780    amap f p = fmap f p
1781
1782instance Annotated Overlap where
1783    ann (NoOverlap l)  = l
1784    ann (Overlap l)    = l
1785    ann (Overlaps l)   = l
1786    ann (Overlappable l) = l
1787    ann (Overlapping l)  = l
1788    ann (Incoherent l) = l
1789    amap = fmap
1790
1791instance Annotated Activation where
1792    ann (ActiveFrom   l _) = l
1793    ann (ActiveUntil  l _) = l
1794    amap = fmap
1795
1796instance Annotated Rule where
1797    ann (Rule l _ _ _ _ _) = l
1798    amap f (Rule l s act mrvs e1 e2) = Rule (f l) s act mrvs e1 e2
1799
1800instance Annotated RuleVar where
1801    ann (RuleVar l _)        = l
1802    ann (TypedRuleVar l _ _) = l
1803    amap f (RuleVar l n) = RuleVar (f l) n
1804    amap f (TypedRuleVar l n t) = TypedRuleVar (f l) n t
1805
1806instance Annotated WarningText where
1807    ann (DeprText l _) = l
1808    ann (WarnText l _) = l
1809    amap = fmap
1810
1811instance Annotated Pat where
1812    ann p = case p of
1813      PVar l _          -> l
1814      PLit l _ _        -> l
1815      PNPlusK l _ _     -> l
1816      PInfixApp l _ _ _ -> l
1817      PApp l _ _        -> l
1818      PTuple l _ _      -> l
1819      PUnboxedSum l _ _ _ -> l
1820      PList l _         -> l
1821      PParen l _        -> l
1822      PRec l _ _        -> l
1823      PAsPat l _ _      -> l
1824      PWildCard l       -> l
1825      PIrrPat l _       -> l
1826      PatTypeSig l _ _  -> l
1827      PViewPat l _ _    -> l
1828      PRPat l _         -> l
1829      PXTag l _ _ _ _   -> l
1830      PXETag l _ _ _    -> l
1831      PXPcdata l _      -> l
1832      PXPatTag l _      -> l
1833      PXRPats  l _      -> l
1834      PSplice l _       -> l
1835      PQuasiQuote l _ _ -> l
1836      PBangPat l _      -> l
1837    amap f p1 = case p1 of
1838      PVar l n          -> PVar (f l) n
1839      PLit l sg lit     -> PLit (f l) sg lit
1840      PNPlusK l n k     -> PNPlusK (f l) n k
1841      PInfixApp l pa qn pb  -> PInfixApp (f l) pa qn pb
1842      PApp l qn ps      -> PApp (f l) qn ps
1843      PTuple l bx ps    -> PTuple (f l) bx ps
1844      PUnboxedSum l b a ps -> PUnboxedSum (f l) b a ps
1845      PList l ps        -> PList (f l) ps
1846      PParen l p        -> PParen (f l) p
1847      PRec l qn pfs     -> PRec (f l) qn pfs
1848      PAsPat l n p      -> PAsPat (f l) n p
1849      PWildCard l       -> PWildCard (f l)
1850      PIrrPat l p       -> PIrrPat (f l) p
1851      PatTypeSig l p t  -> PatTypeSig (f l) p t
1852      PViewPat l e p    -> PViewPat (f l) e p
1853      PRPat l rps       -> PRPat (f l) rps
1854      PXTag l xn pxas mp ps -> PXTag  (f l) xn pxas mp ps
1855      PXETag l xn pxas mp   -> PXETag (f l) xn pxas mp
1856      PXPcdata l s      -> PXPcdata (f l) s
1857      PXPatTag l p      -> PXPatTag (f l) p
1858      PXRPats  l rps    -> PXRPats  (f l) rps
1859      PSplice l sp      -> PSplice (f l) sp
1860      PQuasiQuote l sn st   -> PQuasiQuote (f l) sn st
1861      PBangPat l p          -> PBangPat (f l) p
1862
1863instance Annotated PXAttr where
1864    ann (PXAttr l _ _) = l
1865    amap f (PXAttr l xn p) = PXAttr (f l) xn p
1866
1867instance Annotated RPatOp where
1868    ann (RPStar  l) = l
1869    ann (RPStarG l) = l
1870    ann (RPPlus  l) = l
1871    ann (RPPlusG l) = l
1872    ann (RPOpt   l) = l
1873    ann (RPOptG  l) = l
1874    amap = fmap
1875
1876instance Annotated RPat where
1877    ann rp = case rp of
1878      RPOp l _ _            -> l
1879      RPEither l _ _        -> l
1880      RPSeq l _             -> l
1881      RPGuard l _ _         -> l
1882      RPCAs l _ _           -> l
1883      RPAs l _ _            -> l
1884      RPParen l _           -> l
1885      RPPat l _             -> l
1886    amap f rp1 = case rp1 of
1887      RPOp l rp rop         -> RPOp (f l) rp rop
1888      RPEither l rp1' rp2   -> RPEither (f l) rp1' rp2
1889      RPSeq l rps           -> RPSeq (f l) rps
1890      RPGuard l p ss        -> RPGuard (f l) p ss
1891      RPCAs l n rp          -> RPCAs (f l) n rp
1892      RPAs l n rp           -> RPAs (f l) n rp
1893      RPParen l rp          -> RPParen (f l) rp
1894      RPPat l p             -> RPPat (f l) p
1895
1896instance Annotated PatField where
1897    ann (PFieldPat l _ _)  = l
1898    ann (PFieldPun l _)    = l
1899    ann (PFieldWildcard l) = l
1900    amap f (PFieldPat l qn p) = PFieldPat (f l) qn p
1901    amap f (PFieldPun l n) = PFieldPun (f l) n
1902    amap f (PFieldWildcard l) = PFieldWildcard (f l)
1903
1904instance Annotated Stmt where
1905    ann (Generator l _ _) = l
1906    ann (Qualifier l _)   = l
1907    ann (LetStmt l _)     = l
1908    ann (RecStmt l _)     = l
1909    amap f (Generator l p e) = Generator (f l) p e
1910    amap f (Qualifier l e)   = Qualifier (f l) e
1911    amap f (LetStmt l bs)    = LetStmt (f l) bs
1912    amap f (RecStmt l ss)    = RecStmt (f l) ss
1913
1914instance Annotated QualStmt where
1915    ann (QualStmt     l _)   = l
1916    ann (ThenTrans    l _)   = l
1917    ann (ThenBy       l _ _) = l
1918    ann (GroupBy      l _)   = l
1919    ann (GroupUsing   l _)   = l
1920    ann (GroupByUsing l _ _) = l
1921    amap f (QualStmt     l s) = QualStmt (f l) s
1922    amap f (ThenTrans    l e) = ThenTrans (f l) e
1923    amap f (ThenBy       l e1 e2) = ThenBy (f l) e1 e2
1924    amap f (GroupBy      l e) = GroupBy (f l) e
1925    amap f (GroupUsing   l e) = GroupUsing (f l) e
1926    amap f (GroupByUsing l e1 e2) = GroupByUsing (f l) e1 e2
1927
1928instance Annotated FieldUpdate where
1929    ann (FieldUpdate l _ _)  = l
1930    ann (FieldPun l _)       = l
1931    ann (FieldWildcard l)    = l
1932    amap f (FieldUpdate l qn e) = FieldUpdate (f l) qn e
1933    amap f (FieldPun l n)       = FieldPun (f l) n
1934    amap f (FieldWildcard l)    = FieldWildcard (f l)
1935
1936instance Annotated Alt where
1937    ann (Alt l _ _ _) = l
1938    amap f (Alt l p gs bs) = Alt (f l) p gs bs
1939
1940instance Annotated Promoted where
1941    ann (PromotedInteger l _ _) = l
1942    ann (PromotedString l _ _)  = l
1943    ann (PromotedCon l _ _)     = l
1944    ann (PromotedList l _ _)    = l
1945    ann (PromotedTuple l _)     = l
1946    ann (PromotedUnit l)        = l
1947    amap f (PromotedInteger l int raw) = PromotedInteger (f l) int raw
1948    amap f (PromotedString l str raw) = PromotedString (f l) str raw
1949    amap f (PromotedCon l b qn)   = PromotedCon (f l) b qn
1950    amap f (PromotedList l b ps)  = PromotedList  (f l) b ps
1951    amap f (PromotedTuple l ps) = PromotedTuple (f l) ps
1952    amap f (PromotedUnit l)     = PromotedUnit (f l)
1953