アイデアは、それぞれが範囲として定義された複数の次元を歩くことです
(* lower_bound, upper_bound, number_of_steps *)
type range = real * real * int
そのため、四角形 X Y または立方体 X Y*Zのような関数を適用したり、それらに適用しfun foo y xたりできます。fun foo z y x
SML/NJ は以下の私の実装を好まない:
test2.sml:7.5-22.6 Error: right-hand-side of clause doesn't agree with function result type [circularity]
  expression:  (real -> 'Z) -> unit
  result type:  'Z -> 'Y
  in declaration:
    walk = (fn arg => (fn <pat> => <exp>))
コードは次のとおりです。
fun walk []      _ = ()
  | walk (r::rs) f =
  let
    val (k0, k1, n) = r
    val delta = k1 - k0
    val step = delta / real n
    fun loop 0 _ = ()
      | loop i k = 
        let in
          walk rs (f k) ;          (* Note (f k) "eats" the first argument.
                                      I guess SML doesn't like having the
                                      type of walk change in the middle of its
                                      definition *)
          loop (i - 1) (k + step)
        end
  in
    loop n k0
  end
fun do2D y x = (* ... *) ()
fun do3D z y x = (* ... *) ()
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 _ = walk [y_axis, x_axis] do2D
val _ = walk [z_axis, y_axis, x_axis] do3D
この種の構成は可能ですか?
どんなポインタも歓迎します。