
Hmm. One route would be to build a HsExpr (rather than a CoreExpr) for the reification of your CoreExpr, and stick that into the maw of the type checker. That would hand off all this dictionary construction to the type checker, which is designed for the purpose. Simon From: conal.elliott@gmail.com [mailto:conal.elliott@gmail.com] On Behalf Of Conal Elliott Sent: 05 November 2013 23:41 To: Simon Peyton-Jones Cc: Nicolas Frisby; ghc-devs@haskell.org Subject: Re: Finding & assembling class dictionaries from GHC plugins? Hi Simon, Here's some context on what I'm after. I'll try to include enough to clarify what I'm after, without dragging you into unnecessary detail. I have a Core expression, which I'm systematically translating to a related Core expression. The second one reifies the first one, so that the generated code *evaluates* to a run-time (not compile/Core-time) representation akin to the original Core expression. In this second (reified) representation, I need some run-time representation of types. I use Typeable constraints in my representation, and these constraints don't appear in the original Core representation. For instance, I have the following constructor for function application in a GADT of lambda expressions:
(:^) :: (Typeable a, Typeable b) => E (a -> b) -> E a -> E b
My reification plugin takes a Core application expression, recursively reifies the function and argument expressions, and makes an expression that applies (:^) to the two recursive results. However--and the point of this thread--I also need to come up with Core expressions for the two Typeable dictionaries.
So, to clarify my request, given a Core type representation t, I want to construct a Core expression that evaluates to the dictionary for Typeable t if one exists, or fail if there isn't one. Note that t is not necessarily an atomic type; it could instead be something like [(Bool,Int -> String)].
I'm happy to Skype-chat if it'd help.
Thanks, - Conal
On Tue, Nov 5, 2013 at 2:37 PM, Simon Peyton-Jones
A core-level plug-in can't generate fresh instances. There are some new plug-in hooks that fit earlier in the pipeline, which can. Maybe you can use that, and generate a data type decl with "deriving Typeable"?
We're willing to do some awkward shoehorning in HERMIT to make this work in limited circumstances. (Hopefully including Conal's.) We just don't know how to start - ie how call the right functions from the type checker. Are there any resources explaining the relevant subset of the TcRnIf API? Thanks.
From: ghc-devs [mailto:ghc-devs-bounces@haskell.orgmailto:ghc-devs-bounces@haskell.org] On Behalf Of Conal Elliott Sent: 04 November 2013 20:08 To: ghc-devs@haskell.orgmailto:ghc-devs@haskell.org Subject: Finding & assembling class dictionaries from GHC plugins?
I'm working on a GHC plugin (for compiling Haskell to hardware), and I need to synthesize Typeable (and maybe other) class dictionaries for a wide range of types, including composite types (functions, pairs, lists, etc). Can it be done, and how? I think I'm mainly looking for mechanics of finding existing class instances (however they're defined) and assembling them (for parametrized/composite dictionaries), rather than mechanisms specific to Typeable.
Thanks, -- Conal
_______________________________________________ ghc-devs mailing list ghc-devs@haskell.orgmailto:ghc-devs@haskell.org http://www.haskell.org/mailman/listinfo/ghc-devs