-
Notifications
You must be signed in to change notification settings - Fork 140
A desirable Boxed instance for Unboxed #508
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
Conversation
|
I haven't looked at the code yet. CI is broken at the moment fix should be in #507 |
06b5685 to
7cce2dc
Compare
Shimuuar
left a comment
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.
Please rebase on top current mater. CI is fixed there.
For strict and lazy vectors you simply need to pick Data.Vector.Strict/Data.Vector as a representation and coerce their methods same way as UnboxViaPrim do,
Variant which reduces values to NF is slightly more complicated. You can pick either strict or lazy vector as a representation. Former seems more logical. We evaluate value whenever it's stored in a vector. So following methods need custom code: basicUnsafeWrite, basicUnsafeReplicate, elemseq
Default implementation of baiscSet for boxed vectors basicSet is fine, it's defined in terms of basicUnsafeWrite
54cf581 to
e259872
Compare
|
@recursion-ninja If you're trying to fix doctest it's easier to do so locally. Run in vector subdir. |
e259872 to
8560ab7
Compare
Yes, I was. This is quite helpful. |
f07e3d1 to
7de765b
Compare
|
The test now pass, but I still need to do a pass over the documentation. |
| basicUnsafeReplicate = coerce $ M.basicUnsafeReplicate @S.MVector @a | ||
| basicUnsafeRead = coerce $ M.basicUnsafeRead @S.MVector @a | ||
| basicUnsafeWrite = coerce $ M.basicUnsafeWrite @S.MVector @a | ||
| basicClear = coerce $ M.basicClear @S.MVector @a | ||
| basicSet = coerce $ M.basicSet @S.MVector @a |
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.
We need to ensure that value is reduced to NF before writing it to vector. There are 3 method that could write to vector: basicUnsafeReplicate, basicUnsafeWrite, basicSet. They need custom definition which reduces element to NF before passing it to corresponding method
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.
Thanks for this API insight. I have updated the PR forceing the values to normal form before being inserted into the vector.
7de765b to
91d736d
Compare
I have updated the documentation. @Shimuuar I think the PR is ready for review, and and potentially merged if the package maintainers agree. |
|
Other than comment above PR is good to go. I'm not sure why CI is failing. It seems to have stuck for some reason and then job got cancelled. |
ac6a145 to
b94cb48
Compare
@Shimuuar I addressed the comment above. Should be good to merge now. |
|
Merged. @recursion-ninja Thank you! |
# Changes in version 0.13.2.0 * Strict boxed vector `Data.Vector.Strict` and `Data.Vector.Strict.Mutable` is added (#488). it ensures that all values in the vector are evaluated to WHNF. * `DoNotUnboxStrict`, `DoNotUnboxLazy`, and `DoNotUnboxNormalForm` wrapper are added for defining unbox instances for types that contain not unboxable fields. [#503](haskell/vector#506), [#508](haskell/vector#508) * `spanR` and `breakR` were added [#476](haskell/vector#476). They allow parsing vector from the right. * We had some improvements on `*.Mutable.{next,prev}Permutation{,By}` [#498](haskell/vector#498): * Add `*.Mutable.prevPermutation{,By}` and `*.Mutable.nextPermutationBy` * Improve time performance. We may now expect good specialization supported by inlining. The implementation has also been algorithmically updated: in the previous implementation the full enumeration of all the permutations of `[1..n]` took Omega(n*n!), but it now takes O(n!). * Add tests for `{next,prev}Permutation` * Add benchmarks for `{next,prev}Permutation` * Cabal >= 3.0 is now required for building package (#481). * `vector:benchmarks-O2` public sublibrary containing benchmarks is added (#481). * Type family `Mutable` provides instances for arrays from `primitive`. * Various documentation improvements.
This PR contains a proof of concept for
Unboxinstances of "boxed" data-types by way of the newly addedAsBoxedStrictlyandAsBoxedLazilynewtypes. This PR is intended to address issue #503.The
AsBoxedStrictlynewtype imposes new strictness semantics on the underlying type, ensuring the wrapped value is always reduced to normal form. This invariant requires anNFDatainstance for the underlying type. Furthermore, it requires the use of a "smart constructor" which evaluates the wrapped value to normal form, since a new-type cannot have strictness annotations. Hence there aremakeBoxedStrictlyandgrabBoxedStrictlyexposed from theData.Vector.Unboxedmodule to construct and deconstructAsBoxedStrictlyvalues, respectively.The
AsBoxedLazilynew-type is much simpler since it preserves the strictness semantics of the underlying data-type unaltered.Here are two example usages of the newtypes as a proof of concept:
Strict usage
In
GHCiLazy usage
In
GHCiNota Bene
Since this is a proof of concept, all types and functions names are subject to change after the appropriate level of "bike-shedding" has occurred. Commentary is welcomed and encouraged.