[Haskell-cafe] Re: State & nested structures

Dupont Corentin corentin.dupont at gmail.com
Fri Oct 29 12:46:51 EDT 2010


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.siering 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-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/20101029/aaa3db41/attachment.html


More information about the Haskell-Cafe mailing list