@@ -22,17 +22,27 @@ beta = VarT `liftM` guid
2222unionA = Map.unionWith (++)
2323unionsA = Map.unionsWith (++)
2424
25+getAliases :: [(String,ImportMethod)] -> [(String,Scheme)] -> [(String,Scheme)]
2526getAliases imports hints = concatMap aliasesFrom imports
26− where aliasesFrom (name,method) =
27− let values = concatMap (getValue name) hints
28− in case method of
29− As alias -> map (\(n,t) -> (alias ++ "." ++ n, t)) values
30− Hiding vs -> filter (\(n,t) -> n `notElem` vs) values
31− Importing vs -> filter (\(n,t) -> n `elem` vs) values
32− getValue inModule (name,tipe) =
33− case inModule `isPrefixOf` name of
34− True -> [ (drop (length inModule + 1) name, tipe) ]
35− False -> []
27+ where
28+ -- Get the names of values that are now in scope after a particular
29+ -- import statement.
30+ aliasesFrom :: (String,ImportMethod) -> [(String,Scheme)]
31+ aliasesFrom (name,method) =
32+ let values = concatMap (getValue name) hints
33+ prefixed name = map (\(n,t) -> (name ++ "." ++ n, t)) values
34+ in case method of
35+ As alias -> prefixed alias
36+ Hiding vs -> prefixed name ++ filter (\(n,t) -> n `notElem` vs) values
37+ Importing vs -> prefixed name ++ filter (\(n,t) -> n `elem` vs) values
38+
39+ -- Take a module name and a type annotation. Return the unprefxed
40+ -- type annotation: getValue "List" ("List.map",t) == [("map",t)]
41+ getValue :: String -> (String,Scheme) -> [(String,Scheme)]
42+ getValue inModule (name,tipe) =
43+ case inModule `isPrefixOf` name of
44+ True -> [ (drop (length inModule + 1) name, tipe) ]
45+ False -> []
3646
3747findAmbiguous hints assumptions continue =
3848 let potentialDups = map head . filter (\g -> length g > 1) . group . sort $
@@ -74,10 +84,11 @@ constrain typeHints (Module _ _ imports stmts) = do
7484 let f k s vs = map (\v -> C (Just k) NoSpan $ v :<<: s) vs
7585 cs = concat . Map.elems $ Map.intersectionWithKey f allHints assumptions
7686 escapees = Map.keys $ Map.difference assumptions allHints
87+ msg = "Warning! Type-checker could not find variables:\n" ++ intercalate ", " escapees
7788 return $ case escapees of
7889 [] -> Right (Set.toList constraints ++ cs)
79− _ -> unsafePerformIO (print escapees) `seq` Right (Set.toList constraints ++ cs)
80− _ -> Left ("Undefined variable(s): " ++ intercalate ", " escapees)
90+ _ -> unsafePerformIO (putStrLn msg) `seq` Right (Set.toList constraints ++ cs)
91+ --_ -> Left ("Undefined variable(s): " ++ intercalate ", " escapees)
8192
8293type TVarMap = Map.Map String [X]
8394type ConstraintSet = Set.Set (Context Constraint)