The following script seems to disclose a bug in Hugs 1.3c's type
checker. NB it compiles fine with ghc 3.02.

> class (Show a) => Stringable a where
>     toStrings                 :: a -> ShowS
>
>     toStrings                 =  shows
>
> class (Stringable a) => With style a where
>     with                      :: style -> a -> ShowS
>
>     with _ a                  =  toStrings a
>
> data Align                    =  L Int
>
> instance (Stringable a) => With Align a where
>     with (L w) a              =  showString (ljustify w (toString a))

Some auxiliaries.

> toString                      :: (Stringable a) => a -> String
> toString a                    =  toStrings a ""
> ljustify                      :: Int -> String -> String
> ljustify n s                  =  s ++ spaces (n - length s)
> spaces n                      =  replicate n ' '

Hugs tells me 

ERROR "Bug.lhs" (line 16): Cannot build superclass instance
*** Instance            : With Align a
*** Context supplied    : Stringable a (bad type)
*** Required superclass : Stringable a

The message becomes more obscure when I add a further context to the
last instance declaration.

> instance (Show a, Stringable a) => With Align a where

is prompted by

ERROR "Bug.lhs" (line 16): Cannot build superclass instance
*** Instance            : With Align a
*** Context supplied    : Stringable a ((bad type) a (bad type))
*** Required superclass : Stringable a

As far as I can see both instance declarations are perfectly legal.

Cheers, Ralf

Reply via email to