Created
June 4, 2021 11:22
-
-
Save mpickering/18b70c9779f6988b74f1311001b17622 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# OPTIONS_GHC -fplugin=MyPlugin #-} | |
module Main where | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE TypeFamilies #-} | |
module MyModule where | |
type family MyFam a b where |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module MyPlugin where | |
import GHC.Plugins hiding ((<>)) | |
import GHC.Tc.Types | |
import GHC.Unit.Finder.Types | |
import GHC.Tc.Plugin | |
import MyModule | |
plugin = defaultPlugin { tcPlugin = const (Just (TcPlugin tcPluginInitm undefined undefined)) } | |
myPackage = "this" | |
myModuleName = "MyModule" | |
tcPluginInitm :: TcPluginM () | |
tcPluginInitm = do | |
myModule <- findModule myPackage myModuleName | |
lookupResult <- tcLookupGlobal =<< lookupOrig myModule ( mkTcOcc "MyFam" ) | |
pprPanic "Result was:" ( ppr lookupResult ) | |
findModule :: String -> String -> TcPluginM Module | |
findModule pkg modName = do | |
findResult <- findImportedModule ( mkModuleName modName ) ( Just $ fsLit pkg ) | |
case findResult of | |
Found _ res -> pure res | |
FoundMultiple _ -> error $ "MyPlugin: found multiple modules named " <> modName <> "." | |
_ -> error $ "MyPlugin: could not find any module named " <> modName <> "." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment