on master help sign in
Fix discrepancy in behaviour of run-time and complile-time str-to-int implementations
commit7171465e2acca7b8daa1c589b81bd17ef0619399 authorIlya Rezvov <ilya.rezvov@revjet.com> dateSun 3 Jun 2018, 11:04 (8 years ago) parent3a2f57e
1 file changed+5−1
src/Idris/Primitives.hs+5−1
src/Idris/Primitives.hs+5−1
@@ -416,9 +416,13 @@ getInt (BI x : xs) = x : getInt xs
416416getInt _ = []
417417
418418strToInt :: IntTy -> [Const] -> Maybe Const
419−strToInt ity [Str x] = case reads x of
419+strToInt ity [Str x] = case reads $ dropFirstPlus x of
420420 [(n,s)] -> Just $ if all isSpace s then toInt ity (n :: Integer) else I 0
421421 _ -> Just $ I 0
422+ where
423+ dropFirstPlus :: String -> String
424+ dropFirstPlus ('+' : str) = str
425+ dropFirstPlus str = str
422426strToInt _ _ = Nothing
423427
424428intToFloat :: [Const] -> Maybe Const