Dealing with heterogeneously-typed lists?

Hi all, I'm dealing with some datatype, say: data Invoice = Invoice { invoiceNum :: String, dollarAmt :: Currency, printDate :: Date, dueDate :: Date, vendorNum :: Int, vendorName :: String, isStock :: Bool, } that I want to put in or take out of rows in xml spreadsheets, databases, that sort of thing. The elements of the spreadsheet row want type annotations like "String", "Number, "DateTime", etc. Also, each data element is required to be formatted differently, e.g. (show dueDate) ++ "T00:00:00", because the spreadsheet format wants a time tacked on, too. I know in a language like Java or C++ I might do some sort of run-time type identification, which would detect the type of each element in the list, and output it appropriately. As it is, I'm tupling each accessor function with the the type the spreadsheet wants, as a string: e.g. [(invoiceNum, "String"), (dollarAmt, "Number"), (printDate, "DateTime"),...] Is there a better way of doing this? Maybe messing with the "show" function to precede the string representation with a few characters about the type it's supposed to be? Or would looking into something like this be a good idea? It looks a lil old... http://homepages.cwi.nl/~ralf/HList/http://homepages.cwi.nl/%7Eralf/HList/ --Strongly typed heterogeneous collections Thanks! -Leif

2008/8/12 Leif Warner
I know in a language like Java or C++ I might do some sort of run-time type identification, which would detect the type of each element in the list, and output it appropriately.
I think I've missed a step. Why do you want to break the fields of an Invoice out into a list in the first place?

On 13 Aug 2008, at 00:44, Leif Warner wrote:
Hi all, I'm dealing with some datatype, say: data Invoice = Invoice { invoiceNum :: String, dollarAmt :: Currency, printDate :: Date,
dueDate :: Date, vendorNum :: Int, vendorName :: String, isStock :: Bool, } You probably don't want to put these things into a list at all. Instead, you want to define an Instance of the Show class for Invoice.
Bob
participants (3)
-
Bryan O'Sullivan
-
Leif Warner
-
Thomas Davie