Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is MVector not Foldable?

Tags:

haskell

May I understand why the MVector type(from vector package) doesn't instance the Foldable type class? I suppose people would often need to iterate over vectors. I can freeze it to Data.Vector and then iterate. But I hate transforming these things, as if we don't do it enough with String, Text, Bytestrings etc.

In my case I'd like to print each element.

like image 986
daydaynatation Avatar asked Oct 20 '25 14:10

daydaynatation


1 Answers

Reading from a mutable vector requires doing effects in the associated monad -- IO or ST s. But Foldable requires you to be able to produce a pure answer; if there were an instance, we would have to be able to at least implement

foldr :: (a -> b -> b) -> b -> MVector s a -> b

even when the caller chooses a b that doesn't mention IO or ST. Whoops!

like image 197
Daniel Wagner Avatar answered Oct 23 '25 09:10

Daniel Wagner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!