How to make Data.Set.Set a Functor
Benjamin Franksen
benjamin.franksen at bessy.de
Tue Oct 11 15:13:59 EDT 2005
On Tuesday 11 October 2005 18:16, Lajos Nagy wrote:
> 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:
>
> [...]
>
> On the other hand, it seems intuitively natural to make Set an
> instance of fmap. Any ideas on how to do it?
Hi,
you are not the first one to observe this. AFAIK, there is no really
satisfactory solution available. The general problem is discussed and a
solution (a language extension) proposed in
(http://www.cs.chalmers.se/~rjmh/Papers/restricted-datatypes.ps).
Cheers,
Ben
More information about the Glasgow-haskell-users
mailing list