// module rc_own_param_drop

/// Recursive Int list — boxed.
data IntList = Nil | Cons(Int, IntList)

// @suppress over-strict-mode: RC codegen test: exercises Iter B Own-param dec at fn return
/// Take ownership of an IntList; return its head if Cons, else 0. The tail is
/// loaded as a pattern binder but never consumed — iter A dec's it at arm
/// close. The outer cell is dec'd at fn return via iter B's Own-param emission.
fn head_or_zero(xs: own IntList) -> own Int {
  match xs {
    Nil => 0,
    Cons(h, t) => h
  }
}

/// Build a 5-element IntList; pass to head_or_zero (transferring ownership);
/// print the result.
fn main() -> own Unit with IO {
  let xs = Cons(11, Cons(22, Cons(33, Cons(44, Cons(55, Nil)))));
  print(head_or_zero(xs))
}
