Add some type hints and print out any assumptions that escape type checking.

This commit is contained in:
evancz 2012-08-10 22:16:30 +02:00
parent 028d2eca51
commit 8810898c08
2 changed files with 21 additions and 5 deletions

View file

@ -12,7 +12,7 @@ import Control.Monad.State (evalState)
import Guid import Guid
import Types.Substitutions import Types.Substitutions
--import System.IO.Unsafe import System.IO.Unsafe
prints xs v = v --} unsafePerformIO (putStrLn "~~~~~~~~~~" >> mapM print xs) `seq` v prints xs v = v --} unsafePerformIO (putStrLn "~~~~~~~~~~" >> mapM print xs) `seq` v
@ -27,7 +27,8 @@ constrain hints (Module _ _ _ stmts) = do
assumptions <- foldM insert (unionsA ass) $ map fst (concat schemess) assumptions <- foldM insert (unionsA ass) $ map fst (concat schemess)
let cs = let f k s vs = map (\v -> Context k $ v :<<: s) vs in let cs = let f k s vs = map (\v -> Context k $ v :<<: s) vs in
concat . Map.elems $ Map.intersectionWithKey f allHints assumptions concat . Map.elems $ Map.intersectionWithKey f allHints assumptions
return $ cs ++ Set.toList (Set.unions css) let p = unsafePerformIO (mapM print . Map.toList $ Map.difference assumptions allHints)
seq p . return $ cs ++ Set.toList (Set.unions css)
gen :: Expr -> GuidCounter (Map.Map String [X], Set.Set (Context String Constraint), Type) gen :: Expr -> GuidCounter (Map.Map String [X], Set.Set (Context String Constraint), Type)

View file

@ -27,7 +27,9 @@ elements = let iee = int ==> element ==> element in
, "width" -: iee , "width" -: iee
, "height" -: iee , "height" -: iee
, "size" -: int ==> iee , "size" -: int ==> iee
, "color" -: color ==> element ==> element
, "box" -: iee , "box" -: iee
, "rectangle" -: int ==> int ==> element
, "rightedText" -: text ==> element , "rightedText" -: text ==> element
, "centeredText" -: text ==> element , "centeredText" -: text ==> element
, "justifiedText" -: text ==> element , "justifiedText" -: text ==> element
@ -196,8 +198,12 @@ funcs =
, "Nil" -:: listOf a , "Nil" -:: listOf a
, "Just" -:: a ==> maybeOf a , "Just" -:: a ==> maybeOf a
, "Nothing" -:: maybeOf a , "Nothing" -:: maybeOf a
, "elmRange" -:: int ==> int ==> listOf int , "curry" -:: (tupleOf [a,b] ==> c) ==> a ==> b ==> c
] , "uncurry" -:: (a ==> b ==> c) ==> tupleOf [a,b] ==> c
] ++ map tuple [0..8]
tuple n = ("Tuple" ++ show n, Forall [1..n] [] $ foldr (==>) (tupleOf vs) vs)
where vs = map VarT [1..n]
lists = lists =
[ "and" -:: listOf bool ==> bool [ "and" -:: listOf bool ==> bool
@ -232,11 +238,20 @@ lists =
] ++ map (numScheme (\n -> listOf n ==> n)) [ "sum", "product" ] ++ map (numScheme (\n -> listOf n ==> n)) [ "sum", "product"
, "maximum", "minimum" ] , "maximum", "minimum" ]
maybeFuncs =
[ "maybe" -:: b ==> (a ==> b) ==> maybeOf a ==> b
, "isJust" -:: maybeOf a ==> bool
, "isNothing" -:: maybeOf a ==> bool
, "fromMaybe" -:: a ==> maybeOf a ==> a
, "consMaybe" -:: maybeOf a ==> listOf a ==> listOf a
, "catMaybes" -:: listOf (maybeOf a) ==> listOf a
, "catMaybes" -:: (a ==> maybeOf b) ==> listOf a ==> listOf b
]
-------- Everything -------- -------- Everything --------
hints = mapM (\(n,s) -> (,) n `liftM` rescheme s) hs hints = mapM (\(n,s) -> (,) n `liftM` rescheme s) hs
where hs = concat [ funcs, lists, signals, math, bools, str2elem, textAttrs where hs = concat [ funcs, lists, signals, math, bools, str2elem, textAttrs
, elements, directions, colors, lineTypes, shapes , elements, directions, colors, lineTypes, shapes
, concreteSignals, casts, polyCasts, json , concreteSignals, casts, polyCasts, json, maybeFuncs
] ]