logo       

[Fwd: Instance resolving strangeness]: msg#00023

lang.haskell.glasgow.bugs

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 <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

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
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>
Google Custom Search

News | FAQ | advertise