本文介绍了如何在Haskell中创建数字列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要创建一个函数来制作一块行和列大小的板,然后用零填充它.mkBoard 2 3将使[[0,0,0],[0,0,0]]
I need to create a function that makes a board of size row and column and then populate that with zeros. mkBoard 2 3 would make[[0,0,0],[0,0,0]]
我真的不知道从哪里开始,因为我是Haskell编程的新手,我当时认为该函数应该是这样的:
I don't really know where to start as I am new to Haskell programming I was thinking that the function would be something like this:
:mkBoard = genericMkBoard 0UPD :您也可以使它与replicate更加一致(感谢@chepner):
UPD: Also you can make it like this to be more consistent with replicate (thanks to @chepner):
replicate2D m n x = replicate m (replicate n x) mkBoard m n = replicate2D m n 0这篇关于如何在Haskell中创建数字列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!