load "misc.quox" namespace io { def0 IORes : ★ → ★ = λ A ⇒ A × IOState def0 IO : ★ → ★ = λ A ⇒ IOState → IORes A def pure : 0.(A : ★) → A → IO A = λ A x s ⇒ (x, s) def bind : 0.(A B : ★) → IO A → (A → IO B) → IO B = λ A B m k s0 ⇒ case m s0 return IORes B of { (x, s1) ⇒ k x s1 } def seq : 0.(B : ★) → IO True → IO B → IO B = λ B x y ⇒ bind True B x (λ u ⇒ case u return IO B of { 'true ⇒ y }) def seq' : IO True → IO True → IO True = seq True #[compile-scheme "(lambda (str) (builtin-io (display str) 'true))"] postulate print : String → IO True def newline = print "\n" def println : String → IO True = λ str ⇒ seq' (print str) newline #[compile-scheme "(builtin-io (get-line (current-input-port)))"] postulate readln : IO String }