[Haskell-cafe] need help with monad transformers

Dmitry Olshansky olshanskydr at gmail.com
Thu Mar 1 11:19:29 CET 2012


>> If I'm running register outside runWriterT everything will work.

Maybe just

> lift $ register $ print "freed2"

or I didn't catch something?



2012/3/1 Alexander V Vershilov <alexander.vershilov at gmail.com>

> Hello.
>
> I'm trying to add monad stack into network-conduit, and everything
> works except some details [1].
>
> I've run runReaderT $ runTCPServer (wrapper around runResourceT) and
> inside conduit I want to run writer to gather results of inner computation.
> In inner computation I want to use IO, data from outter stack (ReaderT)
> so I'm running {-1-}:
>
>  (k,t) <- lift $ runWriterT $ ask >>= \x -> tell [x]     {- 1 -}
>
> and {-2-}
>
>  (k,t) <- lift $ runWriterT $ do {- 2 -}
>                    x <- ask
>                    liftIO $ print $x+1
>                    tell [x]
>
> and that will work (except I've thought I should not lift runWriterT, but
> calling functions inside.
>
> And finally in computation that will run once I want to register cleaning
> function (for example register $ putStrLn "cleaned") ({-3-})
>
>  (k,t) <- lift $ runWriterT $ do {- 3 -}
>                    x <- ask
>                    liftIO $ print $x+1
>                    register $ print "freed2"
>                    tell [x]
>
> but I've got type error. If I'm running register outside runWriterT
> everything
> will work.
>
> I would apperated if there will be any suggestions how to make this code
> better or use register in internal computation (runWriterT)
>
> [1] https://gist.github.com/1941151
> --
> Best regards,
>  Alexander V Vershilov
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120301/86961523/attachment.htm>


More information about the Haskell-Cafe mailing list