mirror of
https://github.com/HigherOrderCO/Kind.git
synced 2024-09-11 15:56:12 +03:00
96 lines
2.2 KiB
Plaintext
96 lines
2.2 KiB
Plaintext
IO
|
|
: ∀(A: *) *
|
|
= λA
|
|
$self
|
|
∀(P: ∀(x: (IO A)) *)
|
|
∀(print: ∀(text: String) ∀(then: ∀(x: Unit) (IO A)) (P (IO.print A text then)))
|
|
∀(load: ∀(file: String) ∀(then: ∀(x: String) (IO A)) (P (IO.load A file then)))
|
|
∀(save: ∀(file: String) ∀(data: String) ∀(then: ∀(x: Unit) (IO A)) (P (IO.save A file data then)))
|
|
∀(done: ∀(term: A) (P (IO.done A term)))
|
|
(P self)
|
|
|
|
IO.print
|
|
: ∀(A: *)
|
|
∀(text: String)
|
|
∀(then: ∀(x: Unit) (IO A))
|
|
(IO A)
|
|
= λA λtext λthen
|
|
~λP λprint λload λsave λdone
|
|
(print text then)
|
|
|
|
IO.load
|
|
: ∀(A: *)
|
|
∀(file: String)
|
|
∀(then: ∀(x: String) (IO A))
|
|
(IO A)
|
|
= λA λfile λthen
|
|
~λP λprint λload λsave λdone
|
|
(load file then)
|
|
|
|
IO.save
|
|
: ∀(A: *)
|
|
∀(file: String)
|
|
∀(data: String)
|
|
∀(then: ∀(x: Unit) (IO A))
|
|
(IO A)
|
|
= λA λfile λdata λthen
|
|
~λP λprint λload λsave λdone
|
|
(save file data then)
|
|
|
|
IO.done
|
|
: ∀(A: *)
|
|
∀(term: A)
|
|
(IO A)
|
|
= λA λterm
|
|
~λP λprint λload λsave λdone
|
|
(done term)
|
|
|
|
IO.run
|
|
: ∀(A: *)
|
|
∀(x: (IO A))
|
|
(IO A)
|
|
= λA λx
|
|
let P = λx(A)
|
|
let print = λtext λthen (HVM.print A text (IO.run A (then Unit.one)))
|
|
let load = λfile λthen (HVM.load A file λs(IO.run A (then s)))
|
|
let save = λfile λdata λthen (HVM.save A file data (IO.run A (then Unit.one)))
|
|
let done = λterm (IO.done A term)
|
|
(~x P print load save done)
|
|
|
|
IO.print.do
|
|
: ∀(text: String)
|
|
(IO Unit)
|
|
= λtext
|
|
(IO.print Unit text λx
|
|
(IO.done Unit x))
|
|
|
|
IO.load.do
|
|
: ∀(file: String)
|
|
(IO String)
|
|
= λfile
|
|
(IO.load String file λx
|
|
(IO.done String x))
|
|
|
|
IO.save.do
|
|
: ∀(file: String)
|
|
∀(data: String)
|
|
(IO Unit)
|
|
= λfile λdata
|
|
(IO.save Unit file data λx
|
|
(IO.done Unit x))
|
|
|
|
IO.bind
|
|
: ∀(A: *)
|
|
∀(B: *)
|
|
∀(a: (IO A))
|
|
∀(b: ∀(x: A) (IO B))
|
|
(IO B)
|
|
= λA λB λa λb
|
|
let P = λx ∀(b: ∀(x: A) (IO B)) (IO B)
|
|
let print = λtext λthen λb (IO.print B text λx(IO.bind A B (then x) b))
|
|
let load = λfile λthen λb (IO.load B file λs(IO.bind A B (then s) b))
|
|
let save = λfile λdata λthen λb (IO.save B file data λx(IO.bind A B (then Unit.one) b))
|
|
let done = λterm λb (b term)
|
|
((~a P print load save done) b)
|
|
|