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

Portabilityportable
Stabilityexperimental
MaintainerNiklas Broberg, d00nibro@chalmers.se
Safe HaskellSafe-Inferred

Language.Haskell.Exts.Annotated.Build

Contents

Description

This module contains combinators to use when building Haskell source trees programmatically, as opposed to parsing them from a string. The contents here are quite experimental and will likely receive a lot of attention when the rest has stabilised.

Synopsis

Syntax building functions

name :: l -> String -> Name lSource

An identifier with the given string as its name. The string should be a valid Haskell identifier.

sym :: l -> String -> Name lSource

A symbol identifier. The string should be a valid Haskell symbol identifier.

var :: l -> Name l -> Exp lSource

A local variable as expression.

op :: l -> Name l -> QOp lSource

Use the given identifier as an operator.

qvar :: l -> ModuleName l -> Name l -> Exp lSource

A qualified variable as expression.

pvar :: l -> Name l -> Pat lSource

A pattern variable.

app :: l -> Exp l -> Exp l -> Exp lSource

Application of expressions by juxtaposition.

infixApp :: l -> Exp l -> QOp l -> Exp l -> Exp lSource

Apply an operator infix.

appFun :: [l] -> Exp l -> [Exp l] -> Exp lSource

Apply a function to a list of arguments.

pApp :: l -> Name l -> [Pat l] -> Pat lSource

A constructor pattern, with argument patterns.

tuple :: l -> [Exp l] -> Exp lSource

A tuple expression.

pTuple :: l -> [Pat l] -> Pat lSource

A tuple pattern.

varTuple :: l -> [Name l] -> Exp lSource

A tuple expression consisting of variables only.

pvarTuple :: l -> [Name l] -> Pat lSource

A tuple pattern consisting of variables only.

function :: l -> String -> Exp lSource

A function with a given name.

strE :: l -> String -> Exp lSource

A literal string expression.

charE :: l -> Char -> Exp lSource

A literal character expression.

intE :: l -> Integer -> Exp lSource

A literal integer expression.

strP :: l -> String -> Pat lSource

A literal string pattern.

charP :: l -> Char -> Pat lSource

A literal character pattern.

intP :: l -> Integer -> Pat lSource

A literal integer pattern.

doE :: l -> [Stmt l] -> Exp lSource

A do block formed by the given statements. The last statement in the list should be a Qualifier expression.

lamE :: l -> [Pat l] -> Exp l -> Exp lSource

Lambda abstraction, given a list of argument patterns and an expression body.

letE :: l -> [Decl l] -> Exp l -> Exp lSource

A let ... in block.

caseE :: l -> Exp l -> [Alt l] -> Exp lSource

A case expression.

alt :: l -> Pat l -> Exp l -> Alt lSource

An unguarded alternative in a case expression.

altGW :: l -> Pat l -> [Stmt l] -> Exp l -> Binds l -> Alt lSource

An alternative with a single guard in a case expression.

listE :: l -> [Exp l] -> Exp lSource

A list expression.

eList :: l -> Exp lSource

The empty list expression.

peList :: l -> Pat lSource

The empty list pattern.

paren :: l -> Exp l -> Exp lSource

Put parentheses around an expression.

pParen :: l -> Pat l -> Pat lSource

Put parentheses around a pattern.

qualStmt :: l -> Exp l -> Stmt lSource

A qualifier expression statement.

genStmt :: l -> Pat l -> Exp l -> Stmt lSource

A generator statement: pat <- exp

letStmt :: l -> [Decl l] -> Stmt lSource

A let binding group as a statement.

binds :: l -> [Decl l] -> Binds lSource

Hoist a set of declarations to a binding group.

noBinds :: l -> Binds lSource

An empty binding group.

wildcard :: l -> Pat lSource

The wildcard pattern: _

genNames :: l -> String -> Int -> [Name l]Source

Generate k names by appending numbers 1 through k to a given string.

More advanced building

sfun :: l -> Name l -> [Name l] -> Rhs l -> Maybe (Binds l) -> Decl lSource

A function with a single clause

simpleFun :: l -> Name l -> Name l -> Exp l -> Decl lSource

A function with a single clause, a single argument, no guards and no where declarations

patBind :: l -> Pat l -> Exp l -> Decl lSource

A pattern bind where the pattern is a variable, and where there are no guards and no 'where' clause.

patBindWhere :: l -> Pat l -> Exp l -> [Decl l] -> Decl lSource

A pattern bind where the pattern is a variable, and where there are no guards, but with a 'where' clause.

nameBind :: l -> Name l -> Exp l -> Decl lSource

Bind an identifier to an expression.

metaFunction :: l -> String -> [Exp l] -> Exp lSource

Apply function of a given name to a list of arguments.

metaConPat :: l -> String -> [Pat l] -> Pat lSource

Apply a constructor of a given name to a list of pattern arguments, forming a constructor pattern.