Distinct power numbers: Difference between revisions

m
→‎{{header|Haskell}}: A variation on liftA2
m (→‎{{header|Haskell}}: A variation on liftA2)
Line 378:
(\xs -> [x ^ y | x <- xs, y <- xs]) [2 .. 5]</lang>
 
or a liftA2 expression:
<lang haskell>import Control.Applicative (liftA2)
import Control.Monad (join)
Line 389:
(liftA2 (^))
[2 .. 5]</lang>
 
which can always be reduced (shedding imports) to the pattern:
<lang haskell>import qualified Data.Set as S
 
main :: IO ()
main =
(print . S.elems . S.fromList) $
(\xs -> (^) <$> xs <*> xs)
[2 .. 5]</lang>
 
{{Out}}
<pre>[4,8,9,16,25,27,32,64,81,125,243,256,625,1024,3125]</pre>
9,655

edits