Anonymous user
List comprehensions: Difference between revisions
→{{header|Haskell}}: Add type signatures
(→{{header|Haskell}}: Explicitly import guard) |
(→{{header|Haskell}}: Add type signatures) |
||
Line 808:
=={{header|Haskell}}==
<lang haskell>pyth
pyth n = [(x,y,z) | x <- [1..n], y <- [x..n], z <- [y..n], x^2 + y^2 == z^2]
</lang>
List-comprehensions in Haskell are in fact syntactic sugar for do-notation, so the above is equivalent to the following:
Line 814 ⟶ 816:
<lang haskell>import Control.Monad (guard)
pyth :: (Enum t, Eq t, Num t) => t -> [(t, t, t)]
pyth n = do
x <- [1..n]
|