(module main)

(fn empty_values () -> (vec f64)
  (std.vec.f64.empty))

(fn pair ((base f64)) -> (vec f64)
  (let values (vec f64) (std.vec.f64.empty))
  (let first (vec f64) (std.vec.f64.append values base))
  (std.vec.f64.append first (+ base 1.0)))

(fn echo ((values (vec f64))) -> (vec f64)
  values)

(fn length ((values (vec f64))) -> i32
  (std.vec.f64.len values))

(fn at ((values (vec f64)) (i i32)) -> f64
  (std.vec.f64.index values i))

(fn call_return_value () -> f64
  (at (echo (pair 2147483648.0)) 1))

(fn original_len_after_append () -> i32
  (let values (vec f64) (std.vec.f64.empty))
  (let appended (vec f64) (std.vec.f64.append values 1.0))
  (std.vec.f64.len values))

(test "vec f64 empty length"
  (= (std.vec.f64.len (empty_values)) 0))

(test "vec f64 append length"
  (= (length (pair 40.0)) 2))

(test "vec f64 index"
  (= (at (pair 40.0) 1) 41.0))

(test "vec f64 append is immutable"
  (= (original_len_after_append) 0))

(test "vec f64 equality"
  (= (pair 5.0) (std.vec.f64.append (std.vec.f64.append (std.vec.f64.empty) 5.0) 6.0)))

(fn main () -> i32
  (std.io.print_f64 (call_return_value))
  0)
