
On 04/26/2015 06:13 AM, martin wrote:
Hello all,
I suppose the natural representation for a Table is a List of Tuples. Or more generally I'll probably end up with a type "Table a" where a stands for the Columns.
I cannot figure out how to add a new Column to a Table. What would be the type of such an operation? If I just want to add an empty Column (which what an RDBMS would do), would I do something like this?
addColumn :: ColumnDef -> Table a -> Table b
But what is this ColumnDef? It would need to contain the name and type of the new column. To implement this operation I would have to somewehre add a column to something. But what is the type of this something. I don't see how I can add a component to a Tuple in a generic way, or can I?
type Person = ( Int, -- ID String, -- Name Int, -- Age Bool -- Evil bit ) type Place = ( Int, -- ID String, -- Name Double, -- Longitude Double, -- Latitude Double -- Elevation ) data Column = Person | Place type Table = [Column] addColumn :: Table -> Column -> Table addColumn table col = table ++ [col]