cleaned up a bit
This commit is contained in:
parent
0e7d485e9e
commit
5eaf7ae00d
1 changed files with 7 additions and 33 deletions
|
|
@ -2,6 +2,9 @@
|
||||||
{-# LANGUAGE OverloadedRecordDot #-}
|
{-# LANGUAGE OverloadedRecordDot #-}
|
||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
{-# LANGUAGE QualifiedDo #-}
|
{-# LANGUAGE QualifiedDo #-}
|
||||||
|
-- This should really not be used. Unfortunately time has not allowed us to
|
||||||
|
-- really implement the desugaring phase correctly
|
||||||
|
{-# OPTIONS_GHC -Wno-incomplete-patterns #-}
|
||||||
|
|
||||||
-- | A module for type checking and inference using algorithm W, Hindley-Milner
|
-- | A module for type checking and inference using algorithm W, Hindley-Milner
|
||||||
module TypeChecker.TypeCheckerHm where
|
module TypeChecker.TypeCheckerHm where
|
||||||
|
|
@ -24,6 +27,7 @@ import Grammar.Abs
|
||||||
import Grammar.Print (printTree)
|
import Grammar.Print (printTree)
|
||||||
import TypeChecker.TypeCheckerIr (T, T')
|
import TypeChecker.TypeCheckerIr (T, T')
|
||||||
import TypeChecker.TypeCheckerIr qualified as T
|
import TypeChecker.TypeCheckerIr qualified as T
|
||||||
|
import Debug.Trace (trace)
|
||||||
|
|
||||||
-- | Type check a program
|
-- | Type check a program
|
||||||
typecheck :: Program -> Either String (T.Program' Type, [Warning])
|
typecheck :: Program -> Either String (T.Program' Type, [Warning])
|
||||||
|
|
@ -88,35 +92,6 @@ freeOrdered (TFun a b) = freeOrdered a ++ freeOrdered b
|
||||||
freeOrdered (TData _ a) = concatMap freeOrdered a
|
freeOrdered (TData _ a) = concatMap freeOrdered a
|
||||||
freeOrdered _ = mempty
|
freeOrdered _ = mempty
|
||||||
|
|
||||||
-- Much cleaner implementation, unfortunately one minor bug
|
|
||||||
-- checkBind :: Bind -> Infer (T.Bind' Type)
|
|
||||||
-- checkBind (Bind name args expr) = do
|
|
||||||
-- fr <- fresh
|
|
||||||
-- let lambda = makeLambda expr (reverse (coerce args))
|
|
||||||
-- withBinding (coerce name) fr $ do
|
|
||||||
-- (sub, (e, infSig)) <- algoW lambda
|
|
||||||
-- env <- asks vars
|
|
||||||
-- let genInfSig = generalize (apply sub env) infSig
|
|
||||||
-- maybeSig <- gets (join . M.lookup (coerce name) . sigs)
|
|
||||||
-- case maybeSig of
|
|
||||||
-- Just typSig -> do
|
|
||||||
-- unless
|
|
||||||
-- (genInfSig <<= typSig)
|
|
||||||
-- ( throwError $
|
|
||||||
-- Error
|
|
||||||
-- ( Aux.do
|
|
||||||
-- "Inferred type"
|
|
||||||
-- quote $ printTree infSig
|
|
||||||
-- "doesn't match given type"
|
|
||||||
-- quote $ printTree typSig
|
|
||||||
-- )
|
|
||||||
-- False
|
|
||||||
-- )
|
|
||||||
-- return $ T.Bind (coerce name, typSig) [] (apply sub e, typSig)
|
|
||||||
-- _ -> do
|
|
||||||
-- insertSig (coerce name) (Just genInfSig)
|
|
||||||
-- return $ T.Bind (coerce name, genInfSig) [] (apply sub e, genInfSig)
|
|
||||||
|
|
||||||
checkBind :: Bind -> Infer (T.Bind' Type)
|
checkBind :: Bind -> Infer (T.Bind' Type)
|
||||||
checkBind (Bind name args e) = do
|
checkBind (Bind name args e) = do
|
||||||
let lambda = makeLambda e (reverse (coerce args))
|
let lambda = makeLambda e (reverse (coerce args))
|
||||||
|
|
@ -139,8 +114,6 @@ checkBind (Bind name args e) = do
|
||||||
)
|
)
|
||||||
False
|
False
|
||||||
)
|
)
|
||||||
-- Applying sub to typSig will worsen error messages.
|
|
||||||
-- Unfortunately I do not know a better solution at the moment.
|
|
||||||
return $ T.Bind (coerce name, apply sub typSig) [] (apply sub e, typSig)
|
return $ T.Bind (coerce name, apply sub typSig) [] (apply sub e, typSig)
|
||||||
_ -> do
|
_ -> do
|
||||||
insertSig (coerce name) (Just genInfSig)
|
insertSig (coerce name) (Just genInfSig)
|
||||||
|
|
@ -354,6 +327,7 @@ checkCase expT brnchs = do
|
||||||
(subs, branchTs, injs, returns) <- unzip4 <$> mapM inferBranch brnchs
|
(subs, branchTs, injs, returns) <- unzip4 <$> mapM inferBranch brnchs
|
||||||
-- compose all probably wrong
|
-- compose all probably wrong
|
||||||
let sub0 = composeAll subs
|
let sub0 = composeAll subs
|
||||||
|
trace ("Substitutions: " ++ show subs) pure ()
|
||||||
(sub1, _) <-
|
(sub1, _) <-
|
||||||
foldM
|
foldM
|
||||||
( \(sub, acc) x ->
|
( \(sub, acc) x ->
|
||||||
|
|
@ -435,9 +409,9 @@ inferPattern = \case
|
||||||
( catchableErr $ Aux.do
|
( catchableErr $ Aux.do
|
||||||
"The constructor"
|
"The constructor"
|
||||||
quote $ printTree constr
|
quote $ printTree constr
|
||||||
" should have "
|
"should have"
|
||||||
show numArgs
|
show numArgs
|
||||||
" arguments but has been given "
|
"arguments but has been given"
|
||||||
show (length patterns)
|
show (length patterns)
|
||||||
)
|
)
|
||||||
fr <- fresh
|
fr <- fresh
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue