Skip to content

Instantly share code, notes, and snippets.

@kunishi
Created January 29, 2014 10:22
Show Gist options
  • Save kunishi/8685214 to your computer and use it in GitHub Desktop.
Save kunishi/8685214 to your computer and use it in GitHub Desktop.
fun square(x:real) = x*x;
fun plus(x:real, y) = x+y;
fun length(nil) = 0.0
| length(x::xs) = 1.0 + length(xs);
fun variance(L) =
let
val n = length(L)
in
reduce(plus, map(square, L))/n -
square(reduce(plus, L)/n)
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment