data Renderer = Renderer {destroy :: IO (); render :: SystemOutput -> IO ()} newtype Initializer = Initializer {initialize :: IO Renderer}
Отправлено с iPad 03.09.2011, в 14:15, "M. George Hansen" <technopolit...@gmail.com> написал(а): > Greetings, > > I'm a Python programmer who is relatively new to Haskell, so go easy on me :) > > I have a program that uses (or will use) plugins to render output to > the user in a generic way. I'm basing the design of the plugin > infrastructure on the Plugins library, and have the following > interface: > > data Renderer = Renderer { > initialize :: IO (), > destroy :: IO (), > render :: SystemOutput -> IO () > } > > The program loads plugins at the start and runs the initialize > function, and then enters the main loop where it repeatedly calls the > render function with output to display. When the program exits the > main loop, it calls the destroy function to clean up any resources > used by the plugin. You can probably already see my problem: how do I > pass initialization information created in the initialize function to > the render function? > > I'm vaguely aware of some solutions to the typical "configuration > problem", such as implicit arguments or explicitly passing the > configuration data through the function call hierarchy. As far as I > can tell, neither of these approaches would work because the program > can't know at compile time what, if any, configuration data is used by > the plugin. > > I suppose I could pass a Dynamic up the call chain and let the plugin > decode it in the render function, but that seems a little kludgy to > me. > > Any thoughts would be greatly appreciated. > > -- > M. George Hansen > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe