; Fieldtest cut55-3 — decision (c): value-typed param read multiple times.
;
; clamp reads n three times (two comparisons + a return). n: Int is a
; value type. Per the ledger, `(borrow V)` on a value type is a check
; error — `own` is the only legal mode for Int/Bool/Float/Unit, even when
; the value is read many times and never "consumed" in the heap sense.
; So the author writes `(own (con Int))` for every param here.
;
; Expected: ail check -> ok (no over-strict warning, value types exempt).
; ail run -> prints 5 (clamp 12 0 5 -> 5), then 3 (clamp 3 0 5 -> 3).

(module cut55_3_value_param

  (fn clamp
    (doc "Clamp n into [lo, hi]. All three params are value-typed Ints, read repeatedly.")
    (type
      (fn-type
        (params (own (con Int)) (own (con Int)) (own (con Int)))
        (ret (own (con Int)))))
    (params n lo hi)
    (body
      (if (app lt n lo)
        lo
        (if (app lt hi n)
          hi
          n))))

  (fn main
    (type (fn-type (params) (ret (own (con Unit))) (effects IO)))
    (params)
    (body
      (seq
        (seq (app print (app clamp 12 0 5)) (do io/print_str "\n"))
        (seq (app print (app clamp 3 0 5)) (do io/print_str "\n"))))))
