; Iter 15f — fourth consumer demo. Drives every std_pair combinator
; once. fst/snd are stable at 7/9; swap reverses; map_first/map_second
; demonstrate the Pair<a, b> -> Pair<c, b> / Pair<a, c> reshape with
; b/a held rigid. prep.1 migration (kernel-extension-mechanics):
; std_pair.<fn> -> Pair.<fn>; bare Pair via (import std_pair).

(module std_pair_demo

  (import std_pair)

  (fn inc
    (doc "Add 1. Used as the (a -> c) arg.")
    (type (fn-type (params (own (con Int))) (ret (own (con Int)))))
    (params x)
    (body (app + x 1)))

  (fn double
    (doc "Multiply by 2. Used as the (b -> c) arg.")
    (type (fn-type (params (own (con Int))) (ret (own (con Int)))))
    (params x)
    (body (app * x 2)))

  (fn main
    (doc "Drive every combinator. Expected (per line): 7, 9, 9, 7, 8, 18.")
    (type (fn-type (params) (ret (own (con Unit))) (effects IO)))
    (params)
    (body
      (seq (seq (app print (app Pair.fst (term-ctor Pair MkPair 7 9))) (do io/print_str "\n"))
      (seq (seq (app print (app Pair.snd (term-ctor Pair MkPair 7 9))) (do io/print_str "\n"))
      (seq (seq (app print (app Pair.fst (app Pair.swap (term-ctor Pair MkPair 7 9)))) (do io/print_str "\n"))
      (seq (seq (app print (app Pair.snd (app Pair.swap (term-ctor Pair MkPair 7 9)))) (do io/print_str "\n"))
      (seq (seq (app print (app Pair.fst (app Pair.map_first  inc    (term-ctor Pair MkPair 7 9)))) (do io/print_str "\n"))
           (seq (app print (app Pair.snd (app Pair.map_second double (term-ctor Pair MkPair 7 9)))) (do io/print_str "\n"))))))))))
