-
Notifications
You must be signed in to change notification settings - Fork 141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve README #501
base: master
Are you sure you want to change the base?
Improve README #501
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,6 +1,89 @@ | ||||||||||||||||||||
The `vector` package [![Build Status](https://github.com/haskell/vector/workflows/CI/badge.svg)](https://github.com/haskell/vector/actions?query=branch%3Amaster) | ||||||||||||||||||||
==================== | ||||||||||||||||||||
|
||||||||||||||||||||
An efficient implementation of `Int`-indexed arrays (both mutable and immutable), with a powerful loop optimisation framework. | ||||||||||||||||||||
This package includes various modules that will allow you to | ||||||||||||||||||||
work with vectors and use an optimisation framework called [*fusion*](#fusion). | ||||||||||||||||||||
In this context, vector is an `Int`-indexed array-like data structure with a simpler | ||||||||||||||||||||
API that can contain any Haskell value. Additionally, its equivalence | ||||||||||||||||||||
to C-style arrays and optimisation via fusion accelerates vector’s | ||||||||||||||||||||
performance and makes it a great alternative to list. By installing this | ||||||||||||||||||||
package, you’ll be able to work with [boxed, unboxed, storable, and primitive | ||||||||||||||||||||
vectors](#vectors-available-in-the-package) as well as their generic interface. | ||||||||||||||||||||
|
||||||||||||||||||||
See [`vector` on Hackage](http://hackage.haskell.org/package/vector) for more information. | ||||||||||||||||||||
|
||||||||||||||||||||
## Table of Contents | ||||||||||||||||||||
|
||||||||||||||||||||
<!-- no toc --> | ||||||||||||||||||||
- [Installation](#installation) | ||||||||||||||||||||
- [Tutorial](#tutorial) | ||||||||||||||||||||
- [Vector vs Array](#vector-vs-array) | ||||||||||||||||||||
- [Vectors Available in the Package](#vectors-available-in-the-package) | ||||||||||||||||||||
- [Fusion](#fusion) | ||||||||||||||||||||
|
||||||||||||||||||||
## Installation | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need Installation section? There's nothing nonstandard it works like any other package |
||||||||||||||||||||
|
||||||||||||||||||||
If you use **cabal**, modify `package.cabal` so that its `build-depends` | ||||||||||||||||||||
section includes vector package: | ||||||||||||||||||||
``` | ||||||||||||||||||||
build-depends: base ^>=4.17.2.1 | ||||||||||||||||||||
, vector ==0.13.1.0 | ||||||||||||||||||||
``` | ||||||||||||||||||||
If you use **stack**, modify `package.yaml` so that its `depends` | ||||||||||||||||||||
section includes vector package: | ||||||||||||||||||||
``` | ||||||||||||||||||||
dependencies: | ||||||||||||||||||||
- base >= 4.7 && < 5 | ||||||||||||||||||||
- vector == 0.13.1.0 | ||||||||||||||||||||
``` | ||||||||||||||||||||
|
||||||||||||||||||||
|
||||||||||||||||||||
## Tutorial | ||||||||||||||||||||
|
||||||||||||||||||||
A beginner-friendly tutorial for vectors can be found on | ||||||||||||||||||||
[MMHaskell](https://mmhaskell.com/data-structures/vector). | ||||||||||||||||||||
|
||||||||||||||||||||
|
||||||||||||||||||||
If you have already started your adventure with vectors, | ||||||||||||||||||||
the tutorial on [Haskell Wiki](https://wiki.haskell.org/Numeric_Haskell:_A_Vector_Tutorial) | ||||||||||||||||||||
covers more ground. | ||||||||||||||||||||
|
||||||||||||||||||||
## Vector vs Array | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we even need to compare with |
||||||||||||||||||||
|
||||||||||||||||||||
Arrays are data structures that can store a multitude of elements | ||||||||||||||||||||
and allow immediate access to every one of them. Even though Haskell | ||||||||||||||||||||
has a built-in [Data.Array module](https://hackage.haskell.org/package/array-0.5.7.0), | ||||||||||||||||||||
arrays might be a bit overwhelming to use due to their complex API. | ||||||||||||||||||||
Conversely, vectors incorporate the array’s *O(1)* access to elements | ||||||||||||||||||||
with a much friendlier API of lists. Since they allow for framework | ||||||||||||||||||||
optimisation via loop fusion, vectors emphasise efficiency and keep | ||||||||||||||||||||
a rich interface. Unless you’re confident with arrays, it’s | ||||||||||||||||||||
well-advised to use vectors when looking for a similar functionality. | ||||||||||||||||||||
|
||||||||||||||||||||
## Vectors Available in the Package | ||||||||||||||||||||
|
||||||||||||||||||||
**Boxed vectors** store each of its elements as a pointer to its value. | ||||||||||||||||||||
Because we cannot directly access the contents of a boxed vector, they | ||||||||||||||||||||
are slower in comparison to unboxed vectors. | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||
|
||||||||||||||||||||
|
||||||||||||||||||||
**Unboxed vectors** store solely their elements’ values instead of pointers. | ||||||||||||||||||||
To be unboxed, the elements need to be constant in size. Since we can directly | ||||||||||||||||||||
access the contents of the unboxed vector, working with them is quite efficient. | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this case name lies.
Suggested change
|
||||||||||||||||||||
|
||||||||||||||||||||
|
||||||||||||||||||||
**Storable vectors** are pinned, convertible to and from pointers, and | ||||||||||||||||||||
usable in C functions. | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||
|
||||||||||||||||||||
|
||||||||||||||||||||
**Primitive vectors** contain elements of primitive type. | ||||||||||||||||||||
Primitive types can be recognised by the hash sign attached at | ||||||||||||||||||||
the end of value and/or type’s name, e.g. `3#` or `Int#`. You can read | ||||||||||||||||||||
more about them [here](https://downloads.haskell.org/~ghc/5.00/docs/set/primitives.html). | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's more precise to say that they can hold values that are instances of
Suggested change
|
||||||||||||||||||||
|
||||||||||||||||||||
## Fusion | ||||||||||||||||||||
|
||||||||||||||||||||
An optimisation framework provided in this package, fusion | ||||||||||||||||||||
is a technique that merges several functions into one and forces | ||||||||||||||||||||
it to produce only one outcome. Without fusion, your program might | ||||||||||||||||||||
generate intermediate results for each function separately and | ||||||||||||||||||||
stall its performance. | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Specifically stream fusion as opposed to build/foldr fusion used for lists.
Suggested change
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to cut down this paragraph a bit.