
#9641: Point-free do block gives missing instance error -------------------------------------+------------------------------------- Reporter: rasfar | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Documentation | Version: 7.8.1 Keywords: plugins | Operating System: Linux HasDynFlags | Type of failure: Architecture: x86 | Documentation bug Difficulty: Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- https://www.haskell.org/ghc/docs/latest/html/users_guide/compiler- plugins.html#manipulating-bindings This API example won't compile for me. {{{#!hs 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: {{{#!hs 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. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9641 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler