Home
Reading
Searching
Subscribe
Sponsors
Statistics
Posting
Contact
Spam
Lists
Links
About
Hosting
Filtering
Features Download
Marketing
Archives
FAQ
Blog
 
Gmane
From: <oleg <at> pobox.com>
Subject: HList with new records, in darcs.haskell.org
Newsgroups: gmane.comp.lang.haskell.general
Date: Monday 3rd July 2006 00:59:05 UTC (over 11 years ago)
The HList library of strongly typed heterogenous lists, records,
type-indexed products (TIP) and co-products is now accessible via
DARCS 
	http://darcs.haskell.org/HList/

The library contains a new representation for open records. Previously
(Record.hs) a record is a Scheme-like heterogenous associative list,
that is, the list of pairs of field label and the corresponding field
value. The HList library uses the type of the label, therefore, the
run-time representation of the label is actually `undefined'. Thus, a
record built as
	rec1 = label1 .=. True .*. lab2 .=. 'c' .*. emptyRecord
has the run-time representation
	HCons (undefined,True) (HCons (undefined,'c) HNil)

In the new representation, RecordP.hs in the repository, the record is
a heterogeneous list of field values. Label _types_ are also bundled in a
heterogenous list of types, which annotate the record type as a
phantom type. Thus if we write
	rec2 = label1 .=. True .*. lab2 .=. 'c' .*. emptyRecordP

rec2 now has the run-time representation of 
	HCons True (HCons 'c HNil)

That is, labels are nowhere to be found in the run-time
representation. Field labels become compile-time-only entity. Of
course, by making labels Typeable and using the methods of that class
it is possible to access the label information at run-time, if so
desired. 

The new representation of the records supports the old record
interface; for example, both (rec1 .!. lab2) and (rec2 .!. lab2)
evaluate to 'c', the value of the field lab2. RecordP are similar to
TIP; however, the values of RecordP are indexed by the label types
rather than by their own types. RecordP have an advantage for
representing tables -- homogenous collections of rows, which in turn are
records of fields (columns):
	newtype Table ls vs = Table [RecordP ls vs]
All records have exactly the same field types in the same
sequence. The run-time representation of the table is just the
collection of all the field values. The database schema, labels and
the column types, is a compiled-time entity and used for checking and
compiling of database operations.
 
CD: 3ms