Funny type.

Dylan Thurston dpt@math.harvard.edu
Mon, 28 May 2001 01:01:44 -0400


On Sun, May 27, 2001 at 10:46:37PM -0500, Jay Cox wrote:
> >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
...
> >show s
> >s = Cons 3 [Cons 4 [], Cons 5 [Cons 2 [],Cons 3 []]]

> Anyway, is my instance declaration still a bit mucked up?

Hmm.  To try to deduce Show (S [] Integer), the type checker reduces
it by your instance declaration to Show [S [] Integer], which reduces
to Show (S [] Integer), which reduces to...

ghci or hugs could, in theory, be slightly smarter and handle this case.

> Also, could there be a way to give a definition of show for S [] a? 

Yes.  You could drop the generality:

 instance (Show a) => Show (S [] a) where
    show Nil = "Nil"
    show (Cons x y) = "Cons " ++ show x ++ " " ++ show y

Really, the context you want is something like

 instance (Show a, forall b. Show b => Show (m b)) => Show (S m b) ...

if that were legal.

--Dylan