如何只修改元组的一个元素而不完全重写它?

How to modify just one element of a tuple without rewriting it completely?

在这里我学到了一个有用的 Haskell 语法来修改记录的元素而不完全重写它:

oldrecord { somefield = newvalue }

元组也可以做类似的事情吗?

type ABigTuple = (Int, Int, Double, Int, String)

aBigTuple :: ABigTuple
aBigTuple = (5, 6, 3.2, 10, "asdf") 

anotherBigTuple = -- replace the 3rd elt of the prev tuple with 5.5 i/o 3.2

这是否可以类似于记录的方式,或者我是否必须重写整个元组?

我假设 "rewriting the whole tuple" 你的意思是,

(\(a,b,_,d,e) -> (a,b,3.2,d,e))

lenses 个元组,link 有很多例子。

_3 .~ (3.2 :: Double)