Changes between Version 7 and Version 8 of Records/TypePunningDeclaredOverloadedRecordFields


Ignore:
Timestamp:
Mar 12, 2012 4:37:20 AM (3 years ago)
Author:
AntC
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Records/TypePunningDeclaredOverloadedRecordFields

    v7 v8  
    126126 
    127127{{{ 
     128    data HR = HR { rev :: (forall a. [a] -> [a]) }                      -- would generate: 
     129 
     130    type instance SetResult HR t  = HR                                  -- HR is not parametric 
     131 
     132    newtype Rev = Rev (forall a. [a] -> [a]) 
     133    rev :: HR -> Rev -> (forall a. [a] -> [a])                          -- generated selector is monomorphic 
     134    rev r = get r (undefined :: Rev) 
     135 
     136    instance Has HR Rev                         where                   -- Has instance generated 
     137        get HR{ rev = (Rev x) } = x                                     -- looks OK, but see GetResult 
     138        set x HR{ .. }    = HR{ rev = x, .. }                           -- note x is already wrapped 
     139 
     140    type instance GetResult HR Rev     = (forall a. [a] -> [a])         -- no can do! not allowed forall's on RHS 
     141                                                                        -- (and can't do equality constraints on type instances) 
     142 
     143{- instead, do explicit newtype wrapping for higher-rank types   -} 
     144 
    128145    newtype Rev = Rev (forall a. [a] -> [a])        deriving (Has) 
    129     newtype OrdRev = OrdRev (Ord a => [a] -> [a])   deriving (Has) 
     146    newtype OrdRev = OrdRev (Ord a => [a] -> [a])   deriving (Has)      -- class constrained 
    130147 
    131     data HR = HR{ rev :: Rev, ordRev :: OrdRev } sharing (Rev, OrdRev) 
     148    data HRW = HRW{ rev :: Rev, ordRev :: OrdRev } sharing (Rev, OrdRev) 
    132149}}} 
    133  * Note that to get/set those h-r fields needs them to be un/wrapped within the user code. 
     150 * Now we can now apply the wrapped function polymorphically (after unwrapping within the user code. 
     151 
    134152 
    135153.