ocaml - Doing a N-dimensional walk in pure functional ML? -
This idea is to be run on many dimensions, each one is defined as the limit
( funny foo yx
or function such as
> funny foo zyx
can be applied to whole class X Y or Cube X Y * Z.
SML / NJ 'like my implementation below:
test2.sml: 7.5-22.6 Error: Closed right-to-function function type [circular] expression Do not agree: (Actual -> Z) -> Unit result type: 'Z -'> declaration in Y: move = (fn arg = & gt; (fn & lt; pat & gt; = & Gt; & lt; exp & gt;))
Here is the code:
Fun Playing [] _ = () | Walking (R: RS) f = val (k 0, k1, n) = r val delta = k1 - k = val phase = delta / real n funny loop 0 _ = () | loop i k = walk rs (f) k ); (* Note (FK) "Eats" the first argument I think that SML does not like the change in the middle of its definition * like the type of change) loop (I + 1) (K + phase) finally loop n k the end of the DO2D yx = (* ... *) () Fun do3D zyx = (* ... *) () Val x_axis = (0.0, 1.0, 10) val y_axis = (0.0, 1.0, 10) val z_axis = (0.0, 1.0, 10) Val _ = walking [ Y_axis, x_axis] do2D val _ = walking [z_axis, y_axis, x_axis] do3D
Is this type of build also possible << Strong>
what is to run
M.L. Type Exceptional in the system?
Vel Watch: category list - & gt; (Actual -> Genuine -> Unit) - & gt; Walking Unit Valid: Category List - & gt; (Actual -> Real -> Genuine -> Unit) - & gt; Unit
The same value with both types in ML probably does not exist.
We can easily generate value for the desired types, however.
type category = real * actual * int signature WALK = sig type variable applied: category list - & gt; Apply - & gt; Unit End Structure Walk0: Walk = Strip Type Applied = Unit Fun Play _ _ = () End Joke WALKF (Walk: Walk): Walk = Strip Type Applied = Actual - & gt; to walk. Fun walk (low, high, step) :: rs) f = let's have fun loop i = if i> (Again) and then wal x = less + (high - less) * actual move in real i / walk (walk.walk rs (fx); loop (i + 1)) loop end end struture walk1 = walkf (its Along with, the following values exist with the desired type. val walk.walk: category list -> entity -> unit val walk1.walk: category list -> gt; (Real -> Units) -> Unit Val Walk2.walk: Category List -> (Actual -> Genuine -> Unit) -> Unit Val Walk3.walk: Category List - & Gt; (Actual -> Real -> Vertical C -> Unit) -> Unit
Then you only need to write
val _ = walk2.walk [y_axis, x_axis ] Do2d val _ = walk3.walk [z_axis, y_axis, X_axis] do3D
To use the same walking
for each dimension, you There is a need to use the same type of each dimension.
Fun Walking Void F = F Zero | Walking ((Low, High, Step) :: RS) F = Let's Have Fun Loop i = If i> step then () and wal x = less + (high - less) * actual move in real i / No rs (fn xs - & gt; F (x :: xs)); Loop 0 and
at the end of the loop (i + 1) type
Weal Watch: range list - & gt; (Actual list -> entity) - & gt;
Enjoy your use
DO2D [y, x] = (* ... *) () Shifter do3D [z, y, x] ] = (* ... *) ()
Comments
Post a Comment