List comprehensions: Difference between revisions
→{{header|Haskell}}: Side-stepped imports in Do notation and desugared code
m (→{{header|Haskell}}: (white space adjustment)) |
(→{{header|Haskell}}: Side-stepped imports in Do notation and desugared code) |
||
Line 822:
List-comprehensions and do notation are two alternative and equivalent forms of syntactic sugar in Haskell.
The list comprehension above could be re-sugared in Do notation as:
<lang haskell>
pyth n = do
x <- [1 .. n]
y <- [x .. n]
z <- [y .. n]
else []</lang>
and both of the above could be de-sugared to:
<lang haskell>
pyth n =
[1 .. n] >>=
Line 846 ⟶ 843:
\z ->
case x ^ 2 + y ^ 2 == z ^ 2 of
True ->
which can be further specialised (given the particular context of the list monad, in which (>>=) is flip concatMap, pure is flip (:) [], and empty is []) to:
|