Power set: Difference between revisions

Content added Content deleted
(→‎{{header|Haskell}}: Fixed mismatch between a function name and its type signature name, added a point-free formulation)
Line 1,438: Line 1,438:
or
or
<lang Haskell>powerSet :: [a] -> [[a]]
<lang Haskell>powerSet :: [a] -> [[a]]
powerset = foldr (\x acc -> acc ++ map (x:) acc) [[]]</lang>
powerSet = foldr (\x acc -> acc ++ map (x:) acc) [[]]</lang>

which could also be understood, in point-free terms, as:
<lang haskell>powerSet :: [a] -> [[a]]
powerSet = foldr ((mappend <*>) . fmap . (:)) (pure [])</lang>

Examples:
Examples: