1

I'm neck deep in some complex TemplateHaskell and am desperately looking for a function with the following type signature:

Language.Haskell.TH.Type -> Data.Proxy.Proxy a

Does something like this exist? I can appreciate that it would be hard to determine the type a in the type-sig given above, but is there no way that that the compiler can look at what is inside Type and figure out what a should be?

Here's more context of the overall problem I'm trying to solve: I've "de-structured" a record-type via TH and have a value of [Type], where each element in the list corresponds to a field in the record. I need to pass each of these types to an existing function that takes only a Proxy a. If it makes things easier, the original record already has an instance of Generic

Saurabh Nanda
  • 6,373
  • 5
  • 31
  • 60
  • 1
    There is no way to write this function. Haskell does not support dependant types. – AJF Oct 24 '18 at 06:51

1 Answers1

1

You want a function that, given a type, produces an expression for a Proxy for that type.

proxyFor :: Type -> Exp
proxyFor = SigE (ConE 'Proxy) . AppT (ConT ''Proxy)

e.g.

ghci> let x = $(return $ proxyFor (ConT ''Int)) in x
Proxy

You can map proxyFor over your [Type], get a [Exp], and apply them to your function.

HTNW
  • 27,182
  • 1
  • 32
  • 60