; Iter 15a — first consumer of an stdlib module.
; Imports std_maybe, exercises from_maybe, is_some, is_none, map_maybe.
; First program to import a parameterised ADT (Maybe a) across module
; boundaries. Per the project's qualified-only convention (Iter 5b for
; fns, Iter 15a for types/ctors), every cross-module reference is
; qualified: `std_maybe.from_maybe` for the fn, `std_maybe.Maybe` for
; the type-name slot of `term-ctor`. The bare ctor names (`Just`,
; `Nothing`) stay unqualified — once the type is resolved, the ctor
; lookup is unambiguous within it.

(module std_maybe_demo

  (import std_maybe)

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

  (fn main
    (doc "Drive each combinator once and print 7, 99, true, true, 42.")
    (type (fn-type (params) (ret (con Unit)) (effects IO)))
    (params)
    (body
      (seq (do io/print_int (app std_maybe.from_maybe 99 (term-ctor std_maybe.Maybe Just 7)))
      (seq (do io/print_int (app std_maybe.from_maybe 99 (term-ctor std_maybe.Maybe Nothing)))
      (seq (do io/print_bool (app std_maybe.is_some (term-ctor std_maybe.Maybe Just 5)))
      (seq (do io/print_bool (app std_maybe.is_none (term-ctor std_maybe.Maybe Nothing)))
           (do io/print_int (app std_maybe.from_maybe 0 (app std_maybe.map_maybe inc (term-ctor std_maybe.Maybe Just 41)))))))))))
