On Tue, 2008-05-20 at 10:55 +0200, Ketil Malde wrote: > Yann Golanski <[EMAIL PROTECTED]> writes: > > > 1- Get a list out of a file: I managed to do that using the following: > > > > parseImageFile :: FilePath -> IO [String] > > parseImageFile file = do inpStr <- readFile file > > return $ filter (/="") (breaks (=='\n') inpStr) > > > > Nice, simple and I understand what it is doing. > > Can be improved: > > breaks (=='\n') == lines -- easier to read, no? > filter (/="") == filter (not . null) -- more polymorphic, not important > here > do x <- expr1 == expr1 >>= return . expr2 > return $ expr2 x -- i.e. "readFile f >>= return . filter (not.null) > . lines"
do x <- expr1; return $ expr2 x == expr1 >>= return . expr2 == liftM expr2 expr1 -- or fmap (a.k.a. <$>) if you like So, liftM (filter (not . null) . lines) readFile alternatively, filter (not . null) . lines <$> readFile _______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
