haskell-src- Manipulating Haskell source code





A suite of datatypes describing the abstract syntax of Haskell 98 http://www.haskell.org/onlinereport/ plus a few extensions:

  • multi-parameter type classes
  • parameters of type class assertions are unrestricted

This module has been changed so that show is a real show. For GHC, we also derive Typeable and Data for all types.



data HsExportSpec Source

Export specification.


HsEVar HsQName


HsEAbs HsQName

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

HsEThingAll HsQName

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

HsEThingWith HsQName [HsCName]

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

HsEModuleContents Module

module M: re-export a module.

data HsImportDecl Source

Import declaration.




importLoc :: SrcLoc

position of the import keyword.

importModule :: Module

name of the module imported.

importQualified :: Bool

imported qualified?

importAs :: Maybe Module

optional alias name in an as clause.

importSpecs :: Maybe (Bool, [HsImportSpec])

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

data HsImportSpec Source

Import specification.


HsIVar HsName


HsIAbs HsName

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

HsIThingAll HsName

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

HsIThingWith HsName [HsCName]

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

data HsAssoc Source

Associativity of an operator.



non-associative operator (declared with infix)


left-associative operator (declared with infixl).


right-associative operator (declared with infixr)


data HsConDecl Source

Declaration of a data constructor.


HsConDecl SrcLoc HsName [HsBangType]

ordinary data constructor

HsRecDecl SrcLoc HsName [([HsName], HsBangType)]

record constructor

data HsBangType Source

The type of a constructor argument or field, optionally including a strictness annotation.


HsBangedTy HsType

strict component, marked with "!"

HsUnBangedTy HsType

non-strict component

data HsMatch Source

Clauses of a function binding.

data HsRhs Source

The right hand side of a function or pattern binding.


HsUnGuardedRhs HsExp

unguarded right hand side (exp)

HsGuardedRhss [HsGuardedRhs]

guarded right hand side (gdrhs)

data HsGuardedRhs Source

A guarded right hand side | exp = exp. The first expression will be Boolean-valued.

data HsSafety Source

Safety level for invoking a foreign entity



call may generate callbacks


call will not generate callbacks

Class Assertions and Contexts

data HsQualType Source

A type qualified with a context. An unqualified type has an empty context.

type HsAsst = (HsQName, [HsType])Source

Class assertions. In Haskell 98, the argument would be a tyvar, but this definition allows multiple parameters, and allows them to be types.


data HsType Source

Haskell types and type constructors.


HsTyFun HsType HsType

function type

HsTyTuple [HsType]

tuple type

HsTyApp HsType HsType

application of a type constructor

HsTyVar HsName

type variable

HsTyCon HsQName

named type or type constructor


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


HsVar HsQName


HsCon HsQName

data constructor

HsLit HsLiteral

literal constant

HsInfixApp HsExp HsQOp HsExp

infix application

HsApp HsExp HsExp

ordinary application

HsNegApp HsExp

negation expression - exp

HsLambda SrcLoc [HsPat] HsExp

lambda expression

HsLet [HsDecl] HsExp

local declarations with let

HsIf HsExp HsExp HsExp

if exp then exp else exp

HsCase HsExp [HsAlt]

case exp of alts

HsDo [HsStmt]

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

HsTuple [HsExp]

tuple expression

HsList [HsExp]

list expression

HsParen HsExp

parenthesized expression

HsLeftSection HsExp HsQOp

left section (exp qop)

HsRightSection HsQOp HsExp

right section (qop exp)

HsRecConstr HsQName [HsFieldUpdate]

record construction expression

HsRecUpdate HsExp [HsFieldUpdate]

record update expression

HsEnumFrom HsExp

unbounded arithmetic sequence, incrementing by 1

HsEnumFromTo HsExp HsExp

bounded arithmetic sequence, incrementing by 1

HsEnumFromThen HsExp HsExp

unbounded arithmetic sequence, with first two elements given

HsEnumFromThenTo HsExp HsExp HsExp

bounded arithmetic sequence, with first two elements given

HsListComp HsExp [HsStmt]

list comprehension

HsExpTypeSig SrcLoc HsExp HsQualType

expression type signature

HsAsPat HsName HsExp

patterns only


patterns only

HsIrrPat HsExp

patterns only

data HsStmt Source

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


HsGenerator SrcLoc HsPat HsExp

a generator pat <- exp

HsQualifier HsExp

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

HsLetStmt [HsDecl]

local bindings

data HsFieldUpdate Source

An fbind in a labeled record construction or update expression.

data HsAlt Source

An alt in a case expression.

data HsGuardedAlt Source

A guarded alternative | exp -> exp. The first expression will be Boolean-valued.


data HsPat Source

A pattern, to be matched against a value.


HsPVar HsName


HsPLit HsLiteral

literal constant

HsPNeg HsPat

negated pattern

HsPInfixApp HsPat HsQName HsPat

pattern with infix data constructor

HsPApp HsQName [HsPat]

data constructor and argument patterns

HsPTuple [HsPat]

tuple pattern

HsPList [HsPat]

list pattern

HsPParen HsPat

parenthesized pattern

HsPRec HsQName [HsPatField]

labelled pattern

HsPAsPat HsName HsPat



wildcard pattern (_)

HsPIrrPat HsPat

irrefutable pattern (~)

data HsPatField Source

An fpat in a labeled record pattern.


HsPFieldPat HsQName HsPat 


data HsLiteral 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.


HsChar Char

character literal

HsString String

string literal

HsInt Integer

integer literal

HsFrac Rational

floating point literal

HsCharPrim Char

GHC unboxed character literal

HsStringPrim String

GHC unboxed string literal

HsIntPrim Integer

GHC unboxed integer literal

HsFloatPrim Rational

GHC unboxed float literal

HsDoublePrim Rational

GHC unboxed double literal

Variables, Constructors and Operators

newtype Module Source

The name of a Haskell module.


Module String 

data HsQName Source

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


Qual Module HsName

name qualified with a module name

UnQual HsName

unqualified name

Special HsSpecialCon

built-in constructor with special syntax

data HsName Source

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


HsIdent String

varid or conid

HsSymbol String

varsym or consym

data HsQOp Source

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


HsQVarOp HsQName

variable operator (qvarop)

HsQConOp HsQName

constructor operator (qconop)

data HsOp Source

Operators, appearing in infix declarations.


HsVarOp HsName

variable operator (varop)

HsConOp HsName

constructor operator (conop)

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

HsTupleCon Int

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


list data constructor (:)

data HsCName Source

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


HsVarName HsName

name of a method or field

HsConName HsName

name of a data constructor

Builtin names


Main function of a program


Type constructors

Source coordinates

data SrcLoc Source

A position in the source.