From TKwiki
import Char
type Parser a = String -> Maybe (a, String)
parseInt :: Parser Int
parseInt [] = Nothing
parseInt (x:xs)
| isNumeric x = let (cislo, zbytek) = (parseInt' (x:xs) 0) in Just ( cislo , zbytek )
| otherwise = Nothing
where
parseInt' :: String -> Int -> ( Int , String )
parseInt' [] a = ( a, [] )
parseInt' (x:xs) a
| toNum x == Nothing = (a, (x:xs) )
| otherwise = let Just y = toNum x in parseInt' xs ((a*10)+y)
toNum :: Char -> Maybe Int
toNum x
| isNumeric x = Just ( ord(x) - ord('0') )
| otherwise = Nothing
isNumeric :: Char -> Bool
isNumeric x
| ((ord(x)>=ord('0')) && ( ord(x)<=ord('9') )) = True
| otherwise = False