Skip to content

Instantly share code, notes, and snippets.

@mpickering
Created June 4, 2021 11:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mpickering/18b70c9779f6988b74f1311001b17622 to your computer and use it in GitHub Desktop.
Save mpickering/18b70c9779f6988b74f1311001b17622 to your computer and use it in GitHub Desktop.
{-# OPTIONS_GHC -fplugin=MyPlugin #-}
module Main where
{-# LANGUAGE TypeFamilies #-}
module MyModule where
type family MyFam a b where
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