[Haskell-cafe] Implicit concatenation in list comprehensions

Neil Mitchell ndmitchell at gmail.com
Sun Jul 19 11:14:35 EDT 2009


Hi Max,

> For fun, I spent a few hours yesterday implement support for this
> syntax in GHC, originally propsed by Koen Claessen:
>
>>>> [k, "=", v, " " | (k, v) <- [("foo", "1"), ("bar", "2")]
> ["foo", "=", "1", " ", "bar", "=", "2", " "]
>
> This is a generalisation of list comprehensions that allows several
> items to be concatenated onto the result list at once, by having
> several comma-separated items before the pipe.

I like the power this feature gives, and if it was already in Haskell
98 I'd certainly have used it a few times. I can't think of anything
else the syntax could mean, so I don't see a potential for it stealing
syntax that might otherwise be reused. However, it doesn't seem that
discoverable or natural - I'm not sure I'd have ever guessed that such
a feature might exist.

> P.S. I also implemented tuple sections
> (http://hackage.haskell.org/trac/ghc/ticket/3377#comment:3) which are
> a lot more useful:

Yay! Discoverable, useful and really common in practice - a brilliant
extension :-)

Thanks

Neil


More information about the Haskell-Cafe mailing list