RE: Implict parameters and monomorphism
| a) That adding a type signature can change the dynamic semantics | of the program. This would be the first and only | occurrence of | such behaviour. | | At present, adding a type signature changes both the static | semantics and the cost of running a program That's true: but adopting (B) means that adding a type signature may cause the program to print a different answer! That seems qualitiatively different to giving the same answer only slower or faster; or rejecting the program altogether. Type signatures should specialise a type -- which means that efficiency may increase, or that the program may no longer be typable, but surely it shouldn't change the answer! | Are you sure this second one really holds? I claim the | effects analysis is just type inference! Indeed it is. I just don't want programmers to have to do type inference in their heads to figure out the meaning of the program. Simon
Simon Peyton-Jones wrote:
| a) That adding a type signature can change the dynamic semantics | of the program. This would be the first and only | occurrence of | such behaviour. | | At present, adding a type signature changes both the static | semantics and the cost of running a program
That's true: but adopting (B) means that adding a type signature may cause the program to print a different answer! That seems qualitiatively different to giving the same answer only slower or faster; or rejecting the program altogether. Type signatures should specialise a type -- which means that efficiency may increase, or that the program may no longer be typable, but surely it shouldn't change the answer!
Try this program: -- Try commenting out this type signature. fun :: (Num a) => a -> Int fun 0 = if fun 1 == 1 then fun 2 else fun (3::Int) g :: (a -> b) -> b g f = f undefined ii = g fun class C a where m :: a -> String instance C Int where m _ = "You have a type signature" instance C Integer where m _ = "You forgot the type signature" main = putStrLn (m ii) -- Lennart PS. There are better examples, but this was all I could think of right now.
Thu, 03 May 2001 06:29:35 -0400, Lennart Augustsson <lennart@mail.augustsson.net> pisze:
Try this program: -- Try commenting out this type signature. fun:: (Num a) => a -> Int
Test.hs:7: Ambiguous type variable(s) `a' in the constraint `Num a' arising from use of `fun' at Test.hs:7 In the first argument of `g', namely `fun' In the definition of `ii': g fun Test.hs:18: Ambiguous type variable(s) `a' in the constraint `C a' arising from use of `m' at Test.hs:18 In the first argument of `putStrLn', namely `(m ii)' In the definition of `main': putStrLn (m ii) Defaulting applies only when all classes involved are Haskell 98. hbc, nhc98 and Hugs are not conforming. -- __("< Marcin Kowalczyk * qrczak@knm.org.pl http://qrczak.ids.net.pl/ \__/ ^^ SYGNATURA ZASTÊPCZA QRCZAK
Marcin 'Qrczak' Kowalczyk wrote:
Thu, 03 May 2001 06:29:35 -0400, Lennart Augustsson <lennart@mail.augustsson.net> pisze:
Try this program: -- Try commenting out this type signature. fun:: (Num a) => a -> Int
Test.hs:7: Ambiguous type variable(s) `a' in the constraint `Num a' arising from use of `fun' at Test.hs:7 In the first argument of `g', namely `fun' In the definition of `ii': g fun
Test.hs:18: Ambiguous type variable(s) `a' in the constraint `C a' arising from use of `m' at Test.hs:18 In the first argument of `putStrLn', namely `(m ii)' In the definition of `main': putStrLn (m ii)
Defaulting applies only when all classes involved are Haskell 98.
First, I cannot parse that sentence, but I assume you mean when all classes are Prelude classes. Second, I'm pretty sure we all agreed that this was a silly rule and should not be in the Haskell definition. I was certain that that it had been removed from the Haskell report, but I guess not. (hbc used to make this check, but I removed it when everyone seemed to agree that rule was a bad idea). Third, moving ii to a different module might still exhibit this problem. (I'm not sure how ghc defaults exported definitions.) But most importantly, this was a bad example. There was a much better one posted on this mailing list a while ago. Does anyone remember it? -- Lennart
hbc, nhc98 and Hugs are not conforming.
Lennart Augustsson wrote:
But most importantly, this was a bad example. There was a much better one posted on this mailing list a while ago. Does anyone remember it?
No, but this should do it: data T = T Int instance Show T where show (T n) = show n instance Eq instance Num T where fromInteger n = T n (+) (T _) (T _) = T 0 x :: T -- try removing this type signature x = 1 + 2 main = putStr (show x) - Andreas -- Andreas Rossberg, rossberg@ps.uni-sb.de "Computer games don't affect kids. If Pac Man affected us as kids, we would all be running around in darkened rooms, munching pills, and listening to repetitive music."
Thu, 03 May 2001 08:07:10 -0400, Lennart Augustsson <lennart@mail.augustsson.net> pisze:
First, I cannot parse that sentence, but I assume you mean when all classes are Prelude classes.
Not only Prelude but the whole Haskell 98 standard library.
Second, I'm pretty sure we all agreed that this was a silly rule and should not be in the Haskell definition. I was certain that that it had been removed from the Haskell report, but I guess not.
It was not removed, it's still in <http://research.microsoft.com/~simonpj/haskell98-revised/>. So probably it should be removed now: SimonPJ wanted to freeze the revised report in May.
Third, moving ii to a different module might still exhibit this problem.
Indeed.
(I'm not sure how ghc defaults exported definitions.)
I'm sure that it works as it should: they are defaulted according to visible definitions, to Int or Integer here, and from another module it is not known that the types have been ambiguous, so constraints from non-Haskell-98 classes can't stop the defaulting. This is an argument for removing that part of the defaulting rule. Or for removing the monomorphism restriction. Or both. -- __("< Marcin Kowalczyk * qrczak@knm.org.pl http://qrczak.ids.net.pl/ \__/ ^^ SYGNATURA ZASTÊPCZA QRCZAK
participants (4)
-
Andreas Rossberg -
Lennart Augustsson -
Marcin 'Qrczak' Kowalczyk -
Simon Peyton-Jones