Parameter .. List of lists .. and averages

1

I would like to know how to do in haskell to pass a list of lists by parameter ..? And to get averages with those lists? I need you to return only a list that has the averages of each of the lists that contains the list .. I mean .. [[8,6], [6,2,4]] = [7.5] ... thanks!

    
asked by Pam 28.03.2018 в 04:47
source

1 answer

0

If a list has a generic [a] , then a list of lists would be [[a]] .

To get an average list, you can do it like this:

promedios :: Fractional a => [[a]] -> [a]
promedios xss = map promedio xss
  where
    promedio [] = 0
    promedio xs = sum xs / fromIntegral (length xs)
    
answered by 28.03.2018 в 09:54