-
Notifications
You must be signed in to change notification settings - Fork 58
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
Folds are not implemented for &hlist
and &mut hlist
#180
Comments
Also, the thing about boilerplate is that it is not just in the generic bounds: where &H: lib1::HFoldLeftable<Folder, Acc> + lib2::HFoldLeftable<Folder, Acc> but in the calls to let a1 = lib1::HFoldLeftable::foldl(&hlist);
let a2 = lib2::HFoldLeftable::foldl(&hlist); You can't just import both traits and call a Though, this is unlikely to be a problem, because what sane human being will use two identical traits in the same function, right? |
IIRC way back when I was experimenting with the refactor of frunk, impls of traits on
The compiler bugs might be fixed now. I think you're free to try adding some of these impls. |
By the way, I found an old comment showing the sort of thing that used to make the compiler explode: #106 (comment) |
FWIW, I successfully made this work with the new |
The 1.67 release notes have this: I wonder if that fixes the exploding Sized bounds mentioned above? |
Reasons to have it
The main reason to have it is performance.
HCons<H, T>
intoH
andT
copies bothH
andT
.&HCons<H, T>
into&H
and&T
involves only pointer arithmetic with constants and one pointer copy.The compiler might optimize both lines into the same binary code, or it might not.
Problems
The biggest problem will be UX. Right now
HCons
andHNil
have nice methodsfoldl
andfoldr
, and to use those methods the user doesn't have to import any traits.With three fold impls for
hlist
,&hlist
and&mut hlist
, there should be either no method on the struct itself, or three methods with different names, kinda likeinto_iter()
,iter()
anditer_mut()
.Also, there will be some inconsistency between folds and other things like
HMappable
, which will be implemented for by-value hlists only; thoughHMappable
could be implemented withfoldr
, and the usefulness of this trait is a bit questionable.IntoReverse
could be implemented withfoldl
.ToRef
andToMut
could be implemented withfoldr
.Problems of not having those impls
Some libraries may use hlist instead of tuples with
to make compilation time a bit better, or to avoid some unnecessary
unsafe
in those impls (because hlist could be folded, while tuple could not be).However, generic bounds without fold impls for
&hlist
and&mut hlist
could be messy (or won't compile at all without some serious thinking):Then, the library will write its own
HFoldLeftable
(orHFoldRightable
) due to either performance or generic problems. However, if every such library would write its own folding trait, the user who will try to use both of those libraries in the same function will have to write a bit of boilerplate:The traits are identical, but the user should write both of them in the bound *sad user noises*.
So, yeah, any thoughts about it, @lloydmeta, @ExpHP ?
The text was updated successfully, but these errors were encountered: