Repository navigation
A desirable Boxed instance for Unboxed - #508
Merged
Merged
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
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.