ghc-source-gen-0.4.3.0: Constructs Haskell syntax trees for the GHC API.
Safe HaskellNone
LanguageHaskell2010

GHC.SourceGen.Expr

Description

This module provides combinators for constructing Haskell expressions.

Synopsis

Documentation

type HsExpr' = HsExpr GhcPs Source #

A Haskell expression, as it is represented after the parsing step.

Instances:

overLabel :: String -> HsExpr' Source #

An overloaded label, as used with the OverloadedLabels extension.

#foo
=====
overLabel "foo"

multiIf :: [GuardedExpr] -> HsExpr' Source #

A MultiWayIf expression.

if | f x = "f"
   | g x = "g"
   | otherwise = "h"
=====
multiIf
    [ guardedStmt (var "f" @@ var "x") $ rhs (string "f")
    , guardedStmt (var "g" @@ var "x") $ rhs (string "g")
    , guardedStmt (var "otherwise") $ rhs (string "h")
    ]

do' :: [Stmt'] -> HsExpr' Source #

A do-expression.

Individual statements may be constructed with <-- and/or stmt.

do
  x <- act
  return x
=====
do' [bvar "x" <-- var "act", stmt $ var "return" @@ var "x"]

listComp :: HsExpr' -> [Stmt'] -> HsExpr' Source #

A list comprehension expression.

[x * 2 | x <- [1 .. 10], even x]
=====
listComp (op (bvar "x") "*" (int 2))
         [ bvar "x" <-- fromTo (int 1) (int 10)
         , stmt $ var "even" @@ bvar "x"
         ]

type Stmt' = Stmt GhcPs LHsExpr' Source #

(@::@) :: HsExpr' -> HsType' -> HsExpr' Source #

A type constraint on an expression.

e :: t
=====
var "e" @::@ var "t"

tyApp :: HsExpr' -> HsType' -> HsExpr' Source #

Explicit type application.

f @ Int
=====
var "f" @@ var "Int"

recordConE :: RdrNameStr -> [(RdrNameStr, HsExpr')] -> HsExpr' Source #

Constructs a record with explicit field names.

A { x = y }
=====
recordConE "A" [("x", var "y")]

recordUpd :: HsExpr' -> [(RdrNameStr, HsExpr')] -> HsExpr' Source #

Updates a record expression with explicit field names.

r {a = b, c = d}
=====
recordUpd (var "x") [("a", var "b", ("c", var "d"))]
(f x) {a = b}
=====
recordUpd (var "f" @@ var "x") [("a", var "b")]
f x {a = b} -- equivalent to f (x {a = b})
=====
var "f" @@ recordUpd (var "x") [("a", var "b")]

from :: HsExpr' -> HsExpr' Source #

An arithmetic sequence expression with a start value.

[a ..]
=====
from (var "a")

fromThen :: HsExpr' -> HsExpr' -> HsExpr' Source #

An arithmetic sequence expression with a start and a step values.

[a, b ..]
=====
fromThen (var "a") (var "b")

fromTo :: HsExpr' -> HsExpr' -> HsExpr' Source #

An arithmetic sequence expression with a start and an end values.

[a .. b]
=====
fromTo (var "a") (var "b")

fromThenTo :: HsExpr' -> HsExpr' -> HsExpr' -> HsExpr' Source #

An arithmetic sequence expression with a start, a step, and an end values.

[a, b .. c]
=====
fromThenTo (var "a") (var "b") (var "c")