
On Sat, 11 Mar 2006, Roberto Zunino wrote:
This avoids duplicating code between Show/ShowColl .
instance ShowColl coll => Show (CollTree coll) where show (CollNode n) = "CollNode " ++ showColl n
class ShowColl coll where showColl :: coll (CollTree coll) -> String
instance ShowColl [] where showColl = show
Yes, this solves the problem. Thanks a lot!
Also, with GHC extensions and undecidable instances, the following incantation seems to work:
{-# OPTIONS -fglasgow-exts -fallow-undecidable-instances #-} module CollTree where data CollTree coll = CollNode (coll (CollTree coll))
instance Show (coll (CollTree coll)) => Show (CollTree coll) where show (CollNode n) = "CollNode " ++ show n
*CollTree> show (CollNode [CollNode [],CollNode []]) "CollNode [CollNode [],CollNode []]"
However, I can not figure why the typechecker does not loop here (GHC 6.4.1).
I tried similar things with GHC 6.2 and Hugs and they looped.