[Haskell-cafe] Language extensions

Tomasz Zielonka tomasz.zielonka at gmail.com
Thu May 31 03:25:55 EDT 2007


On Wed, May 30, 2007 at 05:12:48PM +0200, Henk-Jan van Tuyl wrote:
> On Wed, 30 May 2007 09:38:10 +0200, Tomasz Zielonka  
> <tomasz.zielonka at gmail.com> wrote:
> >On Tue, May 29, 2007 at 09:43:03PM +0100, Andrew Coppin wrote:
> >>Henning Thielemann wrote:
> >>>On Sun, 27 May 2007, Andrew Coppin wrote:
> >>>>But every now and then I discover an expression which is
> >>>>apparently  not expressible without them - which is odd,
> >>>>considering they're only "sugar"...
> >>>
> >>>Example?
> >>
> >>Until I learned the trick of using lists as monads, I was utterly
> >>perplexed as to how to get a Cartesian product
> >
> >This is far from not expressible:
> >    cart xs ys = concatMap (\x -> map ((,) x) ys) xs
> 
> A bit simpler is:
>   cart xs ys = [(x, y) | x <- xs, y <- ys]
> 
> or:
>   cart xs ys =
>     do
>       x <- xs
>       y <- ys
>       return (x, y)

I was responding to Andrew saying that computing cartesian product is
apparently not expressible without list comprehensions.

Best regards
Tomek


More information about the Haskell-Cafe mailing list