[Haskell-cafe] Rotating backdrop (aka learning Haskell)
Yann Golanski
yann at kierun.org
Wed May 21 05:20:13 EDT 2008
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 <yann at kierun.org> 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?
--
yann at kierun.org -= H+ =- www.kierun.org
PGP: 009D 7287 C4A7 FD4F 1680 06E4 F751 7006 9DE2 6318
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20080521/aefcc7a5/attachment.bin
More information about the Haskell-Cafe
mailing list