Portability | portable |
---|---|
Stability | experimental |
Maintainer | Niklas Broberg, d00nibro@dtek.chalmers.se |
A suite of datatypes describing the abstract syntax of Haskell 98 http://www.haskell.org/onlinereport/ plus some extensions:
- multi-parameter type classes with functional dependencies
- parameters of type class assertions are unrestricted
-
forall
types as universal and existential quantification - pattern guards
- implicit parameters
- generalised algebraic data types
- template haskell
- empty data type declarations
- unboxed tuples
- regular patterns (HaRP)
- HSP-style XML expressions and patterns (HSP)
Also worth noting is that (n+k) patterns from Haskell 98 are not supported
- data Module = Module SrcLoc ModuleName [OptionPragma] (Maybe WarningText) (Maybe [ExportSpec]) [ImportDecl] [Decl]
- data ExportSpec
- = EVar QName
- | EAbs QName
- | EThingAll QName
- | EThingWith QName [CName]
- | EModuleContents ModuleName
- data ImportDecl = ImportDecl {
- importLoc :: SrcLoc
- importModule :: ModuleName
- importQualified :: Bool
- importSrc :: Bool
- importPkg :: Maybe String
- importAs :: Maybe ModuleName
- importSpecs :: Maybe (Bool, [ImportSpec])
- data ImportSpec
- data Assoc
- = AssocNone
- | AssocLeft
- | AssocRight
- data Decl
- = TypeDecl SrcLoc Name [TyVarBind] Type
- | DataDecl SrcLoc DataOrNew Context Name [TyVarBind] [QualConDecl] [Deriving]
- | GDataDecl SrcLoc DataOrNew Context Name [TyVarBind] (Maybe Kind) [GadtDecl] [Deriving]
- | TypeFamDecl SrcLoc Name [TyVarBind] (Maybe Kind)
- | DataFamDecl SrcLoc Context Name [TyVarBind] (Maybe Kind)
- | TypeInsDecl SrcLoc Type Type
- | DataInsDecl SrcLoc DataOrNew Type [QualConDecl] [Deriving]
- | GDataInsDecl SrcLoc DataOrNew Type (Maybe Kind) [GadtDecl] [Deriving]
- | InfixDecl SrcLoc Assoc Int [Op]
- | ClassDecl SrcLoc Context Name [TyVarBind] [FunDep] [ClassDecl]
- | InstDecl SrcLoc Context QName [Type] [InstDecl]
- | DerivDecl SrcLoc Context QName [Type]
- | DefaultDecl SrcLoc [Type]
- | SpliceDecl SrcLoc Splice
- | TypeSig SrcLoc [Name] Type
- | FunBind [Match]
- | PatBind SrcLoc Pat (Maybe Type) Rhs Binds
- | ForImp SrcLoc CallConv Safety String Name Type
- | ForExp SrcLoc CallConv String Name Type
- | RulePragmaDecl SrcLoc [Rule]
- | DeprPragmaDecl SrcLoc [([Name], String)]
- | WarnPragmaDecl SrcLoc [([Name], String)]
- | InlineSig SrcLoc Bool Activation QName
- | SpecSig SrcLoc QName [Type]
- | SpecInlineSig SrcLoc Bool Activation QName [Type]
- | InstSig SrcLoc Context QName [Type]
- data Binds
- data IPBind = IPBind SrcLoc IPName Exp
- data ClassDecl
- data InstDecl
- type Deriving = (QName, [Type])
- data GadtDecl = GadtDecl SrcLoc Name Type
- data ConDecl
- data QualConDecl = QualConDecl SrcLoc [TyVarBind] Context ConDecl
- data BangType
- = BangedTy Type
- | UnBangedTy Type
- | UnpackedTy Type
- data Match = Match SrcLoc Name [Pat] (Maybe Type) Rhs Binds
- data Rhs
- = UnGuardedRhs Exp
- | GuardedRhss [GuardedRhs]
- data GuardedRhs = GuardedRhs SrcLoc [Stmt] Exp
- data DataOrNew
- type Context = [Asst]
- data FunDep = FunDep [Name] [Name]
- data Asst
- data Type
- data Boxed
- data Kind
- data TyVarBind
- = KindedVar Name Kind
- | UnkindedVar Name
- data Exp
- = Var QName
- | IPVar IPName
- | Con QName
- | Lit Literal
- | InfixApp Exp QOp Exp
- | App Exp Exp
- | NegApp Exp
- | Lambda SrcLoc [Pat] Exp
- | Let Binds Exp
- | If Exp Exp Exp
- | Case Exp [Alt]
- | Do [Stmt]
- | MDo [Stmt]
- | Tuple [Exp]
- | List [Exp]
- | Paren Exp
- | LeftSection Exp QOp
- | RightSection QOp Exp
- | RecConstr QName [FieldUpdate]
- | RecUpdate Exp [FieldUpdate]
- | EnumFrom Exp
- | EnumFromTo Exp Exp
- | EnumFromThen Exp Exp
- | EnumFromThenTo Exp Exp Exp
- | ListComp Exp [QualStmt]
- | ParComp Exp [[QualStmt]]
- | ExpTypeSig SrcLoc Exp Type
- | VarQuote QName
- | TypQuote QName
- | BracketExp Bracket
- | SpliceExp Splice
- | QuasiQuote String String
- | XTag SrcLoc XName [XAttr] (Maybe Exp) [Exp]
- | XETag SrcLoc XName [XAttr] (Maybe Exp)
- | XPcdata String
- | XExpTag Exp
- | CorePragma String
- | SCCPragma String
- | GenPragma String (Int, Int) (Int, Int)
- | Proc Pat Exp
- | LeftArrApp Exp Exp
- | RightArrApp Exp Exp
- | LeftArrHighApp Exp Exp
- | RightArrHighApp Exp Exp
- data Stmt
- data QualStmt
- data FieldUpdate
- = FieldUpdate QName Exp
- | FieldPun Name
- | FieldWildcard
- data Alt = Alt SrcLoc Pat GuardedAlts Binds
- data GuardedAlts
- = UnGuardedAlt Exp
- | GuardedAlts [GuardedAlt]
- data GuardedAlt = GuardedAlt SrcLoc [Stmt] Exp
- data Pat
- = PVar Name
- | PLit Literal
- | PNeg Pat
- | PNPlusK Name Integer
- | PInfixApp Pat QName Pat
- | PApp QName [Pat]
- | PTuple [Pat]
- | PList [Pat]
- | PParen Pat
- | PRec QName [PatField]
- | PAsPat Name Pat
- | PWildCard
- | PIrrPat Pat
- | PatTypeSig SrcLoc Pat Type
- | PViewPat Exp Pat
- | PRPat [RPat]
- | PXTag SrcLoc XName [PXAttr] (Maybe Pat) [Pat]
- | PXETag SrcLoc XName [PXAttr] (Maybe Pat)
- | PXPcdata String
- | PXPatTag Pat
- | PXRPats [RPat]
- | PExplTypeArg QName Type
- | PQuasiQuote String String
- | PBangPat Pat
- data PatField
- data Literal
- newtype ModuleName = ModuleName String
- data QName
- = Qual ModuleName Name
- | UnQual Name
- | Special SpecialCon
- data Name
- data QOp
- data Op
- data SpecialCon
- data CName
- data IPName
- data Bracket
- = ExpBracket Exp
- | PatBracket Pat
- | TypeBracket Type
- | DeclBracket [Decl]
- data Splice
- = IdSplice String
- | ParenSplice Exp
- data RPat
- data RPatOp
- data XAttr = XAttr XName Exp
- data XName
- data PXAttr = PXAttr XName Pat
- data Safety
- data CallConv
- data OptionPragma
- data Tool
- data WarningText
- data Rule = Rule String Activation (Maybe [RuleVar]) Exp Exp
- data RuleVar
- = RuleVar Name
- | TypedRuleVar Name Type
- data Activation
- = AlwaysActive
- | ActiveFrom Int
- | ActiveUntil Int
- prelude_mod :: ModuleName
- main_mod :: ModuleName
- main_name :: Name
- unit_con_name :: QName
- tuple_con_name :: Boxed -> Int -> QName
- list_cons_name :: QName
- unboxed_singleton_con_name :: QName
- unit_con :: Exp
- tuple_con :: Boxed -> Int -> Exp
- unboxed_singleton_con :: Exp
- as_name :: Name
- qualified_name :: Name
- hiding_name :: Name
- minus_name :: Name
- bang_name :: Name
- dot_name :: Name
- star_name :: Name
- export_name :: Name
- safe_name :: Name
- unsafe_name :: Name
- threadsafe_name :: Name
- stdcall_name :: Name
- ccall_name :: Name
- unit_tycon_name :: QName
- fun_tycon_name :: QName
- list_tycon_name :: QName
- tuple_tycon_name :: Boxed -> Int -> QName
- unboxed_singleton_tycon_name :: QName
- unit_tycon :: Type
- fun_tycon :: Type
- list_tycon :: Type
- tuple_tycon :: Boxed -> Int -> Type
- unboxed_singleton_tycon :: Type
- data SrcLoc = SrcLoc {}
Modules
A Haskell source module.
Module SrcLoc ModuleName [OptionPragma] (Maybe WarningText) (Maybe [ExportSpec]) [ImportDecl] [Decl] |
data ExportSpec Source
Export specification.
EVar QName | variable |
EAbs QName |
|
EThingAll QName |
|
EThingWith QName [CName] |
|
EModuleContents ModuleName |
|
data ImportDecl Source
Import declaration.
ImportDecl | |
|
data ImportSpec Source
Import specification.
IVar Name | variable |
IAbs Name |
|
IThingAll Name |
|
IThingWith Name [CName] |
|
Associativity of an operator.
AssocNone | non-associative operator (declared with |
AssocLeft | left-associative operator (declared with |
AssocRight | right-associative operator (declared with |
Declarations
Declarations inside a class declaration
Declarations inside an instance declaration
Declaration of a data constructor.
data QualConDecl Source
The type of a constructor argument or field, optionally including a strictness annotation.
BangedTy Type | strict component, marked with " |
UnBangedTy Type | non-strict component |
UnpackedTy Type | unboxed component |
Clauses of a function binding.
The right hand side of a function or pattern binding.
UnGuardedRhs Exp | unguarded right hand side (exp) |
GuardedRhss [GuardedRhs] | guarded right hand side (gdrhs) |
data GuardedRhs Source
A guarded right hand side |
exp =
exp.
The first expression will be Boolean-valued.
Class Assertions and Contexts
A functional dependency, given on the form l1 l2 ... ln -> r2 r3 .. rn
Class assertions. In Haskell 98, the argument would be a tyvar, but this definition allows multiple parameters, and allows them to be types. Also extended with support for implicit parameters and equality constraints.
Types
A type qualified with a context. An unqualified type has an empty context.
TyForall (Maybe [TyVarBind]) Context Type | |
TyFun Type Type | function type |
TyTuple Boxed [Type] | tuple type, possibly boxed |
TyList Type | list syntax, e.g. [a], as opposed to [] a |
TyApp Type Type | application of a type constructor |
TyVar Name | type variable |
TyCon QName | named type or type constructor |
TyParen Type | type surrounded by parentheses | TyPred Asst -- ^ assertion of an implicit parameter |
TyInfix Type QName Type | infix type constructor |
TyKind Type Kind | type with explicit kind signature |
Expressions
Haskell expressions.
Notes:
- Because it is difficult for parsers to distinguish patterns from expressions, they typically parse them in the same way and then check that they have the appropriate form. Hence the expression type includes some forms that are found only in patterns. After these checks, these constructors should not be used.
- The parser does not take precedence and associativity into account,
so it will leave
InfixApp
s associated to the left. - The
Language.Haskell.Exts.Pretty.Pretty
instance forExp
does not add parentheses in printing.
Var QName | variable |
IPVar IPName | implicit parameter variable |
Con QName | data constructor |
Lit Literal | literal constant |
InfixApp Exp QOp Exp | infix application |
App Exp Exp | ordinary application |
NegApp Exp | negation expression |
Lambda SrcLoc [Pat] Exp | lambda expression |
Let Binds Exp | local declarations with |
If Exp Exp Exp |
|
Case Exp [Alt] |
|
Do [Stmt] |
|
MDo [Stmt] |
|
Tuple [Exp] | tuple expression |
List [Exp] | list expression |
Paren Exp | parenthesized expression |
LeftSection Exp QOp | left section |
RightSection QOp Exp | right section |
RecConstr QName [FieldUpdate] | record construction expression |
RecUpdate Exp [FieldUpdate] | record update expression |
EnumFrom Exp | unbounded arithmetic sequence, incrementing by 1 |
EnumFromTo Exp Exp | bounded arithmetic sequence, incrementing by 1 |
EnumFromThen Exp Exp | unbounded arithmetic sequence, with first two elements given |
EnumFromThenTo Exp Exp Exp | bounded arithmetic sequence, with first two elements given |
ListComp Exp [QualStmt] | list comprehension |
ParComp Exp [[QualStmt]] | parallel list comprehension |
ExpTypeSig SrcLoc Exp Type | expression type signature Template Haskell |
VarQuote QName | 'x |
TypQuote QName | ''T |
BracketExp Bracket | |
SpliceExp Splice | |
QuasiQuote String String |
|
XTag SrcLoc XName [XAttr] (Maybe Exp) [Exp] | |
XETag SrcLoc XName [XAttr] (Maybe Exp) | |
XPcdata String | |
XExpTag Exp | |
CorePragma String | |
SCCPragma String | |
GenPragma String (Int, Int) (Int, Int) | |
Proc Pat Exp |
|
LeftArrApp Exp Exp | exp |
RightArrApp Exp Exp | exp |
LeftArrHighApp Exp Exp | exp |
RightArrHighApp Exp Exp | exp |
This type represents both stmt in a do
-expression,
and qual in a list comprehension, as well as stmt
in a pattern guard.
This type represents a qual in a list comprehension, which could potentially be a transform of the kind enabled by TransformListComp.
data FieldUpdate Source
An fbind in a labeled construction or update.
An alt in a case
expression.
data GuardedAlts Source
UnGuardedAlt Exp |
|
GuardedAlts [GuardedAlt] | gdpat |
data GuardedAlt Source
A guarded alternative |
stmt, ... , stmt ->
exp.
Patterns
A pattern, to be matched against a value.
PVar Name | variable |
PLit Literal | literal constant |
PNeg Pat | negated pattern |
PNPlusK Name Integer | n+k pattern |
PInfixApp Pat QName Pat | pattern with infix data constructor |
PApp QName [Pat] | data constructor and argument patterns |
PTuple [Pat] | tuple pattern |
PList [Pat] | list pattern |
PParen Pat | parenthesized pattern |
PRec QName [PatField] | labelled pattern |
PAsPat Name Pat |
|
PWildCard | wildcard pattern ( |
PIrrPat Pat | irrefutable pattern ( |
PatTypeSig SrcLoc Pat Type | pattern type signature |
PViewPat Exp Pat | view patterns of the form (e -> p) HaRP |
PRPat [RPat] | regular pattern (HaRP) Hsx |
PXTag SrcLoc XName [PXAttr] (Maybe Pat) [Pat] | XML tag pattern |
PXETag SrcLoc XName [PXAttr] (Maybe Pat) | XML singleton tag pattern |
PXPcdata String | XML PCDATA pattern |
PXPatTag Pat | XML embedded pattern |
PXRPats [RPat] | XML regular list pattern |
PExplTypeArg QName Type | Explicit type argument e.g. f {| Int |} x = ... |
PQuasiQuote String String |
|
PBangPat Pat | f !x = ... |
An fpat in a labeled record pattern.
Literals
literal
Values of this type hold the abstract value of the literal, not the
precise string representation used. For example, 10
, 0o12
and 0xa
have the same representation.
Char Char | character literal |
String String | string literal |
Int Integer | integer literal |
Frac Rational | floating point literal |
PrimInt Integer | GHC unboxed integer literal |
PrimWord Integer | GHC unboxed word literal |
PrimFloat Rational | GHC unboxed float literal |
PrimDouble Rational | GHC unboxed double literal |
PrimChar Char | GHC unboxed character literal |
PrimString String | GHC unboxed string literal |
Variables, Constructors and Operators
newtype ModuleName Source
The name of a Haskell module.
This type is used to represent qualified variables, and also qualified constructors.
Qual ModuleName Name | name qualified with a module name |
UnQual Name | unqualified name |
Special SpecialCon | built-in constructor with special syntax |
This type is used to represent variables, and also constructors.
Possibly qualified infix operators (qop), appearing in expressions.
Operators, appearing in infix
declarations.
data SpecialCon Source
Constructors with special syntax. These names are never qualified, and always refer to builtin type or data constructors.
A name (cname) of a component of a class or data type in an import
or export specification.
This type is used to represent implicit parameter names.
Template Haskell
HaRP
An entity in a regular pattern (HaRP)
A regular pattern operator (HaRP)
Hsx
An XML attribute in an XML tag pattern
FFI
Pragmas
data OptionPragma Source
data WarningText Source
data Activation Source
Builtin names
Modules
Main function of a program
Constructors
tuple_con_name :: Boxed -> Int -> QNameSource
Special identifiers
Type constructors
tuple_tycon_name :: Boxed -> Int -> QNameSource
tuple_tycon :: Boxed -> Int -> TypeSource