Constructing TH types

Nicolas Frisby nicolas.frisby at gmail.com
Sun Oct 7 18:24:11 CEST 2012


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 gmail.com> 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