Changes between Version 37 and Version 38 of Records/OverloadedRecordFields/Plan


Ignore:
Timestamp:
Sep 9, 2013 2:23:05 PM (23 months ago)
Author:
adamgundry
Comment:

hull

Legend:

Unmodified
Added
Removed
Modified
  • Records/OverloadedRecordFields/Plan

    v37 v38  
    272272
    273273
     274=== Type-changing update: type families ===
     275
     276Consider the following definitions:
     277
     278{{{
     279type family Goo a
     280data T a = MkT { foo :: Goo a }
     281}}}
     282
     283In order to change the type of the field `foo`, we would need to define something like this:
     284
     285{{{
     286type instance SetResult (T a) "foo" (Goo b) = T b
     287}}}
     288
     289But pattern-matching on a type family (like `Goo`) doesn't work, because type families are not injective. Thus we cannot change type variables that appear only underneath type family applications. We generate an instance like this instead:
     290
     291{{{
     292type instance SetResult (T a) "foo" x = T b
     293}}}
     294
     295On the other hand, in the datatype
     296
     297{{{
     298data U a = MkU { bar :: a -> Goo a }
     299}}}
     300
     301it is fine to change `a` when updating `bar`, because it occurs rigidly as well as under a type family, so we can generate this:
     302
     303{{{
     304type instance SetResult (U a) "bar" (b -> x) = U b
     305}}}
     306
     307This is all a bit subtle. We could make updates entirely non-type-changing if the field type contains a type family, which would be simpler but somewhat unnecessarily restrictive.
     308
    274309
    275310== Design choices ==