PUBLIC
Hi,
I am trying to typecheck & load three modules using the GHC API. The first one defines a class, the second one defines an instance of said class, and the third one uses the instance
(attached as Class.src, Instance.src and Use.src, respectively). The problem is that when I typecheck Use.src, it complains about the missing instance. It should be noted that the class is found, only the instance isn’t.
My code is bypassing the normal GHC driver to feed it modules instead of letting GHC itself come up with dependencies and then loading them from disk; that is because in my real
use case, some dependencies will have interfaces generated on the fly (there is no underlying Haskell source code), or loaded over HTTP, etc. So I am using parseModule and typeCheckModule on each module, make a ModIface from each, and then I try to register
them with GHC, by extending the HPT, the moduleNameProvidersMap, and the EPS. Evidently, this is not enough, and the instances should be registered somewhere else as well – where is that place?
I have attached a simplified version of my code as Main.hs; it is targeting the GHC 9.0 API. It hardcodes the GHC 9.0 package.conf.d due to laziness on my part; please change
line 96 to your environment before running it. As written, it fails when typechecing Use.src with:
input/Use.src:7:7: error:
• No instance for (C X) arising from a use of ‘method’
• In the expression: method
In an equation for ‘foo’: foo = method
|
7 | foo = method
| ^^^^^^
Thanks,
Gergo