Changes between Version 6 and Version 7 of Records/SyntaxDirectedNameResolution


Ignore:
Timestamp:
Feb 28, 2012 12:08:12 AM (4 years ago)
Author:
elaforge
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Records/SyntaxDirectedNameResolution

    v6 v7  
    77the argument type, and look for the symbol `a` in that module.  The module
    88must be imported qualified for the resolution to happen, so compiling a
    9 certain module only needs to look at its direct dependents.
     9certain module only needs to look at its direct dependents.  As a degenerate case,
     10if the argument type is defined in the current module then typing `#a` will resolve to just
     11`a`.  This is nice because if you define a bunch of code in the same module as
     12the record you can then copy-paste it into a new module without having to update
     13every single reference, as long as you used `#` consistently.
    1014
    1115Everything else remains the same.  Records wishing the same name must live in
     
    8690{{{
    8791get :: Lens record field -> record -> field
    88 val = get #a record
     92val = get #a (M.Record 42)
    8993-- Due to type of 'get' and known type of 'record':
    9094#a :: Lens M.Record field
     
    114118
    115119get :: Lens record field -> record -> field
    116 val = get #a record
     120val = get #a (M.Record 42)
    117121
    118122-- Due to type of 'get' and known type of 'record':
     
    149153set :: Lens record field -> field -> record -> record
    150154
    151 record :: Outer.Outer
    152 record = Outer.Outer (Inner.Inner 42)
    153 
    154 val :: Outer.Outer -> Outer.Outer
    155 val = set (#b!#a) 42
    156 
    157 -- Due to the type of 'set' and the type of 'record' already being known:
     155setB :: Outer.Outer -> Outer.Outer
     156setB = set (#b!#a) 42
     157
     158-- Due to the type of 'set' and the type 'Outer.Outer' being declared in 'setB':
    158159(#b!#a) :: Lens Outer.Outer field
    159160-- Due to the definition of (!) and its return type being known:
     
    166167Inner.b :: Lens Inner.Inner Int
    167168-- result is
    168 val = set (Inner.b ! Outer.a) 42 record
     169setB = set (Inner.b ! Outer.a) 42
    169170}}}
    170171
     
    179180}}}
    180181
    181 This is the same as TH macros for existing lens libraries.
     182This is the same as TH macros for existing lens libraries.  And, of course, the old record update syntax is still down there, since the lens is built on top of it.  We can just stop using it so much.  Since it's backward compatible, we can gradually convert existing programs, there is no need for a giant patch of doom that has to simultaneously update an important record to the new records and to update all its call sites.
    182183
    183184Note that there must be a known monomorphic type for the #a so this may require