From 9477dbe667f250ecd23f8fc0d56b942191526421 Mon Sep 17 00:00:00 2001 From: Franciszek Malinka Date: Thu, 25 Feb 2021 14:42:55 +0100 Subject: Stare semestry, niepoukladane --- Semestr 3/pf/lista3/procc.ml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Semestr 3/pf/lista3/procc.ml (limited to 'Semestr 3/pf/lista3/procc.ml') diff --git a/Semestr 3/pf/lista3/procc.ml b/Semestr 3/pf/lista3/procc.ml new file mode 100644 index 0000000..07f4404 --- /dev/null +++ b/Semestr 3/pf/lista3/procc.ml @@ -0,0 +1,30 @@ +type ('z,'i) in_channel = + | In of (('z,'i) out_channel -> 'z) + +and ('z,'o) out_channel = + | Out of ('o -> ('z,'o) in_channel -> 'z) + +type ('z,'i,'o) ans = ('z,'i) in_channel -> ('z,'o) out_channel -> 'z + +type ('a,'z,'i,'o) proc = ('a -> ('z,'i,'o) ans) -> ('z,'i,'o) ans + +let send o k in_ch (Out sendd) = + sendd o (In(fun out_ch -> k () in_ch out_ch)) + +let recv k (In recv) out_ch = + recv (Out(fun v in_ch -> k v in_ch out_ch)) + +let exit_k x _ _ = x + +let (<|>>) p1 p2 _ in_ch out_ch = + p2 exit_k + (In(fun m_ch -> p1 exit_k in_ch m_ch)) + out_ch + +let rec stdin_ch = + In (fun (Out send) -> send (read_line ()) stdin_ch) + +let rec stdout_ch = + Out (fun str (In recv) -> print_endline str; recv stdout_ch) + +let run p = p exit_k stdin_ch stdout_ch -- cgit v1.2.3