Changes between Version 19 and Version 20 of Records/DeclaredOverloadedRecordFields/ImplementorsView


Ignore:
Timestamp:
Mar 3, 2012 5:29:22 AM (2 years ago)
Author:
AntC
Comment:

Option 3 for fieldLabels

Legend:

Unmodified
Added
Removed
Modified
  • Records/DeclaredOverloadedRecordFields/ImplementorsView

    v19 v20  
    5454}}} 
    5555    '''Note:''' the desugarring only applies where the field and function are the same name (and record type argument and result type). Otherwise this syntax is declaring a regular function with a record constraint (could be a 'virtual' field). 
     56 
     57 
     58=== Option Three: Mixed In-situ and Declared ORF === 
     59 
     60    (See discussion at http://www.haskell.org/pipermail/glasgow-haskell-users/2012-March/022061.html "My main complaint against DORF is that having to write fieldLabel declarations for every field you want to use is onerous.") 
     61 
     62There may be some (perhaps most) of the field names in a record type that appear only in that record type. Then this: 
     63{{{ 
     64data Cust_AdHoc = CustAH{ customer_id :: Int, x, y :: String } sharing (customer_id) deriving (...) 
     65}}} 
     66For the non-shared x and y, saves the burden of a `fieldLabel`, by declaring it for you: 
     67{{{ 
     68        data Proxy_x 
     69        x :: Cust_AdHoc{ x :: String } => Cust_AdHoc -> String    -- Note: monomorphic record type 
     70        x r = get r (undefined :: Proxy_x) 
     71}}} 
     72So field selector function x has the same type (in effect) as would have the H98 field selector. 
    5673 
    5774