Haskell can generally infer the type of numeric literals such as 0
as whatever appropriate type you need them to be. This is because it knows what functions you pass them to; if I have a function phi :: Integer -> Integer
, and I call phi 0
, Haskell knows that that particular 0
must have been an Integer
. It's also fine if I call a function pho :: Int -> Int
with pho 0
; that particular 0
is inferred to be an Int
.
However Int
and Integer
are different types, and there's no way one particular 0
can be passed to both phi
and pho
.
Your issue is simply that the tuples that maxRatio
deals with are typed (by you) (Int, Int, Double)
, but that one such tuple is constructed as (n, phi n, ratio)
. Since phi
takes and returns Integer
, the n
in that expression has to be an Integer
. But then that doesn't work for maxRatio
, so you get the error.
Depending on which type you actually wanted (Int
or Integer
), all you need to do is change the type signature of phi
or maxRatio
so that they're working with the same kind of number. Haskell will decide that your literally written 0
s are whatever numeric type is necessary to make that work, provided there is one that can make it work!
Note that the error messaged specifically told you that it was n
in (n, phi n, ratio)
that was expected to be an Int
and was actually an Integer
. The (0, 0, 0.0)
tuple is never mentioned. Often type errors originate somewhere other than where the compiler points you (since all the compiler can do is spot that different chains of inference produce inconsistent requirements on the type of something, with no way to know which part of the whole process is "wrong"), but in this case it did pretty well.
Haskell gets a (fairly justified) bad rep for inscrutable error messages, but it can help a lot to start from what the compiler is telling you is the problem and try to figure out why the facts it's complaining about arise from your code. This will be painful at first, but you'll quickly develop a basic literacy in Haskell's error messages (at least the more straightforward ones) that will help you spot these kinds of errors really quickly, which makes the compiler a very powerful error-detection system for you.