Type checker too lazy

Simon Peyton-Jones simonpj at microsoft.com
Tue Dec 19 03:46:33 EST 2000


Thanks for a fine bug report.

Really there are two bugs

Bug 1: without -fglasgow-exts, this program should be rejected,
since Haskell 98 doesn't allow records with polymorphic fields.
Your record is really
	data Record = R { blub :: forall a. Foo a => a -> [a] }

Bug 2: Assuming -fglasgow-exts, what type should blub have?
The "obvious" type is:

	blub :: Record -> forall a. Foo a => a -> [a]

but GHC doesn't expect functions to have types with a forall
after a function arrow.  This is isomorphic to

	blub :: forall a. Record -> Foo a => a -> [a]

and that is in fact the type that GHC gives it.  But having
given it that type, GHC trips up because it doesn't expect
to see types with a '=>' that isn't preceded by a 'forall'.
Hence the strange error message. 

If we wrote the records selector in plain Haskell thus:

	foo (R x) = x

then GHC would infer the type

	foo :: forall a. Foo a => Record -> a -> [a]

and that would be the right type to give blub.  I'll fix this in the HEAD.
And I hope we'll back-patch the fix to 4.08.2

Thanks again for an excellent report.

Simon

| -----Original Message-----
| From: Volker Stolz [mailto:stolz at I2.Informatik.RWTH-Aachen.DE]
| Sent: 13 December 2000 08:29
| To: glasgow-haskell-bugs at haskell.org
| Subject: Type checker too lazy
| 
| 
| 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
| 
| _______________________________________________
| Glasgow-haskell-bugs mailing list
| Glasgow-haskell-bugs at haskell.org
| http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs
| 




More information about the Glasgow-haskell-bugs mailing list