更改字段值时复制记录

假设你有这种类型:

data Person = Person { name::String, age:: Int } deriving (Show, Eq)

和两个值:

alex = Person { name = "Alex", age = 21 }
jenny = Person { name = "Jenny", age = 36 }

可以通过从 alex 复制来创建 Person 类型的新值,指定要更改的值:

anotherAlex = alex { age = 31 }

alexanotherAlex 的值现在为:

Person {name = "Alex", age = 21}

Person {name = "Alex", age = 31}