
1 Jul
2010
1 Jul
'10
11:17 a.m.
Hi As Benjamin Edwards says you want to be in the IO monad as you are using a file handle Something like this - note the last two lines have changed a bit to accommodate the computation being in the IO monad rather than pure, if you have very large input data you might need to put this in tail recursive form. readNames :: Int -> Handle -> IO [String] readNames 0 _ = return [] -- add a return, to lift the answer into IO readNames n h = do length <- fmap (fromIntegral . runGet getWord32be) $ L.hGet h 4 name <- L.hGet h length rest <- readNames (n-1) h return ((UTF.toString name) : rest)