Suppose I have the following function
printVariance :: [Float] -> IO ()
printVariance [] = return ()
printVariance (x:xs)
| x >= avg (x:xs) = print (x - avg (x:xs)) >> printVariance xs
| otherwise = printVariance xs
Which gets a list, checks which elements are bigger than the average and prints their value - avg.
My problem is that the avg value changes every step. How can I define it just once and use its value for the recursion?
whereor aletbinding where you'd define youravgas something along the lines of(foldr (+) 0 xs) / length xs.