home
/
code
/
cellular-automata.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Support both, plain map and mapi.
[cellular-automata.git]
/
polymorphic-life
/
001
/
src
/
polymorphic_life.ml
diff --git
a/polymorphic-life/001/src/polymorphic_life.ml
b/polymorphic-life/001/src/polymorphic_life.ml
index
4a28992
..
c28852a
100644
(file)
--- a/
polymorphic-life/001/src/polymorphic_life.ml
+++ b/
polymorphic-life/001/src/polymorphic_life.ml
@@
-10,7
+10,9
@@
module type MATRIX = sig
val set : 'a t -> row:int -> col:int -> data:'a -> unit
val set : 'a t -> row:int -> col:int -> data:'a -> unit
- val map : 'a t -> f:(row:int -> col:int -> data:'a -> 'b) -> 'b t
+ val map : 'a t -> f:('a -> 'b) -> 'b t
+
+ val mapi : 'a t -> f:(row:int -> col:int -> data:'a -> 'b) -> 'b t
val iter : 'a t -> f:(row:int -> col:int -> data:'a -> unit) -> unit
val iter : 'a t -> f:(row:int -> col:int -> data:'a -> unit) -> unit
@@
-40,6
+42,9
@@
module Matrix : MATRIX = struct
)
let map t ~f =
)
let map t ~f =
+ Array.map t ~f:(Array.map ~f:(fun x -> f x))
+
+ let mapi t ~f =
Array.mapi t ~f:(
fun row cols ->
Array.mapi cols ~f:(
Array.mapi t ~f:(
fun row cols ->
Array.mapi cols ~f:(
@@
-104,8
+109,7
@@
end
let main rows cols () =
Random.self_init ();
let main rows cols () =
Random.self_init ();
- let init ~row:_ ~col:_ ~data = Conway.init data in
- let grid = Matrix.create ~rows ~cols ~data:() |> Matrix.map ~f:init in
+ let grid = Matrix.create ~rows ~cols ~data:() |> Matrix.map ~f:Conway.init in
Matrix.print grid ~to_string:Conway.to_string
Matrix.print grid ~to_string:Conway.to_string
This page took
0.032594 seconds
and
4
git commands to generate.