Skip to content
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

The Solo instance is incorrect #1119

Open
Qqwy opened this issue Oct 5, 2024 · 2 comments
Open

The Solo instance is incorrect #1119

Qqwy opened this issue Oct 5, 2024 · 2 comments

Comments

@Qqwy
Copy link

Qqwy commented Oct 5, 2024

Solo is the canonical 1-element tuple type.
However, the implementation added in PR #891 treat it as any other normal 1-element type, which is incorrect.

This becomes problematic when you have code that wants to seriaize/deserialize generically over tuples of various arities:

  • (10, 20, 30) <-> "[10, 20, 30]"
  • (10, 20) <-> "[10, 20]"
  • Solo 10 <-> "10" ❗❗❗
  • () <-> "[]"
@sjshuck
Copy link

sjshuck commented Dec 29, 2024

I think "incorrect" is a bit strong but the argument is reasonable. The problem is it would break 4+ years' behavior. I'd be curious to see

code that wants to seriaize/deserialize generically over tuples of various arities

because I suspect a custom datatype implementing a subset of HList functionality would better serve, or demonstrate that genericity isn't worth the trouble, depending on the genericity desired.

@Qqwy
Copy link
Author

Qqwy commented Jan 2, 2025

You're absolutely astute that this change would be backwards-incompatible and thus could only be introduced in a breaking PVP release. That of course shouldn't be done lightly, and this issue by itself by no means is enough to warrant such a breaking change in and of itself. But if there is another change that needs a breaking version release, this problem could be resolved at the same time.


What I ended up doing in the codebase where I first encountered this, is creating a separate datatype called Single that functions as Solo.

Repo here, details of encoding/decoding tuples here.

Indeed, creating a Tuple-like custom type like HList would be another solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants