Here is my code:
let avg l =
List.fold_left ( +. ) 0. l /. float (List.length l);;
let variability l =
let xbar = avg l in
let odp = (List.map (fun i -> ((float) i -. xbar) ** 2.0) l) in
let sum = List.fold_left ( +. ) 0. odp in
sum /. (float) length l;;
Entering this into the toplevel produces the following:
val avg : float list -> float = <fun>
# Characters 107-108:
let odp = (List.map (fun i -> ((float) i -. xbar) ** 2.0) l) in
^
Error: This expression has type float list but is here used with type
int list
I've been trying to work with this for a long time but I can't figure out why this is producting an error. Is it thinking that l
is an int list?
SOLUTION: (from below. Thanks!)
let avg l =
List.fold_left ( +. ) 0. l /. float (List.length l);;
let variability l =
let xbar = avg l in
let odp = (List.map (fun i -> (i -. xbar) ** 2.0) l) in
let sum = List.fold_left ( +. ) 0. odp in
sum /. (float) (List.length l);;