2023-11-03 12:42:59 -04:00
|
|
|
|
def0 Unit : ★ = {tt}
|
|
|
|
|
|
|
|
|
|
def drop-unit : 0.(A : ★) → Unit → A → A =
|
|
|
|
|
λ A u x ⇒ case u return A of {'tt ⇒ x}
|
|
|
|
|
|
|
|
|
|
def0 IO : ★ → ★ = λ A ⇒ IOState → A × IOState
|
|
|
|
|
|
|
|
|
|
def bind : 0.(A B : ★) → IO A → (A → IO B) → IO B =
|
|
|
|
|
λ A B m k s0 ⇒
|
|
|
|
|
case m s0 return B × IOState of { (x, s1) ⇒ k x s1 }
|
|
|
|
|
|
|
|
|
|
def seq : IO Unit → IO Unit → IO Unit =
|
|
|
|
|
λ a b ⇒ bind Unit Unit a (λ u ⇒ drop-unit (IO Unit) u b)
|
|
|
|
|
|
2023-11-16 12:33:03 -05:00
|
|
|
|
#[compile-scheme "(lambda (n) (builtin-io (printf \"~d~n\" n) 'tt))"]
|
2023-11-03 12:42:59 -04:00
|
|
|
|
postulate print-ℕ : ℕ → IO Unit
|
|
|
|
|
|
2023-11-16 12:33:03 -05:00
|
|
|
|
#[compile-scheme "(lambda (s) (builtin-io (printf \"~s~n\" s) 'tt))"]
|
2023-11-03 12:42:59 -04:00
|
|
|
|
postulate print : String → IO Unit
|
|
|
|
|
|
|
|
|
|
load "nat.quox"
|
|
|
|
|
|
|
|
|
|
#[main]
|
2023-11-16 12:33:03 -05:00
|
|
|
|
def main = seq (print-ℕ (nat.plus 60 9)) (print "(nice)")
|