>>>> Is there  some abstraction in  current ghc library  that implements
>>>> something like  Reader, but where  the value of the  environment is
>>>> updated at every "step"?
>>>
> It doesn't  quite make sense,  because one "step" isn't  well defined.
> How many  "steps" is "return (f  x)" ? how  about "return x >>=  \y ->
> return (f y)" ? (...)
>

I  understand.  But  do  you  think something  like  the (obviously  not
working)  code below  could  respect  monad laws,  if  I could  consider
(environment->a) a monad over a?

 update = snd . next ; -- this updates a random number generator

 instance RandomGen environment => Monad ( environment -> a ) where {

   -- below, f :: g1 -> ( environment -> g2 )
   p >>= f = p2 where { p2 e = ( f . p $ e ) . update } ;

   return = const ;

 }

Then I would do something like:

 getStdGen >>= ( return . do { a >>= b >>= c } )

>
> So I think you'd have to make the steps explicit. (...)
>
> advance :: m () -- your primitive which changes the environment
>
> a >>* b = a >> advance >> b
> a >>*= f = do { r <- a; advance; f r }
>

The problem is that I need 'a' or 'b' above to sometimes also change the
environment. I think with this method I could not get that.

Thanks,
Maurício

_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to