From aed335e3fd78a4124f8bbb853682a7e2dccf11eb Mon Sep 17 00:00:00 2001 From: Siraaj Khandkar Date: Sat, 28 Sep 2013 00:29:54 -0400 Subject: [PATCH] Pack options in a record. --- polymorphic-life/001/src/polymorphic_life.ml | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/polymorphic-life/001/src/polymorphic_life.ml b/polymorphic-life/001/src/polymorphic_life.ml index 6d8cd00..8ad51f9 100644 --- a/polymorphic-life/001/src/polymorphic_life.ml +++ b/polymorphic-life/001/src/polymorphic_life.ml @@ -153,18 +153,24 @@ module Conway : CELL = struct end -let rec loop bar pause_span grid = - print_endline bar; +type opt = { interval : Time.Span.t + ; bar : string + } + + +let rec loop opt grid = + print_endline opt.bar; Matrix.print grid ~to_string:Conway.to_string; - print_endline bar; + print_endline opt.bar; + let grid = Matrix.mapi grid ~f:(fun point ~data:cell -> let neighbors = Matrix.get_neighbors grid point in Conway.react cell ~states:(List.map neighbors ~f:Conway.state) ) in - Time.pause pause_span; - loop bar pause_span grid + Time.pause opt.interval; + loop opt grid let main () = @@ -172,7 +178,9 @@ let main () = let rs, ks = Or_error.ok_exn Linux_ext.get_terminal_size () in Matrix.create ~rs:(rs - 3) ~ks ~data:() |> Matrix.map ~f:Conway.create - |> loop (String.make ks '-') (Time.Span.of_float 0.1) + |> loop { interval = Time.Span.of_float 0.1 + ; bar = String.make ks '-' + } let spec = -- 2.20.1