[Haskell-cafe] MonadRandom and traversing infinite streams
Petr Pudlák
petr.mvd at gmail.com
Sat May 31 18:58:40 UTC 2014
Hi Brent and Wouter,
looking at SO questions
http://stackoverflow.com/q/14494648/1333025
http://codereview.stackexchange.com/q/52149/15600
threre are monads and applicative functors that support
```
sequenceInf :: S.Stream (f a) -> f (S.Stream a)
```
that is, allow lazy traversals of streams (infinite lists). Namely those
that don't produce any additional output.
And instances of MonadRandom seem to have valid implementations of
`sequenceInf`, which would allow to produce lazy infinite randomized lists
(basically a generalization of `getRandoms`).
My proposal is to add
```
class Applicative f => LazyApplicative f where
sequenceInf :: S.Stream (f a) -> f (S.Stream a)
sequenceInf = traverseInf id
traverseInf :: (a -> f b) -> S.Stream a -> f (S.Stream b)
traverseInf f = sequenceInf . S.map f
```
to a module in Stream package (for example `Control.Applicative.Lazy`), and
add its instances into `MonadRandom`.
What do you think? I'd be willing to send patches.
Best regards,
Petr
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140531/fabd78e9/attachment.html>
More information about the Haskell-Cafe
mailing list