Anonymous user
List comprehensions: Difference between revisions
Haskell: Fixed missing n; added do-notation variant
m (Added missing parenthesis) |
(Haskell: Fixed missing n; added do-notation variant) |
||
Line 7:
=={{header|Haskell}}==
pyth n = [(x,y,z) | x <- [1..
Since lists are [[Monads]], one can alternatively also use the do-notation (which is practical if the comprehension is large):
import Control.Monad
pyth n = do
x <- [1..n]
y <- [x..n]
z <- [y..n]
guard $ x^2 + y^2 == z^2
return (x,y,z)
=={{header|Python}}==
|