(import std) (define: (io/for xs f) (forall (a) (Fun (Iter a) (Fun a (IO Unit)) (IO Unit))) (IO (fun (real-world) [Unit (foldl (fun (real-world a) (cadr (perform-io (f a) real-world))) real-world xs)]))) (define (io/pure a) (IO (fun (real-world) [Unit real-world]))) (define: (io/map f (IO ma)) (forall (a b) (Fun (Fun a b) (IO a) (IO b))) (IO (o> ma (map-car f)))) (define: (io/bind f (IO ma)) (forall (a b) (Fun (Fun a (IO b)) (IO a) (IO b))) (IO (o> ma (uncurry (o> f perform-io))))) (define io/bindr (flip io/bind)) (define (io/thenl mb ma) (io/bind (const mb) ma)) (define (io/thenr ma mb) (io/bindr ma (const mb))) (define: (unsafe-perform-io ma) (forall (a) (Fun (IO a) a)) (car (perform-io ma UnsafeRealWorld))) (define: (perform-io (IO ma)) (forall (a) (Fun (IO a) RealWorld [a RealWorld])) ma) (extern unsafe-display-inline (Fun Str Unit)) (define (display-inline s) (io/pure (unsafe-display-inline s))) (define (display s) (display-inline (str-append s "\n")))