|
[Fwd: Instance resolving strangeness]: msg#00023lang.haskell.glasgow.bugs
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 <pesco@xxxxxx> To: glasgow-haskell-users@xxxxxxxxxxx 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 Glasgow-haskell-bugs@xxxxxxxxxxx http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: Bug Report: stg_ap_p_ret, oriel maxime |
|---|---|
| Next by Date: | [ ghc-Bugs-1073501 ] checkProddableBlock: invalid fixup in runtime linker, SourceForge.net |
| Previous by Thread: | Bug Report: stg_ap_p_ret, oriel maxime |
| Next by Thread: | RE: [Fwd: Instance resolving strangeness], Simon Peyton-Jones |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |