From Thinking Functionally with Haskell, pg 67:
[...] list comprehensions are translated into equivalent definitions in
terms of map and concat. The translation rules are:
[e | True] = [e]
[e | q] = [e | q, True]
[e | b, Q] = if b then [e | Q] else []
[e | p <- xs, Q] = let ok p = [e | Q]
ok _ = []
in concat (map ok xs)
The author nowhere defines e, q, Q, or b. I take it that the first means "expression," but I've never seen the others before. Could someone please enlighten me?
This translation comes straight out of the official Haskell Report, which has this additional sentence:
where
eranges over expressions,pover patterns,lover list-valued expressions,bover boolean expressions,declsover declaration lists,qover qualifiers, andQover sequences of qualifiers.okis a fresh variable. The functionconcatMap, and boolean valueTrue, are defined in thePrelude.
If you wonder what any of those terms means, the Report has further details.
I would guess that:
BoolBool (this seems a bit strange, though, perhaps I'm wrong...)Right x, Just _, x@(y,z)Bool) or pattern matches, e.g x <- xs, Right x <- xs.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With