
#12778: Expose variables bound in quotations to reify -------------------------------------+------------------------------------- Reporter: | Owner: (none) facundo.dominguez | Type: bug | Status: patch Priority: normal | Milestone: Component: Template Haskell | Version: 8.0.1 Resolution: | Keywords: template- | haskell reify Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D3003 Wiki Page: | -------------------------------------+------------------------------------- Comment (by mboes): In the attached Diff, Simon PJ admits to, understandably, being very confused by the original use case. The description in this ticket doesn't expatiate that, so here's a quick summary. inline-java defines the `java` quasiquoter, which stands for a call to a *typed* static Java method (with the antiquotation variables being the arguments): {{{ jadd :: Int32 -> Int32 -> IO Int32 jadd x y = do [java| { return $x + $y } |] }}} At compile time, we need to add somewhere the definition of this static method. Something like: {{{ public static int wrapperFun(int x, int y) { return x + y; } }}} At runtime, we need to call this method. Note that the user doesn't need to specify the Java types of antiquotation variables, nor the Java return type. Those are inferred from the types in the Haskell context of quasiquote (`Int32` maps to Java's `int`, `Bool` maps to `boolean` etc). We use `addModFinalizer` to compute the signature of the Java method at the very end of type checking a module, at a time when the full types of all the local variables in all contexts are known. Getting the type of antiquotation variables this way works fine in 8.0.2. But getting the expected return type of a quasiquotation and inferring a Java return type is not currently possible. So e.g. above, we can know that `x` and `y` are `int`, because we know that Haskell side `x` and `y` have type `Int32`. But we can't know that the return type is also `int`, because even if the quasiquote expansion is something like {{{ let result = <java method call> in result }}} The type of `result` isn't available, even at the point where module finalizers are executed. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12778#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler