Constructing TH types

Eric M. Pashman eric.pashman at
Sun Oct 7 19:08:38 CEST 2012


Intended usage seems to be something like

AppT ListT $ ConT . mkName $ "Int"

That works. So it seems that there is indeed no way to construct the syntactically special list type from its (valid) name, but it can easily be done as above.

In my opinion, it should be possible to do what we've been trying -- ConT (mkName "[]") `AppT` ConT "Char" -- or whatever. The problem seems simply to be that

ConT . mkName $ "[]" \= ListT

I don't know the first thing about the GHC source, but I would imagine that's easily fixable if the behavior we both expected is more broadly desired.



On Oct 7, 2012, at 11:24 , Nicolas Frisby <nicolas.frisby at> wrote:

> The issue you had with applications of the [] type seems to be more
> insidious than my last email made it out to be. This expression
> (   $(return $ ConE (mkName "[]")) ::
>    $(return $ ConT (mkName "[]") `AppT` ConT ''Char)
> )
> fails with "[] is applied to too many arguments". I'm thinking that
> the "[]" in the type is being resolved somehow to the the [] data
> constructor, not the [] type constructor.
> This seems specific to []; the following works for tuples, even though
> the data and type constructor also share a string name.
> $(return $ ConE (mkName "(,)") `AppE` LitE (CharL 'c') `AppE` LitE
> (CharL 'a')) ::
> $(return $ ConT (mkName "(,)") `AppT` ConT ''Char      `AppT` ConT ''Char)
> I haven't yet narrowed down where the mkName'd string is
> (inappropriately?) resolved in the GHC source.
> Eric, special-casing for ArrowT probably avoids this problem for you.
> The only thing to glean from this email is that you ideally wouldn't
> need to worry about the special-casing for your current application —
> I think there's a TH bug at play, though I haven't found an open GHC
> ticket for it and it may very well still be a known issue.
> On Sun, Oct 7, 2012 at 10:15 AM, Eric M. Pashman <eric.pashman at> wrote:
>> Nicolas, thanks for the welcome, and thanks for pointing out the additional 'Type' constructors!
>> I'd looked over the available constructors, but apparently not very well. The 'ListT', 'TupleT', 'ArrowT', etc., constructors are precisely what I need to make this work in a straightforward fashion.
>> So I don't actually have a problem making the right 'Name' value, just a problem reading the TH source. Well, that's that. ...
>> Many thanks,
>> Eric
> My pleasure.
> However,

More information about the Glasgow-haskell-users mailing list