List comprehensions: Difference between revisions

→‎{{header|Haskell}}: (pure and empty in lieu of return and mzero)
(→‎{{header|Haskell}}: (pure and empty in lieu of return and mzero))
Line 835:
 
and both of the above could be de-sugared to:
<lang haskell>import Control.MonadApplicative (mzeroempty)
 
pyth :: Int -> [(Int, Int, Int)]
Line 845:
[y .. n] >>=
\z ->
case (((x ^ 2) + (y ^ 2)) == (z ^ 2)) of
True -> returnpure (x, y, z)
False -> mzeroempty</lang>
 
which can be further specialised (given the particular context of the list monad, in which >>= is concatMap, pure is flip (:) [], and empty is []) to:
 
<lang haskell>pyth :: Int -> [(Int, Int, Int)]
9,659

edits