[Haskell-cafe] Dealing with heterogeneously-typed lists?

Leif Warner abimelech at gmail.com
Tue Aug 12 18:44:55 EDT 2008


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080812/200b7d02/attachment.htm


More information about the Haskell-Cafe mailing list