frunk
frunk copied to clipboard
Documenting rules for when type inference can solve for indices
I do a small bit of this in the coproduct embed PR, but I think there should be more:
There should be one central piece of documentation (which other methods can link to) describing the Index technique commonly used in frunk, describing how:
- Users should generally not worry about
Indextype parameters. Even when using turbofish syntax (once available), these should generally be left to type inference using_. - Generally speaking, type inference can solve for the indices whenever there is a unique solution.
- This means that methods like hlist's
pluckand coproduct'sinjectsucceed when the type appears exactly once in the HList/coproduct.
It should also explain workarounds for when type inference fails:
- The preferred method, whenever possible, should be to use newtypes in your HList/coproduct, so that all of the types are distinct. (@Centril, @lloydmeta do you agree?)
- As a last resort, indices can be specified explicitly, but I'm not sure that the docs should be suggesting this course of action quite yet as they feel mostly like an implementation detail. (maybe once reified indices are added, if I ever get to that; I still need to get more experience with them first in
funky)
Users should generally not worry about
Indextype parameters. Even when using turbofish syntax (once available), these should generally be left to type inference using_.
Agreed; Hopefully you won't even need to specify _ in the future with some sort of "partial turbofish" (see my RFC on this -- https://github.com/rust-lang/rfcs/pull/2176) mechanism in the language itself.
I also agree with everything else you said.