For efficiency reasons, Set
has an Ord
constraint, but 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)