haskell / haskell/vector

Using mutable and immutable vectors together is painful

Open
#159 6 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haskell
Stars
400
Forks
145
PR merge metrics
No merged PRs in 30d

Description

This is actually 2 closely-related issues:
* Importing both `Data.Vector.Generic` and `Data.Vector.Generic.Mutable` in the same module means one must qualify all the slice and length ops, for example `take` and `drop`, tho these are effectively the same operations on mutable and immutable vectors.
* It is effectively impossible to write one term which works with both mutable and immutable vectors, for examples, all which i needed lately:
* `tails :: Vector v a => v a -> [v a]`
* `tailMay :: Vector v a => v a -> Maybe (v a)`
* `wrapSlice :: Vector v a => Int -> Int -> v a -> v a -- slice wrapping back to start if it goes too far`
* `windows :: Vector v a => Int -> v a -> [v a] -- list of all subvectors of given length`

It should be possible to use the same function to slice both mutable and immutable vectors. I propose this:
```
class Slice v where
length :: v a -> Int
unsafeSlice :: Int -> Int -> v a -> v a
```
and instances for all `Vector` and `MVector` types; i believe the other slicing functions can be defined in terms of these.

I can implement this, so let me know whether you approve.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.