Suppose you have this type:
data Person = Person { name :: String, age:: Int } deriving (Show, Eq)
and two values:
alex = Person { name = "Alex", age = 21 }
jenny = Person { name = "Jenny", age = 36 }
a new value of type Person
can be created by copying from alex
, specifying which values to change:
anotherAlex = alex { age = 31 }
The values of alex
and anotherAlex
will now be:
Person {name = "Alex", age = 21}
Person {name = "Alex", age = 31}