[Template-haskell] Re: Polymorphism + Quasiquoting + Untyped AST = problems

Alfonso Acosta alfonso.acosta at gmail.com
Wed Feb 20 03:41:16 EST 2008


On Wed, Feb 20, 2008 at 9:12 AM, Geoffrey Mainland
<mainland at eecs.harvard.edu> wrote:
> On Wed, Feb 20, 2008 at 08:22:18AM +0100, Alfonso Acosta wrote:
>  > Hi,
>  >
>  > Let me show you why I reached that conclusion through a simple example.
>
>  I can't help but feel I've missed some context :)

Well, I'm probably bad at providing simplified examples ;). The real
purpose of using quasiquoters is to help implementing fixed sized
vectors (numerically parameterized lists using type-level numerals).
See http://www.haskell.org/pipermail/haskell-cafe/2008-February/039801.html
for details.


>  > Using "vector" is simple:
>  >
>  > $(vector [1,2,3,4,5])
>
>  Well, not so simple actually, as you'll get an "ambiguous type variable"
>  error unless you add a type signature. For instance:
>
>  $(vector [1::Int,2,3,4,5])

True, I forgot to include the signature. However, even if a signature
is required, vector can still be used to build vectors of any type,
whereas that is not the case when using quasiquoters.

>  The real problem is that you can't splice in a polymorphic
>  variable. Witness:
>
>  v =  QuasiQuoter (fst . vExp) vPat
>
>  vExp :: Read a => String -> (Q Exp, a)
>  vExp str = do let xs = (parseLTGT str) :: [a]
>               sanityCheck xs
>               ([| MkVec xs |], undefined)
>

Yes, I know. I thought it would maybe be possible if TH had a typed AST.


More information about the template-haskell mailing list