X-Git-Url: https://git.xandkar.net/?a=blobdiff_plain;f=polymorphism%2F001%2Fsrc%2Fpolymorphism.ml;h=5d6fbabb22378df3c7158794a3389dc8d23441b7;hb=56a56c38cbc5eb66950c1f473729b17bf956cac1;hp=ab2cbd5b89e744eaf8fda0b749e3477bbcce82b3;hpb=fd22df899f4fb6b3499f89fdcfd84462d89f40de;p=cellular-automata.git diff --git a/polymorphism/001/src/polymorphism.ml b/polymorphism/001/src/polymorphism.ml index ab2cbd5..5d6fbab 100644 --- a/polymorphism/001/src/polymorphism.ml +++ b/polymorphism/001/src/polymorphism.ml @@ -209,7 +209,7 @@ struct sig type t = D | A - val of_int : int -> t + val random : unit -> t val is_alive : t -> bool @@ -222,7 +222,8 @@ struct struct type t = D | A - let of_int = function + let random () = + match Random.int 2 with | 0 -> D | 1 -> A | _ -> assert false @@ -260,12 +261,12 @@ struct | D -> D end - let create () = - Random.int 2 |> State.of_int |> State.to_cell + let create = + State.random |- State.to_cell let count_of_live = - List.map ~f:State.of_cell_state - |- List.filter ~f:State.is_alive + List.map ~f:State.of_cell_state + |- List.filter ~f:State.is_alive |- List.length let transition ~self ~neighbors = @@ -283,7 +284,7 @@ struct val is_burning : t -> bool - val of_int : int -> t + val random : unit -> t val to_cell : t -> Cell.t @@ -299,7 +300,8 @@ struct | T -> false | B -> true - let of_int = function + let random () = + match Random.int 3 with | 0 -> E | 1 -> T | 2 -> B @@ -342,12 +344,12 @@ struct | B, _ -> E end - let create () = - Random.int 3 |> State.of_int |> State.to_cell + let create = + State.random |- State.to_cell let count_of_burning = - List.map ~f:State.of_cell_state - |- List.filter ~f:State.is_burning + List.map ~f:State.of_cell_state + |- List.filter ~f:State.is_burning |- List.length let transition ~self ~neighbors =