# Why Data.Set (containers) doesn't have Functor and Monad instance?

**URL:** <https://discourse.haskell.org/t/why-data-set-containers-doesnt-have-functor-and-monad-instance/832>\
**Category:** Learn\
**Created:** [August 7, 2019, 8:53am UTC](https://discourse.haskell.org/t/why-data-set-containers-doesnt-have-functor-and-monad-instance/832 "2019-08-07T08:53:09Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![f-a](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/f-a/32/2740_2.png) [@f-a](https://discourse.haskell.org/u/f-a)\
**Post date:** [August 7, 2019, 10:04am UTC](https://discourse.haskell.org/t/why-data-set-containers-doesnt-have-functor-and-monad-instance/832/2 "2019-08-07T10:04:24Z")

</div>

For efficiency reasons, `Set` has an `Ord` constraint, but [Functor](http://hackage.haskell.org/package/base-4.12.0.0/docs/Data-Functor.html#t:Functor) has not!

On top of that, even if the `Ord` constraint were not a problem, `Set` would still not satisfy

```
fmap (f . g) == fmap f . fmap g

```

for some peculiar `Eq` instances. E.g.:

```
import Data.Set as S

newtype A = A Double
    deriving Show

instance Eq A where
    (A a) == (A b) = round a == round b

instance Ord A where
    (A a) <= (A b) = a <= b

prova :: Set A
prova = fromList [A 11, A 12]

main = do
        print (S.map f . S.map g $ prova)
        print (S.map (f . g) prova)
        putStrLn "Ooops!"
    where
        f (A n) = A (n * 10)
        g (A n) = A (n / 10)
```

---

_[View the full topic](https://discourse.haskell.org/t/why-data-set-containers-doesnt-have-functor-and-monad-instance/832)._
