Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experiment with normalizing defs during type checking #162

Draft
wants to merge 24 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/compiler/GF/Compile/TypeCheck/Abstract.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,16 @@ initTCEnv gamma =

-- interface to TC type checker

type2val :: Type -> Val
type2val = VClos []
type2val :: Type -> NotVal
type2val = NVClos []

type2nval :: Type -> NotVal
type2nval = NVClos []

cont2exp :: Context -> Term
cont2exp c = mkProd c eType [] -- to check a context

cont2val :: Context -> Val
cont2val :: Context -> NotVal
cont2val = type2val . cont2exp

-- some top-level batch-mode checkers for the compiler
Expand All @@ -61,9 +64,11 @@ notJustMeta (c,k) = case (c,k) of

grammar2theory :: SourceGrammar -> Theory
grammar2theory gr (m,f) = case lookupFunType gr m f of
Ok t -> return $ type2val t
Ok t -> case lookupAbsDef gr m f of -- TODO: Don't lookup twice
Ok (Just n, Just eqs) -> return (type2val t, Just (n, eqs))
_ -> return (type2val t, Nothing)
Bad s -> case lookupCatContext gr m f of
Ok cont -> return $ cont2val cont
Ok cont -> return (cont2val cont,Nothing)
_ -> Bad s

checkContext :: SourceGrammar -> Context -> [Message]
Expand All @@ -74,7 +79,7 @@ checkTyp gr typ = err (\x -> [pp x]) ppConstrs $ justTypeCheck gr typ vType

checkDef :: SourceGrammar -> Fun -> Type -> Equation -> [Message]
checkDef gr (m,fun) typ eq = err (\x -> [pp x]) ppConstrs $ do
(b,cs) <- checkBranch (grammar2theory gr) (initTCEnv []) eq (type2val typ)
(b,cs) <- checkBranch (grammar2theory gr) (initTCEnv []) eq (type2nval typ)
(constrs,_) <- unifyVal cs
return $ filter notJustMeta constrs

Expand Down
Loading