Skip to content

Instantly share code, notes, and snippets.

@rangalo
Created January 20, 2010 09:25
Show Gist options
  • Save rangalo/281722 to your computer and use it in GitHub Desktop.
Save rangalo/281722 to your computer and use it in GitHub Desktop.
-- file: ch04/IntParse.hs
import Data.Char (digitToInt)
strToInt :: String -> Int
helper_func :: Int -> Char -> Int
helper_func i c = i * 10 + digitToInt c
strToInt ('-':cs) = (-1) * strToInt(cs)
strToInt cs = foldl helper_func 0 cs
strToInt [] = 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment