In fact, you can eliminate the UndecidableInstance requirement for Showhere, although you cannot do the same for Reador Eq.
, -, , . , :
{-
module Free (Free(..)) where
, Show.
newtype Showable = Showable (Int -> ShowS)
showable :: Show a => a -> Showable
showable a = Showable $ \d -> showsPrec d a
instance Show Showable where
showsPrec d (Showable f) = f d
, Showable, Show (f Showable) , a, Show. , . / / , , , , .
Show.
data Free f a = Pure a | Free (f (Free f a))
instance (Functor f, Show (f Showable), Show a) => Show (Free f a) where
showsPrec d (Pure a) = showParen (d > 10) $ showString "Pure " . showsPrec 10 a
showsPrec d (Free as) = showParen (d > 10) $ showString "Free " . showsPrec 10 (fmap showable as)
, , FlexibleContexts, - Haskell 98, .
, ad, .