media :: (Num a) => [a] -> a
media [] = 0
media lst = (head lst) + media (tail lst)
This is a working function that goes through a number list and sum each element with the following element.
media2 :: (Num a) => [a] -> a
media2 str = (media str) / (length str)
This second function was supposed to get that sum and divide it by the length of the list, thus getting the arithmetic mean of the list. BUT the compiler returns me this
src/Main.hs@6:29-6:39Could not deduce (a ~ Int)
from the context (Num a)
bound by the type signature for media2 :: Num a => [a] -> a
at /home/app/isolation-runner-work/projects/32614/src.207/Main.hs:6:1-39
`a' is a rigid type variable bound by
the type signature for media2 :: Num a => [a] -> a
at /home/app/isolation-runner-work/projects/32614/src.207/Main.hs:6:1
In the return type of a call of `length'
In the second argument of `(/)', namely `(length str)'
In the expression: (media str) / (length str)
I don't understand what I am doing wrong, can someone please tell me?