[Haskell-cafe] Re: Monad.Reader with updates
Mauricio
briqueabraque at yahoo.com
Fri Nov 7 11:16:39 EST 2008
> Hi Mauricio. What you want actually already exists in QuickCheck as
> the "Gen" monad.
>
> newtype Gen a
> = Gen (Int -> StdGen -> a)
>
> instance Monad Gen where
> return a = Gen (\n r -> a)
> Gen m >>= k =
> Gen (\n r0 -> let (r1,r2) = split r0
> Gen m' = k (m n r1)
> in m' n r2)
>
> (...)
Nice. I think that's exactly what I was trying to do.
> You could also implement this as a variation on the State monad if you
> wanted to avoid using split: (...)
Yes. After Brent's explanation I finally realized State was the perfect
option. Maybe it should also be better for QuickCheck. I just didn't
know it… There are many things in the standard library that do nice
things, but I don't understand them until I write a few hundred lines
trying to do what they do :)
Thanks for your support and patience,
Maurício
More information about the Haskell-Cafe
mailing list