#5616: TH type quotes cannot contain free type variables -------------------------------+-------------------------------------------- Reporter: Lennart | Owner: Type: bug | Status: closed Priority: normal | Milestone: Component: Template Haskell | Version: 7.2.1 Resolution: invalid | Keywords: Testcase: | Blockedby: Difficulty: | Os: Unknown/Multiple Blocking: | Architecture: Unknown/Multiple Failure: None/Unknown | -------------------------------+--------------------------------------------
Comment(by simonpj): I asked in email: Can’t you pass the whole type? {{{ inst t = [d| instance $t |] }}} You replied. No, you can’t. Both of those give you the error Malformed instance header. Indeed! How could we possibly type check the declaration in {{{ inst t = [d| instance $t where op x = x+2 |] }}} All the usual stuff for type checking instance declarations assumes that we know the class, and indeed the instantiating types, of an instance declaration. Else how would we know whether ‘op` came from the right class, or `op x = x+2` has the right type. I think the real answer here is in my [http://hackage.haskell.org/trac/ghc/blog/Template%20Haskell%20Proposal blog post about Template Haskell]. We can’t reasonably typecheck such declarations, but it is very convenient to use the quotation syntax. So support the quotation syntax, but don’t typecheck it. Restrict typechecking of Template Haskell to ''expressions'', and do the Full Job a la !MetaMl. See my blog post. Here’s another example, even more extreme: {{{ foo :: Name -> Q [Dec] foo t = [d| $t = MkT Int |] }}} Here I want to splice in the ''name'' of the type to be declared. Reasonable enough, and you can do it if you use explicit constructors, but totally impossible using quotation syntax. Do you like the blog post ideas? How much does it matter to you? Simon -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/5616#comment:3> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler _______________________________________________ Glasgow-haskell-bugs mailing list Glasgow-haskell-bugs@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs