Changes between Version 5 and Version 6 of TemplateHaskell/Typed

May 30, 2013 1:09:31 PM (4 years ago)



  • TemplateHaskell/Typed

    v5 v6  
     3== Implementation Plan ==
    15=== Add MetaML-style quotes ===
    4650It is implicit in the above, but should be made explicit: untyped quotes/splices/quasiquotes should continue to work as they are -- which in detail means that they should be run in the renamer.  Typed quotes/splices/quasiquotes, should be run by the typechecker.
     52== Implementation Status ==
     54Implementation work on Typed Template Haskell is being done on the `th-new` branch.
     56=== Compiling the `th-new` branch ===
     58 1. Set up a ghc tree as you normally would. See [wiki:Building/GettingTheSources]. Check out out the `th-new` branch, e.g.,
     59    {{{$ git clone -b th-new}}}
     61 2. Check out the `th-new` branch in `libraries/template-haskell`.
     63 3. Check out the `th-new` branch in `testsuite`.
     65 4. Configure and build as you would normally (see Building). Note that if you want to use the GHC API to perform run time compilation, you will have to add
     71 to your `mk/` file so that GHC is built statically. See #7774.
     73=== Features ===
     75 1. '''A new abstract type of typed expressions''' `TExp a`.  Internally, this is just a Template Haskell `Exp` with a phantom type.
     77 2. '''A new term quotation form''' {{{[||e||]}}}, called a typed quote. The type of the quote is {{{Q (TExp tau)}}}, where {{{tau}}} is the type of {{{e}}}. In the type-system jargon, this is the "introduction form" for {{{TExp}}}. The ''value'' of this quote is an action in the {{{Q}}} monad that computes the (typed) AST for `e`.
     79 3. '''A new splice form''' {{{$$e}}}, called a typed splice. The term {{{e}}} must have type {{{Q (TExp tau)}}}, and the splice {{{$$e}}} then has type tau. This is the "elimination form" for {{{TExp}}}.
     81 4. '''A constant which takes a typed quote and returns an untyped one''': {{{unType :: TExp a -> Exp}}}. There is also a constant {{{unTypeQ :: Q (TExp a) -> Q Exp}}}.
     83 5. '''Typed splices are run in the typechecker.'''
     85 6. '''Un-typed splices are run in the renamer.'''
     87 7. '''Cross-stage persistence is remain unchanged.'''
     89 8. '''(Un-typed) pattern and local declaration splices are supported.'''
     91=== Remaining Issues/Questions ===
     93'''Pattern Splices and Bindings'''
     95Top-level pattern splices are run in the renamer, so they may ''introduce binders''. However, nested pattern splices, i.e., pattern splices that occur in a bracket, ''are not'' run in the renamer, so they ''may not introduce binders''. This is arguably inconsistent and undesirable, although top-level splices really are different beasts from nested splices.
     97This behavior is also inconsistent with quasiquoters. Because ''all'' quasiquoters are run in the renamer, they may introduce binders even when they are nested within brackets!
     99'''Name Splices'''
     101It would be nice to be able to write code like this:
     104foo = [d|data `T = ...|]
     107where {{{T}}} is of type {{{Name}}}. Right now, generating a data type declaration with a gensym'd name requires using the smart constructors provided by the Template Haskell library.
     109Our proposal is to introduce {{{`n}}} as syntax for a ''name splice''. In an expression context, {{{`n}}} would produce a variable expression for the variable with {{{Name}}} {{{n}}}; in a pattern context, it would bind the variable with {{{Name}}} {{{n}}}; in a type constructor context it would produce a declaration for the type constructor with {{{Name}}} {{{n}}}.
     111What about a type context? Should it produce a type variable? And in an expression context, how to we produce a data constructor by name?