Funny type.

Simon Peyton-Jones simonpj@microsoft.com
Mon, 28 May 2001 02:02:29 -0700


You need a language extension.
Check out Section 7 of "Derivable type classes"

	http://research.microsoft.com/~simonpj/Papers/derive.htm

Alas, I have not implemented the idea yet.

(Partly because no one ever reports it as a problem; you=20
are the first!)

Simon

| One day I was playing around with types and I came across this type: =20
|=20
| >data S m a =3D Nil | Cons a (m (S m a))
|=20
| The idea being one could use generic functions with whatever=20
| monad m (of course m doesn't need to be a monad but my=20
| original idea was to be able to make mutable lists with some=20
| sort of monad m.)
|=20
| Anyway in attempting to define a generic show instance for=20
| the above datatype I finally came upon:
|=20
| >instance (Show a, Show (m (S m a))) =3D> Show (S m a)  where
| >  show Nil =3D "Nil"
| >  show (Cons x y) =3D "Cons " ++ show x ++ " " ++ show y
|=20
| which boggles my mind.  But hugs +98 and ghci=20
| -fallow-undecidable-instances both allow it to compile but when i try=20