Changes between Version 11 and Version 12 of ExistingRecords


Ignore:
Timestamp:
Mar 29, 2006 3:03:28 PM (8 years ago)
Author:
nhn@…
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ExistingRecords

    v11 v12  
    201201}}} 
    202202 
     203=== Comment === 
     204 
     205(Comment from Niklas Broberg) 
     206 
     207This suggestion would go a long way to alleviate the burden of 
     208boiler-plate coding. It is a conservative extension, and it is 
     209intuitive at that. Indeed I believe I have written code with the 
     210suggested update mechanism many times without thinking on the type 
     211mismatch (and been beaten on my fingers by the compiler of course). 
     212:-) 
     213 
     214Is this really necessary? Adding `~` seems less intuitive to me than 
     215just writing 
     216{{{ 
     217foo :: T a -> T Int 
     218foo x@(C1 {}) = x {f1 = 1} 
     219foo x@(C2 {}) = x {f1 = 2} 
     220foo x         = x 
     221}}} 
     222or 
     223{{{ 
     224foo x = x {f2 = f2 x + 1} 
     225}}} 
     226for the last example. From an implementor's point of view, if we 
     227expect the proper coercions to be inferred by the type checker it 
     228would still have to check that there are indeed no more fields than 
     229other than `f1` that mention the parameter `a`, and also that there 
     230are no more constructors that mention `f1`. Wouldn't it be just as 
     231simple to assert that for all the fields that mention `a`, none of 
     232these appear in any of the remaining constructors? 
     233 
     234On the other hand pattern matching would certainly be more expressive 
     235if `~` is added, so perhaps adding it has merit of its own. If we 
     236write 
     237{{{ 
     238foo :: T a -> T Int 
     239foo x@(C1 {}) = x {f1 = 1} 
     240foo x@(C2 {}) = x {f1 = 2} 
     241foo x         = x {~f1} 
     242}}} 
     243there could still be more constructors in T a that do mention the `f1` 
     244field, but there is no matching clause for them in the definition of 
     245`foo`. But I would see that as a second separate proposal, e.g. a 
     246Proposal for Negation in Record Pattern Matching. Sure it would fit 
     247very well with the Polymorphic record update discussed here, but I 
     248would think they should be treated separately. 
     249 
    203250= Meta-Proposal = 
    204251