List comprehensions: Difference between revisions

→‎{{header|Haskell}}: Replaced a red link with an external link to the Haskell Wiki.
(add Tcl)
(→‎{{header|Haskell}}: Replaced a red link with an external link to the Haskell Wiki.)
Line 88:
 
=={{header|Haskell}}==
<lang haskell>pyth n = [(x,y,z) | x <- [1..n], y <- [x..n], z <- [y..n], x^2 + y^2 == z^2]</lang>
 
Since lists are [[Monads]http://haskell.org/haskellwiki/Monad monads], one can alternatively also use the do-notation (which is practical if the comprehension is large):
pyth n = [(x,y,z) | x <- [1..n], y <- [x..n], z <- [y..n], x^2 + y^2 == z^2]
 
<lang haskell>import Control.Monad
Since lists are [[Monads]], one can alternatively also use the do-notation (which is practical if the comprehension is large):
 
pyth n = do
import Control.Monad
zx <- [y1..n]
y <- [x..n]
pyth n = do
xz <- [1y..n]
guard $ x^2 + y^2 <-== [x..n]z^2
return (x,y,z)</lang>
z <- [y..n]
guard $ x^2 + y^2 == z^2
return (x,y,z)
 
=={{header|Mathematica}}==
845

edits