How to make Data.Set.Set a Functor
lnagy at fit.edu
Tue Oct 11 12:16:23 EDT 2005
While working on a toy compiler I realized that Data.Set.Set (Set) is not
an instance of the Functor class. In other words: 'fmap' is not defined
on it. I tried various ways of defining an instance but I failed. The
reason is quite interesting: Set is a type constructor (* -> *) so it
should qualify it for being a Functor. (In a sense it is very similar to
a Map or a list.) However, most Set functions require the elements of the
Set to be an instance of Ord. The problem is that this constraint cannot
be deduced from the instance declaration for Functor:
instance Functor Data.Set.Set where
fmap f s = Data.Set.map f s
Could not deduce (Ord a, Ord b) from the context (Functor
arising from use of `Data.Set.map' at ...
Probable fix: add (Ord a, Ord b) to the class or instance method
In the definition of `fmap': fmap f s = Data.Set.map f s
In the definition for method `fmap'
In the instance declaration for `Functor Data.Set.Set'
On the other hand, it seems intuitively natural to make Set an instance of
fmap. Any ideas on how to do it?
Thanks and Regards,
More information about the Glasgow-haskell-users