Let's say I have the following record ADT:
data Foo = Bar { a :: Integer, b :: String, c :: String }
I want a function that takes a record and returns a record (of the same type) where all but one of the fields have identical values to the one passed as argument, like so:
walkDuck x = Bar { a = a x, b = b x, c = lemonadeStand (a x) (b x) }
The above works, but for a record with more fields (say 10
), creating a such function would entail a lot of typing that I feel is quite unnecessary.
Are there any less tedious ways of doing the same?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…