home
/
code
/
cellular-automata.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Use idiomatic abbreviations for rows and columns.
[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
b93a79d
..
1afd1fe
100644
(file)
--- a/
polymorphic-life/001/src/polymorphic_life.ml
+++ b/
polymorphic-life/001/src/polymorphic_life.ml
@@
-4,15
+4,15
@@
open Core.Std
module type MATRIX = sig
type 'a t
module type MATRIX = sig
type 'a t
- val create : r
ows:int -> col
s:int -> data:'a -> 'a t
+ val create : r
s:int -> k
s:int -> data:'a -> 'a t
- val get : 'a t -> r
ow:int -> col
:int -> 'a
+ val get : 'a t -> r
:int -> k
:int -> 'a
val map : 'a t -> f:('a -> 'b) -> 'b t
val map : 'a t -> f:('a -> 'b) -> 'b t
- val mapi : 'a t -> f:(r
ow:int -> col
:int -> data:'a -> 'b) -> 'b t
+ val mapi : 'a t -> f:(r
:int -> k
:int -> data:'a -> 'b) -> 'b t
- val iter : 'a t -> f:(r
ow:int -> col
:int -> data:'a -> unit) -> unit
+ val iter : 'a t -> f:(r
:int -> k
:int -> data:'a -> unit) -> unit
val print : 'a t -> to_string:('a -> string) -> unit
end
val print : 'a t -> to_string:('a -> string) -> unit
end
@@
-20,22
+20,22
@@
end
module Matrix : MATRIX = struct
type 'a t = 'a array array
module Matrix : MATRIX = struct
type 'a t = 'a array array
- let create ~r
ows ~col
s ~data =
- Array.make_matrix ~dimx:r
ows ~dimy:col
s data
+ let create ~r
s ~k
s ~data =
+ Array.make_matrix ~dimx:r
s ~dimy:k
s data
let iter t ~f =
Array.iteri t ~f:(
let iter t ~f =
Array.iteri t ~f:(
- fun r
ow col
s ->
- Array.iteri
col
s ~f:(
- fun
col
data ->
- f ~r
ow ~col
~data
+ fun r
k
s ->
+ Array.iteri
k
s ~f:(
+ fun
k
data ->
+ f ~r
~k
~data
)
)
let print t ~to_string =
Array.iter t ~f:(
)
)
let print t ~to_string =
Array.iter t ~f:(
- fun r
ow
->
- Array.iter r
ow
~f:(fun x -> printf "%s" (to_string x));
+ fun r ->
+ Array.iter r ~f:(fun x -> printf "%s" (to_string x));
print_newline ()
)
print_newline ()
)
@@
-44,15
+44,15
@@
module Matrix : MATRIX = struct
let mapi t ~f =
Array.mapi t ~f:(
let mapi t ~f =
Array.mapi t ~f:(
- fun r
ow col
s ->
- Array.mapi
col
s ~f:(
- fun
col
data ->
- f ~r
ow ~col
~data
+ fun r
k
s ->
+ Array.mapi
k
s ~f:(
+ fun
k
data ->
+ f ~r
~k
~data
)
)
)
)
- let get t ~r
ow ~col
=
- t.(r
ow).(col
)
+ let get t ~r
~k
=
+ t.(r
).(k
)
end
end
@@
-102,9
+102,9
@@
module Conway : CELL = struct
end
end
-let main r
ows col
s () =
+let main r
s k
s () =
Random.self_init ();
Random.self_init ();
- let grid = Matrix.create ~r
ows ~col
s ~data:() |> Matrix.map ~f:Conway.create in
+ let grid = Matrix.create ~r
s ~k
s ~data:() |> Matrix.map ~f:Conway.create in
Matrix.print grid ~to_string:Conway.to_string
Matrix.print grid ~to_string:Conway.to_string
This page took
0.034074 seconds
and
4
git commands to generate.