; Axis: multi-step straight-line numeric build-up (Horner-form
; polynomial evaluation over fixed coefficients).
;
; Evaluate p(x) = 2x^4 + 3x^3 + 0x^2 + 5x + 7 at x.
; Imperative instinct (the shape `mut` would invite):
;   acc = 2
;   acc = acc*x + 3
;   acc = acc*x + 0
;   acc = acc*x + 5
;   acc = acc*x + 7
;   return acc
;
; Surviving-surface shape: a straight chain of `let acc` shadowings,
; each step a pure expression. p(2) = 2*16+3*8+0+5*2+7 = 32+24+10+7
; = 73. Expected stdout: 73

(module remove-mut_3_horner_poly

  (fn poly
    (doc "Horner-form evaluation of 2x^4+3x^3+0x^2+5x+7 as a straight-line let chain (the faithful let/if form of a mutable acc).")
    (type (fn-type (params (own (con Int))) (ret (own (con Int)))))
    (params x)
    (body
      (let acc 2
        (let acc (app + (app * acc x) 3)
          (let acc (app + (app * acc x) 0)
            (let acc (app + (app * acc x) 5)
              (let acc (app + (app * acc x) 7)
                acc)))))))

  (fn main
    (type (fn-type (params) (ret (own (con Unit))) (effects IO)))
    (params)
    (body
      (app print (app poly 2)))))
