
28 Feb
2006
28 Feb
'06
6:52 a.m.
Johannes Waldmann
In Haskell, this is called 'fmap'. :-)
OK, then show me an "instance Functor Set" so that I can use it :-)
instance Function Set where fmap = Data.Set.mapMonotonic Ok, so this introduces a precondition on the function being mapped, so there is a proof obligation on the programmer. But if contexts-on-datatypes worked correctly, data Set a = Ord a => .... then even the "real" map from Data.Set: map :: (Ord a, Ord b) => (a -> b) -> Set a -> Set b could be an instance method of Functor. (Because the Ord constraints would be packaged inside the Set type, rather than needing to be explicit.) Regards, Malcolm