HsDecls

ghc-7.6.3: The GHC API

Safe Haskell | None

HsDecls

Contents

- Toplevel declarations
  - Class or type declarations
  - Instance declarations
  - Standalone deriving declarations
  - `RULE` declarations
  - `VECTORISE` declarations
  - `default` declarations
  - Top-level template haskell splice
  - Foreign function interface declarations
  - Data-constructor declarations
  - Document comments
  - Deprecations
  - Annotations
- Grouping

Description

Abstract syntax of global declarations.

Definitions for: `TyDecl` and `ConDecl`, `ClassDecl`, `InstDecl`, `DefaultDecl` and `ForeignDecl`.

Synopsis

- data HsDecl id
  - = TyClD (TyClDecl id)
  - | InstD (InstDecl id)
  - | DerivD (DerivDecl id)
  - | ValD (HsBind id)
  - | SigD (Sig id)
  - | DefD (DefaultDecl id)
  - | ForD (ForeignDecl id)
  - | WarningD (WarnDecl id)
  - | AnnD (AnnDecl id)
  - | RuleD (RuleDecl id)
  - | VectD (VectDecl id)
  - | SpliceD (SpliceDecl id)
  - | DocD DocDecl
  - | QuasiQuoteD (HsQuasiQuote id)
- type LHsDecl id = Located (HsDecl id)
- data HsTyDefn name
  - = TySynonym {
    - td_synRhs :: LHsType name
    }
  - | TyData {
    - td_ND :: NewOrData
    - td_ctxt :: LHsContext name
    - td_cType :: Maybe CType
    - td_kindSig :: Maybe (LHsKind name)
    - td_cons :: [LConDecl name]
    - td_derivs :: Maybe [LHsType name]
    }
- data TyClDecl name
  - = ForeignType {
    - tcdLName :: Located name
    - tcdExtName :: Maybe FastString
    }
  - | TyFamily {
    - tcdFlavour :: FamilyFlavour
    - tcdLName :: Located name
    - tcdTyVars :: LHsTyVarBndrs name
    - tcdKindSig :: Maybe (LHsKind name)
    }
  - | TyDecl {
    - tcdLName :: Located name
    - tcdTyVars :: LHsTyVarBndrs name
    - tcdTyDefn :: HsTyDefn name
    - tcdFVs :: NameSet
    }
  - | ClassDecl {
    - tcdCtxt :: LHsContext name
    - tcdLName :: Located name
    - tcdTyVars :: LHsTyVarBndrs name
    - tcdFDs :: [Located (FunDep name)]
    - tcdSigs :: [LSig name]
    - tcdMeths :: LHsBinds name
    - tcdATs :: [LTyClDecl name]
    - tcdATDefs :: [LFamInstDecl name]
    - tcdDocs :: [LDocDecl]
    - tcdFVs :: NameSet
    }
- type LTyClDecl name = Located (TyClDecl name)
- type TyClGroup name = [LTyClDecl name]
- isClassDecl :: TyClDecl name -> Bool
- isDataDecl :: TyClDecl name -> Bool
- isSynDecl :: TyClDecl name -> Bool
- isFamilyDecl :: TyClDecl name -> Bool
- isHsDataDefn :: HsTyDefn name -> Bool
- isHsSynDefn :: HsTyDefn name -> Bool
- tcdName :: TyClDecl name -> name
- famInstDeclName :: LFamInstDecl a -> a
- countTyClDecls :: [TyClDecl name] -> (Int, Int, Int, Int, Int)
- pprTyDefnFlavour :: HsTyDefn a -> SDoc
- pprTyClDeclFlavour :: TyClDecl a -> SDoc
- data InstDecl name
  - = ClsInstD {
    - cid_poly_ty :: LHsType name
    - cid_binds :: LHsBinds name
    - cid_sigs :: [LSig name]
    - cid_fam_insts :: [LFamInstDecl name]
    }
  - | FamInstD {
    - lid_inst :: FamInstDecl name
    }
- type LInstDecl name = Located (InstDecl name)
- data NewOrData
  - = NewType
  - | DataType
- data FamilyFlavour
  - = TypeFamily
  - | DataFamily
- data FamInstDecl name = FamInstDecl {
  - fid_tycon :: Located name
  - fid_pats :: HsWithBndrs [LHsType name]
  - fid_defn :: HsTyDefn name
  - fid_fvs :: NameSet
  }
- type LFamInstDecl name = Located (FamInstDecl name)
- instDeclFamInsts :: [LInstDecl name] -> [FamInstDecl name]
- data DerivDecl name = DerivDecl {
  - deriv_type :: LHsType name
  }
- type LDerivDecl name = Located (DerivDecl name)
- data RuleDecl name = HsRule RuleName Activation [RuleBndr name] (Located (HsExpr name)) NameSet (Located (HsExpr name)) NameSet
- type LRuleDecl name = Located (RuleDecl name)
- data RuleBndr name
  - = RuleBndr (Located name)
  - | RuleBndrSig (Located name) (HsWithBndrs (LHsType name))
- collectRuleBndrSigTys :: [RuleBndr name] -> [HsWithBndrs (LHsType name)]
- data VectDecl name
  - = HsVect (Located name) (Maybe (LHsExpr name))
  - | HsNoVect (Located name)
  - | HsVectTypeIn Bool (Located name) (Maybe (Located name))
  - | HsVectTypeOut Bool TyCon (Maybe TyCon)
  - | HsVectClassIn (Located name)
  - | HsVectClassOut Class
  - | HsVectInstIn (LHsType name)
  - | HsVectInstOut ClsInst
- type LVectDecl name = Located (VectDecl name)
- lvectDeclName :: NamedThing name => LVectDecl name -> Name
- lvectInstDecl :: LVectDecl name -> Bool
- data DefaultDecl name = DefaultDecl [LHsType name]
- type LDefaultDecl name = Located (DefaultDecl name)
- data SpliceDecl id = SpliceDecl (Located (HsExpr id)) HsExplicitFlag
- data ForeignDecl name
  - = ForeignImport (Located name) (LHsType name) Coercion ForeignImport
  - | ForeignExport (Located name) (LHsType name) Coercion ForeignExport
- type LForeignDecl name = Located (ForeignDecl name)
- data ForeignImport = CImport CCallConv Safety (Maybe Header) CImportSpec
- data ForeignExport = CExport CExportSpec
- noForeignImportCoercionYet :: Coercion
- noForeignExportCoercionYet :: Coercion
- data CImportSpec
  - = CLabel CLabelString
  - | CFunction CCallTarget
  - | CWrapper
- data ConDecl name = ConDecl {
  - con_name :: Located name
  - con_explicit :: HsExplicitFlag
  - con_qvars :: LHsTyVarBndrs name
  - con_cxt :: LHsContext name
  - con_details :: HsConDeclDetails name
  - con_res :: ResType (LHsType name)
  - con_doc :: Maybe LHsDocString
  - con_old_rec :: Bool
  }
- type LConDecl name = Located (ConDecl name)
- data ResType ty
  - = ResTyH98
  - | ResTyGADT ty
- type HsConDeclDetails name = HsConDetails (LBangType name) [ConDeclField name]
- hsConDeclArgTys :: HsConDeclDetails name -> [LBangType name]
- data DocDecl
  - = DocCommentNext HsDocString
  - | DocCommentPrev HsDocString
  - | DocCommentNamed String HsDocString
  - | DocGroup Int HsDocString
- type LDocDecl = Located DocDecl
- docDeclDoc :: DocDecl -> HsDocString
- data WarnDecl name = Warning name WarningTxt
- type LWarnDecl name = Located (WarnDecl name)
- data AnnDecl name = HsAnnotation (AnnProvenance name) (Located (HsExpr name))
- type LAnnDecl name = Located (AnnDecl name)
- data AnnProvenance name
  - = ValueAnnProvenance name
  - | TypeAnnProvenance name
  - | ModuleAnnProvenance
- annProvenanceName_maybe :: AnnProvenance name -> Maybe name
- modifyAnnProvenanceNameM :: Monad m => (before -> m after) -> AnnProvenance before -> m (AnnProvenance after)
- data HsGroup id = HsGroup {
  - hs_valds :: HsValBinds id
  - hs_tyclds :: [[LTyClDecl id]]
  - hs_instds :: [LInstDecl id]
  - hs_derivds :: [LDerivDecl id]
  - hs_fixds :: [LFixitySig id]
  - hs_defds :: [LDefaultDecl id]
  - hs_fords :: [LForeignDecl id]
  - hs_warnds :: [LWarnDecl id]
  - hs_annds :: [LAnnDecl id]
  - hs_ruleds :: [LRuleDecl id]
  - hs_vects :: [LVectDecl id]
  - hs_docs :: [LDocDecl]
  }
- emptyRdrGroup :: HsGroup a
- emptyRnGroup :: HsGroup a
- appendGroups :: HsGroup a -> HsGroup a -> HsGroup a

# Toplevel declarations

data HsDecl id

A Haskell Declaration

Constructors

TyClD (TyClDecl id) | A type or class declaration.
InstD (InstDecl id) | An instance declaration.
DerivD (DerivDecl id) |
ValD (HsBind id) |
SigD (Sig id) |
DefD (DefaultDecl id) |
ForD (ForeignDecl id) |
WarningD (WarnDecl id) |
AnnD (AnnDecl id) |
RuleD (RuleDecl id) |
VectD (VectDecl id) |
SpliceD (SpliceDecl id) |
DocD DocDecl |
QuasiQuoteD (HsQuasiQuote id) |

Instances

Typeable1 HsDecl |
Data id => Data (HsDecl id) |
OutputableBndr name => Outputable (HsDecl name) |

type LHsDecl id = Located (HsDecl id)

data HsTyDefn name

Constructors

TySynonym | Synonym expansion
Fields td_synRhs :: LHsType name
TyData | Declares a data type or newtype, giving its construcors `data/newtype T a = constrs data/newtype instance T [a] = constrs`
Fields td_ND :: NewOrData td_ctxt :: LHsContext name Context td_cType :: Maybe CType td_kindSig :: Maybe (LHsKind name) Optional kind signature. `(Just k)` for a GADT-style `data`, or `data instance` decl, with explicit kind sig Always `Nothing` for H98-syntax decls td_cons :: [LConDecl name] Data constructors For `data T a = T1 | T2 a` the `LConDecl`s all have `ResTyH98`. For `data T a where { T1 :: T a }` the `LConDecls` all have `ResTyGADT`. td_derivs :: Maybe [LHsType name] Derivings; `Nothing` => not specified, `Just []` => derive exactly what is asked These types must be of form `forall ab. C ty1 ty2` Typically the foralls and ty args are empty, but they are non-empty for the newtype-deriving case

Instances

Typeable1 HsTyDefn |
Data name => Data (HsTyDefn name) |
OutputableBndr name => Outputable (HsTyDefn name) |

## Class or type declarations

data TyClDecl name

A type or class declaration.

Constructors

ForeignType |
Fields tcdLName :: Located name Name of the class Type constructor tcdExtName :: Maybe FastString
TyFamily |
    type/data family T :: *->*
Fields tcdFlavour :: FamilyFlavour tcdLName :: Located name Name of the class Type constructor tcdTyVars :: LHsTyVarBndrs name Class type variables Type variables; for an associated type these include outer binders Eg class T a where type F a :: * type F a = a -> a Here the type decl for `f` includes `a` in its tcdTyVars tcdKindSig :: Maybe (LHsKind name)
TyDecl |
Fields tcdLName :: Located name Name of the class Type constructor tcdTyVars :: LHsTyVarBndrs name Class type variables Type variables; for an associated type these include outer binders Eg class T a where type F a :: * type F a = a -> a Here the type decl for `f` includes `a` in its tcdTyVars tcdTyDefn :: HsTyDefn name tcdFVs :: NameSet
ClassDecl |
Fields tcdCtxt :: LHsContext name Context... tcdLName :: Located name Name of the class Type constructor tcdTyVars :: LHsTyVarBndrs name Class type variables Type variables; for an associated type these include outer binders Eg class T a where type F a :: * type F a = a -> a Here the type decl for `f` includes `a` in its tcdTyVars tcdFDs :: [Located (FunDep name)] Functional deps tcdSigs :: [LSig name] Methods' signatures tcdMeths :: LHsBinds name Default methods tcdATs :: [LTyClDecl name] Associated types; ie only `TyFamily` tcdATDefs :: [LFamInstDecl name] Associated type defaults; ie only `TySynonym` tcdDocs :: [LDocDecl] Haddock docs tcdFVs :: NameSet

Instances

Typeable1 TyClDecl |
Data name => Data (TyClDecl name) |
OutputableBndr name => Outputable (TyClDecl name) |

type LTyClDecl name = Located (TyClDecl name)

type TyClGroup name = [LTyClDecl name]

isClassDecl :: TyClDecl name -> Bool

type class

isDataDecl :: TyClDecl name -> Bool

`True` = argument is a `data`/`newtype` declaration.

isSynDecl :: TyClDecl name -> Bool

type or type instance declaration

isFamilyDecl :: TyClDecl name -> Bool

type family declaration

isHsDataDefn :: HsTyDefn name -> Bool

isHsSynDefn :: HsTyDefn name -> Bool

tcdName :: TyClDecl name -> name

famInstDeclName :: LFamInstDecl a -> a

countTyClDecls :: [TyClDecl name] -> (Int, Int, Int, Int, Int)

pprTyDefnFlavour :: HsTyDefn a -> SDoc

pprTyClDeclFlavour :: TyClDecl a -> SDoc

## Instance declarations

data InstDecl name

Constructors

ClsInstD |
Fields cid_poly_ty :: LHsType name cid_binds :: LHsBinds name cid_sigs :: [LSig name] cid_fam_insts :: [LFamInstDecl name]
FamInstD |
Fields lid_inst :: FamInstDecl name

Instances

Typeable1 InstDecl |
Data name => Data (InstDecl name) |
OutputableBndr name => Outputable (InstDecl name) |

type LInstDecl name = Located (InstDecl name)

data NewOrData

Constructors

NewType |
    newtype Blah ...
DataType |
    data Blah ...

Instances

Eq NewOrData |
Data NewOrData |
Typeable NewOrData |
Outputable NewOrData |

data FamilyFlavour

Constructors

TypeFamily |
    type family ...
DataFamily |
    data family ...

Instances

Data FamilyFlavour |
Typeable FamilyFlavour |

data FamInstDecl name

Constructors

FamInstDecl |
Fields fid_tycon :: Located name fid_pats :: HsWithBndrs [LHsType name] Type patterns (with kind and type bndrs) See Note [Family instance declaration binders] fid_defn :: HsTyDefn name fid_fvs :: NameSet

Instances

Typeable1 FamInstDecl |
Data name => Data (FamInstDecl name) |
OutputableBndr name => Outputable (FamInstDecl name) |

type LFamInstDecl name = Located (FamInstDecl name)

instDeclFamInsts :: [LInstDecl name] -> [FamInstDecl name]

## Standalone deriving declarations

data DerivDecl name

Constructors

DerivDecl |
Fields deriv_type :: LHsType name

Instances

Typeable1 DerivDecl |
Data name => Data (DerivDecl name) |
OutputableBndr name => Outputable (DerivDecl name) |

type LDerivDecl name = Located (DerivDecl name)

## `RULE` declarations

data RuleDecl name

Constructors

HsRule RuleName Activation [RuleBndr name] (Located (HsExpr name)) NameSet (Located (HsExpr name)) NameSet |

Instances

Typeable1 RuleDecl |
Data name => Data (RuleDecl name) |
OutputableBndr name => Outputable (RuleDecl name) |

type LRuleDecl name = Located (RuleDecl name)

data RuleBndr name

Constructors

RuleBndr (Located name) |
RuleBndrSig (Located name) (HsWithBndrs (LHsType name)) |

Instances

Typeable1 RuleBndr |
Data name => Data (RuleBndr name) |
OutputableBndr name => Outputable (RuleBndr name) |

collectRuleBndrSigTys :: [RuleBndr name] -> [HsWithBndrs (LHsType name)]

## `VECTORISE` declarations

data VectDecl name

Constructors

HsVect (Located name) (Maybe (LHsExpr name)) |
HsNoVect (Located name) |
HsVectTypeIn Bool (Located name) (Maybe (Located name)) |
HsVectTypeOut Bool TyCon (Maybe TyCon) |
HsVectClassIn (Located name) |
HsVectClassOut Class |
HsVectInstIn (LHsType name) |
HsVectInstOut ClsInst |

Instances

Typeable1 VectDecl |
Data name => Data (VectDecl name) |
OutputableBndr name => Outputable (VectDecl name) |

type LVectDecl name = Located (VectDecl name)

lvectDeclName :: NamedThing name => LVectDecl name -> Name

lvectInstDecl :: LVectDecl name -> Bool

## `default` declarations

data DefaultDecl name

Constructors

DefaultDecl [LHsType name] |

Instances

Typeable1 DefaultDecl |
Data name => Data (DefaultDecl name) |
OutputableBndr name => Outputable (DefaultDecl name) |

type LDefaultDecl name = Located (DefaultDecl name)

## Top-level template haskell splice

data SpliceDecl id

Constructors

SpliceDecl (Located (HsExpr id)) HsExplicitFlag |

Instances

Typeable1 SpliceDecl |
Data id => Data (SpliceDecl id) |
OutputableBndr name => Outputable (SpliceDecl name) |

## Foreign function interface declarations

data ForeignDecl name

Constructors

ForeignImport (Located name) (LHsType name) Coercion ForeignImport |
ForeignExport (Located name) (LHsType name) Coercion ForeignExport |

Instances

Typeable1 ForeignDecl |
Data name => Data (ForeignDecl name) |
OutputableBndr name => Outputable (ForeignDecl name) |

type LForeignDecl name = Located (ForeignDecl name)

data ForeignImport

Constructors

CImport CCallConv Safety (Maybe Header) CImportSpec |

Instances

Data ForeignImport |
Typeable ForeignImport |
Outputable ForeignImport |

data ForeignExport

Constructors

CExport CExportSpec |

Instances

Data ForeignExport |
Typeable ForeignExport |
Outputable ForeignExport |

noForeignImportCoercionYet :: Coercion

noForeignExportCoercionYet :: Coercion

data CImportSpec

Constructors

CLabel CLabelString |
CFunction CCallTarget |
CWrapper |

Instances

Data CImportSpec |
Typeable CImportSpec |

## Data-constructor declarations

data ConDecl name

Constructors

ConDecl |
Fields con_name :: Located name Constructor name. This is used for the DataCon itself, and for the user-callable wrapper Id. con_explicit :: HsExplicitFlag Is there an user-written forall? (cf. `HsForAllTy`) con_qvars :: LHsTyVarBndrs name Type variables. Depending on `con_res` this describes the following entities ResTyH98: the constructor's *existential* type variables - ResTyGADT: *all* the constructor's quantified type variables If con_explicit is Implicit, then con_qvars is irrelevant until after renaming. con_cxt :: LHsContext name The context. This does not include the "stupid theta" which lives only in the `TyData` decl. con_details :: HsConDeclDetails name The main payload con_res :: ResType (LHsType name) Result type of the constructor con_doc :: Maybe LHsDocString A possible Haddock comment. con_old_rec :: Bool TEMPORARY field; True = user has employed now-deprecated syntax for GADT-style record decl C { blah } :: T a b Remove this when we no longer parse this stuff, and hence do not need to report decprecated use

Instances

Typeable1 ConDecl |
Data name => Data (ConDecl name) |
OutputableBndr name => Outputable (ConDecl name) |

type LConDecl name = Located (ConDecl name)

data ResType ty

Constructors

ResTyH98 |
ResTyGADT ty |

Instances

Typeable1 ResType |
Data ty => Data (ResType ty) |
Outputable ty => Outputable (ResType ty) |

type HsConDeclDetails name = HsConDetails (LBangType name) [ConDeclField name]

hsConDeclArgTys :: HsConDeclDetails name -> [LBangType name]

## Document comments

data DocDecl

Constructors

DocCommentNext HsDocString |
DocCommentPrev HsDocString |
DocCommentNamed String HsDocString |
DocGroup Int HsDocString |

Instances

Data DocDecl |
Typeable DocDecl |
Outputable DocDecl |

type LDocDecl = Located DocDecl

docDeclDoc :: DocDecl -> HsDocString

## Deprecations

data WarnDecl name

Constructors

Warning name WarningTxt |

Instances

Typeable1 WarnDecl |
Data name => Data (WarnDecl name) |
OutputableBndr name => Outputable (WarnDecl name) |

type LWarnDecl name = Located (WarnDecl name)

## Annotations

data AnnDecl name

Constructors

HsAnnotation (AnnProvenance name) (Located (HsExpr name)) |

Instances

Typeable1 AnnDecl |
Data name => Data (AnnDecl name) |
OutputableBndr name => Outputable (AnnDecl name) |

type LAnnDecl name = Located (AnnDecl name)

data AnnProvenance name

Constructors

ValueAnnProvenance name |
TypeAnnProvenance name |
ModuleAnnProvenance |

Instances

Typeable1 AnnProvenance |
Data name => Data (AnnProvenance name) |

annProvenanceName_maybe :: AnnProvenance name -> Maybe name

modifyAnnProvenanceNameM :: Monad m => (before -> m after) -> AnnProvenance before -> m (AnnProvenance after)

# Grouping

data HsGroup id

A `HsDecl` is categorised into a `HsGroup` before being fed to the renamer.

Constructors

HsGroup |
Fields hs_valds :: HsValBinds id hs_tyclds :: [[LTyClDecl id]] hs_instds :: [LInstDecl id] hs_derivds :: [LDerivDecl id] hs_fixds :: [LFixitySig id] hs_defds :: [LDefaultDecl id] hs_fords :: [LForeignDecl id] hs_warnds :: [LWarnDecl id] hs_annds :: [LAnnDecl id] hs_ruleds :: [LRuleDecl id] hs_vects :: [LVectDecl id] hs_docs :: [LDocDecl]

Instances

Typeable1 HsGroup |
Data id => Data (HsGroup id) |
OutputableBndr name => Outputable (HsGroup name) |

emptyRdrGroup :: HsGroup a

emptyRnGroup :: HsGroup a

appendGroups :: HsGroup a -> HsGroup a -> HsGroup a