Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我想只使用sml中的高阶函数对矩阵进行转置,但我真的很喜欢堆栈_Sml_Smlnj - Fatal编程技术网

我想只使用sml中的高阶函数对矩阵进行转置,但我真的很喜欢堆栈

我想只使用sml中的高阶函数对矩阵进行转置,但我真的很喜欢堆栈,sml,smlnj,Sml,Smlnj,我想在sml中只使用高阶函数对矩阵进行转置,但我实际上是堆栈,这里是我所拥有的 fun transpose [] = [] | transpose ([]::_) = [] | transpose mat = (map hd mat)::(transpose(map tl mat)); 但是我不想调用转置,因为递归同样是不允许的。我还想去掉案例。有什么帮助吗 transpose mat = tabulate (length (nth (mat,0)),fn i => map (fn l

我想在sml中只使用高阶函数对矩阵进行转置,但我实际上是堆栈,这里是我所拥有的

fun transpose [] = []
| transpose ([]::_) = []
| transpose mat = (map hd mat)::(transpose(map tl mat));
但是我不想调用转置,因为递归同样是不允许的。我还想去掉案例。有什么帮助吗

transpose mat = tabulate (length (nth (mat,0)),fn i => map (fn l => (nth (l,i))) mat)
或者,为了使空矩阵更具可读性和安全性:

transpose mat =
  let
    val rows = length mat
    val cols = if rows > 0
               then length (nth (mat,0))
               else 0
  in
    tabulate (cols, fn i => map (fn row => (nth (row, i)) mat)
  end
或者,为了使空矩阵更具可读性和安全性:

transpose mat =
  let
    val rows = length mat
    val cols = if rows > 0
               then length (nth (mat,0))
               else 0
  in
    tabulate (cols, fn i => map (fn row => (nth (row, i)) mat)
  end