Match digitsToInt to simpler Rust version

This commit is contained in:
George Thomas 2025-12-13 11:24:46 +00:00
parent dbeac46212
commit 6ca7b4eac8

View File

@ -102,7 +102,7 @@ digit :: (Token s ~ Char, Num b, MonadParsec e s f) => f b
digit = fromIntegral . digitToInt <$> digitChar
digitsToInt :: (Integral a) => [a] -> Int
digitsToInt = snd . foldr (\b (p, acc) -> (10 * p, acc + fromIntegral b * p)) (1, 0)
digitsToInt = foldl' (\acc d -> acc * 10 + fromIntegral d) 0
listIndex :: Int -> [a] -> Maybe a
listIndex n =