A newtype-friendly wrapper for Data.Vector.Unboxed
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
app
scripts
src/Data/Vector
test
.gitignore
ChangeLog.md
LICENSE
README.md
Setup.hs
package.yaml
stack.yaml

README.md

unboxing-vector

A newtype-friendly wrapper for Data.Vector.Unboxed in vector package.

Description

Suppose you define a newtype for Int and want to store them in an unboxed vector.

newtype Foo = Foo Int

generate 10 (\i -> Foo i) :: Vector Foo

With plain Data.Vector.Unboxed, you either write two dozen of lines of code to get it work, or resort to Template Haskell (vector-th-unbox package).

But with Data.Vector.Unboxing, the code you write is just two lines:

instance Data.Vector.Unboxing.Unboxable Foo where
  type Underlying Foo = Int

Note that the vector type provided by this package (Data.Vector.Unboxing.Vector) is different from Data.Vector.Unboxed.Vector, although the former is a newtype for the latter.