Changes between Version 1 and Version 2 of Records/TypeIndexedRecords


Ignore:
Timestamp:
Mar 3, 2012 4:30:20 PM (2 years ago)
Author:
strake888
Comment:

--

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