A desirable Boxed instance for Unboxed #508
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR contains a proof of concept for
Unbox
instances of "boxed" data-types by way of the newly addedAsBoxedStrictly
andAsBoxedLazily
newtypes. This PR is intended to address issue #503.The
AsBoxedStrictly
newtype imposes new strictness semantics on the underlying type, ensuring the wrapped value is always reduced to normal form. This invariant requires anNFData
instance 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 aremakeBoxedStrictly
andgrabBoxedStrictly
exposed from theData.Vector.Unboxed
module to construct and deconstructAsBoxedStrictly
values, respectively.The
AsBoxedLazily
new-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
GHCi
Lazy usage
In
GHCi
Nota 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.