Last active
August 29, 2015 14:08
-
-
Save Deraen/85a30c867c7ec9d9c823 to your computer and use it in GitHub Desktop.
Some Haskell excercises
This file contains 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
#!/usr/bin/env runhaskell | |
import System.IO | |
import Control.Monad | |
import qualified Data.Text as T | |
splitLines :: String -> [String] | |
splitLines s = map T.unpack $ T.splitOn (T.pack ",") $ T.pack s | |
readNumbers :: [String] -> [Int] | |
readNumbers = map (\x -> read x :: Int) | |
lineSum :: String -> Int | |
lineSum s = sum $ readNumbers $ splitLines s | |
mainloop :: Handle -> IO () | |
mainloop inh = do | |
eof <- hIsEOF inh | |
unless eof $ do | |
z <- getLine | |
print $ lineSum z | |
mainloop inh | |
main :: IO () | |
main = mainloop System.IO.stdin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment