Changes between Version 2 and Version 3 of Records/TypePunningDeclaredOverloadedRecordFields


Ignore:
Timestamp:
Mar 12, 2012 3:07:11 AM (2 years ago)
Author:
AntC
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Records/TypePunningDeclaredOverloadedRecordFields

    v2 v3  
    2727TPDORF approaches h-r fields in a different way, which supports __both__ setting and getting those fields. (I'm not claiming this is a ''solution'', more a well-principled work-round. And not a hack.) 
    2828 
    29 '''The main insight''' is that to manage large-scale data models (in which namespacing becomes onerous 
     29'''The main insight''' is that to manage large-scale data models (in which namespacing becomes onerous, and name sharing would be most beneficial), there are typically strong naming conventions and representation hiding for critical fields. For example: 
     30{{{ 
     31    newtype Customer_id = Customer_id Int                               -- data dictionary, could be a data decl 
     32                                                                        -- constructor named same as type 
     33    data Customer = Customer {                                          -- likewise 
     34         customer_id :: Customer_id                                     -- field name puns on the type 
     35       , firstName   :: String                                          -- not a critical/shared field 
     36       , lastName    :: String 
     37       , ...    
     38       }       sharing (customer_id, ...)  deriving (...)               -- new sharing syntax 
     39}}} 
    3040 
    31 , there is a third argument for the field's resulting type. This is set at the instance level using equality constraints in a functional-dependencies style. Here is the `Has` class (`r` is the record, `fld` is the proxy type for the field, `t` is the field's type), with an example record declaration, its `Has` instance, and examples of use: 
     41TPDORF makes a virtue of this punning. (So extend's H98's and NamedFieldPuns punning on the field name.) This allows for some syntactic shortcuts, but still supporting H98-style declaring field names within the record decl for backwards compatibility. 
     42 
     43Here is the `Has` class with instances for the above Customer record, and examples of use: 
    3244{{{ 
    3345    class Has r fld t                                             where