foo:: Int -> Int -> Int
foo z x = if (z < 100)
then z * foo (z+(x*z)) z
else z
How would you print out(the integer z) an output every time it gets called from itself?Can you have function that returns an IO and Int? Do you need a secondary function?
Building on @is7s's answer, a useful idiom for using Debug.Trace
is to do this:
import Debug.Trace
foo:: Int -> Int -> Int
foo z x | trace ("z = " ++ show z) False = undefined
foo z x = if (z < 100)
then z * foo (z+(x*z)) z
else z
Here, we have introduced a definition of foo
with the trace
in a guard which evaluates to False
, so that it will always fall-through to the original definition. In this way, we do not perturb our function, and can turn the tracing on or off by commenting out the line.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With