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 n:: =(Enum [(xt,y,z) |Eq x <- [1..n]t, yNum <-t) [x..n],=> zt <-> [y..n](t, x^2t, + y^2 == z^2t)]</lang>
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]
Anonymous user