[Template-haskell] Using a Typ as a Type

Alastair Reid alastair@reid-consulting-uk.ltd.uk
Thu, 7 Aug 2003 20:09:28 +0100


Is there any way that I can use a Typ (i.e., a reified Type) as a Type inside 
a template so that I can use the Typ to select an instance of a type class.

For example, I'd like to be able to write (this doesn't parse):

  $(test [t[ Float ]] "1.0")

  test :: Q Typ -> String -> Q [Dec]
  test qty x = do
    ty <- qty
    print (read x :: $ty)    -- The ':: $ty' part is the important bit
    return []

I've been going back and forth on whether or not this fits the existing TH 
framework or represents a major excursion into multi-stage templates.

I'd be willing to implement this feature if it fits the existing TH framework 
(i.e., it doesn't require a complete reimplementation of TH).

--
Alastair Reid