[Haskell-cafe] Re: State nested structures

2010-10-29 Thread steffen

 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...@gmail.com wrote:
 2010/10/29 Dupont Corentin corentin.dup...@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...@haskell.orghttp://www.haskell.org/mailman/listinfo/haskell-cafe
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: State nested structures

2010-10-29 Thread Dupont Corentin
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...@googlemail.comwrote:


  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...@gmail.com wrote:
  2010/10/29 Dupont Corentin corentin.dup...@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...@haskell.orghttp://
 www.haskell.org/mailman/listinfo/haskell-cafe
  ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: State nested structures

2010-10-29 Thread steffen
Nothing hinders you writing:

StateT Game (StateT A IO)

or

GameT mt = ErrorT Err (StateT Game (mt IO))
with mt being another Monad-Transformer

Monad-Transformers can be quite tricky. The point is you don't have to
create new Monad instances.

On 29 Okt., 18:46, Dupont Corentin corentin.dup...@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...@googlemail.comwrote:









   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...@gmail.com wrote:
   2010/10/29 Dupont Corentin corentin.dup...@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...@haskell.orghttp://
 www.haskell.org/mailman/listinfo/haskell-cafe
   ___
  Haskell-Cafe mailing list
  haskell-c...@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe



 ___
 Haskell-Cafe mailing list
 haskell-c...@haskell.orghttp://www.haskell.org/mailman/listinfo/haskell-cafe
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: State nested structures

2010-10-29 Thread steffen
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...@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...@googlemail.comwrote:









   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...@gmail.com wrote:
   2010/10/29 Dupont Corentin corentin.dup...@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...@haskell.orghttp://
 www.haskell.org/mailman/listinfo/haskell-cafe
   ___
  Haskell-Cafe mailing list
  haskell-c...@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe



 ___
 Haskell-Cafe mailing list
 haskell-c...@haskell.orghttp://www.haskell.org/mailman/listinfo/haskell-cafe
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe