Changes between Version 14 and Version 15 of Records/OverloadedRecordFields


Ignore:
Timestamp:
Jan 16, 2012 12:10:01 PM (3 years ago)
Author:
strake888
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Records/OverloadedRecordFields

    v14 v15  
    374374== Alternative Proposal == 
    375375 
     376First, we define a class for types with a member at 'k': 
     377 
    376378{{{ 
    377379class Has r k v where select :: r -> k -> v; 
     380}}} 
     381 
     382Next, we define a class for types with a mutable member of certain type: 
     383 
     384{{{ 
    378385class Quasifunctor r s k u v where qfmap :: k -> (u -> v) -> r -> s; 
    379386}}} 
    380387 
    381 Then, for example: 
     388`Quasifunctor r s k u v` means that `r` and `s` have members of types `u` and `v`, in turn, both with selector `k`; thus, one can mutate the member at 'k' with an arbitrary function of type `u -> v`, and the overall function is of type `r -> s`; i.e. one can lift a function of type `u -> v` to a function of type `r -> s`. This is the record update. 
     389 
     390`qfmap` is the lifter function. The first argument serves to specify which member is meant. 
     391 
     392This ought to allow polymorphic mutation; to set member at "x" to value `x` is simply `qfmap (undefined :: "x") (const x)`, though this mechanism is of course more general; one could `qfmap` any arbitrary function, not just a constant function. 
     393 
     394For example: 
    382395{{{ 
    383396data R a = R { x :: a };