如何修改Haskell列表的第i个元素? [英] how to modify the i-th element of a Haskell List?
本文介绍了如何修改Haskell列表的第i个元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找一种修改haskell List的第i个元素的方法.让我们说foobar
是这样的功能,那么下面的工作.
I'm looking for a way to modify the i-th element of haskell List. let says foobar
is such a function, then the following works.
let xs = ["a","b","c","d"]
foobar xs 2 "baba" -- xs = ["a","b","baba","d"]
感谢您的回复!
推荐答案
您可以使用splitAt
做到这一点:
You can do it with splitAt
:
Prelude> let xs = ["a","b","c","d"]
Prelude> (\(l,_:r)->l++"baba":r) $ splitAt 2 xs
["a","b","baba","d"]
这篇关于如何修改Haskell列表的第i个元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文