
Hello! Suppose we have functions f :: ReaderT env monad1 rtype g :: Reader env rtype and we need to call g from f. Currently I write something like f = do env <- ask let r = runReader g env doSmth r I don't like doing it this way (I need to get environment and explicitly pass it). Is there another way to get things done? -- WBR, Max Vasin.

On Sun, May 08, 2005 at 07:54:43PM +0400, Max Vasin wrote:
Hello!
Suppose we have functions
f :: ReaderT env monad1 rtype g :: Reader env rtype
and we need to call g from f.
Currently I write something like
f = do env <- ask let r = runReader g env doSmth r
I don't like doing it this way (I need to get environment and explicitly pass it). Is there another way to get things done?
How about: toReaderT :: (Monad m) => Reader r a -> ReaderT r m a toReaderT (Reader f) = ReaderT (return . f) Best regards Tomasz

On Sun, 8 May 2005 18:34:37 +0200, Tomasz Zielonka
On Sun, May 08, 2005 at 07:54:43PM +0400, Max Vasin wrote:
Hello!
Suppose we have functions
f :: ReaderT env monad1 rtype g :: Reader env rtype
and we need to call g from f.
Currently I write something like
f = do env <- ask let r = runReader g env doSmth r
I don't like doing it this way (I need to get environment and explicitly pass it). Is there another way to get things done?
How about:
toReaderT :: (Monad m) => Reader r a -> ReaderT r m a toReaderT (Reader f) = ReaderT (return . f)
Thanks. -- WBR, Max Vasin.

On Sun, May 08, 2005 at 10:19:28PM +0400, Max Vasin wrote:
On Sun, 8 May 2005 18:34:37 +0200, Tomasz Zielonka
said: On Sun, May 08, 2005 at 07:54:43PM +0400, Max Vasin wrote:
f :: ReaderT env monad1 rtype g :: Reader env rtype
How about: toReaderT :: (Monad m) => Reader r a -> ReaderT r m a toReaderT (Reader f) = ReaderT (return . f)
Thanks.
You can also make 'g' more generic, using the MonadReader type-class. Best regards Tomasz

On Sun, 8 May 2005 20:29:31 +0200, Tomasz Zielonka
On Sun, May 08, 2005 at 10:19:28PM +0400, Max Vasin wrote:
On Sun, 8 May 2005 18:34:37 +0200, Tomasz Zielonka
said: On Sun, May 08, 2005 at 07:54:43PM +0400, Max Vasin wrote:
f :: ReaderT env monad1 rtype g :: Reader env rtype
How about: > toReaderT :: (Monad m) => Reader r a -> ReaderT r m a > toReaderT (Reader f) = ReaderT (return . f)
Thanks. toReaderT should be
toReaderT (Reader f) = ReaderT (return . (runReader f))
You can also make 'g' more generic, using the MonadReader type-class. So I should its type should be
g :: (MonadReader m) => m env rtype and than f = let r = g ? -- WBR, Max Vasin.
participants (2)
-
Max Vasin
-
Tomasz Zielonka