
22 Sep
2016
22 Sep
'16
9:19 a.m.
Hi, can someone explain to me why i cannot define meanList as: meanList :: (Integral a, Fractional b) => [a] -> a meanList xs = (sumList xs) / (lengthList xs) I want to restrict the function to only accept lists like [1,2,3] and return answer 2.0 sumList :: (Num a) => [a] -> a sumList [] = 0 sumList (x:xs) = x + (sumList xs) lengthList :: (Num a) => [t] -> a lengthList [] = 0 lengthList (_:xs) = 1 + (lengthList xs)