let rec next_row prev =
  let rec aux a =
    match a with
    | [_] -> [1]
    | x :: y :: rest -> (x + y) :: aux (y :: rest)
    | [] -> []
  in
  1 :: aux prev

let row n =
  let r = ref [1] in
  for _ = 1 to n do
    r := next_row !r
  done;
  !r

;;

List.nth (row 10) 5
