Duncan Coutts wrote:
On Sun, 2008-11-09 at 19:18 +0000, Andrew Coppin wrote:
Generalised? Heck, I don't use list comprehension at all! :-P
Perhaps you should! :-)
When I first started with Haskell I kind of had the idea that list
comprehensions were just for beginners and that 'real' hackers used just
concatMaps and filters.
A couple years later I 'rediscovered' list comprehensions and I now use
them frequently. There are many cases in real programs where simple and
not-so-simple list comprehensions are the clearest way of expressing the
solution. In particular the easy support for refutable pattern matching
in the generators allows some succinct and clear code.
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?
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe