Skip to content

Documenting rules for when type inference can solve for indices #94

@ExpHP

Description

@ExpHP

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 Index type 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 pluck and coproduct's inject succeed 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)

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions