%
% (c) The Foo Project, University of Glasgow, 1998
%
% @(#) $Docid: Feb. 8th 2003 06:45 Sigbjorn Finne $
% @(#) $Contactid: sof@galois.com $
%
A (restricted) abstract syntax for Haskell.
\begin{code}
module AbstractH where
import Literal
import BasicTypes
\end{code}
The @HTopDecl@ includes Haskell modules, but also
an escape mechanism for inserting stuff that goes
outside it (literate markup/pragmas etc.)
\begin{code}
data HTopDecl
= HMod HModule
| HInclude String
| HLit String
| CLit String
\end{code}
Represent a Haskell module abstractly by @HModule@, which
\begin{code}
data HModule =
HModule
Name
Bool
[HExport]
[HImport]
HDecl
\end{code}
\begin{code}
data HExport = HExport HIEEntity (Maybe String)
data HIEEntity
= IEModule Name
| IEVal Name
| IEClass Name
| IEType Name Bool
deriving Eq
\end{code}
\begin{code}
data HImport
= HImport
Bool --qualified?
(Maybe Name)
Name
(Maybe [HIEEntity])
\end{code}
\begin{code}
data HDecl
= AndDecl HDecl HDecl
| TypeSig Name (Maybe Context) Type
| ValDecl QualName [Pat] [GuardedExpr]
| Primitive Bool CallConv LocSpec Name Type Bool [(Bool,String)] (Bool,String)
| PrimCast CallConv Name Type Bool [(Bool,String)] (Bool,String)
| Entry CallConv Name Name Type
| Callback CallConv Name Type
| ExtLabel Name Name Type
| TyD TyDecl
| Class Context ClassName [TyVar] [HDecl]
| Instance Context ClassName Type [HDecl]
| Include String
| Haskell String
| CCode String
| EmptyDecl
type LocSpec = (String, Maybe Integer, String, Maybe Int)
type ClassName = QualName
data Context
= CtxtTuple [Context]
| CtxtClass ClassName [Type]
deriving ( Eq, Show )
\end{code}
@Type@ represent Haskell types - no explicit
management of the scoping of type variables.
\begin{code}
data Type
= TyVar Bool TyVar
| TyCon TyCon
| TyApply Type [Type]
| TyList Type
| TyTuple [Type]
| TyFun Type Type
| TyCtxt Context Type
deriving ( Eq, Show )
\end{code}
Patterned on @HsDecls.TyDecl@ (no support for
tycon contexts tho')
\begin{code}
data TyDecl
= TypeSyn Name [Name] Type
| TyDecl TyDeclKind
Name
[Name]
[ConDecl]
[QualName]
data TyDeclKind = Data | Newtype
data ConDecl
= ConDecl Name [BangType]
| RecDecl Name [(Name, BangType)]
data BangType = Banged Type | Unbanged Type
type TyVar = QualName
type TyCon = QualName
\end{code}
\begin{code}
data GuardedExpr = GExpr [Expr] Expr
data Expr
= Lit Literal
| Lam [Pat] Expr
| Apply Expr [Expr]
| RApply Expr Expr
| Tup [Expr]
| List [Expr]
| InfixOp Expr VarName Expr
| BinOp BinaryOp Expr Expr
| UnOp UnaryOp Expr
| Bind Expr Pat Expr
| Bind_ Expr Expr
| Return Expr
| Case Expr [CaseAlt]
| If Expr Expr Expr
| Let [Binding] Expr
| Var VarName
| Con ConName
| WithTy Expr Type
data Binding = Binder Name Expr
type VarName = QualName
type ConName = QualName
\end{code}
\begin{code}
data Pat
= PatVar VarName
| PatLit Literal
| PatWildCard
| PatTuple [Pat]
| PatAs VarName Pat
| PatCon ConName [Pat]
| PatList [Pat]
| PatIrrefut Pat
| PatRecord VarName [(VarName,Pat)]
data CaseAlt
= Alt Pat [GuardedExpr]
| Default (Maybe VarName) Expr
\end{code}