gaa*_*kam 2 haskell tuples variable-assignment
在这里,我学到了一种有用的Haskell语法,可以在不完全重写记录的情况下修改记录的元素:
oldrecord { somefield = newvalue }
Run Code Online (Sandbox Code Playgroud)
元组是否有类似的可能?
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
Run Code Online (Sandbox Code Playgroud)
这是否有可能类似于记录,还是我必须重写整个元组?
moo*_*ose 11
我认为“重写整个元组”是指,
(\(a,b,_,d,e) -> (a,b,3.2,d,e))
Run Code Online (Sandbox Code Playgroud)
有用于元组的透镜,链接中有很多示例。
_3 .~ (3.2 :: Double)
Run Code Online (Sandbox Code Playgroud)