haskell-src-exts-0.4.8: Manipulating Haskell source: abstract syntax, lexer, parser, and pretty-printer

MaintainerNiklas 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 ExportSpec Source

Export specification.


EVar QName


EAbs QName

T: a class or datatype exported abstractly, or a type synonym.

EThingAll QName

T(..): a class exported with all of its methods, or a datatype exported with all of its constructors.

EThingWith QName [CName]

T(C_1,...,C_n): a class exported with some of its methods, or a datatype exported with some of its constructors.

EModuleContents ModuleName

module M: re-export a module.

data ImportDecl Source

Import declaration.




importLoc :: SrcLoc

position of the import keyword.

importModule :: ModuleName

name of the module imported.

importQualified :: Bool

imported qualified?

importSrc :: Bool

imported with {--}

importAs :: Maybe ModuleName

optional alias name in an as clause.

importSpecs :: Maybe (Bool, [ImportSpec])

optional list of import specifications. The Bool is True if the names are excluded by hiding.

data ImportSpec Source

Import specification.


IVar Name


IAbs Name

T: the name of a class, datatype or type synonym.

IThingAll Name

T(..): a class imported with all of its methods, or a datatype imported with all of its constructors.

IThingWith Name [CName]

T(C_1,...,C_n): a class imported with some of its methods, or a datatype imported with some of its constructors.

data Assoc Source

Associativity of an operator.



non-associative operator (declared with infix)


left-associative operator (declared with infixl).


right-associative operator (declared with infixr)


data Binds Source


BDecls [Decl] 
IPBinds [IPBind] 

data ConDecl Source

Declaration of a data constructor.


ConDecl Name [BangType]

ordinary data constructor

RecDecl Name [([Name], BangType)]

record constructor

data BangType 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

data Match Source

Clauses of a function binding.


Match SrcLoc Name [Pat] (Maybe Type) Rhs Binds 

data Rhs Source

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.


GuardedRhs SrcLoc [Stmt] Exp 

Class Assertions and Contexts

data FunDep Source

A functional dependency, given on the form l1 l2 ... ln -> r2 r3 .. rn


FunDep [Name] [Name] 

data Asst Source

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.


data Type Source

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

TyApp Type Type

application of a type constructor

TyVar Name

type variable

TyCon QName

named type or type constructor

TyPred Asst

assertion of an implicit parameter

TyInfix Type QName Type

infix type constructor

TyKind Type Kind

type with explicit kind signature

data Boxed Source




data Exp Source

Haskell expressions.


  • 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 InfixApps associated to the left.
  • The Language.Haskell.Exts.Pretty.Pretty instance for Exp does not add parentheses in printing.


Var QName


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 - exp

Lambda SrcLoc [Pat] Exp

lambda expression

Let Binds Exp

local declarations with let

If Exp Exp Exp

if exp then exp else exp

Case Exp [Alt]

case exp of alts

Do [Stmt]

do-expression: the last statement in the list should be an expression.

MDo [Stmt]


Tuple [Exp]

tuple expression

List [Exp]

list expression

Paren Exp

parenthesized expression

LeftSection Exp QOp

left section (exp qop)

RightSection QOp Exp

right section (qop exp)

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 [Stmt]

list comprehension

ExpTypeSig SrcLoc Exp Type

expression type signature Template Haskell

VarQuote QName


TypQuote QName


BracketExp Bracket 
SpliceExp Splice 
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) 
UnknownExpPragma String String 

data Stmt Source

This type represents both stmt in a do-expression, and qual in a list comprehension, as well as stmt in a pattern guard.


Generator SrcLoc Pat Exp

a generator pat <- exp

Qualifier Exp

an exp by itself: in a do-expression, an action whose result is discarded; in a list comprehension, a guard expression

LetStmt Binds

local bindings

data FieldUpdate Source

An fbind in a labeled construction or update.

data Alt Source

An alt in a case expression.

data GuardedAlt Source

A guarded alternative | stmt, ... , stmt -> exp.


GuardedAlt SrcLoc [Stmt] Exp 


data Pat Source

A pattern, to be matched against a value.


PVar Name


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



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

data PatField Source

An fpat in a labeled record pattern.


data Literal Source

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.


ModuleName String 

data QName Source

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

data Name Source

This type is used to represent variables, and also constructors.


Ident String

varid or conid.

Symbol String

varsym or consym

data QOp Source

Possibly qualified infix operators (qop), appearing in expressions.


QVarOp QName

variable operator (qvarop)

QConOp QName

constructor operator (qconop)

data Op Source

Operators, appearing in infix declarations.


VarOp Name

variable operator (varop)

ConOp Name

constructor operator (conop)


data SpecialCon Source

Constructors with special syntax. These names are never qualified, and always refer to builtin type or data constructors.



unit type and data constructor ()


list type constructor []


function type constructor ->

TupleCon Int

n-ary tuple type and data constructors (,) etc


list data constructor (:)

data CName Source

A name (cname) of a component of a class or data type in an import or export specification.


VarName Name

name of a method or field

ConName Name

name of a data constructor

data IPName Source

This type is used to represent implicit parameter names.


IPDup String 
IPLin String 

Template Haskell


data RPat Source

An entity in a regular pattern (HaRP)

data RPatOp Source

A regular pattern operator (HaRP)


data PXAttr Source

An XML attribute in an XML tag pattern


PXAttr XName Pat 



Builtin names


Main function of a program


Special identifiers

Type constructors

Source coordinates

data SrcLoc Source

A position in the source.