| Is "deriving Show" meant to work for higher-order nested datatypes ?

No, it's not, at least for the particular example of a higher-order
nested datatype that you gave.  The reason has to do with the form
of proofs that are required to determine the relationships between
instances, all of which must be finite trees.  To calculate a context
for the derived Show on

 data SM f a = ZeroS (f (f a)) | SuccS (SM (Cons f) a)
               deriving Show

we begin with (Show (f (f a)), Show (SM (Cons f) a)) => Show (SM f a)
                               ~~~~~~~~~~~~~~~~~~~~~
The second constraint, however, is not in the correct form for the
context of an instance declaration, so we need to reduce again, replacing
it with:

 (Show (f (f a)),
    Show (Cons f (Cons f) a),
      Show (SM (Cons (Cons f)) a)) => Show (SM f a)

And on it goes ... In short, there is no context of the correct form for
Haskell 98 that will allow you to derive Show (SM f a), but Hugs can't
tell that and goes on looking, just in case.

If you run in Hugs mode (i.e., -98), then you can specify an instance

 instance (Show (f (f a)), Show (SM (Cons f) a))) => Show (SM f a)

and Hugs will then accept the program.  But this only delays the problem,
which will reappear when you try to use show on a value like SuccS
undefined,
and you get into the same kind of infinite loop once again.

| Hugs hangs when loading in the following file:

You should upgrade to Hugs 98, which gives an error message rather
than just hanging.

All the best,
Mark

Reply via email to