on master help sign in
Print out a bunch of extra information about type checking.
commit6fc30322ce906959b0b7df7aa3abd2a7b77d50cf authorevancz <info@elm-lang.org> dateSun 9 Jun 2013, 11:15 (13 years ago) parent3e45d8e
4 files changed+18−6
Elm.cabal−1 compiler/Types/Constrain.hs+5−2 compiler/Types/Types.hs+2−1 compiler/Types/Unify.hs+11−2
Elm.cabal−1
@@ -86,7 +86,6 @@ Library
8686Executable elm
8787 Main-is: Compiler.hs
8888 Hs-Source-Dirs: compiler, compiler/Gen, compiler/Model, compiler/Transform
89− ghc-options: -rtsopts -prof -auto-all -caf-all
9089 other-modules: Ast,
9190 Located,
9291 CompileToJS,
compiler/Types/Constrain.hs+5−2
@@ -71,6 +71,9 @@ mergeSchemes schmss = do (ass,css,sss) <- unzip3 `liftM` mapM split kvs
7171 [] -> []
7272 , Map.fromList ps )
7373
74+--constrain :: Map.Map String Scheme
75+-- -> Module
76+-- -> GuidCounter (Either String Constraints)
7477constrain typeHints (Module _ _ imports stmts) = do
7578 (ass,css,schemess) <- unzip3 `liftM` mapM stmtGen stmts
7679 aliasHints <- getAliases imports `liftM` typeHints
@@ -86,8 +89,8 @@ constrain typeHints (Module _ _ imports stmts) = do
8689 escapees = Map.keys $ Map.difference assumptions allHints
8790 msg = "Warning! Type-checker could not find variables:\n" ++ intercalate ", " escapees
8891 return $ case escapees of
89− [] -> Right (constraints ++ cs)
90− _ -> unsafePerformIO (putStrLn msg) `seq` Right (constraints ++ cs)
92+ [] -> Right (schemess, constraints ++ cs)
93+ _ -> unsafePerformIO (putStrLn msg) `seq` Right (schemess, constraints ++ cs)
9194 --_ -> Left ("Undefined variable(s): " ++ intercalate ", " escapees)
9295
9396type TVarMap = Map.Map String [X]
compiler/Types/Types.hs+2−1
@@ -18,7 +18,8 @@ data Type = LambdaT Type Type
1818 | Super (Set.Set Type)
1919 deriving (Eq, Ord, Data, Typeable)
2020
21−data Scheme = Forall [X] [Located Constraint] Type deriving (Eq, Ord, Show, Data, Typeable)
21+data Scheme = Forall [X] [Located Constraint] Type
22+ deriving (Eq, Ord, Show, Data, Typeable)
2223
2324data Constraint = Type :=: Type
2425 | Type :<: Type
compiler/Types/Unify.hs+11−2
@@ -10,7 +10,16 @@ import qualified Types.Constrain as Constrain
1010import qualified Types.Solver as Solver
1111import qualified Types.Alias as Alias
1212
13+import qualified Types.Substitutions as Subst
14+import System.IO.Unsafe
15+import Control.Arrow (second)
16+
1317unify hints modul@(Module _ _ _ stmts) = run $ do
14− constraints <- Constrain.constrain hints modul
15− either (return . Left) (Solver.solver (Alias.get stmts) Map.empty) constraints
18+ result <- Constrain.constrain hints modul
19+ case result of
20+ Left err -> return (Left err)
21+ Right (schemes, constraints) ->
22+ do subs <- Solver.solver (Alias.get stmts) Map.empty constraints
23+ let ss = either (const []) Map.toList subs
24+ unsafePerformIO (mapM print . map (second (Subst.subst ss)) $ concatMap Map.toList schemes) `seq` return subs
1625