Sven Moritz Hallberg
Wed, 08 Dec 2004 03:12:08 -0800
test = foo (id 1) (id 2) :: ()
-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
signature.asc
Description: OpenPGP digital signature
_______________________________________________ Glasgow-haskell-bugs mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs
[Fwd: Instance resolving strangeness] Sven Moritz Hallberg
- RE: [Fwd: Instance resolving strangeness] Simon Peyton-Jones