STRING CONVERSION TO INTEGER IN HASKELL

I started to learn Haskell not long time ago. Once I needed function that converts string to integer like atoi in C/C++. I did search but I didn't find what I needed. So, I decided to implement such function in Haskell. Here I presend two versions of this function: strToInt and strToInt2. strToInt uses two foldl calls and strToInt2 uses one foldr.

module StringUtils ( strToInt, strToInt2 ) where import Data.Char strToInt :: String -> Int strToInt s = sum ( zipWith (*) ( foldl(\acc x -> acc ++ [ ord x - ord '0' ] ) [] s ) ( tail $ foldl(\acc x -> ( 10 * head acc ) : acc ) [1] s ) ) strToInt2 :: String -> Int strToInt2 s = fst ( last ( foldr(\x acc -> acc ++ [( fst ( last acc ) + (ord x - ord '0') * snd ( last acc ), 10 * snd ( last acc ) )] ) [(0,1)] s ) ) |