Changes between Version 22 and Version 23 of Records/OverloadedRecordFields/Plan


Ignore:
Timestamp:
Jul 17, 2013 6:37:44 PM (2 years ago)
Author:
adamgundry
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Records/OverloadedRecordFields/Plan

    v22 v23  
    6262{{{
    6363type instance GetResult (T a) "x" = [a]
     64
    6465instance (b ~ [a]) => Get (T a) "x" b where
    65   getFld (MkT { x = x }) = x
     66  getFld _ (MkT x) = x
    6667}}}
    6768
     
    166167=== Lens integration ===
    167168
    168 As noted above, supporting a polymorphic version of the existing record update syntax (in its full generality) is difficult. However, suppose we also generate instances of the following class, which permits type-changing update of single fields:
     169As noted above, supporting a polymorphic version of the existing record update syntax (in its full generality) is difficult. However, we can generate instances of the following class, which permits type-changing update of single fields:
    169170
    170171{{{
     
    175176}}}
    176177
    177 It was implied above that a field like `foo` translates into `getFld (Proxy :: Proxy "foo") :: Get r "foo" t => r -> t`, but this is not quite the whole story. Where possible, we would like fields to be usable as lenses (e.g. using the [http://hackage.haskell.org/package/lens lens] package). This requires a slightly more general translation, using
     178For example, the datatype `T` above would give rise to these instances:
     179
     180{{{
     181type instance SetResult (T a) "x" [c] = T c
     182
     183instance (b ~ [c]) => Set (T a) "x" b where
     184  setFld _ (MkT _) y = MkT y
     185}}}
     186
     187It was implied above that a field like `foo` translates into `getFld (Proxy :: Proxy "foo") :: Get r "foo" t => r -> t`, but this is not quite the whole story. We would like fields to be usable as lenses (e.g. using the [http://hackage.haskell.org/package/lens lens] package). This requires a slightly more general translation, using
    178188
    179189{{{
     
    210220}}}
    211221
    212 Now `fieldLens foo` is a lens whenever `foo` is an overloaded record field that can be updated individually (i.e. a `Set` instance exists).
    213 
    214 `Set` instances are not required when using fields as functions, only when using them as more general `Accessor` instances, so if a `Set` instance cannot be generated (since the field cannot be updated without updating other fields) the basic story about projections still works.
     222Now `fieldLens foo` is a lens whenever `foo` is an overloaded record field.
    215223
    216224