[Haskell-cafe] runSubStateT

Paul Brauner polux2001 at gmail.com
Wed Jan 28 09:27:30 UTC 2015


Yes, I remember seeing a talk by Edward Kmett (at some Scala user group I
think) where he said lenses allowed you to focus on a substate in the state
monad.

Paul

On Tue Jan 27 2015 at 11:21:35 PM PkmX <pkmx.tw at gmail.com> wrote:

> Isn't this exactly what the `zoom` function does from `Control.Lens.Zoom`?
>
> > flip execState (1, 1) $ zoom _1 $ modify succ
> (2, 1)
>
> On Wed, Jan 28, 2015 at 6:14 AM, Christopher Done <chrisdone at gmail.com>
> wrote:
> > runSubStateT :: Monad m
> >              => (s -> s') -> (s' -> s) -> StateT s' m a -> StateT s m a
> > runSubStateT to from m =
> >   StateT (\s ->
> >             liftM (\(a,s') -> (a,from s'))
> >                   (runStateT m (to s)))
> >
> > Anyone ever needed something like this? Does it already exist in some
> > form in the standard libraries?
> >
> > Ciao
> > _______________________________________________
> > Haskell-Cafe mailing list
> > Haskell-Cafe at haskell.org
> > http://www.haskell.org/mailman/listinfo/haskell-cafe
>
> --
> Chih-Mao Chen (PkmX)
> System Software Laboratory
> Department of Computer Science
> National Chiao Tung University
> _______________________________________________
> 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/20150128/b283ce82/attachment.html>


More information about the Haskell-Cafe mailing list