Lokesh Sood schrieb:

 dear sirs, I have a problem to solve in haskell but i do not know how to go about it. the problem is write a haskell function for computing the average value of a list of numbers. I am using Hug 98 for windows and  I tried the following  way: average (x:xs) = s/l                    where                    s=sum(x:xs) && l=(x:xs) I am a beginner studying on my own. I would appreciate it if you could explain what I should and should not do. Thank youyours sincerelyRuhi Sood 


Try the following:

average :: [Int] -> Float
average x      | null x    = 0.0
                    | otherwise    = fromInt(sum x) / fromInt(length x)

Mirko
 
 

  • Re: Mirko Pracht
    • Re: Matthias Kilian

Reply via email to