[Haskell-cafe] The container problem

Jonathan Cast jonathanccast at fastmail.fm
Fri Sep 26 18:27:03 EDT 2008


On Fri, 2008-09-26 at 15:25 -0700, Jason Dusek wrote:
> Can someone explain, why is it that Set can not be a Monad?

It can't even be a functor (which all monads are).  You can't implement

    fmap (+) $ Set.fromList [1, 2, 3]

with Data.Set, because you can't order functions of type Integer ->
Integer in a non-arbitrary way.  So you can't have a balanced binary
tree of them in a non-arbitrary way, either.  Something like

    fmap putStrLn $ Set.fromList ["Hello", "world"]

is similar.

Since Data.Set is implemented in Haskell, it can only use facilities
available to Haskell libraries.  So it can't work for arbitrary
elements; but a Functor instance requires that it does work.

jcc




More information about the Haskell-Cafe mailing list