[Haskell-cafe] Re: GUI programming
Victor Nazarov
asviraspossible at gmail.com
Wed Feb 3 08:51:55 EST 2010
On Wed, Feb 3, 2010 at 4:11 PM, Heinrich Apfelmus
<apfelmus at quantentunnel.de> wrote:
> 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/
>
>
Thank you.
It seems relevant. I'll have a look at it.
Speaking about packages. What is current community status of monad
transformers packages. I'm using MonadIO class and there are mtl,
monads-fd, monads-tf packages that provide it. I personally prefer
type families to functional dependencies. Should I use monads-tf, or
should I stick to mtl?
--
Victor Nazarov
More information about the Haskell-Cafe
mailing list