On 11 October 2005 17: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: > > instance Functor Data.Set.Set where > fmap f s = Data.Set.map f s
A nice way to do this would be: data FSet a where FSet :: Ord a => Set a -> FSet a instance Functor FSet where ... if only GADTs worked with type classes :-) Cheers, Simon _______________________________________________ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users