haskell / vector

An efficient implementation of Int-indexed arrays (both mutable and immutable), with a powerful loop optimisation framework .
Other
366 stars 139 forks source link

Add instances for Mutable t.f. for arrays from primitive #473

Closed Shimuuar closed 8 months ago

Shimuuar commented 1 year ago

While arrays from primitive could not have Vector/MVector instances, Mutable is well defined for them. It's useful on its own and could be used with another pair of type classes.

Shimuuar commented 9 months ago

@lehins, @Bodigrim Any objections?

lehins commented 9 months ago

To be honest with you, I fail to see the usefulness of such type family instance for primitive types, but at the same time, I don't see anything wrong with it either. It should work for all primitive arrays, except for ByteArray, since the kind does not match for it.

Shimuuar commented 9 months ago

Main use is to provide standard type family for Vector/MVector like type classes which provide freezing/thawing etc. I don't quite figured it out.

In particular vector's type classes unify both slicing and array operations. If not for slicing, primitive's arrays could get Vector/MVector instances and could use all vector's machinery.

lehins commented 9 months ago

Maybe we should extract slicing functionality Vector v => Slicable v into a separate class?

Bodigrim commented 9 months ago

To be honest with you, I fail to see the usefulness of such type family instance for primitive types, but at the same time, I don't see anything wrong with it either.

+1.

Shimuuar commented 9 months ago

Maybe we should extract slicing functionality Vector v => Slicable v into a separate class?

It's something that I would like to do. But it's rather complicated, it's quite invasive change which will break all unboxed instances. There're functions like takeWhile which could be implemented in stream fusion framework and as a slice. API for creating slices is quite anemic too. I really should make a writeup about this