blob: a22f1b907d4402cbbf1431cfeb580741491a08a0 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
|