[Haskell-cafe] Re: replicateM over vectors

Chad Scherrer chad.scherrer at gmail.com
Sat Apr 3 15:33:20 EDT 2010

Roman Leshchinskiy <rl <at> cse.unsw.edu.au> writes:

> Ah. I missed that. Then your best bet is probably
> replicate n action = munstream v $ Fusion.Stream.Monadic.generateM n (const
>                                  $ new n
> It's uglier that it should be but vector simply doesn't define the right
combinators for this at the moment.

I'm having trouble getting this to typecheck. I'll reread your "Recycle Your
Arrays" paper; maybe then it will make more sense.

> There are two things one would have to do. First, add a function to
Generic.New which initialises a New from a
> Monadic.Stream and fusion rules for it. That's easy. The hard part is to
generalise New to work with
> arbitrary monads: at the moment it is defined as:
> data New a = New (forall mv s. MVector mv a => ST s (mv s a))
> This is because its basic reason for existence is to be passed to Vector.new
which then does a runST to
> produce an immutable vector. It is perhaps possible to make New more general
but it's quite tricky. I'll
> think about it after the ICFP deadline 

But the "m" I'm interested in happens to be ST. Sounds like it's still easy in
principle, but not immediate. Is that right?


More information about the Haskell-Cafe mailing list