Quoth Derek Elkins on Tue, May 20, 2008 at 11:45:57 -0500
> 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

I'm sorry, this is a little beyond me.  Could you elaborate a little
more on what this actually does?

-- 
[EMAIL PROTECTED]             -= H+ =-             www.kierun.org
   PGP:   009D 7287 C4A7 FD4F 1680  06E4 F751 7006 9DE2 6318

Attachment: pgpRApk90uNyx.pgp
Description: PGP signature

_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to