PageRenderTime 26ms CodeModel.GetById 11ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/froclist/froclist.ml

http://github.com/hhughes/ocaml-frui
OCaml | 44 lines | 32 code | 11 blank | 1 comment | 4 complexity | 3039195558080dd4ee344fbf92f9adbd MD5 | raw file
 1open Froc
 2open Printf
 3
 4let (>>=) = Froc.(>>=)
 5
 6(* assert list is always in *time* order *)
 7
 8let counte,counts = Froc.make_event ()
 9let count = Froc.hold 0 counte
10
11let inc n = fun c -> return (c + n)
12
13let liste,lists = Froc.make_event ()
14let list = Froc.hold [(count >>= inc 2); (count >>= inc 1); (count >>= inc 0)] liste
15
16let rec leq l1 l2 =
17  match (l1, l2) with
18    | [], [] -> true
19    | [], _
20    | _, [] -> false
21    | x::xs, y::ys -> sample x = sample y & (leq xs ys)
22
23let rec lnew lo ln =
24  match (lo, ln) with
25    | [], _
26    | _, []
27    | [], [] -> []
28    | x::xs, y::ys ->
29      if sample x = sample y then []
30      else y :: (lnew lo ys)
31
32let rec lbind l f =
33  let s = sample l in
34  List.iter (fun x -> ignore (x >>= f)) s;
35  l >>= (fun x ->
36    if leq s x then return ()
37    else lbind (return (lnew s x)) f
38  );;
39
40ignore (lbind list (fun i -> printf "item %d\n" i; return ()));;
41
42ignore (send lists [(count >>= inc 4); (count >>= inc 3); (count >>= inc 2); (count >>= inc 1); (count >>= inc 0)]);;
43
44ignore (Froc.send counts ((Froc.sample count) + 1));;