> > Generalised? Heck, I don't use list comprehension at all! :-P
> 
> Perhaps you should! :-)

You definitely should! Take a look at the Uniplate paper for some
wonderful concise uses of list comprehensions for abstract syntax tree
traversals. If you use a language like F# they become even more common -
due to a clunkier syntax for lambdas, less library functions and no
operator sections. In my F# I rarely use a map at all.

But my faviourite list comprehension trick was shown to me by Colin
Runciman:

prettyPrint b (lhs :+: rhs) = ['('|b] ++ f lhs ++ " + " ++ f rhs ++
[')'|b]

Imagine b represents whether something should be bracketed or not. In
general:

if boolean then [value] else []

Can be written as:

[value | boolean]

Thanks

Neil

==============================================================================
Please access the attached hyperlink for an important electronic communications 
disclaimer: 

http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html
==============================================================================

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to