Skip to content

Instantly share code, notes, and snippets.

@astarasikov
Created July 8, 2015 12:16
Show Gist options
  • Select an option

  • Save astarasikov/c4506f456dd69e6a844e to your computer and use it in GitHub Desktop.

Select an option

Save astarasikov/c4506f456dd69e6a844e to your computer and use it in GitHub Desktop.
average
avg [] curr n = curr
avg (x:xs) curr n =
let c' = (x + (curr * n)) / (n + 1)
in avg xs c' (n + 1)
avg' lst = avg lst 0 0
main =
print $ avg' ([1, 2, 3, 4, 5] :: [Double])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment