Changes between Version 16 and Version 17 of Records/SyntaxDirectedNameResolution

Mar 2, 2012 6:29:12 AM (4 years ago)



  • Records/SyntaxDirectedNameResolution

    v16 v17  
    33The idea is a # prefix for identifiers.  `#a` is a "type directed function".
    44It requires the type of its argument to be monomorphic.  An application
    5 `#a :: forall x. M.X -> x` is desugared to `M.a :: M.X -> Y` where `Y` depends
    6 on the concrete type of `M.a`.  All it does is strip the module part off off
    7 the argument type, and look for the symbol `a` in that module.  The module
    8 must be imported qualified for the resolution to happen, so compiling a
     5`#field :: f a b -> c` must have a known type for `a`, and is desugared to `M.field` where `M`
     6is the module that the type of `a` is defined in.  Note that (->) is a special
     7case of the binary type constructor `f`, so `#field :: M.Rec -> a` is desugared
     8to `M.field`.
     10The module must be imported qualified for the resolution to happen, so compiling a
    911certain module only needs to look at its direct dependents.  As a degenerate case,
    1012if the argument type is defined in the current module then typing `#a` will resolve to just
    1517Everything else remains the same.  Records wishing the same name must live in
    16 separate modules, but field access looks like: `(#b . #a) record`.  People
     18separate modules, but field access doesn't have to mention the module names: `(#b . #a) record`.  People
    1719who like unqualified imports can still use them, since `import A.B.C` will
    1820bring `A.B.C.a` into scope as well as `a`.  If there are two `a`s from
    2325imported `A.B.C` qualified.
    25 This is enough for field access, but to support convenient modification, some
    26 notion of lenses has to be built in and the rule has to be modified, from
    27 `#a :: forall x. M.X -> x` ==> `M.a :: M.X -> Y` to look at the first argument
    28 of a `Lens` class:
    29 `#a :: forall x. Lens M.X x` ==> `M.a :: Lens M.X Y`.  Effectively this is
    30 just substituting `Lens` for `(->)`.  Maybe it could be extended to look at
    31 the first argument of any type constructor `forall m x. m M.X x`, that way
    32 the syntax can be used to resolve not just record fields, but any function,
    33 or any member of Category, or whatever.
     27This is enough for field access, but to support convenient modification we
     28can use lenses.  If we substitute `Lens` for `f` instead of (->), then
     29we can write `#field :: Lens M.Rec a -> b` and still have it resolve to `M.field`.
    3531Here's an example using plain function "# resolution":