6

In the source for modify it is stated that the operation will be performed in place if it is safe to do so and will modify a copy of the vector otherwise.

But looking at the code for modify:

modify :: Vector v a => (forall s. Mutable v s a -> ST s ()) -> v a -> v a
modify p = new . New.modify p . clone

It looks to me that clone is always called (which makes sense to me, as I would think it would have to be for a destructive operation on an immutable vector).

Am I misunderstanding this? If not, what is an example of where clone is not called, and how does Data.Vector accomplish the bypass?

bbarker
  • 11,636
  • 9
  • 38
  • 62
  • Maybe the compiler can optimise this away? – AJF Jan 17 '19 at 16:53
  • Sorry, thought I had searched for this late the other night when I was wondering about it - but apparently didn't search well enough! This will take some time to digest but I'm confident it answers my question. If not, I'll ask a more specific question. – bbarker Jan 17 '19 at 18:25
  • 1
    no need to apologize, I only knew of the other question because I had answered. It's a great question. – Thomas M. DuBuisson Jan 17 '19 at 21:44

0 Answers0