[Haskell-cafe] Re: Practise fingerspelling with Haskell! (Code
cleanup request)
apfelmus
apfelmus at quantentunnel.de
Thu Jul 19 07:02:19 EDT 2007
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
More information about the Haskell-Cafe
mailing list