如何在OCaml中打印一个列表的列表

3

你好,我正在尝试打印我的列表,但是我无法做到。我已经尝试了很多方法,但是都没有找到解决方案。

我尝试将我的列表转换为数组,因为我知道如何打印数组,并且我正在使用这个函数 let sll_to_saa sll = Array.of_list (List.map Array.of_list sll) 但它不能将列表转换为简单的数组。它转换为一个Array Array

有人可以帮助我吗?:D


打印整数列表的列表:let print_int_list_list = List.iter (List.iter (Printf.printf "%d ")) - Anton Trunov
2个回答

5

打印列表:let printlist l = List.iter (fun x -> print x) l
打印列表的列表:List.iter (fun ll -> printlist ll) l

关于你的函数sll_to_saa:它根据定义返回一个数组的数组。

如果你希望返回单个数组:也许你想要得到由列表的连接组成的数组。


0
如果您可以打印列表(例如:在OCaml中打印列表),则可以使用concat别名flatten将列表的列表转换为列表,然后打印该列表。
val concat : 'a list list -> 'a list
Concatenate a list of lists. The elements of the argument are all concatenated together (in the same order) to give the result. Not tail-recursive (length of the argument + length of the longest sub-list).

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接