On Fri, Jul 17, 2009 at 1:35 AM, Thomas Hartman <tphya...@gmail.com> wrote:
> on haskell reddit today
> powerSet = filterM (const [True, False])
The M is the list, i.e. *nondeterminism* monad. For each element in the
list, there is one return value where it appears (True), and one where it
does not (False).
Basically, regular filter says that for each element in the list, we need to
make a choice as to whether it occurs in the result. Here we use
nondeterminism to make both choices.
> is said to be beautiful / mind blowing. I just don't get it. I can
> play with transformations until I get
> powerSet  = []
> powerSet (x:xs) =
> let pxs = powerSet xs
> in map (x:) pxs ++ pxs
> which is understandable to me, but no matter how long I look at the
> original filterM definition it just doesn't click.
> Is this a uniquely haskell obfu, or is there a way of reading this
> definition that makes sense?
> If anybody agrees with me, care to throw out other examples of
> "obfuscated haskell considered harmful"?
> Haskell-Cafe mailing list
Haskell-Cafe mailing list