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

Improve composability of Zipper operations. #143

Open
milessabin opened this issue Jun 26, 2014 · 4 comments
Open

Improve composability of Zipper operations. #143

milessabin opened this issue Jun 26, 2014 · 4 comments

Comments

@milessabin
Copy link
Owner

The problem is visible when you try and use the zipper in a polymorphic function. If you've used shapeless you'd expect the function to need a bunch of implicit zipper operation witnesses before you can perform the corresponding operation within the method body. Unfortunately it's extremely difficult to write the signatures for those witnesses. For instance in,

import shapeless._, ops.zipper._
def getRight[T, L <: HList](t: T)
  (implicit gen: Generic.Aux[T, L], right: Right[..]) = Zipper(t).right

what should we write as the type argument for Right in the implicit parameter block above?

@milessabin
Copy link
Owner Author

It should be possible to write a method that takes a Zipper argument and yields the result of .right.get.

@mandubian
Copy link
Contributor

Not sure to understand what you mean by composability...
Do you have the signature of the function you imagine and a short description?

@milessabin
Copy link
Owner Author

@mandubian I've updated the description to make it clearer what the issue actually is. I've also removed the "Low hanging fruit" label because I think it might be quite fiddly to solve in a satisfying way.

@mandubian
Copy link
Contributor

It compiles & works with:

def getRight[T, L <: HList](t: T)
  (implicit gen:   Generic.Aux[T, L],
               right:  Right[Zipper[T, HNil, L, None.type]]
  ) = Zipper(t).right

But we can't write:

def getRight[T, RH, RL <: HList](t: T)
  (implicit gen:   Generic.Aux[T, RH :: RL],
               right:  Right[Zipper[T, HNil, RH :: RL, None.type]]
  ) = Zipper(t).right

The Generic.Aux[T, RH :: RL] can't be inferred by the compiler (the whitebox macro mustn't help it).

If we could write this, it would be easy to infer the Zipper from the Generic.Aux and finally to infer the Right from the Zipper with something like:

implicit def hasRight[C, L <: HList, RH, RT <: HList, P](zipper: Zipper[C, L, RH::RT, P]): Right[Zipper[C, L, RH::RT, P]] = Right.right[C, L, RH, RT, P]

In this case, we wouldn't need the implicit Right[Zipper[...]] in the def getRight but it's not possible as is...

@milessabin milessabin removed the Ready label Oct 3, 2014
@joroKr21 joroKr21 modified the milestones: shapeless-2.4.0, shapeless-2.5.0 Mar 16, 2020
@joroKr21 joroKr21 removed this from the shapeless-2.5.0 milestone Sep 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants