Changes between Version 5 and Version 6 of TemplateHaskell/Typed


Ignore:
Timestamp:
May 30, 2013 1:09:31 PM (21 months ago)
Author:
gmainland
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • TemplateHaskell/Typed

    v5 v6  
     1[[PageOutline]] 
     2 
     3== Implementation Plan == 
     4 
    15=== Add MetaML-style quotes === 
    26 
     
    4549 
    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. 
     51 
     52== Implementation Status == 
     53 
     54Implementation work on Typed Template Haskell is being done on the `th-new` branch. 
     55 
     56=== Compiling the `th-new` branch === 
     57 
     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 http://darcs.haskell.org/ghc.git/}}} 
     60 
     61 2. Check out the `th-new` branch in `libraries/template-haskell`. 
     62 
     63 3. Check out the `th-new` branch in `testsuite`. 
     64 
     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 
     66 
     67{{{ 
     68DYNAMIC_BY_DEFAULT = NO 
     69}}} 
     70 
     71 to your `mk/build.mk` file so that GHC is built statically. See #7774. 
     72 
     73=== Features === 
     74 
     75 1. '''A new abstract type of typed expressions''' `TExp a`.  Internally, this is just a Template Haskell `Exp` with a phantom type. 
     76 
     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`. 
     78 
     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}}}. 
     80 
     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}}}. 
     82 
     83 5. '''Typed splices are run in the typechecker.''' 
     84 
     85 6. '''Un-typed splices are run in the renamer.''' 
     86 
     87 7. '''Cross-stage persistence is remain unchanged.''' 
     88 
     89 8. '''(Un-typed) pattern and local declaration splices are supported.''' 
     90 
     91=== Remaining Issues/Questions === 
     92 
     93'''Pattern Splices and Bindings''' 
     94 
     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. 
     96 
     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! 
     98 
     99'''Name Splices''' 
     100 
     101It would be nice to be able to write code like this: 
     102 
     103{{{ 
     104foo = [d|data `T = ...|] 
     105}}} 
     106 
     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. 
     108 
     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}}}. 
     110 
     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?