One-line definition of the power set function

If you thought the one-line definition of the Fibonacci sequence in Haskell was beautiful, try this:


import Control.Monad
powerset :: [a] -> [[a]]
powerset = filterM (const [True, False])

A black box for sure, unless you have “internalized the list monad“. But it does show how stonkingly powerful monads are.

Leave a Reply