List comprehensions: Difference between revisions

Content deleted Content added
Hout (talk | contribs)
→‎{{header|AppleScript}}: Updated primitives
Hout (talk | contribs)
→‎{{header|Haskell}}: Used mzero rather than [] in immediate desugaring
Line 835: Line 835:


and both of the above could be de-sugared to:
and both of the above could be de-sugared to:
<lang haskell>pyth :: Int -> [(Int, Int, Int)]
<lang haskell>import Control.Monad (mzero)

pyth :: Int -> [(Int, Int, Int)]
pyth n =
pyth n =
[1 .. n] >>=
[1 .. n] >>=
Line 845: Line 847:
case x ^ 2 + y ^ 2 == z ^ 2 of
case x ^ 2 + y ^ 2 == z ^ 2 of
True -> return (x, y, z)
True -> return (x, y, z)
False -> [])))</lang>
False -> mzero)))</lang>


which can be further specialised (given the particular context of the list monad, in which >>= is concatMap) to:
which can be further specialised (given the particular context of the list monad, in which >>= is concatMap) to: