[Haskell-cafe] Removing polymorphism from type classes (viz.
Functor) (Again)
Alexey Karakulov
ankarakulov at gmail.com
Sat Aug 14 07:07:41 EDT 2010
I was inspired by George Pollard's
post<http://www.haskell.org/pipermail/haskell-cafe/2009-July/063981.html>at
haskell-cafe and tried to implement the non-polymorphic Functor class
( I
named it Functor' ). I changed some names and added reasonable constraints.
type family NewPt f a
class Functor' f where
type Point f
map ∷ (a ~ Point f, b ~ Point g, g ~ NewPt f b, Functor' g) ⇒ (a →
b) → f → g
I would like to be able to write:
type OldPt f = NewPt f (Point f)
class (f ~ OldPt f) ⇒ Functor' f ...
but ghc says it's not implemented yet (version 6.12.1). However, it's not
the main problem.
Now I can write some instances:
type instance NewPt [a] b = [b]
instance Functor' [a] where
type Point [a] = a
map = fmap
type instance NewPt ByteString a = ByteString
instance Functor' ByteString where
type Point ByteString = Word8
map = BS.map
But I can't write instance for Set:
type instance NewPt (Set a) b = Set b
instance Ord a ⇒ Functor' (Set a) where
type Point (Set a) = a
map = Set.map
ghci complains: Could not deduce (Ord a1) from the context (g ~ NewPt (Set
a) a1, a1 ~ Point g, Functor' g)
arising from a use of `Set.map' at ...
The type of Set.map is
Set.map :: (Ord a, Ord b) => (a -> b) -> Set a -> Set b
(Ord a) is in the instance context, and what about b? Type of map for Set
instance would be:
original:
map ∷ (a ~ Point f, b ~ Point g, g ~ NewPt f b, Functor' g) ⇒ (a → b) →
f → g
substitute: f → Set a, g → Set b
map :: Functor' (Set b) ⇒ (a →b) →Set a →Set b
(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.
(Sorry for my English, it's not perfect).
--
All the best,
Alexey
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100814/b49398f1/attachment.html
More information about the Haskell-Cafe
mailing list