3 ms·
Nah. Not if you use an appropriate form to extract the desired member while leaving the rest alone. data Person = Person { name :: String ,
by knome 13y ago
Nah. Not if you use an appropriate form to extract the desired member while leaving the rest alone.
data Person = Person { name :: String ,
age :: Integer ,
height :: Integer ,
weight :: Integer
}
deriving (Show)
makeOlder p@(Person { age = current }) increase = p { age = current + increase }
main = let b = (Person { name = "Bob", age = 50, height = 72, weight = 190 })
c = b { age = (age b) + 10 }
d = makeOlder b 10
in do
putStrLn (show b)
putStrLn (show c)
putStrLn (show d)
-- ~/test/E$ ./M
-- Person {name = "Bob", age = 50, height = 72, weight = 190}
-- Person {name = "Bob", age = 60, height = 72, weight = 190}
-- Person {name = "Bob", age = 60, height = 72, weight = 190}