
19 Jul
2007
19 Jul
'07
7:02 a.m.
Dougal Stanton wrote:
I worked out that [ (a,b) | a <- as, b <- bs ] must be equivalent to
comp = concatMap (\x -> map ((,) x) ys) xs
but I can't really say how conditions like "a /= b" get slotted in to that style. Is there a reference for that?
Here's an example translation [ (a,b) | a <- as, b <- bs, a /= b ] = concatMap (\a -> [ (a,b) | b <- bs, a /= b ]) as = concatMap (\a -> concatMap (\b -> [ (a,b) | a /= b ]) bs) as = concatMap (\a -> concatMap (\b -> if a /= b then [(a,b)] else []) bs) as The exact specification can be found at http://www.haskell.org/onlinereport/exps.html#list-comprehensions Of course, this is not very different from monadic expressions in the []-monad. Regards, apfelmus