let rec length (l: int list) : int =
beginmatch l with
| [] -> 0
| x :: tl ->
if x >= 0then1 + length tl
elseif x = -999then1+length []
else0 + length tl
end
(*actual lengthof the list = lengthlist - 1*)
let rec sum_of_list (l: intlist) : int =
beginmatch l with
| [] -> 0
| x :: tl ->
if x >= 0then x + sum_of_list tl
elseif x = -999then x + 999 + sum_of_list []
else0 + sum_of_list tl
end
let rainfall (readings: intlist) : int =
iflength readings - 1 > 0then (sum_of_list readings) / ( length readings )
else-1