Point-free do block gives missing instance error
https://www.haskell.org/ghc/docs/latest/html/users_guide/compiler-plugins.html#manipulating-bindings
This API example won't compile for me.
module SayNames.Plugin (plugin) where
import GhcPlugins
plugin :: Plugin
plugin = defaultPlugin {
installCoreToDos = install
}
install :: [CommandLineOption] -> [CoreToDo] -> CoreM [CoreToDo]
install _ todo = do
reinitializeGlobals
return (CoreDoPluginPass "Say name" pass : todo)
pass :: ModGuts -> CoreM ModGuts
pass = do dflags <- getDynFlags
bindsOnlyPass (mapM (printBind dflags))
where printBind :: DynFlags -> CoreBind -> CoreM CoreBind
printBind dflags bndr@(NonRec b _) = do
putMsgS $ "Non-recursive binding named " ++ showSDoc dflags (ppr b)
return bndr
printBind _ bndr = return bndr
Compiling (GHC 7.8.1, or 7.6.3). I get:
SayNames/Plugin.hs:25:21:
No instance for (HasDynFlags ((->) ModGuts))
arising from a use of ‘getDynFlags’
In a stmt of a 'do' block: dflags <- getDynFlags
In the expression:
do { dflags <- getDynFlags;
bindsOnlyPass (mapM (printBind dflags)) }
In an equation for ‘pass’:
pass
= do { dflags <- getDynFlags;
bindsOnlyPass (mapM (printBind dflags)) }
where
printBind :: DynFlags -> CoreBind -> CoreM CoreBind
printBind dflags bndr@(NonRec b _)
= do { putMsgS
$ "Non-recursive binding named " ++ showSDoc dflags (ppr b);
.... }
printBind _ bndr = return bndr
Changing to pointful style it compiles and works:
pass modguts = do dflags <- getDynFlags
bindsOnlyPass (mapM (printBind dflags)) modguts
Maybe this is a compiler bug, actually? Dunno, I never use point-free style with monadic functions.
Trac metadata
Trac field | Value |
---|---|
Version | 7.8.1 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Documentation |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |