[Haskell-cafe] Re: State & nested structures

steffen steffen.siering at googlemail.com
Fri Oct 29 17:56:14 EDT 2010


you can find a nice introduction on using monad transformers by
developing an interpreter at [1] and a little more detailed one at [2]

[1]http://www.grabmueller.de/martin/www/pub/Transformers.pdf
[2]http://www.haskell.org/all_about_monads/html/

On 29 Okt., 18:46, Dupont Corentin <corentin.dup... at gmail.com> wrote:
> Thank you for your responses. I will look at monad transformers.
> I already use them I think because actually I use something like StateT Game
> IO a.
> You mean I have to implement my own instance?
>
> Oh, can you call me Corentin? This is my name ;)
>
> Cheers,
> Corentin
>
> On Fri, Oct 29, 2010 at 6:19 PM, steffen <steffen.sier... at googlemail.com>wrote:
>
>
>
>
>
>
>
>
>
> > > Horribly enough this one seems to work...
>
> > > mapOnBofA :: SB a -> SA a
> > > mapOnBofA mf = get >>= \st@(A {b=temp}) ->
> > >                let (ans,temp2) = runState mf temp
> > >                in put (st { b=temp2}) >> return ans
>
> > There is nothing horrible about that. You just run a new isolated
> > computation in the State Monad for B and use its results. More or less
> > see same solution as Dupont's.
>
> > @Dupont:
> > telling from your possible use case and your last post with your "MAP"-
> > Problem, these two are very similar. You have a monad and inside your
> > monad you temporarily want to run some computation in another Monad. I
> > think Monad-Transformers are maybe the better option for you
> > (especially your interpreter-Problem was a good use case for StateT/
> > ErrorT instead of State and some Either inside it...).
>
> > On 29 Okt., 17:35, Stephen Tetley <stephen.tet... at gmail.com> wrote:
> > > 2010/10/29 Dupont Corentin <corentin.dup... at gmail.com>:
>
> > > > Also, I can't manage to write the more generic function SB x ->  SA x.
>
> > > However, I'd have to question why you want both SA and SB as state
> > > functional types. Having inner runState's is sometimes good practice
> > > (its an instance of the Local Effect pattern identified by Ralf
> > > Laemmel and Joost Visser), but if you have it "commonly" I'd suspect
> > > you design is somehow contrived and could be simplified.
> > > _______________________________________________
> > > Haskell-Cafe mailing list
> > > Haskell-C... at haskell.orghttp://
> >www.haskell.org/mailman/listinfo/haskell-cafe
> >  _______________________________________________
> > Haskell-Cafe mailing list
> > Haskell-C... at haskell.org
> >http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-C... at haskell.orghttp://www.haskell.org/mailman/listinfo/haskell-cafe


More information about the Haskell-Cafe mailing list