Records in PureScript
Records are basically like Objects in JS. Yet, immutable, of course. As with functions, we can and should describe their structure and types before initialising them:
type Person = { name :: String, age :: Int }
max :: Personmax = { name: "Max", age: 22 }
main = log (show max)The code will log the following in the console:
{ age: 22, name: "Max" }As you can see, just like an object in JavaScript.
Accessing a records properties
Section titled “Accessing a records properties”Accessing those works just like in JavaScript, using the ”.”-operator.
main = log (show max.name)We can also create a function to access the name-property of a Person-type variable:
getName :: Person -> StringgetName person = person.name
main = log (getName max)