
Victor Nazarov wrote:
data Behaviour a = forall b. BBind (Behaviour b) (b -> Behaviour a) | BIO (IO a) | forall obj. GObjectClass obj => BWaitEvent (Event obj) (Behaviour a)
instance Monad Behaviour where action >>= generator = BBind action generator return a = BIO (return a)
instance MonadIO Behaviour where liftIO action = BIO action
runBehaviour :: Behaviour a -> IO a runBehaviour (BBind (BWaitEvent event after) f) = runBehaviour (BWaitEvent event (after >>= f)) runBehaviour (BBind (BIO a) f) = a >>= \x -> runBehaviour (f x) runBehaviour (BBind (BBind a f) g) = runBehaviour (a >>= (\x -> f x >>= g))
Just a minor note: you can somewhat clean up your code by using a generic monad, as implemented in my cabal package operational http://hackage.haskell.org/package/operational and described in Heinrich Apfelmus. The Operational Monad Tutorial. In http://themonadreader.wordpress.com/2010/01/26/issue-15/ Regards, Heinrich Apfelmus -- http://apfelmus.nfshost.com