I am representing a table to store data as a Haskell record and I was wondering if there is a function to get the number of fields given a record?
I ask as I have a type class to represent a table and one of class functions is noOfCols; which correspond to the number of fields in a record representing a table.
data Price = Price {bid=[Float], ask=[Float]}
class Table a where
noOfCols :: a -> Int
...
instance Table Price where
noOfCols t = 2
...
So the problem is that I will be constantly adding new fields so it's possible to forget to update the instance implementation of noOfCols when I add new columns (fields) to Price; i.e. leaving it to 2 when I now have 3 or more fields.
Is there a function that can provide the number of fields for a given record so I don't have to make a manual edit everytime I change the record?