Distinct power numbers: Difference between revisions
Content added Content deleted
m (→{{header|Haskell}}: A variation on liftA2) |
|||
Line 378: | Line 378: | ||
(\xs -> [x ^ y | x <- xs, y <- xs]) [2 .. 5]</lang> |
(\xs -> [x ^ y | x <- xs, y <- xs]) [2 .. 5]</lang> |
||
or liftA2 expression: |
or a liftA2 expression: |
||
<lang haskell>import Control.Applicative (liftA2) |
<lang haskell>import Control.Applicative (liftA2) |
||
import Control.Monad (join) |
import Control.Monad (join) |
||
Line 389: | Line 389: | ||
(liftA2 (^)) |
(liftA2 (^)) |
||
[2 .. 5]</lang> |
[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}} |
{{Out}} |
||
<pre>[4,8,9,16,25,27,32,64,81,125,243,256,625,1024,3125]</pre> |
<pre>[4,8,9,16,25,27,32,64,81,125,243,256,625,1024,3125]</pre> |