I was inspired by George Pollard's <a href="http://www.haskell.org/pipermail/haskell-cafe/2009-July/063981.html">post</a> at haskell-cafe and tried to implement the non-polymorphic Functor class ( I named it Functor' ). I changed some names and added reasonable constraints.<br>
<br> type family NewPt f a <br> class Functor' f where<br> type Point f<br> map ∷ (a ~ Point f, b ~ Point g, g ~ NewPt f b, Functor' g) ⇒ (a → b) → f → g<br><br>I would like to be able to write:<br>
<br> type OldPt f = NewPt f (Point f)<br> class (f ~ OldPt f) ⇒ Functor' f ...<br><br>but ghc says it's not implemented yet (version 6.12.1). However, it's not the main problem.<br><br>Now I can write some instances:<br>
<br> type instance NewPt [a] b = [b]<br> instance Functor' [a] where<br> type Point [a] = a<br> map = fmap<br><br> type instance NewPt ByteString a = ByteString<br> instance Functor' ByteString where<br>
type Point ByteString = Word8<br> map = BS.map<br><br>But I can't write instance for Set:<br><br> type instance NewPt (Set a) b = Set b <br> instance Ord a ⇒ Functor' (Set a) where<br> type Point (Set a) = a<br>
map = Set.map<br><br>ghci complains: Could not deduce (Ord a1) from the context (g ~ NewPt (Set a) a1, a1 ~ Point g, Functor' g)<br> arising from a use of `Set.map' at ...<br><br>The type of Set.map is<br>
<br> Set.map :: (Ord a, Ord b) => (a -> b) -> Set a -> Set b<br><br>(Ord a) is in the instance context, and what about b? Type of map for Set instance would be:<br> <br>original:<br> map ∷ (a ~ Point f, b ~ Point g, g ~ NewPt f b, Functor' g) ⇒ (a → b) → f → g<br>
<br>substitute: f → Set a, g → Set b<br> map :: Functor' (Set b) ⇒ (a →b) →Set a →Set b<br><br>(Ord b) must be deduced from (Functor (Set b)) but it doesn't. I don't know whether it's my mistake somewhere or ghc problem.<br>
<br>(Sorry for my English, it's not perfect). <br>-- <br>All the best,<br>Alexey<br><br>