Changes between Version 8 and Version 9 of Records/TypePunningDeclaredOverloadedRecordFields
- Timestamp:
- 03/11/12 21:57:17 (14 months ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Records/TypePunningDeclaredOverloadedRecordFields
v8 v9 84 84 * The Type must be declared once (within the scope), and is then under regular name control.[[BR]](Probably you're doing this already for critical fields to share.) 85 85 * The type functions are not associated types, because: 86 * GetResultfor shared fields depends only on the Field's type (per Customer_id above);87 * SetResult for non-parametric record types does not change the record type.86 * `GetResult` for shared fields depends only on the Field's type (per Customer_id above); 87 * `SetResult` for non-parametric record types continues the same record type. 88 88 * The field selector function also must be declared once, defined punning on the field's type.[[BR]](See below for syntactic sugar to declare these.) 89 * Possible '''downside:''' for non-`sharing` fields, what's the risk there's already a Type with the same name (upshifted) __and__ that the name is an 'accidental' clash? 89 90 90 91 It is an error to be `sharing` a record field without there being a same-named type in scope. The desugar for the data decl would create the instance to use the Type, but then the instance would fail. … … 120 121 '''Technical capabilities''' and limitations for the `Has` class: 121 122 * Monomorphic fields can be `get` and `set`. 122 * Parametric polymorphic fields can be applied in polymorphic contexts, and can be `set` including changing the type of the record.[[BR]](This uses the SetResult type function.) 123 * Parametric polymorphic fields can be applied in polymorphic contexts, and can be `set` including changing the type of the record.[[BR]](This uses the SetResult type function.)[[BR]]To do: provide example with desugarring. 123 124 * Multiple fields can be updated in a single expression (using familiar H98 syntax), but this desugars to nested updates, which is inefficient. 124 125 * Pattern matching and record creation using the data constructor prefixed to { ... } work as per H98 (using `DisambiguateRecordFields` and friends). 126 * But the types are subtlely different vs. polymorphic update: you must explicitly wrap the types.[[BR]](So this is __not__ backwards compatible. Can we do this?:[[BR]]In `Constr{ fld = e }`, if `e` not type `Fld`, enwrap it with a `Fld` constructor.) 125 127 * Higher-ranked polymorphic fields (including class-constrained) can be applied in polymorphic contexts, and can be set -- __providing__ they are wrapped in a newtype. Here is SPJ's example: 126 128 … … 140 142 type instance GetResult HR Rev = (forall a. [a] -> [a]) -- no can do! not allowed forall's on RHS 141 143 -- (and can't do equality constraints on type instances) 144 {- ??can we do better -- perhaps an eq constraint on the Has instance: 145 (GetResult HR Rev ~ ([a] -> [a])) => Has ... 146 plus a non-commital result for getResult 147 -} 142 148 143 {- instead, do explicit newtype wrapping for higher-rank types -}149 {- instead, do explicit newtype wrapping for higher-rank types: -} 144 150 145 151 newtype Rev = Rev (forall a. [a] -> [a]) deriving (Has)
