Reputation: 2151
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?
Upvotes: 3
Views: 305
Reputation: 152857
This translation comes straight out of the official Haskell Report, which has this additional sentence:
where
e
ranges over expressions,p
over patterns,l
over list-valued expressions,b
over boolean expressions,decls
over declaration lists,q
over qualifiers, andQ
over sequences of qualifiers.ok
is 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.
Upvotes: 6
Reputation: 2151
I would guess that:
Bool
Bool
(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
.Upvotes: 3