ghc-7.0.3: The GHC API

HsExpr

Contents

- Expressions proper

Description

Abstract Haskell syntax for expressions.

Synopsis

- type LHsExpr id = Located (HsExpr id)
- type PostTcExpr = HsExpr Id
- type PostTcTable = [(Name, PostTcExpr)]
- noPostTcExpr :: PostTcExpr
- noPostTcTable :: PostTcTable
- type SyntaxExpr id = HsExpr id
- noSyntaxExpr :: SyntaxExpr id
- type SyntaxTable id = [(Name, SyntaxExpr id)]
- noSyntaxTable :: SyntaxTable id
- data HsExpr id
  - = HsVar id
  - | HsIPVar (IPName id)
  - | HsOverLit (HsOverLit id)
  - | HsLit HsLit
  - | HsLam (MatchGroup id)
  - | HsApp (LHsExpr id) (LHsExpr id)
  - | OpApp (LHsExpr id) (LHsExpr id) Fixity (LHsExpr id)
  - | NegApp (LHsExpr id) (SyntaxExpr id)
  - | HsPar (LHsExpr id)
  - | SectionL (LHsExpr id) (LHsExpr id)
  - | SectionR (LHsExpr id) (LHsExpr id)
  - | ExplicitTuple [HsTupArg id] Boxity
  - | HsCase (LHsExpr id) (MatchGroup id)
  - | HsIf (Maybe (SyntaxExpr id)) (LHsExpr id) (LHsExpr id) (LHsExpr id)
  - | HsLet (HsLocalBinds id) (LHsExpr id)
  - | HsDo (HsStmtContext Name) [LStmt id] (LHsExpr id) PostTcType
  - | ExplicitList PostTcType [LHsExpr id]
  - | ExplicitPArr PostTcType [LHsExpr id]
  - | RecordCon (Located id) PostTcExpr (HsRecordBinds id)
  - | RecordUpd (LHsExpr id) (HsRecordBinds id) [DataCon] [PostTcType] [PostTcType]
  - | ExprWithTySig (LHsExpr id) (LHsType id)
  - | ExprWithTySigOut (LHsExpr id) (LHsType Name)
  - | ArithSeq PostTcExpr (ArithSeqInfo id)
  - | PArrSeq PostTcExpr (ArithSeqInfo id)
  - | HsSCC FastString (LHsExpr id)
  - | HsCoreAnn FastString (LHsExpr id)
  - | HsBracket (HsBracket id)
  - | HsBracketOut (HsBracket Name) [PendingSplice]
  - | HsSpliceE (HsSplice id)
  - | HsQuasiQuoteE (HsQuasiQuote id)
  - | HsProc (LPat id) (LHsCmdTop id)
  - | HsArrApp (LHsExpr id) (LHsExpr id) PostTcType HsArrAppType Bool
  - | HsArrForm (LHsExpr id) (Maybe Fixity) [LHsCmdTop id]
  - | HsTick Int [id] (LHsExpr id)
  - | HsBinTick Int Int (LHsExpr id)
  - | HsTickPragma (FastString, (Int, Int), (Int, Int)) (LHsExpr id)
  - | EWildPat
  - | EAsPat (Located id) (LHsExpr id)
  - | EViewPat (LHsExpr id) (LHsExpr id)
  - | ELazyPat (LHsExpr id)
  - | HsType (LHsType id)
  - | HsWrap HsWrapper (HsExpr id)
- data HsTupArg id
  - = Present (LHsExpr id)
  - | Missing PostTcType
- tupArgPresent :: HsTupArg id -> Bool
- type PendingSplice = (Name, LHsExpr Id)
- pprLExpr :: OutputableBndr id => LHsExpr id -> SDoc
- pprExpr :: OutputableBndr id => HsExpr id -> SDoc
- isQuietHsExpr :: HsExpr id -> Bool
- pprBinds :: (OutputableBndr idL, OutputableBndr idR) => HsLocalBindsLR idL idR -> SDoc
- ppr_lexpr :: OutputableBndr id => LHsExpr id -> SDoc
- ppr_expr :: OutputableBndr id => HsExpr id -> SDoc
- pprCmdArg :: OutputableBndr id => HsCmdTop id -> SDoc
- pa_brackets :: SDoc -> SDoc
- pprDebugParendExpr :: OutputableBndr id => LHsExpr id -> SDoc
- pprParendExpr :: OutputableBndr id => LHsExpr id -> SDoc
- isAtomicHsExpr :: HsExpr id -> Bool
- type HsCmd id = HsExpr id
- type LHsCmd id = LHsExpr id
- data HsArrAppType
  - = HsHigherOrderApp
  - | HsFirstOrderApp
- type LHsCmdTop id = Located (HsCmdTop id)
- data HsCmdTop id = HsCmdTop (LHsCmd id) [PostTcType] PostTcType (SyntaxTable id)
- type HsRecordBinds id = HsRecFields id (LHsExpr id)
- data MatchGroup id = MatchGroup [LMatch id] PostTcType
- type LMatch id = Located (Match id)
- data Match id = Match [LPat id] (Maybe (LHsType id)) (GRHSs id)
- isEmptyMatchGroup :: MatchGroup id -> Bool
- matchGroupArity :: MatchGroup id -> Arity
- hsLMatchPats :: LMatch id -> [LPat id]
- data GRHSs id = GRHSs {
  - grhssGRHSs :: [LGRHS id]
  - grhssLocalBinds :: HsLocalBinds id
  }
- type LGRHS id = Located (GRHS id)
- data GRHS id = GRHS [LStmt id] (LHsExpr id)
- pprMatches :: (OutputableBndr idL, OutputableBndr idR) => HsMatchContext idL -> MatchGroup idR -> SDoc
- pprFunBind :: (OutputableBndr idL, OutputableBndr idR) => idL -> Bool -> MatchGroup idR -> SDoc
- pprPatBind :: (OutputableBndr bndr, OutputableBndr id) => LPat bndr -> GRHSs id -> SDoc
- pprMatch :: (OutputableBndr idL, OutputableBndr idR) => HsMatchContext idL -> Match idR -> SDoc
- pprGRHSs :: (OutputableBndr idL, OutputableBndr idR) => HsMatchContext idL -> GRHSs idR -> SDoc
- pprGRHS :: (OutputableBndr idL, OutputableBndr idR) => HsMatchContext idL -> GRHS idR -> SDoc
- pp_rhs :: OutputableBndr idR => HsMatchContext idL -> LHsExpr idR -> SDoc
- type LStmt id = Located (StmtLR id id)
- type LStmtLR idL idR = Located (StmtLR idL idR)
- type Stmt id = StmtLR id id
- data StmtLR idL idR
  - = BindStmt (LPat idL) (LHsExpr idR) (SyntaxExpr idR) (SyntaxExpr idR)
  - | ExprStmt (LHsExpr idR) (SyntaxExpr idR) PostTcType
  - | LetStmt (HsLocalBindsLR idL idR)
  - | ParStmt [([LStmt idL], [idR])]
  - | TransformStmt [LStmt idL] [idR] (LHsExpr idR) (Maybe (LHsExpr idR))
  - | GroupStmt [LStmt idL] [(idR, idR)] (Maybe (LHsExpr idR)) (Either (LHsExpr idR) (SyntaxExpr idR))
  - | RecStmt {
    - recS_stmts :: [LStmtLR idL idR]
    - recS_later_ids :: [idR]
    - recS_rec_ids :: [idR]
    - recS_bind_fn :: SyntaxExpr idR
    - recS_ret_fn :: SyntaxExpr idR
    - recS_mfix_fn :: SyntaxExpr idR
    - recS_rec_rets :: [PostTcExpr]
    - recS_dicts :: TcEvBinds
    }
- pprStmt :: (OutputableBndr idL, OutputableBndr idR) => StmtLR idL idR -> SDoc
- pprTransformStmt :: OutputableBndr id => [id] -> LHsExpr id -> Maybe (LHsExpr id) -> SDoc
- pprGroupStmt :: OutputableBndr id => Maybe (LHsExpr id) -> Either (LHsExpr id) (SyntaxExpr is) -> SDoc
- pprBy :: OutputableBndr id => Maybe (LHsExpr id) -> SDoc
- pprDo :: OutputableBndr id => HsStmtContext any -> [LStmt id] -> LHsExpr id -> SDoc
- ppr_do_stmts :: OutputableBndr id => [LStmt id] -> LHsExpr id -> SDoc
- ppr_lc_stmts :: OutputableBndr id => [LStmt id] -> [SDoc]
- pprComp :: OutputableBndr id => [LStmt id] -> LHsExpr id -> SDoc
- data HsSplice id = HsSplice id (LHsExpr id)
- pprSplice :: OutputableBndr id => HsSplice id -> SDoc
- data HsBracket id
  - = ExpBr (LHsExpr id)
  - | PatBr (LPat id)
  - | DecBrL [LHsDecl id]
  - | DecBrG (HsGroup id)
  - | TypBr (LHsType id)
  - | VarBr id
- pprHsBracket :: OutputableBndr id => HsBracket id -> SDoc
- thBrackets :: SDoc -> SDoc -> SDoc
- data ArithSeqInfo id
  - = From (LHsExpr id)
  - | FromThen (LHsExpr id) (LHsExpr id)
  - | FromTo (LHsExpr id) (LHsExpr id)
  - | FromThenTo (LHsExpr id) (LHsExpr id) (LHsExpr id)
- pp_dotdot :: SDoc
- data HsMatchContext id
  - = FunRhs id Bool
  - | LambdaExpr
  - | CaseAlt
  - | ProcExpr
  - | PatBindRhs
  - | RecUpd
  - | StmtCtxt (HsStmtContext id)
  - | ThPatQuote
- data HsStmtContext id
  - = ListComp
  - | DoExpr
  - | GhciStmt
  - | MDoExpr PostTcTable
  - | PArrComp
  - | PatGuard (HsMatchContext id)
  - | ParStmtCtxt (HsStmtContext id)
  - | TransformStmtCtxt (HsStmtContext id)
- isDoExpr :: HsStmtContext id -> Bool
- isListCompExpr :: HsStmtContext id -> Bool
- matchSeparator :: HsMatchContext id -> SDoc
- pprMatchContext :: Outputable id => HsMatchContext id -> SDoc
- pprMatchContextNoun :: Outputable id => HsMatchContext id -> SDoc
- pprStmtContext :: Outputable id => HsStmtContext id -> SDoc
- matchContextErrString :: Outputable id => HsMatchContext id -> SDoc
- pprMatchInCtxt :: (OutputableBndr idL, OutputableBndr idR) => HsMatchContext idL -> Match idR -> SDoc
- pprStmtInCtxt :: (OutputableBndr idL, OutputableBndr idR) => HsStmtContext idL -> StmtLR idL idR -> SDoc

# Expressions proper

type LHsExpr id = Located (HsExpr id)Source

type PostTcExpr = HsExpr Id Source

PostTcExpr is an evidence expression attached to the syntax tree by the type checker (c.f. postTcType).

type PostTcTable = [(Name, PostTcExpr)]Source

We use a PostTcTable where there are a bunch of pieces of evidence, more than is convenient to keep individually.

noPostTcExpr :: PostTcExpr Source

noPostTcTable :: PostTcTable Source

type SyntaxExpr id = HsExpr idSource

SyntaxExpr is like `PostTcExpr`, but it's filled in a little earlier, by the renamer. It's used for rebindable syntax.

E.g. `(>>=)` is filled in before the renamer by the appropriate `Name` for `(>>=)`, and then instantiated by the type checker with its type args etc

noSyntaxExpr :: SyntaxExpr idSource

type SyntaxTable id = [(Name, SyntaxExpr id)]Source

Currently used only for `CmdTop` (sigh)

- Before the renamer, this list is `noSyntaxTable`
- After the renamer, it takes the form `[(std_name, HsVar actual_name)]` For example, for the `return` op of a monad
- normal case: `(GHC.Base.return, HsVar GHC.Base.return)`
- with rebindable syntax: `(GHC.Base.return, return_22)` where `return_22` is whatever `return` is in scope
- After the type checker, it takes the form `[(std_name, expression)]` where `expression` is the evidence for the method

noSyntaxTable :: SyntaxTable idSource

data HsExpr id Source

A Haskell expression.

Constructors

HsVar id | variable
HsIPVar (IPName id) | implicit parameter
HsOverLit (HsOverLit id) | Overloaded literals
HsLit HsLit | Simple (non-overloaded) literals
HsLam (MatchGroup id) |
HsApp (LHsExpr id) (LHsExpr id) |
OpApp (LHsExpr id) (LHsExpr id) Fixity (LHsExpr id) |
NegApp (LHsExpr id) (SyntaxExpr id) |
HsPar (LHsExpr id) |
SectionL (LHsExpr id) (LHsExpr id) |
SectionR (LHsExpr id) (LHsExpr id) |
ExplicitTuple [HsTupArg id] Boxity |
HsCase (LHsExpr id) (MatchGroup id) |
HsIf (Maybe (SyntaxExpr id)) (LHsExpr id) (LHsExpr id) (LHsExpr id) |
HsLet (HsLocalBinds id) (LHsExpr id) |
HsDo (HsStmtContext Name) [LStmt id] (LHsExpr id) PostTcType |
ExplicitList PostTcType [LHsExpr id] |
ExplicitPArr PostTcType [LHsExpr id] |
RecordCon (Located id) PostTcExpr (HsRecordBinds id) |
RecordUpd (LHsExpr id) (HsRecordBinds id) [DataCon] [PostTcType] [PostTcType] |
ExprWithTySig (LHsExpr id) (LHsType id) |
ExprWithTySigOut (LHsExpr id) (LHsType Name) |
ArithSeq PostTcExpr (ArithSeqInfo id) |
PArrSeq PostTcExpr (ArithSeqInfo id) |
HsSCC FastString (LHsExpr id) |
HsCoreAnn FastString (LHsExpr id) |
HsBracket (HsBracket id) |
HsBracketOut (HsBracket Name) [PendingSplice] |
HsSpliceE (HsSplice id) |
HsQuasiQuoteE (HsQuasiQuote id) |
HsProc (LPat id) (LHsCmdTop id) |
HsArrApp (LHsExpr id) (LHsExpr id) PostTcType HsArrAppType Bool |
HsArrForm (LHsExpr id) (Maybe Fixity) [LHsCmdTop id] |
HsTick Int [id] (LHsExpr id) |
HsBinTick Int Int (LHsExpr id) |
HsTickPragma (FastString, (Int, Int), (Int, Int)) (LHsExpr id) |
EWildPat |
EAsPat (Located id) (LHsExpr id) |
EViewPat (LHsExpr id) (LHsExpr id) |
ELazyPat (LHsExpr id) |
HsType (LHsType id) |
HsWrap HsWrapper (HsExpr id) |

Instances

Typeable1 HsExpr |
Data id => Data (HsExpr id) |
OutputableBndr id => Outputable (HsExpr id) |

data HsTupArg id Source

Constructors

Present (LHsExpr id) |
Missing PostTcType |

Instances

Typeable1 HsTupArg |
Data id => Data (HsTupArg id) |

tupArgPresent :: HsTupArg id -> Bool Source

type PendingSplice = (Name, LHsExpr Id)Source

pprLExpr :: OutputableBndr id => LHsExpr id -> SDoc Source

pprExpr :: OutputableBndr id => HsExpr id -> SDoc Source

isQuietHsExpr :: HsExpr id -> Bool Source

pprBinds :: (OutputableBndr idL, OutputableBndr idR) => HsLocalBindsLR idL idR -> SDoc Source

ppr_lexpr :: OutputableBndr id => LHsExpr id -> SDoc Source

ppr_expr :: OutputableBndr id => HsExpr id -> SDoc Source

pprCmdArg :: OutputableBndr id => HsCmdTop id -> SDoc Source

pa_brackets :: SDoc -> SDoc Source

pprDebugParendExpr :: OutputableBndr id => LHsExpr id -> SDoc Source

pprParendExpr :: OutputableBndr id => LHsExpr id -> SDoc Source

isAtomicHsExpr :: HsExpr id -> Bool Source

type HsCmd id = HsExpr idSource

type LHsCmd id = LHsExpr idSource

data HsArrAppType Source

Constructors

HsHigherOrderApp |
HsFirstOrderApp |

Instances

Data HsArrAppType |
Typeable HsArrAppType |

type LHsCmdTop id = Located (HsCmdTop id)Source

data HsCmdTop id Source

Constructors

HsCmdTop (LHsCmd id) [PostTcType] PostTcType (SyntaxTable id) |

Instances

Typeable1 HsCmdTop |
Data id => Data (HsCmdTop id) |
OutputableBndr id => Outputable (HsCmdTop id) |

type HsRecordBinds id = HsRecFields id (LHsExpr id)Source

data MatchGroup id Source

Constructors

MatchGroup [LMatch id] PostTcType |

Instances

Typeable1 MatchGroup |
Data id => Data (MatchGroup id) |

type LMatch id = Located (Match id)Source

data Match id Source

Constructors

Match [LPat id] (Maybe (LHsType id)) (GRHSs id) |

Instances

Typeable1 Match |
Data id => Data (Match id) |

isEmptyMatchGroup :: MatchGroup id -> Bool Source

matchGroupArity :: MatchGroup id -> Arity Source

hsLMatchPats :: LMatch id -> [LPat id]Source

data GRHSs id Source

GRHSs are used both for pattern bindings and for Matches

Constructors

GRHSs |

Fields

grhssGRHSs :: [LGRHS id]

  Guarded RHSs

grhssLocalBinds :: HsLocalBinds id

  The where clause

Instances

Typeable1 GRHSs |
Data id => Data (GRHSs id) |

type LGRHS id = Located (GRHS id)Source

data GRHS id Source

Guarded Right Hand Side.

Constructors

GRHS [LStmt id] (LHsExpr id) |

Instances

Typeable1 GRHS |
Data id => Data (GRHS id) |

pprMatches :: (OutputableBndr idL, OutputableBndr idR) => HsMatchContext idL -> MatchGroup idR -> SDoc Source

pprFunBind :: (OutputableBndr idL, OutputableBndr idR) => idL -> Bool -> MatchGroup idR -> SDoc Source

pprPatBind :: (OutputableBndr bndr, OutputableBndr id) => LPat bndr -> GRHSs id -> SDoc Source

pprMatch :: (OutputableBndr idL, OutputableBndr idR) => HsMatchContext idL -> Match idR -> SDoc Source

pprGRHSs :: (OutputableBndr idL, OutputableBndr idR) => HsMatchContext idL -> GRHSs idR -> SDoc Source

pprGRHS :: (OutputableBndr idL, OutputableBndr idR) => HsMatchContext idL -> GRHS idR -> SDoc Source

pp_rhs :: OutputableBndr idR => HsMatchContext idL -> LHsExpr idR -> SDoc Source

type LStmt id = Located (StmtLR id id)Source

type LStmtLR idL idR = Located (StmtLR idL idR)Source

type Stmt id = StmtLR id idSource

data StmtLR idL idR Source

Constructors

BindStmt (LPat idL) (LHsExpr idR) (SyntaxExpr idR) (SyntaxExpr idR) |
ExprStmt (LHsExpr idR) (SyntaxExpr idR) PostTcType |
LetStmt (HsLocalBindsLR idL idR) |
ParStmt [([LStmt idL], [idR])] |
TransformStmt [LStmt idL] [idR] (LHsExpr idR) (Maybe (LHsExpr idR)) |
GroupStmt [LStmt idL] [(idR, idR)] (Maybe (LHsExpr idR)) (Either (LHsExpr idR) (SyntaxExpr idR)) |
RecStmt |

Fields

recS_stmts :: [LStmtLR idL idR]
recS_later_ids :: [idR]
recS_rec_ids :: [idR]
recS_bind_fn :: SyntaxExpr idR
recS_ret_fn :: SyntaxExpr idR
recS_mfix_fn :: SyntaxExpr idR
recS_rec_rets :: [PostTcExpr]
recS_dicts :: TcEvBinds

Instances

Typeable2 StmtLR |
(Data idL, Data idR) => Data (StmtLR idL idR) |
(OutputableBndr idL, OutputableBndr idR) => Outputable (StmtLR idL idR) |

pprStmt :: (OutputableBndr idL, OutputableBndr idR) => StmtLR idL idR -> SDoc Source

pprTransformStmt :: OutputableBndr id => [id] -> LHsExpr id -> Maybe (LHsExpr id) -> SDoc Source

pprGroupStmt :: OutputableBndr id => Maybe (LHsExpr id) -> Either (LHsExpr id) (SyntaxExpr is) -> SDoc Source

pprBy :: OutputableBndr id => Maybe (LHsExpr id) -> SDoc Source

pprDo :: OutputableBndr id => HsStmtContext any -> [LStmt id] -> LHsExpr id -> SDoc Source

ppr_do_stmts :: OutputableBndr id => [LStmt id] -> LHsExpr id -> SDoc Source

ppr_lc_stmts :: OutputableBndr id => [LStmt id] -> [SDoc]Source

pprComp :: OutputableBndr id => [LStmt id] -> LHsExpr id -> SDoc Source

data HsSplice id Source

Constructors

HsSplice id (LHsExpr id) |

Instances

Typeable1 HsSplice |
Data id => Data (HsSplice id) |
OutputableBndr id => Outputable (HsSplice id) |

pprSplice :: OutputableBndr id => HsSplice id -> SDoc Source

data HsBracket id Source

Constructors

ExpBr (LHsExpr id) |
PatBr (LPat id) |
DecBrL [LHsDecl id] |
DecBrG (HsGroup id) |
TypBr (LHsType id) |
VarBr id |

Instances

Typeable1 HsBracket |
Data id => Data (HsBracket id) |
OutputableBndr id => Outputable (HsBracket id) |

pprHsBracket :: OutputableBndr id => HsBracket id -> SDoc Source

thBrackets :: SDoc -> SDoc -> SDoc Source

data ArithSeqInfo id Source

Constructors

From (LHsExpr id) |
FromThen (LHsExpr id) (LHsExpr id) |
FromTo (LHsExpr id) (LHsExpr id) |
FromThenTo (LHsExpr id) (LHsExpr id) (LHsExpr id) |

Instances

Typeable1 ArithSeqInfo |
Data id => Data (ArithSeqInfo id) |
OutputableBndr id => Outputable (ArithSeqInfo id) |

pp_dotdot :: SDoc Source

data HsMatchContext id Source

Constructors

FunRhs id Bool |
LambdaExpr |
CaseAlt |
ProcExpr |
PatBindRhs |
RecUpd |
StmtCtxt (HsStmtContext id) |
ThPatQuote |

Instances

Typeable1 HsMatchContext |
Data id => Data (HsMatchContext id) |

data HsStmtContext id Source

Constructors

ListComp |
DoExpr |
GhciStmt |
MDoExpr PostTcTable |
PArrComp |
PatGuard (HsMatchContext id) |
ParStmtCtxt (HsStmtContext id) |
TransformStmtCtxt (HsStmtContext id) |

Instances

Typeable1 HsStmtContext |
Data id => Data (HsStmtContext id) |

isDoExpr :: HsStmtContext id -> Bool Source

isListCompExpr :: HsStmtContext id -> Bool Source

matchSeparator :: HsMatchContext id -> SDoc Source

pprMatchContext :: Outputable id => HsMatchContext id -> SDoc Source

pprMatchContextNoun :: Outputable id => HsMatchContext id -> SDoc Source

pprStmtContext :: Outputable id => HsStmtContext id -> SDoc Source

matchContextErrString :: Outputable id => HsMatchContext id -> SDoc Source

pprMatchInCtxt :: (OutputableBndr idL, OutputableBndr idR) => HsMatchContext idL -> Match idR -> SDoc Source

pprStmtInCtxt :: (OutputableBndr idL, OutputableBndr idR) => HsStmtContext idL -> StmtLR idL idR -> SDoc Source