(module mut_counter

  (fn main
    (doc "Sum 1..10 via a tail-recursive helper. Expected stdout: 55.")
    (type (fn-type (params) (ret (own (con Unit))) (effects IO)))
    (params)
    (body
      (app print (app sum_helper 1 10 0))))

  (fn sum_helper
    (doc "Accumulator-style tail-recursive helper — sum from lo through hi inclusive.")
    (type (fn-type (params (own (con Int)) (own (con Int)) (own (con Int))) (ret (own (con Int)))))
    (params lo hi acc)
    (body
      (if (app gt lo hi)
        acc
        (tail-app sum_helper (app + lo 1) hi (app + acc lo))))))
