David Fox | 31 Oct 17:17 2013

How do I lift Control.Monad.Reader.local?

I can write a stack push function in the reader monad like so:

    import Control.Monad.Reader

    push :: String -> Reader [String] a ->  Reader [String] a
    push s action = local (s :) action

How can I write a push that works inside a monad transformer?

    push' :: MonadTrans t => String -> t (Reader [String]) a ->  t (Reader [String]) a
    push' s action = ???

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Nickolay Kudasov | 31 Oct 19:59 2013
Picon

Re: How do I lift Control.Monad.Reader.local?

Hi David,

I believe the easiest way to do what you want is to use MonadReader class instead of explicit t (Reader [String] a):

push' :: MonadReader [String] m => String -> m a -> m a push' s = local (s:)

Best,
Nick



2013/10/31 David Fox <dsf <at> seereason.com>
I can write a stack push function in the reader monad like so:

    import Control.Monad.Reader

    push :: String -> Reader [String] a ->  Reader [String] a
    push s action = local (s :) action

How can I write a push that works inside a monad transformer?

    push' :: MonadTrans t => String -> t (Reader [String]) a ->  t (Reader [String]) a
    push' s action = ???


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
David Fox | 31 Oct 23:54 2013

Re: How do I lift Control.Monad.Reader.local?

Hmm, I'm still having trouble implementing local for the MonadReader instance of M.


On Thu, Oct 31, 2013 at 11:59 AM, Nickolay Kudasov <nickolay.kudasov <at> gmail.com> wrote:

Hi David,

I believe the easiest way to do what you want is to use MonadReader class instead of explicit t (Reader [String] a):

push' :: MonadReader [String] m => String -> m a -> m a push' s = local (s:)

Best,
Nick



2013/10/31 David Fox <dsf <at> seereason.com>
I can write a stack push function in the reader monad like so:

    import Control.Monad.Reader

    push :: String -> Reader [String] a ->  Reader [String] a
    push s action = local (s :) action

How can I write a push that works inside a monad transformer?

    push' :: MonadTrans t => String -> t (Reader [String]) a ->  t (Reader [String]) a
    push' s action = ???


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe



_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
David Fox | 31 Oct 23:54 2013

Re: How do I lift Control.Monad.Reader.local?

I mean m, not M.


On Thu, Oct 31, 2013 at 3:54 PM, David Fox <dsf <at> seereason.com> wrote:
Hmm, I'm still having trouble implementing local for the MonadReader instance of M.


On Thu, Oct 31, 2013 at 11:59 AM, Nickolay Kudasov <nickolay.kudasov <at> gmail.com> wrote:

Hi David,

I believe the easiest way to do what you want is to use MonadReader class instead of explicit t (Reader [String] a):

push' :: MonadReader [String] m => String -> m a -> m a push' s = local (s:)

Best,
Nick



2013/10/31 David Fox <dsf <at> seereason.com>
I can write a stack push function in the reader monad like so:

    import Control.Monad.Reader

    push :: String -> Reader [String] a ->  Reader [String] a
    push s action = local (s :) action

How can I write a push that works inside a monad transformer?

    push' :: MonadTrans t => String -> t (Reader [String]) a ->  t (Reader [String]) a
    push' s action = ???


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe




_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Nickolay Kudasov | 1 Nov 21:23 2013
Picon

Re: How do I lift Control.Monad.Reader.local?

So you have some particular ts for which you wish to provide a MonadReader instance?

In that case for each t which lacks MonadReader instance (look here for existing instances) you need to implement it:

instance MonadReader r m => MonadReader r (t m) where ask = lift ask local = ...

The way to implement local is individual for each t, so you might want to specify which transformers are you working with.

Nick



2013/11/1 David Fox <dsf <at> seereason.com>
I mean m, not M.


On Thu, Oct 31, 2013 at 3:54 PM, David Fox <dsf <at> seereason.com> wrote:
Hmm, I'm still having trouble implementing local for the MonadReader instance of M.


On Thu, Oct 31, 2013 at 11:59 AM, Nickolay Kudasov <nickolay.kudasov <at> gmail.com> wrote:

Hi David,

I believe the easiest way to do what you want is to use MonadReader class instead of explicit t (Reader [String] a):

push' :: MonadReader [String] m => String -> m a -> m a push' s = local (s:)

Best,
Nick



2013/10/31 David Fox <dsf <at> seereason.com>
I can write a stack push function in the reader monad like so:

    import Control.Monad.Reader

    push :: String -> Reader [String] a ->  Reader [String] a
    push s action = local (s :) action

How can I write a push that works inside a monad transformer?

    push' :: MonadTrans t => String -> t (Reader [String]) a ->  t (Reader [String]) a
    push' s action = ???


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe





_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Gmane