From dd1b3d4d7c8dd7bbffd2e1f5c20c4d018b55ba74 Mon Sep 17 00:00:00 2001 From: Evan Czaplicki Date: Fri, 21 Feb 2014 16:21:00 -0500 Subject: [PATCH] Restrict list interpolation to numbers! --- compiler/Type/Constrain/Expression.hs | 8 ++++---- compiler/Type/Type.hs | 5 +++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/compiler/Type/Constrain/Expression.hs b/compiler/Type/Constrain/Expression.hs index 21389e5..aa5df70 100644 --- a/compiler/Type/Constrain/Expression.hs +++ b/compiler/Type/Constrain/Expression.hs @@ -36,10 +36,10 @@ constrain env (A region expr) tipe = | otherwise -> return (name - exists $ \x -> do - clo <- constrain env lo x - chi <- constrain env hi x - return $ and [clo, chi, list x === tipe] + existsNumber $ \n -> do + clo <- constrain env lo n + chi <- constrain env hi n + return $ and [clo, chi, list n === tipe] ExplicitList exprs -> exists $ \x -> do diff --git a/compiler/Type/Type.hs b/compiler/Type/Type.hs index 023ecd3..55ec193 100644 --- a/compiler/Type/Type.hs +++ b/compiler/Type/Type.hs @@ -141,6 +141,11 @@ exists f = do v <- liftIO $ var Flexible ex [v] <$> f (VarN v) +existsNumber :: Error e => (Type -> ErrorT e IO TypeConstraint) -> ErrorT e IO TypeConstraint +existsNumber f = do + v <- liftIO $ var (Is Number) + ex [v] <$> f (VarN v) + instance Show a => Show (UF.Point a) where show point = unsafePerformIO $ fmap show (UF.descriptor point)