X-Git-Url: https://git.xandkar.net/?p=cellular-automata.git;a=blobdiff_plain;f=polymorphism%2F001%2Fsrc%2Fpolymorphism.ml;fp=polymorphism%2F001%2Fsrc%2Fpolymorphism.ml;h=ab2cbd5b89e744eaf8fda0b749e3477bbcce82b3;hp=0444595e7d2043888875e90a1709f9c25c543c37;hb=fd22df899f4fb6b3499f89fdcfd84462d89f40de;hpb=47c9d6963d399bc3fac7d39616cf26066311cc29 diff --git a/polymorphism/001/src/polymorphism.ml b/polymorphism/001/src/polymorphism.ml index 0444595..ab2cbd5 100644 --- a/polymorphism/001/src/polymorphism.ml +++ b/polymorphism/001/src/polymorphism.ml @@ -211,7 +211,7 @@ struct val of_int : int -> t - val to_int : t -> int + val is_alive : t -> bool val to_cell : t -> Cell.t @@ -227,9 +227,9 @@ struct | 1 -> A | _ -> assert false - let to_int = function - | D -> 0 - | A -> 1 + let is_alive = function + | D -> false + | A -> true let to_pheno = function | D -> PhenoType.create ' ' None @@ -265,8 +265,8 @@ struct let count_of_live = List.map ~f:State.of_cell_state - |- List.map ~f:State.to_int - |- List.fold_left ~f:(+) ~init:0 + |- List.filter ~f:State.is_alive + |- List.length let transition ~self ~neighbors = self |> State.of_cell_state @@ -285,8 +285,6 @@ struct val of_int : int -> t - val to_int : t -> int - val to_cell : t -> Cell.t val of_cell_state : Cell.State.t -> t @@ -307,11 +305,6 @@ struct | 2 -> B | _ -> assert false - let to_int = function - | E -> 0 - | T -> 1 - | B -> 2 - let to_pheno = function | E -> PhenoType.create ' ' None | T -> PhenoType.create 'T' (Some `green) @@ -355,8 +348,7 @@ struct let count_of_burning = List.map ~f:State.of_cell_state |- List.filter ~f:State.is_burning - |- List.map ~f:State.to_int - |- List.fold_left ~f:(+) ~init:0 + |- List.length let transition ~self ~neighbors = self |> State.of_cell_state