Language.Haskell.Exts.Annotated.Build

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

Copyright | (c) The GHC Team, 1997-2000, (c) Niklas Broberg 2004
License | BSD-style (see the file LICENSE.txt)
Maintainer | Niklas Broberg, d00nibro@chalmers.se
Stability | experimental
Portability | portable
Safe Haskell | Safe
Language | Haskell98

Language.Haskell.Exts.Annotated.Build

Contents

- Syntax building functions
- More advanced building

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

- name :: l -> String -> Name l
- sym :: l -> String -> Name l
- var :: l -> Name l -> Exp l
- op :: l -> Name l -> QOp l
- qvar :: l -> ModuleName l -> Name l -> Exp l
- pvar :: l -> Name l -> Pat l
- app :: l -> Exp l -> Exp l -> Exp l
- infixApp :: l -> Exp l -> QOp l -> Exp l -> Exp l
- appFun :: [l] -> Exp l -> [Exp l] -> Exp l
- pApp :: l -> Name l -> [Pat l] -> Pat l
- tuple :: l -> [Exp l] -> Exp l
- pTuple :: l -> [Pat l] -> Pat l
- varTuple :: l -> [Name l] -> Exp l
- pvarTuple :: l -> [Name l] -> Pat l
- function :: l -> String -> Exp l
- strE :: l -> String -> Exp l
- charE :: l -> Char -> Exp l
- intE :: l -> Integer -> Exp l
- strP :: l -> String -> Pat l
- charP :: l -> Char -> Pat l
- intP :: l -> Integer -> Pat l
- doE :: l -> [Stmt l] -> Exp l
- lamE :: l -> [Pat l] -> Exp l -> Exp l
- letE :: l -> [Decl l] -> Exp l -> Exp l
- caseE :: l -> Exp l -> [Alt l] -> Exp l
- alt :: l -> Pat l -> Exp l -> Alt l
- altGW :: l -> Pat l -> [Stmt l] -> Exp l -> Binds l -> Alt l
- listE :: l -> [Exp l] -> Exp l
- eList :: l -> Exp l
- peList :: l -> Pat l
- paren :: l -> Exp l -> Exp l
- pParen :: l -> Pat l -> Pat l
- qualStmt :: l -> Exp l -> Stmt l
- genStmt :: l -> Pat l -> Exp l -> Stmt l
- letStmt :: l -> [Decl l] -> Stmt l
- binds :: l -> [Decl l] -> Binds l
- noBinds :: l -> Binds l
- wildcard :: l -> Pat l
- genNames :: l -> String -> Int -> [Name l]
- sfun :: l -> Name l -> [Name l] -> Rhs l -> Maybe (Binds l) -> Decl l
- simpleFun :: l -> Name l -> Name l -> Exp l -> Decl l
- patBind :: l -> Pat l -> Exp l -> Decl l
- patBindWhere :: l -> Pat l -> Exp l -> [Decl l] -> Decl l
- nameBind :: l -> Name l -> Exp l -> Decl l
- metaFunction :: l -> String -> [Exp l] -> Exp l
- metaConPat :: l -> String -> [Pat l] -> Pat l

# Syntax building functions

name :: l -> String -> Name l

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

sym :: l -> String -> Name l

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

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

A local variable as expression.

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

Use the given identifier as an operator.

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

A qualified variable as expression.

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

A pattern variable.

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

Application of expressions by juxtaposition.

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

Apply an operator infix.

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

Apply a function to a list of arguments.

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

A constructor pattern, with argument patterns.

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

A tuple expression.

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

A tuple pattern.

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

A tuple expression consisting of variables only.

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

A tuple pattern consisting of variables only.

function :: l -> String -> Exp l

A function with a given name.

strE :: l -> String -> Exp l

A literal string expression.

charE :: l -> Char -> Exp l

A literal character expression.

intE :: l -> Integer -> Exp l

A literal integer expression.

strP :: l -> String -> Pat l

A literal string pattern.

charP :: l -> Char -> Pat l

A literal character pattern.

intP :: l -> Integer -> Pat l

A literal integer pattern.

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

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 l

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

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

A `let` ... `in` block.

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

A `case` expression.

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

An unguarded alternative in a `case` expression.

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

An alternative with a single guard in a `case` expression.

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

A list expression.

eList :: l -> Exp l

The empty list expression.

peList :: l -> Pat l

The empty list pattern.

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

Put parentheses around an expression.

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

Put parentheses around a pattern.

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

A qualifier expression statement.

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

A generator statement: pat `<-` exp

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

A `let` binding group as a statement.

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

Hoist a set of declarations to a binding group.

noBinds :: l -> Binds l

An empty binding group.

wildcard :: l -> Pat l

The wildcard pattern: `_`

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

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 l

A function with a single clause

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

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

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

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 l

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 l

Bind an identifier to an expression.

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

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

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

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