Changes between Version 1 and Version 2 of Records/TypeIndexedRecords
 Timestamp:
 Mar 3, 2012 4:30:20 PM (4 years ago)
Legend:
 Unmodified
 Added
 Removed
 Modified

Records/TypeIndexedRecords
v1 v2 1 Proposal for new Haskell record system. Record selection is simple operator. Keys are arbitrary types. 1 Proposal for new Haskell record system. Record selection is simple operator. Keys are arbitrary types. Scope is controlled as scope of key types. 2 2 3 3 = Basics = … … 8 8 which means that r has member of type v with key type k, and for types with mutable member at 'k' 9 9 {{{ 10 class (Has k u r, Has k v s) => Quasifunctor r s k u vwhere qfmap :: k > (u > v) > r > s;10 class (Has k u r, Has k v s) => Quasifunctor k u v r s where qfmap :: k > (u > v) > r > s; 11 11 }}} 12 12 which 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. 13 13 14 More to follow. 14 A record type is of the form 15 {{{ 16 type R a b c ... = { X ::. a, Y ::. b, Z ::. c, ... }; 17 }}} 18 which automatically generates 19 {{{ 20 instance Has X a (R a b c ...); 21 instance Has Y b (R a b c ...); 22 instance Has Z c (R a b c ...); 23 ... 24 instance Quasifunctor X a a' (R a b c ...) (R a' b c ...); 25 instance Quasifunctor Y b b' (R a b c ...) (R a b' c ...); 26 instance Quasifunctor Z c c' (R a b c ...) (R a b c' ...); 27 ... 28 }}} 29 30 == Record selection and mutation == 31 Let 32 {{{ 33 type R a b c = { X ::. a, Y ::. b, Z ::. c, ... }; 34 35  keys 36 data X = X; 37 data Y = Y; 38 data Z = Z; 39 }}} 40 41 Then `r.X :: a` is the member of `r` at `X`, and `qfmap X f r` is `r` mutated by `f` at `X`; thus also for other keys `Y`, `Z`, .... 42 We might define some sugar for `qfmap`. 43 44 We can define 45 {{{ 46 x = X; 47 y = Y; 48 z = Z; 49 }}} 50 to allow `r.x`, `r.y`, `r.z`, ....