[英]Haskell - add n number of 0s into a list
I'm quite new to haskell.我对haskell很陌生。 Given list [a] of integers and an integer n, how can I add n 0s in the beginning of list [a].
给定整数列表 [a] 和整数 n,如何在列表 [a] 的开头添加 n 个 0。 Many thanks.
非常感谢。
This is super straightforward: it's just这非常简单:它只是
replicate n 0 ++ list
where replicate
just makes a list of n
occurrences of the specified element, and ++
combines the lists together.其中,
replicate
只是生成一个包含指定元素的n
次出现的列表,而++
将这些列表组合在一起。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.