Skip to content

Instantly share code, notes, and snippets.

@danidiaz
Created August 10, 2023 13:31
Show Gist options
  • Save danidiaz/cc1c2d1d970e44499c4195e3d2556e39 to your computer and use it in GitHub Desktop.
Save danidiaz/cc1c2d1d970e44499c4195e3d2556e39 to your computer and use it in GitHub Desktop.
-- code by mniip
types :: [String]
types = $(
do
insts <- reifyInstances ''Exception [VarT (mkName "a")]
let
tyConOf (AppT ty _) = tyConOf ty
tyConOf (ConT con) = Just con
tyConOf _ = Nothing
tyCons <- for insts \case
InstanceD _ _ (AppT (ConT exc) ty) _
| exc == ''Exception
, Just tyCon <- tyConOf ty
-> pure tyCon
Language.Haskell.TH.Syntax.lift $ show <$> filter ((Just "base" ==) . namePackage) tyCons
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment