% (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
%
\begin{code}
+{-# LANGUAGE DeriveDataTypeable #-}
-- | Abstract Haskell syntax for expressions.
module HsExpr where
import SrcLoc
import Outputable
import FastString
+
+-- libraries:
+import Data.Data hiding (Fixity)
\end{code}
| HsWrap HsWrapper -- TRANSLATION
(HsExpr id)
+ deriving (Data, Typeable)
-- HsTupArg is used for tuple sections
-- (,a,) is represented by ExplicitTuple [Mising ty1, Present a, Missing ty3]
data HsTupArg id
= Present (LHsExpr id) -- The argument
| Missing PostTcType -- The argument is missing, but this is its type
+ deriving (Data, Typeable)
tupArgPresent :: HsTupArg id -> Bool
tupArgPresent (Present {}) = True
type LHsCmd id = LHsExpr id
data HsArrAppType = HsHigherOrderApp | HsFirstOrderApp
+ deriving (Data, Typeable)
\end{code}
The legal constructors for commands are:
PostTcType -- return type of the command
(SyntaxTable id) -- after type checking:
-- names used in the command's desugaring
+ deriving (Data, Typeable)
\end{code}
%************************************************************************
PostTcType -- The type is the type of the entire group
-- t1 -> ... -> tn -> tr
-- where there are n patterns
+ deriving (Data, Typeable)
type LMatch id = Located (Match id)
(Maybe (LHsType id)) -- A type signature for the result of the match
-- Nothing after typechecking
(GRHSs id)
+ deriving (Data, Typeable)
isEmptyMatchGroup :: MatchGroup id -> Bool
isEmptyMatchGroup (MatchGroup ms _) = null ms
= GRHSs {
grhssGRHSs :: [LGRHS id], -- ^ Guarded RHSs
grhssLocalBinds :: (HsLocalBinds id) -- ^ The where clause
- }
+ } deriving (Data, Typeable)
type LGRHS id = Located (GRHS id)
-- | Guarded Right Hand Side.
data GRHS id = GRHS [LStmt id] -- Guards
(LHsExpr id) -- Right hand side
+ deriving (Data, Typeable)
\end{code}
We know the list must have at least one @Match@ in it.
-- The fail operator is noSyntaxExpr
-- if the pattern match can't fail
- | ExprStmt (LHsExpr idR)
+ | ExprStmt (LHsExpr idR) -- See Note [ExprStmt]
(SyntaxExpr idR) -- The (>>) operator
PostTcType -- Element type of the RHS (used for arrows)
[LStmt idL] -- Stmts to the *left* of the 'group'
-- which generates the tuples to be grouped
- [(idR, idR)] -- After renaming, the IDs are the binders
- -- occurring within this transform statement that
- -- are used after it which are paired with the
- -- names which they group over in statements
+ [(idR, idR)] -- See Note [GroupStmt binder map]
(Maybe (LHsExpr idR)) -- "by e" (optional)
(SyntaxExpr idR)) -- Right f => implicit; filled in with 'groupWith'
- -- Recursive statement (see Note [RecStmt] below)
+ -- Recursive statement (see Note [How RecStmt works] below)
| RecStmt
{ recS_stmts :: [LStmtLR idL idR]
, recS_dicts :: DictBinds idR -- Method bindings of Ids bound by the
-- RecStmt, and used afterwards
}
+ deriving (Data, Typeable)
\end{code}
+Note [GroupStmt binder map]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~
+The [(idR,idR)] in a GroupStmt behaves as follows:
+
+ * Before renaming: []
+
+ * After renaming:
+ [ (x27,x27), ..., (z35,z35) ]
+ These are the variables
+ bound by the stmts to the left of the 'group'
+ and used either in the 'by' clause,
+ or in the stmts following the 'group'
+ Each item is a pair of identical variables.
+
+ * After typechecking:
+ [ (x27:Int, x27:[Int]), ..., (z35:Bool, z35:[Bool]) ]
+ Each pair has the same unique, but different *types*.
+
+Note [ExprStmt]
+~~~~~~~~~~~~~~~
ExprStmts are a bit tricky, because what they mean
depends on the context. Consider the following contexts:
data HsSplice id = HsSplice -- $z or $(f 4)
id -- The id is just a unique name to
(LHsExpr id) -- identify this splice point
+ deriving (Data, Typeable)
instance OutputableBndr id => Outputable (HsSplice id) where
ppr = pprSplice
| DecBrG (HsGroup id) -- [d| decls |]; result of renamer
| TypBr (LHsType id) -- [t| type |]
| VarBr id -- 'x, ''T
+ deriving (Data, Typeable)
instance OutputableBndr id => Outputable (HsBracket id) where
ppr = pprHsBracket
| FromThenTo (LHsExpr id)
(LHsExpr id)
(LHsExpr id)
+ deriving (Data, Typeable)
\end{code}
\begin{code}
-- runtime error message to generate]
| StmtCtxt (HsStmtContext id) -- Pattern of a do-stmt or list comprehension
| ThPatQuote -- A Template Haskell pattern quotation [p| (a,b) |]
- deriving ()
+ deriving (Data, Typeable)
data HsStmtContext id
= ListComp
| PatGuard (HsMatchContext id) -- Pattern guard for specified thing
| ParStmtCtxt (HsStmtContext id) -- A branch of a parallel stmt
| TransformStmtCtxt (HsStmtContext id) -- A branch of a transform stmt
+ deriving (Data, Typeable)
\end{code}
\begin{code}