Last active
August 12, 2018 20:04
-
-
Save mvaldesdeleon/4d355cd27dcd3f6aab0a972a17adbeee to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
asInt :: String -> Either String Int | |
asInt ('-':xs) = negate <$> asInt xs | |
asInt xs = | |
foldl | |
(\acc x -> acc >>= addNextDigit x) | |
(Right 0) | |
xs | |
where addNextDigit x acc = if isDigit x | |
then Right $ acc * 10 + digitToInt x | |
else Left $ "non-digit" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment