Type checker too lazy

Volker Stolz stolz at I2.Informatik.RWTH-Aachen.DE
Wed Dec 13 03:29:17 EST 2000


Consider the following record (yes, I know, we all hate records but
I use them frequently for read-only data):

> import IO
> 
> class Foo a where
>   bar :: a -> [a]
> 
> instance Foo Int where
>   bar x = replicate x x
> 
> data Record = R {
>      blub :: Foo a => a -> [a]
>     }
> 
> main = do
>   let r = R {blub = bar}
> 
>   print (bar (3::Int)) -- works!
>   --print ((blub r) (3::Int)) -- doesn´t compile!

As long as I don´t try to use "r", everything works fine. Using the latter
print-statement, ghc yields

classTest.lhs:14:
    Couldn't match `Int' against `{Foo a}'
        Expected type: Int
        Inferred type: {Foo a}
    In an expression with a type signature: 3 :: Int

Hugs (Feb´00) is much more eager and wouldn´t even load the working case:
ERROR "classTest.lhs" (line 10): Undefined type variable "a".

Shouldn´t ghc reject the record-declaration altogether like Hugs? Why can´t
I use the record like I´m doing in the first place?
-- 
\usepackage[latin1]{inputenc}!
Volker Stolz * stolz at i2.informatik.rwth-aachen.de * PGP + S/MIME




More information about the Glasgow-haskell-bugs mailing list