[Haskell-cafe] Looking-up a TyCon of a type exposed from public module but defined in hidden module
Richard Eisenberg
rae at richarde.dev
Sun Feb 2 21:41:47 UTC 2020
I don't know the "official" way to do this, but `Module` is a very simple type. You could always build it yourself, using the unit ID from another `singletons` module and just change the module name to suit your needs.
Richard
> On Feb 1, 2020, at 11:59 AM, 石井大海 <konn.jinro at gmail.com> wrote:
>
> Hi cafe,
>
> I'm currently writing GHC Type-Checker Plugin [ghc-typelits-presburger], which enhances type-inference involving type-level naturals using Presburger arithmetic.
>
> To process constraints properly, I need an access to TyCons of `TrueSym0`,
> `FalseSym0`, `GTSym0`, etc. from `singletons` package.
> These types are exposed by public modules, e.g. Data.Singletons.Prelude, but
> it seems that they are originally defined in private module `Data.Singletons.Prelude.Instances`.
>
> I first tried, to retrieve the `TyCon` for `TrueSym0`, the following:
>
> ```
> insts <- lookupModule (mkModuleName "Data.Singletons.Prelude.Instances") (fsLit "singletons")
> singTrueSym0 <- tcLookupTyCon =<< lookupOrig insts (mkTcOcc "TrueSym0")
> ```
>
> But this results in the following compile-time error:
>
> ```
> ghc: panic! (the 'impossible' happened)
> (GHC version 8.6.5 for x86_64-apple-darwin):
> Unable to resolve module looked up by plugin:
> Data.Singletons.Prelude.Instances
>
> Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug
> ```
>
> Then, I tried to lookup `TrueSym0` from exposed module, say Data.Singletons.Prelude:
>
> ```
> prel <- lookupModule (mkModuleName "Data.Singletons.Prelude") (fsLit "singletons")
> singTrueSym0 <- tcLookupTyCon =<< lookupOrig prel (mkTcOcc "TrueSym0")
> ```
>
> But this resulted in the following error:
>
> ```
> • Can't find interface-file declaration for type constructor or class singletons-2.5.1:Data.Singletons.Prelude.TrueSym0
> Probable cause: bug in .hi-boot file, or inconsistent .hi file
> Use -ddump-if-trace to get an idea of which file caused the error
> • In the type signature: ...
> ```
>
> Is there any way, in GHC API, to lookup symbols exported from public module but originally defined in hidden module?
>
> Thanks,
>
> [ghc-typelits-presburger]: https://github.com/konn/ghc-typelits-presburger
>
> -- Hiromi ISHII
> konn.jinro at gmail.com
>
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
More information about the Haskell-Cafe
mailing list