Right. This is definitely a bug in 6.2.2, related to instance matching. (The trouble was in the kind of the type variable used for the literal instance for "1".)
It has been fixed in the HEAD for some time. We don't propose to do any more work on the branch, so you'll have to work around it for now (as indeed you can). Thanks for reporting it. There's a test now, tc186. Simon | -----Original Message----- | From: [EMAIL PROTECTED] [mailto:glasgow-haskell-bugs- | [EMAIL PROTECTED] On Behalf Of Sven Moritz Hallberg | Sent: 07 December 2004 17:20 | To: [EMAIL PROTECTED] | Subject: [Fwd: Instance resolving strangeness] | | I just posted the message below to glasgow-haskell-users. However, after | discovering that | | test = foo (id 1) (id 2) :: () | | also works (see below), this to me looks definately like a bug. A valid | program should still be valid after replacing any occurence of (id x) | with x. Right? | | -SMH | | | -------- Original Message -------- | Subject: Instance resolving strangeness | Date: Tue, 07 Dec 2004 15:56:14 +0100 | From: Sven Moritz Hallberg <[EMAIL PROTECTED]> | To: [EMAIL PROTECTED] | | Hello, | | while trying to implement a certain polyvariadic function, using the | trick posted by Oleg Kiselyov to the Haskell ML some time ago, I | stumbled across some strange behaviour by GHC. | | In particular, I'd like a function with a variable number of arguments | which are either Strings or Ints. I'd like to save the user from giving | explicit signatures to the Ints, so she can write | | foo 1 2 3 | | instead of | | foo (1::Int) (2::Int) (3::Int) . | | | To demonstrate, consider the following declarations: | | > class Foo a where | > foo :: a | > instance Foo () where | > foo = () | > instance (Foo b, Integral a) => Foo (a -> b) where | > foo = \x -> foo | | Given the above, GHC accepts the following line | | > test = foo (1 :: Num a => a) (2 :: Num a => a) :: () | | and | | > main = print test | | prints "()" as expected. This also works in Hugs and requires no extensions. | | If, however, I remove the explicit Num type signature from one (or both) | of the integer literals above, for instance | | test = foo (1 :: Num a => a) 2 :: () , | | GHC rejects the program with the following message. | | Regex.hs:9: | No instance for (Foo (t -> ())) | arising from use of `foo' at Regex.hs:9 | When checking the type signature of the expression: | foo (1 :: forall a. (Num a) => a) 2 :: () | In the definition of `test': | test = foo (1 :: forall a. (Num a) => a) 2 :: () | | Hugs still accepts and prints the expected result. | | Can somebody enlighten me as to the reason for GHC's behaviour here? My | understanding is that the 2 above is taken as (fromIntegral 2) by the | compiler, having type (Num a => a). So restating that type explicitly | should have no effect... | | | Greetings, | Sven Moritz Hallberg _______________________________________________ Glasgow-haskell-bugs mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs
