on master help sign in
Add some type hints and print out any assumptions that escape type checking.
commit8810898c0836cd84c99a01ef339a7a8ece908bcd authorevancz <info@elm-lang.org> dateFri 10 Aug 2012, 22:16 (14 years ago) parent028d2ec
2 files changed+21−5
elm/src/Types/Constrain.hs+3−2 elm/src/Types/Hints.hs+18−3
elm/src/Types/Constrain.hs+3−2
@@ -12,7 +12,7 @@ import Control.Monad.State (evalState)
1212import Guid
1313import Types.Substitutions
1414
15−--import System.IO.Unsafe
15+import System.IO.Unsafe
1616
1717prints xs v = v --} unsafePerformIO (putStrLn "~~~~~~~~~~" >> mapM print xs) `seq` v
1818
@@ -27,7 +27,8 @@ constrain hints (Module _ _ _ stmts) = do
2727 assumptions <- foldM insert (unionsA ass) $ map fst (concat schemess)
2828 let cs = let f k s vs = map (\v -> Context k $ v :<<: s) vs in
2929 concat . Map.elems $ Map.intersectionWithKey f allHints assumptions
30− return $ cs ++ Set.toList (Set.unions css)
30+ let p = unsafePerformIO (mapM print . Map.toList $ Map.difference assumptions allHints)
31+ seq p . return $ cs ++ Set.toList (Set.unions css)
3132
3233gen :: Expr -> GuidCounter (Map.Map String [X], Set.Set (Context String Constraint), Type)
3334
elm/src/Types/Hints.hs+18−3
@@ -27,7 +27,9 @@ elements = let iee = int ==> element ==> element in
2727 , "width" -: iee
2828 , "height" -: iee
2929 , "size" -: int ==> iee
30+ , "color" -: color ==> element ==> element
3031 , "box" -: iee
32+ , "rectangle" -: int ==> int ==> element
3133 , "rightedText" -: text ==> element
3234 , "centeredText" -: text ==> element
3335 , "justifiedText" -: text ==> element
@@ -196,8 +198,12 @@ funcs =
196198 , "Nil" -:: listOf a
197199 , "Just" -:: a ==> maybeOf a
198200 , "Nothing" -:: maybeOf a
199− , "elmRange" -:: int ==> int ==> listOf int
200− ]
201+ , "curry" -:: (tupleOf [a,b] ==> c) ==> a ==> b ==> c
202+ , "uncurry" -:: (a ==> b ==> c) ==> tupleOf [a,b] ==> c
203+ ] ++ map tuple [0..8]
204+
205+tuple n = ("Tuple" ++ show n, Forall [1..n] [] $ foldr (==>) (tupleOf vs) vs)
206+ where vs = map VarT [1..n]
201207
202208lists =
203209 [ "and" -:: listOf bool ==> bool
@@ -232,11 +238,20 @@ lists =
232238 ] ++ map (numScheme (\n -> listOf n ==> n)) [ "sum", "product"
233239 , "maximum", "minimum" ]
234240
241+maybeFuncs =
242+ [ "maybe" -:: b ==> (a ==> b) ==> maybeOf a ==> b
243+ , "isJust" -:: maybeOf a ==> bool
244+ , "isNothing" -:: maybeOf a ==> bool
245+ , "fromMaybe" -:: a ==> maybeOf a ==> a
246+ , "consMaybe" -:: maybeOf a ==> listOf a ==> listOf a
247+ , "catMaybes" -:: listOf (maybeOf a) ==> listOf a
248+ , "catMaybes" -:: (a ==> maybeOf b) ==> listOf a ==> listOf b
249+ ]
235250
236251-------- Everything --------
237252
238253hints = mapM (\(n,s) -> (,) n `liftM` rescheme s) hs
239254 where hs = concat [ funcs, lists, signals, math, bools, str2elem, textAttrs
240255 , elements, directions, colors, lineTypes, shapes
241− , concreteSignals, casts, polyCasts, json
256+ , concreteSignals, casts, polyCasts, json, maybeFuncs
242257 ]