[Haskell-cafe] generalized list comprehensions

Duncan Coutts duncan.coutts at worc.ox.ac.uk
Mon Nov 10 13:51:34 EST 2008


On Mon, 2008-11-10 at 18:19 +0000, Andrew Coppin wrote:

> I don't actually use *lists* all that much - or at least not list 
> transformations. And if I'm going to do something complicated, I'll 
> usually write it as a do-expression rather than a comprehension.
> 
> > Just a random example out of Cabal:
> >
> > warn verbosity $
> >      "This package indirectly depends on multiple versions of the same "
> >   ++ "package. This is highly likely to cause a compile failure.\n"
> >   ++ unlines [ "package " ++ display pkg ++ " requires "
> >             ++ display (PackageIdentifier name ver)
> >              | (name, uses) <- inconsistencies
> >              , (pkg, ver) <- uses ]
> >
> > Pretty concise and clear I think.
> >   
> 
> Erm... yeah, it's not too bad once I change all the formatting to make 
> it clear what's what.
> 
> Wouldn't it be a lot easier as a do-block though?

I don't think so:

   ++ unlines $ do
        (name, uses) <- inconsistencies
        (pkg, ver) <- uses
        return $ "package " ++ display pkg ++ " requires "
              ++ display (PackageIdentifier name ver)

Of course reasonable people may disagree. It's mostly aesthetics.

Duncan



More information about the Haskell-Cafe mailing list