For completeness, I'm going to answer this question:
Can you have function that returns an IO and Int?
...quite literally. The answer is "yes!"... and it's even sometimes useful. Likely this isn't what you want to do as a beginner, but in case it is, here's a sample.
foo :: Int -> Int -> (IO (), Int)
foo z x = if z < 100 then (print z >> io, z * rec) else (return (), z) where
(io, rec) = foo (z+x*z) z
For example, you could print the recursive calls by setting
main = fst $ foo 13 7
or you could just print the answer by setting
main = print . snd $ foo 13 7
or half a dozen other things. Of course, the IO ()
type is a bit hard to inspect; you might consider writing something like this instead:
foo' :: Int -> Int -> Writer [Int] Int
foo' z x = if z < 100
then tell [z] >> fmap (z*) (foo' (z+x*z) z)
else return z
Using this is pretty similar to the above, but with an extra runWriter
thrown in; for example, you could write either of these two:
main = print . snd . runWriter $ foo' 13 7 -- to print a list of the calling values
main = print . fst . runWriter $ foo' 13 7 -- to print the result
The advantage of this method is that you get back a list of calling values, rather than an IO action that prints that list, so you can munge the calls in many more interesting ways.