Repository navigation
Add Binary (Solo a) instance - #248
Open
NopeCharon wants to merge 1 commit into
Open
NopeCharon wants to merge 1 commit into
NopeCharon wants to merge 1 commit into
Conversation
Solo, the canonical lifted 1-tuple, is exported from Data.Tuple since base-4.16 but had no Binary instance, unlike () and the larger tuples. Add an instance that encodes Solo a exactly like a, without a tag or length prefix, consistent with the other tuple instances. It is only defined for base >= 4.16, where Data.Tuple exports Solo; binary does not depend on ghc-prim, which is where GHC 9.0 (base-4.15) defines it. Since base-4.18 the data constructor is MkSolo and the Solo pattern synonym is deprecated, so pattern match on MkSolo there to avoid -Wdeprecations warnings, and on Solo for base-4.16 and base-4.17. Add a round-trip QuickCheck test and a wire-format golden vector pinning the encoding of Solo Word16 to that of Word16. Closes haskell#188
konsumlamm
reviewed
Dec 5, 2026
Comment on lines
+1474
to
+1478
| #if MIN_VERSION_base(4,18,0) | ||
| , testWithGen "Solo Int" (MkSolo <$> (arbitrary :: Gen Int)) | ||
| #elif MIN_VERSION_base(4,16,0) | ||
| , testWithGen "Solo Int" (Solo <$> (arbitrary :: Gen Int)) | ||
| #endif |
Contributor
There was a problem hiding this comment.
Why use testWithGen here?
Author
There was a problem hiding this comment.
QuickCheck only has an Arbitrary (Solo a) instance since 2.17 and the test suite still allows QuickCheck >= 2.9, so I used an explicit generator like the Identity and Monoid.Sum tests below instead of adding an orphan instance or CPP on the QuickCheck version.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Closes #188.
Solo ais encoded exactly likea(no tag, no length prefix), consistent with()and the other tuple instances.The instance requires
base >= 4.16, which is whereData.Tuplestarts exportingSolo. GHC 9.0 only has it inghc-prim'sGHC.Tuple, andbinarydoesn't depend onghc-prim. Sincebase-4.18the data constructor isMkSoloand theSolopattern synonym is deprecated, so the instance matches onMkSolothere (to avoid-Wdeprecationswarnings) and onSoloforbase-4.16/4.17.Tests: a round-trip property in the QuickCheck suite and a wire-format golden vector checking that
Solo Word16encodes likeWord16.