ContentsIndex
Core2Cl
Contents
Translation contexts
CaseExp
Substitution in expressions and patterns
Contexts
From Core to Cl
PJ: Cmp. with Core2Agda.qualifyTcon - what is the difference and why?
Description
This module translates a GHC core Module to a list of Clause. The GHC core module is supposed to have been already lifted (all functions declarations and case at toplevel
Synopsis
core2cl :: Module -> Module
type CaseExp = ([Pat], [([Guard], Maybe Exp, [Local])])
csEmpty :: [CaseExp]
ceExtPat :: Pat -> CaseExp -> CaseExp
csExtPat :: [CaseExp] -> Pat -> [CaseExp]
ceAddGuard :: Guard -> CaseExp -> CaseExp
csReplExp :: [CaseExp] -> (Exp, [(Pat, Exp)]) -> [CaseExp]
csReplPat :: [CaseExp] -> Pat -> Pat -> [CaseExp]
ceToClauses :: Id -> CaseExp -> [Clause]
csToClauses :: Id -> [CaseExp] -> [Clause]
type SubstEnv = [(Id, Pat)]
substEmpty :: SubstEnv
substPat :: SubstEnv -> Pat -> Pat
substAdd :: SubstEnv -> Id -> Pat -> SubstEnv
data Context = C {
modName :: String
cexps :: [CaseExp]
subst :: SubstEnv
erase :: [String]
funs :: [String]
}
ctxEmpty :: String -> [String] -> Context
ctxErase :: Context -> String -> Bool
ctxAddErase :: Context -> String -> Context
ctxReplExp :: Context -> (Exp, [(Pat, Exp)]) -> Context
ctxAddSubst :: Context -> Id -> Pat -> Context
ctxAddGuard :: Context -> Exp -> Context
ctxConcat :: [Context] -> Context -> Context
c2cTopLevelVdefg :: Context -> Vdefg -> ([Clause], [PropCl])
c2cTopLevelVdef :: Context -> Vdef -> ([Clause], [PropCl])
c2cLambda :: Context -> Exp -> Context
c2cCaseExp :: Context -> Exp -> Context
c2cAlt :: Context -> Id -> Alt -> Context
c2cAltGuard :: Context -> Exp -> Alt -> Context
c2cVdefg :: Context -> Vdefg -> [(Pat, Exp)]
c2cVdef :: Context -> Vdef -> [(Pat, Exp)]
c2cExp :: Context -> Exp -> (Exp, [(Pat, Exp)])
c2cId :: Id -> String
qname :: String -> String -> Id
c2cLit :: Lit -> Id
c2cPatExp :: Exp -> [Pat] -> Pat
coreToPrelude :: Id -> Id
clNot :: Exp -> Exp
expOfPat :: (Id -> Exp) -> Pat -> Exp
ctxAddClassOrd :: Context -> Context
lDef :: [Vdefg] -> [String]
data Prop
= ForAll (Exp -> Prop)
| Exists (Exp -> Prop)
| And Prop Prop
| Or Prop Prop
| Not Prop
| Equal Exp Exp
| Using [Id] Prop
| Inline Id
| Ninline Id
type Disj = [Lit]
type Conj = [Disj]
c2pVdef :: Context -> String -> Exp -> PropCl
toProp :: Context -> Exp -> Prop
toPropExp :: Context -> Exp -> Exp
toPropList :: Context -> Exp -> [Id]
toQname :: Context -> Exp -> Id
substProp :: String -> Exp -> Prop -> Prop
substExp :: String -> Exp -> Exp -> Exp
toPropFun :: Context -> Exp -> Exp -> Prop
clausify :: [Exp] -> Prop -> State Int ([Id], [Disj])
positive :: Prop -> Prop
nt :: Prop -> Prop
Documentation
core2cl :: Module -> Module
Translation contexts
CaseExp
type CaseExp = ([Pat], [([Guard], Maybe Exp, [Local])])
CaseExp are unfinished clauses. They are build and extended while going through the graph.
csEmpty :: [CaseExp]
ceExtPat :: Pat -> CaseExp -> CaseExp
csExtPat :: [CaseExp] -> Pat -> [CaseExp]
ceAddGuard :: Guard -> CaseExp -> CaseExp
csReplExp :: [CaseExp] -> (Exp, [(Pat, Exp)]) -> [CaseExp]
csReplPat :: [CaseExp] -> Pat -> Pat -> [CaseExp]
ceToClauses :: Id -> CaseExp -> [Clause]
A CaseExp translates to a list of clauses. Uncomplete CaseExp are discarded (maybe they should raise an error?).
csToClauses :: Id -> [CaseExp] -> [Clause]
Substitution in expressions and patterns
type SubstEnv = [(Id, Pat)]
We need to substitute identifier with pattern and expressions. We use a substitution environment made by an associate list and just traverse the structures.
substEmpty :: SubstEnv
An empty substitution environment.
substPat :: SubstEnv -> Pat -> Pat
substPat env p returns a pattern build from p and where all substitutions defined by env have been processed.
substAdd :: SubstEnv -> Id -> Pat -> SubstEnv
substAdd env id p adds a substitution of identifier id by pattern pat in env. The substitution is propaged down into env.
Contexts
data Context
Contexts are simply records containing a list of CaseExp and a substitution environment.
Constructors
C
modName :: String
cexps :: [CaseExp]
subst :: SubstEnv
erase :: [String]
funs :: [String]
ctxEmpty :: String -> [String] -> Context
An empty context.
ctxErase :: Context -> String -> Bool
ctxAddErase :: Context -> String -> Context
ctxReplExp :: Context -> (Exp, [(Pat, Exp)]) -> Context
ctxAddSubst :: Context -> Id -> Pat -> Context
ctxAddGuard :: Context -> Exp -> Context
ctxConcat :: [Context] -> Context -> Context
From Core to Cl
c2cTopLevelVdefg :: Context -> Vdefg -> ([Clause], [PropCl])
c2cTopLevelVdef :: Context -> Vdef -> ([Clause], [PropCl])
c2cLambda :: Context -> Exp -> Context
Lambdas should all be at toplevel. Processing a lambda consists in adding a parameter in the parameter list of the current list of CaseExp, and calling ourselves recursively. When we have no more lambdas, we start processing cases.
c2cCaseExp :: Context -> Exp -> Context
Case expression should be directly following the lambdas. When processing cases, we have two possibilities: * we do case on a variable - we replace the variable by the binder in the pattern arguments of the context and process the right hand sides. * we do case on a boolean expression, this boolean expression becomes a guard. Others cases (case on a non-trivial, non-boolean expression) are errors, and should not occur. The second case (guard) is not implemented yet!
c2cAlt :: Context -> Id -> Alt -> Context
c2cAltGuard :: Context -> Exp -> Alt -> Context
c2cVdefg :: Context -> Vdefg -> [(Pat, Exp)]
The convertion functions
c2cVdef :: Context -> Vdef -> [(Pat, Exp)]
c2cExp :: Context -> Exp -> (Exp, [(Pat, Exp)])
c2cId :: Id -> String
PJ: Cmp. with Core2Agda.qualifyTcon - what is the difference and why?
qname :: String -> String -> Id
c2cLit :: Lit -> Id
c2cPatExp :: Exp -> [Pat] -> Pat
coreToPrelude :: Id -> Id
clNot :: Exp -> Exp
expOfPat :: (Id -> Exp) -> Pat -> Exp
ctxAddClassOrd :: Context -> Context
lDef :: [Vdefg] -> [String]
data Prop
Constructors
ForAll (Exp -> Prop)
Exists (Exp -> Prop)
And Prop Prop
Or Prop Prop
Not Prop
Equal Exp Exp
Using [Id] Prop
Inline Id
Ninline Id
type Disj = [Lit]
type Conj = [Disj]
c2pVdef :: Context -> String -> Exp -> PropCl
toProp :: Context -> Exp -> Prop
toPropExp :: Context -> Exp -> Exp
toPropList :: Context -> Exp -> [Id]
toQname :: Context -> Exp -> Id
substProp :: String -> Exp -> Prop -> Prop
substExp :: String -> Exp -> Exp -> Exp
toPropFun :: Context -> Exp -> Exp -> Prop
clausify :: [Exp] -> Prop -> State Int ([Id], [Disj])
positive :: Prop -> Prop
nt :: Prop -> Prop
Produced by Haddock version 0.6