When I enter the following module and load it into Hugs:
> module Main where
> plus = zipWith (+)
> main = putStr (show (plus [1.0] [2.0]))
Hugs then gives the following error:
Prelude> :l test.lhs
Reading file "test.lhs":
Type checking
ERROR "test.lhs" (line 5): Int is not an instance of class "Fractional"
Prelude>
Changing the 1.0 and 2.0 to 1 and 2 results in the following:
Prelude> :l test.lhs
Reading file "test.lhs":
Hugs session for:
/usr/local/lib/hugs/lib/Prelude.hs
test.lhs
Main> :t plus
plus :: [Int] -> [Int] -> [Int]
Main> :t zipWith (+)
zipWith (+) :: Num a => [a] -> [a] -> [a]
Main>
A bit of history: this exact line occurred in the "nofib" suite of
tests; specifically, in "fft2", the "Fourier.lhs" file. I was getting
a truly weird type error, and eventually tracked it down to the above
weirdness. The insertion of a type signature cured the problem;
inserting "plus:: Num a -> [a] -> [a] -> [a]" causes no error, and
cures the type error message.
When submitted to ghc version 2.06, the above program compiles with no
problem. It executes, and gives [3.0] as expected.
This appears to be a disagreement in the interpretation of the
monomorphism restriction. Rule 2 seems to apply. In particular, the
example in the report seems directly applicable. Mind you, I never
*have* really understood the monomorphism restriction --- I just
scatter type signatures everywhere (as I believe good programming
practice requires), and things work out fine.
So which is correct, Hugs or GHC 2.06?
Dave Barton <*>
[EMAIL PROTECTED] )0(
http://www.intermetrics.com/~dlb