编辑代码

let rec length (l: int list) : int =
  begin match l with
    | [] -> 0
    | x :: tl ->
          if x >= 0
          then 1 + length tl
          else if x = -999
                then 1+length []
                else 0 + length tl
    end
(*actual length of the list = length list - 1*)

let rec sum_of_list (l: int list) : int =
  begin match l with 
    | [] -> 0
    | x :: tl ->
          if x >= 0
          then x + sum_of_list tl
          else 
            if x = -999
            then x + 999 + sum_of_list []
            else 0 + sum_of_list tl
    end


let rainfall (readings: int list) : int =
  if length readings - 1 > 0
  then (sum_of_list readings) / ( length readings ) 
  else -1