Where (else) do I need to register instances from loaded modules?

Erdi, Gergo Gergo.Erdi at sc.com
Tue Aug 24 02:17:46 UTC 2021


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

This email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please delete all copies and notify the sender immediately. You may wish to refer to the incorporation details of Standard Chartered PLC, Standard Chartered Bank and their subsidiaries at https: //www.sc.com/en/our-locations

Where you have a Financial Markets relationship with Standard Chartered PLC, Standard Chartered Bank and their subsidiaries (the "Group"), information on the regulatory standards we adhere to and how it may affect you can be found in our Regulatory Compliance Statement at https: //www.sc.com/rcs/ and Regulatory Compliance Disclosures at http: //www.sc.com/rcs/fm

Insofar as this communication is not sent by the Global Research team and contains any market commentary, the market commentary has been prepared by the sales and/or trading desk of Standard Chartered Bank or its affiliate. It is not and does not constitute research material, independent research, recommendation or financial advice. Any market commentary is for information purpose only and shall not be relied on for any other purpose and is subject to the relevant disclaimers available at https: //www.sc.com/en/regulatory-disclosures/#market-disclaimer.

Insofar as this communication is sent by the Global Research team and contains any research materials prepared by members of the team, the research material is for information purpose only and shall not be relied on for any other purpose, and is subject to the relevant disclaimers available at https: //research.sc.com/research/api/application/static/terms-and-conditions. 

Insofar as this e-mail contains the term sheet for a proposed transaction, by responding affirmatively to this e-mail, you agree that you have understood the terms and conditions in the attached term sheet and evaluated the merits and risks of the transaction. We may at times also request you to sign the term sheet to acknowledge the same.

Please visit https: //www.sc.com/en/regulatory-disclosures/dodd-frank/ for important information with respect to derivative products.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-devs/attachments/20210824/1bb30519/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Class.src
Type: application/octet-stream
Size: 65 bytes
Desc: Class.src
URL: <http://mail.haskell.org/pipermail/ghc-devs/attachments/20210824/1bb30519/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Instance.src
Type: application/octet-stream
Size: 73 bytes
Desc: Instance.src
URL: <http://mail.haskell.org/pipermail/ghc-devs/attachments/20210824/1bb30519/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Use.src
Type: application/octet-stream
Size: 75 bytes
Desc: Use.src
URL: <http://mail.haskell.org/pipermail/ghc-devs/attachments/20210824/1bb30519/attachment-0002.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Main.hs
Type: application/octet-stream
Size: 10938 bytes
Desc: Main.hs
URL: <http://mail.haskell.org/pipermail/ghc-devs/attachments/20210824/1bb30519/attachment-0003.obj>


More information about the ghc-devs mailing list