From bfafa7dbc3325749358538a95cbb4831db66b03c Mon Sep 17 00:00:00 2001 From: Alex AUVOLAT Date: Wed, 12 Mar 2014 10:11:12 +0100 Subject: First commit --- src/example.ml | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/example.ml (limited to 'src/example.ml') diff --git a/src/example.ml b/src/example.ml new file mode 100644 index 0000000..a22f1b9 --- /dev/null +++ b/src/example.ml @@ -0,0 +1,32 @@ +module Example (K : Kahn.S) = struct + module K = K + module Lib = Kahn.Lib(K) + open Lib + + let integers nmax (qo : int K.out_port) : unit K.process = + let rec loop n = + if n > nmax then + K.put (-1) qo + else + (K.put n qo) >>= (fun () -> loop (n + 1)) + in + loop 2 + + let output (qi : int K.in_port) : unit K.process = + let rec loop () = + (K.get qi) >>= (fun v -> + if v <> -1 then + begin Format.printf "%d@." v; loop () end + else K.return ()) + in + loop () + + let main : unit K.process = + (delay K.new_channel ()) >>= + (fun (q_in, q_out) -> K.doco [ integers 10000 q_out ; output q_in ]) + +end + +module E = Example(Kahn.Seq) + +let () = E.K.run E.main -- cgit v1.2.3