(*----------------------------------------------------------------*) (* Sum of a real list, using hd() and tl() *) (*----------------------------------------------------------------*) fun sum (L: real list) = if null(L) then 0.0 else hd(L) + sum(tl(L)); (*----------------------------------------------------------------*) (* Sum of a real list, using patterns *) (*----------------------------------------------------------------*) fun sump (nil) = 0.0 | sump (Head::Tail: real list) = Head + sump(Tail); (*----------------------------------------------------------------*) (* Calculate the mean of a list of real numbers *) (*----------------------------------------------------------------*) fun mean (L: real list) = sump(L) / real(length(L)); (*----------------------------------------------------------------*) (* Calculate the mean of a list of real numbers *) (*----------------------------------------------------------------*) fun factorial (n) = if n=1 then 1 else n * factorial(n-1);