Better data stream reading in Haskell

Posted by Tim Perry on Stack Overflow See other posts from Stack Overflow or by Tim Perry
Published on 2010-05-19T18:46:17Z Indexed on 2010/05/19 18:50 UTC
Read the original article Hit count: 300

Filed under:
|
|

I am trying to parse an input stream where the first line tells me how many lines of data there are. I'm ending up with the following code, and it works, but I think there is a better way. Is there?

main = do
    numCases <- getLine
    proc $ read numCases

proc :: Integer -> IO ()
proc numCases
     | numCases == 0 = return ()
     | otherwise = do
         str <- getLine
         putStrLn $ findNextPalin str
         proc (numCases - 1)

Note: The code solves the Sphere problem https://www.spoj.pl/problems/PALIN/ but I didn't think posting the rest of the code would impact the discussion of what to do here.

© Stack Overflow or respective owner

Related posts about haskell

Related posts about input-stream