on master help sign in
Merge pull request #3603 from SuprDewd/cast_whitespace

More lenient casting from string to number

commit119d964b75bf6a8b8a2f1f7c24450a4951cf26bc authorNiklas Larsson <metaniklas@gmail.com> dateThu 5 Jan 2017, 16:05 (10 years ago) parentd719f11fb4a909
1 file changed+4−4
src/Idris/Primitives.hs+4−4
src/Idris/Primitives.hs+4−4
@@ -455,8 +455,8 @@ getInt _ = []
455455
456456strToInt :: IntTy -> [Const] -> Maybe Const
457457strToInt ity [Str x] = case reads x of
458− [(n,"")] -> Just $ toInt ity (n :: Integer)
459− _ -> Just $ I 0
458+ [(n,s)] -> Just $ if all isSpace s then toInt ity (n :: Integer) else I 0
459+ _ -> Just $ I 0
460460strToInt _ _ = Nothing
461461
462462intToFloat :: [Const] -> Maybe Const
@@ -481,8 +481,8 @@ c_floatToStr :: [Const] -> Maybe Const
481481c_floatToStr [Fl x] = Just $ Str (show x)
482482c_floatToStr _ = Nothing
483483c_strToFloat [Str x] = case reads x of
484− [(n,"")] -> Just $ Fl n
485− _ -> Just $ Fl 0
484+ [(n,s)] -> Just $ Fl (if all isSpace s then n else 0)
485+ _ -> Just $ Fl 0
486486c_strToFloat _ = Nothing
487487
488488p_fPrim :: (Double -> Double) -> [Const] -> Maybe Const