Funny type.
Koen Claessen
koen@cs.chalmers.se
Tue, 29 May 2001 10:29:01 +0200 (MET DST)
Jay Cox complained that the following is not possible:
| data S m a = Nil | Cons a (m (S m a))
|
| instance (Show a, Show (m (S m a))) => Show (S m a) where
| show Nil = "Nil"
| show (Cons x y) = "Cons " ++ show x ++ " " ++ show y
Ken Shan answered:
| Here's how I've been handling such situations:
|
| data S m a = Nil | Cons a (m (S m a))
|
| -- "ShowF f" means that the functor f "preserves Show"
| class ShowF f where
| showsPrecF :: (Int -> a -> ShowS) -> (Int -> f a -> ShowS)
Actually, this class definition can be simplified to:
class ShowF f where
showsPrecF :: Show a => Int -> f a -> ShowS
And the rest of Ken's code accordingly.
/Koen.
--
Koen Claessen http://www.cs.chalmers.se/~koen
phone:+46-31-772 5424 mailto:koen@cs.chalmers.se
-----------------------------------------------------
Chalmers University of Technology, Gothenburg, Sweden