haskell-tools-rewrite-1.1.1.0: Facilities for generating new parts of the Haskell-Tools AST

Safe HaskellNone
LanguageHaskell2010

Language.Haskell.Tools.Rewrite.Create.Exprs

Contents

Description

Generation of expression-level AST fragments for refactorings. The bindings defined here create a the annotated version of the AST constructor with the same name. For example, mkApp creates the annotated version of the App AST constructor.

Synopsis

Expressions

mkVar :: Name -> Expr Source #

Create a expression for a variable or a data constructor ( a )

mkLit :: Literal -> Expr Source #

Create a literal expression ( 42 )

mkInfixApp :: Expr -> Operator -> Expr -> Expr Source #

Create a infix operator application expression ( a + b )

mkPrefixApp :: Operator -> Expr -> Expr Source #

Create a prefix operator application expression ( -x )

mkApp :: Expr -> Expr -> Expr Source #

Create a function application expression ( f 4 )

mkLambda :: [Pattern] -> Expr -> Expr Source #

Create a lambda expression ( \a b -> a + b )

mkLet :: [LocalBind] -> Expr -> Expr Source #

Create a local binding ( let x = 2; y = 3 in e x y )

mkIf :: Expr -> Expr -> Expr -> Expr Source #

Create a if expression ( if a then b else c )

mkMultiIf :: [GuardedCaseRhs] -> Expr Source #

Create a multi way if expressions with MultiWayIf extension ( if | guard1 -> expr1; guard2 -> expr2 )

mkCase :: Expr -> [Alt] -> Expr Source #

Create a pattern matching expression ( case expr of pat1 -> expr1; pat2 -> expr2 )

mkDoBlock :: [Stmt] -> Expr Source #

Create a do-notation expressions ( do x <- act1; act2 )

mkMDoBlock :: [Stmt] -> Expr Source #

Create a mdo-notation expressions ( mdo x <- act1; act2 )

mkTuple :: [Expr] -> Expr Source #

Create a tuple expression ( (e1, e2, e3) )

mkUnboxedTuple :: [Expr] -> Expr Source #

Create a unboxed tuple expression ( (# e1, e2, e3 #) )

mkTupleSection :: [Maybe Expr] -> Expr Source #

Create a tuple section, enabled with TupleSections ( (a,,b) ). One of the elements must be missing.

mkTupleUnboxedSection :: [Maybe Expr] -> Expr Source #

Create a unboxed tuple section, enabled with TupleSections ( (#a,,b#) ). One of the elements must be missing.

mkList :: [Expr] -> Expr Source #

Create a list expression: [1,2,3]

mkParArray :: [Expr] -> Expr Source #

Create a parallel array expression: [: 1,2,3 :]

mkParen :: Expr -> Expr Source #

Create a parenthesized expression: ( a + b )

mkLeftSection :: Expr -> Operator -> Expr Source #

Create a left operator section: (1+)

mkRightSection :: Operator -> Expr -> Expr Source #

Create a right operator section: (+1)

mkRecCon :: Name -> [FieldUpdate] -> Expr Source #

Create a record value construction: Point { x = 3, y = -2 }

mkRecUpdate :: Expr -> [FieldUpdate] -> Expr Source #

Create a record value update: p1 { x = 3, y = -2 }

mkEnum :: Expr -> Maybe Expr -> Maybe Expr -> Expr Source #

Create a enumeration expression ( [1,3..10] )

mkParArrayEnum :: Expr -> Maybe Expr -> Expr -> Expr Source #

Create a parallel array enumeration ( [: 1,3 .. 10 :] )

mkListComp :: Expr -> [ListCompBody] -> Expr Source #

Create a list comprehension ( [ (x, y) | x <- xs | y <- ys ] )

mkParArrayComp :: Expr -> [ListCompBody] -> Expr Source #

Create a parallel array comprehensions [: (x, y) | x <- xs , y <- ys :] enabled by ParallelArrays

mkExprTypeSig :: Expr -> Type -> Expr Source #

Create a explicit type signature ( x :: Int )

mkExplicitTypeApp :: Expr -> Type -> Expr Source #

Create a explicit type application ( show @Integer (read "5") )

mkVarQuote :: Name -> Expr Source #

'x for template haskell reifying of expressions

mkTypeQuote :: Name -> Expr Source #

''T for template haskell reifying of types

mkBracketExpr :: Bracket -> Expr Source #

Create a template haskell bracket expression

mkSpliceExpr :: Splice -> Expr Source #

Create a template haskell splice expression, for example: $(gen a) or $x

mkQuasiQuoteExpr :: QuasiQuote -> Expr Source #

Create a template haskell quasi quote expression, for example: [quoter| a + b ]

mkExprPragma :: ExprPragma -> Expr -> Expr Source #

Creates a pragma that marks an expression.

mkProcExpr :: Pattern -> Cmd -> Expr Source #

Create a arrow definition: proc a -> f -< a+1

mkArrowApp :: Expr -> ArrowApp -> Expr -> Expr Source #

Create a arrow definition: proc a -> f -< a+1

mkLambdaCase :: [Alt] -> Expr Source #

Create a lambda case ( case 0 -> 1; 1 -> 2 )

mkStaticPointer :: Expr -> Expr Source #

Create a static pointer expression ( static e ). The inner expression must be closed (cannot have variables bound outside)

Field updates

mkFieldUpdate :: Name -> Expr -> FieldUpdate Source #

Create a update of a field ( x = 1 )

mkFieldPun :: Name -> FieldUpdate Source #

Create a update the field to the value of the same name ( x )

mkFieldWildcard :: FieldUpdate Source #

Create a update the fields of the bounded names to their values ( .. ). Must be the last initializer. Cannot be used in a record update expression.

Pattern matching and guards

mkAlt :: Pattern -> CaseRhs -> Maybe LocalBinds -> Alt Source #

Create a clause of case expression ( Just x -> x + 1 )

mkCaseRhs :: Expr -> CaseRhs Source #

Create a unguarded right-hand side a pattern match ( -> 3 )

mkGuardedCaseRhss :: [GuardedCaseRhs] -> CaseRhs Source #

Create a guarded right-hand sides of a pattern match ( | x == 1 -> 3; | otherwise -> 4 )

mkGuardedCaseRhs :: [RhsGuard] -> Expr -> GuardedCaseRhs Source #

Creates a guarded right-hand side of pattern matches binding ( | x > 3 -> 2 )

Pragmas that can be applied to expressions

mkCorePragma :: String -> ExprPragma Source #

Creates a CORE pragma for adding notes to expressions.

mkSccPragma :: String -> ExprPragma Source #

Creates an SCC pragma for defining cost centers for profiling

mkGeneratedPragma :: SourceRange -> ExprPragma Source #

Creates a pragma that describes if an expression was generated from a code fragment by an external tool ( {-# GENERATED "Happy.y" 1:15-1:25 #-} )

mkSourceRange :: String -> Integer -> Integer -> Integer -> Integer -> SourceRange Source #

Create a in-AST source ranges (for generated pragmas)

Commands

mkArrowAppCmd :: Expr -> ArrowApp -> Expr -> Cmd Source #

An arrow application command ( f -< x + 1 )

mkArrowFromCmd :: Expr -> [Cmd] -> Cmd Source #

A form command ( (|untilA (increment -< x+y) (within 0.5 -< x)|) )

mkAppCmd :: Cmd -> Expr -> Cmd Source #

A function application command

mkInfixCmd :: Cmd -> Name -> Cmd -> Cmd Source #

An infix command application

mkLambdaCmd :: [Pattern] -> Cmd -> Cmd Source #

A lambda command

mkParenCmd :: Cmd -> Cmd Source #

A parenthesized command

mkCaseCmd :: Expr -> [CmdAlt] -> Cmd Source #

A pattern match command

mkIfCmd :: Expr -> Cmd -> Cmd -> Cmd Source #

An if command ( if f x y then g -< x+1 else h -< y+2 )

mkLetCmd :: [LocalBind] -> Cmd -> Cmd Source #

A local binding command ( let z = x+y )

mkDoCmd :: [CmdStmt] -> Cmd Source #

A do-notation in a command

mkLeftAppl :: ArrowApp Source #

Left arrow application: -<

mkRightAppl :: ArrowApp Source #

Right arrow application: >-

mkLeftHighAppl :: ArrowApp Source #

Left arrow high application: -<<

mkRightHighAppl :: ArrowApp Source #

Right arrow high application: >>-

mkHole :: Expr Source #

A hole expression _