Skip to content

Instantly share code, notes, and snippets.

@Deraen
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Deraen/85a30c867c7ec9d9c823 to your computer and use it in GitHub Desktop.
Save Deraen/85a30c867c7ec9d9c823 to your computer and use it in GitHub Desktop.
Some Haskell excercises
#!/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