
23 Apr
2009
23 Apr
'09
8:57 a.m.
Hi, I want to make a simple "average" function: average xs = (sum xs)/(length xs) When I try that on ghci I get the following error: No instance for (Fractional Int) arising from a use of `/' at <interactive>:1:17-36 Possible fix: add an instance declaration for (Fractional Int) In the expression: (sum xs) / (length xs) In the definition of `average': average xs = (sum xs) / (length xs) Ok, so 'sum' is of type (Num a => [a] -> a), length is of type ([a] -> Int) and (/) is of type (Fractional a => a -> a -> a). Can someone explain how I can "add an instance declaration" to my function so as to make all these types compatible? Thanks, Daniel.