Haskell Language Record Syntax Copying Records while Changing Field Values

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

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}


Got any Haskell Language Question?