Record syntax seems extremely convenient compared to having to write your own accessor functions. I’ve never seen anyone give any guidelines as to when it’s best to use record syntax over normal data declaration syntax, so I’ll just ask here.
Record syntax seems extremely convenient compared to having to write your own accessor functions.
Share
You should use record syntax in two situations:
For instance a Point type can be simply declared as:
It is obvious that the first Int denotes the x coordinate and the second stands for y. But the case with the following type declaration is different (taken from Learn You a Haskell for Great Good):
The intended type layout is: first name, last name, age, height, phone number, and favorite ice-cream flavor. But this is not evident in the above declaration. Record syntax comes handy here:
The record syntax made the code more readable, and saved a great deal of typing by automatically defining all the accessor functions for us!